<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[224453] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/224453">224453</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2017-11-03 19:12:06 -0700 (Fri, 03 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement ServiceWorkerContainer.getRegistration
https://bugs.webkit.org/show_bug.cgi?id=179253

Patch by Youenn Fablet <youenn@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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsTestExpectations">trunk/LayoutTests/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkeractivationhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerclaimaffectotherregistrationhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerclaimwithredirecthttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkergetregistrationhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkermultiglobalsurlparsinghttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkernavigatewindowhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigate-window.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerregistrationiframehttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerskipwaitingwithoutusingregistrationhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkersyncedstatehttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/synced-state.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerunregisterthenregisterhttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerContainercpp">trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerContainerh">trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationcpp">trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationh">trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWClientConnectioncpp">trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWClientConnectionh">trunk/Source/WebCore/workers/service/server/SWClientConnection.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsworkersserviceresourcesserviceworkergetRegistrationworkerjs">trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration-worker.js</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceresourcesserviceworkergetRegistrationjs">trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration.js</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceserviceworkergetRegistrationexpectedtxt">trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceserviceworkergetRegistrationhtml">trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/ChangeLog 2017-11-04 02:12:06 UTC (rev 224453)
</span><span class="lines">@@ -1,5 +1,18 @@
</span><span class="cx"> 2017-11-03  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><ins>+        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  <youenn@apple.com>
+
</ins><span class="cx">         Requests handled by Service Worker should not go through preflighting
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=179250
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/TestExpectations (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/TestExpectations       2017-11-04 01:57:57 UTC (rev 224452)
+++ trunk/LayoutTests/TestExpectations  2017-11-04 02:12:06 UTC (rev 224453)
</span><span class="lines">@@ -172,6 +172,7 @@
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/update-after-oneday.https.html [ Skip ]
</span><span class="cx"> imported/w3c/web-platform-tests/fetch/api/abort/general-serviceworker.https.html [ Skip ]
</span><ins>+imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https.html [ Skip ]
</ins><span class="cx"> 
</span><span class="cx"> imported/w3c/web-platform-tests/service-workers/service-worker/fetch-cors-xhr.https.html [ Pass Failure ]
</span><span class="cx"> webkit.org/b/179137 imported/w3c/web-platform-tests/service-workers/cache-storage/serviceworker/cache-match.https.html [ Pass Failure ]
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceresourcesserviceworkergetRegistrationworkerjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration-worker.js (0 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceresourcesserviceworkergetRegistrationjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/resources/service-worker-getRegistration.js (0 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,73 @@
</span><ins>+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();
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceserviceworkergetRegistrationexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration-expected.txt (0 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceserviceworkergetRegistrationhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/service-worker-getRegistration.html (0 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+<html>
+<head>
+<script src="resources/sw-test-pre.js"></script>
+</head>
+<body>
+
+<script src="resources/service-worker-getRegistration.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,22 @@
</span><span class="cx"> 2017-11-03  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><ins>+        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  <youenn@apple.com>
+
</ins><span class="cx">         Implement Service Worker Matching Registration algorithm
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=178882
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkeractivationhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,6 +1,7 @@
</span><span class="cx"> 
</span><del>-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')"
</del><span class="cx"> 
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerclaimaffectotherregistrationhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-FAIL claim() should affect the originally controlling registration. promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'r.active')"
</del><ins>+FAIL claim() should affect the originally controlling registration. assert_equals: Should be the same registration expected object "[object ServiceWorkerRegistration]" but got object "[object ServiceWorkerRegistration]"
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerclaimwithredirecthttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-CONSOLE MESSAGE: line 27: Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'r.update')
</del><ins>+CONSOLE MESSAGE: line 27: Unhandled Promise Rejection: NotSupportedError: ServiceWorkerRegistration::update not yet implemented
</ins><span class="cx">   
</span><span class="cx"> 
</span><span class="cx"> FAIL Claim works after redirection to another origin assert_equals: expected (string) "updated" but got (undefined) undefined
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkergetregistrationhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistration.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> 
</span><del>-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
</del><ins>+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 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkermultiglobalsurlparsinghttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multi-globals/url-parsing.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,5 +2,5 @@
</span><span class="cx"> 
</span><span class="cx"> PASS register should use the relevant global of the object it was called on to resolve the script URL and the default scope URL 
</span><span class="cx"> PASS register should use the relevant global of the object it was called on to resolve the script URL and the given scope URL 
</span><del>-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
</del><ins>+PASS getRegistration should use the relevant global of the object it was called on to resolve the script URL 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkernavigatewindowhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigate-window.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><span class="cx"> 
</span><del>-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
</del><ins>+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
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerregistrationiframehttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-iframe.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,6 @@
</span><span class="cx"> 
</span><del>-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
</del><span class="cx"> 
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerskipwaitingwithoutusingregistrationhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting-without-using-registration.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,6 @@
</span><span class="cx"> 
</span><del>-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')"
</del><ins>+Harness Error (TIMEOUT), message = null
</ins><span class="cx"> 
</span><ins>+PASS Test skipWaiting while a client is not being controlled 
+TIMEOUT skipWaiting Test timed out
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkersyncedstatehttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/synced-state.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,3 @@
</span><span class="cx"> 
</span><del>-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
</del><ins>+PASS worker objects for the same entity have the same state 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerunregisterthenregisterhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https-expected.txt (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> 
</span><span class="cx"> PASS Unregister then register resolves to a new value 
</span><span class="cx"> 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
</span><del>-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
</del><ins>+PASS Reloading the last controlled iframe after unregistration should ensure the deletion of the registration 
</ins><span class="cx"> 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
</span><span class="cx"> 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
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2017-11-03  Youenn Fablet  <youenn@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:
+
</ins><span class="cx"> 2017-11-03  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [iOS-WK1] Fix thread safety issue in WebSQLiteDatabaseTrackerClient
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContainercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -176,13 +176,49 @@
</span><span class="cx">     m_swConnection->scheduleJob(rawJob);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ServiceWorkerContainer::getRegistration(const String&, RegistrationPromise&& promise)
</del><ins>+void ServiceWorkerContainer::getRegistration(const String& clientURL, Ref<DeferredPromise>&& promise)
</ins><span class="cx"> {
</span><del>-    // FIXME: Implement getRegistration algorithm, for now pretend there is no registration.
-    // https://bugs.webkit.org/show_bug.cgi?id=178882
-    promise.resolve(nullptr);
</del><ins>+    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());
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ServiceWorkerContainer::updateRegistration(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerIdentifier>& serviceWorkerIdentifier)
+{
+    if (auto* registration = m_registrations.get(key))
+        registration->updateStateFromServer(state, serviceWorkerIdentifier);
+}
+
</ins><span class="cx"> void ServiceWorkerContainer::getRegistrations(RegistrationsPromise&& promise)
</span><span class="cx"> {
</span><span class="cx">     // FIXME: Implement getRegistrations algorithm, for now pretend there is no registration.
</span><span class="lines">@@ -251,12 +287,11 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     activeServiceWorker->setState(ServiceWorker::State::Installing);
</span><del>-    
-    ASSERT(m_swConnection);
-    auto registration = ServiceWorkerRegistration::create(*context, *m_swConnection, WTFMove(data), *activeServiceWorker);
</del><span class="cx"> 
</span><del>-    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration.get());
</del><ins>+    auto registration = ServiceWorkerRegistration::create(*context, *this, WTFMove(data), *activeServiceWorker);
</ins><span class="cx"> 
</span><ins>+    job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(registration);
+
</ins><span class="cx">     // Use a microtask because we need to make sure this is executed after the promise above is resolved.
</span><span class="cx">     MicrotaskQueue::mainThreadQueue().append(std::make_unique<FakeServiceWorkerInstallMicrotask>(WTFMove(registration)));
</span><span class="cx"> }
</span><span class="lines">@@ -312,7 +347,7 @@
</span><span class="cx"> void ServiceWorkerContainer::jobDidFinish(ServiceWorkerJob& job)
</span><span class="cx"> {
</span><span class="cx">     auto taken = m_jobMap.take(job.data().identifier());
</span><del>-    ASSERT_UNUSED(taken, !taken || taken.get() == &job);
</del><ins>+    ASSERT_UNUSED(taken, !taken || taken->ptr() == &job);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> uint64_t ServiceWorkerContainer::connectionIdentifier()
</span><span class="lines">@@ -328,7 +363,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool ServiceWorkerContainer::canSuspendForDocumentSuspension() const
</span><span class="cx"> {
</span><del>-    return true;
</del><ins>+    return !hasPendingActivity();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContainerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -62,12 +62,15 @@
</span><span class="cx">     void addRegistration(const String& scriptURL, const RegistrationOptions&, Ref<DeferredPromise>&&);
</span><span class="cx">     void removeRegistration(const URL& scopeURL, Ref<DeferredPromise>&&);
</span><span class="cx"> 
</span><del>-    using RegistrationPromise = DOMPromiseDeferred<IDLNullable<IDLInterface<ServiceWorkerRegistration>>>;
-    void getRegistration(const String& clientURL, RegistrationPromise&&);
</del><ins>+    void getRegistration(const String& clientURL, Ref<DeferredPromise>&&);
+    void updateRegistration(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerIdentifier>&);
</ins><span class="cx"> 
</span><span class="cx">     using RegistrationsPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<ServiceWorkerRegistration>>>;
</span><span class="cx">     void getRegistrations(RegistrationsPromise&&);
</span><span class="cx"> 
</span><ins>+    void addRegistration(ServiceWorkerRegistration& registration) { m_registrations.add(registration.data().key, &registration); }
+    void removeRegistration(ServiceWorkerRegistration& registration)  { m_registrations.remove(registration.data().key); }
+
</ins><span class="cx">     void startMessages();
</span><span class="cx"> 
</span><span class="cx">     void ref() final { refEventTarget(); }
</span><span class="lines">@@ -93,6 +96,7 @@
</span><span class="cx">     EventTargetInterface eventTargetInterface() const final { return ServiceWorkerContainerEventTargetInterfaceType; }
</span><span class="cx">     void refEventTarget() final;
</span><span class="cx">     void derefEventTarget() final;
</span><ins>+    void stop() final { m_isStopped = true; }
</ins><span class="cx"> 
</span><span class="cx">     ReadyPromise m_readyPromise;
</span><span class="cx"> 
</span><span class="lines">@@ -99,8 +103,11 @@
</span><span class="cx">     NavigatorBase& m_navigator;
</span><span class="cx"> 
</span><span class="cx">     RefPtr<SWClientConnection> m_swConnection;
</span><del>-    HashMap<uint64_t, RefPtr<ServiceWorkerJob>> m_jobMap;
</del><ins>+    HashMap<uint64_t, Ref<ServiceWorkerJob>> m_jobMap;
</ins><span class="cx"> 
</span><ins>+    bool m_isStopped { false };
+    HashMap<ServiceWorkerRegistrationKey, ServiceWorkerRegistration*> m_registrations;
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx">     ThreadIdentifier m_creationThread { currentThread() };
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -36,20 +36,19 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, SWClientConnection& connection, ServiceWorkerRegistrationData&& registrationData, Ref<ServiceWorker>&& serviceWorker)
</del><ins>+ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, Ref<ServiceWorkerContainer>&& container, ServiceWorkerRegistrationData&& registrationData, Ref<ServiceWorker>&& serviceWorker)
</ins><span class="cx">     : ActiveDOMObject(&context)
</span><span class="cx">     , m_registrationData(WTFMove(registrationData))
</span><span class="cx">     , m_serviceWorker(WTFMove(serviceWorker))
</span><del>-    , m_connection(connection)
</del><ins>+    , m_container(WTFMove(container))
</ins><span class="cx"> {
</span><span class="cx">     suspendIfNeeded();
</span><del>-
-    m_connection->addServiceWorkerRegistration(*this);
</del><ins>+    m_container->addRegistration(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ServiceWorkerRegistration::~ServiceWorkerRegistration()
</span><span class="cx"> {
</span><del>-    m_connection->removeServiceWorkerRegistration(*this);
</del><ins>+    m_container->removeRegistration(*this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ServiceWorker* ServiceWorkerRegistration::installing()
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> 
</span><span class="cx"> class ScriptExecutionContext;
</span><span class="cx"> class ServiceWorker;
</span><ins>+class ServiceWorkerContainer;
</ins><span class="cx"> 
</span><span class="cx"> class ServiceWorkerRegistration final : public RefCounted<ServiceWorkerRegistration>, public EventTargetWithInlineData, public ActiveDOMObject, public ThreadSafeIdentified<ServiceWorkerRegistration> {
</span><span class="cx"> public:
</span><span class="lines">@@ -66,7 +67,7 @@
</span><span class="cx">     void updateStateFromServer(ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    ServiceWorkerRegistration(ScriptExecutionContext&, SWClientConnection&, ServiceWorkerRegistrationData&&, Ref<ServiceWorker>&&);
</del><ins>+    ServiceWorkerRegistration(ScriptExecutionContext&, Ref<ServiceWorkerContainer>&&, ServiceWorkerRegistrationData&&, Ref<ServiceWorker>&&);
</ins><span class="cx"> 
</span><span class="cx">     EventTargetInterface eventTargetInterface() const final;
</span><span class="cx">     ScriptExecutionContext* scriptExecutionContext() const final;
</span><span class="lines">@@ -78,7 +79,7 @@
</span><span class="cx"> 
</span><span class="cx">     ServiceWorkerRegistrationData m_registrationData;
</span><span class="cx">     Ref<ServiceWorker> m_serviceWorker;
</span><del>-    Ref<SWClientConnection> m_connection;
</del><ins>+    Ref<ServiceWorkerContainer> m_container;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWClientConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -64,32 +64,6 @@
</span><span class="cx">     finishFetchingScriptInServer({ job.data().identifier(), job.data().connectionIdentifier(), job.data().registrationKey(), { }, error });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-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());
-}
-    
</del><span class="cx"> void SWClientConnection::jobRejectedInServer(uint64_t jobIdentifier, const ExceptionData& exceptionData)
</span><span class="cx"> {
</span><span class="cx">     auto job = m_scheduledJobs.take(jobIdentifier);
</span><span class="lines">@@ -166,12 +140,11 @@
</span><span class="cx"> 
</span><span class="cx"> void SWClientConnection::updateRegistrationState(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
</span><span class="cx"> {
</span><del>-    auto* registrations = m_registrations.get(key);
-    if (!registrations)
-        return;
-    
-    for (auto& registration : *registrations)
-        registration->updateStateFromServer(state, serviceWorkerIdentifier);
</del><ins>+    // 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);
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWClientConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.h (224452 => 224453)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -53,8 +53,6 @@
</span><span class="cx">     void scheduleJob(ServiceWorkerJob&);
</span><span class="cx">     void finishedFetchingScript(ServiceWorkerJob&, const String&);
</span><span class="cx">     void failedFetchingScript(ServiceWorkerJob&, const ResourceError&);
</span><del>-    void addServiceWorkerRegistration(ServiceWorkerRegistration&);
-    void removeServiceWorkerRegistration(ServiceWorkerRegistration&);
</del><span class="cx"> 
</span><span class="cx">     virtual void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&&, ScriptExecutionContext& source) = 0;
</span><span class="cx">     virtual uint64_t identifier() const = 0;
</span><span class="lines">@@ -77,7 +75,6 @@
</span><span class="cx">     virtual void removeServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, uint64_t registrationIdentifier) = 0;
</span><span class="cx"> 
</span><span class="cx">     HashMap<uint64_t, RefPtr<ServiceWorkerJob>> m_scheduledJobs;
</span><del>-    HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<HashSet<ServiceWorkerRegistration*>>> m_registrations;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>

</body>
</html>