Implement "Service Worker Has No Pending Events" / "Update Service Worker Extended...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2017 21:06:23 +0000 (21:06 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Nov 2017 21:06:23 +0000 (21:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179618

Reviewed by Brady Eidson.

Source/WebCore:

Implement "Service Worker Has No Pending Events" / "Update Service Worker Extended Events Set" algorithms:
- https://w3c.github.io/ServiceWorker/#service-worker-has-no-pending-events-algorithm
- https://w3c.github.io/ServiceWorker/#update-service-worker-extended-events-set-algorithm

Test: http/tests/workers/service/basic-unregister-then-register-again-reuse.html

* workers/service/context/SWContextManager.h:
* workers/service/context/ServiceWorkerFetch.cpp:
(WebCore::ServiceWorkerFetch::dispatchFetchEvent):
* workers/service/context/ServiceWorkerFetch.h:
* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::postFetchTask):
(WebCore::ServiceWorkerThread::postMessageToServiceWorkerGlobalScope):
(WebCore::ServiceWorkerThread::updateExtendedEventsSet):
* workers/service/context/ServiceWorkerThread.h:
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::Connection::setServiceWorkerHasPendingEvents):
(WebCore::SWServer::setServiceWorkerHasPendingEvents):
* workers/service/server/SWServer.h:
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::tryActivate):
(WebCore::SWServerJobQueue::tryClearRegistration):
* workers/service/server/SWServerWorker.h:
(WebCore::SWServerWorker::hasPendingEvents const):
(WebCore::SWServerWorker::setHasPendingEvents):

Source/WebKit:

* StorageProcess/StorageProcess.cpp:
(WebKit::StorageProcess::setServiceWorkerHasPendingEvents):
* StorageProcess/StorageProcess.h:
* StorageProcess/StorageProcess.messages.in:
* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::setServiceWorkerHasPendingEvents):
* WebProcess/Storage/WebSWContextManagerConnection.h:

LayoutTests:

Add layout test coverage.

* http/tests/workers/service/basic-unregister-then-register-again-reuse-expected.txt: Added.
* http/tests/workers/service/basic-unregister-then-register-again-reuse.html: Added.
* http/tests/workers/service/resources/basic-unregister-then-register-again-reuse-worker.js: Added.
(event.waitUntil.new.Promise):
(setTimeout):

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

20 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/basic-unregister-then-register-again-reuse-worker.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/workers/service/context/SWContextManager.h
Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp
Source/WebCore/workers/service/context/ServiceWorkerFetch.h
Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
Source/WebCore/workers/service/context/ServiceWorkerThread.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/SWServerWorker.h
Source/WebKit/ChangeLog
Source/WebKit/StorageProcess/StorageProcess.cpp
Source/WebKit/StorageProcess/StorageProcess.h
Source/WebKit/StorageProcess/StorageProcess.messages.in
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h

index 4488f71..b8686db 100644 (file)
@@ -1,3 +1,18 @@
+2017-11-13  Chris Dumez  <cdumez@apple.com>
+
+        Implement "Service Worker Has No Pending Events" / "Update Service Worker Extended Events Set" algorithms
+        https://bugs.webkit.org/show_bug.cgi?id=179618
+
+        Reviewed by Brady Eidson.
+
+        Add layout test coverage.
+
+        * http/tests/workers/service/basic-unregister-then-register-again-reuse-expected.txt: Added.
+        * http/tests/workers/service/basic-unregister-then-register-again-reuse.html: Added.
+        * http/tests/workers/service/resources/basic-unregister-then-register-again-reuse-worker.js: Added.
+        (event.waitUntil.new.Promise):
+        (setTimeout):
+
 2017-11-13  Ryan Haddad  <ryanhaddad@apple.com>
 
         Adjust TestExpectation for js/intl-datetimeformat.html.
diff --git a/LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse-expected.txt b/LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse-expected.txt
new file mode 100644 (file)
index 0000000..58676e3
--- /dev/null
@@ -0,0 +1,5 @@
+PASS: registration1 should not have an installing worker
+PASS: registration1 should not have a waiting worker
+PASS: registration1 should have an active worker
+PASS: Registration was reused
+
diff --git a/LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse.html b/LayoutTests/http/tests/workers/service/basic-unregister-then-register-again-reuse.html
new file mode 100644 (file)
index 0000000..ae7b21d
--- /dev/null
@@ -0,0 +1,55 @@
+<html>
+<head>
+<script src="resources/sw-test-pre.js"></script>
+</head>
+<body>
+<script>
+
+function waitForMessageEvent()
+{
+    return new Promise(resolve => {
+        navigator.serviceWorker.addEventListener('message', resolve, { once: true });
+    });
+}
+
+async function test()
+{
+    try {
+         let registration1 = await navigator.serviceWorker.register("resources/basic-unregister-then-register-again-reuse-worker.js", { });
+         await waitForState(registration1.installing, "activated");
+         if (registration1.installing)
+             log("FAIL: registration1 should not have an installing worker");
+         else
+             log("PASS: registration1 should not have an installing worker");
+
+         if (registration1.waiting)
+             log("FAIL: registration1 should not have a waiting worker");
+         else
+             log("PASS: registration1 should not have a waiting worker");
+
+         if (registration1.active)
+             log("PASS: registration1 should have an active worker");
+         else
+             log("FAIL: registration1 should have an active worker");
+
+         // Service worker will use waitUntil() on the received ExtendableMessageEvent to extend its lifetime.
+         registration1.active.postMessage("ExtendLifetime");
+
+         await waitForMessageEvent();
+         await registration1.unregister();
+
+         let registration2 = await navigator.serviceWorker.register("resources/basic-unregister-then-register-again-reuse-worker.js", { });
+         if (registration1 === registration2)
+             log("PASS: Registration was reused");
+         else
+             log("FAIL: Registration was not reused");
+    } catch (e) {
+        log("FAIL: Got exception " + e);
+    }
+    finishSWTest();
+}
+
+test();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/workers/service/resources/basic-unregister-then-register-again-reuse-worker.js b/LayoutTests/http/tests/workers/service/resources/basic-unregister-then-register-again-reuse-worker.js
new file mode 100644 (file)
index 0000000..4b79afd
--- /dev/null
@@ -0,0 +1,11 @@
+self.addEventListener("message", function(event) {
+    event.waitUntil(new Promise((resolve, reject) => {
+        setTimeout(() => {
+            resolve();
+        }, 10000);
+    }));
+    client = event.source;
+    setTimeout(function() {
+        client.postMessage("ExtendedLifetime");
+    }, 0);
+});
index 0bed46a..0e449a8 100644 (file)
@@ -1,3 +1,36 @@
+2017-11-13  Chris Dumez  <cdumez@apple.com>
+
+        Implement "Service Worker Has No Pending Events" / "Update Service Worker Extended Events Set" algorithms
+        https://bugs.webkit.org/show_bug.cgi?id=179618
+
+        Reviewed by Brady Eidson.
+
+        Implement "Service Worker Has No Pending Events" / "Update Service Worker Extended Events Set" algorithms:
+        - https://w3c.github.io/ServiceWorker/#service-worker-has-no-pending-events-algorithm
+        - https://w3c.github.io/ServiceWorker/#update-service-worker-extended-events-set-algorithm
+
+        Test: http/tests/workers/service/basic-unregister-then-register-again-reuse.html
+
+        * workers/service/context/SWContextManager.h:
+        * workers/service/context/ServiceWorkerFetch.cpp:
+        (WebCore::ServiceWorkerFetch::dispatchFetchEvent):
+        * workers/service/context/ServiceWorkerFetch.h:
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::postFetchTask):
+        (WebCore::ServiceWorkerThread::postMessageToServiceWorkerGlobalScope):
+        (WebCore::ServiceWorkerThread::updateExtendedEventsSet):
+        * workers/service/context/ServiceWorkerThread.h:
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::Connection::setServiceWorkerHasPendingEvents):
+        (WebCore::SWServer::setServiceWorkerHasPendingEvents):
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::tryActivate):
+        (WebCore::SWServerJobQueue::tryClearRegistration):
+        * workers/service/server/SWServerWorker.h:
+        (WebCore::SWServerWorker::hasPendingEvents const):
+        (WebCore::SWServerWorker::setHasPendingEvents):
+
 2017-11-13  Colin Bendell  <colin@bendell.ca>
 
         Added mime type check to the picture source preloader to avoid downloading incompatible resources.
index c507b6e..f61f2fc 100644 (file)
@@ -49,6 +49,7 @@ public:
         virtual void serviceWorkerStartedWithMessage(ServiceWorkerIdentifier, const String& exceptionMessage) = 0;
         virtual void didFinishInstall(ServiceWorkerIdentifier, bool wasSuccessful) = 0;
         virtual void didFinishActivation(ServiceWorkerIdentifier) = 0;
+        virtual void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool) = 0;
     };
 
     WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
index 0efbe9f..baff4f3 100644 (file)
@@ -85,7 +85,7 @@ static void processResponse(Ref<Client>&& client, FetchResponse* response)
     client->didFinish();
 }
 
-void dispatchFetchEvent(Ref<Client>&& client, WorkerGlobalScope& globalScope, ResourceRequest&& request, FetchOptions&& options)
+Ref<FetchEvent> dispatchFetchEvent(Ref<Client>&& client, WorkerGlobalScope& globalScope, ResourceRequest&& request, FetchOptions&& options)
 {
     ASSERT(globalScope.isServiceWorkerGlobalScope());
 
@@ -108,11 +108,12 @@ void dispatchFetchEvent(Ref<Client>&& client, WorkerGlobalScope& globalScope, Re
     if (!event->respondWithEntered()) {
         if (event->defaultPrevented()) {
             client->didFail();
-            return;
+            return event;
         }
         client->didNotHandle();
         // FIXME: Handle soft update.
     }
+    return event;
 }
 
 } // namespace ServiceWorkerFetch
index 278032c..a20341c 100644 (file)
@@ -31,6 +31,7 @@
 #include <wtf/ThreadSafeRefCounted.h>
 
 namespace WebCore {
+class FetchEvent;
 struct FetchOptions;
 class FetchResponse;
 class ResourceRequest;
@@ -50,7 +51,7 @@ public:
     virtual void didNotHandle() = 0;
 };
 
-void dispatchFetchEvent(Ref<Client>&&, WorkerGlobalScope&, ResourceRequest&&, FetchOptions&&);
+Ref<FetchEvent> dispatchFetchEvent(Ref<Client>&&, WorkerGlobalScope&, ResourceRequest&&, FetchOptions&&);
 };
 
 } // namespace WebCore
index 34a3322..6338e4e 100644 (file)
@@ -99,19 +99,22 @@ void ServiceWorkerThread::postFetchTask(Ref<ServiceWorkerFetch::Client>&& client
 {
     // FIXME: instead of directly using runLoop(), we should be using something like WorkerGlobalScopeProxy.
     // FIXME: request and options come straigth from IPC so are already isolated. We should be able to take benefit of that.
-    runLoop().postTaskForMode([client = WTFMove(client), request = request.isolatedCopy(), options = options.isolatedCopy()] (ScriptExecutionContext& context) mutable {
-        ServiceWorkerFetch::dispatchFetchEvent(WTFMove(client), downcast<WorkerGlobalScope>(context), WTFMove(request), WTFMove(options));
+    runLoop().postTaskForMode([this, client = WTFMove(client), request = request.isolatedCopy(), options = options.isolatedCopy()] (ScriptExecutionContext& context) mutable {
+        auto fetchEvent = ServiceWorkerFetch::dispatchFetchEvent(WTFMove(client), downcast<WorkerGlobalScope>(context), WTFMove(request), WTFMove(options));
+        updateExtendedEventsSet(fetchEvent.ptr());
     }, WorkerRunLoop::defaultMode());
 }
 
 void ServiceWorkerThread::postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray>&& channels, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin)
 {
-    ScriptExecutionContext::Task task([channels = WTFMove(channels), message = WTFMove(message), sourceIdentifier, sourceOrigin = sourceOrigin.isolatedCopy()] (ScriptExecutionContext& context) mutable {
+    ScriptExecutionContext::Task task([this, channels = WTFMove(channels), message = WTFMove(message), sourceIdentifier, sourceOrigin = sourceOrigin.isolatedCopy()] (ScriptExecutionContext& context) mutable {
         auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(context);
         auto ports = MessagePort::entanglePorts(serviceWorkerGlobalScope, WTFMove(channels));
         ExtendableMessageEventSource source = RefPtr<ServiceWorkerClient> { ServiceWorkerWindowClient::create(context, sourceIdentifier) };
-        serviceWorkerGlobalScope.dispatchEvent(ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin, { }, WTFMove(source)));
+        auto messageEvent = ExtendableMessageEvent::create(WTFMove(ports), WTFMove(message), sourceOrigin, { }, WTFMove(source));
+        serviceWorkerGlobalScope.dispatchEvent(messageEvent);
         serviceWorkerGlobalScope.thread().workerObjectProxy().confirmMessageFromWorkerObject(serviceWorkerGlobalScope.hasPendingActivity());
+        updateExtendedEventsSet(messageEvent.ptr());
     });
     runLoop().postTask(WTFMove(task));
 }
@@ -157,6 +160,33 @@ void ServiceWorkerThread::fireActivateEvent()
     runLoop().postTask(WTFMove(task));
 }
 
+// https://w3c.github.io/ServiceWorker/#update-service-worker-extended-events-set-algorithm
+void ServiceWorkerThread::updateExtendedEventsSet(ExtendableEvent* newEvent)
+{
+    ASSERT(!isMainThread());
+    ASSERT(!newEvent || !newEvent->isBeingDispatched());
+    bool hadPendingEvents = hasPendingEvents();
+    m_extendedEvents.removeAllMatching([](auto& event) {
+        return !event->pendingPromiseCount();
+    });
+
+    if (newEvent && newEvent->pendingPromiseCount()) {
+        m_extendedEvents.append(*newEvent);
+        newEvent->whenAllExtendLifetimePromisesAreSettled([this](auto&&) {
+            updateExtendedEventsSet();
+        });
+    }
+
+    bool hasPendingEvents = this->hasPendingEvents();
+    if (hasPendingEvents == hadPendingEvents)
+        return;
+
+    callOnMainThread([identifier = this->identifier(), hasPendingEvents] {
+        if (auto* connection = SWContextManager::singleton().connection())
+            connection->setServiceWorkerHasPendingEvents(identifier, hasPendingEvents);
+    });
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)
index d48a719..73decd5 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
 
 class CacheStorageProvider;
 class ContentSecurityPolicyResponseHeaders;
+class ExtendableEvent;
 class MessagePortChannel;
 class SerializedScriptValue;
 class WorkerObjectProxy;
@@ -71,9 +72,13 @@ protected:
 private:
     WEBCORE_EXPORT ServiceWorkerThread(uint64_t serverConnectionIdentifier, 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;
 };
 
 } // namespace WebCore
index cc422d2..5ea544f 100644 (file)
@@ -122,6 +122,11 @@ void SWServer::Connection::didFinishActivation(const ServiceWorkerRegistrationKe
     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);
@@ -255,6 +260,14 @@ void SWServer::didFinishActivation(Connection& connection, const ServiceWorkerRe
         SWServerJobQueue::didFinishActivation(*registration, serviceWorkerIdentifier);
 }
 
+void SWServer::setServiceWorkerHasPendingEvents(Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier, bool hasPendingEvents)
+{
+    ASSERT_UNUSED(connection, m_connections.contains(connection.identifier()));
+
+    if (auto* serviceWorker = m_workersByID.get(serviceWorkerIdentifier))
+        serviceWorker->setHasPendingEvents(hasPendingEvents);
+}
+
 void SWServer::didResolveRegistrationPromise(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey)
 {
     ASSERT(m_connections.contains(connection.identifier()));
index 0ae0312..f0c8c2c 100644 (file)
@@ -63,6 +63,7 @@ public:
         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); }
 
@@ -132,6 +133,7 @@ private:
     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);
index 4b7b072..e69fe57 100644 (file)
@@ -189,12 +189,13 @@ void SWServerJobQueue::tryActivate(SWServer& server, SWServer::Connection& conne
     if (registration.activeWorker() && registration.activeWorker()->state() == ServiceWorkerState::Activating)
         return;
 
-    // FIXME: Invoke Activate with registration if either of the following is true:
+    // Invoke Activate with registration if either of the following is true:
     // - registration's active worker is null.
     // - The result of running Service Worker Has No Pending Events with registration's active worker is true,
-    //   and no service worker client is using registration or registration's waiting worker's skip waiting
-    //   flag is set.
-    activate(server, connection, registration);
+    //   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);
 }
 
 // https://w3c.github.io/ServiceWorker/#activate
@@ -328,8 +329,13 @@ void SWServerJobQueue::tryClearRegistration(SWServerRegistration& registration)
 {
     // FIXME: Make sure that the registration has no service worker client.
 
-    // FIXME: The specification has more complex logic here. We currently clear registrations
-    // too aggressively.
+    if (registration.installingWorker() && registration.installingWorker()->hasPendingEvents())
+        return;
+    if (registration.waitingWorker() && registration.waitingWorker()->hasPendingEvents())
+        return;
+    if (registration.activeWorker() && registration.activeWorker()->hasPendingEvents())
+        return;
+
     clearRegistration(registration);
 }
 
index abcd59c..1a681eb 100644 (file)
@@ -58,6 +58,9 @@ public:
     ServiceWorkerState state() const { return m_state; }
     void setState(ServiceWorkerState state) { m_state = state; }
 
+    bool hasPendingEvents() const { return m_hasPendingEvents; }
+    void setHasPendingEvents(bool value) { m_hasPendingEvents = value; }
+
 private:
     SWServerWorker(const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
 
@@ -68,6 +71,7 @@ private:
     WorkerType m_type;
     
     ServiceWorkerState m_state { ServiceWorkerState::Redundant };
+    bool m_hasPendingEvents { false };
 };
 
 } // namespace WebCore
index 2477ce7..b57a281 100644 (file)
@@ -1,3 +1,18 @@
+2017-11-13  Chris Dumez  <cdumez@apple.com>
+
+        Implement "Service Worker Has No Pending Events" / "Update Service Worker Extended Events Set" algorithms
+        https://bugs.webkit.org/show_bug.cgi?id=179618
+
+        Reviewed by Brady Eidson.
+
+        * StorageProcess/StorageProcess.cpp:
+        (WebKit::StorageProcess::setServiceWorkerHasPendingEvents):
+        * StorageProcess/StorageProcess.h:
+        * StorageProcess/StorageProcess.messages.in:
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::setServiceWorkerHasPendingEvents):
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+
 2017-11-13  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Attachment Support] Implement SPI for clients to request data for a given attachment
index 118ddd7..19e7d00 100644 (file)
@@ -465,6 +465,13 @@ void StorageProcess::didFinishServiceWorkerActivation(uint64_t serverConnectionI
         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 4828edd..ea55034 100644 (file)
@@ -130,6 +130,7 @@ private:
 
     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);
 #endif
 #if ENABLE(INDEXED_DATABASE)
index e8f1984..3b6d339 100644 (file)
@@ -42,6 +42,7 @@ messages -> StorageProcess LegacyReceiver {
     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)
index baa0a4c..edb2454 100644 (file)
@@ -184,6 +184,14 @@ void WebSWContextManagerConnection::didFinishActivation(ServiceWorkerIdentifier
     m_connectionToStorageProcess->send(Messages::StorageProcess::DidFinishServiceWorkerActivation(threadProxy->thread().serverConnectionIdentifier(), data.registrationKey, 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);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)
index 607e00e..8da6a5d 100644 (file)
@@ -54,6 +54,7 @@ private:
     void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, Ref<WebCore::SerializedScriptValue>&& message, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin) final;
     void didFinishInstall(WebCore::ServiceWorkerIdentifier, bool wasSuccessful) final;
     void didFinishActivation(WebCore::ServiceWorkerIdentifier) final;
+    void setServiceWorkerHasPendingEvents(WebCore::ServiceWorkerIdentifier, bool) final;
 
     // IPC messages.
     void serviceWorkerStartedWithMessage(WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;