WebKit Bugzilla
Attachment 342918 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), 12.26 KB, created by
Frédéric Wang (:fredw)
on 2018-06-18 02:08:43 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Frédéric Wang (:fredw)
Created:
2018-06-18 02:08:43 PDT
Size:
12.26 KB
patch
obsolete
>From 044ae5b9f8c499b0edbdc1b1dd9473d67667bacd 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 | 3 +- > Source/WebCore/workers/Worker.cpp | 3 +- > .../WebCore/workers/service/ServiceWorker.cpp | 3 +- > .../workers/service/ServiceWorkerClient.cpp | 3 +- > 8 files changed, 78 insertions(+), 10 deletions(-) > >diff --git a/Source/WebCore/dom/MessagePort.cpp b/Source/WebCore/dom/MessagePort.cpp >index 6f7fd36be3d..97e03bfaa14 100644 >--- a/Source/WebCore/dom/MessagePort.cpp >+++ b/Source/WebCore/dom/MessagePort.cpp >@@ -33,6 +33,7 @@ > #include "MessageEvent.h" > #include "MessagePortChannelProvider.h" > #include "MessageWithMessagePorts.h" >+#include "UserGestureIndicator.h" > #include "WorkerGlobalScope.h" > #include "WorkerThread.h" > >@@ -157,7 +158,7 @@ ExceptionOr<void> MessagePort::postMessage(JSC::ExecState& state, JSC::JSValue m > transferredPorts = disentangleResult.releaseReturnValue(); > } > >- MessageWithMessagePorts message { messageData.releaseReturnValue(), WTFMove(transferredPorts) }; >+ MessageWithMessagePorts message { messageData.releaseReturnValue(), WTFMove(transferredPorts), 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..8289627609f 100644 >--- a/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp >+++ b/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp >@@ -37,6 +37,7 @@ > #include "DedicatedWorkerThread.h" > #include "MessageEvent.h" > #include "SecurityOrigin.h" >+#include "UserGestureIndicator.h" > #include "WorkerObjectProxy.h" > > namespace WebCore { >@@ -73,7 +74,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(), UserGestureIndicator::currentUserGesture() }); > return { }; > } > >diff --git a/Source/WebCore/workers/Worker.cpp b/Source/WebCore/workers/Worker.cpp >index 382447493ad..bebb93781a6 100644 >--- a/Source/WebCore/workers/Worker.cpp >+++ b/Source/WebCore/workers/Worker.cpp >@@ -35,6 +35,7 @@ > #include "PlatformStrategies.h" > #include "ResourceResponse.h" > #include "SecurityOrigin.h" >+#include "UserGestureIndicator.h" > #include "WorkerGlobalScopeProxy.h" > #include "WorkerScriptLoader.h" > #include "WorkerThread.h" >@@ -132,7 +133,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(), UserGestureIndicator::currentUserGesture() }); > return { }; > } > >diff --git a/Source/WebCore/workers/service/ServiceWorker.cpp b/Source/WebCore/workers/service/ServiceWorker.cpp >index 2d9decedd08..8cb568fba8d 100644 >--- a/Source/WebCore/workers/service/ServiceWorker.cpp >+++ b/Source/WebCore/workers/service/ServiceWorker.cpp >@@ -38,6 +38,7 @@ > #include "ServiceWorkerClientData.h" > #include "ServiceWorkerGlobalScope.h" > #include "ServiceWorkerProvider.h" >+#include "UserGestureIndicator.h" > #include <JavaScriptCore/JSCJSValueInlines.h> > #include <wtf/NeverDestroyed.h> > >@@ -124,7 +125,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(), UserGestureIndicator::currentUserGesture() }; > 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..91ba4e774a6 100644 >--- a/Source/WebCore/workers/service/ServiceWorkerClient.cpp >+++ b/Source/WebCore/workers/service/ServiceWorkerClient.cpp >@@ -35,6 +35,7 @@ > #include "ServiceWorkerGlobalScope.h" > #include "ServiceWorkerThread.h" > #include "ServiceWorkerWindowClient.h" >+#include "UserGestureIndicator.h" > > namespace WebCore { > >@@ -97,7 +98,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(), UserGestureIndicator::currentUserGesture() }; > 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