Diff
Modified: trunk/LayoutTests/ChangeLog (224112 => 224113)
--- trunk/LayoutTests/ChangeLog 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/LayoutTests/ChangeLog 2017-10-27 16:35:45 UTC (rev 224113)
@@ -1,3 +1,17 @@
+2017-10-27 Chris Dumez <[email protected]>
+
+ Add initial support for serviceWorkerClient.postMessage()
+ https://bugs.webkit.org/show_bug.cgi?id=178794
+
+ Reviewed by Youenn Fablet.
+
+ Add layout test coverage.
+
+ * http/tests/workers/service/basic-ServiceWorker-postMessage.https-expected.txt:
+ * http/tests/workers/service/resources/basic-ServiceWorker-postMessage-worker.js:
+ * http/tests/workers/service/resources/basic-ServiceWorker-postMessage.js:
+ (then):
+
2017-10-27 Ryan Haddad <[email protected]>
Skip failing service worker tests that were missed in r224066.
Modified: trunk/LayoutTests/http/tests/workers/service/basic-ServiceWorker-postMessage.https-expected.txt (224112 => 224113)
--- trunk/LayoutTests/http/tests/workers/service/basic-ServiceWorker-postMessage.https-expected.txt 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/LayoutTests/http/tests/workers/service/basic-ServiceWorker-postMessage.https-expected.txt 2017-10-27 16:35:45 UTC (rev 224113)
@@ -1,4 +1,5 @@
-PASS: Status code is 200
-PASS: Status text is Worker received the message event. messageEvent.origin was https://127.0.0.1:8443
-PASS: Source is Service worker
+PASS: Client received message from service worker, origin: https://127.0.0.1:8443
+PASS: Service worker received message 'Message 1' from origin 'https://127.0.0.1:8443'
+PASS: Client received message from service worker, origin: https://127.0.0.1:8443
+PASS: Service worker received message 'Message 2' from origin 'https://127.0.0.1:8443'
Modified: trunk/LayoutTests/http/tests/workers/service/resources/basic-ServiceWorker-postMessage-worker.js (224112 => 224113)
--- trunk/LayoutTests/http/tests/workers/service/resources/basic-ServiceWorker-postMessage-worker.js 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/LayoutTests/http/tests/workers/service/resources/basic-ServiceWorker-postMessage-worker.js 2017-10-27 16:35:45 UTC (rev 224113)
@@ -1,14 +1,4 @@
-let responseToSend = { status: 404, statusText: "Not Found" };
-
self.addEventListener("message", (event) => {
- responseToSend = event.data;
- responseToSend.statusText += " messageEvent.origin was " + event.origin;
+ event.source.postMessage("Service worker received message '" + event.data + "' from origin '" + event.origin + "'");
});
-self.addEventListener("fetch", (event) => {
- if (event.request.url.indexOf("test1") !== -1) {
- event.respondWith(new Response(null, responseToSend));
- return;
- }
- event.respondWith(Response.error());
-});
Modified: trunk/LayoutTests/http/tests/workers/service/resources/basic-ServiceWorker-postMessage.js (224112 => 224113)
--- trunk/LayoutTests/http/tests/workers/service/resources/basic-ServiceWorker-postMessage.js 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/LayoutTests/http/tests/workers/service/resources/basic-ServiceWorker-postMessage.js 2017-10-27 16:35:45 UTC (rev 224113)
@@ -1,37 +1,14 @@
-function done()
-{
- finishSWTest();
-}
+var messageNumber = 1;
+navigator.serviceWorker.addEventListener("message", function(event) {
+ log("PASS: Client received message from service worker, origin: " + event.origin);
+ log("PASS: " + event.data);
+ if (messageNumber == 1) {
+ event.source.postMessage("Message 2");
+ messageNumber++;
+ } else
+ finishSWTest();
+});
-async function test()
-{
- try {
- await navigator.serviceWorker.register("resources/basic-ServiceWorker-postMessage-worker.js", { });
-
- navigator.serviceWorker.controller.postMessage({ status: 200, statusText: "Worker received the message event." });
-
- let response = await fetch("test1");
- if (response.status == 200)
- log("PASS: Status code is " + response.status);
- else
- log("FAIL: Status code is " + response.status);
-
- if (response.statusText.startsWith("Worker received the message"))
- log("PASS: Status text is " + response.statusText);
- else
- log("FAIL: Status text is " + response.statusText);
-
- if (window.internals) {
- let source = internals.fetchResponseSource(response);
- if (source === "Service worker")
- log("PASS: Source is " + source);
- else
- log("FAIL: Source is " + source);
- }
- } catch(e) {
- log("Got exception: " + e);
- }
- finishSWTest();
-}
-
-test();
+navigator.serviceWorker.register("resources/basic-ServiceWorker-postMessage-worker.js", { }).then(function() {
+ navigator.serviceWorker.controller.postMessage("Message 1");
+});
Modified: trunk/Source/WebCore/ChangeLog (224112 => 224113)
--- trunk/Source/WebCore/ChangeLog 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/ChangeLog 2017-10-27 16:35:45 UTC (rev 224113)
@@ -1,3 +1,57 @@
+2017-10-27 Chris Dumez <[email protected]>
+
+ Add initial support for serviceWorkerClient.postMessage()
+ https://bugs.webkit.org/show_bug.cgi?id=178794
+
+ Reviewed by Youenn Fablet.
+
+ Add initial support for serviceWorkerClient.postMessage():
+ - https://w3c.github.io/ServiceWorker/#client-postmessage
+
+ It is now possible to do bi-directional communication with a service worker
+ via postMessage().
+
+ No new tests, updated existing test.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * dom/Document.cpp:
+ (WebCore::generateDocumentIdentifier):
+ (WebCore::Document::allDocumentsMap):
+ (WebCore::Document::allDocuments):
+ (WebCore::m_identifier):
+ (WebCore::Document::~Document):
+ * dom/Document.h:
+ (WebCore::Document::identifier const):
+ * dom/ScriptExecutionContext.cpp:
+ (WebCore::ScriptExecutionContext::serviceWorkerContainer):
+ * dom/ScriptExecutionContext.h:
+ * workers/service/ServiceWorker.cpp:
+ (WebCore::ServiceWorker::postMessage):
+ * workers/service/ServiceWorkerClient.cpp:
+ (WebCore::ServiceWorkerClient::ServiceWorkerClient):
+ (WebCore::ServiceWorkerClient::~ServiceWorkerClient):
+ (WebCore::ServiceWorkerClient::id const):
+ (WebCore::ServiceWorkerClient::postMessage):
+ * workers/service/ServiceWorkerClient.h:
+ (WebCore::ServiceWorkerClient::create):
+ * workers/service/ServiceWorkerClient.idl:
+ * workers/service/ServiceWorkerClientIdentifier.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.idl.
+ (WebCore::ServiceWorkerClientIdentifier::toString const):
+ * workers/service/ServiceWorkerRegistration.cpp:
+ (WebCore::ServiceWorkerRegistration::unregister):
+ * workers/service/ServiceWorkerWindowClient.cpp:
+ (WebCore::ServiceWorkerWindowClient::ServiceWorkerWindowClient):
+ * workers/service/ServiceWorkerWindowClient.h:
+ * workers/service/context/SWContextManager.cpp:
+ (WebCore::SWContextManager::postMessageToServiceWorkerGlobalScope):
+ * workers/service/context/SWContextManager.h:
+ * workers/service/context/ServiceWorkerThread.cpp:
+ (WebCore::ServiceWorkerThread::postMessageToServiceWorkerGlobalScope):
+ * workers/service/context/ServiceWorkerThread.h:
+ * workers/service/server/SWClientConnection.cpp:
+ (WebCore::SWClientConnection::postMessageToServiceWorkerClient):
+ * workers/service/server/SWClientConnection.h:
+
2017-10-27 Frederic Wang <[email protected]>
Use auto for some variables in RenderLayerCompositor/Backing
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (224112 => 224113)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-10-27 16:35:45 UTC (rev 224113)
@@ -2243,6 +2243,7 @@
837964CF1F8DB69D00218EA0 /* GeolocationPositionIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 837964CE1F8DB69A00218EA0 /* GeolocationPositionIOS.mm */; };
837A80131E1E127300026B9F /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 837A80111E1E127300026B9F /* Localizable.stringsdict */; };
837B7D201DC3F55000D051FC /* ValidationBubbleIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */; };
+ 837D46271FA2A8CE0054E1FA /* ServiceWorkerClientIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 837D46251FA2A8C50054E1FA /* ServiceWorkerClientIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
837FB3451F9EA06D00D0FC31 /* ExtendableMessageEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 837FB3401F9EA06600D0FC31 /* ExtendableMessageEvent.h */; };
8386A96D19F61B2E00E1EC4A /* StyleBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8386A96C19F61B2E00E1EC4A /* StyleBuilder.h */; };
838867351D13BA5F003697D0 /* RenderObjectEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 838867341D13BA59003697D0 /* RenderObjectEnums.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9521,6 +9522,7 @@
837964CE1F8DB69A00218EA0 /* GeolocationPositionIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = GeolocationPositionIOS.mm; path = Modules/geolocation/ios/GeolocationPositionIOS.mm; sourceTree = SOURCE_ROOT; };
837A80121E1E127300026B9F /* English */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = English; path = English.lproj/Localizable.stringsdict; sourceTree = SOURCE_ROOT; };
837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ValidationBubbleIOS.mm; sourceTree = "<group>"; };
+ 837D46251FA2A8C50054E1FA /* ServiceWorkerClientIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerClientIdentifier.h; sourceTree = "<group>"; };
837DFB341EBFEA7000601385 /* ElementCSSInlineStyle.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ElementCSSInlineStyle.idl; sourceTree = "<group>"; };
837FB3401F9EA06600D0FC31 /* ExtendableMessageEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtendableMessageEvent.h; sourceTree = "<group>"; };
837FB3421F9EA06700D0FC31 /* ExtendableMessageEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendableMessageEvent.cpp; sourceTree = "<group>"; };
@@ -17313,6 +17315,7 @@
46EF14271F97B7BA00C2A524 /* ServiceWorkerClient.cpp */,
46EF14241F97B7BA00C2A524 /* ServiceWorkerClient.h */,
46EF14281F97B7BA00C2A524 /* ServiceWorkerClient.idl */,
+ 837D46251FA2A8C50054E1FA /* ServiceWorkerClientIdentifier.h */,
46EF14211F97B7BA00C2A524 /* ServiceWorkerClients.cpp */,
46EF14221F97B7BA00C2A524 /* ServiceWorkerClients.h */,
46EF14231F97B7BA00C2A524 /* ServiceWorkerClients.idl */,
@@ -28880,6 +28883,7 @@
2D93AEE319DF5641002A86C3 /* ServicesOverlayController.h in Headers */,
51F1755D1F3EBC8300C74950 /* ServiceWorker.h in Headers */,
46EF142D1F97B7D800C2A524 /* ServiceWorkerClient.h in Headers */,
+ 837D46271FA2A8CE0054E1FA /* ServiceWorkerClientIdentifier.h in Headers */,
46EF142C1F97B7D800C2A524 /* ServiceWorkerClients.h in Headers */,
8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */,
51F1755F1F3EBC8300C74950 /* ServiceWorkerContainer.h in Headers */,
Modified: trunk/Source/WebCore/dom/Document.cpp (224112 => 224113)
--- trunk/Source/WebCore/dom/Document.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/dom/Document.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -434,12 +434,23 @@
uint64_t Document::s_globalTreeVersion = 0;
-HashSet<Document*>& Document::allDocuments()
+static uint64_t generateDocumentIdentifier()
{
- static NeverDestroyed<HashSet<Document*>> documents;
+ static uint64_t identifier = 0;
+ return ++identifier;
+}
+
+auto Document::allDocumentsMap() -> DocumentsMap&
+{
+ static NeverDestroyed<DocumentsMap> documents;
return documents;
}
+auto Document::allDocuments() -> DocumentsMap::ValuesIteratorRange
+{
+ return allDocumentsMap().values();
+}
+
static inline int currentOrientation(Frame* frame)
{
#if ENABLE(ORIENTATION_EVENTS)
@@ -496,8 +507,10 @@
, m_isSynthesized(constructionFlags & Synthesized)
, m_isNonRenderedPlaceholder(constructionFlags & NonRenderedPlaceholder)
, m_orientationNotifier(currentOrientation(frame))
+ , m_identifier(generateDocumentIdentifier())
{
- allDocuments().add(this);
+ auto addResult = allDocumentsMap().add(m_identifier, this);
+ ASSERT_UNUSED(addResult, addResult.isNewEntry);
// We depend on the url getting immediately set in subframes, but we
// also depend on the url NOT getting immediately set in opened windows.
@@ -547,7 +560,8 @@
Document::~Document()
{
- allDocuments().remove(this);
+ bool wasRemoved = allDocumentsMap().remove(m_identifier);
+ ASSERT_UNUSED(wasRemoved, wasRemoved);
ASSERT(!renderView());
ASSERT(m_pageCacheState != InPageCache);
Modified: trunk/Source/WebCore/dom/Document.h (224112 => 224113)
--- trunk/Source/WebCore/dom/Document.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/dom/Document.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -347,8 +347,12 @@
void removedLastRef();
- WEBCORE_EXPORT static HashSet<Document*>& allDocuments();
+ uint64_t identifier() const { return m_identifier; }
+ using DocumentsMap = HashMap<uint64_t, Document*>;
+ WEBCORE_EXPORT static DocumentsMap::ValuesIteratorRange allDocuments();
+ WEBCORE_EXPORT static DocumentsMap& allDocumentsMap();
+
MediaQueryMatcher& mediaQueryMatcher();
using ContainerNode::ref;
@@ -1835,6 +1839,7 @@
bool m_grantStorageAccessOverride { false };
RefPtr<DocumentTimeline> m_timeline;
+ uint64_t m_identifier;
};
Element* eventTargetElementForDocument(Document*);
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (224112 => 224113)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -38,6 +38,7 @@
#include "JSDOMExceptionHandling.h"
#include "JSDOMWindow.h"
#include "MessagePort.h"
+#include "Navigator.h"
#include "NoEventDispatchAssertion.h"
#include "PublicURLManager.h"
#include "RejectedPromiseTracker.h"
@@ -45,6 +46,7 @@
#include "ScriptState.h"
#include "Settings.h"
#include "WorkerGlobalScope.h"
+#include "WorkerNavigator.h"
#include "WorkerThread.h"
#include <heap/StrongInlines.h>
#include <inspector/ScriptCallStack.h>
@@ -525,4 +527,18 @@
return execStateFromWorkerGlobalScope(workerGlobalScope);
}
+#if ENABLE(SERVICE_WORKER)
+ServiceWorkerContainer* ScriptExecutionContext::serviceWorkerContainer()
+{
+ NavigatorBase* navigator = nullptr;
+ if (is<Document>(*this)) {
+ if (auto* window = downcast<Document>(*this).domWindow())
+ navigator = window->navigator();
+ } else
+ navigator = &downcast<WorkerGlobalScope>(*this).navigator();
+
+ return navigator ? navigator->serviceWorker() : nullptr;
+}
+#endif
+
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (224112 => 224113)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -68,6 +68,10 @@
class SocketProvider;
class URL;
+#if ENABLE(SERVICE_WORKER)
+class ServiceWorkerContainer;
+#endif
+
namespace IDBClient {
class IDBConnectionProxy;
}
@@ -234,6 +238,8 @@
#if ENABLE(SERVICE_WORKER)
uint64_t selectedServiceWorkerIdentifier() const { return m_serviceWorkerIdentifier; }
void setSelectedServiceWorkerIdentifier(uint64_t identifier) { m_serviceWorkerIdentifier = identifier; }
+
+ ServiceWorkerContainer* serviceWorkerContainer();
#endif
protected:
Modified: trunk/Source/WebCore/workers/service/ServiceWorker.cpp (224112 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -69,7 +69,7 @@
return Exception { NotSupportedError, ASCIILiteral("Passing MessagePort objects to postMessage is not yet supported") };
auto& swConnection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context.sessionID());
- swConnection.postMessageToServiceWorkerGlobalScope(m_identifier, message.releaseReturnValue(), context.origin());
+ swConnection.postMessageToServiceWorkerGlobalScope(m_identifier, message.releaseReturnValue(), context);
return { };
}
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp (224112 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -28,14 +28,26 @@
#if ENABLE(SERVICE_WORKER)
#include "ServiceWorkerClient.h"
+#include "MessagePort.h"
+#include "SWContextManager.h"
+#include "ScriptExecutionContext.h"
+#include "SerializedScriptValue.h"
+#include "ServiceWorkerGlobalScope.h"
+#include "ServiceWorkerThread.h"
+
namespace WebCore {
-ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context, Type type)
+ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context, const Identifier& identifier, Type type)
: ContextDestructionObserver(&context)
+ , m_identifier(identifier)
, m_type(type)
{
}
+ServiceWorkerClient::~ServiceWorkerClient()
+{
+}
+
String ServiceWorkerClient::url() const
{
return { };
@@ -48,14 +60,36 @@
String ServiceWorkerClient::id() const
{
- return { };
+ return m_identifier.toString();
}
-ExceptionOr<void> ServiceWorkerClient::postMessage(JSC::ExecState&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
+ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
{
- UNUSED_PARAM(message);
- UNUSED_PARAM(transfer);
- return Exception { NotSupportedError, ASCIILiteral("client.postMessage() is not yet supported") };
+ auto* execState = context.execState();
+ ASSERT(execState);
+
+ Vector<RefPtr<MessagePort>> ports;
+ auto message = SerializedScriptValue::create(*execState, messageValue, WTFMove(transfer), ports, SerializationContext::WorkerPostMessage);
+ if (message.hasException())
+ return message.releaseException();
+
+ // Disentangle the port in preparation for sending it to the remote context.
+ auto channelsOrException = MessagePort::disentanglePorts(WTFMove(ports));
+ if (channelsOrException.hasException())
+ return channelsOrException.releaseException();
+
+ // FIXME: Support sending the channels.
+ auto channels = channelsOrException.releaseReturnValue();
+ if (channels && !channels->isEmpty())
+ return Exception { NotSupportedError, ASCIILiteral("Passing MessagePort objects to postMessage is not yet supported") };
+
+ uint64_t sourceIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier();
+ callOnMainThread([message = message.releaseReturnValue(), destinationIdentifier = m_identifier, sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
+ if (auto* connection = SWContextManager::singleton().connection())
+ connection->postMessageToServiceWorkerClient(destinationIdentifier, WTFMove(message), sourceIdentifier, sourceOrigin);
+ });
+
+ return { };
}
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.h (224112 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -29,12 +29,12 @@
#include "ContextDestructionObserver.h"
#include "ExceptionOr.h"
+#include "ServiceWorkerClientIdentifier.h"
#include "ServiceWorkerClientType.h"
#include <heap/Strong.h>
#include <wtf/RefCounted.h>
namespace JSC {
-class ExecState;
class JSValue;
}
@@ -42,6 +42,8 @@
class ServiceWorkerClient : public RefCounted<ServiceWorkerClient>, public ContextDestructionObserver {
public:
+ using Identifier = ServiceWorkerClientIdentifier;
+
using Type = ServiceWorkerClientType;
enum class FrameType {
Auxiliary,
@@ -50,21 +52,24 @@
None
};
- static Ref<ServiceWorkerClient> create(ScriptExecutionContext& context, Type type)
+ static Ref<ServiceWorkerClient> create(ScriptExecutionContext& context, const Identifier& identifier, Type type)
{
- return adoptRef(*new ServiceWorkerClient(context, type));
+ return adoptRef(*new ServiceWorkerClient(context, identifier, type));
}
+ ~ServiceWorkerClient();
+
String url() const;
FrameType frameType() const;
Type type() const { return m_type; }
String id() const;
- ExceptionOr<void> postMessage(JSC::ExecState&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&& transfer);
+ ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&& transfer);
protected:
- ServiceWorkerClient(ScriptExecutionContext&, Type);
+ ServiceWorkerClient(ScriptExecutionContext&, const Identifier&, Type);
+ Identifier m_identifier;
Type m_type;
};
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl (224112 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl 2017-10-27 16:35:45 UTC (rev 224113)
@@ -35,7 +35,7 @@
readonly attribute ServiceWorkerClientType type;
readonly attribute DOMString id;
- [CallWith=ScriptState, MayThrowException] void postMessage(any message, optional sequence<object> transfer = []);
+ [CallWith=ScriptExecutionContext, MayThrowException] void postMessage(any message, optional sequence<object> transfer = []);
};
enum FrameType {
Copied: trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h (from rev 224112, trunk/Source/WebCore/workers/service/ServiceWorkerClient.idl) (0 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct ServiceWorkerClientIdentifier {
+ uint64_t serverConnectionIdentifier;
+ uint64_t scriptExecutionContextIdentifier;
+
+ String toString() const { return String::number(serverConnectionIdentifier) + "-" + String::number(scriptExecutionContextIdentifier); }
+};
+
+}
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (224112 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -29,25 +29,11 @@
#if ENABLE(SERVICE_WORKER)
#include "DOMWindow.h"
#include "Document.h"
-#include "Navigator.h"
#include "ServiceWorkerContainer.h"
#include "WorkerGlobalScope.h"
-#include "WorkerNavigator.h"
namespace WebCore {
-static ServiceWorkerContainer* containerForScriptExecutionContext(ScriptExecutionContext& context)
-{
- NavigatorBase* navigator = nullptr;
- if (is<Document>(context)) {
- if (auto* window = downcast<Document>(context).domWindow())
- navigator = window->navigator();
- } else
- navigator = &downcast<WorkerGlobalScope>(context).navigator();
-
- return navigator ? navigator->serviceWorker() : nullptr;
-}
-
ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, ServiceWorkerRegistrationData&& registrationData)
: ActiveDOMObject(&context)
, m_registrationData(WTFMove(registrationData))
@@ -94,7 +80,7 @@
return;
}
- auto* container = containerForScriptExecutionContext(*context);
+ auto* container = context->serviceWorkerContainer();
if (!container) {
promise->reject(Exception(InvalidStateError));
return;
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp (224112 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -32,8 +32,8 @@
namespace WebCore {
-ServiceWorkerWindowClient::ServiceWorkerWindowClient(ScriptExecutionContext& context)
- : ServiceWorkerClient(context, Type::Window)
+ServiceWorkerWindowClient::ServiceWorkerWindowClient(ScriptExecutionContext& context, const Identifier& identifier)
+ : ServiceWorkerClient(context, identifier, Type::Window)
{
}
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.h (224112 => 224113)
--- trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerWindowClient.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -36,9 +36,9 @@
class ServiceWorkerWindowClient final : public ServiceWorkerClient {
public:
- static Ref<ServiceWorkerWindowClient> create(ScriptExecutionContext& context)
+ static Ref<ServiceWorkerWindowClient> create(ScriptExecutionContext& context, const Identifier& identifier)
{
- return adoptRef(*new ServiceWorkerWindowClient(context));
+ return adoptRef(*new ServiceWorkerWindowClient(context, identifier));
}
VisibilityState visibilityState() const;
@@ -48,7 +48,7 @@
void navigate(const String& url, Ref<DeferredPromise>&&);
private:
- explicit ServiceWorkerWindowClient(ScriptExecutionContext&);
+ ServiceWorkerWindowClient(ScriptExecutionContext&, const Identifier&);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.cpp (224112 => 224113)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -59,14 +59,14 @@
return m_workerMap.get(serviceWorkerIdentifier);
}
-void SWContextManager::postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, Ref<SerializedScriptValue>&& message, const String& sourceOrigin)
+void SWContextManager::postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
{
- auto* serviceWorker = m_workerMap.get(serviceWorkerIdentifier);
+ auto* serviceWorker = m_workerMap.get(destinationServiceWorkerIdentifier);
if (!serviceWorker)
return;
// FIXME: We should pass valid MessagePortChannels.
- serviceWorker->thread().postMessageToServiceWorkerGlobalScope(WTFMove(message), nullptr, sourceOrigin);
+ serviceWorker->thread().postMessageToServiceWorkerGlobalScope(WTFMove(message), nullptr, sourceIdentifier, sourceOrigin);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (224112 => 224113)
--- trunk/Source/WebCore/workers/service/context/SWContextManager.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -34,6 +34,7 @@
namespace WebCore {
class SerializedScriptValue;
+struct ServiceWorkerClientIdentifier;
class SWContextManager {
public:
@@ -42,6 +43,8 @@
class Connection {
public:
virtual ~Connection() { }
+
+ virtual void postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, Ref<SerializedScriptValue>&& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin) = 0;
};
WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
@@ -49,7 +52,7 @@
WEBCORE_EXPORT void registerServiceWorkerThread(Ref<ServiceWorkerThreadProxy>&&);
WEBCORE_EXPORT ServiceWorkerThreadProxy* serviceWorkerThreadProxy(uint64_t) const;
- WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, Ref<SerializedScriptValue>&& message, const String& sourceOrigin);
+ WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
private:
SWContextManager() = default;
Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (224112 => 224113)
--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -34,6 +34,7 @@
#include "SecurityOrigin.h"
#include "ServiceWorkerFetch.h"
#include "ServiceWorkerGlobalScope.h"
+#include "ServiceWorkerWindowClient.h"
#include "WorkerLoaderProxy.h"
#include "WorkerObjectProxy.h"
#include <pal/SessionID.h>
@@ -99,12 +100,13 @@
}, WorkerRunLoop::defaultMode());
}
-void ServiceWorkerThread::postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray>&& channels, const String& sourceOrigin)
+void ServiceWorkerThread::postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray>&& channels, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
{
- ScriptExecutionContext::Task task([channels = WTFMove(channels), message = WTFMove(message), sourceOrigin = sourceOrigin.isolatedCopy()] (ScriptExecutionContext& context) mutable {
+ ScriptExecutionContext::Task task([channels = WTFMove(channels), message = WTFMove(message), sourceIdentifier, sourceOrigin = sourceOrigin.isolatedCopy()] (ScriptExecutionContext& context) mutable {
auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
auto ports = MessagePort::entanglePorts(serviceWorkerGlobalScope, WTFMove(channels));
- serviceWorkerGlobalScope.dispatchEvent(ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin));
+ ExtendableMessageEventSource source = RefPtr<ServiceWorkerClient> { ServiceWorkerWindowClient::create(context, sourceIdentifier) };
+ serviceWorkerGlobalScope.dispatchEvent(ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin, { }, WTFMove(source)));
serviceWorkerGlobalScope.thread().workerObjectProxy().confirmMessageFromWorkerObject(serviceWorkerGlobalScope.hasPendingActivity());
});
runLoop().postTask(WTFMove(task));
Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h (224112 => 224113)
--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -40,6 +40,7 @@
class SerializedScriptValue;
class WorkerLoaderProxy;
class WorkerObjectProxy;
+struct ServiceWorkerClientIdentifier;
struct ServiceWorkerContextData;
using MessagePortChannelArray = Vector<std::unique_ptr<MessagePortChannel>, 1>;
@@ -55,7 +56,7 @@
WorkerObjectProxy& workerObjectProxy() const { return m_workerObjectProxy; }
WEBCORE_EXPORT void postFetchTask(Ref<ServiceWorkerFetch::Client>&&, ResourceRequest&&, FetchOptions&&);
- WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, const String& sourceOrigin);
+ WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
protected:
Ref<WorkerGlobalScope> createWorkerGlobalScope(const URL&, const String& identifier, const String& userAgent, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, PAL::SessionID) final;
Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp (224112 => 224113)
--- trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -28,7 +28,10 @@
#if ENABLE(SERVICE_WORKER)
+#include "Document.h"
#include "ExceptionData.h"
+#include "MessageEvent.h"
+#include "ServiceWorkerContainer.h"
#include "ServiceWorkerFetchResult.h"
#include "ServiceWorkerJobData.h"
@@ -109,6 +112,29 @@
job->startScriptFetch();
}
+void SWClientConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, Ref<SerializedScriptValue>&& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin)
+{
+ // FIXME: destinationScriptExecutionContextIdentifier can only identify a Document at the moment.
+ auto* destinationDocument = Document::allDocumentsMap().get(destinationScriptExecutionContextIdentifier);
+ if (!destinationDocument)
+ return;
+
+ auto* container = destinationDocument->serviceWorkerContainer();
+ if (!container)
+ return;
+
+ std::optional<MessageEventSource> source;
+ if (destinationDocument->selectedServiceWorkerIdentifier() == sourceServiceWorkerIdentifier) {
+ ASSERT(container->controller()->identifier() == sourceServiceWorkerIdentifier);
+ source = MessageEventSource { RefPtr<ServiceWorker> { container->controller() } };
+ } else
+ source = MessageEventSource { RefPtr<ServiceWorker> { ServiceWorker::create(*destinationDocument, sourceServiceWorkerIdentifier) } };
+
+ // FIXME: We should pass in ports.
+ auto messageEvent = MessageEvent::create({ }, WTFMove(message), sourceOrigin, { }, WTFMove(source));
+ container->dispatchEvent(messageEvent);
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.h (224112 => 224113)
--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -49,7 +49,7 @@
void scheduleJob(ServiceWorkerJob&);
void finishedFetchingScript(ServiceWorkerJob&, const String&);
void failedFetchingScript(ServiceWorkerJob&, const ResourceError&);
- virtual void postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, Ref<SerializedScriptValue>&&, const String& sourceOrigin) = 0;
+ virtual void postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, Ref<SerializedScriptValue>&&, ScriptExecutionContext& source) = 0;
virtual uint64_t identifier() const = 0;
virtual bool hasServiceWorkerRegisteredForOrigin(const SecurityOrigin&) const = 0;
@@ -59,6 +59,7 @@
WEBCORE_EXPORT void registrationJobResolvedInServer(uint64_t jobIdentifier, ServiceWorkerRegistrationData&&);
WEBCORE_EXPORT void unregistrationJobResolvedInServer(uint64_t jobIdentifier, bool unregistrationResult);
WEBCORE_EXPORT void startScriptFetchForServer(uint64_t jobIdentifier);
+ WEBCORE_EXPORT void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, Ref<SerializedScriptValue>&& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin);
private:
virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0;
Modified: trunk/Source/WebKit/ChangeLog (224112 => 224113)
--- trunk/Source/WebKit/ChangeLog 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/ChangeLog 2017-10-27 16:35:45 UTC (rev 224113)
@@ -1,3 +1,40 @@
+2017-10-27 Chris Dumez <[email protected]>
+
+ Add initial support for serviceWorkerClient.postMessage()
+ https://bugs.webkit.org/show_bug.cgi?id=178794
+
+ Reviewed by Youenn Fablet.
+
+ Add initial support for serviceWorkerClient.postMessage():
+ - https://w3c.github.io/ServiceWorker/#client-postmessage
+
+ It is now possible to do bi-directional communication with a service worker
+ via postMessage().
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::ArgumentCoder<ServiceWorkerClientIdentifier>::encode):
+ (IPC::ArgumentCoder<ServiceWorkerClientIdentifier>::decode):
+ * Shared/WebCoreArgumentCoders.h:
+ * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+ (WebKit::WebSWServerConnection::postMessageToServiceWorkerGlobalScope):
+ (WebKit::WebSWServerConnection::postMessageToServiceWorkerClient):
+ * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+ * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
+ * StorageProcess/StorageProcess.cpp:
+ (WebKit::StorageProcess::postMessageToServiceWorkerClient):
+ * StorageProcess/StorageProcess.h:
+ * StorageProcess/StorageProcess.messages.in:
+ * WebProcess/Storage/WebSWClientConnection.cpp:
+ (WebKit::WebSWClientConnection::postMessageToServiceWorkerGlobalScope):
+ (WebKit::WebSWClientConnection::postMessageToServiceWorkerClient):
+ * WebProcess/Storage/WebSWClientConnection.h:
+ * WebProcess/Storage/WebSWClientConnection.messages.in:
+ * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+ (WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope):
+ (WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerClient):
+ * WebProcess/Storage/WebSWContextManagerConnection.h:
+ * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
2017-10-27 David Kilzer <[email protected]>
REGRESSION (r224077): DeprecatedGlobalSettings::setAVKitEnabled() not protected by HAVE(AVKIT)
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (224112 => 224113)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -65,6 +65,7 @@
#include <WebCore/ScrollingConstraints.h>
#include <WebCore/ScrollingCoordinator.h>
#include <WebCore/SearchPopupMenu.h>
+#include <WebCore/ServiceWorkerClientIdentifier.h>
#include <WebCore/TextCheckerClient.h>
#include <WebCore/TextIndicator.h>
#include <WebCore/TimingFunction.h>
@@ -1901,6 +1902,27 @@
return true;
}
+#if ENABLE(SERVICE_WORKER)
+void ArgumentCoder<ServiceWorkerClientIdentifier>::encode(Encoder& encoder, const ServiceWorkerClientIdentifier& identifier)
+{
+ encoder << identifier.serverConnectionIdentifier << identifier.scriptExecutionContextIdentifier;
+}
+
+bool ArgumentCoder<ServiceWorkerClientIdentifier>::decode(Decoder& decoder, ServiceWorkerClientIdentifier& identifier)
+{
+ uint64_t serverConnectionIdentifier;
+ if (!decoder.decode(serverConnectionIdentifier))
+ return false;
+
+ uint64_t scriptExecutionContextIdentifier;
+ if (!decoder.decode(scriptExecutionContextIdentifier))
+ return false;
+
+ identifier = { serverConnectionIdentifier, scriptExecutionContextIdentifier };
+ return true;
+}
+#endif
+
void ArgumentCoder<TextCheckingResult>::encode(Encoder& encoder, const TextCheckingResult& result)
{
encoder.encodeEnum(result.type);
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (224112 => 224113)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -157,6 +157,10 @@
#if ENABLE(INDEXED_DATABASE)
using IDBKeyPath = Variant<String, Vector<String>>;
#endif
+
+#if ENABLE(SERVICE_WORKER)
+struct ServiceWorkerClientIdentifier;
+#endif
}
namespace IPC {
@@ -477,6 +481,13 @@
static bool decode(Decoder&, WebCore::TextCheckingRequestData&);
};
+#if ENABLE(SERVICE_WORKER)
+template<> struct ArgumentCoder<WebCore::ServiceWorkerClientIdentifier> {
+ static void encode(Encoder&, const WebCore::ServiceWorkerClientIdentifier&);
+ static bool decode(Decoder&, WebCore::ServiceWorkerClientIdentifier&);
+};
+#endif
+
template<> struct ArgumentCoder<WebCore::TextCheckingResult> {
static void encode(Encoder&, const WebCore::TextCheckingResult&);
static std::optional<WebCore::TextCheckingResult> decode(Decoder&);
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224112 => 224113)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -44,6 +44,7 @@
#include <WebCore/ExceptionData.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/SecurityOrigin.h>
+#include <WebCore/ServiceWorkerClientIdentifier.h>
#include <WebCore/ServiceWorkerContextData.h>
#include <WebCore/ServiceWorkerJobData.h>
#include <WebCore/ServiceWorkerRegistrationData.h>
@@ -108,9 +109,10 @@
sendToContextProcess(Messages::WebSWContextManagerConnection::StartFetch(identifier(), fetchIdentifier, serviceWorkerIdentifier, request, options));
}
-void WebSWServerConnection::postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin)
+void WebSWServerConnection::postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin)
{
- sendToContextProcess(Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerGlobalScope(serviceWorkerIdentifier, message, sourceOrigin));
+ ServiceWorkerClientIdentifier sourceIdentifier { identifier(), sourceScriptExecutionContextIdentifier };
+ sendToContextProcess(Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerGlobalScope { destinationServiceWorkerIdentifier, message, sourceIdentifier, sourceOrigin });
}
void WebSWServerConnection::didReceiveFetchResponse(uint64_t fetchIdentifier, const ResourceResponse& response)
@@ -138,6 +140,11 @@
m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidNotHandle { }, fetchIdentifier);
}
+void WebSWServerConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin)
+{
+ send(Messages::WebSWClientConnection::PostMessageToServiceWorkerClient { destinationScriptExecutionContextIdentifier, message, sourceServiceWorkerIdentifier, sourceOrigin });
+}
+
template<typename U> bool WebSWServerConnection::sendToContextProcess(U&& message)
{
if (!m_contextConnection)
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (224112 => 224113)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -57,6 +57,8 @@
void didFailFetch(uint64_t fetchIdentifier);
void didNotHandleFetch(uint64_t fetchIdentifier);
+ void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin);
+
private:
// Implement SWServer::Connection (Messages to the client WebProcess)
void rejectJobInClient(uint64_t jobIdentifier, const WebCore::ExceptionData&) final;
@@ -66,7 +68,7 @@
void startFetch(uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&);
- void postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin);
+ void postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin);
// Messages to the SW context WebProcess
void startServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in (224112 => 224113)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in 2017-10-27 16:35:45 UTC (rev 224113)
@@ -28,7 +28,7 @@
FinishFetchingScriptInServer(struct WebCore::ServiceWorkerFetchResult result)
StartFetch(uint64_t identifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
- PostMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, IPC::DataReference message, String sourceOrigin)
+ PostMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, IPC::DataReference message, uint64_t sourceScriptExecutionContextIdentifier, String sourceOrigin)
}
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.cpp (224112 => 224113)
--- trunk/Source/WebKit/StorageProcess/StorageProcess.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -38,6 +38,7 @@
#include <WebCore/IDBKeyData.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/SecurityOrigin.h>
+#include <WebCore/ServiceWorkerClientIdentifier.h>
#include <WebCore/TextEncoding.h>
#include <pal/SessionID.h>
#include <wtf/CrossThreadTask.h>
@@ -435,6 +436,12 @@
connection->didFinishFetch(fetchIdentifier);
}
+void StorageProcess::postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, const IPC::DataReference& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin)
+{
+ if (auto* connection = m_swServerConnections.get(destinationIdentifier.serverConnectionIdentifier))
+ connection->postMessageToServiceWorkerClient(destinationIdentifier.scriptExecutionContextIdentifier, message, sourceServiceWorkerIdentifier, sourceOrigin);
+}
+
void StorageProcess::registerSWServerConnection(WebSWServerConnection& connection)
{
ASSERT(!m_swServerConnections.contains(connection.identifier()));
Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.h (224112 => 224113)
--- trunk/Source/WebKit/StorageProcess/StorageProcess.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -37,6 +37,7 @@
namespace WebCore {
class SWServer;
struct SecurityOriginData;
+struct ServiceWorkerClientIdentifier;
struct ServiceWorkerRegistrationKey;
}
@@ -125,6 +126,8 @@
void didFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
void didFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
void didNotHandleFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
+
+ void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, const IPC::DataReference& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin);
#endif
#if ENABLE(INDEXED_DATABASE)
Vector<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.messages.in (224112 => 224113)
--- trunk/Source/WebKit/StorageProcess/StorageProcess.messages.in 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.messages.in 2017-10-27 16:35:45 UTC (rev 224113)
@@ -46,5 +46,6 @@
DidReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, WebCore::ResourceResponse response)
DidReceiveFetchData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, IPC::DataReference data, int64_t encodedDataLength)
DidFinishFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
+ PostMessageToServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier destinationIdentifier, IPC::DataReference message, uint64_t sourceServiceWorkerIdentifier, String sourceOrigin)
#endif
}
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224112 => 224113)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -35,6 +35,7 @@
#include "WebCoreArgumentCoders.h"
#include "WebSWOriginTable.h"
#include "WebSWServerConnectionMessages.h"
+#include <WebCore/Document.h>
#include <WebCore/SerializedScriptValue.h>
#include <WebCore/ServiceWorkerFetchResult.h>
#include <WebCore/ServiceWorkerJobData.h>
@@ -68,9 +69,13 @@
send(Messages::WebSWServerConnection::FinishFetchingScriptInServer(result));
}
-void WebSWClientConnection::postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, Ref<SerializedScriptValue>&& scriptValue, const String& sourceOrigin)
+void WebSWClientConnection::postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, Ref<SerializedScriptValue>&& scriptValue, ScriptExecutionContext& source)
{
- send(Messages::WebSWServerConnection::PostMessageToServiceWorkerGlobalScope(serviceWorkerIdentifier, IPC::DataReference { scriptValue->data() }, sourceOrigin));
+ // FIXME: Add support for posting messages from workers.
+ if (!is<Document>(source))
+ return;
+
+ send(Messages::WebSWServerConnection::PostMessageToServiceWorkerGlobalScope(destinationServiceWorkerIdentifier, IPC::DataReference { scriptValue->data() }, downcast<Document>(source).identifier(), source.origin()));
}
bool WebSWClientConnection::hasServiceWorkerRegisteredForOrigin(const SecurityOrigin& origin) const
@@ -92,6 +97,11 @@
return ServiceWorkerClientFetch::create(provider, WTFMove(loader), identifier, m_connection.get(), WTFMove(callback));
}
+void WebSWClientConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin)
+{
+ SWClientConnection::postMessageToServiceWorkerClient(destinationScriptExecutionContextIdentifier, SerializedScriptValue::adopt(message.vector()), sourceServiceWorkerIdentifier, sourceOrigin);
+}
+
} // namespace WebKit
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (224112 => 224113)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -56,7 +56,7 @@
void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
- void postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, Ref<WebCore::SerializedScriptValue>&&, const String& sourceOrigin) final;
+ void postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, Ref<WebCore::SerializedScriptValue>&&, WebCore::ScriptExecutionContext& source) final;
void disconnectedFromWebProcess();
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
@@ -64,6 +64,8 @@
bool hasServiceWorkerRegisteredForOrigin(const WebCore::SecurityOrigin&) const final;
Ref<ServiceWorkerClientFetch> startFetch(WebServiceWorkerProvider&, Ref<WebCore::ResourceLoader>&&, uint64_t identifier, ServiceWorkerClientFetch::Callback&&);
+ void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin);
+
private:
void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (224112 => 224113)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in 2017-10-27 16:35:45 UTC (rev 224113)
@@ -30,6 +30,7 @@
StartScriptFetchForServer(uint64_t jobIdentifier)
SetSWOriginTableSharedMemory(WebKit::SharedMemory::Handle handle)
+ PostMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, IPC::DataReference message, uint64_t sourceServiceWorkerIdentifier, String sourceOrigin)
}
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (224112 => 224113)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-10-27 16:35:45 UTC (rev 224113)
@@ -130,11 +130,16 @@
serviceWorkerThreadProxy->thread().postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
}
-void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin)
+void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, const IPC::DataReference& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
{
- SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(serviceWorkerIdentifier, SerializedScriptValue::adopt(message.vector()), sourceOrigin);
+ SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(destinationServiceWorkerIdentifier, SerializedScriptValue::adopt(message.vector()), sourceIdentifier, sourceOrigin);
}
+void WebSWContextManagerConnection::postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, Ref<SerializedScriptValue>&& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin)
+{
+ m_connectionToStorageProcess->send(Messages::StorageProcess::PostMessageToServiceWorkerClient(destinationIdentifier, IPC::DataReference { message->data() }, sourceServiceWorkerIdentifier, sourceOrigin), 0);
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (224112 => 224113)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h 2017-10-27 16:35:45 UTC (rev 224113)
@@ -41,19 +41,22 @@
struct WebPreferencesStore;
-class WebSWContextManagerConnection : public WebCore::SWContextManager::Connection, public IPC::MessageReceiver {
+class WebSWContextManagerConnection final : public WebCore::SWContextManager::Connection, public IPC::MessageReceiver {
public:
WebSWContextManagerConnection(Ref<IPC::Connection>&&, uint64_t pageID, const WebPreferencesStore&);
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
- void postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin);
-
private:
void updatePreferences(const WebPreferencesStore&);
+ // WebCore::SWContextManager::Connection.
+ void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, Ref<WebCore::SerializedScriptValue>&& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin) final;
+
+ // IPC messages.
void startServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
+ void postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, const IPC::DataReference& message, const WebCore::ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
Ref<IPC::Connection> m_connectionToStorageProcess;
uint64_t m_pageID { 0 };
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (224112 => 224113)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-10-27 16:09:02 UTC (rev 224112)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-10-27 16:35:45 UTC (rev 224113)
@@ -25,7 +25,7 @@
messages -> WebSWContextManagerConnection {
StartServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
- PostMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, IPC::DataReference message, String sourceOrigin)
+ PostMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, String sourceOrigin)
}
#endif