Skip to content

Commit

Permalink
[Site Isolation] Context menu events are always sent to the main frame
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269217
rdar://122819286

Reviewed by Alex Christensen.

Context menu events should not be handled if the mouse event hit a remote frame.

* LayoutTests/http/tests/site-isolation/mouse-events/context-menu-main-frame-event-expected.txt: Added.
* LayoutTests/http/tests/site-isolation/mouse-events/context-menu-main-frame-event.html: Added.
* LayoutTests/http/tests/site-isolation/mouse-events/resources/context-menu-event-listener.html: Added.
* Source/WebKit/WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::handleMouseEvent):

Canonical link: https://commits.webkit.org/274516@main
  • Loading branch information
charliewolfe committed Feb 13, 2024
1 parent 230c082 commit fda3885
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Verifies that the iframe receives a context menu event and the main frame does not.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS iframe received context menu event.
PASS successfullyParsed is true

TEST COMPLETE

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- webkit-test-runner [ SiteIsolationEnabled=true ] -->
<script src="/js-test-resources/js-test.js"></script>
<script>
description("Verifies that the iframe receives a context menu event and the main frame does not.");
jsTestIsAsync = true;

addEventListener("message", (event) => {
if (event.data == "contextmenu") {
testPassed("iframe received context menu event.");
finishJSTest();
}
});

addEventListener("contextmenu", () => {
testFailed("Main frame contextmenu event listener was called.");
finishJSTest();
});

function onLoad() {
let frame = document.getElementById("frame");
let x = frame.offsetParent.offsetLeft + frame.offsetLeft + frame.offsetWidth / 2;
let y = frame.offsetParent.offsetTop + frame.offsetTop + frame.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown(2);
eventSender.mouseUp(2);
}
</script>
<iframe onload="onLoad()" id="frame" src="http://localhost:8000/site-isolation/mouse-events/resources/context-menu-event-listener.html"></iframe>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
addEventListener("contextmenu", () => {
window.parent.postMessage("contextmenu", "*");
});
</script>
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/WebFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ WebCore::HandleUserInputEventResult WebFrame::handleMouseEvent(const WebMouseEve

auto mousePressEventResult = coreLocalFrame->eventHandler().handleMousePressEvent(platformMouseEvent);
#if ENABLE(CONTEXT_MENU_EVENT)
if (isContextClick(platformMouseEvent))
if (isContextClick(platformMouseEvent) && !mousePressEventResult.remoteUserInputEventData())
mousePressEventResult.setHandled(handleContextMenuEvent(platformMouseEvent));
#endif
return mousePressEventResult;
Expand Down

0 comments on commit fda3885

Please sign in to comment.