Title: [224804] trunk
Revision
224804
Author
[email protected]
Date
2017-11-13 22:21:43 -0800 (Mon, 13 Nov 2017)

Log Message

Send ServiceWorkerData structs to the WebProcesses instead of ServiceWorkerIdentifiers
https://bugs.webkit.org/show_bug.cgi?id=179649

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

Rebaseline a couple of WPT tests that are now passing.

* web-platform-tests/service-workers/service-worker/register-wait-forever-in-install-worker.https-expected.txt:
* web-platform-tests/service-workers/service-worker/skip-waiting.https-expected.txt:

Source/WebCore:

Send ServiceWorkerData structs to the WebProcesses instead of ServiceWorkerIdentifiers so that the
WebProcesses can correctly construct ServiceWorker objects, with the right attributes / state.

No new tests, rebaselined existing tests.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::getOrCreate):
(WebCore::ServiceWorker::ServiceWorker):
(WebCore::ServiceWorker::~ServiceWorker):
(WebCore::ServiceWorker::scheduleTaskToUpdateState):
(WebCore::ServiceWorker::postMessage):
* workers/service/ServiceWorker.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::scheduleTaskToUpdateRegistrationState):
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerData.cpp: Copied from Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp.
(WebCore::ServiceWorkerData::isolatedCopy const):
* workers/service/ServiceWorkerData.h: Copied from Source/WebCore/workers/service/server/SWServerWorker.cpp.
(WebCore::ServiceWorkerData::encode const):
(WebCore::ServiceWorkerData::decode):
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
(WebCore::ServiceWorkerRegistration::updateStateFromServer):
* workers/service/ServiceWorkerRegistration.h:
* workers/service/ServiceWorkerRegistrationData.cpp:
(WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
* workers/service/ServiceWorkerRegistrationData.h:
(WebCore::ServiceWorkerRegistrationData::encode const):
(WebCore::ServiceWorkerRegistrationData::decode):
* workers/service/server/SWClientConnection.cpp:
(WebCore::SWClientConnection::postMessageToServiceWorkerClient):
(WebCore::SWClientConnection::updateRegistrationState):
* workers/service/server/SWClientConnection.h:
* workers/service/server/SWServer.h:
* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::updateRegistrationState):
(WebCore::SWServerRegistration::data const):
* workers/service/server/SWServerWorker.cpp:
(WebCore::SWServerWorker::SWServerWorker):
(WebCore::m_script):
* workers/service/server/SWServerWorker.h:
(WebCore::SWServerWorker::scriptURL const):
(WebCore::SWServerWorker::type const):
(WebCore::SWServerWorker::identifier const):
(WebCore::SWServerWorker::state const):
(WebCore::SWServerWorker::setState):
(WebCore::SWServerWorker::data const):

Source/WebKit:

* Shared/WebCoreArgumentCoders.h:
* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::updateRegistrationStateInClient):
(WebKit::WebSWServerConnection::postMessageToServiceWorkerClient):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::postMessageToServiceWorkerClient):
* WebProcess/Storage/WebSWClientConnection.h:
* WebProcess/Storage/WebSWClientConnection.messages.in:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224803 => 224804)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-14 06:21:43 UTC (rev 224804)
@@ -1,3 +1,15 @@
+2017-11-13  Chris Dumez  <[email protected]>
+
+        Send ServiceWorkerData structs to the WebProcesses instead of ServiceWorkerIdentifiers
+        https://bugs.webkit.org/show_bug.cgi?id=179649
+
+        Reviewed by Brady Eidson.
+
+        Rebaseline a couple of WPT tests that are now passing.
+
+        * web-platform-tests/service-workers/service-worker/register-wait-forever-in-install-worker.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/skip-waiting.https-expected.txt:
+
 2017-11-13  Youenn Fablet  <[email protected]>
 
         matchRegistration does not need to go to StorageProcess if no service worker is registered

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-wait-forever-in-install-worker.https-expected.txt (224803 => 224804)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-wait-forever-in-install-worker.https-expected.txt	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/register-wait-forever-in-install-worker.https-expected.txt	2017-11-14 06:21:43 UTC (rev 224804)
@@ -1,3 +1,3 @@
 
-FAIL register worker that calls waitUntil with a promise that never resolves in oninstall assert_equals: expected "https://localhost:9443/service-workers/service-worker/resources/empty-worker.js" but got "https://localhost:9443/service-workers/service-worker/resources/wait-forever-in-install-worker.js"
+PASS register worker that calls waitUntil with a promise that never resolves in oninstall 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting.https-expected.txt (224803 => 224804)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting.https-expected.txt	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/skip-waiting.https-expected.txt	2017-11-14 06:21:43 UTC (rev 224804)
@@ -1,3 +1,3 @@
 
-FAIL Test skipWaiting with both active and waiting workers assert_equals: Worker with url2 should be waiting expected "https://localhost:9443/service-workers/service-worker/resources/empty-worker.js" but got "https://localhost:9443/service-workers/service-worker/resources/empty.js"
+PASS Test skipWaiting with both active and waiting workers 
 

Modified: trunk/Source/WebCore/ChangeLog (224803 => 224804)


--- trunk/Source/WebCore/ChangeLog	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/ChangeLog	2017-11-14 06:21:43 UTC (rev 224804)
@@ -1,3 +1,60 @@
+2017-11-13  Chris Dumez  <[email protected]>
+
+        Send ServiceWorkerData structs to the WebProcesses instead of ServiceWorkerIdentifiers
+        https://bugs.webkit.org/show_bug.cgi?id=179649
+
+        Reviewed by Brady Eidson.
+
+        Send ServiceWorkerData structs to the WebProcesses instead of ServiceWorkerIdentifiers so that the
+        WebProcesses can correctly construct ServiceWorker objects, with the right attributes / state.
+
+        No new tests, rebaselined existing tests.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/service/ServiceWorker.cpp:
+        (WebCore::ServiceWorker::getOrCreate):
+        (WebCore::ServiceWorker::ServiceWorker):
+        (WebCore::ServiceWorker::~ServiceWorker):
+        (WebCore::ServiceWorker::scheduleTaskToUpdateState):
+        (WebCore::ServiceWorker::postMessage):
+        * workers/service/ServiceWorker.h:
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::scheduleTaskToUpdateRegistrationState):
+        * workers/service/ServiceWorkerContainer.h:
+        * workers/service/ServiceWorkerData.cpp: Copied from Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp.
+        (WebCore::ServiceWorkerData::isolatedCopy const):
+        * workers/service/ServiceWorkerData.h: Copied from Source/WebCore/workers/service/server/SWServerWorker.cpp.
+        (WebCore::ServiceWorkerData::encode const):
+        (WebCore::ServiceWorkerData::decode):
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
+        (WebCore::ServiceWorkerRegistration::updateStateFromServer):
+        * workers/service/ServiceWorkerRegistration.h:
+        * workers/service/ServiceWorkerRegistrationData.cpp:
+        (WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
+        * workers/service/ServiceWorkerRegistrationData.h:
+        (WebCore::ServiceWorkerRegistrationData::encode const):
+        (WebCore::ServiceWorkerRegistrationData::decode):
+        * workers/service/server/SWClientConnection.cpp:
+        (WebCore::SWClientConnection::postMessageToServiceWorkerClient):
+        (WebCore::SWClientConnection::updateRegistrationState):
+        * workers/service/server/SWClientConnection.h:
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::SWServerRegistration::updateRegistrationState):
+        (WebCore::SWServerRegistration::data const):
+        * workers/service/server/SWServerWorker.cpp:
+        (WebCore::SWServerWorker::SWServerWorker):
+        (WebCore::m_script):
+        * workers/service/server/SWServerWorker.h:
+        (WebCore::SWServerWorker::scriptURL const):
+        (WebCore::SWServerWorker::type const):
+        (WebCore::SWServerWorker::identifier const):
+        (WebCore::SWServerWorker::state const):
+        (WebCore::SWServerWorker::setState):
+        (WebCore::SWServerWorker::data const):
+
 2017-11-13  Ryosuke Niwa  <[email protected]>
 
         iOS: Enable release asserts in updateStyleIfNeeded() and updateLayout() for WebKit2

Modified: trunk/Source/WebCore/Sources.txt (224803 => 224804)


--- trunk/Source/WebCore/Sources.txt	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/Sources.txt	2017-11-14 06:21:43 UTC (rev 224804)
@@ -2172,6 +2172,7 @@
 workers/service/ServiceWorkerClients.cpp
 workers/service/ServiceWorkerContainer.cpp
 workers/service/ServiceWorkerContextData.cpp
+workers/service/ServiceWorkerData.cpp
 workers/service/ServiceWorkerGlobalScope.cpp
 workers/service/ServiceWorkerJob.cpp
 workers/service/ServiceWorkerJobData.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (224803 => 224804)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-11-14 06:21:43 UTC (rev 224804)
@@ -2243,6 +2243,7 @@
 		83D35AEC1C7187FA00F70D5A /* XMLHttpRequestEventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D35AEA1C7187ED00F70D5A /* XMLHttpRequestEventTarget.h */; };
 		83D35AF21C718D9000F70D5A /* JSXMLHttpRequestEventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D35AF01C718D8400F70D5A /* JSXMLHttpRequestEventTarget.h */; };
 		83E359A21BB1031D002CEB98 /* JSHTMLTimeElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E359A01BB1031D002CEB98 /* JSHTMLTimeElement.h */; };
+		83E866801FBA565B008855C5 /* ServiceWorkerData.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E8667D1FBA563F008855C5 /* ServiceWorkerData.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		83EE598F1F50958E003E8B30 /* JSErrorCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 83EE598B1F50958B003E8B30 /* JSErrorCallback.h */; };
 		83FB33711F508A5400986E54 /* FileSystemDirectoryEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FB336D1F508A4E00986E54 /* FileSystemDirectoryEntry.h */; };
 		83FB33731F508A5800986E54 /* FileSystemEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FB336F1F508A4E00986E54 /* FileSystemEntry.h */; };
@@ -9534,6 +9535,8 @@
 		83E045EF1DAA104F00B0D8B9 /* JSUIEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSUIEventInit.h; sourceTree = "<group>"; };
 		83E359A01BB1031D002CEB98 /* JSHTMLTimeElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLTimeElement.h; sourceTree = "<group>"; };
 		83E359A11BB1031D002CEB98 /* JSHTMLTimeElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLTimeElement.cpp; sourceTree = "<group>"; };
+		83E8667D1FBA563F008855C5 /* ServiceWorkerData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerData.h; sourceTree = "<group>"; };
+		83E8667F1FBA5640008855C5 /* ServiceWorkerData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerData.cpp; sourceTree = "<group>"; };
 		83E959E11B8BC22B004D9385 /* NativeNodeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeNodeFilter.h; sourceTree = "<group>"; };
 		83E9B3001DA5A51E00FFE8F6 /* JSScrollToOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollToOptions.cpp; sourceTree = "<group>"; };
 		83E9B3011DA5A51E00FFE8F6 /* JSScrollToOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollToOptions.h; sourceTree = "<group>"; };
@@ -17296,6 +17299,8 @@
 				51F175561F3EBC0C00C74950 /* ServiceWorkerContainer.idl */,
 				517C87161F8FD4D300EB8076 /* ServiceWorkerContextData.cpp */,
 				51CA7EE71F8832E0003D3131 /* ServiceWorkerContextData.h */,
+				83E8667F1FBA5640008855C5 /* ServiceWorkerData.cpp */,
+				83E8667D1FBA563F008855C5 /* ServiceWorkerData.h */,
 				517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */,
 				51F175551F3EBC0C00C74950 /* ServiceWorkerGlobalScope.cpp */,
 				51F175541F3EBC0C00C74950 /* ServiceWorkerGlobalScope.h */,
@@ -28980,6 +28985,7 @@
 				8369FDFC1FA102E300C1FF1F /* ServiceWorkerClientType.h in Headers */,
 				51F1755F1F3EBC8300C74950 /* ServiceWorkerContainer.h in Headers */,
 				51CA7EE91F883390003D3131 /* ServiceWorkerContextData.h in Headers */,
+				83E866801FBA565B008855C5 /* ServiceWorkerData.h in Headers */,
 				A52B348F1FA3BDA6008B6246 /* ServiceWorkerDebuggable.h in Headers */,
 				419ACF921F97E7DA009F1A83 /* ServiceWorkerFetch.h in Headers */,
 				517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */,

Modified: trunk/Source/WebCore/workers/service/ServiceWorker.cpp (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorker.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -53,13 +53,23 @@
     return allWorkersMap;
 }
 
-ServiceWorker::ServiceWorker(ScriptExecutionContext& context, ServiceWorkerIdentifier identifier, const URL& scriptURL, State state)
+Ref<ServiceWorker> ServiceWorker::getOrCreate(ScriptExecutionContext& context, ServiceWorkerData&& data)
+{
+    auto it = allWorkers().find(data.identifier);
+    if (it != allWorkers().end()) {
+        for (auto& worker : it->value) {
+            if (worker->scriptExecutionContext() == &context)
+                return *worker;
+        }
+    }
+    return adoptRef(*new ServiceWorker(context, WTFMove(data)));
+}
+
+ServiceWorker::ServiceWorker(ScriptExecutionContext& context, ServiceWorkerData&& data)
     : ContextDestructionObserver(&context)
-    , m_identifier(identifier)
-    , m_scriptURL(scriptURL)
-    , m_state(state)
+    , m_data(WTFMove(data))
 {
-    auto result = mutableAllWorkers().ensure(identifier, [] {
+    auto result = mutableAllWorkers().ensure(identifier(), [] {
         return HashSet<ServiceWorker*>();
     });
     result.iterator->value.add(this);
@@ -67,7 +77,7 @@
 
 ServiceWorker::~ServiceWorker()
 {
-    auto iterator = mutableAllWorkers().find(m_identifier);
+    auto iterator = mutableAllWorkers().find(identifier());
 
     ASSERT(iterator->value.contains(this));
     iterator->value.remove(this);
@@ -86,7 +96,7 @@
         return;
 
     context->postTask([this, protectedThis = makeRef(*this), state](ScriptExecutionContext&) {
-        m_state = state;
+        m_data.state = state;
         dispatchEvent(Event::create(eventNames().statechangeEvent, false, false));
     });
 }
@@ -117,7 +127,7 @@
         return Exception { NotSupportedError, ASCIILiteral("Passing MessagePort objects to postMessage is not yet supported") };
 
     auto& swConnection = ServiceWorkerProvider::singleton().serviceWorkerConnectionForSession(context.sessionID());
-    swConnection.postMessageToServiceWorkerGlobalScope(m_identifier, message.releaseReturnValue(), context);
+    swConnection.postMessageToServiceWorkerGlobalScope(identifier(), message.releaseReturnValue(), context);
 
     return { };
 }

Modified: trunk/Source/WebCore/workers/service/ServiceWorker.h (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorker.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -29,8 +29,7 @@
 
 #include "ContextDestructionObserver.h"
 #include "EventTarget.h"
-#include "ServiceWorkerIdentifier.h"
-#include "ServiceWorkerTypes.h"
+#include "ServiceWorkerData.h"
 #include "URL.h"
 #include <heap/Strong.h>
 #include <wtf/RefCounted.h>
@@ -46,22 +45,19 @@
 class ServiceWorker final : public RefCounted<ServiceWorker>, public EventTargetWithInlineData, public ContextDestructionObserver {
 public:
     using State = ServiceWorkerState;
-    static Ref<ServiceWorker> create(ScriptExecutionContext& context, ServiceWorkerIdentifier identifier, const URL& scriptURL, State state = State::Installing)
-    {
-        return adoptRef(*new ServiceWorker(context, identifier, scriptURL, state));
-    }
+    static Ref<ServiceWorker> getOrCreate(ScriptExecutionContext&, ServiceWorkerData&&);
 
     virtual ~ServiceWorker();
 
-    const URL& scriptURL() const { return m_scriptURL; }
+    const URL& scriptURL() const { return m_data.scriptURL; }
 
-    State state() const { return m_state; }
+    State state() const { return m_data.state; }
     
     void scheduleTaskToUpdateState(State);
 
     ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
 
-    ServiceWorkerIdentifier identifier() const { return m_identifier; }
+    ServiceWorkerIdentifier identifier() const { return m_data.identifier; }
 
     using RefCounted::ref;
     using RefCounted::deref;
@@ -69,7 +65,7 @@
     static const HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& allWorkers();
 
 private:
-    ServiceWorker(ScriptExecutionContext&, ServiceWorkerIdentifier, const URL& scriptURL, State);
+    ServiceWorker(ScriptExecutionContext&, ServiceWorkerData&&);
     static HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& mutableAllWorkers();
 
     EventTargetInterface eventTargetInterface() const final;
@@ -77,9 +73,7 @@
     void refEventTarget() final { ref(); }
     void derefEventTarget() final { deref(); }
 
-    ServiceWorkerIdentifier m_identifier;
-    URL m_scriptURL;
-    State m_state;
+    ServiceWorkerData m_data;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -241,15 +241,19 @@
     });
 }
 
-void ServiceWorkerContainer::scheduleTaskToUpdateRegistrationState(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerIdentifier>& serviceWorkerIdentifier)
+void ServiceWorkerContainer::scheduleTaskToUpdateRegistrationState(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerData>& serviceWorkerData)
 {
     auto* context = scriptExecutionContext();
     if (!context)
         return;
 
-    context->postTask([this, protectedThis = makeRef(*this), identifier, state, serviceWorkerIdentifier](ScriptExecutionContext&) {
+    RefPtr<ServiceWorker> serviceWorker;
+    if (serviceWorkerData)
+        serviceWorker = ServiceWorker::getOrCreate(*context, ServiceWorkerData { *serviceWorkerData });
+
+    context->postTask([this, protectedThis = makeRef(*this), identifier, state, serviceWorker = WTFMove(serviceWorker)](ScriptExecutionContext&) mutable {
         if (auto* registration = m_registrations.get(identifier))
-            registration->updateStateFromServer(state, serviceWorkerIdentifier);
+            registration->updateStateFromServer(state, WTFMove(serviceWorker));
     });
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -65,7 +65,7 @@
     void updateRegistration(const URL& scopeURL, const URL& scriptURL, WorkerType, Ref<DeferredPromise>&&);
 
     void getRegistration(const String& clientURL, Ref<DeferredPromise>&&);
-    void scheduleTaskToUpdateRegistrationState(ServiceWorkerRegistrationIdentifier, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerIdentifier>&);
+    void scheduleTaskToUpdateRegistrationState(ServiceWorkerRegistrationIdentifier, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerData>&);
     void scheduleTaskToFireUpdateFoundEvent(ServiceWorkerRegistrationIdentifier);
 
     using RegistrationsPromise = DOMPromiseDeferred<IDLSequence<IDLInterface<ServiceWorkerRegistration>>>;

Copied: trunk/Source/WebCore/workers/service/ServiceWorkerData.cpp (from rev 224803, trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp) (0 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerData.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerData.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(SERVICE_WORKER)
+#include "ServiceWorkerData.h"
+
+namespace WebCore {
+
+ServiceWorkerData ServiceWorkerData::isolatedCopy() const
+{
+    return {
+        identifier,
+        scriptURL.isolatedCopy(),
+        state,
+        type
+    };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Copied: trunk/Source/WebCore/workers/service/ServiceWorkerData.h (from rev 224803, trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp) (0 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerData.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerData.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -0,0 +1,83 @@
+/*
+ * 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 "URL.h"
+#include "WorkerType.h"
+
+namespace WebCore {
+
+struct ServiceWorkerData {
+    ServiceWorkerIdentifier identifier;
+    URL scriptURL;
+    ServiceWorkerState state;
+    WorkerType type;
+
+    ServiceWorkerData isolatedCopy() const;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<ServiceWorkerData> decode(Decoder&);
+};
+
+template<class Encoder>
+void ServiceWorkerData::encode(Encoder& encoder) const
+{
+    encoder << identifier << scriptURL << state << type;
+}
+
+template<class Decoder>
+std::optional<ServiceWorkerData> ServiceWorkerData::decode(Decoder& decoder)
+{
+    std::optional<ServiceWorkerIdentifier> identifier;
+    decoder >> identifier;
+    if (!identifier)
+        return std::nullopt;
+
+    std::optional<URL> scriptURL;
+    decoder >> scriptURL;
+    if (!scriptURL)
+        return std::nullopt;
+
+    std::optional<ServiceWorkerState> state;
+    decoder >> state;
+    if (!state)
+        return std::nullopt;
+
+    std::optional<WorkerType> type;
+    decoder >> type;
+    if (!type)
+        return std::nullopt;
+
+    return { { WTFMove(*identifier), WTFMove(*scriptURL), WTFMove(*state), WTFMove(*type) } };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -45,15 +45,12 @@
     LOG(ServiceWorker, "Creating registration %p for registration key %s", this, m_registrationData.key.loggingString().utf8().data());
     suspendIfNeeded();
 
-    // FIXME: Reconcile worker state properly (see below)
-    if (m_registrationData.installingServiceWorkerIdentifier)
-        m_installingWorker = ServiceWorker::create(context, *m_registrationData.installingServiceWorkerIdentifier, m_registrationData.scriptURL, ServiceWorker::State::Installing);
-    if (m_registrationData.waitingServiceWorkerIdentifier)
-        m_waitingWorker = ServiceWorker::create(context, *m_registrationData.waitingServiceWorkerIdentifier, m_registrationData.scriptURL, ServiceWorker::State::Installed);
-    if (m_registrationData.activeServiceWorkerIdentifier) {
-        // FIXME: Activating or Activated? This is why we have to have more data here...
-        m_activeWorker = ServiceWorker::create(context, *m_registrationData.activeServiceWorkerIdentifier, m_registrationData.scriptURL, ServiceWorker::State::Activated);
-    }
+    if (m_registrationData.installingWorker)
+        m_installingWorker = ServiceWorker::getOrCreate(context, WTFMove(*m_registrationData.installingWorker));
+    if (m_registrationData.waitingWorker)
+        m_waitingWorker = ServiceWorker::getOrCreate(context, WTFMove(*m_registrationData.waitingWorker));
+    if (m_registrationData.activeWorker)
+        m_activeWorker = ServiceWorker::getOrCreate(context, WTFMove(*m_registrationData.activeWorker));
 
     // FIXME: Implement proper selection of service workers.
     context.setActiveServiceWorker(getNewestWorker());
@@ -146,30 +143,17 @@
     container->removeRegistration(m_registrationData.scopeURL, WTFMove(promise));
 }
 
-void ServiceWorkerRegistration::updateStateFromServer(ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
+void ServiceWorkerRegistration::updateStateFromServer(ServiceWorkerRegistrationState state, RefPtr<ServiceWorker>&& serviceWorker)
 {
-    auto* context = scriptExecutionContext();
-    if (!context)
-        return;
-
-    RefPtr<ServiceWorker> worker;
-    if (serviceWorkerIdentifier) {
-        auto* newestWorker = getNewestWorker();
-        if (newestWorker && newestWorker->identifier() == *serviceWorkerIdentifier)
-            worker = newestWorker;
-        else
-            worker = ServiceWorker::create(*context, *serviceWorkerIdentifier, m_registrationData.scriptURL);
-    }
-
     switch (state) {
     case ServiceWorkerRegistrationState::Installing:
-        m_installingWorker = WTFMove(worker);
+        m_installingWorker = WTFMove(serviceWorker);
         break;
     case ServiceWorkerRegistrationState::Waiting:
-        m_waitingWorker = WTFMove(worker);
+        m_waitingWorker = WTFMove(serviceWorker);
         break;
     case ServiceWorkerRegistrationState::Active:
-        m_activeWorker = WTFMove(worker);
+        m_activeWorker = WTFMove(serviceWorker);
         break;
     }
 }

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -67,7 +67,7 @@
     
     const ServiceWorkerRegistrationData& data() const { return m_registrationData; }
 
-    void updateStateFromServer(ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>);
+    void updateStateFromServer(ServiceWorkerRegistrationState, RefPtr<ServiceWorker>&&);
 
 private:
     ServiceWorkerRegistration(ScriptExecutionContext&, Ref<ServiceWorkerContainer>&&, ServiceWorkerRegistrationData&&);

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -36,11 +36,10 @@
         key.isolatedCopy(),
         identifier,
         scopeURL.isolatedCopy(),
-        scriptURL.isolatedCopy(),
         updateViaCache,
-        installingServiceWorkerIdentifier,
-        waitingServiceWorkerIdentifier,
-        activeServiceWorkerIdentifier,
+        installingWorker ? std::optional<ServiceWorkerData>(installingWorker->isolatedCopy()) : std::nullopt,
+        waitingWorker ? std::optional<ServiceWorkerData>(waitingWorker->isolatedCopy()) : std::nullopt,
+        activeWorker ? std::optional<ServiceWorkerData>(activeWorker->isolatedCopy()) : std::nullopt,
     };
 }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h (224803 => 224804)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -27,6 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "ServiceWorkerData.h"
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerRegistrationKey.h"
 #include "ServiceWorkerTypes.h"
@@ -39,12 +40,11 @@
     ServiceWorkerRegistrationKey key;
     ServiceWorkerRegistrationIdentifier identifier;
     URL scopeURL;
-    URL scriptURL;
     ServiceWorkerUpdateViaCache updateViaCache;
 
-    std::optional<ServiceWorkerIdentifier> installingServiceWorkerIdentifier;
-    std::optional<ServiceWorkerIdentifier> waitingServiceWorkerIdentifier;
-    std::optional<ServiceWorkerIdentifier> activeServiceWorkerIdentifier;
+    std::optional<ServiceWorkerData> installingWorker;
+    std::optional<ServiceWorkerData> waitingWorker;
+    std::optional<ServiceWorkerData> activeWorker;
 
     ServiceWorkerRegistrationData isolatedCopy() const;
 
@@ -56,7 +56,7 @@
 template<class Encoder>
 void ServiceWorkerRegistrationData::encode(Encoder& encoder) const
 {
-    encoder << key << identifier << scopeURL << scriptURL << updateViaCache << installingServiceWorkerIdentifier << waitingServiceWorkerIdentifier << activeServiceWorkerIdentifier;
+    encoder << key << identifier << scopeURL << updateViaCache << installingWorker << waitingWorker << activeWorker;
 }
 
 template<class Decoder>
@@ -77,32 +77,27 @@
     if (!scopeURL)
         return std::nullopt;
 
-    std::optional<URL> scriptURL;
-    decoder >> scriptURL;
-    if (!scriptURL)
-        return std::nullopt;
-
     std::optional<ServiceWorkerUpdateViaCache> updateViaCache;
     decoder >> updateViaCache;
     if (!updateViaCache)
         return std::nullopt;
 
-    std::optional<std::optional<ServiceWorkerIdentifier>> installingServiceWorkerIdentifier;
-    decoder >> installingServiceWorkerIdentifier;
-    if (!installingServiceWorkerIdentifier)
+    std::optional<std::optional<ServiceWorkerData>> installingWorker;
+    decoder >> installingWorker;
+    if (!installingWorker)
         return std::nullopt;
 
-    std::optional<std::optional<ServiceWorkerIdentifier>> waitingServiceWorkerIdentifier;
-    decoder >> waitingServiceWorkerIdentifier;
-    if (!waitingServiceWorkerIdentifier)
+    std::optional<std::optional<ServiceWorkerData>> waitingWorker;
+    decoder >> waitingWorker;
+    if (!waitingWorker)
         return std::nullopt;
 
-    std::optional<std::optional<ServiceWorkerIdentifier>> activeServiceWorkerIdentifier;
-    decoder >> activeServiceWorkerIdentifier;
-    if (!activeServiceWorkerIdentifier)
+    std::optional<std::optional<ServiceWorkerData>> activeWorker;
+    decoder >> activeWorker;
+    if (!activeWorker)
         return std::nullopt;
 
-    return { { WTFMove(*key), WTFMove(*identifier), WTFMove(*scopeURL), WTFMove(*scriptURL), WTFMove(*updateViaCache), WTFMove(*installingServiceWorkerIdentifier), WTFMove(*waitingServiceWorkerIdentifier), WTFMove(*activeServiceWorkerIdentifier) } };
+    return { { WTFMove(*key), WTFMove(*identifier), WTFMove(*scopeURL), WTFMove(*updateViaCache), WTFMove(*installingWorker), WTFMove(*waitingWorker), WTFMove(*activeWorker) } };
 }
 
 } // namespace WTF

Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp (224803 => 224804)


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -118,7 +118,7 @@
     job->startScriptFetch();
 }
 
-void SWClientConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, Ref<SerializedScriptValue>&& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
+void SWClientConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, Ref<SerializedScriptValue>&& message, ServiceWorkerData&& sourceData, const String& sourceOrigin)
 {
     // FIXME: destinationScriptExecutionContextIdentifier can only identify a Document at the moment.
     auto* destinationDocument = Document::allDocumentsMap().get(destinationScriptExecutionContextIdentifier);
@@ -129,14 +129,7 @@
     if (!container)
         return;
 
-    std::optional<MessageEventSource> source;
-    auto* activeServiceWorker = destinationDocument->activeServiceWorker();
-    if (activeServiceWorker && activeServiceWorker->identifier() == sourceIdentifier)
-        source = MessageEventSource { RefPtr<ServiceWorker> { activeServiceWorker } };
-    else {
-        // FIXME: Pass in valid scriptURL.
-        source = MessageEventSource { RefPtr<ServiceWorker> { ServiceWorker::create(*destinationDocument, sourceIdentifier, URL()) } };
-    }
+    MessageEventSource source = RefPtr<ServiceWorker> { ServiceWorker::getOrCreate(*destinationDocument, WTFMove(sourceData)) };
 
     // FIXME: We should pass in ports.
     auto messageEvent = MessageEvent::create({ }, WTFMove(message), sourceOrigin, { }, WTFMove(source));
@@ -152,10 +145,10 @@
     }
 }
 
-void SWClientConnection::updateRegistrationState(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
+void SWClientConnection::updateRegistrationState(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerData>& serviceWorkerData)
 {
     forEachContainer([&](ServiceWorkerContainer& container) {
-        container.scheduleTaskToUpdateRegistrationState(identifier, state, serviceWorkerIdentifier);
+        container.scheduleTaskToUpdateRegistrationState(identifier, state, serviceWorkerData);
     });
 }
 

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


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -44,6 +44,7 @@
 enum class ServiceWorkerState;
 enum class ShouldNotifyWhenResolved;
 struct ExceptionData;
+struct ServiceWorkerData;
 struct ServiceWorkerFetchResult;
 struct ServiceWorkerRegistrationData;
 
@@ -74,8 +75,8 @@
     WEBCORE_EXPORT void registrationJobResolvedInServer(uint64_t jobIdentifier, ServiceWorkerRegistrationData&&, ShouldNotifyWhenResolved);
     WEBCORE_EXPORT void unregistrationJobResolvedInServer(uint64_t jobIdentifier, bool unregistrationResult);
     WEBCORE_EXPORT void startScriptFetchForServer(uint64_t jobIdentifier);
-    WEBCORE_EXPORT void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, Ref<SerializedScriptValue>&& message, ServiceWorkerIdentifier source, const String& sourceOrigin);
-    WEBCORE_EXPORT void updateRegistrationState(ServiceWorkerRegistrationIdentifier, ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>);
+    WEBCORE_EXPORT void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, Ref<SerializedScriptValue>&& message, ServiceWorkerData&& source, const String& sourceOrigin);
+    WEBCORE_EXPORT void updateRegistrationState(ServiceWorkerRegistrationIdentifier, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerData>&);
     WEBCORE_EXPORT void updateWorkerState(ServiceWorkerIdentifier, ServiceWorkerState);
     WEBCORE_EXPORT void fireUpdateFoundEvent(ServiceWorkerRegistrationIdentifier);
 

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


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -67,7 +67,7 @@
         const SWServerRegistration* doRegistrationMatching(const SecurityOriginData& topOrigin, const URL& clientURL) const { return m_server.doRegistrationMatching(topOrigin, clientURL); }
 
         // Messages to the client WebProcess
-        virtual void updateRegistrationStateInClient(ServiceWorkerRegistrationIdentifier, ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>) = 0;
+        virtual void updateRegistrationStateInClient(ServiceWorkerRegistrationIdentifier, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerData>&) = 0;
         virtual void updateWorkerStateInClient(ServiceWorkerIdentifier, ServiceWorkerState) = 0;
         virtual void fireUpdateFoundEvent(ServiceWorkerRegistrationIdentifier) = 0;
 

Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (224803 => 224804)


--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -81,12 +81,12 @@
         break;
     };
 
-    std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier;
+    std::optional<ServiceWorkerData> serviceWorkerData;
     if (worker)
-        serviceWorkerIdentifier = worker->identifier();
+        serviceWorkerData = worker->data();
 
     forEachConnection([&](auto& connection) {
-        connection.updateRegistrationStateInClient(identifier(), state, serviceWorkerIdentifier);
+        connection.updateRegistrationStateInClient(identifier(), state, serviceWorkerData);
     });
 }
 
@@ -118,19 +118,19 @@
 
 ServiceWorkerRegistrationData SWServerRegistration::data() const
 {
-    std::optional<ServiceWorkerIdentifier> installingID;
+    std::optional<ServiceWorkerData> installingWorkerData;
     if (m_installingWorker)
-        installingID = m_installingWorker->identifier();
+        installingWorkerData = m_installingWorker->data();
 
-    std::optional<ServiceWorkerIdentifier> waitingID;
+    std::optional<ServiceWorkerData> waitingWorkerData;
     if (m_waitingWorker)
-        waitingID = m_waitingWorker->identifier();
+        waitingWorkerData = m_waitingWorker->data();
 
-    std::optional<ServiceWorkerIdentifier> activeID;
+    std::optional<ServiceWorkerData> activeWorkerData;
     if (m_activeWorker)
-        activeID = m_activeWorker->identifier();
+        activeWorkerData = m_activeWorker->data();
 
-    return { m_registrationKey, identifier(), m_scopeURL, m_scriptURL, m_updateViaCache, installingID, waitingID, activeID };
+    return { m_registrationKey, identifier(), m_scopeURL, m_updateViaCache, WTFMove(installingWorkerData), WTFMove(waitingWorkerData), WTFMove(activeWorkerData) };
 }
 
 void SWServerRegistration::addClientServiceWorkerRegistration(uint64_t connectionIdentifier)

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


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -43,14 +43,12 @@
     return allWorkers().get(identifier);
 }
 
-SWServerWorker::SWServerWorker(SWServer& server, const ServiceWorkerRegistrationKey& registrationKey, SWServerToContextConnectionIdentifier contextConnectionIdentifier, const URL& url, const String& script, WorkerType type, ServiceWorkerIdentifier identifier)
+SWServerWorker::SWServerWorker(SWServer& server, const ServiceWorkerRegistrationKey& registrationKey, SWServerToContextConnectionIdentifier contextConnectionIdentifier, const URL& scriptURL, const String& script, WorkerType type, ServiceWorkerIdentifier identifier)
     : m_server(server)
     , m_registrationKey(registrationKey)
     , m_contextConnectionIdentifier(contextConnectionIdentifier)
-    , m_scriptURL(url)
+    , m_data { identifier, scriptURL, ServiceWorkerState::Redundant, type }
     , m_script(script)
-    , m_identifier(identifier)
-    , m_type(type)
 {
     auto result = allWorkers().add(identifier, this);
     ASSERT_UNUSED(result, result.isNewEntry);
@@ -58,7 +56,7 @@
 
 SWServerWorker::~SWServerWorker()
 {
-    auto taken = allWorkers().take(m_identifier);
+    auto taken = allWorkers().take(identifier());
     ASSERT_UNUSED(taken, taken == this);
 }
 

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


--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -27,6 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "ServiceWorkerData.h"
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerRegistrationKey.h"
 #include "ServiceWorkerTypes.h"
@@ -46,21 +47,21 @@
     }
     
     SWServerWorker(const SWServerWorker&) = delete;
-    ~SWServerWorker();
+    WEBCORE_EXPORT ~SWServerWorker();
 
     void terminate();
 
     SWServer& server();
     const ServiceWorkerRegistrationKey& registrationKey() const { return m_registrationKey; }
-    const URL& scriptURL() const { return m_scriptURL; }
+    const URL& scriptURL() const { return m_data.scriptURL; }
     const String& script() const { return m_script; }
-    WorkerType type() const { return m_type; }
+    WorkerType type() const { return m_data.type; }
 
-    ServiceWorkerIdentifier identifier() const { return m_identifier; }
+    ServiceWorkerIdentifier identifier() const { return m_data.identifier; }
     SWServerToContextConnectionIdentifier contextConnectionIdentifier() const { return m_contextConnectionIdentifier; }
 
-    ServiceWorkerState state() const { return m_state; }
-    void setState(ServiceWorkerState state) { m_state = state; }
+    ServiceWorkerState state() const { return m_data.state; }
+    void setState(ServiceWorkerState state) { m_data.state = state; }
 
     bool hasPendingEvents() const { return m_hasPendingEvents; }
     void setHasPendingEvents(bool value) { m_hasPendingEvents = value; }
@@ -72,6 +73,8 @@
 
     WEBCORE_EXPORT static SWServerWorker* existingWorkerForIdentifier(ServiceWorkerIdentifier);
 
+    const ServiceWorkerData& data() const { return m_data; }
+
 private:
     SWServerWorker(SWServer&, const ServiceWorkerRegistrationKey&, SWServerToContextConnectionIdentifier, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
 
@@ -78,12 +81,8 @@
     SWServer& m_server;
     ServiceWorkerRegistrationKey m_registrationKey;
     SWServerToContextConnectionIdentifier m_contextConnectionIdentifier;
-    URL m_scriptURL;
+    ServiceWorkerData m_data;
     String m_script;
-    ServiceWorkerIdentifier m_identifier;
-    WorkerType m_type;
-    
-    ServiceWorkerState m_state { ServiceWorkerState::Redundant };
     bool m_hasPendingEvents { false };
 };
 

Modified: trunk/Source/WebKit/ChangeLog (224803 => 224804)


--- trunk/Source/WebKit/ChangeLog	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebKit/ChangeLog	2017-11-14 06:21:43 UTC (rev 224804)
@@ -1,3 +1,20 @@
+2017-11-13  Chris Dumez  <[email protected]>
+
+        Send ServiceWorkerData structs to the WebProcesses instead of ServiceWorkerIdentifiers
+        https://bugs.webkit.org/show_bug.cgi?id=179649
+
+        Reviewed by Brady Eidson.
+
+        * Shared/WebCoreArgumentCoders.h:
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::updateRegistrationStateInClient):
+        (WebKit::WebSWServerConnection::postMessageToServiceWorkerClient):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::postMessageToServiceWorkerClient):
+        * WebProcess/Storage/WebSWClientConnection.h:
+        * WebProcess/Storage/WebSWClientConnection.messages.in:
+
 2017-11-13  Brady Eidson  <[email protected]>
 
         Massive "Server-process-to-context-process" connection overhaul.

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224803 => 224804)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -91,9 +91,9 @@
     send(Messages::WebSWClientConnection::StartScriptFetchForServer(jobIdentifier));
 }
 
-void WebSWServerConnection::updateRegistrationStateInClient(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
+void WebSWServerConnection::updateRegistrationStateInClient(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerData>& serviceWorkerData)
 {
-    send(Messages::WebSWClientConnection::UpdateRegistrationState(identifier, state, serviceWorkerIdentifier));
+    send(Messages::WebSWClientConnection::UpdateRegistrationState(identifier, state, serviceWorkerData));
 }
 
 void WebSWServerConnection::fireUpdateFoundEvent(ServiceWorkerRegistrationIdentifier identifier)
@@ -142,9 +142,13 @@
     m_contentConnection->send(Messages::ServiceWorkerClientFetch::DidNotHandle { }, fetchIdentifier);
 }
 
-void WebSWServerConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, ServiceWorkerIdentifier sourceServiceWorkerIdentifier, const String& sourceOrigin)
+void WebSWServerConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
 {
-    send(Messages::WebSWClientConnection::PostMessageToServiceWorkerClient { destinationScriptExecutionContextIdentifier, message, sourceServiceWorkerIdentifier, sourceOrigin });
+    auto* sourceServiceWorker = server().workerByID(sourceIdentifier);
+    if (!sourceServiceWorker)
+        return;
+
+    send(Messages::WebSWClientConnection::PostMessageToServiceWorkerClient { destinationScriptExecutionContextIdentifier, message, sourceServiceWorker->data(), sourceOrigin });
 }
 
 void WebSWServerConnection::matchRegistration(uint64_t registrationMatchRequestIdentifier, const SecurityOriginData& topOrigin, const URL& clientURL)

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (224803 => 224804)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -64,7 +64,7 @@
     void resolveRegistrationJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationData&, WebCore::ShouldNotifyWhenResolved) final;
     void resolveUnregistrationJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationKey&, bool unregistrationResult) final;
     void startScriptFetchInClient(uint64_t jobIdentifier) final;
-    void updateRegistrationStateInClient(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::ServiceWorkerRegistrationState, std::optional<WebCore::ServiceWorkerIdentifier>) final;
+    void updateRegistrationStateInClient(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::ServiceWorkerRegistrationState, const std::optional<WebCore::ServiceWorkerData>&) final;
     void updateWorkerStateInClient(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerState) final;
     void fireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationIdentifier) final;
 

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (224803 => 224804)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2017-11-14 06:21:43 UTC (rev 224804)
@@ -131,9 +131,9 @@
     return ServiceWorkerClientFetch::create(provider, WTFMove(loader), identifier, m_connection.get(), WTFMove(callback));
 }
 
-void WebSWClientConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
+void WebSWClientConnection::postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, ServiceWorkerData&& source, const String& sourceOrigin)
 {
-    SWClientConnection::postMessageToServiceWorkerClient(destinationScriptExecutionContextIdentifier, SerializedScriptValue::adopt(message.vector()), sourceIdentifier, sourceOrigin);
+    SWClientConnection::postMessageToServiceWorkerClient(destinationScriptExecutionContextIdentifier, SerializedScriptValue::adopt(message.vector()), WTFMove(source), sourceOrigin);
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (224803 => 224804)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h	2017-11-14 06:21:43 UTC (rev 224804)
@@ -63,7 +63,7 @@
     bool hasServiceWorkerRegisteredForOrigin(const WebCore::SecurityOrigin&) const final;
     Ref<ServiceWorkerClientFetch> startFetch(WebServiceWorkerProvider&, Ref<WebCore::ResourceLoader>&&, uint64_t identifier, ServiceWorkerClientFetch::Callback&&);
 
-    void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
+    void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, const IPC::DataReference& message, WebCore::ServiceWorkerData&& source, const String& sourceOrigin);
 
 private:
     void scheduleJobInServer(const WebCore::ServiceWorkerJobData&) final;

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (224803 => 224804)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2017-11-14 06:03:07 UTC (rev 224803)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in	2017-11-14 06:21:43 UTC (rev 224804)
@@ -28,12 +28,12 @@
     RegistrationJobResolvedInServer(uint64_t identifier, struct WebCore::ServiceWorkerRegistrationData registration, enum WebCore::ShouldNotifyWhenResolved shouldNotifyWhenResolved)
     UnregistrationJobResolvedInServer(uint64_t identifier, bool unregistrationResult)
     StartScriptFetchForServer(uint64_t jobIdentifier)
-    UpdateRegistrationState(WebCore::ServiceWorkerRegistrationIdentifier identifier, enum WebCore::ServiceWorkerRegistrationState state, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier)
+    UpdateRegistrationState(WebCore::ServiceWorkerRegistrationIdentifier identifier, enum WebCore::ServiceWorkerRegistrationState state, std::optional<WebCore::ServiceWorkerData> serviceWorkerIdentifier)
     UpdateWorkerState(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, enum WebCore::ServiceWorkerState state)
     FireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationIdentifier identifier)
 
     SetSWOriginTableSharedMemory(WebKit::SharedMemory::Handle handle)
-    PostMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, IPC::DataReference message, WebCore::ServiceWorkerIdentifier sourceServiceWorkerIdentifier, String sourceOrigin)
+    PostMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerData source, String sourceOrigin)
 
     DidMatchRegistration(uint64_t matchRequestIdentifier, std::optional<WebCore::ServiceWorkerRegistrationData> data)
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to