Title: [225198] trunk/Source
Revision
225198
Author
[email protected]
Date
2017-11-27 15:13:54 -0800 (Mon, 27 Nov 2017)

Log Message

ASSERTION FAILED: addResult.isNewEntry WebCore::SWServerRegistration::addClientUsingRegistration(WebCore::ServiceWorkerClientIdentifier const&) + 141
https://bugs.webkit.org/show_bug.cgi?id=180049

Reviewed by Brady Eidson.

Source/WebCore:

SWServer::serviceWorkerStoppedControllingClient() was failing to remove the client from the
SWServerRegistration in some cases. This is because we relied on the Service Worker Identifier
to get the SWServerRegistration, via the corresponding SWServerServiceWorker object. However,
It is possible for the SWServerServiceWorker to have been destroyed already.

In serviceWorkerStartedControllingClient / serviceWorkerStoppedControllingClient, we now
pass the registration identifier, so that we are able to look up the registration directly,
without going through the service worker object.

No new tests, already covered by imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https.html.

* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::setActiveServiceWorker):
* workers/service/ServiceWorker.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration):
(WebCore::ServiceWorkerContainer::removeRegistration):
* workers/service/ServiceWorkerData.cpp:
(WebCore::ServiceWorkerData::isolatedCopy const):
* workers/service/ServiceWorkerData.h:
(WebCore::ServiceWorkerData::encode const):
(WebCore::ServiceWorkerData::decode):
* workers/service/server/SWClientConnection.h:
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::addRegistration):
(WebCore::SWServer::removeRegistration):
(WebCore::SWServer::clearAll):
(WebCore::SWServer::Connection::addServiceWorkerRegistrationInServer):
(WebCore::SWServer::Connection::removeServiceWorkerRegistrationInServer):
(WebCore::SWServer::Connection::serviceWorkerStartedControllingClient):
(WebCore::SWServer::Connection::serviceWorkerStoppedControllingClient):
(WebCore::SWServer::addClientServiceWorkerRegistration):
(WebCore::SWServer::removeClientServiceWorkerRegistration):
(WebCore::SWServer::serviceWorkerStartedControllingClient):
(WebCore::SWServer::serviceWorkerStoppedControllingClient):
(WebCore::SWServer::installContextData):
* workers/service/server/SWServer.h:
* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::SWServerWorker):
* workers/service/server/SWServerWorker.h:

Source/WebKit:

* StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::addServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::removeServiceWorkerRegistrationInServer):
(WebKit::WebSWClientConnection::serviceWorkerStartedControllingClient):
(WebKit::WebSWClientConnection::serviceWorkerStoppedControllingClient):
* WebProcess/Storage/WebSWClientConnection.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (225197 => 225198)


--- trunk/Source/WebCore/ChangeLog	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/ChangeLog	2017-11-27 23:13:54 UTC (rev 225198)
@@ -1,3 +1,51 @@
+2017-11-27  Chris Dumez  <[email protected]>
+
+        ASSERTION FAILED: addResult.isNewEntry WebCore::SWServerRegistration::addClientUsingRegistration(WebCore::ServiceWorkerClientIdentifier const&) + 141
+        https://bugs.webkit.org/show_bug.cgi?id=180049
+
+        Reviewed by Brady Eidson.
+
+        SWServer::serviceWorkerStoppedControllingClient() was failing to remove the client from the
+        SWServerRegistration in some cases. This is because we relied on the Service Worker Identifier
+        to get the SWServerRegistration, via the corresponding SWServerServiceWorker object. However,
+        It is possible for the SWServerServiceWorker to have been destroyed already.
+
+        In serviceWorkerStartedControllingClient / serviceWorkerStoppedControllingClient, we now
+        pass the registration identifier, so that we are able to look up the registration directly,
+        without going through the service worker object.
+
+        No new tests, already covered by imported/w3c/web-platform-tests/service-workers/service-worker/claim-affect-other-registration.https.html.
+
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::setActiveServiceWorker):
+        * workers/service/ServiceWorker.h:
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::addRegistration):
+        (WebCore::ServiceWorkerContainer::removeRegistration):
+        * workers/service/ServiceWorkerData.cpp:
+        (WebCore::ServiceWorkerData::isolatedCopy const):
+        * workers/service/ServiceWorkerData.h:
+        (WebCore::ServiceWorkerData::encode const):
+        (WebCore::ServiceWorkerData::decode):
+        * workers/service/server/SWClientConnection.h:
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::addRegistration):
+        (WebCore::SWServer::removeRegistration):
+        (WebCore::SWServer::clearAll):
+        (WebCore::SWServer::Connection::addServiceWorkerRegistrationInServer):
+        (WebCore::SWServer::Connection::removeServiceWorkerRegistrationInServer):
+        (WebCore::SWServer::Connection::serviceWorkerStartedControllingClient):
+        (WebCore::SWServer::Connection::serviceWorkerStoppedControllingClient):
+        (WebCore::SWServer::addClientServiceWorkerRegistration):
+        (WebCore::SWServer::removeClientServiceWorkerRegistration):
+        (WebCore::SWServer::serviceWorkerStartedControllingClient):
+        (WebCore::SWServer::serviceWorkerStoppedControllingClient):
+        (WebCore::SWServer::installContextData):
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerWorker.cpp:
+        (WebCore::SWServerWorker::SWServerWorker):
+        * workers/service/server/SWServerWorker.h:
+
 2017-11-27  Tim Horton  <[email protected]>
 
         REGRESSION (r225142): Crashes when command clicking or force touching links

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (225197 => 225198)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2017-11-27 23:13:54 UTC (rev 225198)
@@ -552,12 +552,12 @@
 
     auto& connection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(sessionID());
     if (m_activeServiceWorker)
-        connection.serviceWorkerStoppedControllingClient(m_activeServiceWorker->identifier(), downcast<Document>(*this).identifier());
+        connection.serviceWorkerStoppedControllingClient(m_activeServiceWorker->identifier(), m_activeServiceWorker->registrationIdentifier(), downcast<Document>(*this).identifier());
 
     m_activeServiceWorker = WTFMove(serviceWorker);
 
     if (m_activeServiceWorker)
-        connection.serviceWorkerStartedControllingClient(m_activeServiceWorker->identifier(), downcast<Document>(*this).identifier());
+        connection.serviceWorkerStartedControllingClient(m_activeServiceWorker->identifier(), m_activeServiceWorker->registrationIdentifier(), downcast<Document>(*this).identifier());
 }
 
 ServiceWorkerContainer* ScriptExecutionContext::serviceWorkerContainer()

Modified: trunk/Source/WebCore/workers/service/ServiceWorker.h (225197 => 225198)


--- trunk/Source/WebCore/workers/service/ServiceWorker.h	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.h	2017-11-27 23:13:54 UTC (rev 225198)
@@ -59,6 +59,7 @@
     ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
 
     ServiceWorkerIdentifier identifier() const { return m_data.identifier; }
+    ServiceWorkerRegistrationIdentifier registrationIdentifier() const { return m_data.registrationIdentifier; }
 
     using RefCounted::ref;
     using RefCounted::deref;

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (225197 => 225198)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-27 23:13:54 UTC (rev 225198)
@@ -401,13 +401,13 @@
 
 void ServiceWorkerContainer::addRegistration(ServiceWorkerRegistration& registration)
 {
-    m_swConnection->addServiceWorkerRegistrationInServer(registration.data().key, registration.identifier());
+    m_swConnection->addServiceWorkerRegistrationInServer(registration.identifier());
     m_registrations.add(registration.identifier(), &registration);
 }
 
 void ServiceWorkerContainer::removeRegistration(ServiceWorkerRegistration& registration)
 {
-    m_swConnection->removeServiceWorkerRegistrationInServer(registration.data().key, registration.identifier());
+    m_swConnection->removeServiceWorkerRegistrationInServer(registration.identifier());
     m_registrations.remove(registration.identifier());
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerData.cpp (225197 => 225198)


--- trunk/Source/WebCore/workers/service/ServiceWorkerData.cpp	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerData.cpp	2017-11-27 23:13:54 UTC (rev 225198)
@@ -36,7 +36,8 @@
         identifier,
         scriptURL.isolatedCopy(),
         state,
-        type
+        type,
+        registrationIdentifier
     };
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerData.h (225197 => 225198)


--- trunk/Source/WebCore/workers/service/ServiceWorkerData.h	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerData.h	2017-11-27 23:13:54 UTC (rev 225198)
@@ -39,6 +39,7 @@
     URL scriptURL;
     ServiceWorkerState state;
     WorkerType type;
+    ServiceWorkerRegistrationIdentifier registrationIdentifier;
 
     ServiceWorkerData isolatedCopy() const;
 
@@ -49,7 +50,7 @@
 template<class Encoder>
 void ServiceWorkerData::encode(Encoder& encoder) const
 {
-    encoder << identifier << scriptURL << state << type;
+    encoder << identifier << scriptURL << state << type << registrationIdentifier;
 }
 
 template<class Decoder>
@@ -75,7 +76,12 @@
     if (!type)
         return std::nullopt;
 
-    return { { WTFMove(*identifier), WTFMove(*scriptURL), WTFMove(*state), WTFMove(*type) } };
+    std::optional<ServiceWorkerRegistrationIdentifier> registrationIdentifier;
+    decoder >> registrationIdentifier;
+    if (!registrationIdentifier)
+        return std::nullopt;
+
+    return { { WTFMove(*identifier), WTFMove(*scriptURL), WTFMove(*state), WTFMove(*type), WTFMove(*registrationIdentifier) } };
 }
 
 } // namespace WebCore

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


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-27 23:13:54 UTC (rev 225198)
@@ -60,8 +60,8 @@
     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;
+    virtual void addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier) = 0;
+    virtual void removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier) = 0;
 
     void scheduleJob(ServiceWorkerJob&);
     void finishedFetchingScript(ServiceWorkerJob&, const String&);
@@ -73,8 +73,8 @@
     virtual SWServerConnectionIdentifier serverConnectionIdentifier() const = 0;
     virtual bool mayHaveServiceWorkerRegisteredForOrigin(const SecurityOrigin&) const = 0;
 
-    virtual void serviceWorkerStartedControllingClient(ServiceWorkerIdentifier, DocumentIdentifier) = 0;
-    virtual void serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier, DocumentIdentifier) = 0;
+    virtual void serviceWorkerStartedControllingClient(ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier, DocumentIdentifier) = 0;
+    virtual void serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier, DocumentIdentifier) = 0;
 
 protected:
     WEBCORE_EXPORT SWClientConnection();

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


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2017-11-27 23:13:54 UTC (rev 225198)
@@ -94,9 +94,13 @@
 void SWServer::addRegistration(std::unique_ptr<SWServerRegistration>&& registration)
 {
     auto key = registration->key();
-    auto result = m_registrations.add(key, WTFMove(registration));
-    ASSERT_UNUSED(result, result.isNewEntry);
+    auto* registrationPtr = registration.get();
+    auto addResult1 = m_registrations.add(key, WTFMove(registration));
+    ASSERT_UNUSED(addResult1, addResult1.isNewEntry);
 
+    auto addResult2 = m_registrationsByID.add(registrationPtr->identifier(), registrationPtr);
+    ASSERT_UNUSED(addResult2, addResult2.isNewEntry);
+
     m_originStore->add(key.topOrigin().securityOrigin());
 }
 
@@ -103,8 +107,10 @@
 void SWServer::removeRegistration(const ServiceWorkerRegistrationKey& key)
 {
     auto topOrigin = key.topOrigin().securityOrigin();
-    auto result = m_registrations.remove(key);
-    ASSERT_UNUSED(result, result);
+    auto registration = m_registrations.take(key);
+    ASSERT(registration);
+    bool wasRemoved = m_registrationsByID.remove(registration->identifier());
+    ASSERT_UNUSED(wasRemoved, wasRemoved);
 
     m_originStore->remove(topOrigin);
 }
@@ -132,6 +138,7 @@
     m_jobQueues.clear();
     while (!m_registrations.isEmpty())
         SWServerJobQueue::clearRegistration(*this, *m_registrations.begin()->value);
+    ASSERT(m_registrationsByID.isEmpty());
     m_originStore->clearAll();
 }
 
@@ -160,24 +167,24 @@
     m_server.didResolveRegistrationPromise(*this, key);
 }
 
-void SWServer::Connection::addServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationIdentifier identifier)
+void SWServer::Connection::addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    m_server.addClientServiceWorkerRegistration(*this, key, identifier);
+    m_server.addClientServiceWorkerRegistration(*this, identifier);
 }
 
-void SWServer::Connection::removeServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationIdentifier identifier)
+void SWServer::Connection::removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    m_server.removeClientServiceWorkerRegistration(*this, key, identifier);
+    m_server.removeClientServiceWorkerRegistration(*this, identifier);
 }
 
-void SWServer::Connection::serviceWorkerStartedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, DocumentIdentifier contextIdentifier)
+void SWServer::Connection::serviceWorkerStartedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentIdentifier contextIdentifier)
 {
-    m_server.serviceWorkerStartedControllingClient(*this, serviceWorkerIdentifier, contextIdentifier);
+    m_server.serviceWorkerStartedControllingClient(*this, serviceWorkerIdentifier, registrationIdentifier, contextIdentifier);
 }
 
-void SWServer::Connection::serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, DocumentIdentifier contextIdentifier)
+void SWServer::Connection::serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentIdentifier contextIdentifier)
 {
-    m_server.serviceWorkerStoppedControllingClient(*this, serviceWorkerIdentifier, contextIdentifier);
+    m_server.serviceWorkerStoppedControllingClient(*this, serviceWorkerIdentifier, registrationIdentifier, contextIdentifier);
 }
 
 SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore)
@@ -296,41 +303,31 @@
         jobQueue->didResolveRegistrationPromise();
 }
 
-void SWServer::addClientServiceWorkerRegistration(Connection& connection, const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationIdentifier identifier)
+void SWServer::addClientServiceWorkerRegistration(Connection& connection, ServiceWorkerRegistrationIdentifier identifier)
 {
-    auto* registration = m_registrations.get(key);
+    auto* registration = m_registrationsByID.get(identifier);
     if (!registration) {
         LOG_ERROR("Request to add client-side ServiceWorkerRegistration to non-existent server-side registration");
         return;
     }
-
-    if (registration->identifier() != identifier)
-        return;
     
     registration->addClientServiceWorkerRegistration(connection.identifier());
 }
 
-void SWServer::removeClientServiceWorkerRegistration(Connection& connection, const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationIdentifier identifier)
+void SWServer::removeClientServiceWorkerRegistration(Connection& connection, ServiceWorkerRegistrationIdentifier identifier)
 {
-    auto* registration = m_registrations.get(key);
+    auto* registration = m_registrationsByID.get(identifier);
     if (!registration) {
         LOG_ERROR("Request to remove client-side ServiceWorkerRegistration from non-existent server-side registration");
         return;
     }
-
-    if (registration->identifier() != identifier)
-        return;
     
     registration->removeClientServiceWorkerRegistration(connection.identifier());
 }
 
-void SWServer::serviceWorkerStartedControllingClient(Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier, DocumentIdentifier contextIdentifier)
+void SWServer::serviceWorkerStartedControllingClient(Connection& connection, ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentIdentifier contextIdentifier)
 {
-    auto* serviceWorker = m_workersByID.get(serviceWorkerIdentifier);
-    if (!serviceWorker)
-        return;
-
-    auto* registration = m_registrations.get(serviceWorker->registrationKey());
+    auto* registration = m_registrationsByID.get(registrationIdentifier);
     if (!registration)
         return;
 
@@ -337,13 +334,9 @@
     registration->addClientUsingRegistration({ connection.identifier(), contextIdentifier });
 }
 
-void SWServer::serviceWorkerStoppedControllingClient(Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier, DocumentIdentifier contextIdentifier)
+void SWServer::serviceWorkerStoppedControllingClient(Connection& connection, ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentIdentifier contextIdentifier)
 {
-    auto* serviceWorker = m_workersByID.get(serviceWorkerIdentifier);
-    if (!serviceWorker)
-        return;
-
-    auto* registration = m_registrations.get(serviceWorker->registrationKey());
+    auto* registration = m_registrationsByID.get(registrationIdentifier);
     if (!registration)
         return;
 
@@ -381,7 +374,10 @@
     auto* connection = SWServerToContextConnection::globalServerToContextConnection();
     ASSERT(connection);
 
-    auto result = m_workersByID.add(data.serviceWorkerIdentifier, SWServerWorker::create(*this, data.registrationKey, connection->identifier(), data.scriptURL, data.script, data.workerType, data.serviceWorkerIdentifier));
+    auto* registration = m_registrations.get(data.registrationKey);
+    RELEASE_ASSERT(registration);
+
+    auto result = m_workersByID.add(data.serviceWorkerIdentifier, SWServerWorker::create(*this, *registration, connection->identifier(), data.scriptURL, data.script, data.workerType, data.serviceWorkerIdentifier));
     ASSERT_UNUSED(result, result.isNewEntry);
 
     connection->installServiceWorkerContext(data);

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


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-27 23:13:54 UTC (rev 225198)
@@ -82,10 +82,10 @@
 
         WEBCORE_EXPORT void scheduleJobInServer(const ServiceWorkerJobData&);
         WEBCORE_EXPORT void finishFetchingScriptInServer(const ServiceWorkerFetchResult&);
-        WEBCORE_EXPORT void addServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier);
-        WEBCORE_EXPORT void removeServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier);
-        WEBCORE_EXPORT void serviceWorkerStartedControllingClient(ServiceWorkerIdentifier, DocumentIdentifier);
-        WEBCORE_EXPORT void serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier, DocumentIdentifier);
+        WEBCORE_EXPORT void addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier);
+        WEBCORE_EXPORT void removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier);
+        WEBCORE_EXPORT void serviceWorkerStartedControllingClient(ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier, DocumentIdentifier);
+        WEBCORE_EXPORT void serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier, DocumentIdentifier);
 
     private:
         // Messages to the client WebProcess
@@ -149,10 +149,10 @@
 
     void didResolveRegistrationPromise(Connection&, const ServiceWorkerRegistrationKey&);
 
-    void addClientServiceWorkerRegistration(Connection&, const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier);
-    void removeClientServiceWorkerRegistration(Connection&, const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier);
-    void serviceWorkerStartedControllingClient(Connection&, ServiceWorkerIdentifier, DocumentIdentifier);
-    void serviceWorkerStoppedControllingClient(Connection&, ServiceWorkerIdentifier, DocumentIdentifier);
+    void addClientServiceWorkerRegistration(Connection&, ServiceWorkerRegistrationIdentifier);
+    void removeClientServiceWorkerRegistration(Connection&, ServiceWorkerRegistrationIdentifier);
+    void serviceWorkerStartedControllingClient(Connection&, ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier, DocumentIdentifier);
+    void serviceWorkerStoppedControllingClient(Connection&, ServiceWorkerIdentifier, ServiceWorkerRegistrationIdentifier, DocumentIdentifier);
 
     WEBCORE_EXPORT const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
 
@@ -160,6 +160,7 @@
 
     HashMap<SWServerConnectionIdentifier, Connection*> m_connections;
     HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerRegistration>> m_registrations;
+    HashMap<ServiceWorkerRegistrationIdentifier, SWServerRegistration*> m_registrationsByID;
     HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerJobQueue>> m_jobQueues;
 
     HashMap<ServiceWorkerIdentifier, Ref<SWServerWorker>> m_workersByID;

Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp (225197 => 225198)


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2017-11-27 23:13:54 UTC (rev 225198)
@@ -43,11 +43,11 @@
     return allWorkers().get(identifier);
 }
 
-SWServerWorker::SWServerWorker(SWServer& server, const ServiceWorkerRegistrationKey& registrationKey, SWServerToContextConnectionIdentifier contextConnectionIdentifier, const URL& scriptURL, const String& script, WorkerType type, ServiceWorkerIdentifier identifier)
+SWServerWorker::SWServerWorker(SWServer& server, SWServerRegistration& registration, SWServerToContextConnectionIdentifier contextConnectionIdentifier, const URL& scriptURL, const String& script, WorkerType type, ServiceWorkerIdentifier identifier)
     : m_server(server)
-    , m_registrationKey(registrationKey)
+    , m_registrationKey(registration.key())
     , m_contextConnectionIdentifier(contextConnectionIdentifier)
-    , m_data { identifier, scriptURL, ServiceWorkerState::Redundant, type }
+    , m_data { identifier, scriptURL, ServiceWorkerState::Redundant, type, registration.identifier() }
     , m_script(script)
 {
     auto result = allWorkers().add(identifier, this);

Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.h (225197 => 225198)


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h	2017-11-27 23:13:54 UTC (rev 225198)
@@ -37,6 +37,7 @@
 namespace WebCore {
 
 class SWServer;
+class SWServerRegistration;
 enum class WorkerType;
 struct ServiceWorkerJobDataIdentifier;
 
@@ -78,7 +79,7 @@
     const ServiceWorkerData& data() const { return m_data; }
 
 private:
-    SWServerWorker(SWServer&, const ServiceWorkerRegistrationKey&, SWServerToContextConnectionIdentifier, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
+    SWServerWorker(SWServer&, SWServerRegistration&, SWServerToContextConnectionIdentifier, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
 
     SWServer& m_server;
     ServiceWorkerRegistrationKey m_registrationKey;

Modified: trunk/Source/WebKit/ChangeLog (225197 => 225198)


--- trunk/Source/WebKit/ChangeLog	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebKit/ChangeLog	2017-11-27 23:13:54 UTC (rev 225198)
@@ -1,3 +1,18 @@
+2017-11-27  Chris Dumez  <[email protected]>
+
+        ASSERTION FAILED: addResult.isNewEntry WebCore::SWServerRegistration::addClientUsingRegistration(WebCore::ServiceWorkerClientIdentifier const&) + 141
+        https://bugs.webkit.org/show_bug.cgi?id=180049
+
+        Reviewed by Brady Eidson.
+
+        * StorageProcess/ServiceWorker/WebSWServerConnection.messages.in:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::addServiceWorkerRegistrationInServer):
+        (WebKit::WebSWClientConnection::removeServiceWorkerRegistrationInServer):
+        (WebKit::WebSWClientConnection::serviceWorkerStartedControllingClient):
+        (WebKit::WebSWClientConnection::serviceWorkerStoppedControllingClient):
+        * WebProcess/Storage/WebSWClientConnection.h:
+
 2017-11-27  Jeremy Jones  <[email protected]>
 
         downcast to WebKit::FullscreenClient can sometimes fail.

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


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.messages.in	2017-11-27 23:13:54 UTC (rev 225198)
@@ -26,10 +26,10 @@
     # When possible, these messages can be implemented directly by WebCore::SWClientConnection
     ScheduleJobInServer(struct WebCore::ServiceWorkerJobData jobData)
     FinishFetchingScriptInServer(struct WebCore::ServiceWorkerFetchResult result)
-    AddServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationKey key, WebCore::ServiceWorkerRegistrationIdentifier identifier)
-    RemoveServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationKey key, WebCore::ServiceWorkerRegistrationIdentifier identifier)
-    ServiceWorkerStartedControllingClient(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::DocumentIdentifier contextIdentifier)
-    ServiceWorkerStoppedControllingClient(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::DocumentIdentifier contextIdentifier)
+    AddServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier identifier)
+    RemoveServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier identifier)
+    ServiceWorkerStartedControllingClient(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::ServiceWorkerRegistrationIdentifier registrationIdentifier, WebCore::DocumentIdentifier contextIdentifier)
+    ServiceWorkerStoppedControllingClient(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, WebCore::ServiceWorkerRegistrationIdentifier registrationIdentifier, WebCore::DocumentIdentifier contextIdentifier)
 
     StartFetch(uint64_t identifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options, IPC::FormDataReference requestBody)
     PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationServiceWorkerIdentifier, IPC::DataReference message, WebCore::DocumentIdentifier sourceContextIdentifier, struct WebCore::ServiceWorkerClientData source)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (225197 => 225198)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-27 23:13:54 UTC (rev 225198)
@@ -72,14 +72,14 @@
     send(Messages::WebSWServerConnection::FinishFetchingScriptInServer(result));
 }
 
-void WebSWClientConnection::addServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationIdentifier identifier)
+void WebSWClientConnection::addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    send(Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer(key, identifier));
+    send(Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer(identifier));
 }
 
-void WebSWClientConnection::removeServiceWorkerRegistrationInServer(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationIdentifier identifier)
+void WebSWClientConnection::removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    send(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer(key, identifier));
+    send(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer(identifier));
 }
 
 void WebSWClientConnection::postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destinationIdentifier, Ref<SerializedScriptValue>&& scriptValue, DocumentIdentifier sourceContextIdentifier, ServiceWorkerClientData&& source)
@@ -87,14 +87,14 @@
     send(Messages::WebSWServerConnection::PostMessageToServiceWorkerGlobalScope(destinationIdentifier, IPC::DataReference { scriptValue->data() }, sourceContextIdentifier, WTFMove(source)));
 }
 
-void WebSWClientConnection::serviceWorkerStartedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, DocumentIdentifier contextIdentifier)
+void WebSWClientConnection::serviceWorkerStartedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentIdentifier contextIdentifier)
 {
-    send(Messages::WebSWServerConnection::ServiceWorkerStartedControllingClient(serviceWorkerIdentifier, contextIdentifier));
+    send(Messages::WebSWServerConnection::ServiceWorkerStartedControllingClient(serviceWorkerIdentifier, registrationIdentifier, contextIdentifier));
 }
 
-void WebSWClientConnection::serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, DocumentIdentifier contextIdentifier)
+void WebSWClientConnection::serviceWorkerStoppedControllingClient(ServiceWorkerIdentifier serviceWorkerIdentifier, ServiceWorkerRegistrationIdentifier registrationIdentifier, DocumentIdentifier contextIdentifier)
 {
-    send(Messages::WebSWServerConnection::ServiceWorkerStoppedControllingClient(serviceWorkerIdentifier, contextIdentifier));
+    send(Messages::WebSWServerConnection::ServiceWorkerStoppedControllingClient(serviceWorkerIdentifier, registrationIdentifier, contextIdentifier));
 }
 
 void WebSWClientConnection::didResolveRegistrationPromise(const ServiceWorkerRegistrationKey& key)

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (225197 => 225198)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2017-11-27 23:05:40 UTC (rev 225197)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2017-11-27 23:13:54 UTC (rev 225198)
@@ -54,8 +54,8 @@
 
     WebCore::SWServerConnectionIdentifier serverConnectionIdentifier() const final { return m_identifier; }
 
-    void addServiceWorkerRegistrationInServer(const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerRegistrationIdentifier) final;
-    void removeServiceWorkerRegistrationInServer(const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerRegistrationIdentifier) final;
+    void addServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier) final;
+    void removeServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier) final;
 
     void disconnectedFromWebProcess();
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
@@ -69,8 +69,8 @@
     void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
     void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, Ref<WebCore::SerializedScriptValue>&&, WebCore::DocumentIdentifier sourceContextIdentifier, WebCore::ServiceWorkerClientData&& source) final;
-    void serviceWorkerStartedControllingClient(WebCore::ServiceWorkerIdentifier, WebCore::DocumentIdentifier) final;
-    void serviceWorkerStoppedControllingClient(WebCore::ServiceWorkerIdentifier, WebCore::DocumentIdentifier) final;
+    void serviceWorkerStartedControllingClient(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, WebCore::DocumentIdentifier) final;
+    void serviceWorkerStoppedControllingClient(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerRegistrationIdentifier, WebCore::DocumentIdentifier) final;
 
     void matchRegistration(const WebCore::SecurityOrigin& topOrigin, const WebCore::URL& clientURL, RegistrationCallback&&) final;
     void didMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData>&&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to