Unreviewed, rolling out r249801.
authorryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Sep 2019 23:59:32 +0000 (23:59 +0000)
committerryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Sep 2019 23:59:32 +0000 (23:59 +0000)
Caused two servier worker layout tests to become flaky.

Reverted changeset:

"Use WebProcess processIdentifier to identify Service Worker
connections"
https://bugs.webkit.org/show_bug.cgi?id=201459
https://trac.webkit.org/changeset/249801

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249820 268f45cc-cd09-0410-ab3c-d52691b4dbfc

36 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/SessionID.h
Source/WebCore/workers/service/ServiceWorkerClient.cpp
Source/WebCore/workers/service/ServiceWorkerTypes.h
Source/WebCore/workers/service/context/SWContextManager.h
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h
Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.messages.in
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp
Source/WebKit/WebProcess/Network/NetworkProcessConnection.h
Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWClientConnection.h
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h
Source/WebKit/WebProcess/WebProcess.messages.in

index 1aea195..df062a7 100644 (file)
@@ -1,3 +1,16 @@
+2019-09-12  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r249801.
+
+        Caused two servier worker layout tests to become flaky.
+
+        Reverted changeset:
+
+        "Use WebProcess processIdentifier to identify Service Worker
+        connections"
+        https://bugs.webkit.org/show_bug.cgi?id=201459
+        https://trac.webkit.org/changeset/249801
+
 2019-09-12  Chris Dumez  <cdumez@apple.com>
 
         [WKTR] Drop TestRunner.setPrivateBrowsingEnabled_DEPRECATED()
index 91d0a2c..3125eff 100644 (file)
@@ -1,3 +1,16 @@
+2019-09-12  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r249801.
+
+        Caused two servier worker layout tests to become flaky.
+
+        Reverted changeset:
+
+        "Use WebProcess processIdentifier to identify Service Worker
+        connections"
+        https://bugs.webkit.org/show_bug.cgi?id=201459
+        https://trac.webkit.org/changeset/249801
+
 2019-09-12  Youenn Fablet  <youenn@apple.com>
 
         Use WebProcess processIdentifier to identify Service Worker connections
index e1443f0..c71d6a2 100644 (file)
@@ -55,11 +55,6 @@ public:
     {
     }
 
-    explicit SessionID(uint64_t identifier)
-        : m_identifier(identifier)
-    {
-    }
-
     PAL_EXPORT static SessionID generateEphemeralSessionID();
     PAL_EXPORT static SessionID generatePersistentSessionID();
     PAL_EXPORT static void enableGenerationProtection();
@@ -81,6 +76,11 @@ public:
     explicit operator bool() const { return m_identifier; }
 
 private:
+    explicit SessionID(uint64_t identifier)
+        : m_identifier(identifier)
+    {
+    }
+
     static bool isValidSessionIDValue(uint64_t sessionID) { return sessionID != HashTableEmptyValueID && sessionID != HashTableDeletedValueID; }
 
     uint64_t m_identifier;
index 760c4cd..7391c4c 100644 (file)
@@ -99,9 +99,9 @@ ExceptionOr<void> ServiceWorkerClient::postMessage(ScriptExecutionContext& conte
 
     MessageWithMessagePorts message = { messageData.releaseReturnValue(), portsOrException.releaseReturnValue() };
     auto sourceIdentifier = downcast<ServiceWorkerGlobalScope>(context).thread().identifier();
-    callOnMainThread([sessionID = context.sessionID(), message = WTFMove(message), destinationIdentifier = identifier(), sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
+    callOnMainThread([message = WTFMove(message), destinationIdentifier = identifier(), sourceIdentifier, sourceOrigin = context.origin().isolatedCopy()] () mutable {
         if (auto* connection = SWContextManager::singleton().connection())
-            connection->postMessageToServiceWorkerClient(sessionID, destinationIdentifier, message, sourceIdentifier, sourceOrigin);
+            connection->postMessageToServiceWorkerClient(destinationIdentifier, WTFMove(message), sourceIdentifier, sourceOrigin);
     });
 
     return { };
index 886c5ad..f028d24 100644 (file)
@@ -28,7 +28,6 @@
 #if ENABLE(SERVICE_WORKER)
 
 #include "DocumentIdentifier.h"
-#include "ProcessIdentifier.h"
 #include "ServiceWorkerIdentifier.h"
 #include <wtf/ObjectIdentifier.h>
 #include <wtf/Variant.h>
@@ -71,7 +70,7 @@ using ServiceWorkerJobIdentifier = ObjectIdentifier<ServiceWorkerJobIdentifierTy
 enum SWServerToContextConnectionIdentifierType { };
 using SWServerToContextConnectionIdentifier = ObjectIdentifier<SWServerToContextConnectionIdentifierType>;
 
-using SWServerConnectionIdentifierType = ProcessIdentifierType;
+enum SWServerConnectionIdentifierType { };
 using SWServerConnectionIdentifier = ObjectIdentifier<SWServerConnectionIdentifierType>;
 
 using DocumentOrWorkerIdentifier = Variant<DocumentIdentifier, ServiceWorkerIdentifier>;
index fffb711..fe0c084 100644 (file)
@@ -49,7 +49,7 @@ public:
     public:
         virtual ~Connection() { }
 
-        virtual void postMessageToServiceWorkerClient(PAL::SessionID, const ServiceWorkerClientIdentifier& destinationIdentifier, const MessageWithMessagePorts&, ServiceWorkerIdentifier source, const String& sourceOrigin) = 0;
+        virtual void postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, MessageWithMessagePorts&&, ServiceWorkerIdentifier source, const String& sourceOrigin) = 0;
         virtual void serviceWorkerStarted(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, bool doesHandleFetch) = 0;
         virtual void serviceWorkerFailedToStart(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& message) = 0;
         virtual void didFinishInstall(Optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, bool wasSuccessful) = 0;
index 128d72f..e04d0b2 100644 (file)
@@ -50,9 +50,9 @@ namespace WebCore {
 
 static Seconds terminationDelay { 10_s };
 
-SWServer::Connection::Connection(SWServer& server, Identifier identifier)
+SWServer::Connection::Connection(SWServer& server)
     : m_server(server)
-    , m_identifier(identifier)
+    , m_identifier(SWServerConnectionIdentifier::generate())
 {
 }
 
index 5ccf2f4..30e2af5 100644 (file)
@@ -56,7 +56,6 @@ class SWServerToContextConnection;
 enum class ServiceWorkerRegistrationState : uint8_t;
 enum class ServiceWorkerState : uint8_t;
 struct ExceptionData;
-struct MessageWithMessagePorts;
 struct ServiceWorkerClientQueryOptions;
 struct ServiceWorkerContextData;
 struct ServiceWorkerFetchResult;
@@ -87,7 +86,6 @@ public:
         virtual void setRegistrationUpdateViaCache(ServiceWorkerRegistrationIdentifier, ServiceWorkerUpdateViaCache) = 0;
         virtual void notifyClientsOfControllerChange(const HashSet<DocumentIdentifier>& contextIdentifiers, const ServiceWorkerData& newController) = 0;
         virtual void registrationReady(uint64_t registrationReadyRequestIdentifier, ServiceWorkerRegistrationData&&) = 0;
-        virtual void postMessageToServiceWorkerClient(DocumentIdentifier, const MessageWithMessagePorts&, ServiceWorkerIdentifier, const String& sourceOrigin) = 0;
 
         virtual void serverToContextConnectionCreated(SWServerToContextConnection&) = 0;
 
@@ -95,7 +93,7 @@ public:
         const SWServer& server() const { return m_server; }
 
     protected:
-        WEBCORE_EXPORT Connection(SWServer&, Identifier);
+        WEBCORE_EXPORT explicit Connection(SWServer&);
 
         WEBCORE_EXPORT void finishFetchingScriptInServer(const ServiceWorkerFetchResult&);
         WEBCORE_EXPORT void addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier);
index fb1f10b..abf1f63 100644 (file)
@@ -1,3 +1,16 @@
+2019-09-12  Ryan Haddad  <ryanhaddad@apple.com>
+
+        Unreviewed, rolling out r249801.
+
+        Caused two servier worker layout tests to become flaky.
+
+        Reverted changeset:
+
+        "Use WebProcess processIdentifier to identify Service Worker
+        connections"
+        https://bugs.webkit.org/show_bug.cgi?id=201459
+        https://trac.webkit.org/changeset/249801
+
 2019-09-12  Chris Dumez  <cdumez@apple.com>
 
         Pass sessionID to WebProcess with other WebProcessDataStoreParameters
index 6b7cee5..34224be 100644 (file)
@@ -213,22 +213,21 @@ void NetworkConnectionToWebProcess::didReceiveMessage(IPC::Connection& connectio
     
 #if ENABLE(SERVICE_WORKER)
     if (decoder.messageReceiverName() == Messages::WebSWServerConnection::messageReceiverName()) {
-        if (auto swConnection = m_swConnections.get(PAL::SessionID { decoder.destinationID() }))
+        if (auto swConnection = m_swConnections.get(makeObjectIdentifier<SWServerConnectionIdentifierType>(decoder.destinationID())))
             swConnection->didReceiveMessage(connection, decoder);
         return;
     }
+
     if (decoder.messageReceiverName() == Messages::WebSWServerToContextConnection::messageReceiverName()) {
-        ASSERT(m_swContextConnection);
-        if (m_swContextConnection) {
-            m_swContextConnection->didReceiveMessage(connection, decoder);
+        if (auto* contextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) {
+            contextConnection->didReceiveMessage(connection, decoder);
             return;
         }
     }
 
     if (decoder.messageReceiverName() == Messages::ServiceWorkerFetchTask::messageReceiverName()) {
-        ASSERT(m_swContextConnection);
-        if (m_swContextConnection) {
-            m_swContextConnection->didReceiveFetchTaskMessage(connection, decoder);
+        if (auto* contextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) {
+            contextConnection->didReceiveFetchTaskMessage(connection, decoder);
             return;
         }
     }
@@ -269,7 +268,7 @@ void NetworkConnectionToWebProcess::didReceiveSyncMessage(IPC::Connection& conne
 
 #if ENABLE(SERVICE_WORKER)
     if (decoder.messageReceiverName() == Messages::WebSWServerConnection::messageReceiverName()) {
-        if (auto swConnection = m_swConnections.get(PAL::SessionID { decoder.destinationID() }))
+        if (auto swConnection = m_swConnections.get(makeObjectIdentifier<SWServerConnectionIdentifierType>(decoder.destinationID())))
             swConnection->didReceiveSyncMessage(connection, decoder, reply);
         return;
     }
@@ -286,19 +285,10 @@ void NetworkConnectionToWebProcess::didReceiveSyncMessage(IPC::Connection& conne
 void NetworkConnectionToWebProcess::didClose(IPC::Connection& connection)
 {
 #if ENABLE(SERVICE_WORKER)
-    if (m_swContextConnection) {
-        auto& registrableDomain = m_swContextConnection->registrableDomain();
-
-        m_swContextConnection->connectionClosed();
-
-        Optional<PAL::SessionID> sessionID;
-        m_networkProcess->forEachSWServer([&](auto& server) {
-            server.markAllWorkersForRegistrableDomainAsTerminated(registrableDomain);
-            if (server.needsServerToContextConnectionForRegistrableDomain(registrableDomain))
-                sessionID = server.sessionID();
-        });
-        if (sessionID)
-            m_networkProcess->createServerToContextConnection(registrableDomain, *sessionID);
+    if (RefPtr<WebSWServerToContextConnection> serverToContextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) {
+        // Service Worker process exited.
+        m_networkProcess->connectionToContextProcessWasClosed(serverToContextConnection.releaseNonNull());
+        return;
     }
 #else
     UNUSED_PARAM(connection);
@@ -873,23 +863,18 @@ void NetworkConnectionToWebProcess::unregisterSWConnections()
     }
 }
 
-void NetworkConnectionToWebProcess::establishSWServerConnection(PAL::SessionID sessionID)
+void NetworkConnectionToWebProcess::establishSWServerConnection(PAL::SessionID sessionID, CompletionHandler<void(WebCore::SWServerConnectionIdentifier&&)>&& completionHandler)
 {
     auto& server = m_networkProcess->swServerForSession(sessionID);
-    auto connection = makeUnique<WebSWServerConnection>(m_networkProcess, server, m_connection.get(), m_webProcessIdentifier, sessionID);
+    auto connection = makeUnique<WebSWServerConnection>(m_networkProcess, server, m_connection.get(), sessionID);
+    
+    SWServerConnectionIdentifier serverConnectionIdentifier = connection->identifier();
+    LOG(ServiceWorker, "NetworkConnectionToWebProcess::establishSWServerConnection - %s", serverConnectionIdentifier.loggingString().utf8().data());
 
-    ASSERT(!m_swConnections.contains(sessionID));
-    m_swConnections.add(sessionID, makeWeakPtr(*connection));
+    ASSERT(!m_swConnections.contains(serverConnectionIdentifier));
+    m_swConnections.add(serverConnectionIdentifier, makeWeakPtr(*connection));
     server.addConnection(WTFMove(connection));
-}
-
-void NetworkConnectionToWebProcess::establishSWContextConnection(RegistrableDomain&& registrableDomain)
-{
-    m_swContextConnection = WebSWServerToContextConnection::create(m_networkProcess, registrableDomain, m_connection.get());
-
-    m_networkProcess->forEachSWServer([&](auto& server) {
-        server.serverToContextConnectionCreated(*m_swContextConnection);
-    });
+    completionHandler(WTFMove(serverConnectionIdentifier));
 }
 #endif
 
index 380b3e9..ce42a24 100644 (file)
@@ -68,7 +68,6 @@ class NetworkSocketChannel;
 class NetworkSocketStream;
 class WebIDBConnectionToClient;
 class WebSWServerConnection;
-class WebSWServerToContextConnection;
 typedef uint64_t ResourceLoadIdentifier;
 
 namespace NetworkCache {
@@ -207,8 +206,7 @@ private:
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    void establishSWServerConnection(PAL::SessionID);
-    void establishSWContextConnection(WebCore::RegistrableDomain&&);
+    void establishSWServerConnection(PAL::SessionID, CompletionHandler<void(WebCore::SWServerConnectionIdentifier&&)>&&);
     void unregisterSWConnections();
 #endif
 
@@ -319,8 +317,7 @@ private:
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    HashMap<PAL::SessionID, WeakPtr<WebSWServerConnection>> m_swConnections;
-    RefPtr<WebSWServerToContextConnection> m_swContextConnection;
+    HashMap<WebCore::SWServerConnectionIdentifier, WeakPtr<WebSWServerConnection>> m_swConnections;
 #endif
 
 #if ENABLE(APPLE_PAY_REMOTE_UI)
index 3212070..4ff068c 100644 (file)
@@ -79,8 +79,7 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    EstablishSWServerConnection(PAL::SessionID sessionID)
-    EstablishSWContextConnection(WebCore::RegistrableDomain domain)
+    EstablishSWServerConnection(PAL::SessionID sessionID) -> (WebCore::SWServerConnectionIdentifier serverConnectionIdentifier) Synchronous
 #endif
 
     CreateNewMessagePortChannel(struct WebCore::MessagePortIdentifier port1, struct WebCore::MessagePortIdentifier port2)
index ec1aa2d..0475b3b 100644 (file)
@@ -228,6 +228,17 @@ void NetworkProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder
     }
 #endif
 
+#if ENABLE(SERVICE_WORKER)
+    if (decoder.messageReceiverName() == Messages::WebSWServerToContextConnection::messageReceiverName()) {
+        ASSERT(parentProcessHasServiceWorkerEntitlement());
+        if (!parentProcessHasServiceWorkerEntitlement())
+            return;
+        if (auto* webSWConnection = connectionToContextProcessFromIPCConnection(connection)) {
+            webSWConnection->didReceiveMessage(connection, decoder);
+            return;
+        }
+    }
+#endif
     didReceiveNetworkProcessMessage(connection, decoder);
 }
 
@@ -418,7 +429,7 @@ static inline Optional<std::pair<IPC::Connection::Identifier, IPC::Attachment>>
 #endif
 }
 
-void NetworkProcess::createNetworkConnectionToWebProcess(ProcessIdentifier identifier, CompletionHandler<void(Optional<IPC::Attachment>&&)>&& completionHandler)
+void NetworkProcess::createNetworkConnectionToWebProcess(ProcessIdentifier identifier, bool isServiceWorkerProcess, WebCore::RegistrableDomain&& registrableDomain, CompletionHandler<void(Optional<IPC::Attachment>&&)>&& completionHandler)
 {
     auto ipcConnection = createIPCConnectionToWebProcess();
     if (!ipcConnection) {
@@ -435,6 +446,24 @@ void NetworkProcess::createNetworkConnectionToWebProcess(ProcessIdentifier ident
     completionHandler(WTFMove(ipcConnection->second));
 
     connection.setOnLineState(NetworkStateNotifier::singleton().onLine());
+    
+#if ENABLE(SERVICE_WORKER)
+    if (isServiceWorkerProcess) {
+        ASSERT(parentProcessHasServiceWorkerEntitlement());
+        ASSERT(m_waitingForServerToContextProcessConnection);
+        auto contextConnection = WebSWServerToContextConnection::create(*this, registrableDomain, connection.connection());
+        auto addResult = m_serverToContextConnections.add(WTFMove(registrableDomain), contextConnection.copyRef());
+        ASSERT_UNUSED(addResult, addResult.isNewEntry);
+
+        m_waitingForServerToContextProcessConnection = false;
+
+        for (auto* server : SWServer::allServers())
+            server->serverToContextConnectionCreated(contextConnection);
+    }
+#else
+    UNUSED_PARAM(isServiceWorkerProcess);
+    UNUSED_PARAM(registrableDomain);
+#endif
 
     m_storageManagerSet->addConnection(connection.connection());
 }
@@ -2372,10 +2401,36 @@ void NetworkProcess::getSandboxExtensionsForBlobFiles(const Vector<String>& file
 #endif // ENABLE(SANDBOX_EXTENSIONS)
 
 #if ENABLE(SERVICE_WORKER)
-void NetworkProcess::forEachSWServer(const Function<void(SWServer&)>& callback)
+WebSWServerToContextConnection* NetworkProcess::connectionToContextProcessFromIPCConnection(IPC::Connection& connection)
 {
-    for (auto& server : m_swServers.values())
-        callback(*server);
+    for (auto& serverToContextConnection : m_serverToContextConnections.values()) {
+        if (serverToContextConnection->ipcConnection() == &connection)
+            return serverToContextConnection.get();
+    }
+    return nullptr;
+}
+
+void NetworkProcess::connectionToContextProcessWasClosed(Ref<WebSWServerToContextConnection>&& serverToContextConnection)
+{
+    auto& registrableDomain = serverToContextConnection->registrableDomain();
+    
+    serverToContextConnection->connectionClosed();
+    m_serverToContextConnections.remove(registrableDomain);
+    
+    for (auto& swServer : m_swServers.values())
+        swServer->markAllWorkersForRegistrableDomainAsTerminated(registrableDomain);
+    
+    if (needsServerToContextConnectionForRegistrableDomain(registrableDomain)) {
+        RELEASE_LOG(ServiceWorker, "Connection to service worker process was closed but is still needed, relaunching it");
+        createServerToContextConnection(registrableDomain, WTF::nullopt);
+    }
+}
+
+bool NetworkProcess::needsServerToContextConnectionForRegistrableDomain(const RegistrableDomain& registrableDomain) const
+{
+    return WTF::anyOf(m_swServers.values(), [&](auto& swServer) {
+        return swServer->needsServerToContextConnectionForRegistrableDomain(registrableDomain);
+    });
 }
 
 SWServer& NetworkProcess::swServerForSession(PAL::SessionID sessionID)
@@ -2403,36 +2458,40 @@ WebSWOriginStore* NetworkProcess::existingSWOriginStoreForSession(PAL::SessionID
     return &static_cast<WebSWOriginStore&>(swServer->originStore());
 }
 
-bool NetworkProcess::needsServerToContextConnectionForRegistrableDomain(const RegistrableDomain& registrableDomain) const
-{
-    return WTF::anyOf(m_swServers.values(), [&](auto& swServer) {
-        return swServer->needsServerToContextConnectionForRegistrableDomain(registrableDomain);
-    });
-}
-
 WebSWServerToContextConnection* NetworkProcess::serverToContextConnectionForRegistrableDomain(const RegistrableDomain& registrableDomain)
 {
     return m_serverToContextConnections.get(registrableDomain);
 }
 
-void NetworkProcess::createServerToContextConnection(const RegistrableDomain& registrableDomain, PAL::SessionID sessionID)
+void NetworkProcess::createServerToContextConnection(const RegistrableDomain& registrableDomain, Optional<PAL::SessionID> sessionID)
 {
-    if (m_pendingConnectionDomains.contains(registrableDomain))
+    if (m_waitingForServerToContextProcessConnection)
         return;
-
-    m_pendingConnectionDomains.add(registrableDomain);
-    parentProcessConnection()->send(Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess { registrableDomain, sessionID }, 0);
+    
+    m_waitingForServerToContextProcessConnection = true;
+    if (sessionID)
+        parentProcessConnection()->send(Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcessForExplicitSession(registrableDomain, *sessionID), 0);
+    else
+        parentProcessConnection()->send(Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess(registrableDomain), 0);
 }
 
-void NetworkProcess::postMessageToServiceWorkerClient(PAL::SessionID sessionID, const ServiceWorkerClientIdentifier& destinationIdentifier, MessageWithMessagePorts&& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
+void NetworkProcess::postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, MessageWithMessagePorts&& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
 {
-    if (auto* connection = swServerForSession(sessionID).connection(destinationIdentifier.serverConnectionIdentifier))
+    if (auto connection = m_swServerConnections.get(destinationIdentifier.serverConnectionIdentifier))
         connection->postMessageToServiceWorkerClient(destinationIdentifier.contextIdentifier, WTFMove(message), sourceIdentifier, sourceOrigin);
 }
 
+void NetworkProcess::postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&& message, const WebCore::ServiceWorkerOrClientIdentifier& source, SWServerConnectionIdentifier connectionIdentifier)
+{
+    if (auto connection = m_swServerConnections.get(connectionIdentifier))
+        connection->postMessageToServiceWorker(destination, WTFMove(message), source);
+}
+
 void NetworkProcess::registerSWServerConnection(WebSWServerConnection& connection)
 {
     ASSERT(parentProcessHasServiceWorkerEntitlement());
+    ASSERT(!m_swServerConnections.contains(connection.identifier()));
+    m_swServerConnections.add(connection.identifier(), makeWeakPtr(connection));
     auto* store = existingSWOriginStoreForSession(connection.sessionID());
     ASSERT(store);
     if (store)
@@ -2441,21 +2500,26 @@ void NetworkProcess::registerSWServerConnection(WebSWServerConnection& connectio
 
 void NetworkProcess::unregisterSWServerConnection(WebSWServerConnection& connection)
 {
+    ASSERT(m_swServerConnections.get(connection.identifier()).get() == &connection);
+    m_swServerConnections.remove(connection.identifier());
     if (auto* store = existingSWOriginStoreForSession(connection.sessionID()))
         store->unregisterSWServerConnection(connection);
 }
 
-void NetworkProcess::registerSWContextConnection(WebSWServerToContextConnection& connection)
-{
-    ASSERT(!m_serverToContextConnections.contains(connection.registrableDomain()));
-    m_pendingConnectionDomains.remove(connection.registrableDomain());
-    m_serverToContextConnections.add(connection.registrableDomain(), &connection);
-}
-
-void NetworkProcess::unregisterSWContextConnection(WebSWServerToContextConnection& connection)
+void NetworkProcess::swContextConnectionMayNoLongerBeNeeded(WebSWServerToContextConnection& serverToContextConnection)
 {
-    ASSERT(m_serverToContextConnections.get(connection.registrableDomain()) == &connection);
-    m_serverToContextConnections.remove(connection.registrableDomain());
+    auto& registrableDomain = serverToContextConnection.registrableDomain();
+    if (needsServerToContextConnectionForRegistrableDomain(registrableDomain))
+        return;
+    
+    RELEASE_LOG(ServiceWorker, "Service worker process is no longer needed, terminating it");
+    serverToContextConnection.terminate();
+    
+    for (auto& swServer : m_swServers.values())
+        swServer->markAllWorkersForRegistrableDomainAsTerminated(registrableDomain);
+    
+    serverToContextConnection.connectionClosed();
+    m_serverToContextConnections.remove(registrableDomain);
 }
 
 void NetworkProcess::disableServiceWorkerProcessTerminationDelay()
index b8ddc8f..6355dd9 100644 (file)
@@ -298,17 +298,16 @@ public:
 
 #if ENABLE(SERVICE_WORKER)
     WebSWServerToContextConnection* serverToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&);
-    void createServerToContextConnection(const WebCore::RegistrableDomain&, PAL::SessionID);
+    void createServerToContextConnection(const WebCore::RegistrableDomain&, Optional<PAL::SessionID>);
     
     WebCore::SWServer& swServerForSession(PAL::SessionID);
     void registerSWServerConnection(WebSWServerConnection&);
     void unregisterSWServerConnection(WebSWServerConnection&);
     
-    void registerSWContextConnection(WebSWServerToContextConnection&);
-    void unregisterSWContextConnection(WebSWServerToContextConnection&);
-
-    bool needsServerToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&) const;
-    void forEachSWServer(const Function<void(WebCore::SWServer&)>&);
+    void swContextConnectionMayNoLongerBeNeeded(WebSWServerToContextConnection&);
+    
+    WebSWServerToContextConnection* connectionToContextProcessFromIPCConnection(IPC::Connection&);
+    void connectionToContextProcessWasClosed(Ref<WebSWServerToContextConnection>&&);
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -394,7 +393,7 @@ private:
     // Message Handlers
     void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
     void initializeNetworkProcess(NetworkProcessCreationParameters&&);
-    void createNetworkConnectionToWebProcess(WebCore::ProcessIdentifier, CompletionHandler<void(Optional<IPC::Attachment>&&)>&&);
+    void createNetworkConnectionToWebProcess(WebCore::ProcessIdentifier, bool isServiceWorkerProcess, WebCore::RegistrableDomain&&, CompletionHandler<void(Optional<IPC::Attachment>&&)>&&);
 
     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, uint64_t callbackID);
@@ -463,12 +462,13 @@ private:
 #if ENABLE(SERVICE_WORKER)
     void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
     
-    void postMessageToServiceWorkerClient(PAL::SessionID, const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
-    void postMessageToServiceWorker(PAL::SessionID, WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
+    void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
+    void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
     
     void disableServiceWorkerProcessTerminationDelay();
     
     WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
+    bool needsServerToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&) const;
 
     void addServiceWorkerSession(PAL::SessionID, String& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
 #endif
@@ -539,11 +539,12 @@ private:
     Lock m_storageTaskMutex;
     
 #if ENABLE(SERVICE_WORKER)
-    HashMap<WebCore::RegistrableDomain, WebSWServerToContextConnection*> m_serverToContextConnections;
+    HashMap<WebCore::RegistrableDomain, RefPtr<WebSWServerToContextConnection>> m_serverToContextConnections;
+    bool m_waitingForServerToContextProcessConnection { false };
     bool m_shouldDisableServiceWorkerProcessTerminationDelay { false };
     HashMap<PAL::SessionID, String> m_swDatabasePaths;
     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
-    HashSet<WebCore::RegistrableDomain> m_pendingConnectionDomains;
+    HashMap<WebCore::SWServerConnectionIdentifier, WeakPtr<WebSWServerConnection>> m_swServerConnections;
 #endif
 
 #if PLATFORM(COCOA)
index a3f7ea3..c11020f 100644 (file)
@@ -25,7 +25,7 @@ messages -> NetworkProcess LegacyReceiver {
     InitializeNetworkProcess(struct WebKit::NetworkProcessCreationParameters processCreationParameters)
 
     # Creates a connection for communication with a WebProcess
-    CreateNetworkConnectionToWebProcess(WebCore::ProcessIdentifier processIdentifier) -> (Optional<IPC::Attachment> connectionIdentifier) Async
+    CreateNetworkConnectionToWebProcess(WebCore::ProcessIdentifier processIdentifier, bool isServiceWorkerProcess, WebCore::RegistrableDomain registrableDomain) -> (Optional<IPC::Attachment> connectionIdentifier) Async
 
 #if USE(SOUP)
     SetIgnoreTLSErrors(bool ignoreTLSErrors)
@@ -151,7 +151,10 @@ messages -> NetworkProcess LegacyReceiver {
     SetCacheStorageParameters(PAL::SessionID sessionID, String cacheStorageDirectory, WebKit::SandboxExtension::Handle handle);
 
 #if ENABLE(SERVICE_WORKER)
-    PostMessageToServiceWorkerClient(PAL::SessionID sessionID, struct WebCore::ServiceWorkerClientIdentifier destinationIdentifier, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerIdentifier sourceIdentifier, String sourceOrigin)
+    PostMessageToServiceWorkerClient(struct WebCore::ServiceWorkerClientIdentifier destinationIdentifier, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerIdentifier sourceIdentifier, String sourceOrigin)
+
+    PostMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerOrClientIdentifier source, WebCore::SWServerConnectionIdentifier connectionIdentifier)
+
     DisableServiceWorkerProcessTerminationDelay()
 #endif
 
index deae2b3..6bcb99a 100644 (file)
@@ -61,8 +61,8 @@ using namespace WebCore;
 #define SWSERVERCONNECTION_RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(m_sessionID.isAlwaysOnLoggingAllowed(), ServiceWorker, "%p - WebSWServerConnection::" fmt, this, ##__VA_ARGS__)
 #define SWSERVERCONNECTION_RELEASE_LOG_ERROR_IF_ALLOWED(fmt, ...) RELEASE_LOG_ERROR_IF(m_sessionID.isAlwaysOnLoggingAllowed(), ServiceWorker, "%p - WebSWServerConnection::" fmt, this, ##__VA_ARGS__)
 
-WebSWServerConnection::WebSWServerConnection(NetworkProcess& networkProcess, SWServer& server, IPC::Connection& connection, ProcessIdentifier processIdentifier, SessionID sessionID)
-    : SWServer::Connection(server, processIdentifier)
+WebSWServerConnection::WebSWServerConnection(NetworkProcess& networkProcess, SWServer& server, IPC::Connection& connection, SessionID sessionID)
+    : SWServer::Connection(server)
     , m_sessionID(sessionID)
     , m_contentConnection(connection)
     , m_networkProcess(networkProcess)
@@ -253,13 +253,13 @@ void WebSWServerConnection::scheduleJobInServer(ServiceWorkerJobData&& jobData)
     server().scheduleJob(WTFMove(jobData));
 }
 
-void WebSWServerConnection::postMessageToServiceWorkerClient(DocumentIdentifier destinationContextIdentifier, const MessageWithMessagePorts& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
+void WebSWServerConnection::postMessageToServiceWorkerClient(DocumentIdentifier destinationContextIdentifier, MessageWithMessagePorts&& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
 {
     auto* sourceServiceWorker = server().workerByID(sourceIdentifier);
     if (!sourceServiceWorker)
         return;
 
-    send(Messages::WebSWClientConnection::PostMessageToServiceWorkerClient { destinationContextIdentifier, message, sourceServiceWorker->data(), sourceOrigin });
+    send(Messages::WebSWClientConnection::PostMessageToServiceWorkerClient { destinationContextIdentifier, WTFMove(message), sourceServiceWorker->data(), sourceOrigin });
 }
 
 void WebSWServerConnection::matchRegistration(uint64_t registrationMatchRequestIdentifier, const SecurityOriginData& topOrigin, const URL& clientURL)
index ade8e7e..90023d6 100644 (file)
@@ -31,7 +31,6 @@
 #include "MessageSender.h"
 #include "ServiceWorkerFetchTask.h"
 #include <WebCore/FetchIdentifier.h>
-#include <WebCore/ProcessIdentifier.h>
 #include <WebCore/SWServer.h>
 #include <pal/SessionID.h>
 #include <wtf/HashMap.h>
@@ -54,7 +53,7 @@ class NetworkProcess;
 
 class WebSWServerConnection : public WebCore::SWServer::Connection, public IPC::MessageSender, public IPC::MessageReceiver {
 public:
-    WebSWServerConnection(NetworkProcess&, WebCore::SWServer&, IPC::Connection&, WebCore::ProcessIdentifier, PAL::SessionID);
+    WebSWServerConnection(NetworkProcess&, WebCore::SWServer&, IPC::Connection&, PAL::SessionID);
     WebSWServerConnection(const WebSWServerConnection&) = delete;
     ~WebSWServerConnection() final;
 
@@ -65,6 +64,9 @@ public:
 
     PAL::SessionID sessionID() const { return m_sessionID; }
 
+    void postMessageToServiceWorkerClient(WebCore::DocumentIdentifier destinationContextIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceServiceWorkerIdentifier, const String& sourceOrigin);
+    void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source);
+
 private:
     // Implement SWServer::Connection (Messages to the client WebProcess)
     void rejectJobInClient(WebCore::ServiceWorkerJobIdentifier, const WebCore::ExceptionData&) final;
@@ -92,8 +94,6 @@ private:
     void unregisterServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier&);
     void syncTerminateWorkerFromClient(WebCore::ServiceWorkerIdentifier&&, CompletionHandler<void()>&&);
 
-    void postMessageToServiceWorkerClient(WebCore::DocumentIdentifier destinationContextIdentifier, const WebCore::MessageWithMessagePorts&, WebCore::ServiceWorkerIdentifier sourceServiceWorkerIdentifier, const String& sourceOrigin) final;
-
     void serverToContextConnectionCreated(WebCore::SWServerToContextConnection&) final;
 
     bool isThrottleable() const { return m_isThrottleable; }
@@ -102,10 +102,8 @@ private:
     void setThrottleState(bool isThrottleable);
     void updateThrottleState();
 
-    void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source);
-
     IPC::Connection* messageSenderConnection() const final { return m_contentConnection.ptr(); }
-    uint64_t messageSenderDestinationID() const final { return m_sessionID.toUInt64(); }
+    uint64_t messageSenderDestinationID() const final { return identifier().toUInt64(); }
     
     template<typename U> static void sendToContextProcess(WebCore::SWServerToContextConnection&, U&& message);
 
index 7b1e920..bfe403d 100644 (file)
 #if ENABLE(SERVICE_WORKER)
 
 #include "FormDataReference.h"
-#include "Logging.h"
 #include "NetworkProcess.h"
 #include "ServiceWorkerFetchTask.h"
 #include "ServiceWorkerFetchTaskMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebSWContextManagerConnectionMessages.h"
-#include <WebCore/SWServer.h>
 #include <WebCore/ServiceWorkerContextData.h>
 
 namespace WebKit {
@@ -46,13 +44,9 @@ WebSWServerToContextConnection::WebSWServerToContextConnection(NetworkProcess& n
     , m_ipcConnection(WTFMove(connection))
     , m_networkProcess(networkProcess)
 {
-    m_networkProcess->registerSWContextConnection(*this);
 }
 
-WebSWServerToContextConnection::~WebSWServerToContextConnection()
-{
-    m_networkProcess->unregisterSWContextConnection(*this);
-}
+WebSWServerToContextConnection::~WebSWServerToContextConnection() = default;
 
 IPC::Connection* WebSWServerToContextConnection::messageSenderConnection() const
 {
@@ -71,12 +65,6 @@ void WebSWServerToContextConnection::connectionClosed()
         fetch->fail(ResourceError { errorDomainWebKitInternal, 0, { }, "Service Worker context closed"_s });
 }
 
-void WebSWServerToContextConnection::postMessageToServiceWorkerClient(PAL::SessionID sessionID, const ServiceWorkerClientIdentifier& destinationIdentifier, const MessageWithMessagePorts& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
-{
-    if (auto* connection = m_networkProcess->swServerForSession(sessionID).connection(destinationIdentifier.serverConnectionIdentifier))
-        connection->postMessageToServiceWorkerClient(destinationIdentifier.contextIdentifier, message, sourceIdentifier, sourceOrigin);
-}
-
 void WebSWServerToContextConnection::installServiceWorkerContext(const ServiceWorkerContextData& data, PAL::SessionID sessionID, const String& userAgent)
 {
     send(Messages::WebSWContextManagerConnection::InstallServiceWorker { data, sessionID, userAgent });
@@ -129,17 +117,7 @@ void WebSWServerToContextConnection::didFinishSkipWaiting(uint64_t callbackID)
 
 void WebSWServerToContextConnection::connectionMayNoLongerBeNeeded()
 {
-    if (m_networkProcess->needsServerToContextConnectionForRegistrableDomain(registrableDomain()))
-        return;
-
-    RELEASE_LOG(ServiceWorker, "Service worker process is no longer needed, terminating it");
-    terminate();
-
-    m_networkProcess->forEachSWServer([&](auto& server) {
-        server.markAllWorkersForRegistrableDomainAsTerminated(registrableDomain());
-    });
-
-    connectionClosed();
+    m_networkProcess->swContextConnectionMayNoLongerBeNeeded(*this);
 }
 
 void WebSWServerToContextConnection::setThrottleState(bool isThrottleable)
index 20ec15e..90a07ea 100644 (file)
@@ -34,7 +34,6 @@
 
 namespace WebCore {
 struct FetchOptions;
-struct MessageWithMessagePorts;
 class ResourceRequest;
 }
 
@@ -83,8 +82,6 @@ private:
     IPC::Connection* messageSenderConnection() const final;
     uint64_t messageSenderDestinationID() const final;
 
-    void postMessageToServiceWorkerClient(PAL::SessionID, const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, const WebCore::MessageWithMessagePorts&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
-
     // Messages to the SW host WebProcess
     void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&, PAL::SessionID, const String& userAgent) final;
     void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
index e3158fc..9949e3d 100644 (file)
@@ -36,7 +36,6 @@ messages -> WebSWServerToContextConnection {
     MatchAll(uint64_t matchAllRequestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, struct WebCore::ServiceWorkerClientQueryOptions options);
     Claim(uint64_t claimRequestIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);
     SetScriptResource(WebCore::ServiceWorkerIdentifier identifier, URL scriptURL, String script, URL responseURL, String mimeType);
-    PostMessageToServiceWorkerClient(PAL::SessionID sessionID, struct WebCore::ServiceWorkerClientIdentifier destination, struct WebCore::MessageWithMessagePorts message, WebCore::ServiceWorkerIdentifier source, String sourceOrigin)
 }
 
 #endif // ENABLE(SERVICE_WORKER)
index 51b3e90..31146bf 100644 (file)
@@ -142,7 +142,16 @@ void NetworkProcessProxy::getNetworkProcessConnection(WebProcessProxy& webProces
 
 void NetworkProcessProxy::openNetworkProcessConnection(uint64_t connectionRequestIdentifier, WebProcessProxy& webProcessProxy)
 {
-    connection()->sendWithAsyncReply(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess { webProcessProxy.coreProcessIdentifier() }, [this, weakThis = makeWeakPtr(this), webProcessProxy = makeWeakPtr(webProcessProxy), connectionRequestIdentifier](auto&& connectionIdentifier) mutable {
+    bool isServiceWorkerProcess = false;
+    RegistrableDomain registrableDomain;
+#if ENABLE(SERVICE_WORKER)
+    if (webProcessProxy.isRunningServiceWorkers()) {
+        isServiceWorkerProcess = true;
+        registrableDomain = webProcessProxy.registrableDomain();
+    }
+#endif
+
+    connection()->sendWithAsyncReply(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess { webProcessProxy.coreProcessIdentifier(), isServiceWorkerProcess, registrableDomain }, [this, weakThis = makeWeakPtr(this), webProcessProxy = makeWeakPtr(webProcessProxy), connectionRequestIdentifier](auto&& connectionIdentifier) mutable {
         if (!weakThis)
             return;
 
@@ -1200,7 +1209,12 @@ void NetworkProcessProxy::getSandboxExtensionsForBlobFiles(const Vector<String>&
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-void NetworkProcessProxy::establishWorkerContextConnectionToNetworkProcess(RegistrableDomain&& registrableDomain, PAL::SessionID sessionID)
+void NetworkProcessProxy::establishWorkerContextConnectionToNetworkProcess(RegistrableDomain&& registrableDomain)
+{
+    m_processPool.establishWorkerContextConnectionToNetworkProcess(*this, WTFMove(registrableDomain), WTF::nullopt);
+}
+
+void NetworkProcessProxy::establishWorkerContextConnectionToNetworkProcessForExplicitSession(RegistrableDomain&& registrableDomain, PAL::SessionID sessionID)
 {
     m_processPool.establishWorkerContextConnectionToNetworkProcess(*this, WTFMove(registrableDomain), sessionID);
 }
index 88da7c0..80dfe60 100644 (file)
@@ -238,7 +238,8 @@ private:
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    void establishWorkerContextConnectionToNetworkProcess(WebCore::RegistrableDomain&&, PAL::SessionID);
+    void establishWorkerContextConnectionToNetworkProcess(WebCore::RegistrableDomain&&);
+    void establishWorkerContextConnectionToNetworkProcessForExplicitSession(WebCore::RegistrableDomain&&, PAL::SessionID);
 #endif
 
     void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t> quota)>&&);
index a6dbb7c..e4afe4b 100644 (file)
@@ -61,7 +61,8 @@ messages -> NetworkProcessProxy LegacyReceiver {
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    EstablishWorkerContextConnectionToNetworkProcess(WebCore::RegistrableDomain registrableDomain, PAL::SessionID sessionID)
+    EstablishWorkerContextConnectionToNetworkProcess(WebCore::RegistrableDomain registrableDomain)
+    EstablishWorkerContextConnectionToNetworkProcessForExplicitSession(WebCore::RegistrableDomain registrableDomain, PAL::SessionID explicitSession)
 #endif
 
     RequestStorageSpace(PAL::SessionID sessionID, struct WebCore::ClientOrigin origin, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired) -> (Optional<uint64_t> newQuota) Async
index 0012abb..7c6c02d 100644 (file)
@@ -687,13 +687,18 @@ void WebProcessPool::getNetworkProcessConnection(WebProcessProxy& webProcessProx
 }
 
 #if ENABLE(SERVICE_WORKER)
-void WebProcessPool::establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy& proxy, RegistrableDomain&& registrableDomain, PAL::SessionID sessionID)
+void WebProcessPool::establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy& proxy, RegistrableDomain&& registrableDomain, Optional<PAL::SessionID> sessionID)
 {
     ASSERT_UNUSED(proxy, &proxy == m_networkProcess.get());
 
+    if (m_serviceWorkerProcesses.contains(registrableDomain))
+        return;
+
     m_mayHaveRegisteredServiceWorkers.clear();
 
-    auto* websiteDataStore = WebsiteDataStore::existingNonDefaultDataStoreForSessionID(sessionID);
+    WebsiteDataStore* websiteDataStore = nullptr;
+    if (sessionID)
+        websiteDataStore = WebsiteDataStore::existingNonDefaultDataStoreForSessionID(*sessionID);
 
     if (!websiteDataStore) {
         if (!m_websiteDataStore)
@@ -701,9 +706,6 @@ void WebProcessPool::establishWorkerContextConnectionToNetworkProcess(NetworkPro
         websiteDataStore = &m_websiteDataStore->websiteDataStore();
     }
 
-    if (m_serviceWorkerProcesses.contains(registrableDomain))
-        return;
-
     if (m_serviceWorkerProcesses.isEmpty())
         sendToAllProcesses(Messages::WebProcess::RegisterServiceWorkerClients { });
 
@@ -716,7 +718,7 @@ void WebProcessPool::establishWorkerContextConnectionToNetworkProcess(NetworkPro
     auto* serviceWorkerProcessProxyPtr = serviceWorkerProcessProxy.ptr();
     m_processes.append(WTFMove(serviceWorkerProcessProxy));
 
-    serviceWorkerProcessProxyPtr->establishServiceWorkerContext(m_serviceWorkerPreferences ? m_serviceWorkerPreferences.value() : m_defaultPageGroup->preferences().store());
+    serviceWorkerProcessProxyPtr->establishServiceWorkerContext(m_serviceWorkerPreferences ? m_serviceWorkerPreferences.value() : m_defaultPageGroup->preferences().store(), sessionID.valueOr(PAL::SessionID::defaultSessionID()));
     if (!m_serviceWorkerUserAgent.isNull())
         serviceWorkerProcessProxyPtr->setServiceWorkerUserAgent(m_serviceWorkerUserAgent);
 }
index 21425d2..5370bd2 100644 (file)
@@ -381,7 +381,7 @@ public:
 
     bool isServiceWorkerPageID(WebPageProxyIdentifier) const;
 #if ENABLE(SERVICE_WORKER)
-    void establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy&, WebCore::RegistrableDomain&&, PAL::SessionID);
+    void establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy&, WebCore::RegistrableDomain&&, Optional<PAL::SessionID>);
     const HashMap<WebCore::RegistrableDomain, WebProcessProxy*>& serviceWorkerProxies() const { return m_serviceWorkerProcesses; }
     void setAllowsAnySSLCertificateForServiceWorker(bool allows) { m_allowsAnySSLCertificateForServiceWorker = allows; }
     bool allowsAnySSLCertificateForServiceWorker() const { return m_allowsAnySSLCertificateForServiceWorker; }
index d3c82f0..c39c4b6 100644 (file)
@@ -1499,9 +1499,9 @@ void WebProcessProxy::releaseBackgroundActivityTokenForFullscreenInput()
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-void WebProcessProxy::establishServiceWorkerContext(const WebPreferencesStore& store)
+void WebProcessProxy::establishServiceWorkerContext(const WebPreferencesStore& store, PAL::SessionID sessionID)
 {
-    send(Messages::WebProcess::EstablishWorkerContextConnectionToNetworkProcess { processPool().defaultPageGroup().pageGroupID(), m_serviceWorkerInformation->serviceWorkerPageProxyID, m_serviceWorkerInformation->serviceWorkerPageID, store, *m_registrableDomain, m_websiteDataStore->sessionID() }, 0);
+    send(Messages::WebProcess::EstablishWorkerContextConnectionToNetworkProcess { processPool().defaultPageGroup().pageGroupID(), m_serviceWorkerInformation->serviceWorkerPageProxyID, m_serviceWorkerInformation->serviceWorkerPageID, store, sessionID }, 0);
 }
 
 void WebProcessProxy::setServiceWorkerUserAgent(const String& userAgent)
index 5d435bf..ae910a5 100644 (file)
@@ -313,7 +313,8 @@ public:
     void deref() final { ThreadSafeRefCounted::deref(); }
 
 #if ENABLE(SERVICE_WORKER)
-    void establishServiceWorkerContext(const WebPreferencesStore&);
+    void establishServiceWorkerContext(const WebPreferencesStore&, PAL::SessionID);
+    void startForServiceWorkers(const WebPreferencesStore&, PAL::SessionID);
     void setServiceWorkerUserAgent(const String&);
     void updateServiceWorkerPreferencesStore(const WebPreferencesStore&);
     bool hasServiceWorkerPageProxy(WebPageProxyIdentifier pageProxyID) { return m_serviceWorkerInformation && m_serviceWorkerInformation->serviceWorkerPageProxyID == pageProxyID; }
index 878006e..949cada 100644 (file)
@@ -137,7 +137,7 @@ void NetworkProcessConnection::didReceiveMessage(IPC::Connection& connection, IP
 
 #if ENABLE(SERVICE_WORKER)
     if (decoder.messageReceiverName() == Messages::WebSWClientConnection::messageReceiverName()) {
-        auto serviceWorkerConnection = m_swConnectionsBySession.get(PAL::SessionID { decoder.destinationID() });
+        auto serviceWorkerConnection = m_swConnectionsByIdentifier.get(makeObjectIdentifier<SWServerConnectionIdentifierType>(decoder.destinationID()));
         if (serviceWorkerConnection)
             serviceWorkerConnection->didReceiveMessage(connection, decoder);
         return;
@@ -200,7 +200,7 @@ void NetworkProcessConnection::didClose(IPC::Connection&)
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    auto swConnections = std::exchange(m_swConnectionsBySession, { });
+    auto swConnections = std::exchange(m_swConnectionsByIdentifier, { });
     for (auto& connection : swConnections.values())
         connection->connectionToServerLost();
 #endif
@@ -264,6 +264,25 @@ WebSWClientConnection& NetworkProcessConnection::serviceWorkerConnectionForSessi
         return WebSWClientConnection::create(sessionID);
     }).iterator->value;
 }
+
+void NetworkProcessConnection::removeSWClientConnection(WebSWClientConnection& connection)
+{
+    ASSERT(m_swConnectionsByIdentifier.contains(connection.serverConnectionIdentifier()));
+    m_swConnectionsByIdentifier.remove(connection.serverConnectionIdentifier());
+}
+
+SWServerConnectionIdentifier NetworkProcessConnection::initializeSWClientConnection(WebSWClientConnection& connection)
+{
+    ASSERT(connection.sessionID().isValid());
+    SWServerConnectionIdentifier identifier;
+    bool result = m_connection->sendSync(Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection(connection.sessionID()), Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection::Reply(identifier), 0);
+    ASSERT_UNUSED(result, result);
+
+    ASSERT(!m_swConnectionsByIdentifier.contains(identifier));
+    m_swConnectionsByIdentifier.add(identifier, &connection);
+
+    return identifier;
+}
 #endif
 
 void NetworkProcessConnection::messagesAvailableForPort(const WebCore::MessagePortIdentifier& messagePortIdentifier)
index 2b4ea1a..cf3ede1 100644 (file)
@@ -78,6 +78,9 @@ public:
 #if ENABLE(SERVICE_WORKER)
     WebSWClientConnection* existingServiceWorkerConnectionForSession(PAL::SessionID sessionID) { return m_swConnectionsBySession.get(sessionID); }
     WebSWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID);
+
+    WebCore::SWServerConnectionIdentifier initializeSWClientConnection(WebSWClientConnection&);
+    void removeSWClientConnection(WebSWClientConnection&);
 #endif
 
 private:
@@ -110,6 +113,7 @@ private:
 
 #if ENABLE(SERVICE_WORKER)
     HashMap<PAL::SessionID, RefPtr<WebSWClientConnection>> m_swConnectionsBySession;
+    HashMap<WebCore::SWServerConnectionIdentifier, WebSWClientConnection*> m_swConnectionsByIdentifier;
 #endif
 };
 
index a8aa679..e75eefa 100644 (file)
@@ -31,7 +31,6 @@
 #include "DataReference.h"
 #include "FormDataReference.h"
 #include "Logging.h"
-#include "NetworkConnectionToWebProcessMessages.h"
 #include "NetworkProcessConnection.h"
 #include "NetworkProcessMessages.h"
 #include "ServiceWorkerClientFetch.h"
@@ -41,7 +40,6 @@
 #include "WebSWOriginTable.h"
 #include "WebSWServerConnectionMessages.h"
 #include <WebCore/Document.h>
-#include <WebCore/ProcessIdentifier.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/SerializedScriptValue.h>
 #include <WebCore/ServiceWorkerClientData.h>
@@ -57,61 +55,77 @@ using namespace WebCore;
 
 WebSWClientConnection::WebSWClientConnection(SessionID sessionID)
     : m_sessionID(sessionID)
-    , m_identifier(Process::identifier())
     , m_swOriginTable(makeUniqueRef<WebSWOriginTable>())
 {
     ASSERT(m_sessionID.isValid());
-    send(Messages::NetworkConnectionToWebProcess::EstablishSWServerConnection { sessionID });
+    initializeConnectionIfNeeded();
 }
 
 WebSWClientConnection::~WebSWClientConnection()
 {
-    clear();
+    if (m_connection)
+        WebProcess::singleton().ensureNetworkProcessConnection().removeSWClientConnection(*this);
 }
 
-IPC::Connection* WebSWClientConnection::messageSenderConnection() const
+void WebSWClientConnection::initializeConnectionIfNeeded()
 {
-    return &WebProcess::singleton().ensureNetworkProcessConnection().connection();
+    if (m_connection)
+        return;
+
+    auto& networkProcessConnection = WebProcess::singleton().ensureNetworkProcessConnection();
+
+    m_connection = &networkProcessConnection.connection();
+    m_identifier = networkProcessConnection.initializeSWClientConnection(*this);
+
+    updateThrottleState();
+}
+
+template<typename U>
+void WebSWClientConnection::ensureConnectionAndSend(const U& message)
+{
+    initializeConnectionIfNeeded();
+    if (m_connection)
+        send(message);
 }
 
 void WebSWClientConnection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
 {
-    send(Messages::WebSWServerConnection::ScheduleJobInServer { jobData });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::ScheduleJobInServer(jobData));
 }
 
 void WebSWClientConnection::finishFetchingScriptInServer(const ServiceWorkerFetchResult& result)
 {
-    send(Messages::WebSWServerConnection::FinishFetchingScriptInServer { result });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::FinishFetchingScriptInServer(result));
 }
 
 void WebSWClientConnection::addServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    send(Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer { identifier });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer(identifier));
 }
 
 void WebSWClientConnection::removeServiceWorkerRegistrationInServer(ServiceWorkerRegistrationIdentifier identifier)
 {
-    send(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer { identifier });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer(identifier));
 }
 
 void WebSWClientConnection::postMessageToServiceWorker(ServiceWorkerIdentifier destinationIdentifier, MessageWithMessagePorts&& message, const ServiceWorkerOrClientIdentifier& sourceIdentifier)
 {
-    send(Messages::WebSWServerConnection::PostMessageToServiceWorker { destinationIdentifier, WTFMove(message), sourceIdentifier });
+    WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkProcess::PostMessageToServiceWorker { destinationIdentifier, WTFMove(message), sourceIdentifier, serverConnectionIdentifier() }, 0);
 }
 
 void WebSWClientConnection::registerServiceWorkerClient(const SecurityOrigin& topOrigin, const WebCore::ServiceWorkerClientData& data, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, const String& userAgent)
 {
-    send(Messages::WebSWServerConnection::RegisterServiceWorkerClient { topOrigin.data(), data, controllingServiceWorkerRegistrationIdentifier, userAgent });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::RegisterServiceWorkerClient { topOrigin.data(), data, controllingServiceWorkerRegistrationIdentifier, userAgent });
 }
 
 void WebSWClientConnection::unregisterServiceWorkerClient(DocumentIdentifier contextIdentifier)
 {
-    send(Messages::WebSWServerConnection::UnregisterServiceWorkerClient { ServiceWorkerClientIdentifier { serverConnectionIdentifier(), contextIdentifier } });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::UnregisterServiceWorkerClient { ServiceWorkerClientIdentifier { serverConnectionIdentifier(), contextIdentifier } });
 }
 
 void WebSWClientConnection::didResolveRegistrationPromise(const ServiceWorkerRegistrationKey& key)
 {
-    send(Messages::WebSWServerConnection::DidResolveRegistrationPromise { key });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::DidResolveRegistrationPromise(key));
 }
 
 bool WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin(const SecurityOriginData& origin) const
@@ -162,24 +176,25 @@ void WebSWClientConnection::matchRegistration(SecurityOriginData&& topOrigin, co
     runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = WTFMove(topOrigin), clientURL]() mutable {
         uint64_t callbackID = ++m_previousCallbackIdentifier;
         m_ongoingMatchRegistrationTasks.add(callbackID, WTFMove(callback));
-        send(Messages::WebSWServerConnection::MatchRegistration(callbackID, topOrigin, clientURL));
+        ensureConnectionAndSend(Messages::WebSWServerConnection::MatchRegistration(callbackID, topOrigin, clientURL));
     });
 }
 
-void WebSWClientConnection::runOrDelayTaskForImport(Function<void()>&& task)
+void WebSWClientConnection::runOrDelayTaskForImport(WTF::Function<void()>&& task)
 {
     if (m_swOriginTable->isImported()) {
         task();
         return;
     }
     m_tasksPendingOriginImport.append(WTFMove(task));
+    initializeConnectionIfNeeded();
 }
 
 void WebSWClientConnection::whenRegistrationReady(const SecurityOriginData& topOrigin, const URL& clientURL, WhenRegistrationReadyCallback&& callback)
 {
     uint64_t callbackID = ++m_previousCallbackIdentifier;
     m_ongoingRegistrationReadyTasks.add(callbackID, WTFMove(callback));
-    send(Messages::WebSWServerConnection::WhenRegistrationReady(callbackID, topOrigin, clientURL));
+    ensureConnectionAndSend(Messages::WebSWServerConnection::WhenRegistrationReady(callbackID, topOrigin, clientURL));
 }
 
 void WebSWClientConnection::registrationReady(uint64_t callbackID, WebCore::ServiceWorkerRegistrationData&& registrationData)
@@ -201,32 +216,29 @@ void WebSWClientConnection::getRegistrations(SecurityOriginData&& topOrigin, con
     runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = WTFMove(topOrigin), clientURL]() mutable {
         uint64_t callbackID = ++m_previousCallbackIdentifier;
         m_ongoingGetRegistrationsTasks.add(callbackID, WTFMove(callback));
-        send(Messages::WebSWServerConnection::GetRegistrations { callbackID, topOrigin, clientURL });
+        ensureConnectionAndSend(Messages::WebSWServerConnection::GetRegistrations(callbackID, topOrigin, clientURL));
     });
 }
 
 void WebSWClientConnection::startFetch(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier, const ResourceRequest& request, const FetchOptions& options, const String& referrer)
 {
-    send(Messages::WebSWServerConnection::StartFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, IPC::FormDataReference { request.httpBody() }, referrer });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::StartFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, IPC::FormDataReference { request.httpBody() }, referrer });
 }
 
 void WebSWClientConnection::cancelFetch(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
 {
-    send(Messages::WebSWServerConnection::CancelFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::CancelFetch { serviceWorkerRegistrationIdentifier, fetchIdentifier });
 }
 
 void WebSWClientConnection::continueDidReceiveFetchResponse(FetchIdentifier fetchIdentifier, ServiceWorkerRegistrationIdentifier serviceWorkerRegistrationIdentifier)
 {
-    send(Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse { serviceWorkerRegistrationIdentifier, fetchIdentifier });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse { serviceWorkerRegistrationIdentifier, fetchIdentifier });
 }
 
 void WebSWClientConnection::connectionToServerLost()
 {
-    clear();
-}
+    m_connection = nullptr;
 
-void WebSWClientConnection::clear()
-{
     auto registrationTasks = WTFMove(m_ongoingMatchRegistrationTasks);
     for (auto& callback : registrationTasks.values())
         callback(WTF::nullopt);
@@ -235,26 +247,31 @@ void WebSWClientConnection::clear()
     for (auto& callback : getRegistrationTasks.values())
         callback({ });
 
-    auto registrationReadyTasks = WTFMove(m_ongoingRegistrationReadyTasks);
-    for (auto& callback : registrationReadyTasks.values())
-        callback({ });
-
     clearPendingJobs();
 }
 
 void WebSWClientConnection::syncTerminateWorker(ServiceWorkerIdentifier identifier)
 {
-    sendSync(Messages::WebSWServerConnection::SyncTerminateWorkerFromClient { identifier }, Messages::WebSWServerConnection::SyncTerminateWorkerFromClient::Reply());
+    initializeConnectionIfNeeded();
+
+    sendSync(Messages::WebSWServerConnection::SyncTerminateWorkerFromClient(identifier), Messages::WebSWServerConnection::SyncTerminateWorkerFromClient::Reply());
+}
+
+WebCore::SWServerConnectionIdentifier WebSWClientConnection::serverConnectionIdentifier() const
+{
+    const_cast<WebSWClientConnection*>(this)->initializeConnectionIfNeeded();
+    return m_identifier;
 }
 
 void WebSWClientConnection::updateThrottleState()
 {
     m_isThrottleable = WebProcess::singleton().areAllPagesThrottleable();
-    send(Messages::WebSWServerConnection::SetThrottleState { m_isThrottleable });
+    ensureConnectionAndSend(Messages::WebSWServerConnection::SetThrottleState { m_isThrottleable });
 }
 
 void WebSWClientConnection::storeRegistrationsOnDiskForTesting(CompletionHandler<void()>&& callback)
 {
+    initializeConnectionIfNeeded();
     sendWithAsyncReply(Messages::WebSWServerConnection::StoreRegistrationsOnDisk { }, WTFMove(callback));
 }
 
index efef36b..3af495d 100644 (file)
@@ -52,7 +52,7 @@ public:
     static Ref<WebSWClientConnection> create(PAL::SessionID sessionID) { return adoptRef(*new WebSWClientConnection { sessionID }); }
     ~WebSWClientConnection();
 
-    WebCore::SWServerConnectionIdentifier serverConnectionIdentifier() const final { return m_identifier; }
+    WebCore::SWServerConnectionIdentifier serverConnectionIdentifier() const final;
 
     void addServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier) final;
     void removeServiceWorkerRegistrationInServer(WebCore::ServiceWorkerRegistrationIdentifier) final;
@@ -74,6 +74,8 @@ public:
 private:
     explicit WebSWClientConnection(PAL::SessionID);
 
+    void initializeConnectionIfNeeded();
+
     void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;
     void finishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult&) final;
     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destinationIdentifier, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source) final;
@@ -95,26 +97,27 @@ private:
 
     void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
 
-    void runOrDelayTaskForImport(Function<void()>&& task);
+    void runOrDelayTaskForImport(WTF::Function<void()>&& task);
 
-    IPC::Connection* messageSenderConnection() const final;
-    uint64_t messageSenderDestinationID() const final { return m_sessionID.toUInt64(); }
+    IPC::Connection* messageSenderConnection() const final { return m_connection.get(); }
+    uint64_t messageSenderDestinationID() const final { return m_identifier.toUInt64(); }
 
     void setSWOriginTableSharedMemory(const SharedMemory::Handle&);
     void setSWOriginTableIsImported();
 
-    void clear();
+    template<typename U> void ensureConnectionAndSend(const U& message);
 
     PAL::SessionID m_sessionID;
     WebCore::SWServerConnectionIdentifier m_identifier;
 
+    RefPtr<IPC::Connection> m_connection;
     UniqueRef<WebSWOriginTable> m_swOriginTable;
 
     uint64_t m_previousCallbackIdentifier { 0 };
     HashMap<uint64_t, RegistrationCallback> m_ongoingMatchRegistrationTasks;
     HashMap<uint64_t, GetRegistrationsCallback> m_ongoingGetRegistrationsTasks;
     HashMap<uint64_t, WhenRegistrationReadyCallback> m_ongoingRegistrationReadyTasks;
-    Deque<Function<void()>> m_tasksPendingOriginImport;
+    Deque<WTF::Function<void()>> m_tasksPendingOriginImport;
     bool m_isThrottleable { true };
 }; // class WebSWServerConnection
 
index 56620f6..028da30 100644 (file)
@@ -31,7 +31,6 @@
 #include "DataReference.h"
 #include "FormDataReference.h"
 #include "Logging.h"
-#include "NetworkConnectionToWebProcessMessages.h"
 #include "NetworkProcessMessages.h"
 #include "ServiceWorkerFetchTaskMessages.h"
 #include "WebCacheStorageProvider.h"
@@ -87,9 +86,8 @@ Ref<DocumentLoader> ServiceWorkerFrameLoaderClient::createDocumentLoader(const R
     return WebDocumentLoader::create(request, substituteData);
 }
 
-WebSWContextManagerConnection::WebSWContextManagerConnection(Ref<IPC::Connection>&& connection, WebCore::RegistrableDomain&& registrableDomain, uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store)
+WebSWContextManagerConnection::WebSWContextManagerConnection(Ref<IPC::Connection>&& connection, uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store)
     : m_connectionToNetworkProcess(WTFMove(connection))
-    , m_registrableDomain(WTFMove(registrableDomain))
     , m_pageGroupID(pageGroupID)
     , m_webPageProxyID(webPageProxyID)
     , m_pageID(pageID)
@@ -100,7 +98,6 @@ WebSWContextManagerConnection::WebSWContextManagerConnection(Ref<IPC::Connection
 #endif
 {
     updatePreferencesStore(store);
-    m_connectionToNetworkProcess->send(Messages::NetworkConnectionToWebProcess::EstablishSWContextConnection { m_registrableDomain }, 0);
 }
 
 WebSWContextManagerConnection::~WebSWContextManagerConnection() = default;
@@ -263,9 +260,9 @@ void WebSWContextManagerConnection::syncTerminateWorker(ServiceWorkerIdentifier
     SWContextManager::singleton().terminateWorker(identifier, syncWorkerTerminationTimeout, WTFMove(reply));
 }
 
-void WebSWContextManagerConnection::postMessageToServiceWorkerClient(PAL::SessionID sessionID, const ServiceWorkerClientIdentifier& destinationIdentifier, const MessageWithMessagePorts& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
+void WebSWContextManagerConnection::postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, MessageWithMessagePorts&& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
 {
-    m_connectionToNetworkProcess->send(Messages::WebSWServerToContextConnection::PostMessageToServiceWorkerClient(sessionID, destinationIdentifier, message, sourceIdentifier, sourceOrigin), 0);
+    m_connectionToNetworkProcess->send(Messages::NetworkProcess::PostMessageToServiceWorkerClient(destinationIdentifier, WTFMove(message), sourceIdentifier, sourceOrigin), 0);
 }
 
 void WebSWContextManagerConnection::didFinishInstall(Optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
index b5a2c68..16cc0de 100644 (file)
@@ -53,7 +53,7 @@ struct WebPreferencesStore;
 
 class WebSWContextManagerConnection final : public WebCore::SWContextManager::Connection, public IPC::MessageReceiver {
 public:
-    WebSWContextManagerConnection(Ref<IPC::Connection>&&, WebCore::RegistrableDomain&&, uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore&);
+    WebSWContextManagerConnection(Ref<IPC::Connection>&&, uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore&);
     ~WebSWContextManagerConnection();
 
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
@@ -65,7 +65,7 @@ private:
     void updatePreferencesStore(const WebPreferencesStore&);
 
     // WebCore::SWContextManager::Connection.
-    void postMessageToServiceWorkerClient(PAL::SessionID, const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, const WebCore::MessageWithMessagePorts&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin) final;
+    void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin) final;
     void didFinishInstall(Optional<WebCore::ServiceWorkerJobDataIdentifier>, WebCore::ServiceWorkerIdentifier, bool wasSuccessful) final;
     void didFinishActivation(WebCore::ServiceWorkerIdentifier) final;
     void setServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier, bool) final;
@@ -99,7 +99,6 @@ private:
     void setThrottleState(bool isThrottleable);
 
     Ref<IPC::Connection> m_connectionToNetworkProcess;
-    WebCore::RegistrableDomain m_registrableDomain;
     uint64_t m_pageGroupID;
     WebPageProxyIdentifier m_webPageProxyID;
     WebCore::PageIdentifier m_pageID;
index 539c15b..b16d6f9 100644 (file)
@@ -1812,13 +1812,13 @@ LibWebRTCNetwork& WebProcess::libWebRTCNetwork()
 }
 
 #if ENABLE(SERVICE_WORKER)
-void WebProcess::establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store, RegistrableDomain&& registrableDomain, PAL::SessionID initialSessionID)
+void WebProcess::establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier webPageProxyID, PageIdentifier pageID, const WebPreferencesStore& store, PAL::SessionID initialSessionID)
 {
     // We are in the Service Worker context process and the call below establishes our connection to the Network Process
     // by calling ensureNetworkProcessConnection. SWContextManager needs to use the same underlying IPC::Connection as the
     // NetworkProcessConnection for synchronization purposes.
     auto& ipcConnection = ensureNetworkProcessConnection().connection();
-    SWContextManager::singleton().setConnection(makeUnique<WebSWContextManagerConnection>(ipcConnection, WTFMove(registrableDomain), pageGroupID, webPageProxyID, pageID, store));
+    SWContextManager::singleton().setConnection(makeUnique<WebSWContextManagerConnection>(ipcConnection, pageGroupID, webPageProxyID, pageID, store));
 }
 
 void WebProcess::registerServiceWorkerClients()
index 2928c10..0c21196 100644 (file)
@@ -367,7 +367,7 @@ private:
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    void establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore&, WebCore::RegistrableDomain&&, PAL::SessionID);
+    void establishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebPageProxyIdentifier, WebCore::PageIdentifier, const WebPreferencesStore&, PAL::SessionID);
     void registerServiceWorkerClients();
 #endif
 
index f449f5f..dcee1f4 100644 (file)
@@ -111,7 +111,7 @@ messages -> WebProcess LegacyReceiver {
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    EstablishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebKit::WebPageProxyIdentifier webPageProxyID, WebCore::PageIdentifier pageID, struct WebKit::WebPreferencesStore store, WebCore::RegistrableDomain domain, PAL::SessionID initialSessionID)
+    EstablishWorkerContextConnectionToNetworkProcess(uint64_t pageGroupID, WebKit::WebPageProxyIdentifier webPageProxyID, WebCore::PageIdentifier pageID, struct WebKit::WebPreferencesStore store, PAL::SessionID initialSessionID)
     RegisterServiceWorkerClients()
 #endif