WebKit Bugzilla
Attachment 343234 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 (more restricted version)
0001-Bug-186593-User-gesture-context-is-not-passed-via-Me.patch (text/plain), 11.15 KB, created by
Frédéric Wang (:fredw)
on 2018-06-21 04:15:28 PDT
(
hide
)
Description:
Patch (more restricted version)
Filename:
MIME Type:
Creator:
Frédéric Wang (:fredw)
Created:
2018-06-21 04:15:28 PDT
Size:
11.15 KB
patch
obsolete
>From 3aaaaad415ba1bb40590b6ba26fdffb70d8e86ad Mon Sep 17 00:00:00 2001 >From: Frederic Wang <fwang@igalia.com> >Date: Mon, 18 Jun 2018 10:43:24 +0200 >Subject: [PATCH xserver] Bug 186593 - User gesture context is not passed via > MessageChannel > >--- > 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 +- > 8 files changed, 74 insertions(+), 10 deletions(-) > >diff --git a/Source/WebCore/dom/MessagePort.cpp b/Source/WebCore/dom/MessagePort.cpp >index 6f7fd36be3d..83b58224cdb 100644 >--- a/Source/WebCore/dom/MessagePort.cpp >+++ b/Source/WebCore/dom/MessagePort.cpp >@@ -157,7 +157,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()); > >@@ -272,6 +273,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 cf8e393b863..4e9a0eb5fdb 100644 >--- a/Source/WebCore/dom/UserGestureIndicator.h >+++ b/Source/WebCore/dom/UserGestureIndicator.h >@@ -63,6 +63,9 @@ public: > m_destructionObservers.append(WTFMove(observer)); > } > >+ template<class Encoder> void encode(Encoder&) const; >+ template<class Decoder> static RefPtr<UserGestureToken> decode(Decoder&); >+ > private: > UserGestureToken(ProcessingUserGestureState state, UserGestureType gestureType) > : m_state(state) >@@ -75,6 +78,26 @@ private: > UserGestureType m_gestureType; > }; > >+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_NONCOPYABLE(UserGestureIndicator); > public: >@@ -93,4 +116,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 8dedf4ed88f..eba0b4ebd8b 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 std::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 @@ std::optional<MessageWithMessagePorts> MessageWithMessagePorts::decode(Decoder& > if (!decoder.decode(result.transferredPorts)) > return std::nullopt; > >+ bool hasUserGestureToken; >+ if (!decoder.decode(hasUserGestureToken)) >+ return std::nullopt; >+ >+ if (hasUserGestureToken) { >+ result.userGestureToken = UserGestureToken::decode(decoder); >+ if (!result.userGestureToken) >+ return std::nullopt; >+ } >+ > return result; > } > >diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp >index ffb07b82322..545f6d25e81 100644 >--- a/Source/WebCore/page/DOMWindow.cpp >+++ b/Source/WebCore/page/DOMWindow.cpp >@@ -156,7 +156,6 @@ public: > , m_source(source) > , m_targetOrigin(WTFMove(targetOrigin)) > , m_stackTrace(stackTrace) >- , m_userGestureToForward(UserGestureIndicator::currentUserGesture()) > { > } > >@@ -174,7 +173,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); > } > >@@ -184,7 +183,6 @@ private: > RefPtr<WindowProxy> m_source; > RefPtr<SecurityOrigin> m_targetOrigin; > RefPtr<ScriptCallStack> m_stackTrace; >- RefPtr<UserGestureToken> m_userGestureToForward; > }; > > typedef HashCountedSet<DOMWindow*> DOMWindowSet; >@@ -958,7 +956,7 @@ ExceptionOr<void> DOMWindow::postMessage(JSC::ExecState& state, DOMWindow& incum > if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument)) > stackTrace = createScriptCallStack(JSMainThreadExecState::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 21ddedb3d03..409d3046c15 100644 >--- a/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp >+++ b/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp >@@ -73,7 +73,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 382447493ad..3da10742b47 100644 >--- a/Source/WebCore/workers/Worker.cpp >+++ b/Source/WebCore/workers/Worker.cpp >@@ -132,7 +132,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 2d9decedd08..78ef5a57f34 100644 >--- a/Source/WebCore/workers/service/ServiceWorker.cpp >+++ b/Source/WebCore/workers/service/ServiceWorker.cpp >@@ -124,7 +124,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.17.0 >
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
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 186593
:
342800
|
342918
|
343234
|
354837
|
363084
|
369470
|
369478