Title: [225341] trunk
Revision
225341
Author
[email protected]
Date
2017-11-30 12:40:04 -0800 (Thu, 30 Nov 2017)

Log Message

Populate self.registration.installing/waiting/active inside service workers
https://bugs.webkit.org/show_bug.cgi?id=180168

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

Rebaseline a couple of WPT that now pass for checks.

* web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt:
* web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt:

Source/WebCore:

Populate self.registration.installing/waiting/active inside service workers.
Also make sure the ServiceWorker's state properly gets updated inside
service workers.

No new tests, extended existing test for self.registration.

* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::scheduleTaskToUpdateState):
* workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::forEachServiceWorkerThread):
* workers/service/context/SWContextManager.h:
* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::fireInstallEvent):
(WebCore::ServiceWorkerThread::fireActivateEvent):
* workers/service/server/SWClientConnection.cpp:
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::SWClientConnection::updateWorkerState):
(WebCore::SWClientConnection::fireUpdateFoundEvent):
* workers/service/server/SWClientConnection.h:

Source/WTF:

Add CrossThreadCopier support for std::optional<>.

* wtf/CrossThreadCopier.h:

LayoutTests:

Extend layout test coverage.

* http/tests/workers/service/resources/self_registration-worker.js:
* http/tests/workers/service/self_registration-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225340 => 225341)


--- trunk/LayoutTests/ChangeLog	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/LayoutTests/ChangeLog	2017-11-30 20:40:04 UTC (rev 225341)
@@ -1,5 +1,17 @@
 2017-11-30  Chris Dumez  <[email protected]>
 
+        Populate self.registration.installing/waiting/active inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180168
+
+        Reviewed by Brady Eidson.
+
+        Extend layout test coverage.
+
+        * http/tests/workers/service/resources/self_registration-worker.js:
+        * http/tests/workers/service/self_registration-expected.txt:
+
+2017-11-30  Chris Dumez  <[email protected]>
+
         Unreviewed, unskip a few Service Workers tests that no longer seem to be flaky.
 
         * TestExpectations:

Modified: trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js (225340 => 225341)


--- trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/LayoutTests/http/tests/workers/service/resources/self_registration-worker.js	2017-11-30 20:40:04 UTC (rev 225341)
@@ -5,11 +5,25 @@
     results.push(msg);
 }
 
+function dumpServiceWorker(workerName, serviceWorker)
+{
+    if (!serviceWorker) {
+        log(workerName + " worker: null");
+        return;
+    }
+    log(workerName + " worker:");
+    log("- scriptURL: " + serviceWorker.scriptURL);
+    log("- state: " + serviceWorker.state);
+}
+
 function dumpRegistration()
 {
     log("* self.registration");
     log("scope: " + self.registration.scope);
     log("updateViaCache: " + self.registration.updateViaCache);
+    dumpServiceWorker("installing", self.registration.installing);
+    dumpServiceWorker("waiting", self.registration.waiting);
+    dumpServiceWorker("active", self.registration.active);
     log("");
 }
 
@@ -16,11 +30,26 @@
 self.addEventListener("install", function() {
     log("Received install event");
     dumpRegistration();
+
+    if (self.registration.installing) {
+        self.registration.installing.addEventListener("statechange", function() {
+            log("Received statechange event on service worker");
+        })
+    }
 });
 
+self.addEventListener("activate", function() {
+    log("Received activate event");
+    dumpRegistration();
+});
+
 self.addEventListener("message", (event) => {
+    dumpRegistration();
     for (let result of results)
         event.source.postMessage(result);
     event.source.postMessage("DONE");
 });
 
+self.registration.addEventListener("updatefound", function() {
+    log("Received updatefound event on self.registration");
+});

Modified: trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt (225340 => 225341)


--- trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/LayoutTests/http/tests/workers/service/self_registration-expected.txt	2017-11-30 20:40:04 UTC (rev 225341)
@@ -1,8 +1,36 @@
 * Add basic testing for ServiceWorkerGlobalScope.registration
 
+Received updatefound event on self.registration
 Received install event
 * self.registration
 scope: http://127.0.0.1:8000/workers/service/
 updateViaCache: imports
+installing worker:
+- scriptURL: http://127.0.0.1:8000/workers/service/resources/self_registration-worker.js
+- state: installing
+waiting worker: null
+active worker: null
 
+Received statechange event on service worker
+Received statechange event on service worker
+Received activate event
+* self.registration
+scope: http://127.0.0.1:8000/workers/service/
+updateViaCache: imports
+installing worker: null
+waiting worker: null
+active worker:
+- scriptURL: http://127.0.0.1:8000/workers/service/resources/self_registration-worker.js
+- state: activating
 
+Received statechange event on service worker
+* self.registration
+scope: http://127.0.0.1:8000/workers/service/
+updateViaCache: imports
+installing worker: null
+waiting worker: null
+active worker:
+- scriptURL: http://127.0.0.1:8000/workers/service/resources/self_registration-worker.js
+- state: activated
+
+

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (225340 => 225341)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-11-30 20:40:04 UTC (rev 225341)
@@ -1,3 +1,15 @@
+2017-11-30  Chris Dumez  <[email protected]>
+
+        Populate self.registration.installing/waiting/active inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180168
+
+        Reviewed by Brady Eidson.
+
+        Rebaseline a couple of WPT that now pass for checks.
+
+        * web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt:
+
 2017-11-30  Ms2ger  <[email protected]>
 
         [GTK] Enable all wpt touch-events tests.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt (225340 => 225341)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/registration-attribute.https-expected.txt	2017-11-30 20:40:04 UTC (rev 225341)
@@ -1,5 +1,4 @@
 
+PASS Verify registration attributes on ServiceWorkerGlobalScope 
+FAIL Verify registration attributes on ServiceWorkerGlobalScope of the newer worker promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
 
-FAIL Verify registration attributes on ServiceWorkerGlobalScope assert_equals: Service Worker should respond to fetch expected "updatefound,install,statechange(installed),statechange(activating),activate,statechange(activated),fetch" but got "{\"error\": {\"message\": \"\", \"code\": 404}}"
-FAIL Verify registration attributes on ServiceWorkerGlobalScope of the newer worker promise_test: Unhandled rejection with value: object "Error: wait_for_state must be passed a ServiceWorker"
-

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt (225340 => 225341)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt	2017-11-30 20:40:04 UTC (rev 225341)
@@ -9,15 +9,15 @@
 FAIL SW-fallbacked redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
 FAIL SW-fallbacked redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
 FAIL SW-fallbacked redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
-TIMEOUT SW-generated redirect to same-origin out-scope. Test timed out
-NOTRUN SW-generated redirect to same-origin same-scope. 
-NOTRUN SW-generated redirect to same-origin other-scope. 
-NOTRUN SW-generated redirect to other-origin out-scope. 
-NOTRUN SW-generated redirect to other-origin in-scope. 
-NOTRUN SW-fetched redirect to same-origin out-scope. 
-NOTRUN SW-fetched redirect to same-origin same-scope. 
-NOTRUN SW-fetched redirect to same-origin other-scope. 
-NOTRUN SW-fetched redirect to other-origin out-scope. 
+FAIL SW-generated redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-generated redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-generated redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-generated redirect to other-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-generated redirect to other-origin in-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fetched redirect to same-origin out-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fetched redirect to same-origin same-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+FAIL SW-fetched redirect to same-origin other-scope. promise_test: Unhandled rejection with value: object "NotSupportedError: Passing MessagePort objects to postMessage is not yet supported"
+TIMEOUT SW-fetched redirect to other-origin out-scope. Test timed out
 NOTRUN SW-fetched redirect to other-origin in-scope. 
 NOTRUN Redirect to same-origin out-scope with opaque redirect response. 
 NOTRUN Redirect to same-origin same-scope with opaque redirect response. 

Modified: trunk/Source/WTF/ChangeLog (225340 => 225341)


--- trunk/Source/WTF/ChangeLog	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WTF/ChangeLog	2017-11-30 20:40:04 UTC (rev 225341)
@@ -1,3 +1,14 @@
+2017-11-30  Chris Dumez  <[email protected]>
+
+        Populate self.registration.installing/waiting/active inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180168
+
+        Reviewed by Brady Eidson.
+
+        Add CrossThreadCopier support for std::optional<>.
+
+        * wtf/CrossThreadCopier.h:
+
 2017-11-29  JF Bastien  <[email protected]>
 
         WTF / bmalloc: don't write to 0xbbadbeef when ASAN is looking

Modified: trunk/Source/WTF/wtf/CrossThreadCopier.h (225340 => 225341)


--- trunk/Source/WTF/wtf/CrossThreadCopier.h	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WTF/wtf/CrossThreadCopier.h	2017-11-30 20:40:04 UTC (rev 225341)
@@ -140,6 +140,17 @@
     }
 };
 
+// Default specialization for std::optional of CrossThreadCopyable class.
+template<typename T> struct CrossThreadCopierBase<false, false, std::optional<T>> {
+    typedef std::optional<T> Type;
+    static Type copy(const Type& source)
+    {
+        if (!source)
+            return std::nullopt;
+        return CrossThreadCopier<T>::copy(*source);
+    }
+};
+
 template<typename T> T crossThreadCopy(const T& source)
 {
     return CrossThreadCopier<T>::copy(source);

Modified: trunk/Source/WebCore/ChangeLog (225340 => 225341)


--- trunk/Source/WebCore/ChangeLog	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WebCore/ChangeLog	2017-11-30 20:40:04 UTC (rev 225341)
@@ -1,5 +1,32 @@
 2017-11-30  Chris Dumez  <[email protected]>
 
+        Populate self.registration.installing/waiting/active inside service workers
+        https://bugs.webkit.org/show_bug.cgi?id=180168
+
+        Reviewed by Brady Eidson.
+
+        Populate self.registration.installing/waiting/active inside service workers.
+        Also make sure the ServiceWorker's state properly gets updated inside
+        service workers.
+
+        No new tests, extended existing test for self.registration.
+
+        * workers/service/ServiceWorker.cpp:
+        (WebCore::ServiceWorker::scheduleTaskToUpdateState):
+        * workers/service/context/SWContextManager.cpp:
+        (WebCore::SWContextManager::forEachServiceWorkerThread):
+        * workers/service/context/SWContextManager.h:
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::fireInstallEvent):
+        (WebCore::ServiceWorkerThread::fireActivateEvent):
+        * workers/service/server/SWClientConnection.cpp:
+        (WebCore::SWClientConnection::updateRegistrationState):
+        (WebCore::SWClientConnection::updateWorkerState):
+        (WebCore::SWClientConnection::fireUpdateFoundEvent):
+        * workers/service/server/SWClientConnection.h:
+
+2017-11-30  Chris Dumez  <[email protected]>
+
         Rename RegistrationOptions to ServiceWorkerRegistrationOptions
         https://bugs.webkit.org/show_bug.cgi?id=180207
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorker.cpp (225340 => 225341)


--- trunk/Source/WebCore/workers/service/ServiceWorker.cpp	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.cpp	2017-11-30 20:40:04 UTC (rev 225341)
@@ -68,9 +68,6 @@
 
 void ServiceWorker::scheduleTaskToUpdateState(State state)
 {
-    // FIXME: Once we support service workers from workers, this might need to change.
-    RELEASE_ASSERT(isMainThread());
-
     auto* context = scriptExecutionContext();
     if (!context)
         return;

Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.cpp (225340 => 225341)


--- trunk/Source/WebCore/workers/service/context/SWContextManager.cpp	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.cpp	2017-11-30 20:40:04 UTC (rev 225341)
@@ -106,6 +106,12 @@
     });
 }
 
+void SWContextManager::forEachServiceWorkerThread(const WTF::Function<void(ServiceWorkerThreadProxy&)>& apply)
+{
+    for (auto& workerThread : m_workerMap.values())
+        apply(*workerThread);
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (225340 => 225341)


--- trunk/Source/WebCore/workers/service/context/SWContextManager.h	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h	2017-11-30 20:40:04 UTC (rev 225341)
@@ -63,6 +63,8 @@
     WEBCORE_EXPORT void fireActivateEvent(ServiceWorkerIdentifier);
     WEBCORE_EXPORT void terminateWorker(ServiceWorkerIdentifier);
 
+    void forEachServiceWorkerThread(const WTF::Function<void(ServiceWorkerThreadProxy&)>&);
+
 private:
     SWContextManager() = default;
 

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (225340 => 225341)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2017-11-30 20:40:04 UTC (rev 225341)
@@ -122,21 +122,23 @@
 void ServiceWorkerThread::fireInstallEvent()
 {
     ScriptExecutionContext::Task task([jobDataIdentifier = m_data.jobDataIdentifier, serviceWorkerIdentifier = this->identifier()] (ScriptExecutionContext& context) mutable {
-        auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
-        auto installEvent = ExtendableEvent::create(eventNames().installEvent, { }, ExtendableEvent::IsTrusted::Yes);
-        serviceWorkerGlobalScope.dispatchEvent(installEvent);
+        context.postTask([jobDataIdentifier, serviceWorkerIdentifier](ScriptExecutionContext& context) {
+            auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
+            auto installEvent = ExtendableEvent::create(eventNames().installEvent, { }, ExtendableEvent::IsTrusted::Yes);
+            serviceWorkerGlobalScope.dispatchEvent(installEvent);
 
-        installEvent->whenAllExtendLifetimePromisesAreSettled([jobDataIdentifier, serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&& extendLifetimePromises) {
-            bool hasRejectedAnyPromise = false;
-            for (auto& promise : extendLifetimePromises) {
-                if (promise->status() == DOMPromise::Status::Rejected) {
-                    hasRejectedAnyPromise = true;
-                    break;
+            installEvent->whenAllExtendLifetimePromisesAreSettled([jobDataIdentifier, serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&& extendLifetimePromises) {
+                bool hasRejectedAnyPromise = false;
+                for (auto& promise : extendLifetimePromises) {
+                    if (promise->status() == DOMPromise::Status::Rejected) {
+                        hasRejectedAnyPromise = true;
+                        break;
+                    }
                 }
-            }
-            callOnMainThread([jobDataIdentifier, serviceWorkerIdentifier, hasRejectedAnyPromise] () mutable {
-                if (auto* connection = SWContextManager::singleton().connection())
-                    connection->didFinishInstall(jobDataIdentifier, serviceWorkerIdentifier, !hasRejectedAnyPromise);
+                callOnMainThread([jobDataIdentifier, serviceWorkerIdentifier, hasRejectedAnyPromise] () mutable {
+                    if (auto* connection = SWContextManager::singleton().connection())
+                        connection->didFinishInstall(jobDataIdentifier, serviceWorkerIdentifier, !hasRejectedAnyPromise);
+                });
             });
         });
     });
@@ -146,14 +148,16 @@
 void ServiceWorkerThread::fireActivateEvent()
 {
     ScriptExecutionContext::Task task([serviceWorkerIdentifier = this->identifier()] (ScriptExecutionContext& context) mutable {
-        auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
-        auto activateEvent = ExtendableEvent::create(eventNames().activateEvent, { }, ExtendableEvent::IsTrusted::Yes);
-        serviceWorkerGlobalScope.dispatchEvent(activateEvent);
+        context.postTask([serviceWorkerIdentifier](ScriptExecutionContext& context) {
+            auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
+            auto activateEvent = ExtendableEvent::create(eventNames().activateEvent, { }, ExtendableEvent::IsTrusted::Yes);
+            serviceWorkerGlobalScope.dispatchEvent(activateEvent);
 
-        activateEvent->whenAllExtendLifetimePromisesAreSettled([serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&&) {
-            callOnMainThread([serviceWorkerIdentifier] () mutable {
-                if (auto* connection = SWContextManager::singleton().connection())
-                    connection->didFinishActivation(serviceWorkerIdentifier);
+            activateEvent->whenAllExtendLifetimePromisesAreSettled([serviceWorkerIdentifier](HashSet<Ref<DOMPromise>>&&) {
+                callOnMainThread([serviceWorkerIdentifier] () mutable {
+                    if (auto* connection = SWContextManager::singleton().connection())
+                        connection->didFinishActivation(serviceWorkerIdentifier);
+                });
             });
         });
     });

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


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp	2017-11-30 20:40:04 UTC (rev 225341)
@@ -32,10 +32,12 @@
 #include "ExceptionData.h"
 #include "MessageEvent.h"
 #include "Microtasks.h"
+#include "SWContextManager.h"
 #include "ServiceWorkerContainer.h"
 #include "ServiceWorkerFetchResult.h"
 #include "ServiceWorkerJobData.h"
 #include "ServiceWorkerRegistration.h"
+#include <wtf/CrossThreadCopier.h>
 
 namespace WebCore {
 
@@ -136,25 +138,30 @@
     container->dispatchEvent(messageEvent);
 }
 
-void SWClientConnection::forEachContainer(const WTF::Function<void(ServiceWorkerContainer&)>& apply)
+void SWClientConnection::updateRegistrationState(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerData>& serviceWorkerData)
 {
-    // FIXME: We should iterate over all service worker clients, not only documents.
+    SWContextManager::singleton().forEachServiceWorkerThread([identifier, state, &serviceWorkerData] (auto& workerThread) {
+        workerThread.thread().runLoop().postTask([identifier, state, serviceWorkerData = crossThreadCopy(serviceWorkerData)](ScriptExecutionContext& context) mutable {
+            if (auto* container = context.serviceWorkerContainer())
+                container->scheduleTaskToUpdateRegistrationState(identifier, state, WTFMove(serviceWorkerData));
+        });
+    });
+
     for (auto* document : Document::allDocuments()) {
         if (auto* container = document->serviceWorkerContainer())
-            apply(*container);
+            container->scheduleTaskToUpdateRegistrationState(identifier, state, serviceWorkerData);
     }
 }
 
-void SWClientConnection::updateRegistrationState(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerData>& serviceWorkerData)
+void SWClientConnection::updateWorkerState(ServiceWorkerIdentifier identifier, ServiceWorkerState state)
 {
-    forEachContainer([&](ServiceWorkerContainer& container) {
-        container.scheduleTaskToUpdateRegistrationState(identifier, state, serviceWorkerData);
+    SWContextManager::singleton().forEachServiceWorkerThread([identifier, state] (auto& workerThread) {
+        workerThread.thread().runLoop().postTask([identifier, state](ScriptExecutionContext& context) {
+            if (auto* serviceWorker = context.serviceWorker(identifier))
+                serviceWorker->scheduleTaskToUpdateState(state);
+        });
     });
-}
 
-void SWClientConnection::updateWorkerState(ServiceWorkerIdentifier identifier, ServiceWorkerState state)
-{
-    // FIXME: We should iterate over all service worker clients, not only documents.
     for (auto* document : Document::allDocuments()) {
         if (auto* serviceWorker = document->serviceWorker(identifier))
             serviceWorker->scheduleTaskToUpdateState(state);
@@ -163,9 +170,17 @@
 
 void SWClientConnection::fireUpdateFoundEvent(ServiceWorkerRegistrationIdentifier identifier)
 {
-    forEachContainer([&](ServiceWorkerContainer& container) {
-        container.scheduleTaskToFireUpdateFoundEvent(identifier);
+    SWContextManager::singleton().forEachServiceWorkerThread([identifier] (auto& workerThread) {
+        workerThread.thread().runLoop().postTask([identifier](ScriptExecutionContext& context) {
+            if (auto* container = context.serviceWorkerContainer())
+                container->scheduleTaskToFireUpdateFoundEvent(identifier);
+        });
     });
+
+    for (auto* document : Document::allDocuments()) {
+        if (auto* container = document->serviceWorkerContainer())
+            container->scheduleTaskToFireUpdateFoundEvent(identifier);
+    }
 }
 
 void SWClientConnection::notifyClientsOfControllerChange(const HashSet<DocumentIdentifier>& contextIdentifiers, ServiceWorkerData&& newController)

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


--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-30 20:39:54 UTC (rev 225340)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h	2017-11-30 20:40:04 UTC (rev 225341)
@@ -95,7 +95,6 @@
 private:
     virtual void scheduleJobInServer(const ServiceWorkerJobData&) = 0;
     virtual void finishFetchingScriptInServer(const ServiceWorkerFetchResult&) = 0;
-    void forEachContainer(const WTF::Function<void(ServiceWorkerContainer&)>& apply);
 
     HashMap<ServiceWorkerJobIdentifier, RefPtr<ServiceWorkerJob>> m_scheduledJobs;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to