Massive "Server-process-to-context-process" connection overhaul.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Nov 2017 03:58:01 +0000 (03:58 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Nov 2017 03:58:01 +0000 (03:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179554

Reviewed by Chris Dumez.

Source/WebCore:

No new tests (Refactor, no behavior change).

Having the SWServer::Connection object be overloaded to mean both client->server and server->context
was the wrong design and was starting to crumble under its own weight.

So this patch introduces a SWServerToContextConnection to manage the StorageProcess-side of connections
to context processes.

Any message that is specifically about the connection between the StorageProcess and context process
should use this connection going forward.

Right now there is only one context process, but this design keeps us ready for that to change.

This patch also gets rid of a lot of "server connection identifier" integers being passed amongst processes
that were actually pointless.

This patch is also a prerequisite for many things that are coming up soon, such as termination.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

* workers/service/ServiceWorkerContextData.cpp:
(WebCore::ServiceWorkerContextData::isolatedCopy const):
* workers/service/ServiceWorkerContextData.h:
(WebCore::ServiceWorkerContextData::encode const):
(WebCore::ServiceWorkerContextData::decode):

* workers/service/ServiceWorkerGlobalScope.cpp:
(WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
* workers/service/ServiceWorkerGlobalScope.h:
(WebCore::ServiceWorkerGlobalScope::serverConnectionIdentifier const): Deleted.

* workers/service/ServiceWorkerTypes.h:

* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::ServiceWorkerThread):
(WebCore::ServiceWorkerThread::createWorkerGlobalScope):
* workers/service/context/ServiceWorkerThread.h:
(WebCore::ServiceWorkerThread::serverConnectionIdentifier const): Deleted.

* workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
(WebCore::ServiceWorkerThreadProxy::create): Deleted.
* workers/service/context/ServiceWorkerThreadProxy.h:

* workers/service/server/SWServer.cpp:
(WebCore::generateServiceWorkerIdentifier):
(WebCore::SWServer::~SWServer):
(WebCore::SWServer::SWServer):
(WebCore::SWServer::scriptContextFailedToStart):
(WebCore::SWServer::scriptContextStarted):
(WebCore::SWServer::didFinishInstall):
(WebCore::SWServer::didFinishActivation):
(WebCore::SWServer::didResolveRegistrationPromise):
(WebCore::SWServer::updateWorker):
(WebCore::SWServer::serverToContextConnectionCreated):
(WebCore::SWServer::installContextData):
(WebCore::SWServer::fireInstallEvent):
(WebCore::SWServer::fireActivateEvent):
(WebCore::SWServer::Connection::didFinishInstall): Deleted.
(WebCore::SWServer::Connection::didFinishActivation): Deleted.
(WebCore::SWServer::Connection::setServiceWorkerHasPendingEvents): Deleted.
(WebCore::SWServer::Connection::scriptContextFailedToStart): Deleted.
(WebCore::SWServer::Connection::scriptContextStarted): Deleted.
(WebCore::SWServer::setServiceWorkerHasPendingEvents): Deleted.
* workers/service/server/SWServer.h:

* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptContextFailedToStart):
(WebCore::SWServerJobQueue::scriptContextStarted):
(WebCore::SWServerJobQueue::install):
(WebCore::SWServerJobQueue::didResolveRegistrationPromise):
(WebCore::SWServerJobQueue::didFinishInstall):
(WebCore::SWServerJobQueue::tryActivate):
(WebCore::SWServerJobQueue::activate):
* workers/service/server/SWServerJobQueue.h:

* workers/service/server/SWServerRegistration.cpp:
(WebCore::generateServiceWorkerRegistrationIdentifier):

* workers/service/server/SWServerToContextConnection.cpp: Added.
(WebCore::generateServerToContextConnectionIdentifier):
(WebCore::SWServerToContextConnection::SWServerToContextConnection):
(WebCore::SWServerToContextConnection::~SWServerToContextConnection):
(WebCore::SWServerToContextConnection::connectionForIdentifier):
(WebCore::SWServerToContextConnection::globalServerToContextConnection):
(WebCore::SWServerToContextConnection::scriptContextFailedToStart):
(WebCore::SWServerToContextConnection::scriptContextStarted):
(WebCore::SWServerToContextConnection::didFinishInstall):
(WebCore::SWServerToContextConnection::didFinishActivation):
(WebCore::SWServerToContextConnection::setServiceWorkerHasPendingEvents):
* workers/service/server/SWServerToContextConnection.h: Copied from Source/WebCore/workers/service/server/SWServerWorker.h.
(WebCore::SWServerToContextConnection::identifier const):

* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::existingWorkerForIdentifier):
(WebCore::SWServerWorker::SWServerWorker):
(WebCore::SWServerWorker::~SWServerWorker):
(WebCore::SWServerWorker::scriptContextFailedToStart):
(WebCore::SWServerWorker::scriptContextStarted):
(WebCore::SWServerWorker::didFinishInstall):
(WebCore::SWServerWorker::didFinishActivation):
* workers/service/server/SWServerWorker.h:
(WebCore::SWServerWorker::create):
(WebCore::SWServerWorker::registrationKey const):
(WebCore::SWServerWorker::contextConnectionIdentifier const):

Source/WebKit:

* DerivedSources.make:
* WebKit.xcodeproj/project.pbxproj:

* Shared/WebCoreArgumentCoders.h:

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::sendToContextProcess):
(WebKit::WebSWServerConnection::installServiceWorkerContext): Deleted.
(WebKit::WebSWServerConnection::fireInstallEvent): Deleted.
(WebKit::WebSWServerConnection::fireActivateEvent): Deleted.
(WebKit::WebSWServerConnection::setContextConnection): Deleted.
* StorageProcess/ServiceWorker/WebSWServerConnection.h:

* StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp: Copied from Source/WebCore/workers/service/server/SWServerWorker.cpp.
(WebKit::WebSWServerToContextConnection::WebSWServerToContextConnection):
(WebKit::WebSWServerToContextConnection::messageSenderConnection):
(WebKit::WebSWServerToContextConnection::messageSenderDestinationID):
(WebKit::WebSWServerToContextConnection::connectionClosed):
(WebKit::WebSWServerToContextConnection::installServiceWorkerContext):
(WebKit::WebSWServerToContextConnection::fireInstallEvent):
(WebKit::WebSWServerToContextConnection::fireActivateEvent):
* StorageProcess/ServiceWorker/WebSWServerToContextConnection.h: Copied from Source/WebCore/workers/service/ServiceWorkerTypes.h.
(WebKit::WebSWServerToContextConnection::create):
(WebKit::WebSWServerToContextConnection::ipcConnection const):
* StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in: Copied from Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in.

* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::didClose):
(WebKit::StorageProcess::didReceiveMessage):
(WebKit::StorageProcess::globalServerToContextConnection):
(WebKit::StorageProcess::createServerToContextConnection):
(WebKit::StorageProcess::didGetWorkerContextProcessConnection):
(WebKit::StorageProcess::workerContextProcessConnection): Deleted.
(WebKit::StorageProcess::createWorkerContextProcessConnection): Deleted.
(WebKit::StorageProcess::serviceWorkerContextFailedToStart): Deleted.
(WebKit::StorageProcess::serviceWorkerContextStarted): Deleted.
(WebKit::StorageProcess::didFinishServiceWorkerInstall): Deleted.
(WebKit::StorageProcess::didFinishServiceWorkerActivation): Deleted.
(WebKit::StorageProcess::setServiceWorkerHasPendingEvents): Deleted.
* StorageProcess/StorageProcess.h:
* StorageProcess/StorageProcess.messages.in:

* StorageProcess/StorageToWebProcessConnection.cpp:
(WebKit::StorageToWebProcessConnection::didReceiveMessage):
(WebKit::StorageToWebProcessConnection::establishSWServerConnection):
(WebKit::StorageToWebProcessConnection::workerContextProcessConnectionCreated):

* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::installServiceWorker):
(WebKit::WebSWContextManagerConnection::serviceWorkerStartedWithMessage):
(WebKit::WebSWContextManagerConnection::fireInstallEvent):
(WebKit::WebSWContextManagerConnection::fireActivateEvent):
(WebKit::WebSWContextManagerConnection::didFinishInstall):
(WebKit::WebSWContextManagerConnection::didFinishActivation):
(WebKit::WebSWContextManagerConnection::setServiceWorkerHasPendingEvents):
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:

Source/WTF:

* wtf/ObjectIdentifier.h:
(WTF::generateObjectIdentifier):
(WTF::makeObjectIdentifier): Deleted.

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

39 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/ObjectIdentifier.h
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/workers/service/ServiceWorkerContextData.cpp
Source/WebCore/workers/service/ServiceWorkerContextData.h
Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp
Source/WebCore/workers/service/ServiceWorkerGlobalScope.h
Source/WebCore/workers/service/ServiceWorkerTypes.h
Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
Source/WebCore/workers/service/context/ServiceWorkerThread.h
Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp
Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServer.h
Source/WebCore/workers/service/server/SWServerJobQueue.cpp
Source/WebCore/workers/service/server/SWServerJobQueue.h
Source/WebCore/workers/service/server/SWServerRegistration.cpp
Source/WebCore/workers/service/server/SWServerToContextConnection.cpp [new file with mode: 0644]
Source/WebCore/workers/service/server/SWServerToContextConnection.h [new file with mode: 0644]
Source/WebCore/workers/service/server/SWServerWorker.cpp
Source/WebCore/workers/service/server/SWServerWorker.h
Source/WebKit/ChangeLog
Source/WebKit/DerivedSources.make
Source/WebKit/Shared/WebCoreArgumentCoders.h
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp [new file with mode: 0644]
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h [new file with mode: 0644]
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in [new file with mode: 0644]
Source/WebKit/StorageProcess/StorageProcess.cpp
Source/WebKit/StorageProcess/StorageProcess.h
Source/WebKit/StorageProcess/StorageProcess.messages.in
Source/WebKit/StorageProcess/StorageToWebProcessConnection.cpp
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in

index 0dabb73..f5df72e 100644 (file)
@@ -1,3 +1,14 @@
+2017-11-13  Brady Eidson  <beidson@apple.com>
+
+        Massive "Server-process-to-context-process" connection overhaul.
+        https://bugs.webkit.org/show_bug.cgi?id=179554
+
+        Reviewed by Chris Dumez.
+
+        * wtf/ObjectIdentifier.h:
+        (WTF::generateObjectIdentifier):
+        (WTF::makeObjectIdentifier): Deleted.
+
 2017-11-13  JF Bastien  <jfbastien@apple.com>
 
         std::expected: fix and test move
index ef37154..67dee02 100644 (file)
@@ -70,7 +70,7 @@ public:
 #endif
 
 private:
-    template<typename U> friend ObjectIdentifier<U> makeObjectIdentifier(uint64_t);
+    template<typename U> friend ObjectIdentifier<U> generateObjectIdentifier();
     friend struct HashTraits<ObjectIdentifier>;
     template<typename U> friend struct ObjectIdentifierHash;
 
@@ -83,12 +83,14 @@ private:
     }
 
     uint64_t m_identifier { 0 };
+    static uint64_t s_currentIdentifier;
 };
 
-template<typename T> inline ObjectIdentifier<T> makeObjectIdentifier(uint64_t identifier)
+template<typename T> uint64_t ObjectIdentifier<T>::s_currentIdentifier;
+
+template<typename T> inline ObjectIdentifier<T> generateObjectIdentifier()
 {
-    ASSERT(ObjectIdentifier<T>::isValidIdentifier(identifier));
-    return ObjectIdentifier<T> { identifier };
+    return ObjectIdentifier<T> { ++ObjectIdentifier<T>::s_currentIdentifier };
 }
 
 template<typename T> struct ObjectIdentifierHash {
@@ -106,4 +108,4 @@ template<typename T> struct DefaultHash<ObjectIdentifier<T>> {
 } // namespace WTF
 
 using WTF::ObjectIdentifier;
-using WTF::makeObjectIdentifier;
+using WTF::generateObjectIdentifier;
index cb5b5cb..c52d357 100644 (file)
@@ -1,3 +1,117 @@
+2017-11-13  Brady Eidson  <beidson@apple.com>
+
+        Massive "Server-process-to-context-process" connection overhaul.
+        https://bugs.webkit.org/show_bug.cgi?id=179554
+
+        Reviewed by Chris Dumez.
+
+        No new tests (Refactor, no behavior change).
+
+        Having the SWServer::Connection object be overloaded to mean both client->server and server->context 
+        was the wrong design and was starting to crumble under its own weight.
+
+        So this patch introduces a SWServerToContextConnection to manage the StorageProcess-side of connections
+        to context processes.
+
+        Any message that is specifically about the connection between the StorageProcess and context process
+        should use this connection going forward.
+
+        Right now there is only one context process, but this design keeps us ready for that to change.
+
+        This patch also gets rid of a lot of "server connection identifier" integers being passed amongst processes
+        that were actually pointless.
+
+        This patch is also a prerequisite for many things that are coming up soon, such as termination.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * workers/service/ServiceWorkerContextData.cpp:
+        (WebCore::ServiceWorkerContextData::isolatedCopy const):
+        * workers/service/ServiceWorkerContextData.h:
+        (WebCore::ServiceWorkerContextData::encode const):
+        (WebCore::ServiceWorkerContextData::decode):
+
+        * workers/service/ServiceWorkerGlobalScope.cpp:
+        (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope):
+        * workers/service/ServiceWorkerGlobalScope.h:
+        (WebCore::ServiceWorkerGlobalScope::serverConnectionIdentifier const): Deleted.
+
+        * workers/service/ServiceWorkerTypes.h:
+
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
+        (WebCore::ServiceWorkerThread::createWorkerGlobalScope):
+        * workers/service/context/ServiceWorkerThread.h:
+        (WebCore::ServiceWorkerThread::serverConnectionIdentifier const): Deleted.
+
+        * workers/service/context/ServiceWorkerThreadProxy.cpp:
+        (WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
+        (WebCore::ServiceWorkerThreadProxy::create): Deleted.
+        * workers/service/context/ServiceWorkerThreadProxy.h:
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::generateServiceWorkerIdentifier):
+        (WebCore::SWServer::~SWServer):
+        (WebCore::SWServer::SWServer):
+        (WebCore::SWServer::scriptContextFailedToStart):
+        (WebCore::SWServer::scriptContextStarted):
+        (WebCore::SWServer::didFinishInstall):
+        (WebCore::SWServer::didFinishActivation):
+        (WebCore::SWServer::didResolveRegistrationPromise):
+        (WebCore::SWServer::updateWorker):
+        (WebCore::SWServer::serverToContextConnectionCreated):
+        (WebCore::SWServer::installContextData):
+        (WebCore::SWServer::fireInstallEvent):
+        (WebCore::SWServer::fireActivateEvent):
+        (WebCore::SWServer::Connection::didFinishInstall): Deleted.
+        (WebCore::SWServer::Connection::didFinishActivation): Deleted.
+        (WebCore::SWServer::Connection::setServiceWorkerHasPendingEvents): Deleted.
+        (WebCore::SWServer::Connection::scriptContextFailedToStart): Deleted.
+        (WebCore::SWServer::Connection::scriptContextStarted): Deleted.
+        (WebCore::SWServer::setServiceWorkerHasPendingEvents): Deleted.
+        * workers/service/server/SWServer.h:
+
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::scriptContextFailedToStart):
+        (WebCore::SWServerJobQueue::scriptContextStarted):
+        (WebCore::SWServerJobQueue::install):
+        (WebCore::SWServerJobQueue::didResolveRegistrationPromise):
+        (WebCore::SWServerJobQueue::didFinishInstall):
+        (WebCore::SWServerJobQueue::tryActivate):
+        (WebCore::SWServerJobQueue::activate):
+        * workers/service/server/SWServerJobQueue.h:
+
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::generateServiceWorkerRegistrationIdentifier):
+
+        * workers/service/server/SWServerToContextConnection.cpp: Added.
+        (WebCore::generateServerToContextConnectionIdentifier):
+        (WebCore::SWServerToContextConnection::SWServerToContextConnection):
+        (WebCore::SWServerToContextConnection::~SWServerToContextConnection):
+        (WebCore::SWServerToContextConnection::connectionForIdentifier):
+        (WebCore::SWServerToContextConnection::globalServerToContextConnection):
+        (WebCore::SWServerToContextConnection::scriptContextFailedToStart):
+        (WebCore::SWServerToContextConnection::scriptContextStarted):
+        (WebCore::SWServerToContextConnection::didFinishInstall):
+        (WebCore::SWServerToContextConnection::didFinishActivation):
+        (WebCore::SWServerToContextConnection::setServiceWorkerHasPendingEvents):
+        * workers/service/server/SWServerToContextConnection.h: Copied from Source/WebCore/workers/service/server/SWServerWorker.h.
+        (WebCore::SWServerToContextConnection::identifier const):
+
+        * workers/service/server/SWServerWorker.cpp:
+        (WebCore::SWServerWorker::existingWorkerForIdentifier):
+        (WebCore::SWServerWorker::SWServerWorker):
+        (WebCore::SWServerWorker::~SWServerWorker):
+        (WebCore::SWServerWorker::scriptContextFailedToStart):
+        (WebCore::SWServerWorker::scriptContextStarted):
+        (WebCore::SWServerWorker::didFinishInstall):
+        (WebCore::SWServerWorker::didFinishActivation):
+        * workers/service/server/SWServerWorker.h:
+        (WebCore::SWServerWorker::create):
+        (WebCore::SWServerWorker::registrationKey const):
+        (WebCore::SWServerWorker::contextConnectionIdentifier const):
+
 2017-11-13  Don Olmstead  <don.olmstead@sony.com>
 
         Unreviewed build fix after r224791.
index 9fddf5c..ac9f6e7 100644 (file)
@@ -2194,6 +2194,7 @@ workers/service/server/SWOriginStore.cpp
 workers/service/server/SWServer.cpp
 workers/service/server/SWServerJobQueue.cpp
 workers/service/server/SWServerRegistration.cpp
+workers/service/server/SWServerToContextConnection.cpp
 workers/service/server/SWServerWorker.cpp
 
 xml/DOMParser.cpp
index ada6e02..8923dca 100644 (file)
                5182C2581F3143CD0059BA7C /* JSServiceWorkerContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C2541F3142500059BA7C /* JSServiceWorkerContainer.h */; };
                5182C25A1F3143CD0059BA7C /* JSServiceWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C24D1F3142500059BA7C /* JSServiceWorkerGlobalScope.h */; };
                5182C25C1F3143CD0059BA7C /* JSServiceWorkerRegistration.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C2501F3142500059BA7C /* JSServiceWorkerRegistration.h */; };
+               5185430B1FB6784500478F95 /* SWServerToContextConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 518543091FB6783E00478F95 /* SWServerToContextConnection.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5185FC751BB4C4E80012898F /* DOMWindowIndexedDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D7196D181106DF0016DC51 /* DOMWindowIndexedDatabase.h */; };
                5185FC7B1BB4C4E80012898F /* IDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 51645B411B9F889B00F789CE /* IDBCursor.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5185FC7E1BB4C4E80012898F /* IDBCursorWithValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 51645B431B9F889B00F789CE /* IDBCursorWithValue.h */; };
                51E6821016387302003BBF3C /* LoaderStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 51E6820F16387302003BBF3C /* LoaderStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51EE7B381AA50B0500F92B21 /* ResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EE7B371AA50B0500F92B21 /* ResourceLoadInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51EEAA741BEFFAB100218008 /* IndexValueEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EEAA721BEFFA7900218008 /* IndexValueEntry.h */; };
-               51F174FE1F35899200C74950 /* WorkerType.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F174FC1F35898800C74950 /* WorkerType.h */; };
+               51F174FE1F35899200C74950 /* WorkerType.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F174FC1F35898800C74950 /* WorkerType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51F175031F358B3B00C74950 /* JSServiceWorkerUpdateViaCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F175011F358B3600C74950 /* JSServiceWorkerUpdateViaCache.h */; };
                51F175061F358BF700C74950 /* JSWorkerType.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F175051F358BDE00C74950 /* JSWorkerType.h */; };
                51F1755D1F3EBC8300C74950 /* ServiceWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F1755A1F3EBC0C00C74950 /* ServiceWorker.h */; };
                5182C2521F3142500059BA7C /* JSServiceWorker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSServiceWorker.h; sourceTree = "<group>"; };
                5182C2531F3142500059BA7C /* JSServiceWorker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSServiceWorker.cpp; sourceTree = "<group>"; };
                5182C2541F3142500059BA7C /* JSServiceWorkerContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSServiceWorkerContainer.h; sourceTree = "<group>"; };
+               518543091FB6783E00478F95 /* SWServerToContextConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWServerToContextConnection.h; sourceTree = "<group>"; };
+               5185430A1FB6783F00478F95 /* SWServerToContextConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWServerToContextConnection.cpp; sourceTree = "<group>"; };
                5185FCBC1BB5CB770012898F /* IDBConnectionToServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBConnectionToServer.cpp; sourceTree = "<group>"; };
                5185FCBD1BB5CB770012898F /* IDBConnectionToServerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBConnectionToServerDelegate.h; sourceTree = "<group>"; };
                518864DE1BBAF30F00E540C9 /* UniqueIDBDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueIDBDatabase.cpp; sourceTree = "<group>"; };
                                8311C0021FAA2E8900E3C8E5 /* SWServerJobQueue.h */,
                                51F645951F4A686100B54DED /* SWServerRegistration.cpp */,
                                51F645941F4A684F00B54DED /* SWServerRegistration.h */,
+                               5185430A1FB6783F00478F95 /* SWServerToContextConnection.cpp */,
+                               518543091FB6783E00478F95 /* SWServerToContextConnection.h */,
                                517A53431F50C16100DCDC0A /* SWServerWorker.cpp */,
                                517A53421F50C16100DCDC0A /* SWServerWorker.h */,
                        );
                        isa = PBXGroup;
                        children = (
                                538EC7F31F96AA5B004D22A8 /* UnifiedSource1-mm.mm */,
-                               538EC7F81F96AA69004D22A8 /* UnifiedSource2-mm.mm */,
-                               538EC7ED1F96AA55004D22A8 /* UnifiedSource3-mm.mm */,
-                               DE5F85491FA1ABBD006DB63A /* UnifiedSource4-mm.mm */,
-                               DE5F85651FA1ABD6006DB63A /* UnifiedSource5-mm.mm */,
-                               DE5F856B1FA1ABDB006DB63A /* UnifiedSource6-mm.mm */,
-                               DE5F855F1FA1ABD1006DB63A /* UnifiedSource7-mm.mm */,
-                               DE5F853D1FA1ABB2006DB63A /* UnifiedSource8-mm.mm */,
-                               DE5F85541FA1ABC7006DB63A /* UnifiedSource9-mm.mm */,
-                               DE5F85631FA1ABD5006DB63A /* UnifiedSource10-mm.mm */,
-                               DE5F85611FA1ABD3006DB63A /* UnifiedSource11-mm.mm */,
-                               DE5F85641FA1ABD5006DB63A /* UnifiedSource12-mm.mm */,
-                               DE5F856A1FA1ABDB006DB63A /* UnifiedSource13-mm.mm */,
-                               DE5F854E1FA1ABC2006DB63A /* UnifiedSource14-mm.mm */,
-                               DE5F853E1FA1ABB3006DB63A /* UnifiedSource15-mm.mm */,
-                               DE5F855E1FA1ABD0006DB63A /* UnifiedSource16-mm.mm */,
-                               DE5F854A1FA1ABBE006DB63A /* UnifiedSource17-mm.mm */,
-                               DE5F85501FA1ABC3006DB63A /* UnifiedSource18-mm.mm */,
-                               DE5F85531FA1ABC6006DB63A /* UnifiedSource19-mm.mm */,
-                               DE5F85521FA1ABC5006DB63A /* UnifiedSource20-mm.mm */,
-                               DE5F855A1FA1ABCD006DB63A /* UnifiedSource21-mm.mm */,
-                               DE5F854D1FA1ABC1006DB63A /* UnifiedSource22-mm.mm */,
-                               DE5F85411FA1ABB6006DB63A /* UnifiedSource23-mm.mm */,
-                               DE5F85461FA1ABBB006DB63A /* UnifiedSource24-mm.mm */,
-                               DE5F85471FA1ABBB006DB63A /* UnifiedSource25-mm.mm */,
-                               DE5F855D1FA1ABCF006DB63A /* UnifiedSource26-mm.mm */,
-                               DE5F85691FA1ABDA006DB63A /* UnifiedSource27-mm.mm */,
-                               DE5F853F1FA1ABB4006DB63A /* UnifiedSource28-mm.mm */,
-                               DE5F85681FA1ABD9006DB63A /* UnifiedSource29-mm.mm */,
-                               DE5F85421FA1ABB7006DB63A /* UnifiedSource30-mm.mm */,
-                               DE5F85511FA1ABC4006DB63A /* UnifiedSource31-mm.mm */,
-                               DE5F85601FA1ABD2006DB63A /* UnifiedSource32-mm.mm */,
-                               DE5F855B1FA1ABCE006DB63A /* UnifiedSource33-mm.mm */,
-                               DE5F85571FA1ABCA006DB63A /* UnifiedSource34-mm.mm */,
-                               DE5F85401FA1ABB5006DB63A /* UnifiedSource35-mm.mm */,
-                               DE5F85551FA1ABC8006DB63A /* UnifiedSource36-mm.mm */,
-                               DE5F85451FA1ABBA006DB63A /* UnifiedSource37-mm.mm */,
-                               DE5F855C1FA1ABCE006DB63A /* UnifiedSource38-mm.mm */,
-                               DE5F85591FA1ABCC006DB63A /* UnifiedSource39-mm.mm */,
-                               DE5F85561FA1ABC9006DB63A /* UnifiedSource40-mm.mm */,
-                               DE5F85661FA1ABD7006DB63A /* UnifiedSource41-mm.mm */,
-                               DE5F854F1FA1ABC3006DB63A /* UnifiedSource42-mm.mm */,
-                               DE5F85481FA1ABBC006DB63A /* UnifiedSource43-mm.mm */,
-                               DE5F85431FA1ABB8006DB63A /* UnifiedSource44-mm.mm */,
-                               DE5F85581FA1ABCB006DB63A /* UnifiedSource45-mm.mm */,
-                               DE5F85441FA1ABB9006DB63A /* UnifiedSource46-mm.mm */,
-                               DE5F85621FA1ABD4006DB63A /* UnifiedSource47-mm.mm */,
-                               DE5F85671FA1ABD8006DB63A /* UnifiedSource48-mm.mm */,
-                               DE5F854B1FA1ABBF006DB63A /* UnifiedSource49-mm.mm */,
-                               DE5F854C1FA1ABC0006DB63A /* UnifiedSource50-mm.mm */,
-                               DE5F86361FA2AF04006DB63A /* UnifiedSource51-mm.mm */,
-                               DE5F86371FA2AF05006DB63A /* UnifiedSource52-mm.mm */,
-                               DE5F86351FA2AF03006DB63A /* UnifiedSource53-mm.mm */,
-                               DE5F86331FA2AF00006DB63A /* UnifiedSource54-mm.mm */,
-                               DE5F863B1FA2AF08006DB63A /* UnifiedSource55-mm.mm */,
-                               DE5F86341FA2AF01006DB63A /* UnifiedSource56-mm.mm */,
-                               DE5F86381FA2AF06006DB63A /* UnifiedSource57-mm.mm */,
-                               DE5F86391FA2AF07006DB63A /* UnifiedSource58-mm.mm */,
-                               DE5F86321FA2AEFF006DB63A /* UnifiedSource59-mm.mm */,
-                               DE5F863A1FA2AF07006DB63A /* UnifiedSource60-mm.mm */,
                                538EC7FA1F96AA70004D22A8 /* UnifiedSource1.cpp */,
+                               538EC7F81F96AA69004D22A8 /* UnifiedSource2-mm.mm */,
                                538EC7EE1F96AA56004D22A8 /* UnifiedSource2.cpp */,
+                               538EC7ED1F96AA55004D22A8 /* UnifiedSource3-mm.mm */,
                                538EC7EC1F96AA54004D22A8 /* UnifiedSource3.cpp */,
+                               DE5F85491FA1ABBD006DB63A /* UnifiedSource4-mm.mm */,
                                538EC7EF1F96AA57004D22A8 /* UnifiedSource4.cpp */,
+                               DE5F85651FA1ABD6006DB63A /* UnifiedSource5-mm.mm */,
                                538EC7F01F96AA58004D22A8 /* UnifiedSource5.cpp */,
+                               DE5F856B1FA1ABDB006DB63A /* UnifiedSource6-mm.mm */,
                                538EC7EB1F96AA53004D22A8 /* UnifiedSource6.cpp */,
+                               DE5F855F1FA1ABD1006DB63A /* UnifiedSource7-mm.mm */,
                                538EC7F11F96AA59004D22A8 /* UnifiedSource7.cpp */,
+                               DE5F853D1FA1ABB2006DB63A /* UnifiedSource8-mm.mm */,
                                538EC7F21F96AA5A004D22A8 /* UnifiedSource8.cpp */,
+                               DE5F85541FA1ABC7006DB63A /* UnifiedSource9-mm.mm */,
                                538EC7FE1F96AA76004D22A8 /* UnifiedSource9.cpp */,
+                               DE5F85631FA1ABD5006DB63A /* UnifiedSource10-mm.mm */,
                                538EC7F51F96AA5E004D22A8 /* UnifiedSource10.cpp */,
+                               DE5F85611FA1ABD3006DB63A /* UnifiedSource11-mm.mm */,
                                538EC7F41F96AA5D004D22A8 /* UnifiedSource11.cpp */,
+                               DE5F85641FA1ABD5006DB63A /* UnifiedSource12-mm.mm */,
                                538EC7F61F96AA5F004D22A8 /* UnifiedSource12.cpp */,
+                               DE5F856A1FA1ABDB006DB63A /* UnifiedSource13-mm.mm */,
                                538EC7FD1F96AA74004D22A8 /* UnifiedSource13.cpp */,
+                               DE5F854E1FA1ABC2006DB63A /* UnifiedSource14-mm.mm */,
                                538EC7FC1F96AA73004D22A8 /* UnifiedSource14.cpp */,
+                               DE5F853E1FA1ABB3006DB63A /* UnifiedSource15-mm.mm */,
                                538EC7FF1F96AA77004D22A8 /* UnifiedSource15.cpp */,
+                               DE5F855E1FA1ABD0006DB63A /* UnifiedSource16-mm.mm */,
                                538EC7F71F96AA60004D22A8 /* UnifiedSource16.cpp */,
+                               DE5F854A1FA1ABBE006DB63A /* UnifiedSource17-mm.mm */,
                                538EC8011F96AA7A004D22A8 /* UnifiedSource17.cpp */,
+                               DE5F85501FA1ABC3006DB63A /* UnifiedSource18-mm.mm */,
                                538EC7FB1F96AA72004D22A8 /* UnifiedSource18.cpp */,
+                               DE5F85531FA1ABC6006DB63A /* UnifiedSource19-mm.mm */,
                                538EC7F91F96AA6E004D22A8 /* UnifiedSource19.cpp */,
+                               DE5F85521FA1ABC5006DB63A /* UnifiedSource20-mm.mm */,
                                538EC8001F96AA78004D22A8 /* UnifiedSource20.cpp */,
+                               DE5F855A1FA1ABCD006DB63A /* UnifiedSource21-mm.mm */,
                                538EC8351F993F0D004D22A8 /* UnifiedSource21.cpp */,
+                               DE5F854D1FA1ABC1006DB63A /* UnifiedSource22-mm.mm */,
                                538EC84A1F993F18004D22A8 /* UnifiedSource22.cpp */,
+                               DE5F85411FA1ABB6006DB63A /* UnifiedSource23-mm.mm */,
                                538EC82A1F993F07004D22A8 /* UnifiedSource23.cpp */,
+                               DE5F85461FA1ABBB006DB63A /* UnifiedSource24-mm.mm */,
                                538EC83F1F993F12004D22A8 /* UnifiedSource24.cpp */,
+                               DE5F85471FA1ABBB006DB63A /* UnifiedSource25-mm.mm */,
                                538EC83A1F993F10004D22A8 /* UnifiedSource25.cpp */,
+                               DE5F855D1FA1ABCF006DB63A /* UnifiedSource26-mm.mm */,
                                538EC84C1F993F19004D22A8 /* UnifiedSource26.cpp */,
+                               DE5F85691FA1ABDA006DB63A /* UnifiedSource27-mm.mm */,
                                538EC85F1F993F23004D22A8 /* UnifiedSource27.cpp */,
+                               DE5F853F1FA1ABB4006DB63A /* UnifiedSource28-mm.mm */,
                                538EC84B1F993F18004D22A8 /* UnifiedSource28.cpp */,
+                               DE5F85681FA1ABD9006DB63A /* UnifiedSource29-mm.mm */,
                                538EC8551F993F1E004D22A8 /* UnifiedSource29.cpp */,
+                               DE5F85421FA1ABB7006DB63A /* UnifiedSource30-mm.mm */,
                                538EC8761F993F2F004D22A8 /* UnifiedSource30.cpp */,
+                               DE5F85511FA1ABC4006DB63A /* UnifiedSource31-mm.mm */,
                                538EC85B1F993F21004D22A8 /* UnifiedSource31.cpp */,
+                               DE5F85601FA1ABD2006DB63A /* UnifiedSource32-mm.mm */,
                                538EC82B1F993F08004D22A8 /* UnifiedSource32.cpp */,
+                               DE5F855B1FA1ABCE006DB63A /* UnifiedSource33-mm.mm */,
                                538EC87F1F993F34004D22A8 /* UnifiedSource33.cpp */,
+                               DE5F85571FA1ABCA006DB63A /* UnifiedSource34-mm.mm */,
                                538EC8571F993F1F004D22A8 /* UnifiedSource34.cpp */,
+                               DE5F85401FA1ABB5006DB63A /* UnifiedSource35-mm.mm */,
                                538EC87A1F993F31004D22A8 /* UnifiedSource35.cpp */,
+                               DE5F85551FA1ABC8006DB63A /* UnifiedSource36-mm.mm */,
                                538EC8601F993F23004D22A8 /* UnifiedSource36.cpp */,
+                               DE5F85451FA1ABBA006DB63A /* UnifiedSource37-mm.mm */,
                                538EC8321F993F0C004D22A8 /* UnifiedSource37.cpp */,
+                               DE5F855C1FA1ABCE006DB63A /* UnifiedSource38-mm.mm */,
                                538EC87B1F993F32004D22A8 /* UnifiedSource38.cpp */,
+                               DE5F85591FA1ABCC006DB63A /* UnifiedSource39-mm.mm */,
                                538EC87C1F993F32004D22A8 /* UnifiedSource39.cpp */,
+                               DE5F85561FA1ABC9006DB63A /* UnifiedSource40-mm.mm */,
                                538EC8491F993F17004D22A8 /* UnifiedSource40.cpp */,
+                               DE5F85661FA1ABD7006DB63A /* UnifiedSource41-mm.mm */,
                                538EC84E1F993F1A004D22A8 /* UnifiedSource41.cpp */,
+                               DE5F854F1FA1ABC3006DB63A /* UnifiedSource42-mm.mm */,
                                538EC83B1F993F10004D22A8 /* UnifiedSource42.cpp */,
+                               DE5F85481FA1ABBC006DB63A /* UnifiedSource43-mm.mm */,
                                538EC8521F993F1C004D22A8 /* UnifiedSource43.cpp */,
+                               DE5F85431FA1ABB8006DB63A /* UnifiedSource44-mm.mm */,
                                538EC86A1F993F29004D22A8 /* UnifiedSource44.cpp */,
+                               DE5F85581FA1ABCB006DB63A /* UnifiedSource45-mm.mm */,
                                538EC83C1F993F11004D22A8 /* UnifiedSource45.cpp */,
+                               DE5F85441FA1ABB9006DB63A /* UnifiedSource46-mm.mm */,
                                538EC8771F993F30004D22A8 /* UnifiedSource46.cpp */,
+                               DE5F85621FA1ABD4006DB63A /* UnifiedSource47-mm.mm */,
                                538EC8681F993F28004D22A8 /* UnifiedSource47.cpp */,
+                               DE5F85671FA1ABD8006DB63A /* UnifiedSource48-mm.mm */,
                                538EC8431F993F14004D22A8 /* UnifiedSource48.cpp */,
+                               DE5F854B1FA1ABBF006DB63A /* UnifiedSource49-mm.mm */,
                                538EC87D1F993F33004D22A8 /* UnifiedSource49.cpp */,
+                               DE5F854C1FA1ABC0006DB63A /* UnifiedSource50-mm.mm */,
                                538EC8271F993F06004D22A8 /* UnifiedSource50.cpp */,
+                               DE5F86361FA2AF04006DB63A /* UnifiedSource51-mm.mm */,
                                538EC8471F993F16004D22A8 /* UnifiedSource51.cpp */,
+                               DE5F86371FA2AF05006DB63A /* UnifiedSource52-mm.mm */,
                                538EC8801F993F34004D22A8 /* UnifiedSource52.cpp */,
+                               DE5F86351FA2AF03006DB63A /* UnifiedSource53-mm.mm */,
                                538EC82C1F993F09004D22A8 /* UnifiedSource53.cpp */,
+                               DE5F86331FA2AF00006DB63A /* UnifiedSource54-mm.mm */,
                                538EC8691F993F28004D22A8 /* UnifiedSource54.cpp */,
+                               DE5F863B1FA2AF08006DB63A /* UnifiedSource55-mm.mm */,
                                538EC86C1F993F2A004D22A8 /* UnifiedSource55.cpp */,
+                               DE5F86341FA2AF01006DB63A /* UnifiedSource56-mm.mm */,
                                538EC8851F993F3A004D22A8 /* UnifiedSource56.cpp */,
+                               DE5F86381FA2AF06006DB63A /* UnifiedSource57-mm.mm */,
                                538EC8781F993F30004D22A8 /* UnifiedSource57.cpp */,
+                               DE5F86391FA2AF07006DB63A /* UnifiedSource58-mm.mm */,
                                538EC82F1F993F0A004D22A8 /* UnifiedSource58.cpp */,
+                               DE5F86321FA2AEFF006DB63A /* UnifiedSource59-mm.mm */,
                                538EC86B1F993F29004D22A8 /* UnifiedSource59.cpp */,
+                               DE5F863A1FA2AF07006DB63A /* UnifiedSource60-mm.mm */,
                                538EC8791F993F31004D22A8 /* UnifiedSource60.cpp */,
                                538EC87E1F993F33004D22A8 /* UnifiedSource61.cpp */,
                                538EC85A1F993F20004D22A8 /* UnifiedSource62.cpp */,
                                517A52F01F47535B00DCDC0A /* SWServer.h in Headers */,
                                8311C0031FAA2E9500E3C8E5 /* SWServerJobQueue.h in Headers */,
                                51F645971F4A686F00B54DED /* SWServerRegistration.h in Headers */,
+                               5185430B1FB6784500478F95 /* SWServerToContextConnection.h in Headers */,
                                517A53461F50C17F00DCDC0A /* SWServerWorker.h in Headers */,
                                E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */,
                                0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */,
                                BE88E0C11715CE2600658D98 /* TrackListBase.cpp in Sources */,
                                073BDC051F68436100EE34ED /* TrackPrivateBase.cpp in Sources */,
                                538EC8031F96AF81004D22A8 /* UnifiedSource1-mm.mm in Sources */,
-                               538EC8051F96AF81004D22A8 /* UnifiedSource2-mm.mm in Sources */,
-                               538EC8071F96AF81004D22A8 /* UnifiedSource3-mm.mm in Sources */,
-                               DE5F856C1FA1ABF3006DB63A /* UnifiedSource4-mm.mm in Sources */,
-                               DE5F856D1FA1ABF3006DB63A /* UnifiedSource5-mm.mm in Sources */,
-                               DE5F856E1FA1ABF3006DB63A /* UnifiedSource6-mm.mm in Sources */,
-                               DE5F856F1FA1ABF3006DB63A /* UnifiedSource7-mm.mm in Sources */,
-                               DE5F85701FA1ABF3006DB63A /* UnifiedSource8-mm.mm in Sources */,
-                               DE5F85711FA1ABF3006DB63A /* UnifiedSource9-mm.mm in Sources */,
-                               DE5F85721FA1ABF3006DB63A /* UnifiedSource10-mm.mm in Sources */,
-                               DE5F85731FA1ABF3006DB63A /* UnifiedSource11-mm.mm in Sources */,
-                               DE5F85741FA1ABF3006DB63A /* UnifiedSource12-mm.mm in Sources */,
-                               DE5F85751FA1ABF3006DB63A /* UnifiedSource13-mm.mm in Sources */,
-                               DE5F85761FA1ABF3006DB63A /* UnifiedSource14-mm.mm in Sources */,
-                               DE5F85771FA1ABF3006DB63A /* UnifiedSource15-mm.mm in Sources */,
-                               DE5F85781FA1ABF3006DB63A /* UnifiedSource16-mm.mm in Sources */,
-                               DE5F85791FA1ABF4006DB63A /* UnifiedSource17-mm.mm in Sources */,
-                               DE5F857A1FA1ABF4006DB63A /* UnifiedSource18-mm.mm in Sources */,
-                               DE5F857B1FA1ABF4006DB63A /* UnifiedSource19-mm.mm in Sources */,
-                               DE5F857C1FA1ABF4006DB63A /* UnifiedSource20-mm.mm in Sources */,
-                               DE5F857D1FA1ABF4006DB63A /* UnifiedSource21-mm.mm in Sources */,
-                               DE5F857E1FA1ABF4006DB63A /* UnifiedSource22-mm.mm in Sources */,
-                               DE5F857F1FA1ABF4006DB63A /* UnifiedSource23-mm.mm in Sources */,
-                               DE5F85801FA1ABF4006DB63A /* UnifiedSource24-mm.mm in Sources */,
-                               DE5F85811FA1ABF4006DB63A /* UnifiedSource25-mm.mm in Sources */,
-                               DE5F85821FA1ABF4006DB63A /* UnifiedSource26-mm.mm in Sources */,
-                               DE5F85831FA1ABF4006DB63A /* UnifiedSource27-mm.mm in Sources */,
-                               DE5F85841FA1ABF4006DB63A /* UnifiedSource28-mm.mm in Sources */,
-                               DE5F85851FA1ABF4006DB63A /* UnifiedSource29-mm.mm in Sources */,
-                               DE5F85861FA1ABF4006DB63A /* UnifiedSource30-mm.mm in Sources */,
-                               DE5F85871FA1ABF4006DB63A /* UnifiedSource31-mm.mm in Sources */,
-                               DE5F85881FA1ABF4006DB63A /* UnifiedSource32-mm.mm in Sources */,
-                               DE5F85891FA1ABF4006DB63A /* UnifiedSource33-mm.mm in Sources */,
-                               DE5F858A1FA1ABF4006DB63A /* UnifiedSource34-mm.mm in Sources */,
-                               DE5F858B1FA1ABF4006DB63A /* UnifiedSource35-mm.mm in Sources */,
-                               DE5F858C1FA1ABF4006DB63A /* UnifiedSource36-mm.mm in Sources */,
-                               DE5F858D1FA1ABF4006DB63A /* UnifiedSource37-mm.mm in Sources */,
-                               DE5F858E1FA1ABF4006DB63A /* UnifiedSource38-mm.mm in Sources */,
-                               DE5F858F1FA1ABF4006DB63A /* UnifiedSource39-mm.mm in Sources */,
-                               DE5F85901FA1ABF4006DB63A /* UnifiedSource40-mm.mm in Sources */,
-                               DE5F85911FA1ABF4006DB63A /* UnifiedSource41-mm.mm in Sources */,
-                               DE5F85921FA1ABF4006DB63A /* UnifiedSource42-mm.mm in Sources */,
-                               DE5F85931FA1ABF4006DB63A /* UnifiedSource43-mm.mm in Sources */,
-                               DE5F85941FA1ABF4006DB63A /* UnifiedSource44-mm.mm in Sources */,
-                               DE5F85951FA1ABF4006DB63A /* UnifiedSource45-mm.mm in Sources */,
-                               DE5F85961FA1ABF4006DB63A /* UnifiedSource46-mm.mm in Sources */,
-                               DE5F85971FA1ABF4006DB63A /* UnifiedSource47-mm.mm in Sources */,
-                               DE5F85981FA1ABF4006DB63A /* UnifiedSource48-mm.mm in Sources */,
-                               DE5F85991FA1ABF4006DB63A /* UnifiedSource49-mm.mm in Sources */,
-                               DE5F859A1FA1ABF4006DB63A /* UnifiedSource50-mm.mm in Sources */,
-                               DE5F86501FA2AF24006DB63A /* UnifiedSource51-mm.mm in Sources */,
-                               DE5F86511FA2AF24006DB63A /* UnifiedSource52-mm.mm in Sources */,
-                               DE5F86521FA2AF24006DB63A /* UnifiedSource53-mm.mm in Sources */,
-                               DE5F86531FA2AF24006DB63A /* UnifiedSource54-mm.mm in Sources */,
-                               DE5F86541FA2AF24006DB63A /* UnifiedSource55-mm.mm in Sources */,
-                               DE5F86551FA2AF24006DB63A /* UnifiedSource56-mm.mm in Sources */,
-                               DE5F86561FA2AF24006DB63A /* UnifiedSource57-mm.mm in Sources */,
-                               DE5F86571FA2AF24006DB63A /* UnifiedSource58-mm.mm in Sources */,
-                               DE5F86581FA2AF24006DB63A /* UnifiedSource59-mm.mm in Sources */,
-                               DE5F86591FA2AF24006DB63A /* UnifiedSource60-mm.mm in Sources */,
                                538EC8021F96AF81004D22A8 /* UnifiedSource1.cpp in Sources */,
+                               538EC8051F96AF81004D22A8 /* UnifiedSource2-mm.mm in Sources */,
                                538EC8041F96AF81004D22A8 /* UnifiedSource2.cpp in Sources */,
+                               538EC8071F96AF81004D22A8 /* UnifiedSource3-mm.mm in Sources */,
                                538EC8061F96AF81004D22A8 /* UnifiedSource3.cpp in Sources */,
+                               DE5F856C1FA1ABF3006DB63A /* UnifiedSource4-mm.mm in Sources */,
                                538EC8081F96AF81004D22A8 /* UnifiedSource4.cpp in Sources */,
+                               DE5F856D1FA1ABF3006DB63A /* UnifiedSource5-mm.mm in Sources */,
                                538EC8091F96AF81004D22A8 /* UnifiedSource5.cpp in Sources */,
+                               DE5F856E1FA1ABF3006DB63A /* UnifiedSource6-mm.mm in Sources */,
                                538EC80A1F96AF81004D22A8 /* UnifiedSource6.cpp in Sources */,
+                               DE5F856F1FA1ABF3006DB63A /* UnifiedSource7-mm.mm in Sources */,
                                538EC80B1F96AF81004D22A8 /* UnifiedSource7.cpp in Sources */,
+                               DE5F85701FA1ABF3006DB63A /* UnifiedSource8-mm.mm in Sources */,
                                538EC80C1F96AF81004D22A8 /* UnifiedSource8.cpp in Sources */,
+                               DE5F85711FA1ABF3006DB63A /* UnifiedSource9-mm.mm in Sources */,
                                538EC80D1F96AF81004D22A8 /* UnifiedSource9.cpp in Sources */,
+                               DE5F85721FA1ABF3006DB63A /* UnifiedSource10-mm.mm in Sources */,
                                538EC80E1F96AF81004D22A8 /* UnifiedSource10.cpp in Sources */,
+                               DE5F85731FA1ABF3006DB63A /* UnifiedSource11-mm.mm in Sources */,
                                538EC80F1F96AF81004D22A8 /* UnifiedSource11.cpp in Sources */,
+                               DE5F85741FA1ABF3006DB63A /* UnifiedSource12-mm.mm in Sources */,
                                538EC8101F96AF81004D22A8 /* UnifiedSource12.cpp in Sources */,
+                               DE5F85751FA1ABF3006DB63A /* UnifiedSource13-mm.mm in Sources */,
                                538EC8111F96AF81004D22A8 /* UnifiedSource13.cpp in Sources */,
+                               DE5F85761FA1ABF3006DB63A /* UnifiedSource14-mm.mm in Sources */,
                                538EC8121F96AF81004D22A8 /* UnifiedSource14.cpp in Sources */,
+                               DE5F85771FA1ABF3006DB63A /* UnifiedSource15-mm.mm in Sources */,
                                538EC8131F96AF81004D22A8 /* UnifiedSource15.cpp in Sources */,
+                               DE5F85781FA1ABF3006DB63A /* UnifiedSource16-mm.mm in Sources */,
                                538EC8141F96AF81004D22A8 /* UnifiedSource16.cpp in Sources */,
+                               DE5F85791FA1ABF4006DB63A /* UnifiedSource17-mm.mm in Sources */,
                                538EC8151F96AF81004D22A8 /* UnifiedSource17.cpp in Sources */,
+                               DE5F857A1FA1ABF4006DB63A /* UnifiedSource18-mm.mm in Sources */,
                                538EC8161F96AF81004D22A8 /* UnifiedSource18.cpp in Sources */,
+                               DE5F857B1FA1ABF4006DB63A /* UnifiedSource19-mm.mm in Sources */,
                                538EC8171F96AF81004D22A8 /* UnifiedSource19.cpp in Sources */,
+                               DE5F857C1FA1ABF4006DB63A /* UnifiedSource20-mm.mm in Sources */,
                                538EC8181F96AF81004D22A8 /* UnifiedSource20.cpp in Sources */,
+                               DE5F857D1FA1ABF4006DB63A /* UnifiedSource21-mm.mm in Sources */,
                                538EC8861F993F9C004D22A8 /* UnifiedSource21.cpp in Sources */,
+                               DE5F857E1FA1ABF4006DB63A /* UnifiedSource22-mm.mm in Sources */,
                                538EC8871F993F9C004D22A8 /* UnifiedSource22.cpp in Sources */,
+                               DE5F857F1FA1ABF4006DB63A /* UnifiedSource23-mm.mm in Sources */,
                                538EC8881F993F9C004D22A8 /* UnifiedSource23.cpp in Sources */,
+                               DE5F85801FA1ABF4006DB63A /* UnifiedSource24-mm.mm in Sources */,
                                538EC8891F993F9D004D22A8 /* UnifiedSource24.cpp in Sources */,
+                               DE5F85811FA1ABF4006DB63A /* UnifiedSource25-mm.mm in Sources */,
                                538EC88A1F993F9D004D22A8 /* UnifiedSource25.cpp in Sources */,
+                               DE5F85821FA1ABF4006DB63A /* UnifiedSource26-mm.mm in Sources */,
                                538EC88B1F993F9D004D22A8 /* UnifiedSource26.cpp in Sources */,
+                               DE5F85831FA1ABF4006DB63A /* UnifiedSource27-mm.mm in Sources */,
                                538EC88C1F993F9D004D22A8 /* UnifiedSource27.cpp in Sources */,
+                               DE5F85841FA1ABF4006DB63A /* UnifiedSource28-mm.mm in Sources */,
                                538EC88D1F993F9D004D22A8 /* UnifiedSource28.cpp in Sources */,
+                               DE5F85851FA1ABF4006DB63A /* UnifiedSource29-mm.mm in Sources */,
                                538EC88E1F993F9D004D22A8 /* UnifiedSource29.cpp in Sources */,
+                               DE5F85861FA1ABF4006DB63A /* UnifiedSource30-mm.mm in Sources */,
                                538EC88F1F993F9D004D22A8 /* UnifiedSource30.cpp in Sources */,
+                               DE5F85871FA1ABF4006DB63A /* UnifiedSource31-mm.mm in Sources */,
                                538EC8901F993F9D004D22A8 /* UnifiedSource31.cpp in Sources */,
+                               DE5F85881FA1ABF4006DB63A /* UnifiedSource32-mm.mm in Sources */,
                                538EC8911F993F9D004D22A8 /* UnifiedSource32.cpp in Sources */,
+                               DE5F85891FA1ABF4006DB63A /* UnifiedSource33-mm.mm in Sources */,
                                538EC8921F993F9D004D22A8 /* UnifiedSource33.cpp in Sources */,
+                               DE5F858A1FA1ABF4006DB63A /* UnifiedSource34-mm.mm in Sources */,
                                538EC8931F993F9D004D22A8 /* UnifiedSource34.cpp in Sources */,
+                               DE5F858B1FA1ABF4006DB63A /* UnifiedSource35-mm.mm in Sources */,
                                538EC8941F993F9D004D22A8 /* UnifiedSource35.cpp in Sources */,
+                               DE5F858C1FA1ABF4006DB63A /* UnifiedSource36-mm.mm in Sources */,
                                538EC8951F993F9D004D22A8 /* UnifiedSource36.cpp in Sources */,
+                               DE5F858D1FA1ABF4006DB63A /* UnifiedSource37-mm.mm in Sources */,
                                538EC8961F993F9D004D22A8 /* UnifiedSource37.cpp in Sources */,
+                               DE5F858E1FA1ABF4006DB63A /* UnifiedSource38-mm.mm in Sources */,
                                538EC8971F993F9D004D22A8 /* UnifiedSource38.cpp in Sources */,
+                               DE5F858F1FA1ABF4006DB63A /* UnifiedSource39-mm.mm in Sources */,
                                538EC8981F993F9D004D22A8 /* UnifiedSource39.cpp in Sources */,
+                               DE5F85901FA1ABF4006DB63A /* UnifiedSource40-mm.mm in Sources */,
                                538EC8991F993F9D004D22A8 /* UnifiedSource40.cpp in Sources */,
+                               DE5F85911FA1ABF4006DB63A /* UnifiedSource41-mm.mm in Sources */,
                                538EC89A1F993F9D004D22A8 /* UnifiedSource41.cpp in Sources */,
+                               DE5F85921FA1ABF4006DB63A /* UnifiedSource42-mm.mm in Sources */,
                                538EC89B1F993F9D004D22A8 /* UnifiedSource42.cpp in Sources */,
+                               DE5F85931FA1ABF4006DB63A /* UnifiedSource43-mm.mm in Sources */,
                                538EC89C1F993F9D004D22A8 /* UnifiedSource43.cpp in Sources */,
+                               DE5F85941FA1ABF4006DB63A /* UnifiedSource44-mm.mm in Sources */,
                                538EC89D1F993F9D004D22A8 /* UnifiedSource44.cpp in Sources */,
+                               DE5F85951FA1ABF4006DB63A /* UnifiedSource45-mm.mm in Sources */,
                                538EC89E1F993F9D004D22A8 /* UnifiedSource45.cpp in Sources */,
+                               DE5F85961FA1ABF4006DB63A /* UnifiedSource46-mm.mm in Sources */,
                                538EC89F1F993F9D004D22A8 /* UnifiedSource46.cpp in Sources */,
+                               DE5F85971FA1ABF4006DB63A /* UnifiedSource47-mm.mm in Sources */,
                                538EC8A01F993F9D004D22A8 /* UnifiedSource47.cpp in Sources */,
+                               DE5F85981FA1ABF4006DB63A /* UnifiedSource48-mm.mm in Sources */,
                                538EC8A11F993F9D004D22A8 /* UnifiedSource48.cpp in Sources */,
+                               DE5F85991FA1ABF4006DB63A /* UnifiedSource49-mm.mm in Sources */,
                                538EC8A21F993F9D004D22A8 /* UnifiedSource49.cpp in Sources */,
+                               DE5F859A1FA1ABF4006DB63A /* UnifiedSource50-mm.mm in Sources */,
                                538EC8A31F993F9D004D22A8 /* UnifiedSource50.cpp in Sources */,
+                               DE5F86501FA2AF24006DB63A /* UnifiedSource51-mm.mm in Sources */,
                                538EC8A41F993F9D004D22A8 /* UnifiedSource51.cpp in Sources */,
+                               DE5F86511FA2AF24006DB63A /* UnifiedSource52-mm.mm in Sources */,
                                538EC8A51F993F9D004D22A8 /* UnifiedSource52.cpp in Sources */,
+                               DE5F86521FA2AF24006DB63A /* UnifiedSource53-mm.mm in Sources */,
                                538EC8A61F993F9D004D22A8 /* UnifiedSource53.cpp in Sources */,
+                               DE5F86531FA2AF24006DB63A /* UnifiedSource54-mm.mm in Sources */,
                                538EC8A71F993F9D004D22A8 /* UnifiedSource54.cpp in Sources */,
+                               DE5F86541FA2AF24006DB63A /* UnifiedSource55-mm.mm in Sources */,
                                538EC8A81F993F9D004D22A8 /* UnifiedSource55.cpp in Sources */,
+                               DE5F86551FA2AF24006DB63A /* UnifiedSource56-mm.mm in Sources */,
                                538EC8A91F993F9D004D22A8 /* UnifiedSource56.cpp in Sources */,
+                               DE5F86561FA2AF24006DB63A /* UnifiedSource57-mm.mm in Sources */,
                                538EC8AA1F993F9D004D22A8 /* UnifiedSource57.cpp in Sources */,
+                               DE5F86571FA2AF24006DB63A /* UnifiedSource58-mm.mm in Sources */,
                                538EC8AB1F993F9D004D22A8 /* UnifiedSource58.cpp in Sources */,
+                               DE5F86581FA2AF24006DB63A /* UnifiedSource59-mm.mm in Sources */,
                                538EC8AC1F993F9D004D22A8 /* UnifiedSource59.cpp in Sources */,
+                               DE5F86591FA2AF24006DB63A /* UnifiedSource60-mm.mm in Sources */,
                                538EC8AD1F993F9D004D22A8 /* UnifiedSource60.cpp in Sources */,
                                538EC8AE1F993F9D004D22A8 /* UnifiedSource61.cpp in Sources */,
                                538EC8AF1F993F9D004D22A8 /* UnifiedSource62.cpp in Sources */,
index 4d33501..f0ec766 100644 (file)
@@ -32,7 +32,7 @@ namespace WebCore {
 
 ServiceWorkerContextData ServiceWorkerContextData::isolatedCopy() const
 {
-    return { registrationKey.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), scriptURL.isolatedCopy() };
+    return { registrationKey.isolatedCopy(), serviceWorkerIdentifier, script.isolatedCopy(), scriptURL.isolatedCopy(), workerType };
 }
 
 } // namespace WebCore
index 08c31bc..b7d66f1 100644 (file)
@@ -28,6 +28,7 @@
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerRegistrationKey.h"
 #include "URL.h"
+#include "WorkerType.h"
 
 #if ENABLE(SERVICE_WORKER)
 
@@ -38,6 +39,7 @@ struct ServiceWorkerContextData {
     ServiceWorkerIdentifier serviceWorkerIdentifier;
     String script;
     URL scriptURL;
+    WorkerType workerType;
     
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<ServiceWorkerContextData> decode(Decoder&);
@@ -48,7 +50,7 @@ struct ServiceWorkerContextData {
 template<class Encoder>
 void ServiceWorkerContextData::encode(Encoder& encoder) const
 {
-    encoder << registrationKey << serviceWorkerIdentifier << script << scriptURL;
+    encoder << registrationKey << serviceWorkerIdentifier << script << scriptURL << workerType;
 }
 
 template<class Decoder>
@@ -69,8 +71,12 @@ std::optional<ServiceWorkerContextData> ServiceWorkerContextData::decode(Decoder
     URL scriptURL;
     if (!decoder.decode(scriptURL))
         return std::nullopt;
-
-    return {{ WTFMove(*registrationKey), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(scriptURL) }};
+    
+    WorkerType workerType;
+    if (!decoder.decodeEnum(workerType))
+        return std::nullopt;
+    
+    return {{ WTFMove(*registrationKey), WTFMove(*serviceWorkerIdentifier), WTFMove(script), WTFMove(scriptURL), workerType }};
 }
 
 } // namespace WebCore
index 4bf19d8..3a20b3a 100644 (file)
@@ -33,9 +33,8 @@
 
 namespace WebCore {
 
-ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, const URL& url, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread& thread, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, PAL::SessionID sessionID)
+ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const ServiceWorkerContextData& data, const URL& url, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread& thread, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, PAL::SessionID sessionID)
     : WorkerGlobalScope(url, identifier, userAgent, isOnline, thread, shouldBypassMainWorldContentSecurityPolicy, WTFMove(topOrigin), timeOrigin, connectionProxy, socketProvider, sessionID)
-    , m_serverConnectionIdentifier(serverConnectionIdentifier)
     , m_contextData(crossThreadCopy(data))
     , m_clients(ServiceWorkerClients::create(*this))
 {
index ee49586..9001517 100644 (file)
@@ -51,8 +51,6 @@ public:
     ServiceWorkerClients& clients() { return m_clients.get(); }
     ServiceWorkerRegistration* registration();
     
-    uint64_t serverConnectionIdentifier() const { return m_serverConnectionIdentifier; }
-
     void skipWaiting(Ref<DeferredPromise>&&);
 
     EventTargetInterface eventTargetInterface() const final;
@@ -60,9 +58,8 @@ public:
     ServiceWorkerThread& thread();
 
 private:
-    ServiceWorkerGlobalScope(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, const URL&, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, PAL::SessionID);
+    ServiceWorkerGlobalScope(const ServiceWorkerContextData&, const URL&, const String& identifier, const String& userAgent, bool isOnline, ServiceWorkerThread&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, PAL::SessionID);
 
-    uint64_t m_serverConnectionIdentifier;
     ServiceWorkerContextData m_contextData;
     Ref<ServiceWorkerClients> m_clients;
 };
index a3c6c3e..c70ae08 100644 (file)
@@ -50,6 +50,9 @@ enum class ShouldNotifyWhenResolved { No, Yes };
 enum ServiceWorkerRegistrationIdentifierType { };
 using ServiceWorkerRegistrationIdentifier = ObjectIdentifier<ServiceWorkerRegistrationIdentifierType>;
 
+enum SWServerToContextConnectionIdentifierType { };
+using SWServerToContextConnectionIdentifier = ObjectIdentifier<SWServerToContextConnectionIdentifierType>;
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)
index 6338e4e..23c6bb6 100644 (file)
@@ -73,9 +73,8 @@ private:
 // FIXME: Use a valid isOnline flag
 // FIXME: Use valid runtime flags
 
-ServiceWorkerThread::ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy)
+ServiceWorkerThread::ServiceWorkerThread(const ServiceWorkerContextData& data, PAL::SessionID, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy)
     : WorkerThread(data.scriptURL, "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), ASCIILiteral("WorkerUserAgent"), /* isOnline */ false, data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, ContentSecurityPolicyResponseHeaders { }, false, SecurityOrigin::create(data.scriptURL).get(), MonotonicTime::now(), nullptr, nullptr, JSC::RuntimeFlags::createAllEnabled(), SessionID::defaultSessionID())
-    , m_serverConnectionIdentifier(serverConnectionIdentifier)
     , m_data(data.isolatedCopy())
     , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
 {
@@ -86,7 +85,7 @@ ServiceWorkerThread::~ServiceWorkerThread() = default;
 
 Ref<WorkerGlobalScope> ServiceWorkerThread::createWorkerGlobalScope(const URL& url, const String& identifier, const String& userAgent, bool isOnline, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, PAL::SessionID sessionID)
 {
-    return ServiceWorkerGlobalScope::create(m_serverConnectionIdentifier, m_data, url, identifier, userAgent, isOnline, *this, shouldBypassMainWorldContentSecurityPolicy, WTFMove(topOrigin), timeOrigin, idbConnectionProxy(), socketProvider(), sessionID);
+    return ServiceWorkerGlobalScope::create(m_data, url, identifier, userAgent, isOnline, *this, shouldBypassMainWorldContentSecurityPolicy, WTFMove(topOrigin), timeOrigin, idbConnectionProxy(), socketProvider(), sessionID);
 }
 
 void ServiceWorkerThread::runEventLoop()
index 73decd5..84a8e3b 100644 (file)
@@ -60,7 +60,6 @@ public:
     void fireInstallEvent();
     void fireActivateEvent();
 
-    uint64_t serverConnectionIdentifier() const { return m_serverConnectionIdentifier; }
     const ServiceWorkerContextData& contextData() const { return m_data; }
 
     ServiceWorkerIdentifier identifier() const { return m_data.serviceWorkerIdentifier; }
@@ -70,12 +69,11 @@ protected:
     void runEventLoop() override;
 
 private:
-    WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, WorkerLoaderProxy&, WorkerDebuggerProxy&);
+    WEBCORE_EXPORT ServiceWorkerThread(const ServiceWorkerContextData&, PAL::SessionID, WorkerLoaderProxy&, WorkerDebuggerProxy&);
 
     void updateExtendedEventsSet(ExtendableEvent* newEvent = nullptr);
     bool hasPendingEvents() const { return !m_extendedEvents.isEmpty(); }
 
-    uint64_t m_serverConnectionIdentifier;
     ServiceWorkerContextData m_data;
     WorkerObjectProxy& m_workerObjectProxy;
     Vector<Ref<ExtendableEvent>> m_extendedEvents;
index 821dcea..0f57b09 100644 (file)
 
 namespace WebCore {
 
-Ref<ServiceWorkerThreadProxy> ServiceWorkerThreadProxy::create(PageConfiguration&& pageConfiguration, uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID sessionID, CacheStorageProvider& cacheStorageProvider)
-{
-    return adoptRef(*new ServiceWorkerThreadProxy { WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, cacheStorageProvider });
-}
-
 static inline UniqueRef<Page> createPageForServiceWorker(PageConfiguration&& configuration, const URL& url)
 {
     auto page = makeUniqueRef<Page>(WTFMove(configuration));
@@ -52,10 +47,10 @@ static inline UniqueRef<Page> createPageForServiceWorker(PageConfiguration&& con
     return page;
 }
 
-ServiceWorkerThreadProxy::ServiceWorkerThreadProxy(PageConfiguration&& pageConfiguration, uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID sessionID, CacheStorageProvider& cacheStorageProvider)
+ServiceWorkerThreadProxy::ServiceWorkerThreadProxy(PageConfiguration&& pageConfiguration, const ServiceWorkerContextData& data, PAL::SessionID sessionID, CacheStorageProvider& cacheStorageProvider)
     : m_page(createPageForServiceWorker(WTFMove(pageConfiguration), data.scriptURL))
     , m_document(*m_page->mainFrame().document())
-    , m_serviceWorkerThread(ServiceWorkerThread::create(serverConnectionIdentifier, data, sessionID, *this, *this))
+    , m_serviceWorkerThread(ServiceWorkerThread::create(data, sessionID, *this, *this))
     , m_cacheStorageProvider(cacheStorageProvider)
     , m_sessionID(sessionID)
     , m_inspectorProxy(*this)
index b998856..1272b24 100644 (file)
@@ -47,14 +47,17 @@ struct ServiceWorkerContextData;
 
 class ServiceWorkerThreadProxy final : public ThreadSafeRefCounted<ServiceWorkerThreadProxy>, public WorkerLoaderProxy, public WorkerDebuggerProxy {
 public:
-    WEBCORE_EXPORT static Ref<ServiceWorkerThreadProxy> create(PageConfiguration&&, uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&);
+    template<typename... Args> static Ref<ServiceWorkerThreadProxy> create(Args&&... args)
+    {
+        return adoptRef(*new ServiceWorkerThreadProxy(std::forward<Args>(args)...));
+    }
 
     ServiceWorkerIdentifier identifier() const { return m_serviceWorkerThread->identifier(); }
     ServiceWorkerThread& thread() { return m_serviceWorkerThread.get(); }
     ServiceWorkerInspectorProxy& inspectorProxy() { return m_inspectorProxy; }
 
 private:
-    ServiceWorkerThreadProxy(PageConfiguration&&, uint64_t serverConnectionIdentifier, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&);
+    WEBCORE_EXPORT ServiceWorkerThreadProxy(PageConfiguration&&, const ServiceWorkerContextData&, PAL::SessionID, CacheStorageProvider&);
 
     // WorkerLoaderProxy
     bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
index b90b8b6..d6d1342 100644 (file)
 #include "SWOriginStore.h"
 #include "SWServerJobQueue.h"
 #include "SWServerRegistration.h"
+#include "SWServerToContextConnection.h"
 #include "SWServerWorker.h"
 #include "SecurityOrigin.h"
 #include "ServiceWorkerContextData.h"
 #include "ServiceWorkerFetchResult.h"
 #include "ServiceWorkerJobData.h"
+#include <wtf/NeverDestroyed.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
 static ServiceWorkerIdentifier generateServiceWorkerIdentifier()
 {
-    static uint64_t identifier = 0;
-    return makeObjectIdentifier<ServiceWorkerIdentifierType>(++identifier);
+    return generateObjectIdentifier<ServiceWorkerIdentifierType>();
 }
 
 SWServer::Connection::Connection(SWServer& server, uint64_t identifier)
@@ -61,6 +62,12 @@ SWServer::Connection::~Connection()
     m_server.unregisterConnection(*this);
 }
 
+HashSet<SWServer*>& SWServer::allServers()
+{
+    static NeverDestroyed<HashSet<SWServer*>> servers;
+    return servers;
+}
+
 SWServer::~SWServer()
 {
     RELEASE_ASSERT(m_connections.isEmpty());
@@ -75,6 +82,8 @@ SWServer::~SWServer()
     // But once it does start happening, this ASSERT will catch us doing it wrong.
     Locker<Lock> locker(m_taskThreadLock);
     ASSERT(!m_taskThread);
+    
+    allServers().remove(this);
 }
 
 SWServerRegistration* SWServer::getRegistration(const ServiceWorkerRegistrationKey& registrationKey)
@@ -128,21 +137,6 @@ void SWServer::Connection::finishFetchingScriptInServer(const ServiceWorkerFetch
     m_server.scriptFetchFinished(*this, result);
 }
 
-void SWServer::Connection::didFinishInstall(const ServiceWorkerRegistrationKey& key, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
-{
-    m_server.didFinishInstall(*this, key, serviceWorkerIdentifier, wasSuccessful);
-}
-
-void SWServer::Connection::didFinishActivation(const ServiceWorkerRegistrationKey& key, ServiceWorkerIdentifier serviceWorkerIdentifier)
-{
-    m_server.didFinishActivation(*this, key, serviceWorkerIdentifier);
-}
-
-void SWServer::Connection::setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents)
-{
-    m_server.setServiceWorkerHasPendingEvents(*this, serviceWorkerIdentifier, hasPendingEvents);
-}
-
 void SWServer::Connection::didResolveRegistrationPromise(const ServiceWorkerRegistrationKey& key)
 {
     m_server.didResolveRegistrationPromise(*this, key);
@@ -158,19 +152,10 @@ void SWServer::Connection::removeServiceWorkerRegistrationInServer(const Service
     m_server.removeClientServiceWorkerRegistration(*this, key, identifier);
 }
 
-void SWServer::Connection::scriptContextFailedToStart(const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier identifier, const String& message)
-{
-    m_server.scriptContextFailedToStart(*this, registrationKey, identifier, message);
-}
-
-void SWServer::Connection::scriptContextStarted(const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier identifier)
-{
-    m_server.scriptContextStarted(*this, registrationKey, identifier);
-}
-
 SWServer::SWServer(UniqueRef<SWOriginStore>&& originStore)
     : m_originStore(WTFMove(originStore))
 {
+    allServers().add(this);
     m_taskThread = Thread::create(ASCIILiteral("ServiceWorker Task Thread"), [this] {
         taskThreadEntryPoint();
     });
@@ -245,52 +230,36 @@ void SWServer::scriptFetchFinished(Connection& connection, const ServiceWorkerFe
     jobQueue->scriptFetchFinished(connection, result);
 }
 
-void SWServer::scriptContextFailedToStart(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier identifier, const String& message)
+void SWServer::scriptContextFailedToStart(SWServerWorker& worker, const String& message)
 {
-    ASSERT(m_connections.contains(connection.identifier()));
-    
-    if (auto* jobQueue = m_jobQueues.get(registrationKey))
-        jobQueue->scriptContextFailedToStart(connection, identifier, message);
+    if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
+        jobQueue->scriptContextFailedToStart(worker.identifier(), message);
 }
 
-void SWServer::scriptContextStarted(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier identifier)
+void SWServer::scriptContextStarted(SWServerWorker& worker)
 {
-    ASSERT(m_connections.contains(connection.identifier()));
-
-    if (auto* jobQueue = m_jobQueues.get(registrationKey))
-        jobQueue->scriptContextStarted(connection, identifier);
-}
-
-void SWServer::didFinishInstall(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
-{
-    ASSERT(m_connections.contains(connection.identifier()));
-
-    if (auto* jobQueue = m_jobQueues.get(registrationKey))
-        jobQueue->didFinishInstall(connection, serviceWorkerIdentifier, wasSuccessful);
+    if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
+        jobQueue->scriptContextStarted(worker.identifier());
 }
 
-void SWServer::didFinishActivation(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier serviceWorkerIdentifier)
+void SWServer::didFinishInstall(SWServerWorker& worker, bool wasSuccessful)
 {
-    ASSERT_UNUSED(connection, m_connections.contains(connection.identifier()));
-
-    if (auto* registration = getRegistration(registrationKey))
-        SWServerJobQueue::didFinishActivation(*registration, serviceWorkerIdentifier);
+    if (auto* jobQueue = m_jobQueues.get(worker.registrationKey()))
+        jobQueue->didFinishInstall(worker.identifier(), wasSuccessful);
 }
 
-void SWServer::setServiceWorkerHasPendingEvents(Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents)
+void SWServer::didFinishActivation(SWServerWorker& worker)
 {
-    ASSERT_UNUSED(connection, m_connections.contains(connection.identifier()));
-
-    if (auto* serviceWorker = m_workersByID.get(serviceWorkerIdentifier))
-        serviceWorker->setHasPendingEvents(hasPendingEvents);
+    if (auto* registration = getRegistration(worker.registrationKey()))
+        SWServerJobQueue::didFinishActivation(*registration, worker.identifier());
 }
 
 void SWServer::didResolveRegistrationPromise(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey)
 {
-    ASSERT(m_connections.contains(connection.identifier()));
+    ASSERT_UNUSED(connection, m_connections.contains(connection.identifier()));
 
     if (auto* jobQueue = m_jobQueues.get(registrationKey))
-        jobQueue->didResolveRegistrationPromise(connection);
+        jobQueue->didResolveRegistrationPromise();
 }
 
 void SWServer::addClientServiceWorkerRegistration(Connection& connection, const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationIdentifier identifier)
@@ -321,26 +290,75 @@ void SWServer::removeClientServiceWorkerRegistration(Connection& connection, con
     registration->removeClientServiceWorkerRegistration(connection.identifier());
 }
 
-Ref<SWServerWorker> SWServer::updateWorker(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type)
+void SWServer::updateWorker(Connection&, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type)
 {
     auto serviceWorkerIdentifier = generateServiceWorkerIdentifier();
 
-    auto result = m_workersByID.add(serviceWorkerIdentifier, SWServerWorker::create(registrationKey, url, script, type, serviceWorkerIdentifier));
-    ASSERT(result.isNewEntry);
+    ServiceWorkerContextData data = { registrationKey, serviceWorkerIdentifier, script, url, type };
 
-    connection.installServiceWorkerContext({ registrationKey, serviceWorkerIdentifier, script, url });
+    // Right now we only ever keep up to one connection to one SW context process.
+    // And it should always exist if we're calling updateWorker
+    auto* connection = SWServerToContextConnection::globalServerToContextConnection();
+    if (!connection) {
+        m_pendingContextDatas.append(WTFMove(data));
+        return;
+    }
     
-    return result.iterator->value.get();
+    installContextData(data);
 }
 
-void SWServer::fireInstallEvent(Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier)
+void SWServer::serverToContextConnectionCreated()
 {
-    connection.fireInstallEvent(serviceWorkerIdentifier);
+    ASSERT(SWServerToContextConnection::globalServerToContextConnection());
+    for (auto& data : m_pendingContextDatas)
+        installContextData(data);
+    
+    m_pendingContextDatas.clear();
 }
 
-void SWServer::fireActivateEvent(Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier)
+void SWServer::installContextData(const ServiceWorkerContextData& data)
 {
-    connection.fireActivateEvent(serviceWorkerIdentifier);
+    auto* connection = SWServerToContextConnection::globalServerToContextConnection();
+    ASSERT(connection);
+
+    auto result = m_workersByID.add(data.serviceWorkerIdentifier, SWServerWorker::create(*this, data.registrationKey, connection->identifier(), data.scriptURL, data.script, data.workerType, data.serviceWorkerIdentifier));
+    ASSERT_UNUSED(result, result.isNewEntry);
+
+    connection->installServiceWorkerContext(data);
+}
+
+void SWServer::fireInstallEvent(SWServerWorker& worker)
+{
+//    auto* worker = m_workersByID.get(serviceWorkerIdentifier);
+//    if (!worker) {
+//        LOG_ERROR("Request to fire install event on a worker that cannot be found in the server");
+//        return;
+//    }
+
+    auto* connection = SWServerToContextConnection::connectionForIdentifier(worker.contextConnectionIdentifier());
+    if (!connection) {
+        LOG_ERROR("Request to fire install event on a worker whose context connection does not exist");
+        return;
+    }
+
+    connection->fireInstallEvent(worker.identifier());
+}
+
+void SWServer::fireActivateEvent(SWServerWorker& worker)
+{
+//    auto* worker = m_workersByID.get(serviceWorkerIdentifier);
+//    if (!worker) {
+//        LOG_ERROR("Request to fire install event on a worker that cannot be found in the server");
+//        return;
+//    }
+
+    auto* connection = SWServerToContextConnection::connectionForIdentifier(worker.contextConnectionIdentifier());
+    if (!connection) {
+        LOG_ERROR("Request to fire install event on a worker whose context connection does not exist");
+        return;
+    }
+
+    connection->fireActivateEvent(worker.identifier());
 }
 
 void SWServer::taskThreadEntryPoint()
index bca3865..838c7e5 100644 (file)
@@ -32,6 +32,7 @@
 #include "ServiceWorkerJob.h"
 #include "ServiceWorkerRegistrationData.h"
 #include "ServiceWorkerRegistrationKey.h"
+#include "ServiceWorkerTypes.h"
 #include <wtf/CrossThreadQueue.h>
 #include <wtf/CrossThreadTask.h>
 #include <wtf/HashMap.h>
@@ -47,6 +48,7 @@ namespace WebCore {
 class SWOriginStore;
 class SWServerJobQueue;
 class SWServerRegistration;
+class SWServerToContextConnection;
 enum class ServiceWorkerRegistrationState;
 enum class ServiceWorkerState;
 struct ExceptionData;
@@ -61,11 +63,6 @@ public:
     public:
         WEBCORE_EXPORT virtual ~Connection();
 
-        WEBCORE_EXPORT void scriptContextFailedToStart(const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier, const String& message);
-        WEBCORE_EXPORT void scriptContextStarted(const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier);
-        WEBCORE_EXPORT void didFinishInstall(const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier, bool wasSuccessful);
-        WEBCORE_EXPORT void didFinishActivation(const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier);
-        WEBCORE_EXPORT void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool hasPendingEvents);
         WEBCORE_EXPORT void didResolveRegistrationPromise(const ServiceWorkerRegistrationKey&);
         const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const { return m_server.doRegistrationMatching(topOrigin, clientURL); }
 
@@ -90,11 +87,6 @@ public:
         virtual void resolveUnregistrationJobInClient(uint64_t jobIdentifier, const ServiceWorkerRegistrationKey&, bool registrationResult) = 0;
         virtual void startScriptFetchInClient(uint64_t jobIdentifier) = 0;
 
-        // Messages to the SW host WebProcess
-        virtual void installServiceWorkerContext(const ServiceWorkerContextData&) = 0;
-        virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
-        virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
-
         SWServer& m_server;
     };
 
@@ -118,14 +110,23 @@ public:
     void postTask(CrossThreadTask&&);
     void postTaskReply(CrossThreadTask&&);
 
-    Ref<SWServerWorker> updateWorker(Connection&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);
-    void fireInstallEvent(Connection&, ServiceWorkerIdentifier);
-    void fireActivateEvent(Connection&, ServiceWorkerIdentifier);
+    void updateWorker(Connection&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);
+    void fireInstallEvent(SWServerWorker&);
+    void fireActivateEvent(SWServerWorker&);
     SWServerWorker* workerByID(ServiceWorkerIdentifier identifier) const { return m_workersByID.get(identifier); }
     
     Connection* getConnection(uint64_t identifier) { return m_connections.get(identifier); }
     SWOriginStore& originStore() { return m_originStore; }
 
+    void scriptContextFailedToStart(SWServerWorker&, const String& message);
+    void scriptContextStarted(SWServerWorker&);
+    void didFinishInstall(SWServerWorker&, bool wasSuccessful);
+    void didFinishActivation(SWServerWorker&);
+
+    WEBCORE_EXPORT void serverToContextConnectionCreated();
+    
+    WEBCORE_EXPORT static HashSet<SWServer*>& allServers();
+
 private:
     void registerConnection(Connection&);
     void unregisterConnection(Connection&);
@@ -134,11 +135,7 @@ private:
     void handleTaskRepliesOnMainThread();
 
     void scriptFetchFinished(Connection&, const ServiceWorkerFetchResult&);
-    void scriptContextFailedToStart(Connection&, const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier, const String& message);
-    void scriptContextStarted(Connection&, const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier);
-    void didFinishInstall(Connection&, const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier, bool wasSuccessful);
-    void didFinishActivation(Connection&, const ServiceWorkerRegistrationKey&, ServiceWorkerIdentifier);
-    void setServiceWorkerHasPendingEvents(Connection&, ServiceWorkerIdentifier, bool hasPendingEvents);
+
     void didResolveRegistrationPromise(Connection&, const ServiceWorkerRegistrationKey&);
 
     void addClientServiceWorkerRegistration(Connection&, const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationIdentifier);
@@ -146,6 +143,8 @@ private:
 
     WEBCORE_EXPORT const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const;
 
+    void installContextData(const ServiceWorkerContextData&);
+
     HashMap<uint64_t, Connection*> m_connections;
     HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerRegistration>> m_registrations;
     HashMap<ServiceWorkerRegistrationKey, std::unique_ptr<SWServerJobQueue>> m_jobQueues;
@@ -161,6 +160,7 @@ private:
     Lock m_mainThreadReplyLock;
     bool m_mainThreadReplyScheduled { false };
     UniqueRef<SWOriginStore> m_originStore;
+    Deque<ServiceWorkerContextData> m_pendingContextDatas;
 };
 
 } // namespace WebCore
index f849ab8..9fefa12 100644 (file)
@@ -84,7 +84,7 @@ void SWServerJobQueue::scriptFetchFinished(SWServer::Connection& connection, con
 }
 
 // https://w3c.github.io/ServiceWorker/#update-algorithm
-void SWServerJobQueue::scriptContextFailedToStart(SWServer::Connection&, ServiceWorkerIdentifier, const String& message)
+void SWServerJobQueue::scriptContextFailedToStart(ServiceWorkerIdentifier, const String& message)
 {
     // If an uncaught runtime script error occurs during the above step, then:
     auto* registration = m_server.getRegistration(m_registrationKey);
@@ -101,16 +101,16 @@ void SWServerJobQueue::scriptContextFailedToStart(SWServer::Connection&, Service
     finishCurrentJob();
 }
 
-void SWServerJobQueue::scriptContextStarted(SWServer::Connection& connection, ServiceWorkerIdentifier identifier)
+void SWServerJobQueue::scriptContextStarted(ServiceWorkerIdentifier identifier)
 {
     auto* registration = m_server.getRegistration(m_registrationKey);
     ASSERT(registration);
 
-    install(*registration, connection, identifier);
+    install(*registration, identifier);
 }
 
 // https://w3c.github.io/ServiceWorker/#install
-void SWServerJobQueue::install(SWServerRegistration& registration, SWServer::Connection&, ServiceWorkerIdentifier installingWorker)
+void SWServerJobQueue::install(SWServerRegistration& registration, ServiceWorkerIdentifier installingWorker)
 {
     // The Install algorithm should never be invoked with a null worker.
     auto* worker = m_server.workerByID(installingWorker);
@@ -124,7 +124,7 @@ void SWServerJobQueue::install(SWServerRegistration& registration, SWServer::Con
 }
 
 // https://w3c.github.io/ServiceWorker/#install (after resolving promise).
-void SWServerJobQueue::didResolveRegistrationPromise(SWServer::Connection& connection)
+void SWServerJobQueue::didResolveRegistrationPromise()
 {
     auto* registration = m_server.getRegistration(m_registrationKey);
     ASSERT(registration);
@@ -136,11 +136,12 @@ void SWServerJobQueue::didResolveRegistrationPromise(SWServer::Connection& conne
     registration->fireUpdateFoundEvent();
 
     // Queue a task to fire the InstallEvent.
-    m_server.fireInstallEvent(connection, registration->installingWorker()->identifier());
+    ASSERT(registration->installingWorker());
+    m_server.fireInstallEvent(*registration->installingWorker());
 }
 
 // https://w3c.github.io/ServiceWorker/#install
-void SWServerJobQueue::didFinishInstall(SWServer::Connection& connection, ServiceWorkerIdentifier identifier, bool wasSuccessful)
+void SWServerJobQueue::didFinishInstall(ServiceWorkerIdentifier identifier, bool wasSuccessful)
 {
     auto* registration = m_server.getRegistration(m_registrationKey);
     ASSERT(registration);
@@ -179,11 +180,11 @@ void SWServerJobQueue::didFinishInstall(SWServer::Connection& connection, Servic
     finishCurrentJob();
 
     // FIXME: Wait for all the tasks queued by Update Worker State invoked in this algorithm have executed.
-    tryActivate(m_server, connection, *registration);
+    tryActivate(m_server, *registration);
 }
 
 // https://w3c.github.io/ServiceWorker/#try-activate-algorithm
-void SWServerJobQueue::tryActivate(SWServer& server, SWServer::Connection& connection, SWServerRegistration& registration)
+void SWServerJobQueue::tryActivate(SWServer& server, SWServerRegistration& registration)
 {
     // If registration's waiting worker is null, return.
     if (!registration.waitingWorker())
@@ -198,11 +199,11 @@ void SWServerJobQueue::tryActivate(SWServer& server, SWServer::Connection& conne
     //   and no service worker client is using registration
     // FIXME: Check for the skip waiting flag.
     if (!registration.activeWorker() || !registration.activeWorker()->hasPendingEvents())
-        activate(server, connection, registration);
+        activate(server, registration);
 }
 
 // https://w3c.github.io/ServiceWorker/#activate
-void SWServerJobQueue::activate(SWServer& server, SWServer::Connection& connection, SWServerRegistration& registration)
+void SWServerJobQueue::activate(SWServer& server, SWServerRegistration& registration)
 {
     // If registration's waiting worker is null, abort these steps.
     if (!registration.waitingWorker())
@@ -226,7 +227,8 @@ void SWServerJobQueue::activate(SWServer& server, SWServer::Connection& connecti
     // FIXME: Invoke Run Service Worker algorithm with activeWorker as the argument.
 
     // Queue a task to fire the activate event.
-    server.fireActivateEvent(connection, registration.activeWorker()->identifier());
+    ASSERT(registration.activeWorker());
+    server.fireActivateEvent(*registration.activeWorker());
 }
 
 // https://w3c.github.io/ServiceWorker/#activate (post activate event steps).
index 2f77b09..310d18b 100644 (file)
@@ -48,11 +48,11 @@ public:
     void runNextJob();
 
     void scriptFetchFinished(SWServer::Connection&, const ServiceWorkerFetchResult&);
-    void scriptContextFailedToStart(SWServer::Connection&, ServiceWorkerIdentifier, const String& message);
-    void scriptContextStarted(SWServer::Connection&, ServiceWorkerIdentifier);
-    void didFinishInstall(SWServer::Connection&, ServiceWorkerIdentifier, bool wasSuccessful);
+    void scriptContextFailedToStart(ServiceWorkerIdentifier, const String& message);
+    void scriptContextStarted(ServiceWorkerIdentifier);
+    void didFinishInstall(ServiceWorkerIdentifier, bool wasSuccessful);
     static void didFinishActivation(SWServerRegistration&, ServiceWorkerIdentifier);
-    void didResolveRegistrationPromise(SWServer::Connection&);
+    void didResolveRegistrationPromise();
 
 private:
     void jobTimerFired();
@@ -66,9 +66,9 @@ private:
 
     void tryClearRegistration(SWServerRegistration&);
     void clearRegistration(SWServerRegistration&);
-    void install(SWServerRegistration&, SWServer::Connection&, ServiceWorkerIdentifier);
-    static void tryActivate(SWServer&, SWServer::Connection&, SWServerRegistration&);
-    static void activate(SWServer&, SWServer::Connection&, SWServerRegistration&);
+    void install(SWServerRegistration&, ServiceWorkerIdentifier);
+    static void tryActivate(SWServer&, SWServerRegistration&);
+    static void activate(SWServer&, SWServerRegistration&);
 
     Deque<ServiceWorkerJobData> m_jobQueue;
 
index f73befe..7327797 100644 (file)
@@ -37,8 +37,7 @@ namespace WebCore {
 
 static ServiceWorkerRegistrationIdentifier generateServiceWorkerRegistrationIdentifier()
 {
-    static uint64_t identifier = 0;
-    return makeObjectIdentifier<ServiceWorkerRegistrationIdentifierType>(++identifier);
+    return generateObjectIdentifier<ServiceWorkerRegistrationIdentifierType>();
 }
 
 SWServerRegistration::SWServerRegistration(SWServer& server, const ServiceWorkerRegistrationKey& key, ServiceWorkerUpdateViaCache updateViaCache, const URL& scopeURL, const URL& scriptURL)
diff --git a/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp b/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp
new file mode 100644 (file)
index 0000000..3fe010f
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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"
+#include "SWServerToContextConnection.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "SWServer.h"
+#include "SWServerWorker.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+static SWServerToContextConnectionIdentifier generateServerToContextConnectionIdentifier()
+{
+    return generateObjectIdentifier<SWServerToContextConnectionIdentifierType>();
+}
+
+static HashMap<SWServerToContextConnectionIdentifier, SWServerToContextConnection*>& allConnections()
+{
+    static NeverDestroyed<HashMap<SWServerToContextConnectionIdentifier, SWServerToContextConnection*>> connections;
+    return connections;
+}
+
+SWServerToContextConnection::SWServerToContextConnection()
+    : m_identifier(generateServerToContextConnectionIdentifier())
+{
+    auto result = allConnections().add(m_identifier, this);
+    ASSERT_UNUSED(result, result.isNewEntry);
+}
+
+SWServerToContextConnection::~SWServerToContextConnection()
+{
+    auto result = allConnections().remove(m_identifier);
+    ASSERT_UNUSED(result, result);
+}
+
+SWServerToContextConnection* SWServerToContextConnection::connectionForIdentifier(SWServerToContextConnectionIdentifier identifier)
+{
+    return allConnections().get(identifier);
+}
+
+SWServerToContextConnection* SWServerToContextConnection::globalServerToContextConnection()
+{
+    if (allConnections().isEmpty())
+        return nullptr;
+    
+    ASSERT(allConnections().size() == 1);
+    return allConnections().begin()->value;
+}
+
+void SWServerToContextConnection::scriptContextFailedToStart(ServiceWorkerIdentifier serviceWorkerIdentifier, const String& message)
+{
+    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
+        worker->scriptContextFailedToStart(message);
+}
+
+void SWServerToContextConnection::scriptContextStarted(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
+        worker->scriptContextStarted();
+}
+    
+void SWServerToContextConnection::didFinishInstall(ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
+{
+    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
+        worker->didFinishInstall(wasSuccessful);
+}
+
+void SWServerToContextConnection::didFinishActivation(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
+        worker->didFinishActivation();
+}
+
+void SWServerToContextConnection::setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents)
+{
+    if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
+        worker->setHasPendingEvents(hasPendingEvents);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
diff --git a/Source/WebCore/workers/service/server/SWServerToContextConnection.h b/Source/WebCore/workers/service/server/SWServerToContextConnection.h
new file mode 100644 (file)
index 0000000..24a546c
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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 "ServiceWorkerIdentifier.h"
+#include "ServiceWorkerTypes.h"
+#include <wtf/ThreadSafeRefCounted.h>
+
+namespace WebCore {
+
+class SWServer;
+struct ServiceWorkerContextData;
+
+class SWServerToContextConnection : public ThreadSafeRefCounted<SWServerToContextConnection> {
+public:
+    WEBCORE_EXPORT virtual ~SWServerToContextConnection();
+
+    SWServerToContextConnectionIdentifier identifier() const { return m_identifier; }
+
+    // Messages to the SW host process
+    virtual void installServiceWorkerContext(const ServiceWorkerContextData&) = 0;
+    virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
+    virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0;
+
+    // Messages back from the SW host process
+    WEBCORE_EXPORT void scriptContextFailedToStart(ServiceWorkerIdentifier, const String& message);
+    WEBCORE_EXPORT void scriptContextStarted(ServiceWorkerIdentifier);
+    WEBCORE_EXPORT void didFinishInstall(ServiceWorkerIdentifier, bool wasSuccessful);
+    WEBCORE_EXPORT void didFinishActivation(ServiceWorkerIdentifier);
+    WEBCORE_EXPORT void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool hasPendingEvents);
+
+    static SWServerToContextConnection* connectionForIdentifier(SWServerToContextConnectionIdentifier);
+
+    // FIXME: While we only ever have one SW context process this method makes sense.
+    // Once we have multiple ones this method should go away forcing use of connectionForIdentifier()
+    WEBCORE_EXPORT static SWServerToContextConnection* globalServerToContextConnection();
+
+protected:
+    WEBCORE_EXPORT SWServerToContextConnection();
+
+private:
+    SWServerToContextConnectionIdentifier m_identifier;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
index 125a264..5bb230c 100644 (file)
 
 #if ENABLE(SERVICE_WORKER)
 
+#include <wtf/NeverDestroyed.h>
+
 namespace WebCore {
 
-SWServerWorker::SWServerWorker(const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type, ServiceWorkerIdentifier identifier)
-    : m_registrationKey(registrationKey)
+static HashMap<ServiceWorkerIdentifier, SWServerWorker*>& allWorkers()
+{
+    static NeverDestroyed<HashMap<ServiceWorkerIdentifier, SWServerWorker*>> workers;
+    return workers;
+}
+
+SWServerWorker* SWServerWorker::existingWorkerForIdentifier(ServiceWorkerIdentifier identifier)
+{
+    return allWorkers().get(identifier);
+}
+
+SWServerWorker::SWServerWorker(SWServer& server, const ServiceWorkerRegistrationKey& registrationKey, SWServerToContextConnectionIdentifier contextConnectionIdentifier, const URL& url, const String& script, WorkerType type, ServiceWorkerIdentifier identifier)
+    : m_server(server)
+    , m_registrationKey(registrationKey)
+    , m_contextConnectionIdentifier(contextConnectionIdentifier)
     , m_scriptURL(url)
     , m_script(script)
     , m_identifier(identifier)
     , m_type(type)
 {
+    auto result = allWorkers().add(identifier, this);
+    ASSERT_UNUSED(result, result.isNewEntry);
 }
 
-SWServerWorker::~SWServerWorker() = default;
+SWServerWorker::~SWServerWorker()
+{
+    auto taken = allWorkers().take(m_identifier);
+    ASSERT_UNUSED(taken, taken == this);
+}
 
 void SWServerWorker::terminate()
 {
     // FIXME: Implement
 }
 
+void SWServerWorker::scriptContextFailedToStart(const String& message)
+{
+    m_server.scriptContextFailedToStart(*this, message);
+}
+
+void SWServerWorker::scriptContextStarted()
+{
+    m_server.scriptContextStarted(*this);
+}
+
+void SWServerWorker::didFinishInstall(bool wasSuccessful)
+{
+    m_server.didFinishInstall(*this, wasSuccessful);
+}
+
+void SWServerWorker::didFinishActivation()
+{
+    m_server.didFinishActivation(*this);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)
index 1a681eb..38b0b47 100644 (file)
 
 namespace WebCore {
 
+class SWServer;
 enum class WorkerType;
 
 class SWServerWorker : public ThreadSafeRefCounted<SWServerWorker> {
 public:
-    static Ref<SWServerWorker> create(const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type, ServiceWorkerIdentifier identifier)
+    template <typename... Args> static Ref<SWServerWorker> create(Args&&... args)
     {
-        return adoptRef(*new SWServerWorker(registrationKey, url, script, type, identifier));
+        return adoptRef(*new SWServerWorker(std::forward<Args>(args)...));
     }
     
     SWServerWorker(const SWServerWorker&) = delete;
@@ -49,11 +50,14 @@ public:
 
     void terminate();
 
+    SWServer& server();
+    const ServiceWorkerRegistrationKey& registrationKey() const { return m_registrationKey; }
     const URL& scriptURL() const { return m_scriptURL; }
     const String& script() const { return m_script; }
     WorkerType type() const { return m_type; }
 
     ServiceWorkerIdentifier identifier() const { return m_identifier; }
+    SWServerToContextConnectionIdentifier contextConnectionIdentifier() const { return m_contextConnectionIdentifier; }
 
     ServiceWorkerState state() const { return m_state; }
     void setState(ServiceWorkerState state) { m_state = state; }
@@ -61,10 +65,19 @@ public:
     bool hasPendingEvents() const { return m_hasPendingEvents; }
     void setHasPendingEvents(bool value) { m_hasPendingEvents = value; }
 
+    void scriptContextFailedToStart(const String& message);
+    void scriptContextStarted();
+    void didFinishInstall(bool wasSuccessful);
+    void didFinishActivation();
+
+    WEBCORE_EXPORT static SWServerWorker* existingWorkerForIdentifier(ServiceWorkerIdentifier);
+
 private:
-    SWServerWorker(const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
+    SWServerWorker(SWServer&, const ServiceWorkerRegistrationKey&, SWServerToContextConnectionIdentifier, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
 
+    SWServer& m_server;
     ServiceWorkerRegistrationKey m_registrationKey;
+    SWServerToContextConnectionIdentifier m_contextConnectionIdentifier;
     URL m_scriptURL;
     String m_script;
     ServiceWorkerIdentifier m_identifier;
index 7945379..08538cf 100644 (file)
@@ -1,3 +1,68 @@
+2017-11-13  Brady Eidson  <beidson@apple.com>
+
+        Massive "Server-process-to-context-process" connection overhaul.
+        https://bugs.webkit.org/show_bug.cgi?id=179554
+
+        Reviewed by Chris Dumez.
+
+        * DerivedSources.make:
+        * WebKit.xcodeproj/project.pbxproj:
+
+        * Shared/WebCoreArgumentCoders.h:
+
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::sendToContextProcess):
+        (WebKit::WebSWServerConnection::installServiceWorkerContext): Deleted.
+        (WebKit::WebSWServerConnection::fireInstallEvent): Deleted.
+        (WebKit::WebSWServerConnection::fireActivateEvent): Deleted.
+        (WebKit::WebSWServerConnection::setContextConnection): Deleted.
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp: Copied from Source/WebCore/workers/service/server/SWServerWorker.cpp.
+        (WebKit::WebSWServerToContextConnection::WebSWServerToContextConnection):
+        (WebKit::WebSWServerToContextConnection::messageSenderConnection):
+        (WebKit::WebSWServerToContextConnection::messageSenderDestinationID):
+        (WebKit::WebSWServerToContextConnection::connectionClosed):
+        (WebKit::WebSWServerToContextConnection::installServiceWorkerContext):
+        (WebKit::WebSWServerToContextConnection::fireInstallEvent):
+        (WebKit::WebSWServerToContextConnection::fireActivateEvent):
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.h: Copied from Source/WebCore/workers/service/ServiceWorkerTypes.h.
+        (WebKit::WebSWServerToContextConnection::create):
+        (WebKit::WebSWServerToContextConnection::ipcConnection const):
+        * StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in: Copied from Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in.
+
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::didClose):
+        (WebKit::StorageProcess::didReceiveMessage):
+        (WebKit::StorageProcess::globalServerToContextConnection):
+        (WebKit::StorageProcess::createServerToContextConnection):
+        (WebKit::StorageProcess::didGetWorkerContextProcessConnection):
+        (WebKit::StorageProcess::workerContextProcessConnection): Deleted.
+        (WebKit::StorageProcess::createWorkerContextProcessConnection): Deleted.
+        (WebKit::StorageProcess::serviceWorkerContextFailedToStart): Deleted.
+        (WebKit::StorageProcess::serviceWorkerContextStarted): Deleted.
+        (WebKit::StorageProcess::didFinishServiceWorkerInstall): Deleted.
+        (WebKit::StorageProcess::didFinishServiceWorkerActivation): Deleted.
+        (WebKit::StorageProcess::setServiceWorkerHasPendingEvents): Deleted.
+        * StorageProcess/StorageProcess.h:
+        * StorageProcess/StorageProcess.messages.in:
+
+        * StorageProcess/StorageToWebProcessConnection.cpp:
+        (WebKit::StorageToWebProcessConnection::didReceiveMessage):
+        (WebKit::StorageToWebProcessConnection::establishSWServerConnection):
+        (WebKit::StorageToWebProcessConnection::workerContextProcessConnectionCreated):
+
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::installServiceWorker):
+        (WebKit::WebSWContextManagerConnection::serviceWorkerStartedWithMessage):
+        (WebKit::WebSWContextManagerConnection::fireInstallEvent):
+        (WebKit::WebSWContextManagerConnection::fireActivateEvent):
+        (WebKit::WebSWContextManagerConnection::didFinishInstall):
+        (WebKit::WebSWContextManagerConnection::didFinishActivation):
+        (WebKit::WebSWContextManagerConnection::setServiceWorkerHasPendingEvents):
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
 2017-11-13  Brent Fulgham  <bfulgham@apple.com>
 
         WebContent sandbox should not include 'system.sb'
index 439b1ee..d721c0b 100644 (file)
@@ -164,6 +164,7 @@ MESSAGE_RECEIVERS = \
     WebSWClientConnection \
     WebSWContextManagerConnection \
     WebSWServerConnection \
+    WebSWServerToContextConnection \
     PlaybackSessionManager \
     PlaybackSessionManagerProxy \
     WebProcess \
index 98d97ad..e99cb6d 100644 (file)
@@ -42,6 +42,7 @@
 #include <WebCore/ServiceWorkerTypes.h>
 #include <WebCore/ServiceWorkerUpdateViaCache.h>
 #include <WebCore/StoredCredentialsPolicy.h>
+#include <WebCore/WorkerType.h>
 
 namespace WTF {
 class MonotonicTime;
@@ -797,6 +798,14 @@ template <> struct EnumTraits<WebCore::StoredCredentialsPolicy> {
     >;
 };
 
+template <> struct EnumTraits<WebCore::WorkerType> {
+    using values = EnumValues<
+        WebCore::WorkerType,
+        WebCore::WorkerType::Classic,
+        WebCore::WorkerType::Module
+    >;
+};
+
 #if ENABLE(SERVICE_WORKER)
 template <> struct EnumTraits<WebCore::ServiceWorkerUpdateViaCache> {
     using values = EnumValues<
index 6a8b330..28cdbb7 100644 (file)
@@ -31,6 +31,7 @@
 #include "DataReference.h"
 #include "Logging.h"
 #include "ServiceWorkerClientFetchMessages.h"
+#include "StorageProcess.h"
 #include "StorageToWebProcessConnectionMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebProcess.h"
@@ -38,6 +39,7 @@
 #include "WebSWClientConnectionMessages.h"
 #include "WebSWContextManagerConnectionMessages.h"
 #include "WebSWServerConnectionMessages.h"
+#include "WebSWServerToContextConnection.h"
 #include "WebToStorageProcessConnection.h"
 #include <WebCore/ExceptionData.h>
 #include <WebCore/NotImplemented.h>
@@ -104,24 +106,6 @@ void WebSWServerConnection::updateWorkerStateInClient(ServiceWorkerIdentifier wo
     send(Messages::WebSWClientConnection::UpdateWorkerState(worker, state));
 }
 
-void WebSWServerConnection::installServiceWorkerContext(const ServiceWorkerContextData& data)
-{
-    if (sendToContextProcess(Messages::WebSWContextManagerConnection::InstallServiceWorker(identifier(), data)))
-        return;
-
-    m_pendingContextDatas.append(data);
-}
-
-void WebSWServerConnection::fireInstallEvent(ServiceWorkerIdentifier serviceWorkerIdentifier)
-{
-    sendToContextProcess(Messages::WebSWContextManagerConnection::FireInstallEvent(identifier(), serviceWorkerIdentifier));
-}
-
-void WebSWServerConnection::fireActivateEvent(ServiceWorkerIdentifier serviceWorkerIdentifier)
-{
-    sendToContextProcess(Messages::WebSWContextManagerConnection::FireActivateEvent(identifier(), serviceWorkerIdentifier));
-}
-
 void WebSWServerConnection::startFetch(uint64_t fetchIdentifier, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier, const ResourceRequest& request, const FetchOptions& options)
 {
     sendToContextProcess(Messages::WebSWContextManagerConnection::StartFetch(identifier(), fetchIdentifier, serviceWorkerIdentifier, request, options));
@@ -172,25 +156,12 @@ void WebSWServerConnection::matchRegistration(uint64_t registrationMatchRequestI
     send(Messages::WebSWClientConnection::DidMatchRegistration { registrationMatchRequestIdentifier, std::nullopt });
 }
 
-template<typename U> bool WebSWServerConnection::sendToContextProcess(U&& message)
+template<typename U> void WebSWServerConnection::sendToContextProcess(U&& message)
 {
-    if (!m_contextConnection)
-        return false;
-
-    return m_contextConnection->send<U>(WTFMove(message), 0);
+    if (auto* connection = StorageProcess::singleton().globalServerToContextConnection())
+        connection->send(WTFMove(message));
 }
 
-void WebSWServerConnection::setContextConnection(IPC::Connection* connection)
-{
-    m_contextConnection = connection;
-
-    // We can now start any pending service worker updates.
-    for (auto& pendingContextData : m_pendingContextDatas)
-        installServiceWorkerContext(pendingContextData);
-    
-    m_pendingContextDatas.clear();
-}
-    
 } // namespace WebKit
 
 #endif // ENABLE(SERVICE_WORKER)
index 7f1cd51..b80b3bf 100644 (file)
@@ -46,7 +46,6 @@ public:
     ~WebSWServerConnection() final;
 
     void disconnectedFromWebProcess();
-    void setContextConnection(IPC::Connection*);
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
 
     PAL::SessionID sessionID() const { return m_sessionID; }
@@ -75,22 +74,15 @@ private:
 
     void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData&, const WebCore::URL& clientURL);
 
-    // Messages to the SW context WebProcess
-    void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
-    void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
-    void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
-
     IPC::Connection* messageSenderConnection() final { return m_contentConnection.ptr(); }
     uint64_t messageSenderDestinationID() final { return identifier(); }
-
-    template<typename U> bool sendToContextProcess(U&& message);
     
+    template<typename U> void sendToContextProcess(U&& message);
+
     PAL::SessionID m_sessionID;
 
     Ref<IPC::Connection> m_contentConnection;
     RefPtr<IPC::Connection> m_contextConnection;
-    
-    Deque<WebCore::ServiceWorkerContextData> m_pendingContextDatas;
 }; // class WebSWServerConnection
 
 } // namespace WebKit
diff --git a/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp b/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.cpp
new file mode 100644 (file)
index 0000000..b82ef35
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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"
+#include "WebSWServerToContextConnection.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+#include "WebCoreArgumentCoders.h"
+#include "WebSWContextManagerConnectionMessages.h"
+#include <WebCore/ServiceWorkerContextData.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebSWServerToContextConnection::WebSWServerToContextConnection(Ref<IPC::Connection>&& connection)
+    : m_ipcConnection(WTFMove(connection))
+{
+}
+
+IPC::Connection* WebSWServerToContextConnection::messageSenderConnection()
+{
+    return m_ipcConnection.ptr();
+}
+
+uint64_t WebSWServerToContextConnection::messageSenderDestinationID()
+{
+    return 0;
+}
+
+void WebSWServerToContextConnection::connectionClosed()
+{
+    // FIXME: Do what here...?
+}
+
+void WebSWServerToContextConnection::installServiceWorkerContext(const ServiceWorkerContextData& data)
+{
+    send(Messages::WebSWContextManagerConnection::InstallServiceWorker(data));
+}
+
+void WebSWServerToContextConnection::fireInstallEvent(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+    send(Messages::WebSWContextManagerConnection::FireInstallEvent(serviceWorkerIdentifier));
+}
+
+void WebSWServerToContextConnection::fireActivateEvent(ServiceWorkerIdentifier serviceWorkerIdentifier)
+{
+    send(Messages::WebSWContextManagerConnection::FireActivateEvent(serviceWorkerIdentifier));
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_WORKER)
diff --git a/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h b/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.h
new file mode 100644 (file)
index 0000000..87b76d2
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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 "MessageReceiver.h"
+#include "MessageSender.h"
+#include <WebCore/SWServerToContextConnection.h>
+
+namespace WebKit {
+
+class WebSWServerToContextConnection : public WebCore::SWServerToContextConnection, public IPC::MessageSender, public IPC::MessageReceiver {
+public:
+    template <typename... Args> static Ref<WebSWServerToContextConnection> create(Args&&... args)
+    {
+        return adoptRef(*new WebSWServerToContextConnection(std::forward<Args>(args)...));
+    }
+
+    void connectionClosed();
+
+    IPC::Connection* ipcConnection() const { return m_ipcConnection.ptr(); }
+
+    // IPC::MessageReceiver
+    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
+
+private:
+    explicit WebSWServerToContextConnection(Ref<IPC::Connection>&&);
+
+    // IPC::MessageSender
+    IPC::Connection* messageSenderConnection() final;
+    uint64_t messageSenderDestinationID() final;
+
+    // Messages to the SW host WebProcess
+    void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
+    void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
+    void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final;
+    
+    Ref<IPC::Connection> m_ipcConnection;
+    
+}; // class WebSWServerToContextConnection
+
+} // namespace WebKit
+
+#endif // ENABLE(SERVICE_WORKER)
+
diff --git a/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in b/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerToContextConnection.messages.in
new file mode 100644 (file)
index 0000000..9dc8c16
--- /dev/null
@@ -0,0 +1,35 @@
+# 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.
+
+#if ENABLE(SERVICE_WORKER)
+
+messages -> WebSWServerToContextConnection {
+    # When possible, these messages can be implemented directly by WebCore::SWServerToContextConnection
+
+    ScriptContextFailedToStart(WebCore::ServiceWorkerIdentifier identifier, String message);
+    ScriptContextStarted(WebCore::ServiceWorkerIdentifier identifier);
+    DidFinishInstall(WebCore::ServiceWorkerIdentifier identifier, bool wasSuccessful);
+    DidFinishActivation(WebCore::ServiceWorkerIdentifier identifier);
+    SetServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents);
+}
+
+#endif // ENABLE(SERVICE_WORKER)
index b4cf8e9..6f13ebf 100644 (file)
 #include "WebCoreArgumentCoders.h"
 #include "WebSWOriginStore.h"
 #include "WebSWServerConnection.h"
+#include "WebSWServerToContextConnection.h"
 #include "WebsiteData.h"
 #include <WebCore/FileSystem.h>
 #include <WebCore/IDBKeyData.h>
 #include <WebCore/NotImplemented.h>
+#include <WebCore/SWServerWorker.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/ServiceWorkerClientIdentifier.h>
 #include <WebCore/TextEncoding.h>
 #include <wtf/CrossThreadTask.h>
 #include <wtf/MainThread.h>
 
+#if ENABLE(SERVICE_WORKER)
+#include "WebSWServerToContextConnectionMessages.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -79,8 +85,9 @@ bool StorageProcess::shouldTerminate()
 void StorageProcess::didClose(IPC::Connection& connection)
 {
 #if ENABLE(SERVICE_WORKER)
-    if (m_workerContextProcessConnection == &connection) {
-        m_workerContextProcessConnection = nullptr;
+    if (m_serverToContextConnection && m_serverToContextConnection->ipcConnection() == &connection) {
+        m_serverToContextConnection->connectionClosed();
+        m_serverToContextConnection = nullptr;
         return;
     }
 #else
@@ -98,6 +105,16 @@ void StorageProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder
         didReceiveStorageProcessMessage(connection, decoder);
         return;
     }
+
+#if ENABLE(SERVICE_WORKER)
+    if (decoder.messageReceiverName() == Messages::WebSWServerToContextConnection::messageReceiverName()) {
+        if (auto* swConnection = SWServerToContextConnection::globalServerToContextConnection()) {
+            auto* webSWConnection = static_cast<WebSWServerToContextConnection*>(swConnection);
+            webSWConnection->didReceiveMessage(connection, decoder);
+            return;        
+        }
+    }
+#endif
 }
 
 #if ENABLE(INDEXED_DATABASE)
@@ -353,24 +370,24 @@ WebSWOriginStore& StorageProcess::swOriginStoreForSession(PAL::SessionID session
     return static_cast<WebSWOriginStore&>(swServerForSession(sessionID).originStore());
 }
 
-IPC::Connection* StorageProcess::workerContextProcessConnection()
+WebSWServerToContextConnection* StorageProcess::globalServerToContextConnection()
 {
-    return m_workerContextProcessConnection.get();
+    return m_serverToContextConnection.get();
 }
 
-void StorageProcess::createWorkerContextProcessConnection()
+void StorageProcess::createServerToContextConnection()
 {
-    if (m_waitingForWorkerContextProcessConnection)
+    if (m_waitingForServerToContextProcessConnection)
         return;
     
-    m_waitingForWorkerContextProcessConnection = true;
+    m_waitingForServerToContextProcessConnection = true;
     parentProcessConnection()->send(Messages::StorageProcessProxy::GetWorkerContextProcessConnection(), 0);
 }
 
 void StorageProcess::didGetWorkerContextProcessConnection(IPC::Attachment&& encodedConnectionIdentifier)
 {
-    ASSERT(m_waitingForWorkerContextProcessConnection);
-    m_waitingForWorkerContextProcessConnection = false;
+    ASSERT(m_waitingForServerToContextProcessConnection);
+    m_waitingForServerToContextProcessConnection = false;
 
 #if USE(UNIX_DOMAIN_SOCKETS)
     IPC::Connection::Identifier connectionIdentifier = encodedConnectionIdentifier.releaseFileDescriptor();
@@ -385,25 +402,14 @@ void StorageProcess::didGetWorkerContextProcessConnection(IPC::Attachment&& enco
         return;
     }
 
-    m_workerContextProcessConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
-    m_workerContextProcessConnection->open();
+    auto ipcConnection = IPC::Connection::createClientConnection(connectionIdentifier, *this);
+    ipcConnection->open();
+    m_serverToContextConnection = WebSWServerToContextConnection::create(WTFMove(ipcConnection));
     
     for (auto& connection : m_storageToWebProcessConnections)
         connection->workerContextProcessConnectionCreated();
 }
 
-void StorageProcess::serviceWorkerContextFailedToStart(uint64_t serverConnectionIdentifier, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& message)
-{
-    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
-        connection->scriptContextFailedToStart(registrationKey, serviceWorkerIdentifier, message);
-}
-
-void StorageProcess::serviceWorkerContextStarted(uint64_t serverConnectionIdentifier, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier serviceWorkerIdentifier)
-{
-    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
-        connection->scriptContextStarted(registrationKey, serviceWorkerIdentifier);
-}
-
 void StorageProcess::didFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
 {
     if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
@@ -440,25 +446,6 @@ void StorageProcess::postMessageToServiceWorkerClient(const ServiceWorkerClientI
         connection->postMessageToServiceWorkerClient(destinationIdentifier.scriptExecutionContextIdentifier, message, sourceIdentifier, sourceOrigin);
 }
 
-void StorageProcess::didFinishServiceWorkerInstall(uint64_t serverConnectionIdentifier, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
-{
-    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
-        connection->didFinishInstall(registrationKey, serviceWorkerIdentifier, wasSuccessful);
-}
-
-void StorageProcess::didFinishServiceWorkerActivation(uint64_t serverConnectionIdentifier, const ServiceWorkerRegistrationKey& registrationKey, ServiceWorkerIdentifier serviceWorkerIdentifier)
-{
-    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
-        connection->didFinishActivation(registrationKey, serviceWorkerIdentifier);
-}
-
-
-void StorageProcess::setServiceWorkerHasPendingEvents(uint64_t serverConnectionIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents)
-{
-    if (auto* connection = m_swServerConnections.get(serverConnectionIdentifier))
-        connection->setServiceWorkerHasPendingEvents(serviceWorkerIdentifier, hasPendingEvents);
-}
-
 void StorageProcess::registerSWServerConnection(WebSWServerConnection& connection)
 {
     ASSERT(!m_swServerConnections.contains(connection.identifier()));
index 626f7d7..591b583 100644 (file)
@@ -46,6 +46,7 @@ namespace WebKit {
 
 class StorageToWebProcessConnection;
 class WebSWServerConnection;
+class WebSWServerToContextConnection;
 enum class WebsiteDataType;
 struct StorageProcessCreationParameters;
 
@@ -80,8 +81,10 @@ public:
 #endif
 
 #if ENABLE(SERVICE_WORKER)
-    IPC::Connection* workerContextProcessConnection();
-    void createWorkerContextProcessConnection();
+    // For now we just have one global connection to service worker context processes.
+    // This will change in the future.
+    WebSWServerToContextConnection* globalServerToContextConnection();
+    void createServerToContextConnection();
 
     WebCore::SWServer& swServerForSession(PAL::SessionID);
     void registerSWServerConnection(WebSWServerConnection&);
@@ -116,8 +119,6 @@ private:
 #endif
 #if ENABLE(SERVICE_WORKER)
     void didGetWorkerContextProcessConnection(IPC::Attachment&& encodedConnectionIdentifier);
-    void serviceWorkerContextFailedToStart(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerIdentifier, const String& message);
-    void serviceWorkerContextStarted(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerIdentifier);
 
     void didReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const WebCore::ResourceResponse&);
     void didReceiveFetchData(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, const IPC::DataReference&, int64_t encodedDataLength);
@@ -125,9 +126,6 @@ private:
     void didFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
     void didNotHandleFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier);
 
-    void didFinishServiceWorkerInstall(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerIdentifier, bool wasSuccessful);
-    void didFinishServiceWorkerActivation(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerIdentifier);
-    void setServiceWorkerHasPendingEvents(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier, bool hasPendingEvents);
     void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
     WebSWOriginStore& swOriginStoreForSession(PAL::SessionID);
 #endif
@@ -156,8 +154,8 @@ private:
 #if ENABLE(SERVICE_WORKER)
     void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
 
-    RefPtr<IPC::Connection> m_workerContextProcessConnection;
-    bool m_waitingForWorkerContextProcessConnection { false };
+    RefPtr<WebSWServerToContextConnection> m_serverToContextConnection;
+    bool m_waitingForServerToContextProcessConnection { false };
     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
     HashMap<uint64_t, WebSWServerConnection*> m_swServerConnections;
 #endif
index 3b6d339..0574902 100644 (file)
@@ -38,12 +38,6 @@ messages -> StorageProcess LegacyReceiver {
 #if ENABLE(SERVICE_WORKER)
     DidGetWorkerContextProcessConnection(IPC::Attachment connectionHandle)
 
-    ServiceWorkerContextFailedToStart(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, String message)
-    ServiceWorkerContextStarted(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier)
-    DidFinishServiceWorkerInstall(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful);
-    DidFinishServiceWorkerActivation(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerRegistrationKey registrationKey, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier);
-    SetServiceWorkerHasPendingEvents(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents);
-
     DidNotHandleFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     DidFailFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier)
     DidReceiveFetchResponse(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, WebCore::ResourceResponse response)
index 4545bc4..9b09778 100644 (file)
 #include "WebSWServerConnectionMessages.h"
 #include <wtf/RunLoop.h>
 
+#if ENABLE(SERVICE_WORKER)
+#include "WebSWServerToContextConnection.h"
+#include "WebSWServerToContextConnectionMessages.h"
+#endif
+
 using namespace PAL;
 using namespace WebCore;
 
@@ -85,6 +90,11 @@ void StorageToWebProcessConnection::didReceiveMessage(IPC::Connection& connectio
             iterator->value->didReceiveMessage(connection, decoder);
         return;
     }
+
+    if (decoder.messageReceiverName() == Messages::WebSWServerToContextConnection::messageReceiverName()) {
+        StorageProcess::singleton().globalServerToContextConnection()->didReceiveMessage(connection, decoder);
+        return;
+    }
 #endif
 
     ASSERT_NOT_REACHED();
@@ -148,10 +158,8 @@ void StorageToWebProcessConnection::establishSWServerConnection(SessionID sessio
 
     StorageProcess::singleton().registerSWServerConnection(*(connectionResult.iterator->value));
 
-    if (auto* connection = StorageProcess::singleton().workerContextProcessConnection())
-        connectionResult.iterator->value->setContextConnection(connection);
-    else
-        StorageProcess::singleton().createWorkerContextProcessConnection();
+    if (!StorageProcess::singleton().globalServerToContextConnection())
+        StorageProcess::singleton().createServerToContextConnection();
 }
 
 void StorageToWebProcessConnection::removeSWServerConnection(uint64_t serverConnectionIdentifier)
@@ -165,11 +173,8 @@ void StorageToWebProcessConnection::removeSWServerConnection(uint64_t serverConn
 
 void StorageToWebProcessConnection::workerContextProcessConnectionCreated()
 {
-    auto* ipcConnection = StorageProcess::singleton().workerContextProcessConnection();
-    ASSERT(ipcConnection);
-
-    for (auto& swConnection : m_swConnections.values())
-        swConnection->setContextConnection(ipcConnection);
+    for (auto* server : SWServer::allServers())
+        server->serverToContextConnectionCreated();
 }
 #endif
 
index 9a1447b..08de3c3 100644 (file)
                514BDED316C98EDD00E4E25E /* StatisticsRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 514BDED216C98EDD00E4E25E /* StatisticsRequest.h */; };
                514D9F5719119D35000063A7 /* ServicesController.h in Headers */ = {isa = PBXBuildFile; fileRef = 514D9F5519119D35000063A7 /* ServicesController.h */; };
                514D9F5819119D35000063A7 /* ServicesController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514D9F5619119D35000063A7 /* ServicesController.mm */; };
+               515262BC1FB9515D0070E579 /* WebSWServerToContextConnectionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 515262BB1FB951310070E579 /* WebSWServerToContextConnectionMessages.h */; };
+               515262BD1FB951610070E579 /* WebSWServerToContextConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515262BA1FB951310070E579 /* WebSWServerToContextConnectionMessageReceiver.cpp */; };
                51578B831209ECEF00A37C4A /* APIData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51578B821209ECEF00A37C4A /* APIData.h */; };
                515BE1771D53FE8700DD7C68 /* WebGamepadProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1731D53FDDC00DD7C68 /* WebGamepadProvider.cpp */; };
                515BE1791D53FE8F00DD7C68 /* WebGamepadProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 515BE1741D53FDDC00DD7C68 /* WebGamepadProvider.h */; };
                517DD5BE180DA7D30081660B /* StorageProcessProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517DD5BC180DA7D30081660B /* StorageProcessProxy.cpp */; };
                517DD5BF180DA7D30081660B /* StorageProcessProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 517DD5BD180DA7D30081660B /* StorageProcessProxy.h */; };
                5183DDEC1630BDFC008BE5C7 /* NetworkProcessConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5105B0D4162F7A7A00E27709 /* NetworkProcessConnection.cpp */; };
+               5185430E1FB6816100478F95 /* WebSWServerToContextConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5185430D1FB680FA00478F95 /* WebSWServerToContextConnection.cpp */; };
                51871B5B127CB89D00F76232 /* WebContextMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51871B59127CB89D00F76232 /* WebContextMenu.cpp */; };
                51871B5C127CB89D00F76232 /* WebContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 51871B5A127CB89D00F76232 /* WebContextMenu.h */; };
                518ACAEA12AEE6BB00B04B83 /* WKProtectionSpaceTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 518ACAE912AEE6BB00B04B83 /* WKProtectionSpaceTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                514BDED216C98EDD00E4E25E /* StatisticsRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StatisticsRequest.h; sourceTree = "<group>"; };
                514D9F5519119D35000063A7 /* ServicesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServicesController.h; sourceTree = "<group>"; };
                514D9F5619119D35000063A7 /* ServicesController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ServicesController.mm; sourceTree = "<group>"; };
+               515262B91FB950350070E579 /* WebSWServerToContextConnection.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebSWServerToContextConnection.messages.in; sourceTree = "<group>"; };
+               515262BA1FB951310070E579 /* WebSWServerToContextConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWServerToContextConnectionMessageReceiver.cpp; sourceTree = "<group>"; };
+               515262BB1FB951310070E579 /* WebSWServerToContextConnectionMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWServerToContextConnectionMessages.h; sourceTree = "<group>"; };
                51578B821209ECEF00A37C4A /* APIData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIData.h; sourceTree = "<group>"; };
                515BE1731D53FDDC00DD7C68 /* WebGamepadProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebGamepadProvider.cpp; sourceTree = "<group>"; };
                515BE1741D53FDDC00DD7C68 /* WebGamepadProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGamepadProvider.h; sourceTree = "<group>"; };
                517DD5BC180DA7D30081660B /* StorageProcessProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageProcessProxy.cpp; sourceTree = "<group>"; };
                517DD5BD180DA7D30081660B /* StorageProcessProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageProcessProxy.h; sourceTree = "<group>"; };
                5183B3931379F85C00E8754E /* Shim.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Shim.xcconfig; sourceTree = "<group>"; };
+               5185430C1FB680F900478F95 /* WebSWServerToContextConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSWServerToContextConnection.h; sourceTree = "<group>"; };
+               5185430D1FB680FA00478F95 /* WebSWServerToContextConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSWServerToContextConnection.cpp; sourceTree = "<group>"; };
                51871B59127CB89D00F76232 /* WebContextMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextMenu.cpp; sourceTree = "<group>"; };
                51871B5A127CB89D00F76232 /* WebContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenu.h; sourceTree = "<group>"; };
                518ACAE912AEE6BB00B04B83 /* WKProtectionSpaceTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKProtectionSpaceTypes.h; sourceTree = "<group>"; };
                                517A53091F479E3100DCDC0A /* WebSWServerConnection.cpp */,
                                517A53071F479E3100DCDC0A /* WebSWServerConnection.h */,
                                517A53081F479E3100DCDC0A /* WebSWServerConnection.messages.in */,
+                               5185430D1FB680FA00478F95 /* WebSWServerToContextConnection.cpp */,
+                               5185430C1FB680F900478F95 /* WebSWServerToContextConnection.h */,
+                               515262B91FB950350070E579 /* WebSWServerToContextConnection.messages.in */,
                        );
                        path = ServiceWorker;
                        sourceTree = "<group>";
                                460F488E1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessages.h */,
                                517A52D71F43A9B600DCDC0A /* WebSWServerConnectionMessageReceiver.cpp */,
                                517A52D61F43A9B600DCDC0A /* WebSWServerConnectionMessages.h */,
+                               515262BA1FB951310070E579 /* WebSWServerToContextConnectionMessageReceiver.cpp */,
+                               515262BB1FB951310070E579 /* WebSWServerToContextConnectionMessages.h */,
                                1AAF08B519269E6D00B6390C /* WebUserContentControllerMessageReceiver.cpp */,
                                1AAF08B619269E6D00B6390C /* WebUserContentControllerMessages.h */,
                                7C361D76192803BD0036A59D /* WebUserContentControllerProxyMessageReceiver.cpp */,
                                83F1A07A1F96E7790045B94E /* WebSWOriginTable.h in Headers */,
                                517A530B1F479E3600DCDC0A /* WebSWServerConnection.h in Headers */,
                                517A52D91F43A9DA00DCDC0A /* WebSWServerConnectionMessages.h in Headers */,
+                               515262BC1FB9515D0070E579 /* WebSWServerToContextConnectionMessages.h in Headers */,
                                5118E99C1F295266003EF9F5 /* WebToStorageProcessConnection.h in Headers */,
                                BCA0EF7F12331E78007D3CFB /* WebUndoStep.h in Headers */,
                                1AAF08AE1926936700B6390C /* WebUserContentController.h in Headers */,
                                83F1A0791F96E7790045B94E /* WebSWOriginTable.cpp in Sources */,
                                517A530A1F479E3600DCDC0A /* WebSWServerConnection.cpp in Sources */,
                                517A52D81F43A9DA00DCDC0A /* WebSWServerConnectionMessageReceiver.cpp in Sources */,
+                               5185430E1FB6816100478F95 /* WebSWServerToContextConnection.cpp in Sources */,
+                               515262BD1FB951610070E579 /* WebSWServerToContextConnectionMessageReceiver.cpp in Sources */,
                                5118E99B1F295266003EF9F5 /* WebToStorageProcessConnection.cpp in Sources */,
                                C0337DD8127A51B6008FF4F4 /* WebTouchEvent.cpp in Sources */,
                                2DA944A31884E4F000ED86DB /* WebTouchEventIOS.cpp in Sources */,
index edb2454..dfdc62f 100644 (file)
@@ -37,6 +37,7 @@
 #include "WebPreferencesKeys.h"
 #include "WebPreferencesStore.h"
 #include "WebProcess.h"
+#include "WebSWServerToContextConnectionMessages.h"
 #include "WebServiceWorkerFetchTaskClient.h"
 #include "WebSocketProvider.h"
 #include <WebCore/EditorClient.h>
@@ -95,8 +96,10 @@ void WebSWContextManagerConnection::updatePreferences(const WebPreferencesStore&
     RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey()));
 }
 
-void WebSWContextManagerConnection::installServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
+void WebSWContextManagerConnection::installServiceWorker(const ServiceWorkerContextData& data)
 {
+    LOG(ServiceWorker, "WebSWContextManagerConnection::installServiceWorker for worker %s", data.serviceWorkerIdentifier.loggingString().utf8().data());
+
     // FIXME: Provide a sensical session ID.
     auto sessionID = PAL::SessionID::defaultSessionID();
 
@@ -113,7 +116,7 @@ void WebSWContextManagerConnection::installServiceWorker(uint64_t serverConnecti
     auto frameLoaderClient = std::make_unique<ServiceWorkerFrameLoaderClient>(sessionID, m_pageID, ++m_previousServiceWorkerID);
     pageConfiguration.loaderClientForMainFrame = frameLoaderClient.release();
 
-    auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, WebProcess::singleton().cacheStorageProvider());
+    auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), data, sessionID, WebProcess::singleton().cacheStorageProvider());
     SWContextManager::singleton().registerServiceWorkerThreadForInstall(WTFMove(serviceWorkerThreadProxy));
 
     LOG(ServiceWorker, "Context process PID: %i created worker thread\n", getpid());
@@ -121,15 +124,10 @@ void WebSWContextManagerConnection::installServiceWorker(uint64_t serverConnecti
 
 void WebSWContextManagerConnection::serviceWorkerStartedWithMessage(ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
 {
-    auto* threadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier);
-    ASSERT(threadProxy);
-    
-    auto& data = threadProxy->thread().contextData();
-    
     if (exceptionMessage.isEmpty())
-        m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(threadProxy->thread().serverConnectionIdentifier(), data.registrationKey, serviceWorkerIdentifier), 0);
+        m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::ScriptContextStarted(serviceWorkerIdentifier), 0);
     else
-        m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextFailedToStart(threadProxy->thread().serverConnectionIdentifier(), data.registrationKey, serviceWorkerIdentifier, exceptionMessage), 0);
+        m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::ScriptContextFailedToStart(serviceWorkerIdentifier, exceptionMessage), 0);
 }
 
 void WebSWContextManagerConnection::startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier, ResourceRequest&& request, FetchOptions&& options)
@@ -149,15 +147,13 @@ void WebSWContextManagerConnection::postMessageToServiceWorkerGlobalScope(Servic
     SWContextManager::singleton().postMessageToServiceWorkerGlobalScope(destinationIdentifier, SerializedScriptValue::adopt(message.vector()), sourceIdentifier, sourceOrigin);
 }
 
-void WebSWContextManagerConnection::fireInstallEvent(uint64_t serverConnectionIdentifier, ServiceWorkerIdentifier identifier)
+void WebSWContextManagerConnection::fireInstallEvent(ServiceWorkerIdentifier identifier)
 {
-    UNUSED_PARAM(serverConnectionIdentifier);
     SWContextManager::singleton().fireInstallEvent(identifier);
 }
 
-void WebSWContextManagerConnection::fireActivateEvent(uint64_t serverConnectionIdentifier, ServiceWorkerIdentifier identifier)
+void WebSWContextManagerConnection::fireActivateEvent(ServiceWorkerIdentifier identifier)
 {
-    UNUSED_PARAM(serverConnectionIdentifier);
     SWContextManager::singleton().fireActivateEvent(identifier);
 }
 
@@ -168,28 +164,17 @@ void WebSWContextManagerConnection::postMessageToServiceWorkerClient(const Servi
 
 void WebSWContextManagerConnection::didFinishInstall(ServiceWorkerIdentifier serviceWorkerIdentifier, bool wasSuccessful)
 {
-    auto* threadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier);
-    ASSERT(threadProxy);
-
-    auto& data = threadProxy->thread().contextData();
-    m_connectionToStorageProcess->send(Messages::StorageProcess::DidFinishServiceWorkerInstall(threadProxy->thread().serverConnectionIdentifier(), data.registrationKey, serviceWorkerIdentifier, wasSuccessful), 0);
+    m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::DidFinishInstall(serviceWorkerIdentifier, wasSuccessful), 0);
 }
 
 void WebSWContextManagerConnection::didFinishActivation(ServiceWorkerIdentifier serviceWorkerIdentifier)
 {
-    auto* threadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier);
-    ASSERT(threadProxy);
-
-    auto& data = threadProxy->thread().contextData();
-    m_connectionToStorageProcess->send(Messages::StorageProcess::DidFinishServiceWorkerActivation(threadProxy->thread().serverConnectionIdentifier(), data.registrationKey, serviceWorkerIdentifier), 0);
+    m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::DidFinishActivation(serviceWorkerIdentifier), 0);
 }
 
 void WebSWContextManagerConnection::setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents)
 {
-    auto* threadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier);
-    ASSERT(threadProxy);
-
-    m_connectionToStorageProcess->send(Messages::StorageProcess::SetServiceWorkerHasPendingEvents(threadProxy->thread().serverConnectionIdentifier(), serviceWorkerIdentifier, hasPendingEvents), 0);
+    m_connectionToStorageProcess->send(Messages::WebSWServerToContextConnection::SetServiceWorkerHasPendingEvents(serviceWorkerIdentifier, hasPendingEvents), 0);
 }
 
 } // namespace WebCore
index 8da6a5d..fa2ac83 100644 (file)
@@ -58,11 +58,11 @@ private:
 
     // IPC messages.
     void serviceWorkerStartedWithMessage(WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
-    void installServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
+    void installServiceWorker(const WebCore::ServiceWorkerContextData&);
     void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, const WebCore::ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
-    void fireInstallEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier);
-    void fireActivateEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier);
+    void fireInstallEvent(WebCore::ServiceWorkerIdentifier);
+    void fireActivateEvent(WebCore::ServiceWorkerIdentifier);
 
     Ref<IPC::Connection> m_connectionToStorageProcess;
     uint64_t m_pageID { 0 };
index 5d2555a..1498d27 100644 (file)
 #if ENABLE(SERVICE_WORKER)
 
 messages -> WebSWContextManagerConnection {
-    InstallServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
+    InstallServiceWorker(struct WebCore::ServiceWorkerContextData contextData)
     StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
     PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, String sourceOrigin)
-    FireInstallEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier identifier)
-    FireActivateEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier identifier)
+    FireInstallEvent(WebCore::ServiceWorkerIdentifier identifier)
+    FireActivateEvent(WebCore::ServiceWorkerIdentifier identifier)
 }
 
 #endif