[Service Workers] Implement Client API
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2017 18:00:24 +0000 (18:00 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2017 18:00:24 +0000 (18:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179709

Reviewed by Alex Christensen.

Source/WebCore:

Implement Client API as per:
- https://w3c.github.io/ServiceWorker/#client-interface

Tests:
http/tests/workers/service/Client-properties.html
http/tests/workers/service/Client-properties-subframe.html
http/tests/workers/service/Client-properties-auxiliary.html

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::postMessage):
* workers/service/ServiceWorkerClient.cpp:
(WebCore::ServiceWorkerClient::ServiceWorkerClient):
(WebCore::ServiceWorkerClient::url const):
(WebCore::ServiceWorkerClient::type const):
(WebCore::ServiceWorkerClient::frameType const):
(WebCore::ServiceWorkerClient::id const):
(WebCore::ServiceWorkerClient::postMessage):
* workers/service/ServiceWorkerClient.h:
(WebCore::ServiceWorkerClient::create):
* workers/service/ServiceWorkerClientData.cpp: Copied from Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp.
(WebCore::toServiceWorkerClientFrameType):
(WebCore::ServiceWorkerClientData::isolatedCopy const):
(WebCore::ServiceWorkerClientData::from):
* workers/service/ServiceWorkerClientData.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.h.
(WebCore::ServiceWorkerClientData::encode const):
(WebCore::ServiceWorkerClientData::decode):
* workers/service/ServiceWorkerClientIdentifier.h:
(WebCore::ServiceWorkerClientIdentifier::encode const):
(WebCore::ServiceWorkerClientIdentifier::decode):
* workers/service/ServiceWorkerTypes.h:
* 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.h:

Source/WebKit:

* Shared/WebCoreArgumentCoders.cpp:
* Shared/WebCoreArgumentCoders.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::postMessageToServiceWorkerGlobalScope):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::postMessageToServiceWorkerGlobalScope):
* WebProcess/Storage/WebSWClientConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope):
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:

LayoutTests:

Add layout test coverage.

* http/tests/workers/service/Client-properties-auxiliary-expected.txt: Added.
* http/tests/workers/service/Client-properties-auxiliary.html: Added.
* http/tests/workers/service/Client-properties-expected.txt: Added.
* http/tests/workers/service/Client-properties-subframe-expected.txt: Added.
* http/tests/workers/service/Client-properties-subframe.html: Added.
* http/tests/workers/service/Client-properties.html: Added.
* http/tests/workers/service/resources/Client-properties-worker.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224880 268f45cc-cd09-0410-ab3c-d52691b4dbfc

39 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/Client-properties-auxiliary-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/Client-properties-auxiliary.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/Client-properties-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/Client-properties-subframe-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/Client-properties-subframe.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/Client-properties.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/Client-properties-worker.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/workers/service/ServiceWorker.cpp
Source/WebCore/workers/service/ServiceWorkerClient.cpp
Source/WebCore/workers/service/ServiceWorkerClient.h
Source/WebCore/workers/service/ServiceWorkerClientData.cpp [new file with mode: 0644]
Source/WebCore/workers/service/ServiceWorkerClientData.h [new file with mode: 0644]
Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h
Source/WebCore/workers/service/ServiceWorkerClientType.h
Source/WebCore/workers/service/ServiceWorkerRegistrationData.h
Source/WebCore/workers/service/ServiceWorkerTypes.h
Source/WebCore/workers/service/ServiceWorkerUpdateViaCache.h
Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp
Source/WebCore/workers/service/ServiceWorkerWindowClient.h
Source/WebCore/workers/service/context/SWContextManager.cpp
Source/WebCore/workers/service/context/SWContextManager.h
Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
Source/WebCore/workers/service/context/ServiceWorkerThread.h
Source/WebCore/workers/service/server/SWClientConnection.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/Shared/WebCoreArgumentCoders.h
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in
Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWClientConnection.h
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in

index 4853fb6..506cf89 100644 (file)
@@ -1,3 +1,20 @@
+2017-11-15  Chris Dumez  <cdumez@apple.com>
+
+        [Service Workers] Implement Client API
+        https://bugs.webkit.org/show_bug.cgi?id=179709
+
+        Reviewed by Alex Christensen.
+
+        Add layout test coverage.
+
+        * http/tests/workers/service/Client-properties-auxiliary-expected.txt: Added.
+        * http/tests/workers/service/Client-properties-auxiliary.html: Added.
+        * http/tests/workers/service/Client-properties-expected.txt: Added.
+        * http/tests/workers/service/Client-properties-subframe-expected.txt: Added.
+        * http/tests/workers/service/Client-properties-subframe.html: Added.
+        * http/tests/workers/service/Client-properties.html: Added.
+        * http/tests/workers/service/resources/Client-properties-worker.js: Added.
+
 2017-11-15  Youenn Fablet  <youenn@apple.com>
 
         Remove service worker selection based on registration
diff --git a/LayoutTests/http/tests/workers/service/Client-properties-auxiliary-expected.txt b/LayoutTests/http/tests/workers/service/Client-properties-auxiliary-expected.txt
new file mode 100644 (file)
index 0000000..ed0f2e3
--- /dev/null
@@ -0,0 +1,5 @@
+client.url: http://127.0.0.1:8000/workers/service/Client-properties.html
+client.frameType: auxiliary
+client.type: window
+client.id is non empty: YES
+
diff --git a/LayoutTests/http/tests/workers/service/Client-properties-auxiliary.html b/LayoutTests/http/tests/workers/service/Client-properties-auxiliary.html
new file mode 100644 (file)
index 0000000..043e9fa
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+if (window.testRunner)
+    testRunner.setCanOpenWindows(true);
+
+window.open("Client-properties.html");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/workers/service/Client-properties-expected.txt b/LayoutTests/http/tests/workers/service/Client-properties-expected.txt
new file mode 100644 (file)
index 0000000..bc183e8
--- /dev/null
@@ -0,0 +1,5 @@
+client.url: http://127.0.0.1:8000/workers/service/Client-properties.html
+client.frameType: top-level
+client.type: window
+client.id is non empty: YES
+
diff --git a/LayoutTests/http/tests/workers/service/Client-properties-subframe-expected.txt b/LayoutTests/http/tests/workers/service/Client-properties-subframe-expected.txt
new file mode 100644 (file)
index 0000000..cf99d66
--- /dev/null
@@ -0,0 +1,6 @@
+
+client.url: http://127.0.0.1:8000/workers/service/Client-properties.html
+client.frameType: nested
+client.type: window
+client.id is non empty: YES
+
diff --git a/LayoutTests/http/tests/workers/service/Client-properties-subframe.html b/LayoutTests/http/tests/workers/service/Client-properties-subframe.html
new file mode 100644 (file)
index 0000000..d3f48ef
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<iframe src="Client-properties.html"></iframe>
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/workers/service/Client-properties.html b/LayoutTests/http/tests/workers/service/Client-properties.html
new file mode 100644 (file)
index 0000000..244497a
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="resources/sw-test-pre.js"></script>
+<script>
+
+logWindow = window;
+if (window.opener)
+    logWindow = window.opener;
+else if (window.parent)
+    logWindow = window.parent;
+
+navigator.serviceWorker.addEventListener("message", function(event) {
+    if (event.data === "DONE") {
+        finishSWTest();
+        return;
+    }
+        logWindow.log(event.data);
+});
+
+navigator.serviceWorker.register("resources/Client-properties-worker.js", { }).then(function() {
+    navigator.serviceWorker.controller.postMessage("TEST");
+});
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/workers/service/resources/Client-properties-worker.js b/LayoutTests/http/tests/workers/service/resources/Client-properties-worker.js
new file mode 100644 (file)
index 0000000..116c57f
--- /dev/null
@@ -0,0 +1,10 @@
+self.addEventListener("message", function(e) {
+    let client = e.source;
+
+    client.postMessage("client.url: " + client.url);
+    client.postMessage("client.frameType: " + client.frameType);
+    client.postMessage("client.type: " + client.type);
+    client.postMessage("client.id is non empty: " + (client.id.length ? "YES" : "NO"));
+
+    client.postMessage("DONE");
+});
index 9803830..6028e46 100644 (file)
@@ -1,3 +1,53 @@
+2017-11-15  Chris Dumez  <cdumez@apple.com>
+
+        [Service Workers] Implement Client API
+        https://bugs.webkit.org/show_bug.cgi?id=179709
+
+        Reviewed by Alex Christensen.
+
+        Implement Client API as per:
+        - https://w3c.github.io/ServiceWorker/#client-interface
+
+        Tests:
+        http/tests/workers/service/Client-properties.html
+        http/tests/workers/service/Client-properties-subframe.html
+        http/tests/workers/service/Client-properties-auxiliary.html
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/service/ServiceWorker.cpp:
+        (WebCore::ServiceWorker::postMessage):
+        * workers/service/ServiceWorkerClient.cpp:
+        (WebCore::ServiceWorkerClient::ServiceWorkerClient):
+        (WebCore::ServiceWorkerClient::url const):
+        (WebCore::ServiceWorkerClient::type const):
+        (WebCore::ServiceWorkerClient::frameType const):
+        (WebCore::ServiceWorkerClient::id const):
+        (WebCore::ServiceWorkerClient::postMessage):
+        * workers/service/ServiceWorkerClient.h:
+        (WebCore::ServiceWorkerClient::create):
+        * workers/service/ServiceWorkerClientData.cpp: Copied from Source/WebCore/workers/service/ServiceWorkerWindowClient.cpp.
+        (WebCore::toServiceWorkerClientFrameType):
+        (WebCore::ServiceWorkerClientData::isolatedCopy const):
+        (WebCore::ServiceWorkerClientData::from):
+        * workers/service/ServiceWorkerClientData.h: Copied from Source/WebCore/workers/service/ServiceWorkerClient.h.
+        (WebCore::ServiceWorkerClientData::encode const):
+        (WebCore::ServiceWorkerClientData::decode):
+        * workers/service/ServiceWorkerClientIdentifier.h:
+        (WebCore::ServiceWorkerClientIdentifier::encode const):
+        (WebCore::ServiceWorkerClientIdentifier::decode):
+        * workers/service/ServiceWorkerTypes.h:
+        * 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.h:
+
 2017-11-15  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r224863.
index 9cb3136..fc67cf5 100644 (file)
@@ -2172,6 +2172,7 @@ workers/service/ExtendableMessageEvent.cpp
 workers/service/FetchEvent.cpp
 workers/service/ServiceWorker.cpp
 workers/service/ServiceWorkerClient.cpp
+workers/service/ServiceWorkerClientData.cpp
 workers/service/ServiceWorkerClients.cpp
 workers/service/ServiceWorkerContainer.cpp
 workers/service/ServiceWorkerContextData.cpp
index 803551b..4d0d3d0 100644 (file)
                836589DE1F54A76900DC31F4 /* JSFileSystemDirectoryReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D91F54A76200DC31F4 /* JSFileSystemDirectoryReader.h */; };
                836589E01F54A76E00DC31F4 /* JSFileSystemEntriesCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 836589D81F54A76200DC31F4 /* JSFileSystemEntriesCallback.h */; };
                8367587F1C56E99B008A1087 /* JSHTMLDataElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 834B86A81C56E93E00F3F0E3 /* JSHTMLDataElement.h */; };
-               8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8369FDFB1FA102CB00C1FF1F /* ServiceWorkerClientType.h */; };
+               8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8369FDFB1FA102CB00C1FF1F /* ServiceWorkerClientType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                836ACEC31ECA62C8004BD012 /* DOMMatrixReadOnly.h in Headers */ = {isa = PBXBuildFile; fileRef = 836ACEC01ECA62B0004BD012 /* DOMMatrixReadOnly.h */; };
                836ACECA1ECA9569004BD012 /* DOMMatrix.h in Headers */ = {isa = PBXBuildFile; fileRef = 836ACEC51ECA6654004BD012 /* DOMMatrix.h */; };
                836ACECB1ECA956D004BD012 /* DOMMatrixInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 836ACEC71ECA6654004BD012 /* DOMMatrixInit.h */; };
                8371AC3B1F509BE400FBF284 /* ErrorCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 8371AC391F509BDD00FBF284 /* ErrorCallback.h */; };
                8372DB311A6780A800C697C5 /* DiagnosticLoggingResultType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                83765F951DAC522F00C06537 /* MouseEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83765F941DAC521800C06537 /* MouseEventInit.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               8379363F1FBBB0B400C8023C /* ServiceWorkerClientData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8379363E1FBBB0A500C8023C /* ServiceWorkerClientData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                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 */; };
                837609C81F54CC13000C122D /* ErrorCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ErrorCallback.cpp; sourceTree = "<group>"; };
                83765F931DAC521800C06537 /* MouseEventInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MouseEventInit.idl; sourceTree = "<group>"; };
                83765F941DAC521800C06537 /* MouseEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MouseEventInit.h; sourceTree = "<group>"; };
+               8379363C1FBBB0A400C8023C /* ServiceWorkerClientData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerClientData.cpp; sourceTree = "<group>"; };
+               8379363E1FBBB0A500C8023C /* ServiceWorkerClientData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerClientData.h; sourceTree = "<group>"; };
                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>"; };
                                46EF14271F97B7BA00C2A524 /* ServiceWorkerClient.cpp */,
                                46EF14241F97B7BA00C2A524 /* ServiceWorkerClient.h */,
                                46EF14281F97B7BA00C2A524 /* ServiceWorkerClient.idl */,
+                               8379363C1FBBB0A400C8023C /* ServiceWorkerClientData.cpp */,
+                               8379363E1FBBB0A500C8023C /* ServiceWorkerClientData.h */,
                                837D46251FA2A8C50054E1FA /* ServiceWorkerClientIdentifier.h */,
                                46EF14211F97B7BA00C2A524 /* ServiceWorkerClients.cpp */,
                                46EF14221F97B7BA00C2A524 /* ServiceWorkerClients.h */,
                                51F1755D1F3EBC8300C74950 /* ServiceWorker.h in Headers */,
                                A581ED131FB288CF00CED4EC /* ServiceWorkerAgent.h in Headers */,
                                46EF142D1F97B7D800C2A524 /* ServiceWorkerClient.h in Headers */,
+                               8379363F1FBBB0B400C8023C /* ServiceWorkerClientData.h in Headers */,
                                837D46271FA2A8CE0054E1FA /* ServiceWorkerClientIdentifier.h in Headers */,
                                46EF142C1F97B7D800C2A524 /* ServiceWorkerClients.h in Headers */,
                                8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */,
index 3f49493..7796627 100644 (file)
@@ -33,6 +33,7 @@
 #include "SWClientConnection.h"
 #include "ScriptExecutionContext.h"
 #include "SerializedScriptValue.h"
+#include "ServiceWorkerClientData.h"
 #include "ServiceWorkerProvider.h"
 #include <runtime/JSCJSValueInlines.h>
 #include <wtf/NeverDestroyed.h>
@@ -126,8 +127,14 @@ ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JS
     if (channels && !channels->isEmpty())
         return Exception { NotSupportedError, ASCIILiteral("Passing MessagePort objects to postMessage is not yet supported") };
 
+    // FIXME: We should add support for workers.
+    if (!is<Document>(context))
+        return Exception { NotSupportedError, ASCIILiteral("serviceWorkerClient.postMessage() from workers is not yet supported") };
+
+    auto sourceClientData = ServiceWorkerClientData::from(context);
+
     auto& swConnection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context.sessionID());
-    swConnection.postMessageToServiceWorkerGlobalScope(identifier(), message.releaseReturnValue(), context);
+    swConnection.postMessageToServiceWorkerGlobalScope(identifier(), message.releaseReturnValue(), WTFMove(sourceClientData));
 
     return { };
 }
index 02ab224..3602e34 100644 (file)
 
 namespace WebCore {
 
-ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context, const Identifier& identifier, Type type)
+ServiceWorkerClient::ServiceWorkerClient(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
     : ContextDestructionObserver(&context)
-    , m_identifier(identifier)
-    , m_type(type)
+    , m_data(WTFMove(data))
 {
+    ASSERT(m_data.identifier.serverConnectionIdentifier);
+    ASSERT(m_data.identifier.scriptExecutionContextIdentifier);
 }
 
 ServiceWorkerClient::~ServiceWorkerClient()
 {
 }
 
-String ServiceWorkerClient::url() const
+const URL& ServiceWorkerClient::url() const
 {
-    return { };
+    return m_data.url;
+}
+
+auto ServiceWorkerClient::type() const -> Type
+{
+    return m_data.type;
 }
 
 auto ServiceWorkerClient::frameType() const -> FrameType
 {
-    return FrameType::None;
+    return m_data.frameType;
 }
 
 String ServiceWorkerClient::id() const
 {
-    return m_identifier.toString();
+    return m_data.identifier.toString();
 }
 
 ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
@@ -84,7 +90,7 @@ ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& conte
         return Exception { NotSupportedError, ASCIILiteral("Passing MessagePort objects to postMessage is not yet supported") };
 
     auto sourceIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier();
-    callOnMainThread([message = message.releaseReturnValue(), destinationIdentifier = m_identifier, sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
+    callOnMainThread([message = message.releaseReturnValue(), destinationIdentifier = m_data.identifier, sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
         if (auto* connection = SWContextManager::singleton().connection())
             connection->postMessageToServiceWorkerClient(destinationIdentifier, WTFMove(message), sourceIdentifier, sourceOrigin);
     });
index 538c0b2..cec375d 100644 (file)
@@ -29,8 +29,7 @@
 
 #include "ContextDestructionObserver.h"
 #include "ExceptionOr.h"
-#include "ServiceWorkerClientIdentifier.h"
-#include "ServiceWorkerClientType.h"
+#include "ServiceWorkerClientData.h"
 #include <heap/Strong.h>
 #include <wtf/RefCounted.h>
 
@@ -45,32 +44,26 @@ public:
     using Identifier = ServiceWorkerClientIdentifier;
 
     using Type = ServiceWorkerClientType;
-    enum class FrameType {
-        Auxiliary,
-        TopLevel,
-        Nested,
-        None
-    };
+    using FrameType = ServiceWorkerClientFrameType;
 
-    static Ref<ServiceWorkerClient> create(ScriptExecutionContext& context, const Identifier& identifier, Type type)
+    static Ref<ServiceWorkerClient> create(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
     {
-        return adoptRef(*new ServiceWorkerClient(context, identifier, type));
+        return adoptRef(*new ServiceWorkerClient(context, WTFMove(data)));
     }
 
     ~ServiceWorkerClient();
 
-    String url() const;
+    const URL& url() const;
     FrameType frameType() const;
-    Type type() const { return m_type; }
+    Type type() const;
     String id() const;
 
     ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&& transfer);
 
 protected:
-    ServiceWorkerClient(ScriptExecutionContext&, const Identifier&, Type);
+    ServiceWorkerClient(ScriptExecutionContext&, ServiceWorkerClientData&&);
 
-    Identifier m_identifier;
-    Type m_type;
+    ServiceWorkerClientData m_data;
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/workers/service/ServiceWorkerClientData.cpp b/Source/WebCore/workers/service/ServiceWorkerClientData.cpp
new file mode 100644 (file)
index 0000000..ec99d79
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+
+#if ENABLE(SERVICE_WORKER)
+#include "ServiceWorkerClientData.h"
+
+#include "DOMWindow.h"
+#include "Document.h"
+#include "Frame.h"
+
+namespace WebCore {
+
+static ServiceWorkerClientFrameType toServiceWorkerClientFrameType(ScriptExecutionContext& context)
+{
+    if (!is<Document>(context))
+        return ServiceWorkerClientFrameType::None;
+
+    auto& document = downcast<Document>(context);
+    auto* frame = document.frame();
+    if (!frame)
+        return ServiceWorkerClientFrameType::None;
+
+    if (frame->isMainFrame()) {
+        if (auto* window = document.domWindow()) {
+            if (window->opener())
+                return ServiceWorkerClientFrameType::Auxiliary;
+        }
+        return ServiceWorkerClientFrameType::TopLevel;
+    }
+    return ServiceWorkerClientFrameType::Nested;
+}
+
+ServiceWorkerClientData ServiceWorkerClientData::isolatedCopy() const
+{
+    return { identifier, type, frameType, url.isolatedCopy() };
+}
+
+ServiceWorkerClientData ServiceWorkerClientData::from(ScriptExecutionContext& context)
+{
+    bool isDocument = is<Document>(context);
+
+    ASSERT_WITH_MESSAGE(isDocument, "Only documents have identifiers at the moment");
+
+    return {
+        { 0, downcast<Document>(context).identifier() },
+        isDocument ? ServiceWorkerClientType::Window : ServiceWorkerClientType::Worker,
+        toServiceWorkerClientFrameType(context),
+        context.url()
+    };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
diff --git a/Source/WebCore/workers/service/ServiceWorkerClientData.h b/Source/WebCore/workers/service/ServiceWorkerClientData.h
new file mode 100644 (file)
index 0000000..851867c
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "ServiceWorkerClientIdentifier.h"
+#include "ServiceWorkerClientType.h"
+#include "ServiceWorkerTypes.h"
+#include "URL.h"
+
+namespace WebCore {
+
+class ScriptExecutionContext;
+
+struct ServiceWorkerClientData {
+    ServiceWorkerClientIdentifier identifier;
+    ServiceWorkerClientType type;
+    ServiceWorkerClientFrameType frameType;
+    URL url;
+
+    ServiceWorkerClientData isolatedCopy() const;
+
+    static ServiceWorkerClientData from(ScriptExecutionContext&);
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<ServiceWorkerClientData> decode(Decoder&);
+};
+
+template<class Encoder>
+void ServiceWorkerClientData::encode(Encoder& encoder) const
+{
+    encoder << identifier << type << frameType << url;
+}
+
+template<class Decoder>
+std::optional<ServiceWorkerClientData> ServiceWorkerClientData::decode(Decoder& decoder)
+{
+    std::optional<ServiceWorkerClientIdentifier> identifier;
+    decoder >> identifier;
+    if (!identifier)
+        return std::nullopt;
+
+    std::optional<ServiceWorkerClientType> type;
+    decoder >> type;
+    if (!type)
+        return std::nullopt;
+
+    std::optional<ServiceWorkerClientFrameType> frameType;
+    decoder >> frameType;
+    if (!frameType)
+        return std::nullopt;
+
+    std::optional<URL> url;
+    decoder >> url;
+    if (!url)
+        return std::nullopt;
+
+    return { { WTFMove(*identifier), WTFMove(*type), WTFMove(*frameType), WTFMove(*url) } };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
index 1464852..a152be1 100644 (file)
@@ -34,6 +34,31 @@ struct ServiceWorkerClientIdentifier {
     uint64_t scriptExecutionContextIdentifier;
 
     String toString() const { return String::number(serverConnectionIdentifier) + "-" +  String::number(scriptExecutionContextIdentifier); }
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<ServiceWorkerClientIdentifier> decode(Decoder&);
 };
 
+template<class Encoder>
+void ServiceWorkerClientIdentifier::encode(Encoder& encoder) const
+{
+    encoder << serverConnectionIdentifier << scriptExecutionContextIdentifier;
+}
+
+template<class Decoder>
+std::optional<ServiceWorkerClientIdentifier> ServiceWorkerClientIdentifier::decode(Decoder& decoder)
+{
+    std::optional<uint64_t> serverConnectionIdentifier;
+    decoder >> serverConnectionIdentifier;
+    if (!serverConnectionIdentifier)
+        return std::nullopt;
+
+    std::optional<uint64_t> scriptExecutionContextIdentifier;
+    decoder >> scriptExecutionContextIdentifier;
+    if (!scriptExecutionContextIdentifier)
+        return std::nullopt;
+
+    return { { WTFMove(*serverConnectionIdentifier), WTFMove(*scriptExecutionContextIdentifier) } };
+}
+
 }
index 4069aa5..aae9cf0 100644 (file)
@@ -27,6 +27,8 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include <wtf/EnumTraits.h>
+
 namespace WebCore {
 
 enum class ServiceWorkerClientType {
@@ -36,6 +38,20 @@ enum class ServiceWorkerClientType {
     All
 };
 
-}
+} // namespace WebCore
+
+namespace WTF {
+
+template <> struct EnumTraits<WebCore::ServiceWorkerClientType> {
+    using values = EnumValues<
+        WebCore::ServiceWorkerClientType,
+        WebCore::ServiceWorkerClientType::Window,
+        WebCore::ServiceWorkerClientType::Worker,
+        WebCore::ServiceWorkerClientType::Sharedworker,
+        WebCore::ServiceWorkerClientType::All
+    >;
+};
+
+} // namespace WTF
 
 #endif
index e80630a..3669369 100644 (file)
@@ -31,6 +31,7 @@
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerRegistrationKey.h"
 #include "ServiceWorkerTypes.h"
+#include "ServiceWorkerUpdateViaCache.h"
 
 namespace WebCore {
 
index c70ae08..b323b89 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include <wtf/EnumTraits.h>
 #include <wtf/ObjectIdentifier.h>
 
 namespace WebCore {
@@ -45,6 +46,13 @@ enum class ServiceWorkerState {
     Redundant,
 };
 
+enum class ServiceWorkerClientFrameType {
+    Auxiliary,
+    TopLevel,
+    Nested,
+    None
+};
+
 enum class ShouldNotifyWhenResolved { No, Yes };
 
 enum ServiceWorkerRegistrationIdentifierType { };
@@ -55,4 +63,46 @@ using SWServerToContextConnectionIdentifier = ObjectIdentifier<SWServerToContext
 
 } // namespace WebCore
 
+namespace WTF {
+
+template <> struct EnumTraits<WebCore::ServiceWorkerClientFrameType> {
+    using values = EnumValues<
+        WebCore::ServiceWorkerClientFrameType,
+        WebCore::ServiceWorkerClientFrameType::Auxiliary,
+        WebCore::ServiceWorkerClientFrameType::TopLevel,
+        WebCore::ServiceWorkerClientFrameType::Nested,
+        WebCore::ServiceWorkerClientFrameType::None
+    >;
+};
+
+template <> struct EnumTraits<WebCore::ServiceWorkerRegistrationState> {
+    using values = EnumValues<
+        WebCore::ServiceWorkerRegistrationState,
+        WebCore::ServiceWorkerRegistrationState::Installing,
+        WebCore::ServiceWorkerRegistrationState::Waiting,
+        WebCore::ServiceWorkerRegistrationState::Active
+    >;
+};
+
+template <> struct EnumTraits<WebCore::ServiceWorkerState> {
+    using values = EnumValues<
+        WebCore::ServiceWorkerState,
+        WebCore::ServiceWorkerState::Installing,
+        WebCore::ServiceWorkerState::Installed,
+        WebCore::ServiceWorkerState::Activating,
+        WebCore::ServiceWorkerState::Activated,
+        WebCore::ServiceWorkerState::Redundant
+    >;
+};
+
+template <> struct EnumTraits<WebCore::ShouldNotifyWhenResolved> {
+    using values = EnumValues<
+        WebCore::ShouldNotifyWhenResolved,
+        WebCore::ShouldNotifyWhenResolved::No,
+        WebCore::ShouldNotifyWhenResolved::Yes
+    >;
+};
+
+} // namespace WTF
+
 #endif // ENABLE(SERVICE_WORKER)
index a0321ab..23b2dc7 100644 (file)
@@ -27,6 +27,8 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include <wtf/EnumTraits.h>
+
 namespace WebCore {
 
 enum class ServiceWorkerUpdateViaCache {
@@ -37,4 +39,17 @@ enum class ServiceWorkerUpdateViaCache {
 
 } // namespace WebCore
 
+namespace WTF {
+
+template <> struct EnumTraits<WebCore::ServiceWorkerUpdateViaCache> {
+    using values = EnumValues<
+        WebCore::ServiceWorkerUpdateViaCache,
+        WebCore::ServiceWorkerUpdateViaCache::Imports,
+        WebCore::ServiceWorkerUpdateViaCache::All,
+        WebCore::ServiceWorkerUpdateViaCache::None
+    >;
+};
+
+} // namespace WTF
+
 #endif // ENABLE(SERVICE_WORKER)
index e71443b..ab3c75b 100644 (file)
@@ -32,8 +32,8 @@
 
 namespace WebCore {
 
-ServiceWorkerWindowClient::ServiceWorkerWindowClient(ScriptExecutionContext& context, const Identifier& identifier)
-    : ServiceWorkerClient(context, identifier, Type::Window)
+ServiceWorkerWindowClient::ServiceWorkerWindowClient(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
+    : ServiceWorkerClient(context, WTFMove(data))
 {
 }
 
index 3e2f395..555ee79 100644 (file)
@@ -36,9 +36,9 @@ class DeferredPromise;
 
 class ServiceWorkerWindowClient final : public ServiceWorkerClient {
 public:
-    static Ref<ServiceWorkerWindowClient> create(ScriptExecutionContext& context, const Identifier& identifier)
+    static Ref<ServiceWorkerWindowClient> create(ScriptExecutionContext& context, ServiceWorkerClientData&& data)
     {
-        return adoptRef(*new ServiceWorkerWindowClient(context, identifier));
+        return adoptRef(*new ServiceWorkerWindowClient(context, WTFMove(data)));
     }
 
     VisibilityState visibilityState() const;
@@ -48,7 +48,7 @@ public:
     void navigate(const String& url, Ref<DeferredPromise>&&);
 
 private:
-    ServiceWorkerWindowClient(ScriptExecutionContext&, const Identifier&);
+    ServiceWorkerWindowClient(ScriptExecutionContext&, ServiceWorkerClientData&&);
 };
 
 } // namespace WebCore
index a889607..b3ccb63 100644 (file)
@@ -64,14 +64,14 @@ ServiceWorkerThreadProxy* SWContextManager::serviceWorkerThreadProxy(ServiceWork
     return m_workerMap.get(identifier);
 }
 
-void SWContextManager::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
+void SWContextManager::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, ServiceWorkerClientData&& source)
 {
     auto* serviceWorker = m_workerMap.get(destination);
     if (!serviceWorker)
         return;
 
     // FIXME: We should pass valid MessagePortChannels.
-    serviceWorker->thread().postMessageToServiceWorkerGlobalScope(WTFMove(message), nullptr, sourceIdentifier, sourceOrigin);
+    serviceWorker->thread().postMessageToServiceWorkerGlobalScope(WTFMove(message), nullptr, WTFMove(source));
 }
 
 void SWContextManager::fireInstallEvent(ServiceWorkerIdentifier identifier)
index f61f2fc..6f291dc 100644 (file)
@@ -57,7 +57,7 @@ public:
 
     WEBCORE_EXPORT void registerServiceWorkerThreadForInstall(Ref<ServiceWorkerThreadProxy>&&);
     WEBCORE_EXPORT ServiceWorkerThreadProxy* serviceWorkerThreadProxy(ServiceWorkerIdentifier) const;
-    WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
+    WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, ServiceWorkerClientData&& source);
     WEBCORE_EXPORT void fireInstallEvent(ServiceWorkerIdentifier);
     WEBCORE_EXPORT void fireActivateEvent(ServiceWorkerIdentifier);
 
index 23c6bb6..1beae9f 100644 (file)
@@ -104,13 +104,14 @@ void ServiceWorkerThread::postFetchTask(Ref<ServiceWorkerFetch::Client>&& client
     }, WorkerRunLoop::defaultMode());
 }
 
-void ServiceWorkerThread::postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray>&& channels, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
+void ServiceWorkerThread::postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray>&& channels, ServiceWorkerClientData&& source)
 {
-    ScriptExecutionContext::Task task([this, channels = WTFMove(channels), message = WTFMove(message), sourceIdentifier, sourceOrigin = sourceOrigin.isolatedCopy()] (ScriptExecutionContext& context) mutable {
+    ScriptExecutionContext::Task task([this, channels = WTFMove(channels), message = WTFMove(message), sourceData = source.isolatedCopy()] (ScriptExecutionContext& context) mutable {
         auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
         auto ports = MessagePort::entanglePorts(serviceWorkerGlobalScope, WTFMove(channels));
-        ExtendableMessageEventSource source = RefPtr<ServiceWorkerClient> { ServiceWorkerWindowClient::create(context, sourceIdentifier) };
-        auto messageEvent = ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin, { }, WTFMove(source));
+        RefPtr<ServiceWorkerClient> source = ServiceWorkerWindowClient::create(context, WTFMove(sourceData));
+        auto sourceOrigin = SecurityOrigin::create(source->url());
+        auto messageEvent = ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin->toString(), { }, ExtendableMessageEventSource { source });
         serviceWorkerGlobalScope.dispatchEvent(messageEvent);
         serviceWorkerGlobalScope.thread().workerObjectProxy().confirmMessageFromWorkerObject(serviceWorkerGlobalScope.hasPendingActivity());
         updateExtendedEventsSet(messageEvent.ptr());
index 84a8e3b..6a10806 100644 (file)
@@ -40,6 +40,7 @@ class ExtendableEvent;
 class MessagePortChannel;
 class SerializedScriptValue;
 class WorkerObjectProxy;
+struct ServiceWorkerClientData;
 struct ServiceWorkerClientIdentifier;
 struct ServiceWorkerContextData;
 
@@ -56,7 +57,7 @@ public:
     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 ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
+    WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, ServiceWorkerClientData&& source);
     void fireInstallEvent();
     void fireActivateEvent();
 
index 8f7745e..cb03d01 100644 (file)
@@ -44,6 +44,7 @@ enum class ServiceWorkerRegistrationState;
 enum class ServiceWorkerState;
 enum class ShouldNotifyWhenResolved;
 struct ExceptionData;
+struct ServiceWorkerClientData;
 struct ServiceWorkerData;
 struct ServiceWorkerFetchResult;
 struct ServiceWorkerRegistrationData;
@@ -67,7 +68,7 @@ public:
 
     virtual void didResolveRegistrationPromise(const ServiceWorkerRegistrationKey&) = 0;
 
-    virtual void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&&, ScriptExecutionContext& source) = 0;
+    virtual void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&&, ServiceWorkerClientData&& source) = 0;
     virtual uint64_t identifier() const = 0;
     virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOrigin&) const = 0;
 
index e14cf34..03aa1e1 100644 (file)
@@ -1,3 +1,24 @@
+2017-11-15  Chris Dumez  <cdumez@apple.com>
+
+        [Service Workers] Implement Client API
+        https://bugs.webkit.org/show_bug.cgi?id=179709
+
+        Reviewed by Alex Christensen.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        * Shared/WebCoreArgumentCoders.h:
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::postMessageToServiceWorkerGlobalScope):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+        * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::postMessageToServiceWorkerGlobalScope):
+        * WebProcess/Storage/WebSWClientConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope):
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
 2017-11-15  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r224863.
index 39e0f89..4afe7e7 100644 (file)
@@ -65,7 +65,6 @@
 #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>
@@ -1902,27 +1901,6 @@ bool ArgumentCoder<TextCheckingRequestData>::decode(Decoder& decoder, TextChecki
     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);
index e99cb6d..a1e7a39 100644 (file)
@@ -39,8 +39,6 @@
 #include <WebCore/PaymentHeaders.h>
 #include <WebCore/RealtimeMediaSource.h>
 #include <WebCore/ScrollSnapOffsetsInfo.h>
-#include <WebCore/ServiceWorkerTypes.h>
-#include <WebCore/ServiceWorkerUpdateViaCache.h>
 #include <WebCore/StoredCredentialsPolicy.h>
 #include <WebCore/WorkerType.h>
 
@@ -159,10 +157,6 @@ struct MediaConstraints;
 #if ENABLE(INDEXED_DATABASE)
 using IDBKeyPath = Variant<String, Vector<String>>;
 #endif
-
-#if ENABLE(SERVICE_WORKER)
-struct ServiceWorkerClientIdentifier;
-#endif
 }
 
 namespace IPC {
@@ -483,13 +477,6 @@ template<> struct ArgumentCoder<WebCore::TextCheckingRequestData> {
     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&);
@@ -806,43 +793,4 @@ template <> struct EnumTraits<WebCore::WorkerType> {
     >;
 };
 
-#if ENABLE(SERVICE_WORKER)
-template <> struct EnumTraits<WebCore::ServiceWorkerUpdateViaCache> {
-    using values = EnumValues<
-        WebCore::ServiceWorkerUpdateViaCache,
-        WebCore::ServiceWorkerUpdateViaCache::Imports,
-        WebCore::ServiceWorkerUpdateViaCache::All,
-        WebCore::ServiceWorkerUpdateViaCache::None
-    >;
-};
-
-template <> struct EnumTraits<WebCore::ServiceWorkerRegistrationState> {
-    using values = EnumValues<
-        WebCore::ServiceWorkerRegistrationState,
-        WebCore::ServiceWorkerRegistrationState::Installing,
-        WebCore::ServiceWorkerRegistrationState::Waiting,
-        WebCore::ServiceWorkerRegistrationState::Active
-    >;
-};
-    
-template <> struct EnumTraits<WebCore::ServiceWorkerState> {
-    using values = EnumValues<
-        WebCore::ServiceWorkerState,
-        WebCore::ServiceWorkerState::Installing,
-        WebCore::ServiceWorkerState::Installed,
-        WebCore::ServiceWorkerState::Activating,
-        WebCore::ServiceWorkerState::Activated,
-        WebCore::ServiceWorkerState::Redundant
-    >;
-};
-
-template <> struct EnumTraits<WebCore::ShouldNotifyWhenResolved> {
-    using values = EnumValues<
-        WebCore::ShouldNotifyWhenResolved,
-        WebCore::ShouldNotifyWhenResolved::No,
-        WebCore::ShouldNotifyWhenResolved::Yes
-    >;
-};
-#endif
-
 } // namespace WTF
index 385a102..79632cc 100644 (file)
@@ -45,6 +45,7 @@
 #include <WebCore/NotImplemented.h>
 #include <WebCore/SWServerRegistration.h>
 #include <WebCore/SecurityOrigin.h>
+#include <WebCore/ServiceWorkerClientData.h>
 #include <WebCore/ServiceWorkerClientIdentifier.h>
 #include <WebCore/ServiceWorkerContextData.h>
 #include <WebCore/ServiceWorkerJobData.h>
@@ -111,10 +112,10 @@ void WebSWServerConnection::startFetch(uint64_t fetchIdentifier, std::optional<S
     sendToContextProcess(Messages::WebSWContextManagerConnection::StartFetch(identifier(), fetchIdentifier, serviceWorkerIdentifier, request, options));
 }
 
-void WebSWServerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationServiceWorkerIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin)
+void WebSWServerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationServiceWorkerIdentifier, const IPC::DataReference& message, ServiceWorkerClientData&& source)
 {
-    ServiceWorkerClientIdentifier sourceIdentifier { identifier(), sourceScriptExecutionContextIdentifier };
-    sendToContextProcess(Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerGlobalScope { destinationServiceWorkerIdentifier, message, sourceIdentifier, sourceOrigin });
+    source.identifier.serverConnectionIdentifier = identifier();
+    sendToContextProcess(Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerGlobalScope { destinationServiceWorkerIdentifier, message, WTFMove(source) });
 }
 
 void WebSWServerConnection::didReceiveFetchResponse(uint64_t fetchIdentifier, const ResourceResponse& response)
index f84f375..b5f4b96 100644 (file)
@@ -34,6 +34,7 @@
 
 namespace WebCore {
 struct ExceptionData;
+struct ServiceWorkerClientData;
 class ServiceWorkerRegistrationKey;
 }
 
@@ -70,7 +71,7 @@ private:
 
     void startFetch(uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, const WebCore::ResourceRequest&, const WebCore::FetchOptions&);
 
-    void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin);
+    void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerClientData&& source);
 
     void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::URL& clientURL);
     void getRegistrations(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::URL& clientURL);
index ec44c08..0a8a48e 100644 (file)
@@ -30,7 +30,7 @@ messages -> WebSWServerConnection {
     RemoveServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationKey key, WebCore::ServiceWorkerRegistrationIdentifier identifier)
 
     StartFetch(uint64_t identifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
-    PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationServiceWorkerIdentifier, IPC::DataReference message, uint64_t sourceScriptExecutionContextIdentifier, String sourceOrigin)
+    PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationServiceWorkerIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientData source)
 
     DidResolveRegistrationPromise(WebCore::ServiceWorkerRegistrationKey key)
 
index b08285a..43c5769 100644 (file)
@@ -37,6 +37,7 @@
 #include "WebSWServerConnectionMessages.h"
 #include <WebCore/Document.h>
 #include <WebCore/SerializedScriptValue.h>
+#include <WebCore/ServiceWorkerClientData.h>
 #include <WebCore/ServiceWorkerFetchResult.h>
 #include <WebCore/ServiceWorkerJobData.h>
 #include <WebCore/ServiceWorkerRegistrationData.h>
@@ -80,13 +81,9 @@ void WebSWClientConnection::removeServiceWorkerRegistrationInServer(const Servic
     send(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer(key, identifier));
 }
 
-void WebSWClientConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&& scriptValue, ScriptExecutionContext& source)
+void WebSWClientConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&& scriptValue, ServiceWorkerClientData&& source)
 {
-    // FIXME: Add support for posting messages from workers.
-    if (!is<Document>(source))
-        return;
-
-    send(Messages::WebSWServerConnection::PostMessageToServiceWorkerGlobalScope(destinationIdentifier, IPC::DataReference { scriptValue->data() }, downcast<Document>(source).identifier(), source.origin()));
+    send(Messages::WebSWServerConnection::PostMessageToServiceWorkerGlobalScope(destinationIdentifier, IPC::DataReference { scriptValue->data() }, WTFMove(source)));
 }
 
 void WebSWClientConnection::didResolveRegistrationPromise(const ServiceWorkerRegistrationKey& key)
index 6020f06..bbd0efd 100644 (file)
@@ -68,7 +68,7 @@ public:
 private:
     void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
     void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
-    void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, Ref<WebCore::SerializedScriptValue>&&, WebCore::ScriptExecutionContext& source) final;
+    void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, Ref<WebCore::SerializedScriptValue>&&, WebCore::ServiceWorkerClientData&& source) final;
 
     void matchRegistration(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, RegistrationCallback&&) final;
     void didMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData>&&);
index dfdc62f..cdd95d8 100644 (file)
@@ -47,6 +47,7 @@
 #include <WebCore/PageConfiguration.h>
 #include <WebCore/RuntimeEnabledFeatures.h>
 #include <WebCore/SerializedScriptValue.h>
+#include <WebCore/ServiceWorkerClientIdentifier.h>
 #include <pal/SessionID.h>
 
 #if USE(QUICK_LOOK)
@@ -142,9 +143,9 @@ void WebSWContextManagerConnection::startFetch(uint64_t serverConnectionIdentifi
     serviceWorkerThreadProxy->thread().postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
 }
 
-void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
+void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, ServiceWorkerClientData&& source)
 {
-    SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(destinationIdentifier, SerializedScriptValue::adopt(message.vector()), sourceIdentifier, sourceOrigin);
+    SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(destinationIdentifier, SerializedScriptValue::adopt(message.vector()), WTFMove(source));
 }
 
 void WebSWContextManagerConnection::fireInstallEvent(ServiceWorkerIdentifier identifier)
index fa2ac83..8e4d56b 100644 (file)
@@ -60,7 +60,7 @@ private:
     void serviceWorkerStartedWithMessage(WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
     void installServiceWorker(const WebCore::ServiceWorkerContextData&);
     void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
-    void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, const WebCore::ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
+    void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerClientData&& source);
     void fireInstallEvent(WebCore::ServiceWorkerIdentifier);
     void fireActivateEvent(WebCore::ServiceWorkerIdentifier);
 
index 1498d27..7331a8d 100644 (file)
@@ -25,7 +25,7 @@
 messages -> WebSWContextManagerConnection {
     InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData)
     StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
-    PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, String sourceOrigin)
+    PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientData source)
     FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier)
     FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)
 }