StorageToWebProcessConnection & WebSWServerToContextConnection should use the same...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 21:11:04 +0000 (21:11 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 21:11:04 +0000 (21:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180147

Reviewed by Brady Eidson.

StorageToWebProcessConnection & WebSWServerToContextConnection should use the same underlying IPC::Connection.
Otherwise, we have with 2 IPC::Connections between the StorageProcess and the ServiceWorker (aka Context) process,
which makes synchronization of IPC messages difficult.

* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::createStorageToWebProcessConnection):
(WebKit::StorageProcess::createServerToContextConnection):
* StorageProcess/StorageProcess.h:
* StorageProcess/StorageProcess.messages.in:
* StorageProcess/StorageToWebProcessConnection.cpp:
(WebKit::StorageToWebProcessConnection::didReceiveMessage):
* UIProcess/ServiceWorkerProcessProxy.cpp:
(WebKit::ServiceWorkerProcessProxy::start):
* UIProcess/ServiceWorkerProcessProxy.h:
* UIProcess/Storage/StorageProcessProxy.cpp:
(WebKit::StorageProcessProxy::getStorageProcessConnection):
(WebKit::StorageProcessProxy::didFinishLaunching):
(WebKit::StorageProcessProxy::establishWorkerContextConnectionToStorageProcess):
* UIProcess/Storage/StorageProcessProxy.h:
* UIProcess/Storage/StorageProcessProxy.messages.in:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::getStorageProcessConnection):
(WebKit::WebProcessPool::establishWorkerContextConnectionToStorageProcess):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::getStorageProcessConnection):
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::isServiceWorkerProcess const):
* UIProcess/WebProcessProxy.messages.in:
* WebProcess/Storage/WebToStorageProcessConnection.cpp:
(WebKit::WebToStorageProcessConnection::didReceiveMessage):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::didReceiveMessage):
(WebKit::WebProcess::establishWorkerContextConnectionToStorageProcess):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

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

19 files changed:
Source/WebKit/ChangeLog
Source/WebKit/StorageProcess/StorageProcess.cpp
Source/WebKit/StorageProcess/StorageProcess.h
Source/WebKit/StorageProcess/StorageProcess.messages.in
Source/WebKit/StorageProcess/StorageToWebProcessConnection.cpp
Source/WebKit/UIProcess/ServiceWorkerProcessProxy.cpp
Source/WebKit/UIProcess/ServiceWorkerProcessProxy.h
Source/WebKit/UIProcess/Storage/StorageProcessProxy.cpp
Source/WebKit/UIProcess/Storage/StorageProcessProxy.h
Source/WebKit/UIProcess/Storage/StorageProcessProxy.messages.in
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/WebProcessProxy.messages.in
Source/WebKit/WebProcess/Storage/WebToStorageProcessConnection.cpp
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h
Source/WebKit/WebProcess/WebProcess.messages.in

index adfba5d..421c353 100644 (file)
@@ -1,5 +1,49 @@
 2017-11-29  Chris Dumez  <cdumez@apple.com>
 
+        StorageToWebProcessConnection & WebSWServerToContextConnection should use the same underlying IPC::Connection
+        https://bugs.webkit.org/show_bug.cgi?id=180147
+
+        Reviewed by Brady Eidson.
+
+        StorageToWebProcessConnection & WebSWServerToContextConnection should use the same underlying IPC::Connection.
+        Otherwise, we have with 2 IPC::Connections between the StorageProcess and the ServiceWorker (aka Context) process,
+        which makes synchronization of IPC messages difficult.
+
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::createStorageToWebProcessConnection):
+        (WebKit::StorageProcess::createServerToContextConnection):
+        * StorageProcess/StorageProcess.h:
+        * StorageProcess/StorageProcess.messages.in:
+        * StorageProcess/StorageToWebProcessConnection.cpp:
+        (WebKit::StorageToWebProcessConnection::didReceiveMessage):
+        * UIProcess/ServiceWorkerProcessProxy.cpp:
+        (WebKit::ServiceWorkerProcessProxy::start):
+        * UIProcess/ServiceWorkerProcessProxy.h:
+        * UIProcess/Storage/StorageProcessProxy.cpp:
+        (WebKit::StorageProcessProxy::getStorageProcessConnection):
+        (WebKit::StorageProcessProxy::didFinishLaunching):
+        (WebKit::StorageProcessProxy::establishWorkerContextConnectionToStorageProcess):
+        * UIProcess/Storage/StorageProcessProxy.h:
+        * UIProcess/Storage/StorageProcessProxy.messages.in:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::getStorageProcessConnection):
+        (WebKit::WebProcessPool::establishWorkerContextConnectionToStorageProcess):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::getStorageProcessConnection):
+        * UIProcess/WebProcessProxy.h:
+        (WebKit::WebProcessProxy::isServiceWorkerProcess const):
+        * UIProcess/WebProcessProxy.messages.in:
+        * WebProcess/Storage/WebToStorageProcessConnection.cpp:
+        (WebKit::WebToStorageProcessConnection::didReceiveMessage):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::didReceiveMessage):
+        (WebKit::WebProcess::establishWorkerContextConnectionToStorageProcess):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
+2017-11-29  Chris Dumez  <cdumez@apple.com>
+
         ensure*Connection() methods on WebProcess should return a reference
         https://bugs.webkit.org/show_bug.cgi?id=180149
 
index 17e0e74..6e7d064 100644 (file)
@@ -189,7 +189,7 @@ void StorageProcess::performNextStorageTask()
     task.performTask();
 }
 
-void StorageProcess::createStorageToWebProcessConnection()
+void StorageProcess::createStorageToWebProcessConnection(bool isServiceWorkerProcess)
 {
 #if USE(UNIX_DOMAIN_SOCKETS)
     IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
@@ -208,6 +208,19 @@ void StorageProcess::createStorageToWebProcessConnection()
 #else
     notImplemented();
 #endif
+
+#if ENABLE(SERVICE_WORKER)
+    if (isServiceWorkerProcess && !m_storageToWebProcessConnections.isEmpty()) {
+        ASSERT(m_waitingForServerToContextProcessConnection);
+        m_serverToContextConnection = WebSWServerToContextConnection::create(m_storageToWebProcessConnections.last()->connection());
+        m_waitingForServerToContextProcessConnection = false;
+
+        for (auto& connection : m_storageToWebProcessConnections)
+            connection->workerContextProcessConnectionCreated();
+    }
+#else
+    UNUSED_PARAM(isServiceWorkerProcess);
+#endif
 }
 
 void StorageProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, uint64_t callbackID)
@@ -381,33 +394,7 @@ void StorageProcess::createServerToContextConnection()
         return;
     
     m_waitingForServerToContextProcessConnection = true;
-    parentProcessConnection()->send(Messages::StorageProcessProxy::GetWorkerContextProcessConnection(), 0);
-}
-
-void StorageProcess::didGetWorkerContextProcessConnection(IPC::Attachment&& encodedConnectionIdentifier)
-{
-    ASSERT(m_waitingForServerToContextProcessConnection);
-    m_waitingForServerToContextProcessConnection = false;
-
-#if USE(UNIX_DOMAIN_SOCKETS)
-    IPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.releaseFileDescriptor();
-#elif OS(DARWIN)
-    IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port());
-#else
-    ASSERT_NOT_REACHED();
-#endif
-
-    if (IPC::Connection::identifierIsNull(connectionIdentifier)) {
-        LOG_ERROR("StorageProcess::didGetWorkerContextProcessConnection - Received null connection identifier");
-        return;
-    }
-
-    auto ipcConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
-    ipcConnection->open();
-    m_serverToContextConnection = WebSWServerToContextConnection::create(WTFMove(ipcConnection));
-    
-    for (auto& connection : m_storageToWebProcessConnections)
-        connection->workerContextProcessConnectionCreated();
+    parentProcessConnection()->send(Messages::StorageProcessProxy::EstablishWorkerContextConnectionToStorageProcess(), 0);
 }
 
 void StorageProcess::didFailFetch(SWServerConnectionIdentifier serverConnectionIdentifier, uint64_t fetchIdentifier)
index 4cb2bdd..81587b0 100644 (file)
@@ -96,6 +96,8 @@ public:
     void unregisterSWServerConnection(WebSWServerConnection&);
 #endif
 
+    void didReceiveStorageProcessMessage(IPC::Connection&, IPC::Decoder&);
+
 private:
     StorageProcess();
 
@@ -109,11 +111,10 @@ private:
     // IPC::Connection::Client
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
     void didClose(IPC::Connection&) override;
-    void didReceiveStorageProcessMessage(IPC::Connection&, IPC::Decoder&);
 
     // Message Handlers
     void initializeWebsiteDataStore(const StorageProcessCreationParameters&);
-    void createStorageToWebProcessConnection();
+    void createStorageToWebProcessConnection(bool isServiceWorkerProcess);
 
     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType> websiteDataTypes, uint64_t callbackID);
     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID);
@@ -123,8 +124,6 @@ private:
     void didGetSandboxExtensionsForBlobFiles(uint64_t requestID, SandboxExtension::HandleArray&&);
 #endif
 #if ENABLE(SERVICE_WORKER)
-    void didGetWorkerContextProcessConnection(IPC::Attachment&& encodedConnectionIdentifier);
-
     void didReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, uint64_t fetchIdentifier, const WebCore::ResourceResponse&);
     void didReceiveFetchData(WebCore::SWServerConnectionIdentifier, uint64_t fetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
     void didReceiveFetchFormData(WebCore::SWServerConnectionIdentifier, uint64_t fetchIdentifier, const IPC::FormDataReference&);
index fb5e4d8..99277d1 100644 (file)
@@ -25,7 +25,7 @@ messages -> StorageProcess LegacyReceiver {
     InitializeWebsiteDataStore(struct WebKit::StorageProcessCreationParameters processCreationParameters)
 
     # Creates a connection for communication with a WebProcess
-    CreateStorageToWebProcessConnection()
+    CreateStorageToWebProcessConnection(bool isServiceWorkerProcess)
 
     FetchWebsiteData(PAL::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, uint64_t callbackID)
     DeleteWebsiteData(PAL::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
@@ -36,8 +36,6 @@ messages -> StorageProcess LegacyReceiver {
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    DidGetWorkerContextProcessConnection(IPC::Attachment connectionHandle)
-
     DidNotHandleFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, uint64_t fetchIdentifier)
     DidFailFetch(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, uint64_t fetchIdentifier)
     DidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier serverConnectionIdentifier, uint64_t fetchIdentifier, WebCore::ResourceResponse response)
index 13a77db..0cf83ff 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "Logging.h"
 #include "StorageProcess.h"
+#include "StorageProcessMessages.h"
 #include "StorageToWebProcessConnectionMessages.h"
 #include "WebIDBConnectionToClient.h"
 #include "WebIDBConnectionToClientMessages.h"
@@ -69,6 +70,11 @@ void StorageToWebProcessConnection::didReceiveMessage(IPC::Connection& connectio
         return;
     }
 
+    if (decoder.messageReceiverName() == Messages::StorageProcess::messageReceiverName()) {
+        StorageProcess::singleton().didReceiveStorageProcessMessage(connection, decoder);
+        return;
+    }
+
 #if ENABLE(INDEXED_DATABASE)
     if (decoder.messageReceiverName() == Messages::WebIDBConnectionToClient::messageReceiverName()) {
         auto iterator = m_webIDBConnections.find(decoder.destinationID());
index e6bc4c2..8df7d98 100644 (file)
@@ -61,7 +61,7 @@ void ServiceWorkerProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions&
 
 void ServiceWorkerProcessProxy::start(const WebPreferencesStore& store)
 {
-    send(Messages::WebProcess::GetWorkerContextConnection(m_serviceWorkerPageID, store), 0);
+    send(Messages::WebProcess::EstablishWorkerContextConnectionToStorageProcess(m_serviceWorkerPageID, store), 0);
 }
 
 void ServiceWorkerProcessProxy::didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, Ref<AuthenticationChallengeProxy>&& challenge)
index 1186b7a..1ac4556 100644 (file)
@@ -41,11 +41,12 @@ public:
     void start(const WebPreferencesStore&);
     uint64_t pageID() const { return m_serviceWorkerPageID; }
 
-protected:
+private:
     // ChildProcessProxy
     void getLaunchOptions(ProcessLauncher::LaunchOptions&) final;
 
-private:
+    bool isServiceWorkerProcess() const final { return true; }
+
     ServiceWorkerProcessProxy(WebProcessPool&, WebsiteDataStore&);
     uint64_t m_serviceWorkerPageID { 0 };
 };
index 98425d1..4c0ad60 100644 (file)
@@ -111,7 +111,7 @@ void StorageProcessProxy::deleteWebsiteDataForOrigins(PAL::SessionID sessionID,
     send(Messages::StorageProcess::DeleteWebsiteDataForOrigins(sessionID, dataTypes, origins, callbackID), 0);
 }
 
-void StorageProcessProxy::getStorageProcessConnection(Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&& reply)
+void StorageProcessProxy::getStorageProcessConnection(bool isServiceWorkerProcess, Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&& reply)
 {
     m_pendingConnectionReplies.append(WTFMove(reply));
 
@@ -120,7 +120,7 @@ void StorageProcessProxy::getStorageProcessConnection(Ref<Messages::WebProcessPr
         return;
     }
 
-    send(Messages::StorageProcess::CreateStorageToWebProcessConnection(), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
+    send(Messages::StorageProcess::CreateStorageToWebProcessConnection(isServiceWorkerProcess), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
 }
 
 void StorageProcessProxy::didClose(IPC::Connection&)
@@ -215,26 +215,16 @@ void StorageProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Con
     }
 
     for (unsigned i = 0; i < m_numPendingConnectionRequests; ++i)
-        send(Messages::StorageProcess::CreateStorageToWebProcessConnection(), 0);
+        send(Messages::StorageProcess::CreateStorageToWebProcessConnection(false), 0);
     
     m_numPendingConnectionRequests = 0;
 }
 
 #if ENABLE(SERVICE_WORKER)
-void StorageProcessProxy::getWorkerContextProcessConnection()
+void StorageProcessProxy::establishWorkerContextConnectionToStorageProcess()
 {
-    ASSERT(!m_waitingOnWorkerContextProcessConnection);
-    m_waitingOnWorkerContextProcessConnection = true;
-    
-    m_processPool.getWorkerContextProcessConnection(*this);
+    m_processPool.establishWorkerContextConnectionToStorageProcess(*this);
 }
-
-void StorageProcessProxy::didGetWorkerContextProcessConnection(const IPC::Attachment& connection)
-{
-    m_waitingOnWorkerContextProcessConnection = false;
-    send(Messages::StorageProcess::DidGetWorkerContextProcessConnection(connection), 0);
-}
-
 #endif
 
 } // namespace WebKit
index fc91719..26dee87 100644 (file)
@@ -55,11 +55,7 @@ public:
     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, std::chrono::system_clock::time_point modifiedSince, WTF::Function<void()>&& completionHandler);
     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>&, WTF::Function<void()>&& completionHandler);
 
-    void getStorageProcessConnection(Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&&);
-
-#if ENABLE(SERVICE_WORKER)
-    void didGetWorkerContextProcessConnection(const IPC::Attachment& connection);
-#endif
+    void getStorageProcessConnection(bool isServiceWorkerProcess, Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&&);
 
 private:
     StorageProcessProxy(WebProcessPool&);
@@ -84,8 +80,7 @@ private:
     void getSandboxExtensionsForBlobFiles(uint64_t requestID, const Vector<String>& paths);
 #endif
 #if ENABLE(SERVICE_WORKER)
-    void getWorkerContextProcessConnection();
-    bool m_waitingOnWorkerContextProcessConnection { false };
+    void establishWorkerContextConnectionToStorageProcess();
 #endif
 
     // ProcessLauncher::Client
index b9fcd19..c212b22 100644 (file)
@@ -32,6 +32,6 @@ messages -> StorageProcessProxy LegacyReceiver {
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    GetWorkerContextProcessConnection()
+    EstablishWorkerContextConnectionToStorageProcess()
 #endif
 }
index 99115e2..b9bb7a4 100644 (file)
@@ -566,11 +566,11 @@ void WebProcessPool::ensureStorageProcessAndWebsiteDataStore(WebsiteDataStore* r
     m_storageProcess->send(Messages::StorageProcess::InitializeWebsiteDataStore(relevantDataStore->storageProcessParameters()), 0);
 }
 
-void WebProcessPool::getStorageProcessConnection(Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&& reply)
+void WebProcessPool::getStorageProcessConnection(bool isServiceWorkerProcess, Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&& reply)
 {
     ensureStorageProcessAndWebsiteDataStore(nullptr);
 
-    m_storageProcess->getStorageProcessConnection(WTFMove(reply));
+    m_storageProcess->getStorageProcessConnection(isServiceWorkerProcess, WTFMove(reply));
 }
 
 void WebProcessPool::storageProcessCrashed(StorageProcessProxy* storageProcessProxy)
@@ -586,7 +586,7 @@ void WebProcessPool::storageProcessCrashed(StorageProcessProxy* storageProcessPr
 }
 
 #if ENABLE(SERVICE_WORKER)
-void WebProcessPool::getWorkerContextProcessConnection(StorageProcessProxy& proxy)
+void WebProcessPool::establishWorkerContextConnectionToStorageProcess(StorageProcessProxy& proxy)
 {
     ASSERT_UNUSED(proxy, &proxy == m_storageProcess);
 
@@ -602,13 +602,6 @@ void WebProcessPool::getWorkerContextProcessConnection(StorageProcessProxy& prox
     m_processes.append(WTFMove(serviceWorkerProcessProxy));
     m_serviceWorkerProcess->start(m_defaultPageGroup->preferences().store());
 }
-
-void WebProcessPool::didGetWorkerContextProcessConnection(const IPC::Attachment& connection)
-{
-    if (!m_storageProcess)
-        return;
-    m_storageProcess->didGetWorkerContextProcessConnection(connection);
-}
 #endif
 
 void WebProcessPool::willStartUsingPrivateBrowsing()
index 33c821d..41aa3c3 100644 (file)
@@ -319,10 +319,10 @@ public:
 
     void ensureStorageProcessAndWebsiteDataStore(WebsiteDataStore* relevantDataStore);
     StorageProcessProxy* storageProcess() { return m_storageProcess.get(); }
-    void getStorageProcessConnection(Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&&);
+    void getStorageProcessConnection(bool isServiceWorkerProcess, Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&&);
     void storageProcessCrashed(StorageProcessProxy*);
 #if ENABLE(SERVICE_WORKER)
-    void getWorkerContextProcessConnection(StorageProcessProxy&);
+    void establishWorkerContextConnectionToStorageProcess(StorageProcessProxy&);
     bool isServiceWorker(uint64_t pageID) const { return m_serviceWorkerProcess && m_serviceWorkerProcess->pageID() == pageID; }
     ServiceWorkerProcessProxy* serviceWorkerProxy() const { return m_serviceWorkerProcess; }
     void setAllowsAnySSLCertificateForServiceWorker(bool allows) { m_allowsAnySSLCertificateForServiceWorker = allows; }
@@ -422,10 +422,6 @@ public:
     static uint64_t registerProcessPoolCreationListener(Function<void(WebProcessPool&)>&&);
     static void unregisterProcessPoolCreationListener(uint64_t identifier);
 
-#if ENABLE(SERVICE_WORKER)
-    void didGetWorkerContextProcessConnection(const IPC::Attachment& connection);
-#endif
-
 private:
     void platformInitialize();
 
index 0e8fd09..617a639 100644 (file)
@@ -573,7 +573,7 @@ void WebProcessProxy::getNetworkProcessConnection(Ref<Messages::WebProcessProxy:
 
 void WebProcessProxy::getStorageProcessConnection(Ref<Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply>&& reply)
 {
-    m_processPool->getStorageProcessConnection(WTFMove(reply));
+    m_processPool->getStorageProcessConnection(isServiceWorkerProcess(), WTFMove(reply));
 }
 
 #if !PLATFORM(COCOA)
@@ -1227,11 +1227,4 @@ const HashSet<String>& WebProcessProxy::platformPathsWithAssumedReadAccess()
 }
 #endif
 
-#if ENABLE(SERVICE_WORKER)
-void WebProcessProxy::didGetWorkerContextConnection(const IPC::Attachment& connection)
-{
-    m_processPool->didGetWorkerContextProcessConnection(connection);
-}
-#endif
-
 } // namespace WebKit
index e28cdb2..36972a5 100644 (file)
@@ -103,6 +103,8 @@ public:
     unsigned pageCount() const { return m_pageMap.size(); }
     unsigned visiblePageCount() const { return m_visiblePageCounter.value(); }
 
+    virtual bool isServiceWorkerProcess() const { return false; }
+
     void addVisitedLinkStore(VisitedLinkStore&);
     void addWebUserContentControllerProxy(WebUserContentControllerProxy&, WebPageCreationParameters&);
     void didDestroyVisitedLinkStore(VisitedLinkStore&);
@@ -182,10 +184,6 @@ public:
     bool isUnderMemoryPressure() const { return m_isUnderMemoryPressure; }
     void didExceedInactiveMemoryLimitWhileActive();
 
-#if ENABLE(SERVICE_WORKER)
-    void didGetWorkerContextConnection(const IPC::Attachment& connection);
-#endif
-
     void processTerminated();
 
     void didExceedCPULimit();
index 191be4a..ad69c52 100644 (file)
@@ -54,8 +54,4 @@ messages -> WebProcessProxy LegacyReceiver {
 
     MemoryPressureStatusChanged(bool isUnderMemoryPressure)
     DidExceedInactiveMemoryLimitWhileActive()
-
-#if ENABLE(SERVICE_WORKER)
-    DidGetWorkerContextConnection(IPC::Attachment connection)
-#endif
 }
index d593876..b5e9f7d 100644 (file)
 #include "WebProcess.h"
 #include "WebSWClientConnection.h"
 #include "WebSWClientConnectionMessages.h"
+#include "WebSWContextManagerConnection.h"
+#include "WebSWContextManagerConnectionMessages.h"
 #include "WebServiceWorkerProvider.h"
+#include <WebCore/SWContextManager.h>
 
 using namespace PAL;
 using namespace WebCore;
@@ -73,6 +76,12 @@ void WebToStorageProcessConnection::didReceiveMessage(IPC::Connection& connectio
         WebServiceWorkerProvider::singleton().didReceiveServiceWorkerClientFetchMessage(connection, decoder);
         return;
     }
+    if (decoder.messageReceiverName() == Messages::WebSWContextManagerConnection::messageReceiverName()) {
+        ASSERT(SWContextManager::singleton().connection());
+        if (auto* contextManagerConnection = SWContextManager::singleton().connection())
+            static_cast<WebSWContextManagerConnection&>(*contextManagerConnection).didReceiveMessage(connection, decoder);
+        return;
+    }
 #endif
     ASSERT_NOT_REACHED();
 }
index cf4d19f..f02c53b 100644 (file)
@@ -646,6 +646,7 @@ void WebProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& de
     }
 
 #if ENABLE(SERVICE_WORKER)
+    // FIXME: Remove?
     if (decoder.messageReceiverName() == Messages::WebSWContextManagerConnection::messageReceiverName()) {
         ASSERT(SWContextManager::singleton().connection());
         if (auto* contextManagerConnection = SWContextManager::singleton().connection())
@@ -1616,30 +1617,13 @@ LibWebRTCNetwork& WebProcess::libWebRTCNetwork()
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-void WebProcess::getWorkerContextConnection(uint64_t pageID, const WebPreferencesStore& store)
+void WebProcess::establishWorkerContextConnectionToStorageProcess(uint64_t pageID, const WebPreferencesStore& store)
 {
-#if USE(UNIX_DOMAIN_SOCKETS)
-    IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
-    IPC::Connection::Identifier connectionIdentifier(socketPair.server);
-    IPC::Attachment connectionClientPort(socketPair.client);
-#elif OS(DARWIN)
-    mach_port_t listeningPort;
-    if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort) != KERN_SUCCESS)
-        CRASH();
-
-    if (mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS)
-        CRASH();
-
-    IPC::Connection::Identifier connectionIdentifier(listeningPort);
-    IPC::Attachment connectionClientPort(listeningPort, MACH_MSG_TYPE_MOVE_SEND);
-#else
-    RELEASE_ASSERT_NOT_REACHED();
-#endif
-
-    auto workerContextConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
-    workerContextConnection->open();
-    SWContextManager::singleton().setConnection(std::make_unique<WebSWContextManagerConnection>(WTFMove(workerContextConnection), pageID, store));
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidGetWorkerContextConnection(connectionClientPort), 0);
+    // We are in the Service Worker context process and the call below establishes our connection to the Storage Process
+    // by calling webToStorageProcessConnection. SWContextManager needs to use the same underlying IPC::Connection as the
+    // WebToStorageProcessConnection for synchronization purposes.
+    auto& ipcConnection = ensureWebToStorageProcessConnection().connection();
+    SWContextManager::singleton().setConnection(std::make_unique<WebSWContextManagerConnection>(ipcConnection, pageID, store));
 }
 #endif
 
index 131e17e..1556efc 100644 (file)
@@ -297,7 +297,7 @@ private:
     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
 #endif
 #if ENABLE(SERVICE_WORKER)
-    void getWorkerContextConnection(uint64_t pageID, const WebPreferencesStore&);
+    void establishWorkerContextConnectionToStorageProcess(uint64_t pageID, const WebPreferencesStore&);
 #endif
 
     void releasePageCache();
index 758a5e6..9ecf8e5 100644 (file)
@@ -114,6 +114,6 @@ messages -> WebProcess LegacyReceiver {
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    GetWorkerContextConnection(uint64_t pageID, struct WebKit::WebPreferencesStore store)
+    EstablishWorkerContextConnectionToStorageProcess(uint64_t pageID, struct WebKit::WebPreferencesStore store)
 #endif
 }