Title: [224453] trunk
Revision
224453
Author
cdu...@apple.com
Date
2017-11-03 19:12:06 -0700 (Fri, 03 Nov 2017)

Log Message

Implement ServiceWorkerContainer.getRegistration
https://bugs.webkit.org/show_bug.cgi?id=179253

Patch by Youenn Fablet <you...@apple.com> on 2017-11-03
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/activation.https-expected.txt:
* web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https-expected.txt:
* web-platform-tests/service-workers/service-worker/claim-with-redirect.https-expected.txt:
* web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt:
* web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt:
* web-platform-tests/service-workers/service-worker/navigate-window.https-expected.txt:
* web-platform-tests/service-workers/service-worker/registration-iframe.https-expected.txt:
* web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https-expected.txt:
* web-platform-tests/service-workers/service-worker/synced-state.https-expected.txt:

Source/WebCore:

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

Added a map of ServiceWorkerRegistration in ServiceWorkerContainer.
Removing a similar map from SWClientConnection as it is more convenient to have this map per ScriptExecutionContext.

This map allows returning the same JS object for different getRegistration.
Delegating the actual matching to SWServer::Connection which is implemented on the StorageProcess through IPC.

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::getRegistration):
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
(WebCore::ServiceWorkerContainer::jobDidFinish):
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerContainer.idl:
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
(WebCore::ServiceWorkerRegistration::~ServiceWorkerRegistration):
* workers/service/ServiceWorkerRegistration.h:
* workers/service/server/SWClientConnection.cpp:
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::SWClientConnection::addServiceWorkerRegistration): Deleted.
(WebCore::SWClientConnection::removeServiceWorkerRegistration): Deleted.
* workers/service/server/SWClientConnection.h:

LayoutTests:

* TestExpectations:
* http/tests/workers/service/resources/service-worker-getRegistration-worker.js: Added.
* http/tests/workers/service/resources/service-worker-getRegistration.js: Added.
* http/tests/workers/service/service-worker-getRegistration-expected.txt: Added.
* http/tests/workers/service/service-worker-getRegistration.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (224452 => 224453)


--- trunk/LayoutTests/ChangeLog	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/ChangeLog	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,5 +1,18 @@
 2017-11-03  Youenn Fablet  <you...@apple.com>
 
+        Implement ServiceWorkerContainer.getRegistration
+        https://bugs.webkit.org/show_bug.cgi?id=179253
+
+        Reviewed by Chris Dumez.
+
+        * TestExpectations:
+        * http/tests/workers/service/resources/service-worker-getRegistration-worker.js: Added.
+        * http/tests/workers/service/resources/service-worker-getRegistration.js: Added.
+        * http/tests/workers/service/service-worker-getRegistration-expected.txt: Added.
+        * http/tests/workers/service/service-worker-getRegistration.html: Added.
+
+2017-11-03  Youenn Fablet  <you...@apple.com>
+
         Requests handled by Service Worker should not go through preflighting
         https://bugs.webkit.org/show_bug.cgi?id=179250
 

Modified: trunk/LayoutTests/TestExpectations (224452 => 224453)


--- trunk/LayoutTests/TestExpectations	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/TestExpectations	2017-11-04 02:12:06 UTC (rev 224453)
@@ -172,6 +172,7 @@
 imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html [ Skip ]
 imported/w3c/web-platform-tests/service-workers/service-worker/update-after-oneday.https.html [ Skip ]
 imported/w3c/web-platform-tests/fetch/api/abort/general-serviceworker.https.html [ Skip ]
+imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https.html [ Skip ]
 
 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-cors-xhr.https.html [ Pass Failure ]
 webkit.org/b/179137 imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-match.https.html [ Pass Failure ]

Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration-worker.js (0 => 224453)


--- trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration-worker.js	2017-11-04 02:12:06 UTC (rev 224453)
@@ -0,0 +1 @@
+

Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration.js (0 => 224453)


--- trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration.js	2017-11-04 02:12:06 UTC (rev 224453)
@@ -0,0 +1,73 @@
+function checkRegistration(registration, expected, name)
+{
+    if (registration === expected) {
+        log("PASS: " + name + " is as expected");
+        return;
+    }
+    if (registration === null) {
+        log("FAIL: " + name + " is null");
+        return;
+    }
+
+    if (expected === null) {
+        log("FAIL: " + name + " is not null");
+        return;
+    }
+    log("FAIL: " + name + " is not as expected. Its scope is " + registration.scope + " expected scope is " + expected.scope);
+}
+
+async function test()
+{
+    try {
+        log("Registering service worker 0");
+        var newRegistration0 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js", { scope: "/test1" });
+        log("Service worker 0 registered with scope " + newRegistration0.scope);
+
+        var registration0 = await navigator.serviceWorker.getRegistration();
+        checkRegistration(registration0, undefined, "registration0");
+
+        var registration1 = await navigator.serviceWorker.getRegistration("/test1");
+        checkRegistration(registration1, newRegistration0, "registration1");
+
+        var registration2 = await navigator.serviceWorker.getRegistration("/test");
+        checkRegistration(registration2, undefined, "registration2");
+
+        var registration3 = await navigator.serviceWorker.getRegistration("/test1/test2/test3");
+        checkRegistration(registration3, newRegistration0, "registration3");
+
+        log("Registering service worker 1");
+        var newRegistration1 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js", { scope: "/test1/test2" });
+        log("Service worker 1 registered with scope " + newRegistration1.scope);
+
+        log("Registering service worker 2");
+        var newRegistration2 = await navigator.serviceWorker.register("resources/service-worker-getRegistration-worker.js");
+        log("Service worker 2 registered with scope " + newRegistration2.scope);
+
+        var registration4 = await navigator.serviceWorker.getRegistration("/test1/test2");
+        checkRegistration(registration4, newRegistration1, "registration4");
+
+        var registration5 = await navigator.serviceWorker.getRegistration("/test1/test2-test3");
+        checkRegistration(registration5, newRegistration1, "registration5");
+
+        var registration6 = await navigator.serviceWorker.getRegistration();
+        checkRegistration(registration6, newRegistration2, "registration6");
+
+        var registration7 = await navigator.serviceWorker.getRegistration("");
+        checkRegistration(registration7, newRegistration2, "registration7");
+
+        var registration8 = await navigator.serviceWorker.getRegistration("foo");
+        checkRegistration(registration8, newRegistration2, "registration8");
+
+        var registration9 = await navigator.serviceWorker.getRegistration("/foo");
+        checkRegistration(registration9, undefined, "registration9");
+
+        await newRegistration1.unregister();
+        var registration10 = await navigator.serviceWorker.getRegistration("/test1/test2");
+        checkRegistration(registration10, newRegistration0, "registration10");
+    } catch(e) {
+        log("Got exception: " + e);
+    }
+    finishSWTest();
+}
+
+test();

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


--- trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -0,0 +1,18 @@
+Registering service worker 0
+Service worker 0 registered with scope http://127.0.0.1:8000/test1
+PASS: registration0 is as expected
+PASS: registration1 is as expected
+PASS: registration2 is as expected
+PASS: registration3 is as expected
+Registering service worker 1
+Service worker 1 registered with scope http://127.0.0.1:8000/test1/test2
+Registering service worker 2
+Service worker 2 registered with scope http://127.0.0.1:8000/workers/service/
+PASS: registration4 is as expected
+PASS: registration5 is as expected
+PASS: registration6 is as expected
+PASS: registration7 is as expected
+PASS: registration8 is as expected
+PASS: registration9 is as expected
+PASS: registration10 is as expected
+

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


--- trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration.html	2017-11-04 02:12:06 UTC (rev 224453)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,5 +1,22 @@
 2017-11-03  Youenn Fablet  <you...@apple.com>
 
+        Implement ServiceWorkerContainer.getRegistration
+        https://bugs.webkit.org/show_bug.cgi?id=179253
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/activation.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/claim-with-redirect.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/navigate-window.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/registration-iframe.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/synced-state.https-expected.txt:
+
+2017-11-03  Youenn Fablet  <you...@apple.com>
+
         Implement Service Worker Matching Registration algorithm
         https://bugs.webkit.org/show_bug.cgi?id=178882
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,6 +1,7 @@
 
-FAIL loss of controllees triggers activation promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'document.body.appendChild')"
-FAIL finishing a request triggers activation promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'document.body.appendChild')"
-FAIL skipWaiting bypasses no controllee requirement promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'document.body.appendChild')"
-FAIL finishing a request triggers unregister promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'document.body.appendChild')"
 
+FAIL loss of controllees triggers activation assert_not_equals: got disallowed value null
+FAIL finishing a request triggers activation assert_not_equals: got disallowed value null
+FAIL skipWaiting bypasses no controllee requirement assert_not_equals: got disallowed value null
+FAIL finishing a request triggers unregister assert_not_equals: got disallowed value null
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,4 +1,4 @@
 
 
-FAIL claim() should affect the originally controlling registration. promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'r.active')"
+FAIL claim() should affect the originally controlling registration. assert_equals: Should be the same registration expected object "[object ServiceWorkerRegistration]" but got object "[object ServiceWorkerRegistration]"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 27: Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'r.update')
+CONSOLE MESSAGE: line 27: Unhandled Promise Rejection: NotSupportedError: ServiceWorkerRegistration::update not yet implemented
   
 
 FAIL Claim works after redirection to another origin assert_equals: expected (string) "updated" but got (undefined) undefined

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,7 +1,7 @@
 
-FAIL getRegistration assert_unreached: unexpected rejection: assert_equals: getRegistration should resolve with undefined expected (undefined) undefined but got (object) null Reached unreachable code
-FAIL Register then getRegistration assert_unreached: unexpected rejection: assert_equals: getRegistration should resolve to the same registration object expected object "[object ServiceWorkerRegistration]" but got null Reached unreachable code
-FAIL Register then getRegistration with a URL having a fragment assert_unreached: unexpected rejection: assert_equals: getRegistration should resolve to the same registration object expected object "[object ServiceWorkerRegistration]" but got null Reached unreachable code
-FAIL getRegistration with a cross origin URL assert_unreached: unexpected rejection: assert_unreached: getRegistration with an out of origin URL should fail Reached unreachable code Reached unreachable code
-FAIL Register then Unregister then getRegistration assert_unreached: unexpected rejection: assert_equals: getRegistration should resolve with undefined expected (undefined) undefined but got (object) null Reached unreachable code
+PASS getRegistration 
+PASS Register then getRegistration 
+PASS Register then getRegistration with a URL having a fragment 
+PASS getRegistration with a cross origin URL 
+PASS Register then Unregister then getRegistration 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -2,5 +2,5 @@
 
 PASS register should use the relevant global of the object it was called on to resolve the script URL and the default scope URL 
 PASS register should use the relevant global of the object it was called on to resolve the script URL and the given scope URL 
-FAIL getRegistration should use the relevant global of the object it was called on to resolve the script URL assert_not_equals: the registration from the other frame should not be null got disallowed value null
+PASS getRegistration should use the relevant global of the object it was called on to resolve the script URL 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigate-window.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigate-window.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigate-window.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,4 +1,4 @@
 
-FAIL Clients.matchAll() should not show an old window as controlled after it navigates. assert_unreached: unexpected rejection: null is not an object (evaluating 'reg.active') Reached unreachable code
-FAIL Clients.matchAll() should not show an old window after it navigates. assert_unreached: unexpected rejection: null is not an object (evaluating 'reg.active') Reached unreachable code
+FAIL Clients.matchAll() should not show an old window as controlled after it navigates. assert_unreached: unexpected rejection: null is not an object (evaluating 'sw.postMessage') Reached unreachable code
+FAIL Clients.matchAll() should not show an old window after it navigates. assert_unreached: unexpected rejection: null is not an object (evaluating 'sw.postMessage') Reached unreachable code
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,5 +1,6 @@
 
-FAIL register method should use the "relevant global object" to parse its scriptURL and scope - normal case assert_unreached: unexpected rejection: null is not an object (evaluating 'document.body.appendChild') Reached unreachable code
-FAIL register method should use the "relevant global object" to parse its scriptURL and scope - error case assert_unreached: unexpected rejection: undefined is not an object (evaluating 'frame.remove') Reached unreachable code
-FAIL A scope url should start with the given script url assert_unreached: unexpected rejection: assert_equals: The scope set to a non-subdirectory of the scriptURL should reject with SecurityError expected "SecurityError" but got "TypeError" Reached unreachable code
 
+PASS register method should use the "relevant global object" to parse its scriptURL and scope - normal case 
+FAIL register method should use the "relevant global object" to parse its scriptURL and scope - error case assert_unreached: unexpected rejection: assert_unreached: register() should reject Reached unreachable code Reached unreachable code
+FAIL A scope url should start with the given script url assert_unreached: unexpected rejection: assert_unreached: register() should reject Reached unreachable code Reached unreachable code
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,3 +1,6 @@
 
-FAIL Test skipWaiting while a client is not being controlled promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'document.body.appendChild')"
+Harness Error (TIMEOUT), message = null
 
+PASS Test skipWaiting while a client is not being controlled 
+TIMEOUT skipWaiting Test timed out
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/synced-state.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/synced-state.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/synced-state.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,3 +1,3 @@
 
-FAIL worker objects for the same entity have the same state assert_equals: getRegistration should return the same object expected object "[object ServiceWorkerRegistration]" but got null
+PASS worker objects for the same entity have the same state 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt (224452 => 224453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt	2017-11-04 02:12:06 UTC (rev 224453)
@@ -2,7 +2,7 @@
 
 PASS Unregister then register resolves to a new value 
 FAIL Unregister then register resolves to the original value if the registration is in use. assert_unreached: unexpected rejection: assert_equals: new registration should resolve to the same registration expected object "[object ServiceWorkerRegistration]" but got object "[object ServiceWorkerRegistration]" Reached unreachable code
-FAIL Reloading the last controlled iframe after unregistration should ensure the deletion of the registration assert_unreached: unexpected rejection: assert_equals: getRegistration should return undefined after unregistration expected (undefined) undefined but got (object) null Reached unreachable code
+PASS Reloading the last controlled iframe after unregistration should ensure the deletion of the registration 
 FAIL Unregister then register does not affect existing controllee assert_unreached: unexpected rejection: assert_equals: installing version is null expected null but got object "[object ServiceWorker]" Reached unreachable code
 FAIL Unregister then register resurrects the registration assert_unreached: unexpected rejection: assert_not_equals: document should have a controller got disallowed value null Reached unreachable code
 

Modified: trunk/Source/WebCore/ChangeLog (224452 => 224453)


--- trunk/Source/WebCore/ChangeLog	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/Source/WebCore/ChangeLog	2017-11-04 02:12:06 UTC (rev 224453)
@@ -1,3 +1,34 @@
+2017-11-03  Youenn Fablet  <you...@apple.com>
+
+        Implement ServiceWorkerContainer.getRegistration
+        https://bugs.webkit.org/show_bug.cgi?id=179253
+
+        Reviewed by Chris Dumez.
+
+        Test: http/tests/workers/service/service-worker-getRegistration.html
+
+        Added a map of ServiceWorkerRegistration in ServiceWorkerContainer.
+        Removing a similar map from SWClientConnection as it is more convenient to have this map per ScriptExecutionContext.
+
+        This map allows returning the same JS object for different getRegistration.
+        Delegating the actual matching to SWServer::Connection which is implemented on the StorageProcess through IPC.
+
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::getRegistration):
+        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
+        (WebCore::ServiceWorkerContainer::jobDidFinish):
+        * workers/service/ServiceWorkerContainer.h:
+        * workers/service/ServiceWorkerContainer.idl:
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
+        (WebCore::ServiceWorkerRegistration::~ServiceWorkerRegistration):
+        * workers/service/ServiceWorkerRegistration.h:
+        * workers/service/server/SWClientConnection.cpp:
+        (WebCore::SWClientConnection::updateRegistrationState):
+        (WebCore::SWClientConnection::addServiceWorkerRegistration): Deleted.
+        (WebCore::SWClientConnection::removeServiceWorkerRegistration): Deleted.
+        * workers/service/server/SWClientConnection.h:
+
 2017-11-03  Chris Dumez  <cdu...@apple.com>
 
         [iOS-WK1] Fix thread safety issue in WebSQLiteDatabaseTrackerClient

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (224452 => 224453)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-04 02:12:06 UTC (rev 224453)
@@ -176,13 +176,49 @@
     m_swConnection->scheduleJob(rawJob);
 }
 
-void ServiceWorkerContainer::getRegistration(const String&, RegistrationPromise&& promise)
+void ServiceWorkerContainer::getRegistration(const String& clientURL, Ref<DeferredPromise>&& promise)
 {
-    // FIXME: Implement getRegistration algorithm, for now pretend there is no registration.
-    // https://bugs.webkit.org/show_bug.cgi?id=178882
-    promise.resolve(nullptr);
+    auto* context = scriptExecutionContext();
+    if (!context) {
+        ASSERT_NOT_REACHED();
+        promise->reject(Exception { InvalidStateError });
+        return;
+    }
+
+    URL parsedURL = context->completeURL(clientURL);
+    if (!protocolHostAndPortAreEqual(parsedURL, context->url())) {
+        promise->reject(Exception { SecurityError, ASCIILiteral("Origin of clientURL is not client's origin") });
+        return;
+    }
+
+    if (!m_swConnection)
+        m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context->sessionID());
+
+    return m_swConnection->matchRegistration(context->topOrigin(), parsedURL, [promise = WTFMove(promise), protectingThis = makePendingActivity(*this), this] (auto&& result) mutable {
+        if (m_isStopped)
+            return;
+
+        if (!result) {
+            promise->resolve();
+            return;
+        }
+
+        RefPtr<ServiceWorkerRegistration> registration = m_registrations.get(result->key);
+        if (!registration) {
+            auto& context = *scriptExecutionContext();
+            auto worker = ServiceWorker::create(context, *result->activeServiceWorkerIdentifier, result->scriptURL);
+            registration = ServiceWorkerRegistration::create(context, *this, WTFMove(result.value()), WTFMove(worker));
+        }
+        promise->resolve<IDLInterface<ServiceWorkerRegistration>>(registration.releaseNonNull());
+    });
 }
 
+void ServiceWorkerContainer::updateRegistration(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerIdentifier>& serviceWorkerIdentifier)
+{
+    if (auto* registration = m_registrations.get(key))
+        registration->updateStateFromServer(state, serviceWorkerIdentifier);
+}
+
 void ServiceWorkerContainer::getRegistrations(RegistrationsPromise&& promise)
 {
     // FIXME: Implement getRegistrations algorithm, for now pretend there is no registration.
@@ -251,12 +287,11 @@
     }
 
     activeServiceWorker->setState(ServiceWorker::State::Installing);
-    
-    ASSERT(m_swConnection);
-    auto registration = ServiceWorkerRegistration::create(*context, *m_swConnection, WTFMove(data), *activeServiceWorker);
 
-    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration.get());
+    auto registration = ServiceWorkerRegistration::create(*context, *this, WTFMove(data), *activeServiceWorker);
 
+    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration);
+
     // Use a microtask because we need to make sure this is executed after the promise above is resolved.
     MicrotaskQueue::mainThreadQueue().append(std::make_unique<FakeServiceWorkerInstallMicrotask>(WTFMove(registration)));
 }
@@ -312,7 +347,7 @@
 void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job)
 {
     auto taken = m_jobMap.take(job.data().identifier());
-    ASSERT_UNUSED(taken, !taken || taken.get() == &job);
+    ASSERT_UNUSED(taken, !taken || taken->ptr() == &job);
 }
 
 uint64_t ServiceWorkerContainer::connectionIdentifier()
@@ -328,7 +363,7 @@
 
 bool ServiceWorkerContainer::canSuspendForDocumentSuspension() const
 {
-    return true;
+    return !hasPendingActivity();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (224452 => 224453)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2017-11-04 02:12:06 UTC (rev 224453)
@@ -62,12 +62,15 @@
     void addRegistration(const String& scriptURL, const RegistrationOptions&, Ref<DeferredPromise>&&);
     void removeRegistration(const URL& scopeURL, Ref<DeferredPromise>&&);
 
-    using RegistrationPromise = DOMPromiseDeferred<IDLNullable<IDLInterface<ServiceWorkerRegistration>>>;
-    void getRegistration(const String& clientURL, RegistrationPromise&&);
+    void getRegistration(const String& clientURL, Ref<DeferredPromise>&&);
+    void updateRegistration(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerIdentifier>&);
 
     using RegistrationsPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<ServiceWorkerRegistration>>>;
     void getRegistrations(RegistrationsPromise&&);
 
+    void addRegistration(ServiceWorkerRegistration& registration) { m_registrations.add(registration.data().key, &registration); }
+    void removeRegistration(ServiceWorkerRegistration& registration)  { m_registrations.remove(registration.data().key); }
+
     void startMessages();
 
     void ref() final { refEventTarget(); }
@@ -93,6 +96,7 @@
     EventTargetInterface eventTargetInterface() const final { return ServiceWorkerContainerEventTargetInterfaceType; }
     void refEventTarget() final;
     void derefEventTarget() final;
+    void stop() final { m_isStopped = true; }
 
     ReadyPromise m_readyPromise;
 
@@ -99,8 +103,11 @@
     NavigatorBase& m_navigator;
 
     RefPtr<SWClientConnection> m_swConnection;
-    HashMap<uint64_t, RefPtr<ServiceWorkerJob>> m_jobMap;
+    HashMap<uint64_t, Ref<ServiceWorkerJob>> m_jobMap;
 
+    bool m_isStopped { false };
+    HashMap<ServiceWorkerRegistrationKey, ServiceWorkerRegistration*> m_registrations;
+
 #ifndef NDEBUG
     ThreadIdentifier m_creationThread { currentThread() };
 #endif

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (224452 => 224453)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2017-11-04 02:12:06 UTC (rev 224453)
@@ -36,20 +36,19 @@
 
 namespace WebCore {
 
-ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, SWClientConnection& connection, ServiceWorkerRegistrationData&& registrationData, Ref<ServiceWorker>&& serviceWorker)
+ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, Ref<ServiceWorkerContainer>&& container, ServiceWorkerRegistrationData&& registrationData, Ref<ServiceWorker>&& serviceWorker)
     : ActiveDOMObject(&context)
     , m_registrationData(WTFMove(registrationData))
     , m_serviceWorker(WTFMove(serviceWorker))
-    , m_connection(connection)
+    , m_container(WTFMove(container))
 {
     suspendIfNeeded();
-
-    m_connection->addServiceWorkerRegistration(*this);
+    m_container->addRegistration(*this);
 }
 
 ServiceWorkerRegistration::~ServiceWorkerRegistration()
 {
-    m_connection->removeServiceWorkerRegistration(*this);
+    m_container->removeRegistration(*this);
 }
 
 ServiceWorker* ServiceWorkerRegistration::installing()

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h (224452 => 224453)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h	2017-11-04 02:12:06 UTC (rev 224453)
@@ -38,6 +38,7 @@
 
 class ScriptExecutionContext;
 class ServiceWorker;
+class ServiceWorkerContainer;
 
 class ServiceWorkerRegistration final : public RefCounted<ServiceWorkerRegistration>, public EventTargetWithInlineData, public ActiveDOMObject, public ThreadSafeIdentified<ServiceWorkerRegistration> {
 public:
@@ -66,7 +67,7 @@
     void updateStateFromServer(ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>);
 
 private:
-    ServiceWorkerRegistration(ScriptExecutionContext&, SWClientConnection&, ServiceWorkerRegistrationData&&, Ref<ServiceWorker>&&);
+    ServiceWorkerRegistration(ScriptExecutionContext&, Ref<ServiceWorkerContainer>&&, ServiceWorkerRegistrationData&&, Ref<ServiceWorker>&&);
 
     EventTargetInterface eventTargetInterface() const final;
     ScriptExecutionContext* scriptExecutionContext() const final;
@@ -78,7 +79,7 @@
 
     ServiceWorkerRegistrationData m_registrationData;
     Ref<ServiceWorker> m_serviceWorker;
-    Ref<SWClientConnection> m_connection;
+    Ref<ServiceWorkerContainer> m_container;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp (224452 => 224453)


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-11-04 02:12:06 UTC (rev 224453)
@@ -64,32 +64,6 @@
     finishFetchingScriptInServer({ job.data().identifier(), job.data().connectionIdentifier(), job.data().registrationKey(), { }, error });
 }
 
-void SWClientConnection::addServiceWorkerRegistration(ServiceWorkerRegistration& registration)
-{
-    auto result = m_registrations.ensure(registration.data().key, [] {
-        return std::make_unique<HashSet<ServiceWorkerRegistration*>>();
-    });
-
-    ASSERT(!result.iterator->value->contains(&registration));
-    result.iterator->value->add(&registration);
-    
-    addServiceWorkerRegistrationInServer(registration.data().key, registration.identifier());
-}
-
-void SWClientConnection::removeServiceWorkerRegistration(ServiceWorkerRegistration& registration)
-{
-    auto iterator = m_registrations.find(registration.data().key);
-
-    ASSERT(iterator != m_registrations.end());
-    ASSERT(iterator->value && iterator->value->contains(&registration));
-    iterator->value->remove(&registration);
-
-    if (iterator->value->isEmpty())
-        m_registrations.remove(iterator);
-
-    removeServiceWorkerRegistrationInServer(registration.data().key, registration.identifier());
-}
-    
 void SWClientConnection::jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData& exceptionData)
 {
     auto job = m_scheduledJobs.take(jobIdentifier);
@@ -166,12 +140,11 @@
 
 void SWClientConnection::updateRegistrationState(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
 {
-    auto* registrations = m_registrations.get(key);
-    if (!registrations)
-        return;
-    
-    for (auto& registration : *registrations)
-        registration->updateStateFromServer(state, serviceWorkerIdentifier);
+    // FIXME: We should iterate over all service worker clients, not only documents.
+    for (auto& document : Document::allDocuments()) {
+        if (auto* container = document->serviceWorkerContainer())
+            container->updateRegistration(key, state, serviceWorkerIdentifier);
+    }
 }
 
 } // namespace WebCore

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


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-04 02:12:06 UTC (rev 224453)
@@ -53,8 +53,6 @@
     void scheduleJob(ServiceWorkerJob&);
     void finishedFetchingScript(ServiceWorkerJob&, const String&);
     void failedFetchingScript(ServiceWorkerJob&, const ResourceError&);
-    void addServiceWorkerRegistration(ServiceWorkerRegistration&);
-    void removeServiceWorkerRegistration(ServiceWorkerRegistration&);
 
     virtual void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&&, ScriptExecutionContext& source) = 0;
     virtual uint64_t identifier() const = 0;
@@ -77,7 +75,6 @@
     virtual void removeServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, uint64_t registrationIdentifier) = 0;
 
     HashMap<uint64_t, RefPtr<ServiceWorkerJob>> m_scheduledJobs;
-    HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<HashSet<ServiceWorkerRegistration*>>> m_registrations;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to