<!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>[224857] 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/224857">224857</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2017-11-14 16:04:33 -0800 (Tue, 14 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Service Workers] Implement container.getRegistrations()
https://bugs.webkit.org/show_bug.cgi?id=179672

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

Rebaseline test now that more checks are passing.

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

Source/WebCore:

Implement container.getRegistrations():
- https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-getregistrations

No new tests, rebaselined existing test.

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::getRegistration):
(WebCore::ServiceWorkerContainer::getRegistrations):
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::getOrCreate):
* workers/service/ServiceWorkerRegistration.h:
* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::isMatching const):
(WebCore::ServiceWorkerRegistrationKey::originIsMatching const):
* workers/service/ServiceWorkerRegistrationKey.h:
* workers/service/server/SWClientConnection.h:
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::getRegistrations):
* workers/service/server/SWServer.h:

Source/WebKit:

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::getRegistrations):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::didGetRegistrations):
(WebKit::WebSWClientConnection::getRegistrations):
* WebProcess/Storage/WebSWClientConnection.h:
* WebProcess/Storage/WebSWClientConnection.messages.in:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkergetregistrationshttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.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="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeycpp">trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeyh">trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWClientConnectionh">trunk/Source/WebCore/workers/service/server/SWClientConnection.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="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectioncpp">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectionh">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectionmessagesin">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWClientConnectioncpp">trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWClientConnectionh">trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWClientConnectionmessagesin">trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2017-11-14  Chris Dumez  <cdumez@apple.com>
+
+        [Service Workers] Implement container.getRegistrations()
+        https://bugs.webkit.org/show_bug.cgi?id=179672
+
+        Reviewed by Brady Eidson.
+
+        Rebaseline test now that more checks are passing.
+
+        * web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt:
+
</ins><span class="cx"> 2017-11-14  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Implement ServiceWorker handle fetch for navigation loads
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkergetregistrationshttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt     2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt        2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -1,8 +1,8 @@
</span><span class="cx"> 
</span><span class="cx"> PASS registrations are not returned following unregister 
</span><del>-FAIL Register then getRegistrations assert_array_equals: getRegistrations should resolve with array of registrations. lengths differ, expected 1 got 0
-FAIL Register multiple times then getRegistrations assert_array_equals: getRegistrations should resolve with array of registrations. lengths differ, expected 2 got 0
</del><ins>+PASS Register then getRegistrations 
+PASS Register multiple times then getRegistrations 
</ins><span class="cx"> PASS Register then Unregister then getRegistrations 
</span><span class="cx"> FAIL Register then Unregister with controlled frame then getRegistrations assert_equals: expected "activated" but got "redundant"
</span><del>-FAIL getRegistrations promise resolves only with same origin registrations. assert_array_equals: getRegistrations should only return same origin registrations. lengths differ, expected 1 got 0
</del><ins>+PASS getRegistrations promise resolves only with same origin registrations. 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/ChangeLog      2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2017-11-14  Chris Dumez  <cdumez@apple.com>
+
+        [Service Workers] Implement container.getRegistrations()
+        https://bugs.webkit.org/show_bug.cgi?id=179672
+
+        Reviewed by Brady Eidson.
+
+        Implement container.getRegistrations():
+        - https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-getregistrations
+
+        No new tests, rebaselined existing test.
+
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::getRegistration):
+        (WebCore::ServiceWorkerContainer::getRegistrations):
+        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
+        * workers/service/ServiceWorkerContainer.h:
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::getOrCreate):
+        * workers/service/ServiceWorkerRegistration.h:
+        * workers/service/ServiceWorkerRegistrationKey.cpp:
+        (WebCore::ServiceWorkerRegistrationKey::isMatching const):
+        (WebCore::ServiceWorkerRegistrationKey::originIsMatching const):
+        * workers/service/ServiceWorkerRegistrationKey.h:
+        * workers/service/server/SWClientConnection.h:
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::getRegistrations):
+        * workers/service/server/SWServer.h:
+
</ins><span class="cx"> 2017-11-14  Alex Christensen  <achristensen@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Fix Windows build.
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContainercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp  2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp     2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -230,14 +230,8 @@
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        RefPtr<ServiceWorkerRegistration> registration = m_registrations.get(result->identifier);
-        if (!registration) {
-            auto& context = *scriptExecutionContext();
-            // FIXME: We should probably not be constructing ServiceWorkerRegistration objects here. Instead, we should make
-            // sure that ServiceWorkerRegistration objects stays alive as long as their SWServerRegistration on server side.
-            registration = ServiceWorkerRegistration::create(context, *this, WTFMove(result.value()));
-        }
-        promise->resolve<IDLInterface<ServiceWorkerRegistration>>(registration.releaseNonNull());
</del><ins>+        auto registration = ServiceWorkerRegistration::getOrCreate(*scriptExecutionContext(), *this, WTFMove(result.value()));
+        promise->resolve<IDLInterface<ServiceWorkerRegistration>>(WTFMove(registration));
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -259,8 +253,28 @@
</span><span class="cx"> 
</span><span class="cx"> void ServiceWorkerContainer::getRegistrations(RegistrationsPromise&& promise)
</span><span class="cx"> {
</span><del>-    // FIXME: Implement getRegistrations algorithm, for now pretend there is no registration.
-    promise.resolve({ });
</del><ins>+    auto* context = scriptExecutionContext();
+    if (!context) {
+        promise.reject(Exception { InvalidStateError });
+        return;
+    }
+
+    if (!m_swConnection)
+        m_swConnection = &ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context->sessionID());
+
+    return m_swConnection->getRegistrations(context->topOrigin(), context->url(), [this, pendingActivity = makePendingActivity(*this), promise = WTFMove(promise)] (auto&& registrationDatas) mutable {
+        if (m_isStopped)
+            return;
+
+        Vector<Ref<ServiceWorkerRegistration>> registrations;
+        registrations.reserveInitialCapacity(registrationDatas.size());
+        for (auto& registrationData : registrationDatas) {
+            auto registration = ServiceWorkerRegistration::getOrCreate(*scriptExecutionContext(), *this, WTFMove(registrationData));
+            registrations.uncheckedAppend(WTFMove(registration));
+        }
+
+        promise.resolve(WTFMove(registrations));
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ServiceWorkerContainer::startMessages()
</span><span class="lines">@@ -305,13 +319,11 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     context->postTask([this, protectedThis = makeRef(*this), job = makeRef(job), data = WTFMove(data), promiseResolvedHandler = WTFMove(promiseResolvedHandler)](ScriptExecutionContext& context) mutable {
</span><del>-        RefPtr<ServiceWorkerRegistration> registration = m_registrations.get(data.identifier);
-        if (!registration)
-            registration = ServiceWorkerRegistration::create(context, *this, WTFMove(data));
</del><ins>+        auto registration = ServiceWorkerRegistration::getOrCreate(context, *this, WTFMove(data));
</ins><span class="cx"> 
</span><del>-        LOG(ServiceWorker, "Container %p resolved job with registration %p", this, registration.get());
</del><ins>+        LOG(ServiceWorker, "Container %p resolved job with registration %p", this, registration.ptr());
</ins><span class="cx"> 
</span><del>-        job->promise().resolve<IDLInterface<ServiceWorkerRegistration>>(*registration);
</del><ins>+        job->promise().resolve<IDLInterface<ServiceWorkerRegistration>>(WTFMove(registration));
</ins><span class="cx"> 
</span><span class="cx">         MicrotaskQueue::mainThreadQueue().append(std::make_unique<VoidMicrotask>([promiseResolvedHandler = WTFMove(promiseResolvedHandler)] {
</span><span class="cx">             promiseResolvedHandler();
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContainerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h    2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h       2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -71,6 +71,8 @@
</span><span class="cx">     using RegistrationsPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<ServiceWorkerRegistration>>>;
</span><span class="cx">     void getRegistrations(RegistrationsPromise&&);
</span><span class="cx"> 
</span><ins>+    ServiceWorkerRegistration* registration(ServiceWorkerRegistrationIdentifier identifier) const { return m_registrations.get(identifier); }
+
</ins><span class="cx">     void addRegistration(ServiceWorkerRegistration&);
</span><span class="cx">     void removeRegistration(ServiceWorkerRegistration&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp       2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp  2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -37,6 +37,14 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+Ref<ServiceWorkerRegistration> ServiceWorkerRegistration::getOrCreate(ScriptExecutionContext& context, Ref<ServiceWorkerContainer>&& container, ServiceWorkerRegistrationData&& data)
+{
+    if (auto* registration = container->registration(data.identifier))
+        return *registration;
+
+    return adoptRef(*new ServiceWorkerRegistration(context, WTFMove(container), WTFMove(data)));
+}
+
</ins><span class="cx"> ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, Ref<ServiceWorkerContainer>&& container, ServiceWorkerRegistrationData&& registrationData)
</span><span class="cx">     : ActiveDOMObject(&context)
</span><span class="cx">     , m_registrationData(WTFMove(registrationData))
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h 2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h    2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -41,10 +41,7 @@
</span><span class="cx"> 
</span><span class="cx"> class ServiceWorkerRegistration final : public RefCounted<ServiceWorkerRegistration>, public EventTargetWithInlineData, public ActiveDOMObject {
</span><span class="cx"> public:
</span><del>-    template <typename... Args> static Ref<ServiceWorkerRegistration> create(Args&&... args)
-    {
-        return adoptRef(*new ServiceWorkerRegistration(std::forward<Args>(args)...));
-    }
</del><ins>+    static Ref<ServiceWorkerRegistration> getOrCreate(ScriptExecutionContext&, Ref<ServiceWorkerContainer>&&, ServiceWorkerRegistrationData&&);
</ins><span class="cx"> 
</span><span class="cx">     ~ServiceWorkerRegistration();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp    2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp       2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -67,13 +67,15 @@
</span><span class="cx"> 
</span><span class="cx"> bool ServiceWorkerRegistrationKey::isMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const
</span><span class="cx"> {
</span><ins>+    return originIsMatching(topOrigin, clientURL) && clientURL.string().startsWith(m_scope);
+}
+
+bool ServiceWorkerRegistrationKey::originIsMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const
+{
</ins><span class="cx">     if (topOrigin != m_topOrigin)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    if (!protocolHostAndPortAreEqual(clientURL, m_scope))
-        return false;
-
-    return clientURL.string().startsWith(m_scope);
</del><ins>+    return protocolHostAndPortAreEqual(clientURL, m_scope);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #ifndef NDEBUG
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h      2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h 2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx"> 
</span><span class="cx">     bool operator==(const ServiceWorkerRegistrationKey&) const;
</span><span class="cx">     bool isMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
</span><ins>+    bool originIsMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
</ins><span class="cx">     size_t scopeLength() const { return m_scope.string().length(); }
</span><span class="cx"> 
</span><span class="cx">     const SecurityOriginData& topOrigin() const { return m_topOrigin; }
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWClientConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h 2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h    2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -55,6 +55,9 @@
</span><span class="cx">     using RegistrationCallback = WTF::CompletionHandler<void(std::optional<ServiceWorkerRegistrationData>&&)>;
</span><span class="cx">     virtual void matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&&) = 0;
</span><span class="cx"> 
</span><ins>+    using GetRegistrationsCallback = WTF::CompletionHandler<void(Vector<ServiceWorkerRegistrationData>&&)>;
+    virtual void getRegistrations(const SecurityOrigin& topOrigin, const URL& clientURL, GetRegistrationsCallback&&) = 0;
+
</ins><span class="cx">     virtual void addServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier) = 0;
</span><span class="cx">     virtual void removeServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier) = 0;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp    2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -109,6 +109,24 @@
</span><span class="cx">     m_originStore->remove(topOrigin);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Vector<ServiceWorkerRegistrationData> SWServer::getRegistrations(const SecurityOriginData& topOrigin, const URL& clientURL)
+{
+    Vector<SWServerRegistration*> matchingRegistrations;
+    for (auto& item : m_registrations) {
+        if (!item.value->isUninstalling() && item.key.originIsMatching(topOrigin, clientURL))
+            matchingRegistrations.append(item.value.get());
+    }
+    // The specification mandates that registrations are returned in the insertion order.
+    std::sort(matchingRegistrations.begin(), matchingRegistrations.end(), [](auto& a, auto& b) {
+        return a->creationTime() < b->creationTime();
+    });
+    Vector<ServiceWorkerRegistrationData> matchingRegistrationDatas;
+    matchingRegistrationDatas.reserveInitialCapacity(matchingRegistrations.size());
+    for (auto* registration : matchingRegistrations)
+        matchingRegistrationDatas.uncheckedAppend(registration->data());
+    return matchingRegistrationDatas;
+}
+
</ins><span class="cx"> void SWServer::clearAll()
</span><span class="cx"> {
</span><span class="cx">     m_jobQueues.clear();
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.h   2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h      2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -100,6 +100,7 @@
</span><span class="cx">     SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
</span><span class="cx">     void addRegistration(std::unique_ptr<SWServerRegistration>&&);
</span><span class="cx">     void removeRegistration(const ServiceWorkerRegistrationKey&);
</span><ins>+    WEBCORE_EXPORT Vector<ServiceWorkerRegistrationData> getRegistrations(const SecurityOriginData& topOrigin, const URL& clientURL);
</ins><span class="cx"> 
</span><span class="cx">     void scheduleJob(const ServiceWorkerJobData&);
</span><span class="cx">     void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerRegistrationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp     2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp        2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx">     , m_scopeURL(scopeURL)
</span><span class="cx">     , m_scriptURL(scriptURL)
</span><span class="cx">     , m_server(server)
</span><ins>+    , m_creationTime(MonotonicTime::now())
</ins><span class="cx"> {
</span><span class="cx">     m_scopeURL.removeFragmentIdentifier();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerRegistrationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.h       2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.h  2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include "ServiceWorkerRegistrationData.h"
</span><span class="cx"> #include "ServiceWorkerTypes.h"
</span><span class="cx"> #include <wtf/HashCountedSet.h>
</span><ins>+#include <wtf/MonotonicTime.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -69,6 +70,8 @@
</span><span class="cx">     SWServerWorker* waitingWorker() const { return m_waitingWorker.get(); }
</span><span class="cx">     SWServerWorker* activeWorker() const { return m_activeWorker.get(); }
</span><span class="cx"> 
</span><ins>+    MonotonicTime creationTime() const { return m_creationTime; }
+
</ins><span class="cx"> private:
</span><span class="cx">     void forEachConnection(const WTF::Function<void(SWServer::Connection&)>&);
</span><span class="cx"> 
</span><span class="lines">@@ -87,6 +90,8 @@
</span><span class="cx">     
</span><span class="cx">     HashCountedSet<uint64_t> m_connectionsWithClientRegistrations;
</span><span class="cx">     SWServer& m_server;
</span><ins>+
+    MonotonicTime m_creationTime;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebKit/ChangeLog       2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-11-14  Chris Dumez  <cdumez@apple.com>
+
+        [Service Workers] Implement container.getRegistrations()
+        https://bugs.webkit.org/show_bug.cgi?id=179672
+
+        Reviewed by Brady Eidson.
+
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::getRegistrations):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+        * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::didGetRegistrations):
+        (WebKit::WebSWClientConnection::getRegistrations):
+        * WebProcess/Storage/WebSWClientConnection.h:
+        * WebProcess/Storage/WebSWClientConnection.messages.in:
+
</ins><span class="cx"> 2017-11-14  Youenn Fablet  <youenn@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Implement ServiceWorker handle fetch for navigation loads
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp       2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp  2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -160,6 +160,12 @@
</span><span class="cx">     send(Messages::WebSWClientConnection::DidMatchRegistration { registrationMatchRequestIdentifier, std::nullopt });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebSWServerConnection::getRegistrations(uint64_t registrationMatchRequestIdentifier, const SecurityOriginData& topOrigin, const URL& clientURL)
+{
+    auto registrations = server().getRegistrations(topOrigin, clientURL);
+    send(Messages::WebSWClientConnection::DidGetRegistrations { registrationMatchRequestIdentifier, registrations });
+}
+
</ins><span class="cx"> template<typename U> void WebSWServerConnection::sendToContextProcess(U&& message)
</span><span class="cx"> {
</span><span class="cx">     if (auto* connection = StorageProcess::singleton().globalServerToContextConnection())
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h 2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h    2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -72,7 +72,8 @@
</span><span class="cx"> 
</span><span class="cx">     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin);
</span><span class="cx"> 
</span><del>-    void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData&, const WebCore::URL& clientURL);
</del><ins>+    void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::URL& clientURL);
+    void getRegistrations(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::URL& clientURL);
</ins><span class="cx"> 
</span><span class="cx">     IPC::Connection* messageSenderConnection() final { return m_contentConnection.ptr(); }
</span><span class="cx">     uint64_t messageSenderDestinationID() final { return identifier(); }
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in       2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in  2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx">     DidResolveRegistrationPromise(WebCore::ServiceWorkerRegistrationKey key)
</span><span class="cx"> 
</span><span class="cx">     MatchRegistration(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, WebCore::URL clientURL)
</span><ins>+    GetRegistrations(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, WebCore::URL clientURL)
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SERVICE_WORKER)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWClientConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp    2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -118,6 +118,12 @@
</span><span class="cx">         completionHandler(WTFMove(result));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebSWClientConnection::didGetRegistrations(uint64_t matchingRequest, Vector<ServiceWorkerRegistrationData>&& registrations)
+{
+    if (auto completionHandler = m_ongoingGetRegistrationsTasks.take(matchingRequest))
+        completionHandler(WTFMove(registrations));
+}
+
</ins><span class="cx"> void WebSWClientConnection::matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&& callback)
</span><span class="cx"> {
</span><span class="cx">     if (!mayHaveServiceWorkerRegisteredForOrigin(topOrigin)) {
</span><span class="lines">@@ -130,6 +136,18 @@
</span><span class="cx">     send(Messages::WebSWServerConnection::MatchRegistration(requestIdentifier, SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebSWClientConnection::getRegistrations(const SecurityOrigin& topOrigin, const URL& clientURL, GetRegistrationsCallback&& callback)
+{
+    if (!mayHaveServiceWorkerRegisteredForOrigin(topOrigin)) {
+        callback({ });
+        return;
+    }
+
+    uint64_t requestIdentifier = ++m_previousGetRegistrationsTaskIdentifier;
+    m_ongoingGetRegistrationsTasks.add(requestIdentifier, WTFMove(callback));
+    send(Messages::WebSWServerConnection::GetRegistrations(requestIdentifier, SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL));
+}
+
</ins><span class="cx"> Ref<ServiceWorkerClientFetch> WebSWClientConnection::startFetch(WebServiceWorkerProvider& provider, Ref<WebCore::ResourceLoader>&& loader, uint64_t identifier, ServiceWorkerClientFetch::Callback&& callback)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(loader->options().serviceWorkersMode != ServiceWorkersMode::None && loader->options().serviceWorkerIdentifier);
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWClientConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h   2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h      2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -72,7 +72,10 @@
</span><span class="cx"> 
</span><span class="cx">     void matchRegistration(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, RegistrationCallback&&) final;
</span><span class="cx">     void didMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData>&&);
</span><ins>+    void didGetRegistrations(uint64_t matchRequestIdentifier, Vector<WebCore::ServiceWorkerRegistrationData>&&);
</ins><span class="cx"> 
</span><ins>+    void getRegistrations(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, GetRegistrationsCallback&&) final;
+
</ins><span class="cx">     void didResolveRegistrationPromise(const WebCore::ServiceWorkerRegistrationKey&) final;
</span><span class="cx"> 
</span><span class="cx">     void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
</span><span class="lines">@@ -92,6 +95,9 @@
</span><span class="cx">     uint64_t m_previousMatchRegistrationTaskIdentifier { 0 };
</span><span class="cx">     HashMap<uint64_t, RegistrationCallback> m_ongoingMatchRegistrationTasks;
</span><span class="cx"> 
</span><ins>+    uint64_t m_previousGetRegistrationsTaskIdentifier { 0 };
+    HashMap<uint64_t, GetRegistrationsCallback> m_ongoingGetRegistrationsTasks;
+
</ins><span class="cx"> }; // class WebSWServerConnection
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWClientConnectionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (224856 => 224857)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in 2017-11-14 23:49:24 UTC (rev 224856)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in    2017-11-15 00:04:33 UTC (rev 224857)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx">     PostMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerData source, String sourceOrigin)
</span><span class="cx"> 
</span><span class="cx">     DidMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData> data)
</span><ins>+    DidGetRegistrations(uint64_t matchRequestIdentifier, Vector<WebCore::ServiceWorkerRegistrationData> registrations)
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SERVICE_WORKER)
</span></span></pre>
</div>
</div>

</body>
</html>