Title: [224857] trunk
Revision
224857
Author
cdu...@apple.com
Date
2017-11-14 16:04:33 -0800 (Tue, 14 Nov 2017)

Log Message

[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:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224856 => 224857)


--- 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)
@@ -1,3 +1,14 @@
+2017-11-14  Chris Dumez  <cdu...@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:
+
 2017-11-14  Youenn Fablet  <you...@apple.com>
 
         Implement ServiceWorker handle fetch for navigation loads

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/getregistrations.https-expected.txt (224856 => 224857)


--- 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)
@@ -1,8 +1,8 @@
 
 PASS registrations are not returned following unregister 
-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
+PASS Register then getRegistrations 
+PASS Register multiple times then getRegistrations 
 PASS Register then Unregister then getRegistrations 
 FAIL Register then Unregister with controlled frame then getRegistrations assert_equals: expected "activated" but got "redundant"
-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
+PASS getRegistrations promise resolves only with same origin registrations. 
 

Modified: trunk/Source/WebCore/ChangeLog (224856 => 224857)


--- 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)
@@ -1,3 +1,32 @@
+2017-11-14  Chris Dumez  <cdu...@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:
+
 2017-11-14  Alex Christensen  <achristen...@webkit.org>
 
         Fix Windows build.

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (224856 => 224857)


--- 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)
@@ -230,14 +230,8 @@
             return;
         }
 
-        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());
+        auto registration = ServiceWorkerRegistration::getOrCreate(*scriptExecutionContext(), *this, WTFMove(result.value()));
+        promise->resolve<IDLInterface<ServiceWorkerRegistration>>(WTFMove(registration));
     });
 }
 
@@ -259,8 +253,28 @@
 
 void ServiceWorkerContainer::getRegistrations(RegistrationsPromise&& promise)
 {
-    // FIXME: Implement getRegistrations algorithm, for now pretend there is no registration.
-    promise.resolve({ });
+    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));
+    });
 }
 
 void ServiceWorkerContainer::startMessages()
@@ -305,13 +319,11 @@
     }
 
     context->postTask([this, protectedThis = makeRef(*this), job = makeRef(job), data = "" promiseResolvedHandler = WTFMove(promiseResolvedHandler)](ScriptExecutionContext& context) mutable {
-        RefPtr<ServiceWorkerRegistration> registration = m_registrations.get(data.identifier);
-        if (!registration)
-            registration = ServiceWorkerRegistration::create(context, *this, WTFMove(data));
+        auto registration = ServiceWorkerRegistration::getOrCreate(context, *this, WTFMove(data));
 
-        LOG(ServiceWorker, "Container %p resolved job with registration %p", this, registration.get());
+        LOG(ServiceWorker, "Container %p resolved job with registration %p", this, registration.ptr());
 
-        job->promise().resolve<IDLInterface<ServiceWorkerRegistration>>(*registration);
+        job->promise().resolve<IDLInterface<ServiceWorkerRegistration>>(WTFMove(registration));
 
         MicrotaskQueue::mainThreadQueue().append(std::make_unique<VoidMicrotask>([promiseResolvedHandler = WTFMove(promiseResolvedHandler)] {
             promiseResolvedHandler();

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (224856 => 224857)


--- 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)
@@ -71,6 +71,8 @@
     using RegistrationsPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<ServiceWorkerRegistration>>>;
     void getRegistrations(RegistrationsPromise&&);
 
+    ServiceWorkerRegistration* registration(ServiceWorkerRegistrationIdentifier identifier) const { return m_registrations.get(identifier); }
+
     void addRegistration(ServiceWorkerRegistration&);
     void removeRegistration(ServiceWorkerRegistration&);
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (224856 => 224857)


--- 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)
@@ -37,6 +37,14 @@
 
 namespace WebCore {
 
+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)));
+}
+
 ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& context, Ref<ServiceWorkerContainer>&& container, ServiceWorkerRegistrationData&& registrationData)
     : ActiveDOMObject(&context)
     , m_registrationData(WTFMove(registrationData))

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h (224856 => 224857)


--- 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)
@@ -41,10 +41,7 @@
 
 class ServiceWorkerRegistration final : public RefCounted<ServiceWorkerRegistration>, public EventTargetWithInlineData, public ActiveDOMObject {
 public:
-    template <typename... Args> static Ref<ServiceWorkerRegistration> create(Args&&... args)
-    {
-        return adoptRef(*new ServiceWorkerRegistration(std::forward<Args>(args)...));
-    }
+    static Ref<ServiceWorkerRegistration> getOrCreate(ScriptExecutionContext&, Ref<ServiceWorkerContainer>&&, ServiceWorkerRegistrationData&&);
 
     ~ServiceWorkerRegistration();
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp (224856 => 224857)


--- 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)
@@ -67,13 +67,15 @@
 
 bool ServiceWorkerRegistrationKey::isMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const
 {
+    return originIsMatching(topOrigin, clientURL) && clientURL.string().startsWith(m_scope);
+}
+
+bool ServiceWorkerRegistrationKey::originIsMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const
+{
     if (topOrigin != m_topOrigin)
         return false;
 
-    if (!protocolHostAndPortAreEqual(clientURL, m_scope))
-        return false;
-
-    return clientURL.string().startsWith(m_scope);
+    return protocolHostAndPortAreEqual(clientURL, m_scope);
 }
 
 #ifndef NDEBUG

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h (224856 => 224857)


--- 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)
@@ -42,6 +42,7 @@
 
     bool operator==(const ServiceWorkerRegistrationKey&) const;
     bool isMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
+    bool originIsMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
     size_t scopeLength() const { return m_scope.string().length(); }
 
     const SecurityOriginData& topOrigin() const { return m_topOrigin; }

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


--- 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)
@@ -55,6 +55,9 @@
     using RegistrationCallback = WTF::CompletionHandler<void(std::optional<ServiceWorkerRegistrationData>&&)>;
     virtual void matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&&) = 0;
 
+    using GetRegistrationsCallback = WTF::CompletionHandler<void(Vector<ServiceWorkerRegistrationData>&&)>;
+    virtual void getRegistrations(const SecurityOrigin& topOrigin, const URL& clientURL, GetRegistrationsCallback&&) = 0;
+
     virtual void addServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier) = 0;
     virtual void removeServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier) = 0;
 

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


--- 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)
@@ -109,6 +109,24 @@
     m_originStore->remove(topOrigin);
 }
 
+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;
+}
+
 void SWServer::clearAll()
 {
     m_jobQueues.clear();

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


--- 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)
@@ -100,6 +100,7 @@
     SWServerRegistration* getRegistration(const ServiceWorkerRegistrationKey&);
     void addRegistration(std::unique_ptr<SWServerRegistration>&&);
     void removeRegistration(const ServiceWorkerRegistrationKey&);
+    WEBCORE_EXPORT Vector<ServiceWorkerRegistrationData> getRegistrations(const SecurityOriginData& topOrigin, const URL& clientURL);
 
     void scheduleJob(const ServiceWorkerJobData&);
     void rejectJob(const ServiceWorkerJobData&, const ExceptionData&);

Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (224856 => 224857)


--- 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)
@@ -47,6 +47,7 @@
     , m_scopeURL(scopeURL)
     , m_scriptURL(scriptURL)
     , m_server(server)
+    , m_creationTime(MonotonicTime::now())
 {
     m_scopeURL.removeFragmentIdentifier();
 }

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


--- 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)
@@ -31,6 +31,7 @@
 #include "ServiceWorkerRegistrationData.h"
 #include "ServiceWorkerTypes.h"
 #include <wtf/HashCountedSet.h>
+#include <wtf/MonotonicTime.h>
 
 namespace WebCore {
 
@@ -69,6 +70,8 @@
     SWServerWorker* waitingWorker() const { return m_waitingWorker.get(); }
     SWServerWorker* activeWorker() const { return m_activeWorker.get(); }
 
+    MonotonicTime creationTime() const { return m_creationTime; }
+
 private:
     void forEachConnection(const WTF::Function<void(SWServer::Connection&)>&);
 
@@ -87,6 +90,8 @@
     
     HashCountedSet<uint64_t> m_connectionsWithClientRegistrations;
     SWServer& m_server;
+
+    MonotonicTime m_creationTime;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/ChangeLog (224856 => 224857)


--- 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)
@@ -1,3 +1,20 @@
+2017-11-14  Chris Dumez  <cdu...@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:
+
 2017-11-14  Youenn Fablet  <you...@apple.com>
 
         Implement ServiceWorker handle fetch for navigation loads

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224856 => 224857)


--- 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)
@@ -160,6 +160,12 @@
     send(Messages::WebSWClientConnection::DidMatchRegistration { registrationMatchRequestIdentifier, std::nullopt });
 }
 
+void WebSWServerConnection::getRegistrations(uint64_t registrationMatchRequestIdentifier, const SecurityOriginData& topOrigin, const URL& clientURL)
+{
+    auto registrations = server().getRegistrations(topOrigin, clientURL);
+    send(Messages::WebSWClientConnection::DidGetRegistrations { registrationMatchRequestIdentifier, registrations });
+}
+
 template<typename U> void WebSWServerConnection::sendToContextProcess(U&& message)
 {
     if (auto* connection = StorageProcess::singleton().globalServerToContextConnection())

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (224856 => 224857)


--- 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)
@@ -72,7 +72,8 @@
 
     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, uint64_t sourceScriptExecutionContextIdentifier, const String& sourceOrigin);
 
-    void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData&, const WebCore::URL& clientURL);
+    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);
 
     IPC::Connection* messageSenderConnection() final { return m_contentConnection.ptr(); }
     uint64_t messageSenderDestinationID() final { return identifier(); }

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


--- 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)
@@ -35,6 +35,7 @@
     DidResolveRegistrationPromise(WebCore::ServiceWorkerRegistrationKey key)
 
     MatchRegistration(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, WebCore::URL clientURL)
+    GetRegistrations(uint64_t serviceRegistrationMatchRequestIdentifier, struct WebCore::SecurityOriginData topOrigin, WebCore::URL clientURL)
 }
 
 #endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224856 => 224857)


--- 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)
@@ -118,6 +118,12 @@
         completionHandler(WTFMove(result));
 }
 
+void WebSWClientConnection::didGetRegistrations(uint64_t matchingRequest, Vector<ServiceWorkerRegistrationData>&& registrations)
+{
+    if (auto completionHandler = m_ongoingGetRegistrationsTasks.take(matchingRequest))
+        completionHandler(WTFMove(registrations));
+}
+
 void WebSWClientConnection::matchRegistration(const SecurityOrigin& topOrigin, const URL& clientURL, RegistrationCallback&& callback)
 {
     if (!mayHaveServiceWorkerRegisteredForOrigin(topOrigin)) {
@@ -130,6 +136,18 @@
     send(Messages::WebSWServerConnection::MatchRegistration(requestIdentifier, SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL));
 }
 
+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));
+}
+
 Ref<ServiceWorkerClientFetch> WebSWClientConnection::startFetch(WebServiceWorkerProvider& provider, Ref<WebCore::ResourceLoader>&& loader, uint64_t identifier, ServiceWorkerClientFetch::Callback&& callback)
 {
     ASSERT(loader->options().serviceWorkersMode != ServiceWorkersMode::None && loader->options().serviceWorkerIdentifier);

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (224856 => 224857)


--- 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)
@@ -72,7 +72,10 @@
 
     void matchRegistration(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, RegistrationCallback&&) final;
     void didMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData>&&);
+    void didGetRegistrations(uint64_t matchRequestIdentifier, Vector<WebCore::ServiceWorkerRegistrationData>&&);
 
+    void getRegistrations(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, GetRegistrationsCallback&&) final;
+
     void didResolveRegistrationPromise(const WebCore::ServiceWorkerRegistrationKey&) final;
 
     void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
@@ -92,6 +95,9 @@
     uint64_t m_previousMatchRegistrationTaskIdentifier { 0 };
     HashMap<uint64_t, RegistrationCallback> m_ongoingMatchRegistrationTasks;
 
+    uint64_t m_previousGetRegistrationsTaskIdentifier { 0 };
+    HashMap<uint64_t, GetRegistrationsCallback> m_ongoingGetRegistrationsTasks;
+
 }; // class WebSWServerConnection
 
 } // namespace WebKit

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


--- 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)
@@ -37,6 +37,7 @@
     PostMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerData source, String sourceOrigin)
 
     DidMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData> data)
+    DidGetRegistrations(uint64_t matchRequestIdentifier, Vector<WebCore::ServiceWorkerRegistrationData> registrations)
 }
 
 #endif // ENABLE(SERVICE_WORKER)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to