Bring back SWContextManager abstraction in WebCore
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2017 20:14:40 +0000 (20:14 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2017 20:14:40 +0000 (20:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178876

Reviewed by Geoffrey Garen.

Bring back SWContextManager abstraction in WebCore. It was killed in <https://trac.webkit.org/changeset/223718> but
is actually useful when the ServiceWorker wants to message the storage process.

Source/WebCore:

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* workers/service/context/SWContextManager.cpp: Added.
(WebCore::SWContextManager::singleton):
(WebCore::SWContextManager::setConnection):
(WebCore::SWContextManager::connection const):
(WebCore::SWContextManager::registerServiceWorkerThread):
(WebCore::SWContextManager::serviceWorkerThreadProxy const):
(WebCore::SWContextManager::postMessageToServiceWorkerGlobalScope):
* workers/service/context/SWContextManager.h: Copied from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h.
(WebCore::SWContextManager::Connection::~Connection):

Source/WebKit:

* CMakeLists.txt:
* DerivedSources.make:
* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::startServiceWorkerContext):
(WebKit::WebSWServerConnection::startFetch):
(WebKit::WebSWServerConnection::postMessageToServiceWorkerGlobalScope):
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Storage/WebSWContextManagerConnection.cpp: Renamed from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp.
(WebKit::WebSWContextManagerConnection::WebSWContextManagerConnection):
(WebKit::WebSWContextManagerConnection::updatePreferences):
(WebKit::WebSWContextManagerConnection::startServiceWorker):
(WebKit::WebSWContextManagerConnection::startFetch):
(WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope):
* WebProcess/Storage/WebSWContextManagerConnection.h: Renamed from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h.
* WebProcess/Storage/WebSWContextManagerConnection.messages.in: Renamed from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.messages.in.
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::didReceiveMessage):
(WebKit::WebProcess::getWorkerContextConnection):
* WebProcess/WebProcess.h:

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/workers/service/context/SWContextManager.cpp [new file with mode: 0644]
Source/WebCore/workers/service/context/SWContextManager.h [new file with mode: 0644]
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/DerivedSources.make
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp [moved from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp with 78% similarity]
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h [moved from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h with 81% similarity]
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in [moved from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.messages.in with 89% similarity]
Source/WebKit/WebProcess/WebProcess.cpp
Source/WebKit/WebProcess/WebProcess.h

index 56e1353..03e7e3b 100644 (file)
@@ -1,3 +1,25 @@
+2017-10-26  Chris Dumez  <cdumez@apple.com>
+
+        Bring back SWContextManager abstraction in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=178876
+
+        Reviewed by Geoffrey Garen.
+
+        Bring back SWContextManager abstraction in WebCore. It was killed in <https://trac.webkit.org/changeset/223718> but
+        is actually useful when the ServiceWorker wants to message the storage process.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/service/context/SWContextManager.cpp: Added.
+        (WebCore::SWContextManager::singleton):
+        (WebCore::SWContextManager::setConnection):
+        (WebCore::SWContextManager::connection const):
+        (WebCore::SWContextManager::registerServiceWorkerThread):
+        (WebCore::SWContextManager::serviceWorkerThreadProxy const):
+        (WebCore::SWContextManager::postMessageToServiceWorkerGlobalScope):
+        * workers/service/context/SWContextManager.h: Copied from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h.
+        (WebCore::SWContextManager::Connection::~Connection):
+
 2017-10-26  Basuke Suzuki  <Basuke.Suzuki@sony.com>
 
         [Curl] Rename CurlJobManager to CurlRequestScheduler
index 07f6fab..216a140 100644 (file)
@@ -2169,6 +2169,7 @@ workers/service/ServiceWorkerWindowClient.cpp
 workers/service/context/ServiceWorkerFetch.cpp
 workers/service/context/ServiceWorkerThread.cpp
 workers/service/context/ServiceWorkerThreadProxy.cpp
+workers/service/context/SWContextManager.cpp
 
 workers/service/server/SWClientConnection.cpp
 workers/service/server/SWServer.cpp
index aa60fc4..640008d 100644 (file)
                4634592C1AC2271000ECB71C /* PowerObserverMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */; };
                463EB6231B8789E00096ED51 /* TagCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 463EB6211B8789CB0096ED51 /* TagCollection.h */; };
                465307D01DB6EE4800E4137C /* JSUIEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E045EF1DAA104F00B0D8B9 /* JSUIEventInit.h */; };
+               46658DC91FA24B8700F7DD54 /* SWContextManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4672413B1FA24B140088BD6D /* SWContextManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
                466ED8D31EDE0144005E43F6 /* JSDOMRectList.h in Headers */ = {isa = PBXBuildFile; fileRef = 466ED8D21EDE0135005E43F6 /* JSDOMRectList.h */; };
                4671E0661D67A59600C6B497 /* CanvasPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 4671E0641D67A57B00C6B497 /* CanvasPath.h */; };
                467302021C4EFE7800BCB357 /* IgnoreOpensDuringUnloadCountIncrementer.h in Headers */ = {isa = PBXBuildFile; fileRef = 467302011C4EFE6600BCB357 /* IgnoreOpensDuringUnloadCountIncrementer.h */; };
                466ED8D21EDE0135005E43F6 /* JSDOMRectList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMRectList.h; sourceTree = "<group>"; };
                4671E0631D67A57B00C6B497 /* CanvasPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CanvasPath.cpp; sourceTree = "<group>"; };
                4671E0641D67A57B00C6B497 /* CanvasPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CanvasPath.h; sourceTree = "<group>"; };
+               4672413A1FA24B140088BD6D /* SWContextManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWContextManager.cpp; sourceTree = "<group>"; };
+               4672413B1FA24B140088BD6D /* SWContextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWContextManager.h; sourceTree = "<group>"; };
                467302011C4EFE6600BCB357 /* IgnoreOpensDuringUnloadCountIncrementer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IgnoreOpensDuringUnloadCountIncrementer.h; sourceTree = "<group>"; };
                4682D1FF1F79782300C863DB /* StoredCredentialsPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StoredCredentialsPolicy.h; sourceTree = "<group>"; };
                468344DC1EDDFA5F00B7795B /* DOMRectList.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMRectList.idl; sourceTree = "<group>"; };
                                517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */,
                                4112B5411F9F9C9C00E67875 /* ServiceWorkerThreadProxy.cpp */,
                                4112B53F1F9F9C9B00E67875 /* ServiceWorkerThreadProxy.h */,
+                               4672413A1FA24B140088BD6D /* SWContextManager.cpp */,
+                               4672413B1FA24B140088BD6D /* SWContextManager.h */,
                        );
                        path = context;
                        sourceTree = "<group>";
                                B2227AF60D00BF220071B782 /* SVGZoomAndPan.h in Headers */,
                                B2E4EC980D00C22B00432643 /* SVGZoomEvent.h in Headers */,
                                517A531D1F4B53B100DCDC0A /* SWClientConnection.h in Headers */,
+                               46658DC91FA24B8700F7DD54 /* SWContextManager.h in Headers */,
                                517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
                                51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
                                517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */,
diff --git a/Source/WebCore/workers/service/context/SWContextManager.cpp b/Source/WebCore/workers/service/context/SWContextManager.cpp
new file mode 100644 (file)
index 0000000..678b92b
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(SERVICE_WORKER)
+#include "SWContextManager.h"
+
+namespace WebCore {
+
+SWContextManager& SWContextManager::singleton()
+{
+    static SWContextManager* sharedManager = new SWContextManager;
+    return *sharedManager;
+}
+
+void SWContextManager::setConnection(std::unique_ptr<Connection>&& connection)
+{
+    ASSERT(!m_connection);
+    m_connection = WTFMove(connection);
+}
+
+auto SWContextManager::connection() const -> Connection*
+{
+    return m_connection.get();
+}
+
+void SWContextManager::registerServiceWorkerThread(Ref<ServiceWorkerThreadProxy>&& serviceWorkerThreadProxy)
+{
+    auto serviceWorkerIdentifier = serviceWorkerThreadProxy->identifier();
+    auto result = m_workerMap.add(serviceWorkerIdentifier, WTFMove(serviceWorkerThreadProxy));
+    ASSERT_UNUSED(result, result.isNewEntry);
+}
+
+ServiceWorkerThreadProxy* SWContextManager::serviceWorkerThreadProxy(uint64_t serviceWorkerIdentifier) const
+{
+    return m_workerMap.get(serviceWorkerIdentifier);
+}
+
+void SWContextManager::postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, Ref<SerializedScriptValue>&& message, const String& sourceOrigin)
+{
+    auto* serviceWorker = m_workerMap.get(serviceWorkerIdentifier);
+    if (!serviceWorker)
+        return;
+
+    // FIXME: We should pass valid MessagePortChannels.
+    serviceWorker->thread().postMessageToServiceWorkerGlobalScope(WTFMove(message), nullptr, sourceOrigin);
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/workers/service/context/SWContextManager.h b/Source/WebCore/workers/service/context/SWContextManager.h
new file mode 100644 (file)
index 0000000..cdccacc
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "ExceptionOr.h"
+#include "ServiceWorkerThreadProxy.h"
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+
+class SerializedScriptValue;
+
+class SWContextManager {
+public:
+    WEBCORE_EXPORT static SWContextManager& singleton();
+
+    class Connection {
+    public:
+        virtual ~Connection() { }
+    };
+
+    WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
+    WEBCORE_EXPORT Connection* connection() const;
+
+    WEBCORE_EXPORT void registerServiceWorkerThread(Ref<ServiceWorkerThreadProxy>&&);
+    WEBCORE_EXPORT ServiceWorkerThreadProxy* serviceWorkerThreadProxy(uint64_t) const;
+    WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, Ref<SerializedScriptValue>&& message, const String& sourceOrigin);
+
+private:
+    SWContextManager() = default;
+
+    HashMap<uint64_t, RefPtr<ServiceWorkerThreadProxy>> m_workerMap;
+    std::unique_ptr<Connection> m_connection;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
index 9841183..e1877fc 100644 (file)
@@ -541,8 +541,8 @@ set(WebKit_SOURCES
     WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
 
     WebProcess/Storage/ServiceWorkerClientFetch.cpp
-    WebProcess/Storage/ServiceWorkerContextManager.cpp
     WebProcess/Storage/WebSWClientConnection.cpp
+    WebProcess/Storage/WebSWContextManagerConnection.cpp
     WebProcess/Storage/WebSWOriginTable.cpp
     WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp
     WebProcess/Storage/WebServiceWorkerProvider.cpp
@@ -688,8 +688,8 @@ set(WebKit_MESSAGES_IN_FILES
     WebProcess/Plugins/PluginProxy.messages.in
 
     WebProcess/Storage/ServiceWorkerClientFetch.messages.in
-    WebProcess/Storage/ServiceWorkerContextManager.messages.in
     WebProcess/Storage/WebSWClientConnection.messages.in
+    WebProcess/Storage/WebSWContextManagerConnection.messages.in
 
     WebProcess/UserContent/WebUserContentController.messages.in
 
index 00a79a8..cea5845 100644 (file)
@@ -1,3 +1,33 @@
+2017-10-26  Chris Dumez  <cdumez@apple.com>
+
+        Bring back SWContextManager abstraction in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=178876
+
+        Reviewed by Geoffrey Garen.
+
+        Bring back SWContextManager abstraction in WebCore. It was killed in <https://trac.webkit.org/changeset/223718> but
+        is actually useful when the ServiceWorker wants to message the storage process.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::startServiceWorkerContext):
+        (WebKit::WebSWServerConnection::startFetch):
+        (WebKit::WebSWServerConnection::postMessageToServiceWorkerGlobalScope):
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp: Renamed from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.cpp.
+        (WebKit::WebSWContextManagerConnection::WebSWContextManagerConnection):
+        (WebKit::WebSWContextManagerConnection::updatePreferences):
+        (WebKit::WebSWContextManagerConnection::startServiceWorker):
+        (WebKit::WebSWContextManagerConnection::startFetch):
+        (WebKit::WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope):
+        * WebProcess/Storage/WebSWContextManagerConnection.h: Renamed from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.h.
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in: Renamed from Source/WebKit/WebProcess/Storage/ServiceWorkerContextManager.messages.in.
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::didReceiveMessage):
+        (WebKit::WebProcess::getWorkerContextConnection):
+        * WebProcess/WebProcess.h:
+
 2017-10-26  Alexey Proskuryakov  <ap@apple.com>
 
         Remove deprecated WebKit symbols
index 6681476..7b53f27 100644 (file)
@@ -126,7 +126,6 @@ MESSAGE_RECEIVERS = \
     RemoteWebInspectorUI \
     SecItemShimProxy \
     ServiceWorkerClientFetch \
-    ServiceWorkerContextManager \
     SmartMagnificationController \
     StorageAreaMap \
     StorageManager \
@@ -163,6 +162,7 @@ MESSAGE_RECEIVERS = \
     WebPaymentCoordinator \
     WebPaymentCoordinatorProxy \
     WebSWClientConnection \
+    WebSWContextManagerConnection \
     WebSWServerConnection \
     PlaybackSessionManager \
     PlaybackSessionManagerProxy \
index e9bcb32..fc1c5f0 100644 (file)
 #include "DataReference.h"
 #include "Logging.h"
 #include "ServiceWorkerClientFetchMessages.h"
-#include "ServiceWorkerContextManagerMessages.h"
 #include "StorageProcess.h"
 #include "StorageToWebProcessConnectionMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebProcess.h"
 #include "WebProcessMessages.h"
 #include "WebSWClientConnectionMessages.h"
+#include "WebSWContextManagerConnectionMessages.h"
 #include "WebSWOriginStore.h"
 #include "WebSWServerConnectionMessages.h"
 #include "WebToStorageProcessConnection.h"
@@ -97,7 +97,7 @@ void WebSWServerConnection::startScriptFetchInClient(uint64_t jobIdentifier)
 
 void WebSWServerConnection::startServiceWorkerContext(const ServiceWorkerContextData& data)
 {
-    if (sendToContextProcess(Messages::ServiceWorkerContextManager::StartServiceWorker(identifier(), data)))
+    if (sendToContextProcess(Messages::WebSWContextManagerConnection::StartServiceWorker(identifier(), data)))
         return;
 
     m_pendingContextDatas.append(data);
@@ -105,12 +105,12 @@ void WebSWServerConnection::startServiceWorkerContext(const ServiceWorkerContext
 
 void WebSWServerConnection::startFetch(uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, const ResourceRequest& request, const FetchOptions& options)
 {
-    sendToContextProcess(Messages::ServiceWorkerContextManager::StartFetch(identifier(), fetchIdentifier, serviceWorkerIdentifier, request, options));
+    sendToContextProcess(Messages::WebSWContextManagerConnection::StartFetch(identifier(), fetchIdentifier, serviceWorkerIdentifier, request, options));
 }
 
 void WebSWServerConnection::postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin)
 {
-    sendToContextProcess(Messages::ServiceWorkerContextManager::PostMessageToServiceWorkerGlobalScope(identifier(), serviceWorkerIdentifier, message, sourceOrigin));
+    sendToContextProcess(Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerGlobalScope(serviceWorkerIdentifier, message, sourceOrigin));
 }
 
 void WebSWServerConnection::didReceiveFetchResponse(uint64_t fetchIdentifier, const ResourceResponse& response)
index 1ff4e23..2df7234 100644 (file)
                413075B31DE85F580039EC69 /* LibWebRTCProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 413075A71DE85EE70039EC69 /* LibWebRTCProvider.cpp */; };
                413075B41DE85F580039EC69 /* LibWebRTCProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 413075A81DE85EE70039EC69 /* LibWebRTCProvider.h */; };
                4131F3D11F96BCCC0059995A /* ServiceWorkerClientFetch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4131F3D01F96BCC80059995A /* ServiceWorkerClientFetch.cpp */; };
-               4131F3D41F96E9350059995A /* ServiceWorkerContextManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4131F3D31F96E9310059995A /* ServiceWorkerContextManager.cpp */; };
-               4131F3D51F96E9350059995A /* ServiceWorkerContextManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4131F3D21F96E9300059995A /* ServiceWorkerContextManager.h */; };
                4131F3E21F9880840059995A /* WebServiceWorkerFetchTaskClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4131F3E01F98712C0059995A /* WebServiceWorkerFetchTaskClient.cpp */; };
                4135FBD11F4FB8090074C47B /* CacheStorageEngineCaches.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4135FBCF1F4FB7F20074C47B /* CacheStorageEngineCaches.cpp */; };
                414DEDD71F9EDDE50047C40D /* ServiceWorkerProcessProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 414DEDD51F9EDDDF0047C40D /* ServiceWorkerProcessProxy.h */; };
                41FAF5F81E3C1021001AE678 /* LibWebRTCResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FAF5F61E3C0B47001AE678 /* LibWebRTCResolver.h */; };
                41FAF5F91E3C1025001AE678 /* LibWebRTCResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41FAF5F71E3C0B47001AE678 /* LibWebRTCResolver.cpp */; };
                4450AEC01DC3FAE5009943F2 /* SharedMemoryCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */; };
-               460F488F1F996F7100CF4B87 /* ServiceWorkerContextManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460F488D1F996F6C00CF4B87 /* ServiceWorkerContextManagerMessageReceiver.cpp */; };
-               460F48901F996F7100CF4B87 /* ServiceWorkerContextManagerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 460F488E1F996F6C00CF4B87 /* ServiceWorkerContextManagerMessages.h */; };
+               460F488F1F996F7100CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460F488D1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp */; };
+               460F48901F996F7100CF4B87 /* WebSWContextManagerConnectionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 460F488E1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessages.h */; };
                462107D81F38DBDB00DD7810 /* PingLoad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 462107D71F38DBD300DD7810 /* PingLoad.cpp */; };
                463FD4801EB9459600A2982C /* WKProcessTerminationReason.h in Headers */ = {isa = PBXBuildFile; fileRef = 463FD47F1EB9458400A2982C /* WKProcessTerminationReason.h */; settings = {ATTRIBUTES = (Private, ); }; };
                463FD4821EB94EC000A2982C /* ProcessTerminationReason.h in Headers */ = {isa = PBXBuildFile; fileRef = 463FD4811EB94EAD00A2982C /* ProcessTerminationReason.h */; };
                465250E61ECF52DC002025CB /* WebKit2InitializeCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 465250E51ECF52CD002025CB /* WebKit2InitializeCocoa.mm */; };
+               466BC03B1FA266DA002FA9C1 /* WebSWContextManagerConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 466BC0381FA266C9002FA9C1 /* WebSWContextManagerConnection.cpp */; };
+               466BC03C1FA266DA002FA9C1 /* WebSWContextManagerConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 466BC0391FA266C9002FA9C1 /* WebSWContextManagerConnection.h */; };
                46A2B6081E5676A600C3DEDA /* BackgroundProcessResponsivenessTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A2B6061E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.cpp */; };
                46A2B6091E5676A600C3DEDA /* BackgroundProcessResponsivenessTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A2B6071E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.h */; };
                46DF063B1F3905F8001980BB /* NetworkCORSPreflightChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46DF06391F3905E5001980BB /* NetworkCORSPreflightChecker.cpp */; };
                4131F3CE1F96A4950059995A /* ServiceWorkerClientFetch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerClientFetch.h; sourceTree = "<group>"; };
                4131F3CF1F96A9360059995A /* ServiceWorkerClientFetch.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ServiceWorkerClientFetch.messages.in; sourceTree = "<group>"; };
                4131F3D01F96BCC80059995A /* ServiceWorkerClientFetch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerClientFetch.cpp; sourceTree = "<group>"; };
-               4131F3D21F96E9300059995A /* ServiceWorkerContextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerContextManager.h; sourceTree = "<group>"; };
-               4131F3D31F96E9310059995A /* ServiceWorkerContextManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerContextManager.cpp; sourceTree = "<group>"; };
                4131F3E01F98712C0059995A /* WebServiceWorkerFetchTaskClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebServiceWorkerFetchTaskClient.cpp; sourceTree = "<group>"; };
                4135FBCF1F4FB7F20074C47B /* CacheStorageEngineCaches.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheStorageEngineCaches.cpp; sourceTree = "<group>"; };
                4135FBD01F4FB7F20074C47B /* CacheStorageEngineCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheStorageEngineCaches.h; sourceTree = "<group>"; };
                41FAF5F61E3C0B47001AE678 /* LibWebRTCResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCResolver.h; path = Network/webrtc/LibWebRTCResolver.h; sourceTree = "<group>"; };
                41FAF5F71E3C0B47001AE678 /* LibWebRTCResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCResolver.cpp; path = Network/webrtc/LibWebRTCResolver.cpp; sourceTree = "<group>"; };
                4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedMemoryCocoa.cpp; sourceTree = "<group>"; };
-               460F488D1F996F6C00CF4B87 /* ServiceWorkerContextManagerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerContextManagerMessageReceiver.cpp; sourceTree = "<group>"; };
-               460F488E1F996F6C00CF4B87 /* ServiceWorkerContextManagerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerContextManagerMessages.h; sourceTree = "<group>"; };
+               460F488D1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWContextManagerConnectionMessageReceiver.cpp; sourceTree = "<group>"; };
+               460F488E1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWContextManagerConnectionMessages.h; sourceTree = "<group>"; };
                462107D71F38DBD300DD7810 /* PingLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PingLoad.cpp; path = NetworkProcess/PingLoad.cpp; sourceTree = "<group>"; };
                463FD47F1EB9458400A2982C /* WKProcessTerminationReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKProcessTerminationReason.h; sourceTree = "<group>"; };
                463FD4811EB94EAD00A2982C /* ProcessTerminationReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessTerminationReason.h; sourceTree = "<group>"; };
                465250E51ECF52CD002025CB /* WebKit2InitializeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKit2InitializeCocoa.mm; sourceTree = "<group>"; };
+               466BC0381FA266C9002FA9C1 /* WebSWContextManagerConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWContextManagerConnection.cpp; sourceTree = "<group>"; };
+               466BC0391FA266C9002FA9C1 /* WebSWContextManagerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWContextManagerConnection.h; sourceTree = "<group>"; };
+               466BC03A1FA266C9002FA9C1 /* WebSWContextManagerConnection.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebSWContextManagerConnection.messages.in; sourceTree = "<group>"; };
                46A2B6061E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BackgroundProcessResponsivenessTimer.cpp; sourceTree = "<group>"; };
                46A2B6071E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackgroundProcessResponsivenessTimer.h; sourceTree = "<group>"; };
                46DF06391F3905E5001980BB /* NetworkCORSPreflightChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkCORSPreflightChecker.cpp; path = NetworkProcess/NetworkCORSPreflightChecker.cpp; sourceTree = "<group>"; };
                                4131F3D01F96BCC80059995A /* ServiceWorkerClientFetch.cpp */,
                                4131F3CE1F96A4950059995A /* ServiceWorkerClientFetch.h */,
                                4131F3CF1F96A9360059995A /* ServiceWorkerClientFetch.messages.in */,
-                               4131F3D31F96E9310059995A /* ServiceWorkerContextManager.cpp */,
-                               4131F3D21F96E9300059995A /* ServiceWorkerContextManager.h */,
                                414DEDC51F9E4BEC0047C40D /* ServiceWorkerFrameLoaderClient.cpp */,
                                414DEDC41F9E4BEB0047C40D /* ServiceWorkerFrameLoaderClient.h */,
                                4131F3E01F98712C0059995A /* WebServiceWorkerFetchTaskClient.cpp */,
                                517A53031F4793B200DCDC0A /* WebSWClientConnection.cpp */,
                                517A53021F4793B200DCDC0A /* WebSWClientConnection.h */,
                                517A530C1F479E9700DCDC0A /* WebSWClientConnection.messages.in */,
+                               466BC0381FA266C9002FA9C1 /* WebSWContextManagerConnection.cpp */,
+                               466BC0391FA266C9002FA9C1 /* WebSWContextManagerConnection.h */,
+                               466BC03A1FA266C9002FA9C1 /* WebSWContextManagerConnection.messages.in */,
                                83F1A0771F96E7700045B94E /* WebSWOriginTable.cpp */,
                                83F1A0781F96E7710045B94E /* WebSWOriginTable.h */,
                                5118E9991F295259003EF9F5 /* WebToStorageProcessConnection.cpp */,
                                E18E6913169B667B009B6670 /* SecItemShimProxyMessageReceiver.cpp */,
                                E18E6914169B667B009B6670 /* SecItemShimProxyMessages.h */,
                                617A52D71F43A9B600DCDC0A /* ServiceWorkerClientFetchMessageReceiver.cpp */,
-                               460F488D1F996F6C00CF4B87 /* ServiceWorkerContextManagerMessageReceiver.cpp */,
-                               460F488E1F996F6C00CF4B87 /* ServiceWorkerContextManagerMessages.h */,
                                2DE6943B18BD2A68005C15E5 /* SmartMagnificationControllerMessageReceiver.cpp */,
                                2DE6943C18BD2A68005C15E5 /* SmartMagnificationControllerMessages.h */,
                                1A334DEB16DE8F88006A8E38 /* StorageAreaMapMessageReceiver.cpp */,
                                5C0B17771E7C879C00E9123C /* WebSocketStreamMessages.h */,
                                517A530E1F47A84300DCDC0A /* WebSWClientConnectionMessageReceiver.cpp */,
                                517A530D1F47A84300DCDC0A /* WebSWClientConnectionMessages.h */,
+                               460F488D1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp */,
+                               460F488E1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessages.h */,
                                517A52D71F43A9B600DCDC0A /* WebSWServerConnectionMessageReceiver.cpp */,
                                517A52D61F43A9B600DCDC0A /* WebSWServerConnectionMessages.h */,
                                1AAF08B519269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp */,
                                E18E690C169B563F009B6670 /* SecItemShimProxy.h in Headers */,
                                E18E6918169B667B009B6670 /* SecItemShimProxyMessages.h in Headers */,
                                514D9F5719119D35000063A7 /* ServicesController.h in Headers */,
-                               4131F3D51F96E9350059995A /* ServiceWorkerContextManager.h in Headers */,
-                               460F48901F996F7100CF4B87 /* ServiceWorkerContextManagerMessages.h in Headers */,
                                414DEDD71F9EDDE50047C40D /* ServiceWorkerProcessProxy.h in Headers */,
                                1AFDE65A1954A42B00C48FFA /* SessionState.h in Headers */,
                                1A002D49196B345D00B9AD44 /* SessionStateCoding.h in Headers */,
                                1A52C0F81A38CDC70016160A /* WebStorageNamespaceProvider.h in Headers */,
                                517A53051F4793C600DCDC0A /* WebSWClientConnection.h in Headers */,
                                517A53101F47A86200DCDC0A /* WebSWClientConnectionMessages.h in Headers */,
+                               466BC03C1FA266DA002FA9C1 /* WebSWContextManagerConnection.h in Headers */,
+                               460F48901F996F7100CF4B87 /* WebSWContextManagerConnectionMessages.h in Headers */,
                                832994A81F96F50200AC57B1 /* WebSWOriginStore.h in Headers */,
                                83F1A07A1F96E7790045B94E /* WebSWOriginTable.h in Headers */,
                                517A530B1F479E3600DCDC0A /* WebSWServerConnection.h in Headers */,
                                514D9F5819119D35000063A7 /* ServicesController.mm in Sources */,
                                4131F3D11F96BCCC0059995A /* ServiceWorkerClientFetch.cpp in Sources */,
                                617A52D81F43A9DA00DCDC0A /* ServiceWorkerClientFetchMessageReceiver.cpp in Sources */,
-                               4131F3D41F96E9350059995A /* ServiceWorkerContextManager.cpp in Sources */,
-                               460F488F1F996F7100CF4B87 /* ServiceWorkerContextManagerMessageReceiver.cpp in Sources */,
                                414DEDD81F9EDDE50047C40D /* ServiceWorkerProcessProxy.cpp in Sources */,
                                1AFDE6591954A42B00C48FFA /* SessionState.cpp in Sources */,
                                1A002D48196B345D00B9AD44 /* SessionStateCoding.mm in Sources */,
                                1A52C0F71A38CDC70016160A /* WebStorageNamespaceProvider.cpp in Sources */,
                                517A53041F4793C600DCDC0A /* WebSWClientConnection.cpp in Sources */,
                                517A530F1F47A86200DCDC0A /* WebSWClientConnectionMessageReceiver.cpp in Sources */,
+                               466BC03B1FA266DA002FA9C1 /* WebSWContextManagerConnection.cpp in Sources */,
+                               460F488F1F996F7100CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp in Sources */,
                                832994A71F96F50200AC57B1 /* WebSWOriginStore.cpp in Sources */,
                                83F1A0791F96E7790045B94E /* WebSWOriginTable.cpp in Sources */,
                                517A530A1F479E3600DCDC0A /* WebSWServerConnection.cpp in Sources */,
@@ -24,7 +24,7 @@
  */
 
 #include "config.h"
-#include "ServiceWorkerContextManager.h"
+#include "WebSWContextManagerConnection.h"
 
 #if ENABLE(SERVICE_WORKER)
 
@@ -43,7 +43,6 @@
 #include <WebCore/EmptyClients.h>
 #include <WebCore/EmptyFrameLoaderClient.h>
 #include <WebCore/LibWebRTCProvider.h>
-#include <WebCore/MessagePortChannel.h>
 #include <WebCore/PageConfiguration.h>
 #include <WebCore/RuntimeEnabledFeatures.h>
 #include <WebCore/SerializedScriptValue.h>
@@ -82,20 +81,20 @@ private:
     uint64_t m_frameID { 0 };
 };
 
-ServiceWorkerContextManager::ServiceWorkerContextManager(Ref<IPC::Connection>&& connection, uint64_t pageID, const WebPreferencesStore& store)
+WebSWContextManagerConnection::WebSWContextManagerConnection(Ref<IPC::Connection>&& connection, uint64_t pageID, const WebPreferencesStore& store)
     : m_connectionToStorageProcess(WTFMove(connection))
     , m_pageID(pageID)
 {
     updatePreferences(store);
 }
 
-void ServiceWorkerContextManager::updatePreferences(const WebPreferencesStore& store)
+void WebSWContextManagerConnection::updatePreferences(const WebPreferencesStore& store)
 {
     RuntimeEnabledFeatures::sharedFeatures().setCacheAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::cacheAPIEnabledKey()));
     RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey()));
 }
 
-void ServiceWorkerContextManager::startServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
+void WebSWContextManagerConnection::startServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
 {
     // FIXME: Provide a sensical session ID.
     auto sessionID = PAL::SessionID::defaultSessionID();
@@ -112,17 +111,16 @@ void ServiceWorkerContextManager::startServiceWorker(uint64_t serverConnectionId
 
     auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, WebProcess::singleton().cacheStorageProvider());
     auto serviceWorkerIdentifier = serviceWorkerThreadProxy->identifier();
-    auto result = m_workerMap.add(serviceWorkerIdentifier, WTFMove(serviceWorkerThreadProxy));
-    ASSERT_UNUSED(result, result.isNewEntry);
+    SWContextManager::singleton().registerServiceWorkerThread(WTFMove(serviceWorkerThreadProxy));
 
     LOG(ServiceWorker, "Context process PID: %i started worker thread %s\n", getpid(), data.workerID.utf8().data());
 
     m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(serverConnectionIdentifier, data.registrationKey, serviceWorkerIdentifier, data.workerID), 0);
 }
 
-void ServiceWorkerContextManager::startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, ResourceRequest&& request, FetchOptions&& options)
+void WebSWContextManagerConnection::startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, ResourceRequest&& request, FetchOptions&& options)
 {
-    auto serviceWorkerThreadProxy = serviceWorkerIdentifier ? m_workerMap.get(serviceWorkerIdentifier) : nullptr;
+    auto* serviceWorkerThreadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier);
     if (!serviceWorkerThreadProxy) {
         m_connectionToStorageProcess->send(Messages::StorageProcess::DidNotHandleFetch(serverConnectionIdentifier, fetchIdentifier), 0);
         return;
@@ -132,14 +130,9 @@ void ServiceWorkerContextManager::startFetch(uint64_t serverConnectionIdentifier
     serviceWorkerThreadProxy->thread().postFetchTask(WTFMove(client), WTFMove(request), WTFMove(options));
 }
 
-void ServiceWorkerContextManager::postMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin)
+void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin)
 {
-    auto* serviceWorker = m_workerMap.get(serviceWorkerIdentifier);
-    if (!serviceWorker)
-        return;
-
-    // FIXME: We should pass valid MessagePortChannels.
-    serviceWorker->thread().postMessageToServiceWorkerGlobalScope(SerializedScriptValue::adopt(message.vector()), nullptr, sourceOrigin);
+    SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(serviceWorkerIdentifier, SerializedScriptValue::adopt(message.vector()), sourceOrigin);
 }
 
 } // namespace WebCore
@@ -29,8 +29,7 @@
 
 #include "Connection.h"
 #include "MessageReceiver.h"
-#include <WebCore/ServiceWorkerThreadProxy.h>
-#include <wtf/HashMap.h>
+#include <WebCore/SWContextManager.h>
 
 namespace WebCore {
 struct FetchOptions;
@@ -39,23 +38,24 @@ struct ServiceWorkerContextData;
 }
 
 namespace WebKit {
+
 struct WebPreferencesStore;
 
-class ServiceWorkerContextManager : public IPC::MessageReceiver {
+class WebSWContextManagerConnection : public WebCore::SWContextManager::Connection, public IPC::MessageReceiver {
 public:
-    ServiceWorkerContextManager(Ref<IPC::Connection>&&, uint64_t pageID, const WebPreferencesStore&);
+    WebSWContextManagerConnection(Ref<IPC::Connection>&&, uint64_t pageID, const WebPreferencesStore&);
 
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
 
+    void postMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin);
+
 private:
     void updatePreferences(const WebPreferencesStore&);
 
     void startServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
     void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
-    void postMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, const IPC::DataReference& message, const String& sourceOrigin);
 
     Ref<IPC::Connection> m_connectionToStorageProcess;
-    HashMap<uint64_t, RefPtr<WebCore::ServiceWorkerThreadProxy>> m_workerMap;
     uint64_t m_pageID { 0 };
     uint64_t m_previousServiceWorkerID { 0 };
 };
 
 #if ENABLE(SERVICE_WORKER)
 
-messages -> ServiceWorkerContextManager {
+messages -> WebSWContextManagerConnection {
     StartServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
     StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
-    PostMessageToServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, uint64_t serviceWorkerIdentifier, IPC::DataReference message, String sourceOrigin)
+    PostMessageToServiceWorkerGlobalScope(uint64_t serviceWorkerIdentifier, IPC::DataReference message, String sourceOrigin)
 }
 
 #endif
index 3384ab8..d77f56c 100644 (file)
@@ -41,8 +41,6 @@
 #include "NetworkSession.h"
 #include "NetworkSessionCreationParameters.h"
 #include "PluginProcessConnectionManager.h"
-#include "ServiceWorkerContextManager.h"
-#include "ServiceWorkerContextManagerMessages.h"
 #include "SessionTracker.h"
 #include "StatisticsData.h"
 #include "StorageProcessMessages.h"
@@ -68,6 +66,8 @@
 #include "WebProcessPoolMessages.h"
 #include "WebProcessProxyMessages.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
+#include "WebSWContextManagerConnection.h"
+#include "WebSWContextManagerConnectionMessages.h"
 #include "WebServiceWorkerProvider.h"
 #include "WebSocketStream.h"
 #include "WebToStorageProcessConnection.h"
@@ -674,10 +674,10 @@ void WebProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& de
     }
 
 #if ENABLE(SERVICE_WORKER)
-    if (decoder.messageReceiverName() == Messages::ServiceWorkerContextManager::messageReceiverName()) {
-        ASSERT(m_serviceWorkerManager);
-        if (m_serviceWorkerManager)
-            m_serviceWorkerManager->didReceiveMessage(connection, decoder);
+    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
@@ -1642,8 +1642,6 @@ LibWebRTCNetwork& WebProcess::libWebRTCNetwork()
 #if ENABLE(SERVICE_WORKER)
 void WebProcess::getWorkerContextConnection(uint64_t pageID, const WebPreferencesStore& store)
 {
-    ASSERT(!m_serviceWorkerManager);
-
 #if USE(UNIX_DOMAIN_SOCKETS)
     IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
     IPC::Connection::Identifier connectionIdentifier(socketPair.server);
@@ -1664,7 +1662,7 @@ void WebProcess::getWorkerContextConnection(uint64_t pageID, const WebPreference
 
     auto workerContextConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
     workerContextConnection->open();
-    m_serviceWorkerManager = ServiceWorkerContextManager(WTFMove(workerContextConnection), pageID, store);
+    SWContextManager::singleton().setConnection(std::make_unique<WebSWContextManagerConnection>(WTFMove(workerContextConnection), pageID, store));
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidGetWorkerContextConnection(connectionClientPort), 0);
 }
 #endif
index 246f77f..2f262a6 100644 (file)
@@ -30,7 +30,6 @@
 #include "PluginProcessConnectionManager.h"
 #include "ResourceCachesToClear.h"
 #include "SandboxExtension.h"
-#include "ServiceWorkerContextManager.h"
 #include "TextCheckerState.h"
 #include "ViewUpdateDispatcher.h"
 #include "WebInspectorInterruptDispatcher.h"
@@ -437,9 +436,6 @@ private:
 #if PLATFORM(WAYLAND)
     std::unique_ptr<WaylandCompositorDisplay> m_waylandCompositorDisplay;
 #endif
-#if ENABLE(SERVICE_WORKER)
-    std::optional<ServiceWorkerContextManager> m_serviceWorkerManager;
-#endif
 };
 
 } // namespace WebKit