<!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>[225537] 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/225537">225537</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-12-05 13:51:42 -0800 (Tue, 05 Dec 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement https://w3c.github.io/ServiceWorker/#clients-claim
https://bugs.webkit.org/show_bug.cgi?id=180261

Patch by Youenn Fablet <youenn@apple.com> on 2017-12-05
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/activation.https-expected.txt:

Source/WebCore:

Test: http/tests/workers/service/serviceworkerclients-claim.https.html

Implement claim by going to the storage process and then iterate over clients to see whether active worker can be set.
Update SWServerWorker to call registration tryClear/tryActivate whenever a service worker has no pending event.

* workers/service/ServiceWorkerClients.cpp:
(WebCore::ServiceWorkerClients::claim):
* workers/service/context/SWContextManager.h:
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::claim):
(WebCore::SWServer::doRegistrationMatching):
(WebCore::SWServer::doRegistrationMatching const): Deleted.
* workers/service/server/SWServer.h:
(WebCore::SWServer::Connection::doRegistrationMatching):
* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::controlClient):
* workers/service/server/SWServerRegistration.h:
* workers/service/server/SWServerToContextConnection.cpp:
(WebCore::SWServerToContextConnection::claim):
* workers/service/server/SWServerToContextConnection.h:
* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::claim):
* workers/service/server/SWServerWorker.h:

Source/WebKit:

Add IPC plumbery for clients claim between ServiceWorker process and Storage process.

* StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
(WebKit::WebSWServerToContextConnection::claimCompleted):
* StorageProcess/ServiceWorker/WebSWServerToContextConnection.h:
* StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::claim):
(WebKit::WebSWContextManagerConnection::claimCompleted):
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:

LayoutTests:

* http/tests/workers/service/serviceworkerclients-claim-worker.js: Added.
* http/tests/workers/service/serviceworkerclients-claim.https-expected.txt: Added.
* http/tests/workers/service/serviceworkerclients-claim.https.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</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="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceSWClientConnectioncpp">trunk/Source/WebCore/workers/service/SWClientConnection.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerClientscpp">trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersservicecontextSWContextManagerh">trunk/Source/WebCore/workers/service/context/SWContextManager.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServercpp">trunk/Source/WebCore/workers/service/server/SWServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerh">trunk/Source/WebCore/workers/service/server/SWServer.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerRegistrationcpp">trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerRegistrationh">trunk/Source/WebCore/workers/service/server/SWServerRegistration.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerToContextConnectioncpp">trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerToContextConnectionh">trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerWorkercpp">trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerWorkerh">trunk/Source/WebCore/workers/service/server/SWServerWorker.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerToContextConnectioncpp">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerToContextConnectionh">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerToContextConnectionmessagesin">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectioncpp">trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionh">trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionmessagesin">trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsworkersserviceserviceworkerclientsclaimworkerjs">trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim-worker.js</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceserviceworkerclientsclaimhttpsexpectedtxt">trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsworkersserviceserviceworkerclientsclaimhttpshtml">trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/LayoutTests/ChangeLog 2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -1,5 +1,16 @@
</span><span class="cx"> 2017-12-05  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><ins>+        Implement https://w3c.github.io/ServiceWorker/#clients-claim
+        https://bugs.webkit.org/show_bug.cgi?id=180261
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/workers/service/serviceworkerclients-claim-worker.js: Added.
+        * http/tests/workers/service/serviceworkerclients-claim.https-expected.txt: Added.
+        * http/tests/workers/service/serviceworkerclients-claim.https.html: Added.
+
+2017-12-05  Youenn Fablet  <youenn@apple.com>
+
</ins><span class="cx">         Unskip some more Service Worker tests
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=180428
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceserviceworkerclientsclaimworkerjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim-worker.js (0 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim-worker.js                                (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim-worker.js   2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -0,0 +1,34 @@
</span><ins>+self.addEventListener("fetch", async (event) => {
+    if (event.request.url.indexOf("pinkelephant") !== -1)
+        event.respondWith(new Response("PASS"));
+});
+
+var tryClaimPromise = self.clients.claim().then(() => {
+    return "FAIL: claim did not throw";
+}, (e) => {
+    return "PASS, received exception " + e;
+});
+
+async function doTest(event)
+{
+    if (event.data !== "start") {
+        event.source.postMessage("FAIL: received unexpected message from client");
+        return;
+    }
+
+    var result = await tryClaimPromise;
+    if (!result.startsWith("PASS")) {
+        event.source.postMessage(result);
+        return;
+    }
+
+    self.clients.claim().then(() => {
+        event.source.postMessage("CLAIMED");
+    }, () => {
+        event.source.postMessage("FAIL: received exception " + e);
+    });
+}
+
+
+self.addEventListener("message", doTest);
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceserviceworkerclientsclaimhttpsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https-expected.txt (0 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https-expected.txt                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https-expected.txt  2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+
+PASS Setup worker 
+PASS Test self.clients.claim 
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsworkersserviceserviceworkerclientsclaimhttpshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https.html (0 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https.html                               (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/serviceworkerclients-claim.https.html  2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -0,0 +1,52 @@
</span><ins>+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+var scope = "/workers/service/serviceworkerclients-claim.https.html";
+var activeWorker;
+
+promise_test(async (test) => {
+    var registration = await navigator.serviceWorker.getRegistration(scope);
+    if (registration && registration.scope === scope)
+        await registration.unregister();
+
+    var registration = await navigator.serviceWorker.register("serviceworkerclients-claim-worker.js", { scope : scope });
+    activeWorker = registration.active;
+    if (activeWorker)
+        return;
+    activeWorker = registration.installing;
+    return new Promise(resolve => {
+        activeWorker.addEventListener('statechange', () => {
+            if (activeWorker.state === "activated")
+                resolve();
+        });
+    });
+}, "Setup worker");
+
+promise_test(async (test) => {
+    var promise = new Promise((resolve, reject) => {
+        navigator.serviceWorker.addEventListener("message", test.step_func((event) => {
+            if (event.data === "CLAIMED") {
+                resolve();
+                return;
+            }
+            if (!event.data.startsWith("PASS")) {
+                reject(event.data);
+                return;
+            }
+        }));
+    });
+
+    activeWorker.postMessage("start");
+    await promise;
+
+    var response = await fetch("pinkelephant");
+    var text = await response.text();
+    assert_equals(text, "PASS");
+}, "Test self.clients.claim");
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -1,5 +1,14 @@
</span><span class="cx"> 2017-12-05  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><ins>+        Implement https://w3c.github.io/ServiceWorker/#clients-claim
+        https://bugs.webkit.org/show_bug.cgi?id=180261
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/activation.https-expected.txt:
+
+2017-12-05  Youenn Fablet  <youenn@apple.com>
+
</ins><span class="cx">         Unskip some more Service Worker tests
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=180428
</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 (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt   2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/activation.https-expected.txt      2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-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
</del><ins>+PASS loss of controllees triggers activation 
+PASS finishing a request triggers activation 
+PASS skipWaiting bypasses no controllee requirement 
+FAIL finishing a request triggers unregister assert_equals: expected null but got object "[object ServiceWorker]"
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/ChangeLog      2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2017-12-05  Youenn Fablet  <youenn@apple.com>
+
+        Implement https://w3c.github.io/ServiceWorker/#clients-claim
+        https://bugs.webkit.org/show_bug.cgi?id=180261
+
+        Reviewed by Chris Dumez.
+
+        Test: http/tests/workers/service/serviceworkerclients-claim.https.html
+
+        Implement claim by going to the storage process and then iterate over clients to see whether active worker can be set.
+        Update SWServerWorker to call registration tryClear/tryActivate whenever a service worker has no pending event.
+
+        * workers/service/ServiceWorkerClients.cpp:
+        (WebCore::ServiceWorkerClients::claim):
+        * workers/service/context/SWContextManager.h:
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::claim):
+        (WebCore::SWServer::doRegistrationMatching):
+        (WebCore::SWServer::doRegistrationMatching const): Deleted.
+        * workers/service/server/SWServer.h:
+        (WebCore::SWServer::Connection::doRegistrationMatching):
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::SWServerRegistration::controlClient):
+        * workers/service/server/SWServerRegistration.h:
+        * workers/service/server/SWServerToContextConnection.cpp:
+        (WebCore::SWServerToContextConnection::claim):
+        * workers/service/server/SWServerToContextConnection.h:
+        * workers/service/server/SWServerWorker.cpp:
+        (WebCore::SWServerWorker::claim):
+        * workers/service/server/SWServerWorker.h:
+
</ins><span class="cx"> 2017-12-05  Per Arne Vollan  <pvollan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [Win] Scrollbars are sometimes not rendered in accelerated compositing mode.
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceSWClientConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/SWClientConnection.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/SWClientConnection.cpp      2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/SWClientConnection.cpp 2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -218,8 +218,7 @@
</span><span class="cx">         if (!client)
</span><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        ASSERT(client->activeServiceWorker());
-        ASSERT(client->activeServiceWorker()->identifier() != newController.identifier);
</del><ins>+        ASSERT(!client->activeServiceWorker() || client->activeServiceWorker()->identifier() != newController.identifier);
</ins><span class="cx">         client->setActiveServiceWorker(ServiceWorker::getOrCreate(*client, ServiceWorkerData { newController }));
</span><span class="cx">         if (auto* container = client->serviceWorkerContainer())
</span><span class="cx">             container->scheduleTaskToFireControllerChangeEvent();
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerClientscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp    2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClients.cpp       2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -107,9 +107,29 @@
</span><span class="cx">     promise->reject(Exception { NotSupportedError, ASCIILiteral("clients.openWindow() is not yet supported") });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ServiceWorkerClients::claim(ScriptExecutionContext&, Ref<DeferredPromise>&& promise)
</del><ins>+void ServiceWorkerClients::claim(ScriptExecutionContext& context, Ref<DeferredPromise>&& promise)
</ins><span class="cx"> {
</span><del>-    promise->reject(Exception { NotSupportedError, ASCIILiteral("clients.claim() is not yet supported") });
</del><ins>+    auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
+
+    auto serviceWorkerIdentifier = serviceWorkerGlobalScope.thread().identifier();
+
+    if (!serviceWorkerGlobalScope.registration().active() || serviceWorkerGlobalScope.registration().active()->identifier() != serviceWorkerIdentifier) {
+        promise->reject(Exception { InvalidStateError, ASCIILiteral("Service worker is not active") });
+        return;
+    }
+
+    auto promisePointer = promise.ptr();
+    m_pendingPromises.add(promisePointer, WTFMove(promise));
+
+    callOnMainThread([promisePointer, serviceWorkerIdentifier] () mutable {
+        auto connection = SWContextManager::singleton().connection();
+        connection->claim(serviceWorkerIdentifier, [promisePointer, serviceWorkerIdentifier] () mutable {
+            SWContextManager::singleton().postTaskToServiceWorker(serviceWorkerIdentifier, [promisePointer] (auto& scope) mutable {
+                if (auto promise = scope.clients().m_pendingPromises.take(promisePointer))
+                    promise.value()->resolve();
+            });
+        });
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersservicecontextSWContextManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/context/SWContextManager.h  2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h     2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">         using FindClientByIdentifierCallback = WTF::CompletionHandler<void(ExceptionOr<std::optional<ServiceWorkerClientData>>&&)>;
</span><span class="cx">         virtual void findClientByIdentifier(ServiceWorkerIdentifier, ServiceWorkerClientIdentifier, FindClientByIdentifierCallback&&) = 0;
</span><span class="cx">         virtual void matchAll(ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&) = 0;
</span><ins>+        virtual void claim(ServiceWorkerIdentifier, WTF::CompletionHandler<void()>&&) = 0;
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp    2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -344,6 +344,31 @@
</span><span class="cx">     callback(WTFMove(clients));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SWServer::claim(SWServerWorker& worker)
+{
+    auto& origin = worker.origin();
+    auto iterator = m_clients.find(origin);
+    if (iterator == m_clients.end())
+        return;
+
+    auto& clients = iterator->value.clients;
+    for (auto& client : clients) {
+        auto* registration = doRegistrationMatching(origin.topOrigin, client.data.url);
+        if (!(registration && registration->key() == worker.registrationKey()))
+            continue;
+
+        auto result = m_clientToControllingWorker.add(client.identifier, worker.identifier());
+        if (!result.isNewEntry) {
+            if (result.iterator->value == worker.identifier())
+                continue;
+            if (auto* controllingRegistration = registrationFromServiceWorkerIdentifier(result.iterator->value))
+                controllingRegistration->removeClientUsingRegistration(client.identifier);
+            result.iterator->value = worker.identifier();
+        }
+        registration->controlClient(client.identifier);
+    }
+}
+
</ins><span class="cx"> void SWServer::didResolveRegistrationPromise(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey)
</span><span class="cx"> {
</span><span class="cx">     ASSERT_UNUSED(connection, m_connections.contains(connection.identifier()));
</span><span class="lines">@@ -566,9 +591,9 @@
</span><span class="cx">         registration->unregisterServerConnection(connection.identifier());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-const SWServerRegistration* SWServer::doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const
</del><ins>+SWServerRegistration* SWServer::doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL)
</ins><span class="cx"> {
</span><del>-    const SWServerRegistration* selectedRegistration = nullptr;
</del><ins>+    SWServerRegistration* selectedRegistration = nullptr;
</ins><span class="cx">     for (auto& registration : m_registrations.values()) {
</span><span class="cx">         if (!registration->key().isMatching(topOrigin, clientURL))
</span><span class="cx">             continue;
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.h   2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h      2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -74,7 +74,7 @@
</span><span class="cx">         Identifier identifier() const { return m_identifier; }
</span><span class="cx"> 
</span><span class="cx">         WEBCORE_EXPORT void didResolveRegistrationPromise(const ServiceWorkerRegistrationKey&);
</span><del>-        const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const { return m_server.doRegistrationMatching(topOrigin, clientURL); }
</del><ins>+        SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) { return m_server.doRegistrationMatching(topOrigin, clientURL); }
</ins><span class="cx">         void resolveRegistrationReadyRequests(SWServerRegistration&);
</span><span class="cx"> 
</span><span class="cx">         // Messages to the client WebProcess
</span><span class="lines">@@ -150,6 +150,7 @@
</span><span class="cx">     void workerContextTerminated(SWServerWorker&);
</span><span class="cx">     std::optional<ServiceWorkerClientData> findClientByIdentifier(const ClientOrigin&, ServiceWorkerClientIdentifier);
</span><span class="cx">     void matchAll(SWServerWorker&, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&);
</span><ins>+    void claim(SWServerWorker&);
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void serverToContextConnectionCreated();
</span><span class="cx">     
</span><span class="lines">@@ -177,7 +178,7 @@
</span><span class="cx">     void addClientServiceWorkerRegistration(Connection&, ServiceWorkerRegistrationIdentifier);
</span><span class="cx">     void removeClientServiceWorkerRegistration(Connection&, ServiceWorkerRegistrationIdentifier);
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
</del><ins>+    WEBCORE_EXPORT SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL);
</ins><span class="cx"> 
</span><span class="cx">     void installContextData(const ServiceWorkerContextData&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerRegistrationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp     2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp        2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -300,6 +300,17 @@
</span><span class="cx">     tryActivate();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SWServerRegistration::controlClient(ServiceWorkerClientIdentifier identifier)
+{
+    ASSERT(activeWorker());
+
+    addClientUsingRegistration(identifier);
+
+    HashSet<DocumentIdentifier> identifiers;
+    identifiers.add(identifier.contextIdentifier);
+    m_server.getConnection(identifier.serverConnectionIdentifier)->notifyClientsOfControllerChange(identifiers, activeWorker()->data());
+}
+
</ins><span class="cx"> void SWServerRegistration::setIsUninstalling(bool value)
</span><span class="cx"> {
</span><span class="cx">     if (m_uninstalling == value)
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerRegistrationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.h (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.h       2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.h  2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -80,6 +80,7 @@
</span><span class="cx">     void unregisterServerConnection(SWServerConnectionIdentifier);
</span><span class="cx"> 
</span><span class="cx">     void notifyClientsOfControllerChange();
</span><ins>+    void controlClient(ServiceWorkerClientIdentifier);
</ins><span class="cx"> 
</span><span class="cx">     void clear();
</span><span class="cx">     bool tryClear();
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerToContextConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp      2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp 2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -123,6 +123,14 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SWServerToContextConnection::claim(uint64_t requestIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier)) {
+        worker->claim();
+        globalServerToContextConnection()->claimCompleted(requestIdentifier);
+    }
+}
+
</ins><span class="cx"> void SWServerToContextConnection::skipWaiting(ServiceWorkerIdentifier serviceWorkerIdentifier, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerToContextConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h        2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h   2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -55,6 +55,7 @@
</span><span class="cx">     virtual void syncTerminateWorker(ServiceWorkerIdentifier) = 0;
</span><span class="cx">     virtual void findClientByIdentifierCompleted(uint64_t requestIdentifier, const std::optional<ServiceWorkerClientData>&, bool hasSecurityError) = 0;
</span><span class="cx">     virtual void matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientInformation>&) = 0;
</span><ins>+    virtual void claimCompleted(uint64_t requestIdentifier) = 0;
</ins><span class="cx">     virtual void didFinishSkipWaiting(uint64_t callbackID) = 0;
</span><span class="cx"> 
</span><span class="cx">     // Messages back from the SW host process
</span><span class="lines">@@ -67,6 +68,7 @@
</span><span class="cx">     WEBCORE_EXPORT void workerTerminated(ServiceWorkerIdentifier);
</span><span class="cx">     WEBCORE_EXPORT void findClientByIdentifier(uint64_t clientIdRequestIdentifier, ServiceWorkerIdentifier, ServiceWorkerClientIdentifier);
</span><span class="cx">     WEBCORE_EXPORT void matchAll(uint64_t requestIdentifier, ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&);
</span><ins>+    WEBCORE_EXPORT void claim(uint64_t requestIdentifier, ServiceWorkerIdentifier);
</ins><span class="cx"> 
</span><span class="cx">     static SWServerToContextConnection* connectionForIdentifier(SWServerToContextConnectionIdentifier);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerWorkercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp   2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp      2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -116,6 +116,11 @@
</span><span class="cx">     return m_server.matchAll(*this, options, WTFMove(callback));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SWServerWorker::claim()
+{
+    return m_server.claim(*this);
+}
+
</ins><span class="cx"> void SWServerWorker::skipWaiting()
</span><span class="cx"> {
</span><span class="cx">     m_isSkipWaitingFlagSet = true;
</span><span class="lines">@@ -125,6 +130,23 @@
</span><span class="cx">     registration->tryActivate();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SWServerWorker::setHasPendingEvents(bool hasPendingEvents)
+{
+    if (m_hasPendingEvents == hasPendingEvents)
+        return;
+
+    m_hasPendingEvents = hasPendingEvents;
+    if (m_hasPendingEvents)
+        return;
+
+    // Do tryClear/tryActivate, as per https://w3c.github.io/ServiceWorker/#wait-until-method.
+    auto* registration = m_server.getRegistration(m_registrationKey);
+    ASSERT(registration);
+    if (registration->isUninstalling() && registration->tryClear())
+        return;
+    registration->tryActivate();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SERVICE_WORKER)
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerWorkerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.h (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h     2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h        2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -81,7 +81,7 @@
</span><span class="cx">     void setState(ServiceWorkerState state) { m_data.state = state; }
</span><span class="cx"> 
</span><span class="cx">     bool hasPendingEvents() const { return m_hasPendingEvents; }
</span><del>-    void setHasPendingEvents(bool value) { m_hasPendingEvents = value; }
</del><ins>+    void setHasPendingEvents(bool);
</ins><span class="cx"> 
</span><span class="cx">     void scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>&, const String& message);
</span><span class="cx">     void scriptContextStarted(const std::optional<ServiceWorkerJobDataIdentifier>&);
</span><span class="lines">@@ -90,6 +90,7 @@
</span><span class="cx">     void contextTerminated();
</span><span class="cx">     std::optional<ServiceWorkerClientData> findClientByIdentifier(ServiceWorkerClientIdentifier);
</span><span class="cx">     void matchAll(const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&);
</span><ins>+    void claim();
</ins><span class="cx"> 
</span><span class="cx">     void skipWaiting();
</span><span class="cx">     bool isSkipWaitingFlagSet() const { return m_isSkipWaitingFlagSet; }
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebKit/ChangeLog       2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2017-12-05  Youenn Fablet  <youenn@apple.com>
+
+        Implement https://w3c.github.io/ServiceWorker/#clients-claim
+        https://bugs.webkit.org/show_bug.cgi?id=180261
+
+        Reviewed by Chris Dumez.
+
+        Add IPC plumbery for clients claim between ServiceWorker process and Storage process.
+
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+        (WebKit::WebSWServerToContextConnection::claimCompleted):
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.h:
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in:
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::claim):
+        (WebKit::WebSWContextManagerConnection::claimCompleted):
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
</ins><span class="cx"> 2017-12-05  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add support for ServiceWorkerContainer.prototype.ready
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerToContextConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp      2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -91,6 +91,11 @@
</span><span class="cx">     send(Messages::WebSWContextManagerConnection::MatchAllCompleted { requestIdentifier, clientsData });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebSWServerToContextConnection::claimCompleted(uint64_t requestIdentifier)
+{
+    send(Messages::WebSWContextManagerConnection::ClaimCompleted { requestIdentifier });
+}
+
</ins><span class="cx"> void WebSWServerToContextConnection::didFinishSkipWaiting(uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     send(Messages::WebSWContextManagerConnection::DidFinishSkipWaiting { callbackID });
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerToContextConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h        2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h   2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -62,6 +62,7 @@
</span><span class="cx">     void syncTerminateWorker(WebCore::ServiceWorkerIdentifier) final;
</span><span class="cx">     void findClientByIdentifierCompleted(uint64_t requestIdentifier, const std::optional<WebCore::ServiceWorkerClientData>&, bool hasSecurityError) final;
</span><span class="cx">     void matchAllCompleted(uint64_t requestIdentifier, const Vector<WebCore::ServiceWorkerClientInformation>&) final;
</span><ins>+    void claimCompleted(uint64_t requestIdentifier) final;
</ins><span class="cx">     void didFinishSkipWaiting(uint64_t callbackID) final;
</span><span class="cx"> 
</span><span class="cx">     Ref<IPC::Connection> m_ipcConnection;
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerToContextConnectionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in      2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in 2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx">     WorkerTerminated(WebCore::ServiceWorkerIdentifier identifier);
</span><span class="cx">     FindClientByIdentifier(uint64_t requestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, struct WebCore::ServiceWorkerClientIdentifier clientIdentifier);
</span><span class="cx">     MatchAll(uint64_t matchAllRequestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, struct WebCore::ServiceWorkerClientQueryOptions options);
</span><ins>+    Claim(uint64_t claimRequestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SERVICE_WORKER)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp    2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -245,6 +245,19 @@
</span><span class="cx">         callback(WTFMove(clientsData));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebSWContextManagerConnection::claim(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, CompletionHandler<void()>&& callback)
+{
+    auto requestIdentifier = ++m_previousRequestIdentifier;
+    m_claimRequests.add(requestIdentifier, WTFMove(callback));
+    m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::Claim { requestIdentifier, serviceWorkerIdentifier }, 0);
+}
+
+void WebSWContextManagerConnection::claimCompleted(uint64_t claimRequestIdentifier)
+{
+    if (auto callback = m_claimRequests.take(claimRequestIdentifier))
+        callback();
+}
+
</ins><span class="cx"> void WebSWContextManagerConnection::didFinishSkipWaiting(uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     if (auto callback = m_skipWaitingRequests.take(callbackID))
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h   2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h      2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -66,6 +66,7 @@
</span><span class="cx">     void workerTerminated(WebCore::ServiceWorkerIdentifier) final;
</span><span class="cx">     void findClientByIdentifier(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerClientIdentifier, FindClientByIdentifierCallback&&) final;
</span><span class="cx">     void matchAll(WebCore::ServiceWorkerIdentifier, const WebCore::ServiceWorkerClientQueryOptions&, WebCore::ServiceWorkerClientsMatchAllCallback&&) final;
</span><ins>+    void claim(WebCore::ServiceWorkerIdentifier, WTF::CompletionHandler<void()>&&) final;
</ins><span class="cx">     void skipWaiting(WebCore::ServiceWorkerIdentifier, WTF::Function<void()>&& callback) final;
</span><span class="cx"> 
</span><span class="cx">     // IPC messages.
</span><span class="lines">@@ -80,6 +81,7 @@
</span><span class="cx">     void syncTerminateWorker(WebCore::ServiceWorkerIdentifier, Ref<Messages::WebSWContextManagerConnection::SyncTerminateWorker::DelayedReply>&&);
</span><span class="cx">     void findClientByIdentifierCompleted(uint64_t requestIdentifier, std::optional<WebCore::ServiceWorkerClientData>&&, bool hasSecurityError);
</span><span class="cx">     void matchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientInformation>&&);
</span><ins>+    void claimCompleted(uint64_t claimRequestIdentifier);
</ins><span class="cx">     void didFinishSkipWaiting(uint64_t callbackID);
</span><span class="cx"> 
</span><span class="cx">     Ref<IPC::Connection> m_connectionToStorageProcess;
</span><span class="lines">@@ -88,6 +90,7 @@
</span><span class="cx"> 
</span><span class="cx">     HashMap<uint64_t, FindClientByIdentifierCallback> m_findClientByIdentifierRequests;
</span><span class="cx">     HashMap<uint64_t, WebCore::ServiceWorkerClientsMatchAllCallback> m_matchAllRequests;
</span><ins>+    HashMap<uint64_t, WTF::CompletionHandler<void()>> m_claimRequests;
</ins><span class="cx">     HashMap<uint64_t, WTF::Function<void()>> m_skipWaitingRequests;
</span><span class="cx">     uint64_t m_previousRequestIdentifier { 0 };
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (225536 => 225537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-12-05 21:40:57 UTC (rev 225536)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in    2017-12-05 21:51:42 UTC (rev 225537)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx">     SyncTerminateWorker(WebCore::ServiceWorkerIdentifier identifier) -> () Delayed
</span><span class="cx">     FindClientByIdentifierCompleted(uint64_t clientIdRequestIdentifier, std::optional<WebCore::ServiceWorkerClientData> data, bool hasSecurityError)
</span><span class="cx">     MatchAllCompleted(uint64_t matchAllRequestIdentifier, Vector<WebCore::ServiceWorkerClientInformation> clientsData)
</span><ins>+    ClaimCompleted(uint64_t claimRequestIdentifier)
</ins><span class="cx">     DidFinishSkipWaiting(uint64_t callbackID)
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>