WebKit Bugzilla
Attachment 369470 Details for
Bug 186593
: User gesture context is not passed via MessageChannel
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
0001-Bug-186593-User-gesture-context-is-not-passed-via-Me.patch (text/plain), 29.82 KB, created by
Frédéric Wang (:fredw)
on 2019-05-08 23:24:53 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Frédéric Wang (:fredw)
Created:
2019-05-08 23:24:53 PDT
Size:
29.82 KB
patch
obsolete
>From 1127bc39e972c5e67867dc9cb91a40298b2f9e1a Mon Sep 17 00:00:00 2001 >From: Frederic Wang <fwang@igalia.com> >Date: Thu, 9 May 2019 08:23:25 +0200 >Subject: [PATCH xserver] Bug 186593 - User gesture context is not passed via > MessageChannel > >--- > LayoutTests/ChangeLog | 26 ++++++ > ...-triggered-by-user-activation-expected.txt | 8 ++ > ...user-activation-from-subframe-expected.txt | 8 ++ > ...ered-by-user-activation-from-subframe.html | 60 ++++++++++++++ > ...tMessage-triggered-by-user-activation.html | 80 +++++++++++++++++++ > ...triggered-by-user-activation-subframe.html | 46 +++++++++++ > ...ostMessage-triggered-by-user-activation.js | 18 +++++ > LayoutTests/platform/gtk/TestExpectations | 2 + > LayoutTests/platform/wpe/TestExpectations | 2 + > Source/WebCore/ChangeLog | 49 ++++++++++++ > Source/WebCore/dom/MessagePort.cpp | 4 +- > Source/WebCore/dom/UserGestureIndicator.h | 51 +++++++++++- > .../messageports/MessageWithMessagePorts.h | 15 ++++ > Source/WebCore/page/DOMWindow.cpp | 6 +- > .../workers/DedicatedWorkerGlobalScope.cpp | 2 +- > Source/WebCore/workers/Worker.cpp | 2 +- > .../WebCore/workers/service/ServiceWorker.cpp | 2 +- > .../workers/service/ServiceWorkerClient.cpp | 2 +- > 18 files changed, 373 insertions(+), 10 deletions(-) > create mode 100644 LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-expected.txt > create mode 100644 LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe-expected.txt > create mode 100644 LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html > create mode 100644 LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation.html > create mode 100644 LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation-subframe.html > create mode 100644 LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation.js > >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 2f702f48d4b..c9ad2ab6167 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,29 @@ >+2018-11-14 Frederic Wang <fwang@igalia.com> >+ >+ User gesture context is not passed via MessageChannel >+ https://bugs.webkit.org/show_bug.cgi?id=186593#c3 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch adds WPT tests from [1], adapted to rely on UIHelper for user interaction. We >+ tests message posting via Window, MessageChannel, BroadcastChannel although the latter is >+ not supported by WebKit yet [2]. We also verify message coming from the same window or >+ from a subframe. >+ >+ [1] https://github.com/web-platform-tests/wpt/pull/11668 >+ [2] https://bugs.webkit.org/show_bug.cgi?id=161472 >+ >+ * http/tests/messaging/postMessage-triggered-by-user-activation-expected.txt: Added. >+ * http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe-expected.txt: Added. >+ * http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html: Added. >+ * http/tests/messaging/postMessage-triggered-by-user-activation.html: Added. >+ * http/tests/messaging/resources/postMessage-triggered-by-user-activation-subframe.html: Added. >+ * http/tests/messaging/resources/postMessage-triggered-by-user-activation.js: Added. >+ (canOpenPopup): >+ (appendButton): >+ * platform/gtk/TestExpectations: Skip tests since click emulation is not available. >+ * platform/wpe/TestExpectations: Ditto. >+ > 2019-05-08 Rob Buis <rbuis@igalia.com> > > Link prefetch not useful for top-level navigation >diff --git a/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-expected.txt b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-expected.txt >new file mode 100644 >index 00000000000..177fc1d3e1a >--- /dev/null >+++ b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-expected.txt >@@ -0,0 +1,8 @@ >+Click all the buttons below. If only "PASS" results appear the test passes, otherwise it fails. >+ >+Window's postMessageMessagePort's postMessage >+ >+PASS With window >+PASS With a MessageChannel and its MessagePorts >+FAIL With a BroadcastChannel assert_true: The browser must support BroadcastChannel expected true got false >+ >diff --git a/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe-expected.txt b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe-expected.txt >new file mode 100644 >index 00000000000..f64f7661f46 >--- /dev/null >+++ b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe-expected.txt >@@ -0,0 +1,8 @@ >+Click all the buttons below. If only "PASS" results appear the test passes, otherwise it fails. >+ >+ >+ >+PASS With window >+PASS With a MessageChannel and its MessagePorts >+FAIL With a BroadcastChannel assert_true: The browser must support BroadcastChannel expected true got false >+ >diff --git a/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html >new file mode 100644 >index 00000000000..62dd41a40a8 >--- /dev/null >+++ b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html >@@ -0,0 +1,60 @@ >+<!DOCTYPE html> >+<title>postMessage's task triggered by user activation from a subframe</title> >+<script src="/resources/testharness.js"></script> >+<script src="/resources/testharnessreport.js"></script> >+<script src="resources/postMessage-triggered-by-user-activation.js"></script> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/web-messaging.html#dom-window-postmessage"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/comms.html#dom-messageport-postmessage"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-postmessage"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-activation"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/browsers.html#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name"> >+<body> >+<p>Click all the buttons below. If only "PASS" results appear the test passes, >+ otherwise it fails.</p> >+<script> >+"use strict"; >+ >+let windowTest = async_test("With window"); >+let click1 = windowTest.step_func(() => { >+ assert_true(canOpenPopup(), "onmessage should be able to open popup"); >+ windowTest.done(); >+}); >+ >+let messagePortTest = async_test(() => { >+ assert_true("MessageChannel" in self, "The browser must support MessageChannel"); >+}, "With a MessageChannel and its MessagePorts"); >+let channel2 = messagePortTest.step_func(port => { >+ port.onmessage = messagePortTest.step_func_done(e => { >+ assert_equals(e.data, "click2"); >+ assert_true(canOpenPopup(), "onmessage should be able to open popup"); >+ }); >+}); >+ >+async_test(t => { >+ assert_true("BroadcastChannel" in self, "The browser must support BroadcastChannel"); >+ >+ const channel = new BroadcastChannel("channel3"); >+ >+ channel.onmessage = t.step_func_done(e => { >+ assert_equals(e.data, "click3"); >+ assert_true(canOpenPopup(), "onmessage should be able to open popup"); >+ }); >+}, "With a BroadcastChannel"); >+ >+window.onmessage = (e => { >+ if (e.data === "click1") >+ click1(); >+ else if (e.data === "channel2") { >+ let port = e.ports[0]; >+ channel2(port); >+ } else if (e.data === "sendFrameCoordinatesInParent") { >+ var iframe = document.querySelector("iframe"); >+ // The iframe uses eventSender to emulate a user navigation, which requires absolute coordinates. >+ // Because the iframe is cross-origin, it can't get the offsets itself, so leak them. >+ frames[0].postMessage({x: iframe.offsetLeft, y: iframe.offsetTop}, "*"); >+ } else >+ assert_unreached("Unknown message received"); >+}); >+</script> >+<iframe src="resources/postMessage-triggered-by-user-activation-subframe.html"></iframe> >+</body> >diff --git a/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation.html b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation.html >new file mode 100644 >index 00000000000..1cd7e969fab >--- /dev/null >+++ b/LayoutTests/http/tests/messaging/postMessage-triggered-by-user-activation.html >@@ -0,0 +1,80 @@ >+<!DOCTYPE html> >+<title>postMessage's task triggered by user activation</title> >+<script src="/resources/testharness.js"></script> >+<script src="/resources/testharnessreport.js"></script> >+<!-- FIXME(https://webkit.org/b/187039): Emulate user clicks with testdriver.js --> >+<script src="/js-test-resources/ui-helper.js"></script> >+<script src="resources/postMessage-triggered-by-user-activation.js"></script> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/web-messaging.html#dom-window-postmessage"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/comms.html#dom-messageport-postmessage"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-postmessage"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-activation"> >+<link rel="help" href="https://html.spec.whatwg.org/multipage/browsers.html#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name"> >+<body> >+<p>Click all the buttons below. If only "PASS" results appear the test passes, >+ otherwise it fails.</p> >+<script> >+"use strict"; >+ >+async_test(t => { >+ window.onmessage = t.step_func_done(e => { >+ assert_equals(e.data, "click1"); >+ assert_true(canOpenPopup(), "onmessage should be able to open popup"); >+ }); >+ >+ let button = appendButton("Window's postMessage", t.step_func(() => { >+ window.postMessage("click1", "*"); >+ })); >+ // FIXME(https://webkit.org/b/187039): Emulate user clicks with testdriver.js >+ if (window.testRunner) { >+ window.UIHelper.activateElement(button).catch(reason => { >+ assert_unreached("Cannot emulate click: ${reason}"); >+ }); >+ } >+}, "With window"); >+ >+async_test(t => { >+ assert_true("MessageChannel" in self, "The browser must support MessageChannel"); >+ >+ const channel = new MessageChannel(); >+ >+ channel.port2.onmessage = t.step_func_done(e => { >+ assert_equals(e.data, "click2"); >+ assert_true(canOpenPopup(), "onmessage should be able to open popup"); >+ }); >+ >+ let button = appendButton("MessagePort's postMessage", t.step_func(() => { >+ channel.port1.postMessage("click2"); >+ })); >+ // FIXME(https://webkit.org/b/187039): Emulate user clicks with testdriver.js >+ if (window.testRunner) { >+ window.UIHelper.activateElement(button).catch(reason => { >+ assert_unreached("Cannot emulate click: ${reason}"); >+ }); >+ } >+}, "With a MessageChannel and its MessagePorts"); >+ >+async_test(t => { >+ assert_true("BroadcastChannel" in self, "The browser must support BroadcastChannel"); >+ >+ const channel = new BroadcastChannel("channel3"); >+ >+ channel.onmessage = t.step_func_done(e => { >+ assert_equals(e.data, "click3"); >+ assert_true(canOpenPopup(), "onmessage should be able to open popup"); >+ }); >+ >+ let button = appendButton("BroadcastChannel's postMessage", t.step_func(() => { >+ let myChannel = new BroadcastChannel("channel3"); >+ myChannel.postMessage("click3"); >+ })); >+ // FIXME(https://webkit.org/b/187039): Emulate user clicks with testdriver.js >+ if (window.testRunner) { >+ window.UIHelper.activateElement(button).catch(reason => { >+ assert_unreached("Cannot emulate click: ${reason}"); >+ }); >+ } >+}, "With a BroadcastChannel"); >+ >+</script> >+</body> >diff --git a/LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation-subframe.html b/LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation-subframe.html >new file mode 100644 >index 00000000000..e76521b7cfd >--- /dev/null >+++ b/LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation-subframe.html >@@ -0,0 +1,46 @@ >+<!DOCTYPE html> >+<html> >+<head> >+ <title>Subframe for testing postMessage's task triggered by user activation</title> >+ <script src="postMessage-triggered-by-user-activation.js"></script> >+ <script src="/js-test-resources/ui-helper.js"></script> >+</head> >+<body> >+ <script> >+ appendButton("Window's postMessage", () => { >+ window.parent.postMessage("click1", "*"); >+ }); >+ >+ (() => { >+ if (!window.MessageChannel) >+ return; >+ const channel = new MessageChannel(); >+ window.parent.postMessage("channel2", "*", [channel.port2]); >+ appendButton("MessagePort's postMessage ", () => { >+ channel.port1.postMessage("click2"); >+ }); >+ })(); >+ >+ (() => { >+ if (!window.BroadcastChannel) >+ return; >+ const channel = new BroadcastChannel("channel3"); >+ appendButton("BroadcastChannel's postMessage", () => { >+ channel.postMessage("click3"); >+ }); >+ })(); >+ >+ window.onmessage = (event => { >+ if (!window.testRunner) >+ return; >+ // FIXME(https://webkit.org/b/187039): Emulate user clicks with testdriver.js >+ document.querySelectorAll("button").forEach(async button => { >+ await window.UIHelper.activateAt(event.data.x + button.offsetLeft + 2, event.data.y + button.offsetTop + 2).catch(reason => { >+ parent.postMessage("Cannot emulate click: ${reason}", "*"); >+ }); >+ }); >+ }); >+ window.parent.postMessage("sendFrameCoordinatesInParent", "*"); >+ </script> >+</body> >+</html> >diff --git a/LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation.js b/LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation.js >new file mode 100644 >index 00000000000..22936fe0f03 >--- /dev/null >+++ b/LayoutTests/http/tests/messaging/resources/postMessage-triggered-by-user-activation.js >@@ -0,0 +1,18 @@ >+"use strict"; >+ >+function canOpenPopup() { >+ let popup = window.open("about:blank", "_blank"); >+ if (popup) { >+ popup.close(); >+ return true; >+ } >+ return false; >+} >+ >+function appendButton(buttonText, onClickCallback) { >+ let button = document.createElement("button"); >+ button.textContent = buttonText; >+ button.onclick = onClickCallback; >+ document.body.appendChild(button); >+ return button; >+} >diff --git a/LayoutTests/platform/gtk/TestExpectations b/LayoutTests/platform/gtk/TestExpectations >index a394fcd3791..6896b896946 100644 >--- a/LayoutTests/platform/gtk/TestExpectations >+++ b/LayoutTests/platform/gtk/TestExpectations >@@ -954,6 +954,8 @@ webkit.org/b/153833 fast/events/can-click-element-on-page-with-active-pseudo-cla > webkit.org/b/153833 fast/shadow-dom/touch-event-ios.html [ Skip ] > webkit.org/b/153833 fast/events/before-input-prevent-insert-replacement.html [ Skip ] > webkit.org/b/153833 fast/events/input-event-insert-replacement.html [ Skip ] >+webkit.org/b/153833 http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html [ Skip ] >+webkit.org/b/153833 http/tests/messaging/postMessage-triggered-by-user-activation.html [ Skip ] > > # Skip tests requiring UIScriptController::zoomToScale > webkit.org/b/168050 fast/visual-viewport/resize-event-fired.html [ Skip ] >diff --git a/LayoutTests/platform/wpe/TestExpectations b/LayoutTests/platform/wpe/TestExpectations >index a4ea66d9758..d9dbf328f07 100644 >--- a/LayoutTests/platform/wpe/TestExpectations >+++ b/LayoutTests/platform/wpe/TestExpectations >@@ -1135,6 +1135,8 @@ webkit.org/b/173419 fast/events/touch/multi-touch-inside-nested-iframes.html [ T > webkit.org/b/173419 fast/events/touch/page-scaled-touch-gesture-click.html [ Timeout ] > webkit.org/b/173419 fast/events/touch/touch-target-limited.html [ Timeout ] > webkit.org/b/173419 fast/events/touch/touch-target.html [ Timeout ] >+webkit.org/b/173419 http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html [ Skip ] >+webkit.org/b/173419 http/tests/messaging/postMessage-triggered-by-user-activation.html [ Skip ] > > webkit.org/b/163858 fast/events/touch/touch-constructor.html [ Skip ] > webkit.org/b/173411 fast/events/touch/frame-hover-update.html [ Failure ] >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 6210b9469ac..7623ebd7e0f 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,52 @@ >+2018-11-14 Frederic Wang <fwang@igalia.com> >+ >+ User gesture context is not passed via MessageChannel >+ https://bugs.webkit.org/show_bug.cgi?id=186593#c3 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch enables to pass user gesture via MessageChannel. The HTML5 specification does give >+ any hint about when such behavior should be prohibited [1]. We try to align on Chromium's >+ new behavior [2] but try to be conservative by preventing transfer whenever workers are >+ involved: >+ - DOMWindow::postMessage continues to always pass the user gesture context. >+ - MessagePort::postMessage passes the user gesture context as long as it is not used in a worker context. >+ - Worker::postMessage will never pass the user gesture context. >+ For testing, we use the WPT tests written in [3] but rely on UIHelper to emulate user's >+ interaction. >+ >+ [1] https://html.spec.whatwg.org/multipage/web-messaging.html#dom-messageport-postmessage >+ [2] https://bugs.chromium.org/p/chromium/issues/detail?id=851493#c1 >+ [3] https://github.com/web-platform-tests/wpt/pull/11668 >+ >+ Tests: http/tests/messaging/postMessage-triggered-by-user-activation-from-subframe.html >+ http/tests/messaging/postMessage-triggered-by-user-activation.html >+ >+ * dom/MessagePort.cpp: >+ (WebCore::MessagePort::postMessage): Pass user gesture via MessagePort when we are outside a >+ worker context. This is the only new behavior introduced by this patch. >+ (WebCore::MessagePort::dispatchMessages): Apply user gesture token carried by the message. >+ * dom/UserGestureIndicator.h: Add encoding/decoding facilities for UserGestureToken, so that >+ they can be passed via cross-process messaging. >+ (WebCore::UserGestureToken::encode const): >+ (WebCore::UserGestureToken::decode): >+ * dom/messageports/MessageWithMessagePorts.h: Add a UserGestureToken member to >+ MessageWithMessagePorts and again ensure they can properly be encoded/decoded. >+ (WebCore::MessageWithMessagePorts::encode const): >+ (WebCore::MessageWithMessagePorts::decode): >+ * page/DOMWindow.cpp: Use the new UserGestureToken member on MessageWithMessagePorts to >+ propagate current user gesture instead of one on DOMWindow. >+ (WebCore::PostMessageTimer::PostMessageTimer): >+ (WebCore::DOMWindow::postMessage): >+ * workers/DedicatedWorkerGlobalScope.cpp: Do not propagate user gesture in worker. >+ (WebCore::DedicatedWorkerGlobalScope::postMessage): >+ * workers/Worker.cpp: Ditto. >+ (WebCore::Worker::postMessage): >+ * workers/service/ServiceWorker.cpp: Ditto. >+ (WebCore::ServiceWorker::postMessage): >+ * workers/service/ServiceWorkerClient.cpp: Ditto. >+ (WebCore::ServiceWorkerClient::postMessage): >+ > 2019-05-08 Rob Buis <rbuis@igalia.com> > > Link prefetch not useful for top-level navigation >diff --git a/Source/WebCore/dom/MessagePort.cpp b/Source/WebCore/dom/MessagePort.cpp >index a029b3d71e7..2afae7004f4 100644 >--- a/Source/WebCore/dom/MessagePort.cpp >+++ b/Source/WebCore/dom/MessagePort.cpp >@@ -156,7 +156,8 @@ ExceptionOr<void> MessagePort::postMessage(JSC::ExecState& state, JSC::JSValue m > transferredPorts = disentangleResult.releaseReturnValue(); > } > >- MessageWithMessagePorts message { messageData.releaseReturnValue(), WTFMove(transferredPorts) }; >+ bool contextIsWorker = is<WorkerGlobalScope>(*m_scriptExecutionContext); >+ MessageWithMessagePorts message { messageData.releaseReturnValue(), WTFMove(transferredPorts), contextIsWorker ? nullptr : UserGestureIndicator::currentUserGesture() }; > > LOG(MessagePorts, "Actually posting message to port %s (to be received by port %s)", m_identifier.logString().utf8().data(), m_remoteIdentifier.logString().utf8().data()); > >@@ -271,6 +272,7 @@ void MessagePort::dispatchMessages() > // close() in Worker onmessage handler should prevent next message from dispatching. > if (contextIsWorker && downcast<WorkerGlobalScope>(*m_scriptExecutionContext).isClosing()) > return; >+ UserGestureIndicator gestureIndicator(message.userGestureToken); > auto ports = MessagePort::entanglePorts(*m_scriptExecutionContext, WTFMove(message.transferredPorts)); > dispatchEvent(MessageEvent::create(WTFMove(ports), message.message.releaseNonNull())); > } >diff --git a/Source/WebCore/dom/UserGestureIndicator.h b/Source/WebCore/dom/UserGestureIndicator.h >index cca4240edce..7262cecc2df 100644 >--- a/Source/WebCore/dom/UserGestureIndicator.h >+++ b/Source/WebCore/dom/UserGestureIndicator.h >@@ -63,6 +63,7 @@ public: > m_destructionObservers.append(WTFMove(observer)); > } > >+ > DOMPasteAccessPolicy domPasteAccessPolicy() const { return m_domPasteAccessPolicy; } > void didRequestDOMPasteAccess(DOMPasteAccessResponse response) > { >@@ -87,6 +88,8 @@ public: > { > return m_startTime + expirationInterval < MonotonicTime::now(); > } >+ template<class Encoder> void encode(Encoder&) const; >+ template<class Decoder> static RefPtr<UserGestureToken> decode(Decoder&); > > private: > UserGestureToken(ProcessingUserGestureState state, UserGestureType gestureType) >@@ -103,6 +106,26 @@ private: > MonotonicTime m_startTime { MonotonicTime::now() }; > }; > >+template<class Encoder> >+void UserGestureToken::encode(Encoder& encoder) const >+{ >+ encoder << m_state << m_gestureType; >+} >+ >+template<class Decoder> >+RefPtr<UserGestureToken> UserGestureToken::decode(Decoder& decoder) >+{ >+ ProcessingUserGestureState state; >+ if (!decoder.decode(state)) >+ return nullptr; >+ >+ UserGestureType gestureType; >+ if (!decoder.decode(gestureType)) >+ return nullptr; >+ >+ return UserGestureToken::create(state, gestureType); >+} >+ > class UserGestureIndicator { > WTF_MAKE_FAST_ALLOCATED; > WTF_MAKE_NONCOPYABLE(UserGestureIndicator); >@@ -122,4 +145,30 @@ private: > RefPtr<UserGestureToken> m_previousToken; > }; > >-} >+} // namespace WebCore >+ >+namespace WTF { >+ >+template<typename> struct EnumTraits; >+template<typename E, E...> struct EnumValues; >+ >+enum class UserGestureType { EscapeKey, Other }; >+ >+template<> struct EnumTraits<WebCore::ProcessingUserGestureState> { >+ using values = EnumValues< >+ WebCore::ProcessingUserGestureState, >+ WebCore::ProcessingUserGesture, >+ WebCore::ProcessingPotentialUserGesture, >+ WebCore::NotProcessingUserGesture >+ >; >+}; >+ >+template<> struct EnumTraits<WebCore::UserGestureType> { >+ using values = EnumValues< >+ WebCore::UserGestureType, >+ WebCore::UserGestureType::EscapeKey, >+ WebCore::UserGestureType::Other >+ >; >+}; >+ >+} // namespace WTF >diff --git a/Source/WebCore/dom/messageports/MessageWithMessagePorts.h b/Source/WebCore/dom/messageports/MessageWithMessagePorts.h >index a39075759e9..1468ba7ff14 100644 >--- a/Source/WebCore/dom/messageports/MessageWithMessagePorts.h >+++ b/Source/WebCore/dom/messageports/MessageWithMessagePorts.h >@@ -27,6 +27,7 @@ > > #include "MessagePortIdentifier.h" > #include "SerializedScriptValue.h" >+#include "UserGestureIndicator.h" > #include <wtf/RefPtr.h> > > namespace WebCore { >@@ -38,6 +39,7 @@ typedef Vector<std::pair<WebCore::MessagePortIdentifier, WebCore::MessagePortIde > struct MessageWithMessagePorts { > RefPtr<SerializedScriptValue> message; > TransferredMessagePortArray transferredPorts; >+ RefPtr<UserGestureToken> userGestureToken; > > template<class Encoder> void encode(Encoder&) const; > template<class Decoder> static Optional<MessageWithMessagePorts> decode(Decoder&); >@@ -49,6 +51,9 @@ void MessageWithMessagePorts::encode(Encoder& encoder) const > { > ASSERT(message); > encoder << *message << transferredPorts; >+ encoder << !!userGestureToken; >+ if (userGestureToken) >+ encoder << *userGestureToken; > } > > template<class Decoder> >@@ -63,6 +68,16 @@ Optional<MessageWithMessagePorts> MessageWithMessagePorts::decode(Decoder& decod > if (!decoder.decode(result.transferredPorts)) > return WTF::nullopt; > >+ bool hasUserGestureToken; >+ if (!decoder.decode(hasUserGestureToken)) >+ return WTF::nullopt; >+ >+ if (hasUserGestureToken) { >+ result.userGestureToken = UserGestureToken::decode(decoder); >+ if (!result.userGestureToken) >+ return WTF::nullopt; >+ } >+ > return result; > } > >diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp >index 7197b118313..8ca5b836fc2 100644 >--- a/Source/WebCore/page/DOMWindow.cpp >+++ b/Source/WebCore/page/DOMWindow.cpp >@@ -157,7 +157,6 @@ public: > , m_source(source) > , m_targetOrigin(WTFMove(targetOrigin)) > , m_stackTrace(stackTrace) >- , m_userGestureToForward(UserGestureIndicator::currentUserGesture()) > { > } > >@@ -175,7 +174,7 @@ private: > // This object gets deleted when std::unique_ptr falls out of scope.. > std::unique_ptr<PostMessageTimer> timer(this); > >- UserGestureIndicator userGestureIndicator(m_userGestureToForward); >+ UserGestureIndicator userGestureIndicator(m_message.userGestureToken); > m_window->postMessageTimerFired(*timer); > } > >@@ -185,7 +184,6 @@ private: > RefPtr<WindowProxy> m_source; > RefPtr<SecurityOrigin> m_targetOrigin; > RefPtr<ScriptCallStack> m_stackTrace; >- RefPtr<UserGestureToken> m_userGestureToForward; > }; > > typedef HashCountedSet<DOMWindow*> DOMWindowSet; >@@ -891,7 +889,7 @@ ExceptionOr<void> DOMWindow::postMessage(JSC::ExecState& state, DOMWindow& incum > if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument)) > stackTrace = createScriptCallStack(JSExecState::currentState()); > >- MessageWithMessagePorts message { messageData.releaseReturnValue(), disentangledPorts.releaseReturnValue() }; >+ MessageWithMessagePorts message { messageData.releaseReturnValue(), disentangledPorts.releaseReturnValue(), UserGestureIndicator::currentUserGesture() }; > > // Schedule the message. > RefPtr<WindowProxy> incumbentWindowProxy = incumbentWindow.frame() ? &incumbentWindow.frame()->windowProxy() : nullptr; >diff --git a/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp b/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp >index e68616c6e8b..b7b5458d1fd 100644 >--- a/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp >+++ b/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp >@@ -77,7 +77,7 @@ ExceptionOr<void> DedicatedWorkerGlobalScope::postMessage(JSC::ExecState& state, > if (channels.hasException()) > return channels.releaseException(); > >- thread().workerObjectProxy().postMessageToWorkerObject({ message.releaseReturnValue(), channels.releaseReturnValue() }); >+ thread().workerObjectProxy().postMessageToWorkerObject({ message.releaseReturnValue(), channels.releaseReturnValue(), nullptr }); > return { }; > } > >diff --git a/Source/WebCore/workers/Worker.cpp b/Source/WebCore/workers/Worker.cpp >index ed25bff73ac..4174d00f917 100644 >--- a/Source/WebCore/workers/Worker.cpp >+++ b/Source/WebCore/workers/Worker.cpp >@@ -136,7 +136,7 @@ ExceptionOr<void> Worker::postMessage(JSC::ExecState& state, JSC::JSValue messag > if (channels.hasException()) > return channels.releaseException(); > >- m_contextProxy.postMessageToWorkerGlobalScope({ message.releaseReturnValue(), channels.releaseReturnValue() }); >+ m_contextProxy.postMessageToWorkerGlobalScope({ message.releaseReturnValue(), channels.releaseReturnValue(), nullptr }); > return { }; > } > >diff --git a/Source/WebCore/workers/service/ServiceWorker.cpp b/Source/WebCore/workers/service/ServiceWorker.cpp >index e52e49ef969..61ff81dd054 100644 >--- a/Source/WebCore/workers/service/ServiceWorker.cpp >+++ b/Source/WebCore/workers/service/ServiceWorker.cpp >@@ -121,7 +121,7 @@ ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JS > sourceIdentifier = ServiceWorkerClientIdentifier { connection.serverConnectionIdentifier(), downcast<Document>(context).identifier() }; > } > >- MessageWithMessagePorts message = { messageData.releaseReturnValue(), portsOrException.releaseReturnValue() }; >+ MessageWithMessagePorts message = { messageData.releaseReturnValue(), portsOrException.releaseReturnValue(), nullptr }; > callOnMainThread([sessionID = context.sessionID(), destinationIdentifier = identifier(), message = WTFMove(message), sourceIdentifier = WTFMove(sourceIdentifier)]() mutable { > auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(sessionID); > connection.postMessageToServiceWorker(destinationIdentifier, WTFMove(message), sourceIdentifier); >diff --git a/Source/WebCore/workers/service/ServiceWorkerClient.cpp b/Source/WebCore/workers/service/ServiceWorkerClient.cpp >index 7391c4c21a3..e0c45de1bd1 100644 >--- a/Source/WebCore/workers/service/ServiceWorkerClient.cpp >+++ b/Source/WebCore/workers/service/ServiceWorkerClient.cpp >@@ -97,7 +97,7 @@ ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& conte > if (portsOrException.hasException()) > return portsOrException.releaseException(); > >- MessageWithMessagePorts message = { messageData.releaseReturnValue(), portsOrException.releaseReturnValue() }; >+ MessageWithMessagePorts message = { messageData.releaseReturnValue(), portsOrException.releaseReturnValue(), nullptr }; > auto sourceIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier(); > callOnMainThread([message = WTFMove(message), destinationIdentifier = identifier(), sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable { > if (auto* connection = SWContextManager::singleton().connection()) >-- >2.20.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
fred.wang
:
review?
ews-watchlist
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 186593
:
342800
|
342918
|
343234
|
354837
|
363084
| 369470 |
369478