Implement "UpdateWorkerState" and use it
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Nov 2017 23:06:55 +0000 (23:06 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Nov 2017 23:06:55 +0000 (23:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179318

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/update.https-expected.txt:

Source/WebCore:

No new tests (Existing tests and changes there-to).

* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::allWorkers):
(WebCore::ServiceWorker::mutableAllWorkers):
(WebCore::ServiceWorker::ServiceWorker):
(WebCore::ServiceWorker::~ServiceWorker):
(WebCore::ServiceWorker::updateWorkerState):
(WebCore::ServiceWorker::setState): Deleted.
* workers/service/ServiceWorker.h:

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::updateRegistrationState):
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
* workers/service/ServiceWorkerContainer.h:

* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
(WebCore::ServiceWorkerRegistration::~ServiceWorkerRegistration):
(WebCore::ServiceWorkerRegistration::updateStateFromServer):

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

* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::loggingString const):
* workers/service/ServiceWorkerRegistrationKey.h:

* workers/service/ServiceWorkerTypes.h:

* workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
(WebCore::SWContextManager::registerServiceWorkerThreadForUpdate): Deleted.
* workers/service/context/SWContextManager.h:

* workers/service/server/SWClientConnection.cpp:
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::SWClientConnection::updateWorkerState):
* workers/service/server/SWClientConnection.h:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::updateWorker):
* workers/service/server/SWServer.h:
(WebCore::SWServer::workerByID const):

* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptFetchFinished):
(WebCore::SWServerJobQueue::scriptContextStarted):
(WebCore::SWServerJobQueue::install):
(WebCore::SWServerJobQueue::tryClearRegistration):

* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::updateRegistrationState):
(WebCore::SWServerRegistration::updateWorkerState):
(WebCore::SWServerRegistration::data const):
* workers/service/server/SWServerRegistration.h:
(WebCore::SWServerRegistration::setActiveServiceWorkerIdentifier): Deleted.

* workers/service/server/SWServerWorker.h:
(WebCore::SWServerWorker::state const):
(WebCore::SWServerWorker::setState):

Source/WebKit:

* Scripts/webkit/messages.py:
(headers_for_type):
* Shared/WebCoreArgumentCoders.h:

       * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::updateWorkerStateInClient):
(WebKit::WebSWServerConnection::installServiceWorkerContext):
(WebKit::WebSWServerConnection::setContextConnection):
(WebKit::WebSWServerConnection::updateServiceWorkerContext): Deleted.
* StorageProcess/ServiceWorker/WebSWServerConnection.h:

* WebProcess/Storage/WebSWClientConnection.messages.in:

* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::installServiceWorker):
(WebKit::WebSWContextManagerConnection::updateServiceWorker): Deleted.
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:

Source/WTF:

* wtf/ObjectIdentifier.h:
(WTF::ObjectIdentifier::loggingString const):

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

34 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update.https-expected.txt
Source/WTF/ChangeLog
Source/WTF/wtf/ObjectIdentifier.h
Source/WebCore/ChangeLog
Source/WebCore/workers/service/ServiceWorker.cpp
Source/WebCore/workers/service/ServiceWorker.h
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebCore/workers/service/ServiceWorkerContainer.h
Source/WebCore/workers/service/ServiceWorkerRegistration.cpp
Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp
Source/WebCore/workers/service/ServiceWorkerRegistrationData.h
Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp
Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h
Source/WebCore/workers/service/ServiceWorkerTypes.h
Source/WebCore/workers/service/context/SWContextManager.cpp
Source/WebCore/workers/service/context/SWContextManager.h
Source/WebCore/workers/service/server/SWClientConnection.cpp
Source/WebCore/workers/service/server/SWClientConnection.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/SWServerRegistration.cpp
Source/WebCore/workers/service/server/SWServerRegistration.h
Source/WebCore/workers/service/server/SWServerWorker.h
Source/WebKit/ChangeLog
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/Shared/WebCoreArgumentCoders.h
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in

index 5e963d0..f79bc4e 100644 (file)
@@ -1,3 +1,12 @@
+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/update.https-expected.txt:
+
 2017-11-07  Maciej Stachowiak  <mjs@apple.com>
 
         Update WPT encoding test suite to the latest version.
index 1b80752..22df205 100644 (file)
@@ -1,3 +1,3 @@
 
-FAIL Update a registration. promise_test: Unhandled rejection with value: object "TypeError: Cannot update a null/nonexistent service worker registration"
+FAIL Update a registration. assert_unreached: update() should reject. Reached unreachable code
 
index 4b8b209..889bd79 100644 (file)
@@ -1,3 +1,13 @@
+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        * wtf/ObjectIdentifier.h:
+        (WTF::ObjectIdentifier::loggingString const):
+
 2017-11-07  Michael Saboff  <msaboff@apple.com>
 
         Add SPI function pointers qualifiers for CPU(ARM64E)
index 09f901c..ef37154 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <wtf/HashTraits.h>
+#include <wtf/text/WTFString.h>
 
 namespace WTF {
 
@@ -60,6 +61,13 @@ public:
     {
         return m_identifier != other.m_identifier;
     }
+    
+#ifndef NDEBUG
+    String loggingString() const
+    {
+        return String::number(m_identifier);
+    }
+#endif
 
 private:
     template<typename U> friend ObjectIdentifier<U> makeObjectIdentifier(uint64_t);
index ad7f3b5..477901e 100644 (file)
@@ -1,3 +1,75 @@
+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        No new tests (Existing tests and changes there-to).
+
+        * workers/service/ServiceWorker.cpp:
+        (WebCore::ServiceWorker::allWorkers):
+        (WebCore::ServiceWorker::mutableAllWorkers):
+        (WebCore::ServiceWorker::ServiceWorker):
+        (WebCore::ServiceWorker::~ServiceWorker):
+        (WebCore::ServiceWorker::updateWorkerState):
+        (WebCore::ServiceWorker::setState): Deleted.
+        * workers/service/ServiceWorker.h:
+
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::updateRegistrationState):
+        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
+        * workers/service/ServiceWorkerContainer.h:
+
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
+        (WebCore::ServiceWorkerRegistration::~ServiceWorkerRegistration):
+        (WebCore::ServiceWorkerRegistration::updateStateFromServer):
+
+        * workers/service/ServiceWorkerRegistrationData.cpp:
+        (WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
+        * workers/service/ServiceWorkerRegistrationData.h:
+        (WebCore::ServiceWorkerRegistrationData::encode const):
+        (WebCore::ServiceWorkerRegistrationData::decode):
+
+        * workers/service/ServiceWorkerRegistrationKey.cpp:
+        (WebCore::ServiceWorkerRegistrationKey::loggingString const):
+        * workers/service/ServiceWorkerRegistrationKey.h:
+
+        * workers/service/ServiceWorkerTypes.h:
+
+        * workers/service/context/SWContextManager.cpp:
+        (WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
+        (WebCore::SWContextManager::registerServiceWorkerThreadForUpdate): Deleted.
+        * workers/service/context/SWContextManager.h:
+
+        * workers/service/server/SWClientConnection.cpp:
+        (WebCore::SWClientConnection::updateRegistrationState):
+        (WebCore::SWClientConnection::updateWorkerState):
+        * workers/service/server/SWClientConnection.h:
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::updateWorker):
+        * workers/service/server/SWServer.h:
+        (WebCore::SWServer::workerByID const):
+
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::scriptFetchFinished):
+        (WebCore::SWServerJobQueue::scriptContextStarted):
+        (WebCore::SWServerJobQueue::install):
+        (WebCore::SWServerJobQueue::tryClearRegistration):
+
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::SWServerRegistration::updateRegistrationState):
+        (WebCore::SWServerRegistration::updateWorkerState):
+        (WebCore::SWServerRegistration::data const):
+        * workers/service/server/SWServerRegistration.h:
+        (WebCore::SWServerRegistration::setActiveServiceWorkerIdentifier): Deleted.
+
+        * workers/service/server/SWServerWorker.h:
+        (WebCore::SWServerWorker::state const):
+        (WebCore::SWServerWorker::setState):
+
 2017-11-07  Zalan Bujtas  <zalan@apple.com>
 
         [LayoutState cleanup] Remove explicit LayoutStateMaintainer::pop calls.
index bbbd39f..9f34151 100644 (file)
 #include "SerializedScriptValue.h"
 #include "ServiceWorkerProvider.h"
 #include <runtime/JSCJSValueInlines.h>
+#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
+const HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& ServiceWorker::allWorkers()
+{
+    return mutableAllWorkers();
+}
+
+HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& ServiceWorker::mutableAllWorkers()
+{
+    // FIXME: Once we support service workers from workers, this will need to change.
+    RELEASE_ASSERT(isMainThread());
+    
+    static NeverDestroyed<HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>> allWorkersMap;
+    return allWorkersMap;
+}
+
 ServiceWorker::ServiceWorker(ScriptExecutionContext& context, ServiceWorkerIdentifier identifier, const URL& scriptURL)
     : ContextDestructionObserver(&context)
     , m_identifier(identifier)
     , m_scriptURL(scriptURL)
 {
+    auto result = mutableAllWorkers().ensure(identifier, [] {
+        return HashSet<ServiceWorker*>();
+    });
+    result.iterator->value.add(this);
 }
 
-void ServiceWorker::setState(State state)
+ServiceWorker::~ServiceWorker()
 {
+    auto iterator = mutableAllWorkers().find(m_identifier);
+
+    ASSERT(iterator->value.contains(this));
+    iterator->value.remove(this);
+
+    if (iterator->value.isEmpty())
+        mutableAllWorkers().remove(iterator);
+}
+
+void ServiceWorker::updateWorkerState(State state, ShouldFireStateChangeEvent shouldFire)
+{
+    // FIXME: Once we support service workers from workers, this might need to change.
+    RELEASE_ASSERT(isMainThread());
+
     m_state = state;
-    dispatchEvent(Event::create(eventNames().statechangeEvent, false, false));
+    
+    if (shouldFire == FireStateChangeEvent)
+        dispatchEvent(Event::create(eventNames().statechangeEvent, false, false));
 }
 
 ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
index 5af3f42..06852af 100644 (file)
@@ -30,6 +30,7 @@
 #include "ContextDestructionObserver.h"
 #include "EventTarget.h"
 #include "ServiceWorkerIdentifier.h"
+#include "ServiceWorkerTypes.h"
 #include "URL.h"
 #include <heap/Strong.h>
 #include <wtf/RefCounted.h>
@@ -49,20 +50,18 @@ public:
         return adoptRef(*new ServiceWorker(context, identifier, scriptURL));
     }
 
-    virtual ~ServiceWorker() = default;
-
-    enum class State {
-        Installing,
-        Installed,
-        Activating,
-        Activated,
-        Redundant,
-    };
+    virtual ~ServiceWorker();
 
     const URL& scriptURL() const { return m_scriptURL; }
 
+    using State = ServiceWorkerState;
     State state() const { return m_state; }
-    void setState(State);
+    
+    enum ShouldFireStateChangeEvent {
+        FireStateChangeEvent,
+        DoNotFireStateChangeEvent,
+    };
+    void updateWorkerState(State, ShouldFireStateChangeEvent = FireStateChangeEvent);
 
     ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
 
@@ -71,8 +70,11 @@ public:
     using RefCounted::ref;
     using RefCounted::deref;
 
+    static const HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& allWorkers();
+
 private:
     ServiceWorker(ScriptExecutionContext&, ServiceWorkerIdentifier, const URL& scriptURL);
+    static HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& mutableAllWorkers();
 
     virtual EventTargetInterface eventTargetInterface() const;
     virtual ScriptExecutionContext* scriptExecutionContext() const;
index 7bbc29d..06d602b 100644 (file)
@@ -241,7 +241,7 @@ void ServiceWorkerContainer::getRegistration(const String& clientURL, Ref<Deferr
     });
 }
 
-void ServiceWorkerContainer::updateRegistration(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerIdentifier>& serviceWorkerIdentifier)
+void ServiceWorkerContainer::updateRegistrationState(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerIdentifier>& serviceWorkerIdentifier)
 {
     if (auto* registration = m_registrations.get(key))
         registration->updateStateFromServer(state, serviceWorkerIdentifier);
@@ -299,17 +299,17 @@ private:
                 return;
             registration->setInstallingWorker(nullptr);
             registration->setWaitingWorker(serviceWorker.copyRef());
-            serviceWorker->setState(ServiceWorker::State::Installed);
+            serviceWorker->updateWorkerState(ServiceWorker::State::Installed);
             callOnMainThread([container = WTFMove(container), registration = WTFMove(registration), serviceWorker = WTFMove(serviceWorker)] () mutable {
                 if (container->isStopped())
                     return;
                 registration->setWaitingWorker(nullptr);
                 registration->setActiveWorker(serviceWorker.copyRef());
-                serviceWorker->setState(ServiceWorker::State::Activating);
+                serviceWorker->updateWorkerState(ServiceWorker::State::Activating);
                 callOnMainThread([container = WTFMove(container), serviceWorker = WTFMove(serviceWorker)] () mutable {
                     if (container->isStopped())
                         return;
-                    serviceWorker->setState(ServiceWorker::State::Activated);
+                    serviceWorker->updateWorkerState(ServiceWorker::State::Activated);
                 });
             });
         });
@@ -346,19 +346,30 @@ void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job,
     }
 
     // FIXME: Implement proper selection of service workers.
-    auto* activeServiceWorker = context->activeServiceWorker();
-    ASSERT(data.activeServiceWorkerIdentifier);
-    if (!activeServiceWorker || activeServiceWorker->identifier() != *data.activeServiceWorkerIdentifier) {
-        context->setActiveServiceWorker(ServiceWorker::create(*context, *data.activeServiceWorkerIdentifier, data.scriptURL));
-        activeServiceWorker = context->activeServiceWorker();
+    auto* installingServiceWorker = context->activeServiceWorker();
+    ASSERT(data.installingServiceWorkerIdentifier);
+    if (!installingServiceWorker || installingServiceWorker->identifier() != *data.installingServiceWorkerIdentifier) {
+        context->setActiveServiceWorker(ServiceWorker::create(*context, *data.installingServiceWorkerIdentifier, data.scriptURL));
+        installingServiceWorker = context->activeServiceWorker();
     }
 
     RefPtr<ServiceWorkerRegistration> registration = m_registrations.get(data.key);
-    if (!registration)
+    if (!registration) {
+        // Currently the only registrations that can be created for the first time here should be Installing.
+        ASSERT(data.installingServiceWorkerIdentifier);
+        auto installingIdentifier = *data.installingServiceWorkerIdentifier;
+        
         registration = ServiceWorkerRegistration::create(*context, *this, WTFMove(data));
+        registration->updateStateFromServer(ServiceWorkerRegistrationState::Installing, installingIdentifier);
+        ASSERT(registration->installing());
+
+        installingServiceWorker = registration->installing();
+    }
+
+    installingServiceWorker->updateWorkerState(ServiceWorkerState::Installing, ServiceWorker::DoNotFireStateChangeEvent);
+    registration->setInstallingWorker(installingServiceWorker);
 
-    activeServiceWorker->setState(ServiceWorker::State::Installing);
-    registration->setInstallingWorker(activeServiceWorker);
+    LOG(ServiceWorker, "Container %p resolved job with registration %p", this, registration.get());
 
     job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(*registration);
 }
index f230576..737de48 100644 (file)
@@ -65,7 +65,7 @@ public:
     void updateRegistration(const URL& scopeURL, const URL& scriptURL, WorkerType, Ref<DeferredPromise>&&);
 
     void getRegistration(const String& clientURL, Ref<DeferredPromise>&&);
-    void updateRegistration(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerIdentifier>&);
+    void updateRegistrationState(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerIdentifier>&);
     void fireUpdateFoundEvent(const ServiceWorkerRegistrationKey&);
     void firePostInstallEvents(const ServiceWorkerRegistrationKey&);
 
index 3a3813e..a4a5556 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(SERVICE_WORKER)
 #include "DOMWindow.h"
 #include "Document.h"
+#include "Logging.h"
 #include "ServiceWorker.h"
 #include "ServiceWorkerContainer.h"
 #include "ServiceWorkerTypes.h"
@@ -41,12 +42,15 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(ScriptExecutionContext& con
     , m_registrationData(WTFMove(registrationData))
     , m_container(WTFMove(container))
 {
+    LOG(ServiceWorker, "Creating registration %p for registration key %s", this, m_registrationData.key.loggingString().utf8().data());
     suspendIfNeeded();
     m_container->addRegistration(*this);
 }
 
 ServiceWorkerRegistration::~ServiceWorkerRegistration()
 {
+    LOG(ServiceWorker, "Deleting registration %p for registration key %s", this, m_registrationData.key.loggingString().utf8().data());
+
     m_container->removeRegistration(*this);
 }
 
@@ -145,9 +149,25 @@ void ServiceWorkerRegistration::unregister(Ref<DeferredPromise>&& promise)
 
 void ServiceWorkerRegistration::updateStateFromServer(ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
 {
-    // FIXME: Implement here along with "Update Worker State" algorithm
-    UNUSED_PARAM(state);
-    UNUSED_PARAM(serviceWorkerIdentifier);
+    auto* context = scriptExecutionContext();
+    if (!context)
+        return;
+
+    RefPtr<ServiceWorker> worker;
+    if (serviceWorkerIdentifier)
+        worker = ServiceWorker::create(*context, *serviceWorkerIdentifier, m_registrationData.scriptURL);
+
+    switch (state) {
+    case ServiceWorkerRegistrationState::Installing:
+        m_installingWorker = WTFMove(worker);
+        break;
+    case ServiceWorkerRegistrationState::Waiting:
+        m_waitingWorker = WTFMove(worker);
+        break;
+    case ServiceWorkerRegistrationState::Active:
+        m_activeWorker = WTFMove(worker);
+        break;
+    }
 }
 
 EventTargetInterface ServiceWorkerRegistration::eventTargetInterface() const
index 68794d4..416c5e2 100644 (file)
@@ -35,10 +35,12 @@ ServiceWorkerRegistrationData ServiceWorkerRegistrationData::isolatedCopy() cons
     return {
         key.isolatedCopy(),
         identifier,
-        activeServiceWorkerIdentifier,
         scopeURL.isolatedCopy(),
         scriptURL.isolatedCopy(),
-        updateViaCache
+        updateViaCache,
+        installingServiceWorkerIdentifier,
+        waitingServiceWorkerIdentifier,
+        activeServiceWorkerIdentifier,
     };
 }
 
index 2e84d7e..acd324e 100644 (file)
@@ -37,11 +37,14 @@ enum class ServiceWorkerUpdateViaCache;
 struct ServiceWorkerRegistrationData {
     ServiceWorkerRegistrationKey key;
     uint64_t identifier;
-    std::optional<ServiceWorkerIdentifier> activeServiceWorkerIdentifier; // FIXME: This should not be part of registrationData.
     URL scopeURL;
     URL scriptURL;
     ServiceWorkerUpdateViaCache updateViaCache;
 
+    std::optional<ServiceWorkerIdentifier> installingServiceWorkerIdentifier;
+    std::optional<ServiceWorkerIdentifier> waitingServiceWorkerIdentifier;
+    std::optional<ServiceWorkerIdentifier> activeServiceWorkerIdentifier;
+
     ServiceWorkerRegistrationData isolatedCopy() const;
 
     template<class Encoder> void encode(Encoder&) const;
@@ -52,7 +55,7 @@ struct ServiceWorkerRegistrationData {
 template<class Encoder>
 void ServiceWorkerRegistrationData::encode(Encoder& encoder) const
 {
-    encoder << key << identifier << activeServiceWorkerIdentifier << scopeURL << scriptURL << updateViaCache;
+    encoder << key << identifier << scopeURL << scriptURL << updateViaCache << installingServiceWorkerIdentifier << waitingServiceWorkerIdentifier << activeServiceWorkerIdentifier;
 }
 
 template<class Decoder>
@@ -68,12 +71,6 @@ std::optional<ServiceWorkerRegistrationData> ServiceWorkerRegistrationData::deco
     if (!identifier)
         return std::nullopt;
 
-
-    std::optional<std::optional<ServiceWorkerIdentifier>> activeServiceWorkerIdentifier;
-    decoder >> activeServiceWorkerIdentifier;
-    if (!activeServiceWorkerIdentifier)
-        return std::nullopt;
-
     std::optional<URL> scopeURL;
     decoder >> scopeURL;
     if (!scopeURL)
@@ -89,7 +86,22 @@ std::optional<ServiceWorkerRegistrationData> ServiceWorkerRegistrationData::deco
     if (!updateViaCache)
         return std::nullopt;
 
-    return { { WTFMove(*key), WTFMove(*identifier), WTFMove(*activeServiceWorkerIdentifier), WTFMove(*scopeURL), WTFMove(*scriptURL), WTFMove(*updateViaCache) } };
+    std::optional<std::optional<ServiceWorkerIdentifier>> installingServiceWorkerIdentifier;
+    decoder >> installingServiceWorkerIdentifier;
+    if (!installingServiceWorkerIdentifier)
+        return std::nullopt;
+
+    std::optional<std::optional<ServiceWorkerIdentifier>> waitingServiceWorkerIdentifier;
+    decoder >> waitingServiceWorkerIdentifier;
+    if (!waitingServiceWorkerIdentifier)
+        return std::nullopt;
+
+    std::optional<std::optional<ServiceWorkerIdentifier>> activeServiceWorkerIdentifier;
+    decoder >> activeServiceWorkerIdentifier;
+    if (!activeServiceWorkerIdentifier)
+        return std::nullopt;
+
+    return { { WTFMove(*key), WTFMove(*identifier), WTFMove(*scopeURL), WTFMove(*scriptURL), WTFMove(*updateViaCache), WTFMove(*installingServiceWorkerIdentifier), WTFMove(*waitingServiceWorkerIdentifier), WTFMove(*activeServiceWorkerIdentifier) } };
 }
 
 } // namespace WTF
index 072e923..440729b 100644 (file)
@@ -76,6 +76,13 @@ bool ServiceWorkerRegistrationKey::isMatching(const SecurityOriginData& topOrigi
     return clientURL.string().startsWith(m_scope);
 }
 
+#ifndef NDEBUG
+String ServiceWorkerRegistrationKey::loggingString() const
+{
+    return makeString(m_topOrigin.debugString(), "-", m_clientCreationURL.string(), "-", m_scope.string());
+}
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)
index 2597064..0bf2cbd 100644 (file)
@@ -53,6 +53,10 @@ public:
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<ServiceWorkerRegistrationKey> decode(Decoder&);
 
+#ifndef NDEBUG
+    String loggingString() const;
+#endif
+
 private:
     URL m_clientCreationURL;
     SecurityOriginData m_topOrigin;
index 44d5f42..d640299 100644 (file)
@@ -35,6 +35,14 @@ enum class ServiceWorkerRegistrationState {
     Active = 2,
 };
 
+enum class ServiceWorkerState {
+    Installing,
+    Installed,
+    Activating,
+    Activated,
+    Redundant,
+};
+
 } // namespace WebCore
 
 #endif // ENABLE(SERVICE_WORKER)
index de6ef3a..49b6eb3 100644 (file)
@@ -47,7 +47,7 @@ auto SWContextManager::connection() const -> Connection*
     return m_connection.get();
 }
 
-void SWContextManager::registerServiceWorkerThreadForUpdate(Ref<ServiceWorkerThreadProxy>&& serviceWorkerThreadProxy)
+void SWContextManager::registerServiceWorkerThreadForInstall(Ref<ServiceWorkerThreadProxy>&& serviceWorkerThreadProxy)
 {
     auto serviceWorkerIdentifier = serviceWorkerThreadProxy->identifier();
     auto* threadProxy = serviceWorkerThreadProxy.ptr();
index 9ae1bd9..5d84773 100644 (file)
@@ -53,10 +53,11 @@ public:
     WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
     WEBCORE_EXPORT Connection* connection() const;
 
-    WEBCORE_EXPORT void registerServiceWorkerThreadForUpdate(Ref<ServiceWorkerThreadProxy>&&);
+    WEBCORE_EXPORT void registerServiceWorkerThreadForInstall(Ref<ServiceWorkerThreadProxy>&&);
     WEBCORE_EXPORT ServiceWorkerThreadProxy* serviceWorkerThreadProxy(ServiceWorkerIdentifier) const;
     WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
     WEBCORE_EXPORT void fireInstallEvent(ServiceWorkerIdentifier);
+
 private:
     SWContextManager() = default;
 
index 6e30c32..d9341b8 100644 (file)
@@ -150,10 +150,18 @@ void SWClientConnection::forEachContainer(const WTF::Function<void(ServiceWorker
 void SWClientConnection::updateRegistrationState(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
 {
     forEachContainer([&](ServiceWorkerContainer& container) {
-        container.updateRegistration(key, state, serviceWorkerIdentifier);
+        container.updateRegistrationState(key, state, serviceWorkerIdentifier);
     });
 }
 
+void SWClientConnection::updateWorkerState(ServiceWorkerIdentifier worker, ServiceWorkerState state)
+{
+    const auto& matchingWorkers = ServiceWorker::allWorkers().get(worker);
+    
+    for (auto* worker : matchingWorkers)
+        worker->updateWorkerState(state);
+}
+
 void SWClientConnection::fireUpdateFoundEvent(const ServiceWorkerRegistrationKey& key)
 {
     forEachContainer([&](ServiceWorkerContainer& container) {
index 0fc8a44..bff3c62 100644 (file)
@@ -40,6 +40,7 @@ class ServiceWorkerContainer;
 class ServiceWorkerRegistration;
 class SharedBuffer;
 enum class ServiceWorkerRegistrationState;
+enum class ServiceWorkerState;
 struct ExceptionData;
 struct ServiceWorkerFetchResult;
 struct ServiceWorkerRegistrationData;
@@ -68,6 +69,7 @@ protected:
     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(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>);
+    WEBCORE_EXPORT void updateWorkerState(ServiceWorkerIdentifier, ServiceWorkerState);
     WEBCORE_EXPORT void fireUpdateFoundEvent(const ServiceWorkerRegistrationKey&);
     WEBCORE_EXPORT void firePostInstallEvents(const ServiceWorkerRegistrationKey&);
 
index 531e94c..1f69207 100644 (file)
@@ -262,11 +262,11 @@ void SWServer::removeClientServiceWorkerRegistration(Connection& connection, con
 Ref<SWServerWorker> SWServer::updateWorker(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type)
 {
     auto serviceWorkerIdentifier = generateServiceWorkerIdentifier();
-    
+
     auto result = m_workersByID.add(serviceWorkerIdentifier, SWServerWorker::create(registrationKey, url, script, type, serviceWorkerIdentifier));
     ASSERT(result.isNewEntry);
-    
-    connection.updateServiceWorkerContext({ registrationKey, serviceWorkerIdentifier, script, url });
+
+    connection.installServiceWorkerContext({ registrationKey, serviceWorkerIdentifier, script, url });
     
     return result.iterator->value.get();
 }
index b758af9..ef6a02c 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(SERVICE_WORKER)
 
+#include "SWServerWorker.h"
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerJob.h"
 #include "ServiceWorkerRegistrationData.h"
@@ -44,8 +45,8 @@ namespace WebCore {
 
 class SWServerJobQueue;
 class SWServerRegistration;
-class SWServerWorker;
 enum class ServiceWorkerRegistrationState;
+enum class ServiceWorkerState;
 struct ExceptionData;
 struct ServiceWorkerContextData;
 struct ServiceWorkerFetchResult;
@@ -65,6 +66,7 @@ public:
 
         // Messages to the client WebProcess
         virtual void updateRegistrationStateInClient(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>) = 0;
+        virtual void updateWorkerStateInClient(ServiceWorkerIdentifier, ServiceWorkerState) = 0;
         virtual void fireUpdateFoundEvent(const ServiceWorkerRegistrationKey&) = 0;
         virtual void firePostInstallEvents(const ServiceWorkerRegistrationKey&) = 0;
 
@@ -85,7 +87,7 @@ public:
         virtual void startScriptFetchInClient(uint64_t jobIdentifier) = 0;
 
         // Messages to the SW host WebProcess
-        virtual void updateServiceWorkerContext(const ServiceWorkerContextData&) = 0;
+        virtual void installServiceWorkerContext(const ServiceWorkerContextData&) = 0;
         virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
 
         SWServer& m_server;
@@ -111,6 +113,7 @@ public:
 
     Ref<SWServerWorker> updateWorker(Connection&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);
     void fireInstallEvent(Connection&, ServiceWorkerIdentifier);
+    SWServerWorker* workerByID(ServiceWorkerIdentifier identifier) const { return m_workersByID.get(identifier); }
     
     Connection* getConnection(uint64_t identifier) { return m_connections.get(identifier); }
 
index 27e3ddd..448cdb6 100644 (file)
@@ -73,20 +73,11 @@ void SWServerJobQueue::scriptFetchFinished(SWServer::Connection& connection, con
         return;
     }
 
-    // If newestWorker is not null, newestWorker's script url equals job's script url with the exclude fragments
+    // FIXME: If newestWorker is not null, newestWorker's script url equals job's script url with the exclude fragments
     // flag set, and script's source text is a byte-for-byte match with newestWorker's script resource's source
     // text, then:
-    if (newestWorker && equalIgnoringFragmentIdentifier(newestWorker->scriptURL(), job.scriptURL) && result.script == newestWorker->script()) {
-        // FIXME: if script is a classic script, and script's module record's [[ECMAScriptCode]] is a byte-for-byte
-        // match with newestWorker's script resource's module record's [[ECMAScriptCode]] otherwise.
-
-        // Invoke Resolve Job Promise with job and registration.
-        m_server.resolveRegistrationJob(job, registration->data());
-
-        // Invoke Finish Job with job and abort these steps.
-        finishCurrentJob();
-        return;
-    }
+    // - Invoke Resolve Job Promise with job and registration.
+    // - Invoke Finish Job with job and abort these steps.
 
     // FIXME: Support the proper worker type (classic vs module)
     m_server.updateWorker(connection, m_registrationKey, job.scriptURL, result.script, WorkerType::Classic);
@@ -113,14 +104,20 @@ void SWServerJobQueue::scriptContextStarted(SWServer::Connection& connection, Se
 {
     auto* registration = m_server.getRegistration(m_registrationKey);
     ASSERT(registration);
-    registration->setActiveServiceWorkerIdentifier(identifier);
 
     install(*registration, connection, identifier);
 }
 
 // https://w3c.github.io/ServiceWorker/#install
-void SWServerJobQueue::install(SWServerRegistration& registration, SWServer::Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier)
+void SWServerJobQueue::install(SWServerRegistration& registration, SWServer::Connection& connection, ServiceWorkerIdentifier installingWorker)
 {
+    // The Install algorithm should never be invoked with a null worker.
+    auto* worker = m_server.workerByID(installingWorker);
+    RELEASE_ASSERT(worker);
+
+    registration.updateRegistrationState(ServiceWorkerRegistrationState::Installing, worker);
+    registration.updateWorkerState(*worker, ServiceWorkerState::Installing);
+
     // Invoke Resolve Job Promise with job and registration.
     m_server.resolveRegistrationJob(firstJob(), registration.data());
 
@@ -130,7 +127,7 @@ void SWServerJobQueue::install(SWServerRegistration& registration, SWServer::Con
     registration.fireUpdateFoundEvent(firstJob().connectionIdentifier());
 
     // Queue a task to fire the InstallEvent.
-    m_server.fireInstallEvent(connection, serviceWorkerIdentifier);
+    m_server.fireInstallEvent(connection, installingWorker);
 }
 
 // https://w3c.github.io/ServiceWorker/#install
@@ -250,9 +247,9 @@ void SWServerJobQueue::tryClearRegistration(SWServerRegistration& registration)
 {
     // FIXME: Make sure that the registration has no service worker client.
 
-    // FIXME: The specification has more complex logic here.
-    if (!registration.getNewestWorker())
-        clearRegistration(registration);
+    // FIXME: The specification has more complex logic here. We currently clear registrations
+    // too aggressively.
+    clearRegistration(registration);
 }
 
 // https://w3c.github.io/ServiceWorker/#clear-registration
index 7b14857..e5bab02 100644 (file)
@@ -61,6 +61,8 @@ SWServerWorker* SWServerRegistration::getNewestWorker()
 
 void SWServerRegistration::updateRegistrationState(ServiceWorkerRegistrationState state, SWServerWorker* worker)
 {
+    LOG(ServiceWorker, "(%p) Updating registration state to %i with worker %p", this, (int)state, worker);
+    
     switch (state) {
     case ServiceWorkerRegistrationState::Installing:
         m_installingWorker = worker;
@@ -83,6 +85,18 @@ void SWServerRegistration::updateRegistrationState(ServiceWorkerRegistrationStat
     }
 }
 
+void SWServerRegistration::updateWorkerState(SWServerWorker& worker, ServiceWorkerState state)
+{
+    LOG(ServiceWorker, "Updating worker %p state to %i (%p)", &worker, (int)state, this);
+
+    worker.setState(state);
+
+    for (auto& connectionIdentifierWithClients : m_clientRegistrationsByConnection.keys()) {
+        if (auto* connection = m_server.getConnection(connectionIdentifierWithClients))
+            connection->updateWorkerStateInClient(worker.identifier(), state);
+    }
+}
+
 void SWServerRegistration::fireUpdateFoundEvent(uint64_t connectionIdentifier)
 {
     // No matter what, we send the event to the connection that scheduled the job. The client registration
@@ -115,7 +129,19 @@ void SWServerRegistration::firePostInstallEvents(uint64_t connectionIdentifier)
 
 ServiceWorkerRegistrationData SWServerRegistration::data() const
 {
-    return { m_registrationKey, identifier(), m_activeServiceWorkerIdentifier, m_scopeURL, m_scriptURL, m_updateViaCache };
+    std::optional<ServiceWorkerIdentifier> installingID;
+    if (m_installingWorker)
+        installingID = m_installingWorker->identifier();
+
+    std::optional<ServiceWorkerIdentifier> waitingID;
+    if (m_waitingWorker)
+        waitingID = m_waitingWorker->identifier();
+
+    std::optional<ServiceWorkerIdentifier> activeID;
+    if (m_activeWorker)
+        activeID = m_activeWorker->identifier();
+
+    return { m_registrationKey, identifier(), m_scopeURL, m_scriptURL, m_updateViaCache, installingID, waitingID, activeID };
 }
 
 void SWServerRegistration::addClientServiceWorkerRegistration(uint64_t connectionIdentifier, uint64_t clientRegistrationIdentifier)
index 93bcc4d..d92f43e 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
 class SWServer;
 class SWServerWorker;
 enum class ServiceWorkerRegistrationState;
+enum class ServiceWorkerState;
 struct ExceptionData;
 struct ServiceWorkerFetchResult;
 
@@ -55,9 +56,8 @@ public:
     void setLastUpdateTime(double time) { m_lastUpdateTime = time; }
     ServiceWorkerUpdateViaCache updateViaCache() const { return m_updateViaCache; }
 
-    void setActiveServiceWorkerIdentifier(ServiceWorkerIdentifier identifier) { m_activeServiceWorkerIdentifier = identifier; }
-
     void updateRegistrationState(ServiceWorkerRegistrationState, SWServerWorker*);
+    void updateWorkerState(SWServerWorker&, ServiceWorkerState);
     void fireUpdateFoundEvent(uint64_t connectionIdentifier);
     void firePostInstallEvents(uint64_t connectionIdentifier);
 
@@ -75,8 +75,6 @@ private:
     RefPtr<SWServerWorker> m_waitingWorker;
     RefPtr<SWServerWorker> m_activeWorker;
 
-    std::optional<ServiceWorkerIdentifier> m_activeServiceWorkerIdentifier;
-
     double m_lastUpdateTime { 0 };
     
     HashMap<uint64_t, std::unique_ptr<HashSet<uint64_t>>> m_clientRegistrationsByConnection;
index f8a5548..a3c8145 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "ServiceWorkerIdentifier.h"
 #include "ServiceWorkerRegistrationKey.h"
+#include "ServiceWorkerTypes.h"
 #include "URL.h"
 #include <wtf/ThreadSafeRefCounted.h>
 
@@ -49,8 +50,12 @@ public:
     const URL& scriptURL() const { return m_scriptURL; }
     const String& script() const { return m_script; }
     WorkerType type() const { return m_type; }
+
     ServiceWorkerIdentifier identifier() const { return m_identifier; }
-    
+
+    ServiceWorkerState state() const { return m_state; }
+    void setState(ServiceWorkerState state) { m_state = state; }
+
 private:
     SWServerWorker(const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
 
@@ -59,6 +64,8 @@ private:
     String m_script;
     ServiceWorkerIdentifier m_identifier;
     WorkerType m_type;
+    
+    ServiceWorkerState m_state { ServiceWorkerState::Redundant };
 };
 
 } // namespace WebCore
index 251a894..5be060f 100644 (file)
@@ -1,3 +1,29 @@
+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        * Scripts/webkit/messages.py:
+        (headers_for_type):
+        * Shared/WebCoreArgumentCoders.h:
+       * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::updateWorkerStateInClient):
+        (WebKit::WebSWServerConnection::installServiceWorkerContext):
+        (WebKit::WebSWServerConnection::setContextConnection):
+        (WebKit::WebSWServerConnection::updateServiceWorkerContext): Deleted.
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+
+        * WebProcess/Storage/WebSWClientConnection.messages.in:
+
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::installServiceWorker):
+        (WebKit::WebSWContextManagerConnection::updateServiceWorker): Deleted.
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
 2017-11-07  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r224512 and r224521.
index 8a65d05..2db00f0 100644 (file)
@@ -373,6 +373,7 @@ def headers_for_type(type):
         'WebCore::PolicyAction': ['<WebCore/FrameLoaderTypes.h>'],
         'WebCore::RecentSearch': ['<WebCore/SearchPopupMenu.h>'],
         'WebCore::ServiceWorkerRegistrationState': ['<WebCore/ServiceWorkerTypes.h>'],
+        'WebCore::ServiceWorkerState': ['<WebCore/ServiceWorkerTypes.h>'],
         'WebCore::ShippingContactUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
         'WebCore::ShippingMethodUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
         'WebCore::ShouldSample': ['<WebCore/DiagnosticLoggingClient.h>'],
index 76d76e3..33596be 100644 (file)
@@ -815,6 +815,17 @@ template <> struct EnumTraits<WebCore::ServiceWorkerRegistrationState> {
         WebCore::ServiceWorkerRegistrationState::Active
     >;
 };
+    
+template <> struct EnumTraits<WebCore::ServiceWorkerState> {
+    using values = EnumValues<
+        WebCore::ServiceWorkerState,
+        WebCore::ServiceWorkerState::Installing,
+        WebCore::ServiceWorkerState::Installed,
+        WebCore::ServiceWorkerState::Activating,
+        WebCore::ServiceWorkerState::Activated,
+        WebCore::ServiceWorkerState::Redundant
+    >;
+};
 #endif
 
 } // namespace WTF
index 0178595..856df0e 100644 (file)
@@ -111,9 +111,14 @@ void WebSWServerConnection::firePostInstallEvents(const ServiceWorkerRegistratio
     send(Messages::WebSWClientConnection::FirePostInstallEvents(key));
 }
 
-void WebSWServerConnection::updateServiceWorkerContext(const ServiceWorkerContextData& data)
+void WebSWServerConnection::updateWorkerStateInClient(ServiceWorkerIdentifier worker, ServiceWorkerState state)
 {
-    if (sendToContextProcess(Messages::WebSWContextManagerConnection::UpdateServiceWorker(identifier(), data)))
+    send(Messages::WebSWClientConnection::UpdateWorkerState(worker, state));
+}
+
+void WebSWServerConnection::installServiceWorkerContext(const ServiceWorkerContextData& data)
+{
+    if (sendToContextProcess(Messages::WebSWContextManagerConnection::InstallServiceWorker(identifier(), data)))
         return;
 
     m_pendingContextDatas.append(data);
@@ -188,7 +193,7 @@ void WebSWServerConnection::setContextConnection(IPC::Connection* connection)
 
     // We can now start any pending service worker updates.
     for (auto& pendingContextData : m_pendingContextDatas)
-        updateServiceWorkerContext(pendingContextData);
+        installServiceWorkerContext(pendingContextData);
     
     m_pendingContextDatas.clear();
 }
index 30124e5..9779728 100644 (file)
@@ -66,6 +66,7 @@ private:
     void resolveUnregistrationJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationKey&, bool unregistrationResult) final;
     void startScriptFetchInClient(uint64_t jobIdentifier) final;
     void updateRegistrationStateInClient(const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerRegistrationState, std::optional<WebCore::ServiceWorkerIdentifier>) final;
+    void updateWorkerStateInClient(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerState) final;
     void fireUpdateFoundEvent(const WebCore::ServiceWorkerRegistrationKey&) final;
     void firePostInstallEvents(const WebCore::ServiceWorkerRegistrationKey&) final;
 
@@ -76,7 +77,7 @@ private:
     void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData&, const WebCore::URL& clientURL);
 
     // Messages to the SW context WebProcess
-    void updateServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
+    void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
     void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
 
     IPC::Connection* messageSenderConnection() final { return m_contentConnection.ptr(); }
index fb0a1d6..c0330e3 100644 (file)
@@ -29,6 +29,7 @@ messages -> WebSWClientConnection {
     UnregistrationJobResolvedInServer(uint64_t identifier, bool unregistrationResult)
     StartScriptFetchForServer(uint64_t jobIdentifier)
     UpdateRegistrationState(WebCore::ServiceWorkerRegistrationKey key, enum WebCore::ServiceWorkerRegistrationState state, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier)
+    UpdateWorkerState(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, enum WebCore::ServiceWorkerState state)
     FireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationKey key)
     FirePostInstallEvents(WebCore::ServiceWorkerRegistrationKey key)
 
index 46be339..db3197c 100644 (file)
@@ -95,7 +95,7 @@ void WebSWContextManagerConnection::updatePreferences(const WebPreferencesStore&
     RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey()));
 }
 
-void WebSWContextManagerConnection::updateServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
+void WebSWContextManagerConnection::installServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
 {
     // FIXME: Provide a sensical session ID.
     auto sessionID = PAL::SessionID::defaultSessionID();
@@ -114,7 +114,7 @@ void WebSWContextManagerConnection::updateServiceWorker(uint64_t serverConnectio
     pageConfiguration.loaderClientForMainFrame = frameLoaderClient.release();
 
     auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, WebProcess::singleton().cacheStorageProvider());
-    SWContextManager::singleton().registerServiceWorkerThreadForUpdate(WTFMove(serviceWorkerThreadProxy));
+    SWContextManager::singleton().registerServiceWorkerThreadForInstall(WTFMove(serviceWorkerThreadProxy));
 
     LOG(ServiceWorker, "Context process PID: %i created worker thread\n", getpid());
 }
index 66d4596..031ab2f 100644 (file)
@@ -56,7 +56,7 @@ private:
 
     // IPC messages.
     void serviceWorkerStartedWithMessage(WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
-    void updateServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
+    void installServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
     void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, const WebCore::ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
     void fireInstallEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier);
index 5d149c6..2b51526 100644 (file)
@@ -23,7 +23,7 @@
 #if ENABLE(SERVICE_WORKER)
 
 messages -> WebSWContextManagerConnection {
-    UpdateServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
+    InstallServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
     StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
     PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, String sourceOrigin)
     FireInstallEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier identifier)