Title: [224408] trunk
Revision
224408
Author
[email protected]
Date
2017-11-03 11:21:46 -0700 (Fri, 03 Nov 2017)

Log Message

Implement Service Worker Matching Registration algorithm
https://bugs.webkit.org/show_bug.cgi?id=178882

Patch by Youenn Fablet <[email protected]> on 2017-11-03
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt:
* web-platform-tests/service-workers/service-worker/multiple-register.https-expected.txt:
* web-platform-tests/service-workers/service-worker/registration-basic.https-expected.txt:
* web-platform-tests/service-workers/service-worker/registration-scope.https-expected.txt:
* web-platform-tests/service-workers/service-worker/serviceworkerobject-scripturl.https-expected.txt:
* web-platform-tests/service-workers/service-worker/unregister-controller.https-expected.txt:
* web-platform-tests/service-workers/service-worker/unregister.https-expected.txt:

Source/WebCore:

Test: http/tests/workers/service/service-worker-clear.html

Adding support for scope as part of the ServiceWorkerRegistrationKey to disambiguate several service workers registered with different scopes.
Adding the Service Worker Registration algorithm in SWServer and adding internals API to test it.
Making ServiceWorkerRegistrationKey a class to protect its internal field to be reused in wrong places.

Added preliminary support for clearing service workers for a given session ID as this is needed by WTR for stable testing.

* testing/Internals.cpp:
(WebCore::Internals::hasServiceWorkerRegistration):
* testing/Internals.h:
* testing/Internals.idl:
* workers/service/ServiceWorkerJobData.cpp:
(WebCore::ServiceWorkerJobData::registrationKey const):
* workers/service/ServiceWorkerRegistration.h:
* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::hash const):
(WebCore::ServiceWorkerRegistrationKey::operator== const):
(WebCore::ServiceWorkerRegistrationKey::isolatedCopy const):
* workers/service/ServiceWorkerRegistrationKey.h:
(WebCore::ServiceWorkerRegistrationKey::encode const):
(WebCore::ServiceWorkerRegistrationKey::decode):
* workers/service/server/SWClientConnection.h:
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::clear):
(WebCore::SWServer::doRegistrationMatching const):
* workers/service/server/SWServer.h:
(WebCore::SWServer::Connection::doRegistrationMatching const):
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::~SWServerJobQueue):
* workers/service/server/SWServerRegistration.h:

Source/WebKit:

Added IPC plumbery for matchRegistration request and response.
Added some limited clearing of workers and registrations.

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::matchRegistration):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::deleteWebsiteData):
(WebKit::StorageProcess::deleteWebsiteDataForOrigins):
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::didMatchRegistration):
(WebKit::WebSWClientConnection::matchRegistration):
* WebProcess/Storage/WebSWClientConnection.h:
* WebProcess/Storage/WebSWClientConnection.messages.in:
* WebProcess/Storage/WebServiceWorkerProvider.h:

LayoutTests:

* TestExpectations:
* http/tests/workers/service/basic-register-exceptions-expected.txt:
* http/tests/workers/service/resources/basic-register.js: Fixing flakiness.
* http/tests/workers/service/service-worker-clear-expected.txt: Added.
* http/tests/workers/service/service-worker-clear.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (224407 => 224408)


--- trunk/LayoutTests/ChangeLog	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/ChangeLog	2017-11-03 18:21:46 UTC (rev 224408)
@@ -1,3 +1,16 @@
+2017-11-03  Youenn Fablet  <[email protected]>
+
+        Implement Service Worker Matching Registration algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=178882
+
+        Reviewed by Chris Dumez.
+
+        * TestExpectations:
+        * http/tests/workers/service/basic-register-exceptions-expected.txt:
+        * http/tests/workers/service/resources/basic-register.js: Fixing flakiness.
+        * http/tests/workers/service/service-worker-clear-expected.txt: Added.
+        * http/tests/workers/service/service-worker-clear.html: Added.
+
 2017-11-02  Dean Jackson  <[email protected]>
 
         Add basic OffscreenCanvas interface

Modified: trunk/LayoutTests/TestExpectations (224407 => 224408)


--- trunk/LayoutTests/TestExpectations	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/TestExpectations	2017-11-03 18:21:46 UTC (rev 224408)
@@ -184,6 +184,8 @@
 imported/w3c/web-platform-tests/service-workers/service-worker/websocket.https.html [ Pass Failure ]
 http/tests/workers/service/service-worker-cache-api.https.html [ Pass Failure ]
 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-header-visibility.https.html [ Pass Failure ]
+imported/w3c/web-platform-tests/service-workers/service-worker/unregister-controller.https.html [ Pass Failure ]
+imported/w3c/web-platform-tests/service-workers/service-worker/update-bytecheck.https.html [ Pass Failure ]
 
 # textarea.animate is not supported
 imported/w3c/web-platform-tests/css/css-ui-3/caret-color-018.html [ Skip ]

Modified: trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt (224407 => 224408)


--- trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/http/tests/workers/service/basic-register-exceptions-expected.txt	2017-11-03 18:21:46 UTC (rev 224408)
@@ -4,7 +4,5 @@
 CONSOLE MESSAGE: line 50: Registration failed with error: TypeError: serviceWorker.register() must be called with a script URL whose path does not contain '%2f' or '%5c'
 CONSOLE MESSAGE: line 60: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS
 CONSOLE MESSAGE: line 70: Registration failed with error: TypeError: Scope URL provided to serviceWorker.register() cannot have a path that contains '%2f' or '%5c'
-CONSOLE MESSAGE: line 8: Registered! (unexpectedly)
-CONSOLE MESSAGE: line 80: Registration failed with error: SecurityError: Script origin does not match the registering client's origin
 CONSOLE MESSAGE: line 91: Registration failed with error: SecurityError: Scope origin does not match the registering client's origin
 

Modified: trunk/LayoutTests/http/tests/workers/service/resources/basic-register.js (224407 => 224408)


--- trunk/LayoutTests/http/tests/workers/service/resources/basic-register.js	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/http/tests/workers/service/resources/basic-register.js	2017-11-03 18:21:46 UTC (rev 224408)
@@ -3,46 +3,34 @@
     finishSWTest();
 }
 
-function log(msg)
+async function test()
 {
-    let console = document.getElementById("console");
-    if (!console) {
-        console = document.createElement("div");
-        console.id = "console";
-        document.body.appendChild(console);
-    }
-    let span = document.createElement("span");
-    span.innerHTML = msg + "<br>";
-    console.appendChild(span);
-}
+    if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
+        log("PASS: No service worker is initially registered for this origin");
+    else
+        log("FAIL: A service worker is initially registered for this origin");
 
-if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
-    log("PASS: No service worker is initially registered for this origin");
-else
-    log("FAIL: A service worker is initially registered for this origin");
+    testRunner.setPrivateBrowsingEnabled(true);
 
-testRunner.setPrivateBrowsingEnabled(true);
+    if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
+        log("PASS: No service worker is initially registered for this origin in private session");
+    else
+        log("FAIL: A service worker is initially registered for this origin in private session");
 
-if (!internals.hasServiceWorkerRegisteredForOrigin(self.origin))
-    log("PASS: No service worker is initially registered for this origin in private session");
-else
-    log("FAIL: A service worker is initially registered for this origin in private session");
+    testRunner.setPrivateBrowsingEnabled(false);
+    try {
+        r = await navigator.serviceWorker.register("resources/empty-worker.js", { scope: "/test", updateViaCache: "none" })
+        log("Registered!");
 
-testRunner.setPrivateBrowsingEnabled(false);
-
-navigator.serviceWorker.register("resources/empty-worker.js", { scope: "/test", updateViaCache: "none" })
-.then(function(r) {
-	log("Registered!");
-
         if (r.scope == "http://127.0.0.1:8000/test")
-           log("PASS: registration object's scope is valid");
+            log("PASS: registration object's scope is valid");
         else
-           log("FAIL: registration object's scope is invalid, got: " + r.scope);
+            log("FAIL: registration object's scope is invalid, got: " + r.scope);
 
         if (r.updateViaCache == "none")
-           log("PASS: registration object's updateViaCache is valid");
+            log("PASS: registration object's updateViaCache is valid");
         else
-           log("FAIL: registration object's updateViaCache is invalid, got: " + r.updateViaCache);
+            log("FAIL: registration object's updateViaCache is invalid, got: " + r.updateViaCache);
 
         if (internals.hasServiceWorkerRegisteredForOrigin(self.origin))
             log("PASS: A service worker is now registered for this origin");
@@ -57,22 +45,13 @@
             log("FAIL: A service worker is registered for this origin in private session");
 
         testRunner.setPrivateBrowsingEnabled(false);
-}, function(e) {
-        log("Registration failed with error: " + e);
-})
-.catch(function(e) {
-	log("Exception registering: " + e);
-});
 
-navigator.serviceWorker.register("resources/empty-worker-doesnt-exist.js", { })
-.then(function(r) {
-	log("Registered!");
-	done();
-}, function(e) {
-	log("Registration failed with error: " + e);
-	done();
-})
-.catch(function(e) {
-	log("Exception registering: " + e);
-	done();
-});
+        r = await navigator.serviceWorker.register("resources/empty-worker-doesnt-exist.js", { })
+        log("Registered!");
+    } catch (e) {
+        log("Exception registering: " + e);
+    }
+    done();
+}
+
+test();

Added: trunk/LayoutTests/http/tests/workers/service/service-worker-clear-expected.txt (0 => 224408)


--- trunk/LayoutTests/http/tests/workers/service/service-worker-clear-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-clear-expected.txt	2017-11-03 18:21:46 UTC (rev 224408)
@@ -0,0 +1,3 @@
+PASS: No registration
+PASS: Got registration
+

Added: trunk/LayoutTests/http/tests/workers/service/service-worker-clear.html (0 => 224408)


--- trunk/LayoutTests/http/tests/workers/service/service-worker-clear.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-clear.html	2017-11-03 18:21:46 UTC (rev 224408)
@@ -0,0 +1,29 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+async function test()
+{
+    try {
+        if (!window.internals) {
+            log("test requires internals");
+            return;
+        }
+        var hasRegistration = await internals.hasServiceWorkerRegistration("");
+        log(hasRegistration ? "FAIL: Got registration" : "PASS: No registration");
+
+        await navigator.serviceWorker.register("resources/service-worker-fetch-worker.js", { });
+
+        var hasRegistration = await internals.hasServiceWorkerRegistration("");
+        log(hasRegistration ? "PASS: Got registration" : "FAIL: No registration");
+    } catch(e) {
+        log("Got exception: " + e);
+    }
+    finishSWTest();
+}
+test();
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224407 => 224408)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-03 18:21:46 UTC (rev 224408)
@@ -1,3 +1,18 @@
+2017-11-03  Youenn Fablet  <[email protected]>
+
+        Implement Service Worker Matching Registration algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=178882
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/multiple-register.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/registration-basic.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/registration-scope.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/serviceworkerobject-scripturl.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/unregister-controller.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/unregister.https-expected.txt:
+
 2017-11-03  Ms2ger  <[email protected]>
 
         Update Event-timestamp-high-resolution.html.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multiple-register.https-expected.txt (224407 => 224408)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multiple-register.https-expected.txt	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multiple-register.https-expected.txt	2017-11-03 18:21:46 UTC (rev 224408)
@@ -1,6 +1,6 @@
 
 
 FAIL Subsequent registrations resolve to the same registration object assert_unreached: unexpected rejection: assert_equals: register should resolve to the same registration expected object "[object ServiceWorkerRegistration]" but got object "[object ServiceWorkerRegistration]" Reached unreachable code
-FAIL Subsequent registrations from a different iframe resolve to the different registration object but they refer to the same registration and workers assert_unreached: unexpected rejection: assert_equals: registrations should have the same scope expected "https://localhost:9443/service-workers/service-worker/resources/scope/subsequent-register-from-different-iframe" but got "https://localhost:9443/service-workers/service-worker/resources/scope/subsequent-register-from-same-window" Reached unreachable code
+FAIL Subsequent registrations from a different iframe resolve to the different registration object but they refer to the same registration and workers assert_unreached: unexpected rejection: assert_equals: installing worker should be null expected null but got object "[object ServiceWorker]" Reached unreachable code
 FAIL Concurrent registrations resolve to the same registration object assert_unreached: unexpected rejection: assert_equals: register should resolve to the same registration expected object "[object ServiceWorkerRegistration]" but got object "[object ServiceWorkerRegistration]" Reached unreachable code
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-controller.https-expected.txt (224407 => 224408)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-controller.https-expected.txt	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-controller.https-expected.txt	2017-11-03 18:21:46 UTC (rev 224408)
@@ -1,6 +1,6 @@
 
 
 FAIL Unregister does not affect existing controller assert_unreached: unexpected rejection: assert_true: document should load with a controller expected true got false Reached unreachable code
-FAIL Unregister prevents control of subsequent navigations assert_unreached: unexpected rejection: assert_equals: requests should not be intercepted expected "a simple text file\n" but got "ERROR" Reached unreachable code
+PASS Unregister prevents control of subsequent navigations 
 PASS Unregister prevents new controllee even if registration is still in use 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister.https-expected.txt (224407 => 224408)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister.https-expected.txt	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister.https-expected.txt	2017-11-03 18:21:46 UTC (rev 224408)
@@ -1,4 +1,4 @@
 
 PASS Unregister twice 
-FAIL Register then unregister assert_unreached: unexpected rejection: assert_equals: unregistration should resolve with true expected true but got false Reached unreachable code
+PASS Register then unregister 
 

Modified: trunk/Source/WebCore/ChangeLog (224407 => 224408)


--- trunk/Source/WebCore/ChangeLog	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/ChangeLog	2017-11-03 18:21:46 UTC (rev 224408)
@@ -1,3 +1,42 @@
+2017-11-03  Youenn Fablet  <[email protected]>
+
+        Implement Service Worker Matching Registration algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=178882
+
+        Reviewed by Chris Dumez.
+
+        Test: http/tests/workers/service/service-worker-clear.html
+
+        Adding support for scope as part of the ServiceWorkerRegistrationKey to disambiguate several service workers registered with different scopes.
+        Adding the Service Worker Registration algorithm in SWServer and adding internals API to test it.
+        Making ServiceWorkerRegistrationKey a class to protect its internal field to be reused in wrong places.
+
+        Added preliminary support for clearing service workers for a given session ID as this is needed by WTR for stable testing.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::hasServiceWorkerRegistration):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        * workers/service/ServiceWorkerJobData.cpp:
+        (WebCore::ServiceWorkerJobData::registrationKey const):
+        * workers/service/ServiceWorkerRegistration.h:
+        * workers/service/ServiceWorkerRegistrationKey.cpp:
+        (WebCore::ServiceWorkerRegistrationKey::hash const):
+        (WebCore::ServiceWorkerRegistrationKey::operator== const):
+        (WebCore::ServiceWorkerRegistrationKey::isolatedCopy const):
+        * workers/service/ServiceWorkerRegistrationKey.h:
+        (WebCore::ServiceWorkerRegistrationKey::encode const):
+        (WebCore::ServiceWorkerRegistrationKey::decode):
+        * workers/service/server/SWClientConnection.h:
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::clear):
+        (WebCore::SWServer::doRegistrationMatching const):
+        * workers/service/server/SWServer.h:
+        (WebCore::SWServer::Connection::doRegistrationMatching const):
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::~SWServerJobQueue):
+        * workers/service/server/SWServerRegistration.h:
+
 2017-11-02  Dean Jackson  <[email protected]>
 
         Add basic OffscreenCanvas interface

Modified: trunk/Source/WebCore/page/SecurityOriginData.h (224407 => 224408)


--- trunk/Source/WebCore/page/SecurityOriginData.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/page/SecurityOriginData.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -83,6 +83,7 @@
 };
 
 WEBCORE_EXPORT bool operator==(const SecurityOriginData&, const SecurityOriginData&);
+inline bool operator!=(const SecurityOriginData& first, const SecurityOriginData& second) { return !(first == second); }
 
 template<class Encoder>
 void SecurityOriginData::encode(Encoder& encoder) const

Modified: trunk/Source/WebCore/testing/Internals.cpp (224407 => 224408)


--- trunk/Source/WebCore/testing/Internals.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/testing/Internals.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -132,6 +132,7 @@
 #include "SecurityOrigin.h"
 #include "SerializedScriptValue.h"
 #include "ServiceWorkerProvider.h"
+#include "ServiceWorkerRegistrationData.h"
 #include "Settings.h"
 #include "ShadowRoot.h"
 #include "SourceBuffer.h"
@@ -4265,6 +4266,17 @@
     return event;
 }
 
+void Internals::hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&& promise)
+{
+    if (!contextDocument())
+        return;
+
+    URL parsedURL = contextDocument()->completeURL(clientURL);
+
+    return ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(contextDocument()->sessionID()).matchRegistration(contextDocument()->topOrigin(), parsedURL, [promise = WTFMove(promise)] (auto&& result) mutable {
+        promise.resolve(!!result);
+    });
+}
 #endif
 
 String Internals::timelineDescription(AnimationTimeline& timeline)

Modified: trunk/Source/WebCore/testing/Internals.h (224407 => 224408)


--- trunk/Source/WebCore/testing/Internals.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/testing/Internals.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -617,10 +617,12 @@
     void waitForExtendableEventToFinish(ExtendableEvent&, DOMPromiseDeferred<void>&&);
     Ref<FetchEvent> createBeingDispatchedFetchEvent(ScriptExecutionContext&);
     Ref<ExtendableEvent> createTrustedExtendableEvent();
+    using HasRegistrationPromise = DOMPromiseDeferred<IDLBoolean>;
+    void hasServiceWorkerRegistration(const String& clientURL, HasRegistrationPromise&&);
 #endif
 
     bool hasServiceWorkerRegisteredForOrigin(const String&);
-        
+
 #if ENABLE(APPLE_PAY)
     MockPaymentCoordinator& mockPaymentCoordinator() const;
 #endif

Modified: trunk/Source/WebCore/testing/Internals.idl (224407 => 224408)


--- trunk/Source/WebCore/testing/Internals.idl	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/testing/Internals.idl	2017-11-03 18:21:46 UTC (rev 224408)
@@ -562,6 +562,7 @@
     [Conditional=SERVICE_WORKER] Promise<void> waitForExtendableEventToFinish(ExtendableEvent event);
     [Conditional=SERVICE_WORKER, CallWith=ScriptExecutionContext] FetchEvent createBeingDispatchedFetchEvent();
     [Conditional=SERVICE_WORKER] ExtendableEvent createTrustedExtendableEvent();
+    [Conditional=SERVICE_WORKER] Promise<boolean> hasServiceWorkerRegistration(DOMString scopeURL);
 
     boolean hasServiceWorkerRegisteredForOrigin(DOMString origin);
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp (224407 => 224408)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -43,7 +43,9 @@
 
 ServiceWorkerRegistrationKey ServiceWorkerJobData::registrationKey() const
 {
-    return { clientCreationURL, topOrigin };
+    URL scope = scopeURL;
+    scope.removeFragmentIdentifier();
+    return { URL { clientCreationURL }, SecurityOriginData { topOrigin }, WTFMove(scope) };
 }
 
 ServiceWorkerJobData ServiceWorkerJobData::isolatedCopy() const

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp (224407 => 224408)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -32,6 +32,14 @@
 
 namespace WebCore {
 
+ServiceWorkerRegistrationKey::ServiceWorkerRegistrationKey(URL&& clientURL, SecurityOriginData&& topOrigin, URL&& scope)
+    : m_clientCreationURL(WTFMove(clientURL))
+    , m_topOrigin(WTFMove(topOrigin))
+    , m_scope(WTFMove(scope))
+{
+    ASSERT(!m_scope.hasFragment());
+}
+
 ServiceWorkerRegistrationKey ServiceWorkerRegistrationKey::emptyKey()
 {
     return { };
@@ -39,9 +47,10 @@
 
 unsigned ServiceWorkerRegistrationKey::hash() const
 {
-    unsigned hashes[2];
-    hashes[0] = URLHash::hash(clientCreationURL);
-    hashes[1] = SecurityOriginDataHash::hash(topOrigin);
+    unsigned hashes[3];
+    hashes[0] = URLHash::hash(m_clientCreationURL);
+    hashes[1] = SecurityOriginDataHash::hash(m_topOrigin);
+    hashes[2] = StringHash::hash(m_scope);
 
     return StringHasher::hashMemory(hashes, sizeof(hashes));
 }
@@ -48,17 +57,25 @@
 
 bool ServiceWorkerRegistrationKey::operator==(const ServiceWorkerRegistrationKey& other) const
 {
-    return clientCreationURL == other.clientCreationURL && topOrigin == other.topOrigin;
+    return m_clientCreationURL == other.m_clientCreationURL && m_topOrigin == other.m_topOrigin && m_scope == other.m_scope;
 }
 
 ServiceWorkerRegistrationKey ServiceWorkerRegistrationKey::isolatedCopy() const
 {
-    ServiceWorkerRegistrationKey result;
-    result.clientCreationURL = clientCreationURL.isolatedCopy();
-    result.topOrigin = topOrigin.isolatedCopy();
-    return result;
+    return { m_clientCreationURL.isolatedCopy(), m_topOrigin.isolatedCopy(), m_scope.isolatedCopy() };
 }
 
+bool ServiceWorkerRegistrationKey::isMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const
+{
+    if (topOrigin != m_topOrigin)
+        return false;
+
+    if (!protocolHostAndPortAreEqual(clientURL, m_scope))
+        return false;
+
+    return clientURL.string().startsWith(m_scope);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h (224407 => 224408)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -32,25 +32,37 @@
 
 namespace WebCore {
 
-struct ServiceWorkerRegistrationKey {
-    URL clientCreationURL;
-    SecurityOriginData topOrigin;
+class ServiceWorkerRegistrationKey {
+public:
+    ServiceWorkerRegistrationKey() = default;
+    WEBCORE_EXPORT ServiceWorkerRegistrationKey(URL&& clientURL, SecurityOriginData&& topOrigin, URL&& scope);
 
     static ServiceWorkerRegistrationKey emptyKey();
     unsigned hash() const;
 
     bool operator==(const ServiceWorkerRegistrationKey&) const;
+    bool isMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
+    size_t scopeLength() const { return m_scope.string().length(); }
 
+    const SecurityOriginData& topOrigin() const { return m_topOrigin; }
+    const URL& clientCreationURL() const { return m_clientCreationURL; }
+    void setClientCreationURL(URL&& url) { m_clientCreationURL = WTFMove(url); }
+
     ServiceWorkerRegistrationKey isolatedCopy() const;
 
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<ServiceWorkerRegistrationKey> decode(Decoder&);
+
+private:
+    URL m_clientCreationURL;
+    SecurityOriginData m_topOrigin;
+    URL m_scope;
 };
 
 template<class Encoder>
 void ServiceWorkerRegistrationKey::encode(Encoder& encoder) const
 {
-    encoder << clientCreationURL << topOrigin;
+    encoder << m_clientCreationURL << m_topOrigin << m_scope;
 }
 
 template<class Decoder>
@@ -64,8 +76,12 @@
     decoder >> topOrigin;
     if (!topOrigin)
         return std::nullopt;
-    
-    return {{ WTFMove(clientCreationURL), WTFMove(*topOrigin) }};
+
+    URL scope;
+    if (!decoder.decode(scope))
+        return std::nullopt;
+
+    return { { WTFMove(clientCreationURL), WTFMove(*topOrigin), WTFMove(scope) } };
 }
 
 } // namespace WebCore
@@ -81,8 +97,8 @@
 template<> struct HashTraits<WebCore::ServiceWorkerRegistrationKey> : GenericHashTraits<WebCore::ServiceWorkerRegistrationKey> {
     static WebCore::ServiceWorkerRegistrationKey emptyValue() { return WebCore::ServiceWorkerRegistrationKey::emptyKey(); }
 
-    static void constructDeletedValue(WebCore::ServiceWorkerRegistrationKey& slot) { slot.clientCreationURL = WebCore::URL(HashTableDeletedValue); }
-    static bool isDeletedValue(const WebCore::ServiceWorkerRegistrationKey& slot) { return slot.clientCreationURL.isHashTableDeletedValue(); }
+    static void constructDeletedValue(WebCore::ServiceWorkerRegistrationKey& slot) { slot.setClientCreationURL(WebCore::URL(HashTableDeletedValue)); }
+    static bool isDeletedValue(const WebCore::ServiceWorkerRegistrationKey& slot) { return slot.clientCreationURL().isHashTableDeletedValue(); }
 };
 
 template<> struct DefaultHash<WebCore::ServiceWorkerRegistrationKey> {

Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.h (224407 => 224408)


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -47,6 +47,9 @@
 public:
     WEBCORE_EXPORT virtual ~SWClientConnection();
 
+    using RegistrationCallback = WTF::CompletionHandler<void(std::optional<ServiceWorkerRegistrationData>&&)>;
+    virtual void matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&&) = 0;
+
     void scheduleJob(ServiceWorkerJob&);
     void finishedFetchingScript(ServiceWorkerJob&, const String&);
     void failedFetchingScript(ServiceWorkerJob&, const ResourceError&);

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (224407 => 224408)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -34,6 +34,7 @@
 #include "SWServerJobQueue.h"
 #include "SWServerRegistration.h"
 #include "SWServerWorker.h"
+#include "SecurityOrigin.h"
 #include "ServiceWorkerContextData.h"
 #include "ServiceWorkerFetchResult.h"
 #include "ServiceWorkerJobData.h"
@@ -91,6 +92,13 @@
     m_registrations.remove(registrationKey);
 }
 
+void SWServer::clear()
+{
+    m_jobQueues.clear();
+    m_registrations.clear();
+    // FIXME: We should probably ask service workers to terminate.
+}
+
 void SWServer::Connection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
 {
     LOG(ServiceWorker, "Scheduling ServiceWorker job %" PRIu64 "-%" PRIu64 " in server", jobData.connectionIdentifier(), jobData.identifier());
@@ -304,6 +312,19 @@
     m_connections.remove(connection.identifier());
 }
 
+const SWServerRegistration* SWServer::doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const
+{
+    const SWServerRegistration* selectedRegistration = nullptr;
+    for (auto& registration : m_registrations.values()) {
+        if (!registration->key().isMatching(topOrigin, clientURL))
+            continue;
+        if (!selectedRegistration || selectedRegistration->key().scopeLength() < registration->key().scopeLength())
+            selectedRegistration = registration.get();
+    }
+
+    return (selectedRegistration && !selectedRegistration->isUninstalling()) ? selectedRegistration : nullptr;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (224407 => 224408)


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -29,6 +29,7 @@
 
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerJob.h"
+#include "ServiceWorkerRegistrationData.h"
 #include "ServiceWorkerRegistrationKey.h"
 #include <wtf/CrossThreadQueue.h>
 #include <wtf/CrossThreadTask.h>
@@ -59,7 +60,8 @@
 
         WEBCORE_EXPORT void scriptContextFailedToStart(const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier, const String& message);
         WEBCORE_EXPORT void scriptContextStarted(const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier);
-        
+        const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const { return m_server.doRegistrationMatching(topOrigin, clientURL); }
+
         // Messages to the client WebProcess
         virtual void updateRegistrationStateInClient(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>) = 0;
 
@@ -88,6 +90,8 @@
     WEBCORE_EXPORT SWServer();
     WEBCORE_EXPORT ~SWServer();
 
+    WEBCORE_EXPORT void clear();
+
     SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
     void addRegistration(std::unique_ptr<SWServerRegistration>&&);
     void removeRegistration(const ServiceWorkerRegistrationKey&);
@@ -119,6 +123,8 @@
     void addClientServiceWorkerRegistration(Connection&, const ServiceWorkerRegistrationKey&, uint64_t registrationIdentifier);
     void removeClientServiceWorkerRegistration(Connection&, const ServiceWorkerRegistrationKey&, uint64_t registrationIdentifier);
 
+    WEBCORE_EXPORT const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
+
     HashMap<uint64_t, Connection*> m_connections;
     HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerRegistration>> m_registrations;
     HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerJobQueue>> m_jobQueues;

Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp (224407 => 224408)


--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -48,7 +48,6 @@
 
 SWServerJobQueue::~SWServerJobQueue()
 {
-    ASSERT(m_jobQueue.isEmpty());
 }
 
 void SWServerJobQueue::scriptFetchFinished(SWServer::Connection& connection, const ServiceWorkerFetchResult& result)

Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.h (224407 => 224408)


--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -47,7 +47,7 @@
     const ServiceWorkerRegistrationKey& key() const { return m_registrationKey; }
 
     SWServerWorker* getNewestWorker();
-    ServiceWorkerRegistrationData data() const;
+    WEBCORE_EXPORT ServiceWorkerRegistrationData data() const;
 
     bool isUninstalling() const { return m_uninstalling; }
     void setIsUninstalling(bool value) { m_uninstalling = value; }

Modified: trunk/Source/WebKit/ChangeLog (224407 => 224408)


--- trunk/Source/WebKit/ChangeLog	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/ChangeLog	2017-11-03 18:21:46 UTC (rev 224408)
@@ -1,3 +1,27 @@
+2017-11-03  Youenn Fablet  <[email protected]>
+
+        Implement Service Worker Matching Registration algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=178882
+
+        Reviewed by Chris Dumez.
+
+        Added IPC plumbery for matchRegistration request and response.
+        Added some limited clearing of workers and registrations.
+
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::matchRegistration):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+        * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::deleteWebsiteData):
+        (WebKit::StorageProcess::deleteWebsiteDataForOrigins):
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::didMatchRegistration):
+        (WebKit::WebSWClientConnection::matchRegistration):
+        * WebProcess/Storage/WebSWClientConnection.h:
+        * WebProcess/Storage/WebSWClientConnection.messages.in:
+        * WebProcess/Storage/WebServiceWorkerProvider.h:
+
 2017-11-03  Jeremy Jones  <[email protected]>
 
         Element fullscreen should use FloatRects instead of IntRects in beganEnterFullScreenWithInitialFrame

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224407 => 224408)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -43,11 +43,11 @@
 #include "WebToStorageProcessConnection.h"
 #include <WebCore/ExceptionData.h>
 #include <WebCore/NotImplemented.h>
+#include <WebCore/SWServerRegistration.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/ServiceWorkerClientIdentifier.h>
 #include <WebCore/ServiceWorkerContextData.h>
 #include <WebCore/ServiceWorkerJobData.h>
-#include <WebCore/ServiceWorkerRegistrationData.h>
 #include <wtf/MainThread.h>
 
 using namespace PAL;
@@ -78,7 +78,7 @@
 
 void WebSWServerConnection::resolveRegistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationData& registrationData)
 {
-    auto origin = registrationData.key.topOrigin.securityOrigin();
+    auto origin = registrationData.key.topOrigin().securityOrigin();
     StorageProcess::singleton().ensureSWOriginStoreForSession(m_sessionID).add(origin);
     send(Messages::WebSWClientConnection::RegistrationJobResolvedInServer(jobIdentifier, registrationData));
 }
@@ -85,7 +85,7 @@
 
 void WebSWServerConnection::resolveUnregistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationKey& registrationKey, bool unregistrationResult)
 {
-    auto origin = registrationKey.topOrigin.securityOrigin();
+    auto origin = registrationKey.topOrigin().securityOrigin();
     if (auto* store = StorageProcess::singleton().swOriginStoreForSession(m_sessionID))
         store->remove(origin);
     send(Messages::WebSWClientConnection::UnregistrationJobResolvedInServer(jobIdentifier, unregistrationResult));
@@ -150,6 +150,15 @@
     send(Messages::WebSWClientConnection::PostMessageToServiceWorkerClient { destinationScriptExecutionContextIdentifier, message, sourceServiceWorkerIdentifier, sourceOrigin });
 }
 
+void WebSWServerConnection::matchRegistration(uint64_t registrationMatchRequestIdentifier, const SecurityOriginData& topOrigin, const URL& clientURL)
+{
+    if (auto* registration = doRegistrationMatching(topOrigin, clientURL)) {
+        send(Messages::WebSWClientConnection::DidMatchRegistration { registrationMatchRequestIdentifier, registration->data() });
+        return;
+    }
+    send(Messages::WebSWClientConnection::DidMatchRegistration { registrationMatchRequestIdentifier, std::nullopt });
+}
+
 template<typename U> bool WebSWServerConnection::sendToContextProcess(U&& message)
 {
     if (!m_contextConnection)

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (224407 => 224408)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -34,7 +34,7 @@
 
 namespace WebCore {
 struct ExceptionData;
-struct ServiceWorkerRegistrationKey;
+class ServiceWorkerRegistrationKey;
 }
 
 namespace WebKit {
@@ -71,6 +71,8 @@
 
     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin);
 
+    void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData&, const WebCore::URL& clientURL);
+
     // Messages to the SW context WebProcess
     void updateServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
 

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in (224407 => 224408)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in	2017-11-03 18:21:46 UTC (rev 224408)
@@ -26,11 +26,13 @@
     # When possible, these messages can be implemented directly by WebCore::SWClientConnection
     ScheduleJobInServer(struct WebCore::ServiceWorkerJobData jobData)
     FinishFetchingScriptInServer(struct WebCore::ServiceWorkerFetchResult result)
-    AddServiceWorkerRegistrationInServer(struct WebCore::ServiceWorkerRegistrationKey key, uint64_t registrationIdentifier)
-    RemoveServiceWorkerRegistrationInServer(struct WebCore::ServiceWorkerRegistrationKey key, uint64_t registrationIdentifier)
+    AddServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationKey key, uint64_t registrationIdentifier)
+    RemoveServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationKey key, uint64_t registrationIdentifier)
 
     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)
+
+    MatchRegistration(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, WebCore::URL clientURL)
 }
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.cpp (224407 => 224408)


--- trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -226,6 +226,8 @@
     if (websiteDataTypes.contains(WebsiteDataType::ServiceWorkerRegistrations)) {
         if (auto* store = swOriginStoreForSession(sessionID))
             store->clear();
+        if (auto* server = m_swServers.get(sessionID))
+            server->clear();
     }
 #endif
 
@@ -251,6 +253,7 @@
             for (auto& originData : securityOriginDatas)
                 store->remove(originData.securityOrigin());
         }
+        // FIXME: Clear service workers and registrations related to the origin.
     }
 #endif
 

Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.h (224407 => 224408)


--- trunk/Source/WebKit/StorageProcess/StorageProcess.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -39,7 +39,7 @@
 class SWServer;
 struct SecurityOriginData;
 struct ServiceWorkerClientIdentifier;
-struct ServiceWorkerRegistrationKey;
+class ServiceWorkerRegistrationKey;
 }
 
 namespace WebKit {

Modified: trunk/Source/WebKit/StorageProcess/StorageProcess.messages.in (224407 => 224408)


--- trunk/Source/WebKit/StorageProcess/StorageProcess.messages.in	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/StorageProcess/StorageProcess.messages.in	2017-11-03 18:21:46 UTC (rev 224408)
@@ -38,8 +38,8 @@
 #if ENABLE(SERVICE_WORKER)
     DidGetWorkerContextProcessConnection(IPC::Attachment connectionHandle)
 
-    ServiceWorkerContextFailedToStart(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message)
-    ServiceWorkerContextStarted(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier)
+    ServiceWorkerContextFailedToStart(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message)
+    ServiceWorkerContextStarted(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier)
 
     DidNotHandleFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     DidFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224407 => 224408)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-03 18:21:46 UTC (rev 224408)
@@ -39,6 +39,7 @@
 #include <WebCore/SerializedScriptValue.h>
 #include <WebCore/ServiceWorkerFetchResult.h>
 #include <WebCore/ServiceWorkerJobData.h>
+#include <WebCore/ServiceWorkerRegistrationData.h>
 
 using namespace PAL;
 using namespace WebCore;
@@ -98,6 +99,19 @@
     m_swOriginTable->setSharedMemory(handle);
 }
 
+void WebSWClientConnection::didMatchRegistration(uint64_t matchingRequest, std::optional<ServiceWorkerRegistrationData>&& result)
+{
+    if (auto completionHandler = m_ongoingMatchRegistrationTasks.take(matchingRequest))
+        completionHandler(WTFMove(result));
+}
+
+void WebSWClientConnection::matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&& callback)
+{
+    uint64_t requestIdentifier = ++m_previousMatchRegistrationTaskIdentifier;
+    m_ongoingMatchRegistrationTasks.add(requestIdentifier, WTFMove(callback));
+    send(Messages::WebSWServerConnection::MatchRegistration(requestIdentifier, SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL));
+}
+
 Ref<ServiceWorkerClientFetch> WebSWClientConnection::startFetch(WebServiceWorkerProvider& provider, Ref<WebCore::ResourceLoader>&& loader, uint64_t identifier, ServiceWorkerClientFetch::Callback&& callback)
 {
     ASSERT(loader->options().serviceWorkersMode == ServiceWorkersMode::All);

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (224407 => 224408)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -54,11 +54,8 @@
 
     uint64_t identifier() const final { return m_identifier; }
 
-    void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
-    void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
     void addServiceWorkerRegistrationInServer(const WebCore::ServiceWorkerRegistrationKey&, uint64_t registrationIdentifier) final;
     void removeServiceWorkerRegistrationInServer(const WebCore::ServiceWorkerRegistrationKey&, uint64_t registrationIdentifier) final;
-    void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, Ref<WebCore::SerializedScriptValue>&&, WebCore::ScriptExecutionContext& source) final;
 
     void disconnectedFromWebProcess();
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
@@ -69,6 +66,13 @@
     void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
 
 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 matchRegistration(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, RegistrationCallback&&) final;
+    void didMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData>&&);
+
     void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
 
     IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
@@ -81,6 +85,10 @@
 
     Ref<IPC::Connection> m_connection;
     UniqueRef<WebSWOriginTable> m_swOriginTable;
+
+    uint64_t m_previousMatchRegistrationTaskIdentifier { 0 };
+    HashMap<uint64_t, RegistrationCallback> m_ongoingMatchRegistrationTasks;
+
 }; // class WebSWServerConnection
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (224407 => 224408)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2017-11-03 18:21:46 UTC (rev 224408)
@@ -28,10 +28,12 @@
     RegistrationJobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration)
     UnregistrationJobResolvedInServer(uint64_t identifier, bool unregistrationResult)
     StartScriptFetchForServer(uint64_t jobIdentifier)
-    UpdateRegistrationState(struct WebCore::ServiceWorkerRegistrationKey key, enum WebCore::ServiceWorkerRegistrationState state, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier)
+    UpdateRegistrationState(WebCore::ServiceWorkerRegistrationKey key, enum WebCore::ServiceWorkerRegistrationState state, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier)
 
     SetSWOriginTableSharedMemory(WebKit::SharedMemory::Handle handle)
     PostMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, IPC::DataReference message, WebCore::ServiceWorkerIdentifier sourceServiceWorkerIdentifier, String sourceOrigin)
+
+    DidMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData> data)
 }
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h (224407 => 224408)


--- trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h	2017-11-03 18:05:13 UTC (rev 224407)
+++ trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.h	2017-11-03 18:21:46 UTC (rev 224408)
@@ -46,6 +46,7 @@
     void fetchFinished(uint64_t fetchIdentifier);
 
     void didReceiveServiceWorkerClientFetchMessage(IPC::Connection&, IPC::Decoder&);
+    void didReceiveServiceWorkerClientRegistrationMatch(IPC::Connection&, IPC::Decoder&);
 
 private:
     friend NeverDestroyed<WebServiceWorkerProvider>;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to