Support updating a service worker registration's updateViaCache flag
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Dec 2017 00:48:04 +0000 (00:48 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Dec 2017 00:48:04 +0000 (00:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180888

Reviewed by Brady Eidson.

LayoutTests/imported/w3c:

Rebaseline WPT test now that more checks are passing.

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

Source/WebCore:

Support updating a service worker registration's updateViaCache flag to match other browsers:
- https://github.com/w3c/ServiceWorker/issues/1189

No new tests, rebaselined existing test.

* workers/service/SWClientConnection.cpp:
(WebCore::SWClientConnection::setRegistrationUpdateViaCache):
* workers/service/SWClientConnection.h:
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::setUpdateViaCache):
* workers/service/ServiceWorkerRegistration.h:
* workers/service/server/SWServer.h:
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::runRegisterJob):
* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::setUpdateViaCache):
* workers/service/server/SWServerRegistration.h:

Source/WebKit:

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::setRegistrationUpdateViaCache):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
* WebProcess/Storage/WebSWClientConnection.messages.in:

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

15 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-updateviacache.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/workers/service/SWClientConnection.cpp
Source/WebCore/workers/service/SWClientConnection.h
Source/WebCore/workers/service/ServiceWorkerRegistration.cpp
Source/WebCore/workers/service/ServiceWorkerRegistration.h
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/WebKit/ChangeLog
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in

index 63f3908..b3980e4 100644 (file)
@@ -1,5 +1,16 @@
 2017-12-15  Chris Dumez  <cdumez@apple.com>
 
+        Support updating a service worker registration's updateViaCache flag
+        https://bugs.webkit.org/show_bug.cgi?id=180888
+
+        Reviewed by Brady Eidson.
+
+        Rebaseline WPT test now that more checks are passing.
+
+        * web-platform-tests/service-workers/service-worker/registration-updateviacache.https-expected.txt:
+
+2017-12-15  Chris Dumez  <cdumez@apple.com>
+
         Unreviewed, rebaseline Service Workers flaky tests.
 
         * web-platform-tests/service-workers/cache-storage/serviceworker/cache-match.https-expected.txt:
index cf43e8e..fc7773d 100644 (file)
@@ -5,18 +5,18 @@ FAIL register-with-updateViaCache-all assert_equals: No new service worker expec
 PASS register-with-updateViaCache-none 
 PASS register-with-updateViaCache-undefined-then-undefined 
 PASS register-with-updateViaCache-undefined-then-imports 
-FAIL register-with-updateViaCache-undefined-then-all assert_equals: reg.updateViaCache updated expected "all" but got "imports"
-FAIL register-with-updateViaCache-undefined-then-none assert_equals: reg.updateViaCache updated expected "none" but got "imports"
+FAIL register-with-updateViaCache-undefined-then-all assert_equals: No new service worker expected null but got object "[object ServiceWorker]"
+PASS register-with-updateViaCache-undefined-then-none 
 PASS register-with-updateViaCache-imports-then-undefined 
 PASS register-with-updateViaCache-imports-then-imports 
-FAIL register-with-updateViaCache-imports-then-all assert_equals: reg.updateViaCache updated expected "all" but got "imports"
-FAIL register-with-updateViaCache-imports-then-none assert_equals: reg.updateViaCache updated expected "none" but got "imports"
-FAIL register-with-updateViaCache-all-then-undefined assert_equals: reg.updateViaCache updated expected "imports" but got "all"
-FAIL register-with-updateViaCache-all-then-imports assert_equals: reg.updateViaCache updated expected "imports" but got "all"
+FAIL register-with-updateViaCache-imports-then-all assert_equals: No new service worker expected null but got object "[object ServiceWorker]"
+PASS register-with-updateViaCache-imports-then-none 
+PASS register-with-updateViaCache-all-then-undefined 
+PASS register-with-updateViaCache-all-then-imports 
 PASS register-with-updateViaCache-all-then-all 
-FAIL register-with-updateViaCache-all-then-none assert_equals: reg.updateViaCache updated expected "none" but got "all"
-FAIL register-with-updateViaCache-none-then-undefined assert_equals: reg.updateViaCache updated expected "imports" but got "none"
-FAIL register-with-updateViaCache-none-then-imports assert_equals: reg.updateViaCache updated expected "imports" but got "none"
-FAIL register-with-updateViaCache-none-then-all assert_equals: reg.updateViaCache updated expected "all" but got "none"
+PASS register-with-updateViaCache-all-then-none 
+PASS register-with-updateViaCache-none-then-undefined 
+PASS register-with-updateViaCache-none-then-imports 
+FAIL register-with-updateViaCache-none-then-all assert_equals: No new service worker expected null but got object "[object ServiceWorker]"
 PASS register-with-updateViaCache-none-then-none 
 
index 95cb657..9abe3e7 100644 (file)
@@ -1,3 +1,28 @@
+2017-12-15  Chris Dumez  <cdumez@apple.com>
+
+        Support updating a service worker registration's updateViaCache flag
+        https://bugs.webkit.org/show_bug.cgi?id=180888
+
+        Reviewed by Brady Eidson.
+
+        Support updating a service worker registration's updateViaCache flag to match other browsers:
+        - https://github.com/w3c/ServiceWorker/issues/1189
+
+        No new tests, rebaselined existing test.
+
+        * workers/service/SWClientConnection.cpp:
+        (WebCore::SWClientConnection::setRegistrationUpdateViaCache):
+        * workers/service/SWClientConnection.h:
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::setUpdateViaCache):
+        * workers/service/ServiceWorkerRegistration.h:
+        * workers/service/server/SWServer.h:
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::runRegisterJob):
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::SWServerRegistration::setUpdateViaCache):
+        * workers/service/server/SWServerRegistration.h:
+
 2017-12-15  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r225941.
index 62094d9..6fe0611 100644 (file)
@@ -228,6 +228,27 @@ void SWClientConnection::setRegistrationLastUpdateTime(ServiceWorkerRegistration
     }
 }
 
+void SWClientConnection::setRegistrationUpdateViaCache(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerUpdateViaCache updateViaCache)
+{
+    ASSERT(isMainThread());
+
+    SWContextManager::singleton().forEachServiceWorkerThread([identifier, updateViaCache] (auto& workerThread) {
+        workerThread.thread().runLoop().postTask([identifier, updateViaCache](ScriptExecutionContext& context) {
+            if (auto* container = context.serviceWorkerContainer()) {
+                if (auto* registration = container->registration(identifier))
+                    registration->setUpdateViaCache(updateViaCache);
+            }
+        });
+    });
+
+    for (auto* document : Document::allDocuments()) {
+        if (auto* container = document->serviceWorkerContainer()) {
+            if (auto* registration = container->registration(identifier))
+                registration->setUpdateViaCache(updateViaCache);
+        }
+    }
+}
+
 void SWClientConnection::notifyClientsOfControllerChange(const HashSet<DocumentIdentifier>& contextIdentifiers, ServiceWorkerData&& newController)
 {
     ASSERT(isMainThread());
index d60a81b..7875f64 100644 (file)
@@ -95,6 +95,7 @@ protected:
     WEBCORE_EXPORT void updateWorkerState(ServiceWorkerIdentifier, ServiceWorkerState);
     WEBCORE_EXPORT void fireUpdateFoundEvent(ServiceWorkerRegistrationIdentifier);
     WEBCORE_EXPORT void setRegistrationLastUpdateTime(ServiceWorkerRegistrationIdentifier, WallTime);
+    WEBCORE_EXPORT void setRegistrationUpdateViaCache(ServiceWorkerRegistrationIdentifier, ServiceWorkerUpdateViaCache);
     WEBCORE_EXPORT void notifyClientsOfControllerChange(const HashSet<DocumentIdentifier>& contextIdentifiers, ServiceWorkerData&& newController);
 
     WEBCORE_EXPORT void clearPendingJobs();
index 0e9ffbc..8666e86 100644 (file)
@@ -122,6 +122,11 @@ void ServiceWorkerRegistration::setLastUpdateTime(WallTime lastUpdateTime)
     m_registrationData.lastUpdateTime = lastUpdateTime;
 }
 
+void ServiceWorkerRegistration::setUpdateViaCache(ServiceWorkerUpdateViaCache updateViaCache)
+{
+    m_registrationData.updateViaCache = updateViaCache;
+}
+
 void ServiceWorkerRegistration::update(Ref<DeferredPromise>&& promise)
 {
     if (m_isStopped) {
index 6a1b184..5f2841f 100644 (file)
@@ -54,7 +54,9 @@ public:
     ServiceWorker* getNewestWorker();
 
     const String& scope() const;
+
     ServiceWorkerUpdateViaCache updateViaCache() const;
+    void setUpdateViaCache(ServiceWorkerUpdateViaCache);
 
     WallTime lastUpdateTime() const;
     void setLastUpdateTime(WallTime);
index c46aae4..2773689 100644 (file)
@@ -83,6 +83,7 @@ public:
         virtual void updateWorkerStateInClient(ServiceWorkerIdentifier, ServiceWorkerState) = 0;
         virtual void fireUpdateFoundEvent(ServiceWorkerRegistrationIdentifier) = 0;
         virtual void setRegistrationLastUpdateTime(ServiceWorkerRegistrationIdentifier, WallTime) = 0;
+        virtual void setRegistrationUpdateViaCache(ServiceWorkerRegistrationIdentifier, ServiceWorkerUpdateViaCache) = 0;
         virtual void notifyClientsOfControllerChange(const HashSet<DocumentIdentifier>& contextIdentifiers, const ServiceWorkerData& newController) = 0;
         virtual void registrationReady(uint64_t registrationReadyRequestIdentifier, ServiceWorkerRegistrationData&&) = 0;
 
index c906013..eb2db5b 100644 (file)
@@ -251,6 +251,9 @@ void SWServerJobQueue::runRegisterJob(const ServiceWorkerJobData& job)
             finishCurrentJob();
             return;
         }
+        // This is not specified yet (https://github.com/w3c/ServiceWorker/issues/1189).
+        if (registration->updateViaCache() != job.registrationOptions.updateViaCache)
+            registration->setUpdateViaCache(job.registrationOptions.updateViaCache);
     } else {
         auto newRegistration = std::make_unique<SWServerRegistration>(m_server, m_registrationKey, job.registrationOptions.updateViaCache, job.scopeURL, job.scriptURL);
         m_server.addRegistration(WTFMove(newRegistration));
index fa16aff..0f3f8b8 100644 (file)
@@ -102,6 +102,14 @@ void SWServerRegistration::updateWorkerState(SWServerWorker& worker, ServiceWork
     });
 }
 
+void SWServerRegistration::setUpdateViaCache(ServiceWorkerUpdateViaCache updateViaCache)
+{
+    m_updateViaCache = updateViaCache;
+    forEachConnection([&](auto& connection) {
+        connection.setRegistrationUpdateViaCache(identifier(), updateViaCache);
+    });
+}
+
 void SWServerRegistration::setLastUpdateTime(WallTime time)
 {
     m_lastUpdateTime = time;
index 7e62633..4b0b95b 100644 (file)
@@ -63,6 +63,7 @@ public:
     void setLastUpdateTime(WallTime);
     WallTime lastUpdateTime() const { return m_lastUpdateTime; }
 
+    void setUpdateViaCache(ServiceWorkerUpdateViaCache);
     ServiceWorkerUpdateViaCache updateViaCache() const { return m_updateViaCache; }
 
     void updateRegistrationState(ServiceWorkerRegistrationState, SWServerWorker*);
index c62148f..d560c64 100644 (file)
@@ -1,3 +1,15 @@
+2017-12-15  Chris Dumez  <cdumez@apple.com>
+
+        Support updating a service worker registration's updateViaCache flag
+        https://bugs.webkit.org/show_bug.cgi?id=180888
+
+        Reviewed by Brady Eidson.
+
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::setRegistrationUpdateViaCache):
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+        * WebProcess/Storage/WebSWClientConnection.messages.in:
+
 2017-12-15  Alex Christensen  <achristensen@webkit.org>
 
         Introduce SPI _WKWebsitePolicies.websiteDataStore
index 53d9471..b24bf07 100644 (file)
@@ -111,6 +111,11 @@ void WebSWServerConnection::setRegistrationLastUpdateTime(ServiceWorkerRegistrat
     send(Messages::WebSWClientConnection::SetRegistrationLastUpdateTime(identifier, lastUpdateTime));
 }
 
+void WebSWServerConnection::setRegistrationUpdateViaCache(ServiceWorkerRegistrationIdentifier identifier, ServiceWorkerUpdateViaCache updateViaCache)
+{
+    send(Messages::WebSWClientConnection::SetRegistrationUpdateViaCache(identifier, updateViaCache));
+}
+
 void WebSWServerConnection::notifyClientsOfControllerChange(const HashSet<DocumentIdentifier>& contextIdentifiers, const ServiceWorkerData& newController)
 {
     send(Messages::WebSWClientConnection::NotifyClientsOfControllerChange(contextIdentifiers, newController));
index 807a2de..6b7a5d0 100644 (file)
@@ -79,6 +79,7 @@ private:
     void updateWorkerStateInClient(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerState) final;
     void fireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationIdentifier) final;
     void setRegistrationLastUpdateTime(WebCore::ServiceWorkerRegistrationIdentifier, WallTime) final;
+    void setRegistrationUpdateViaCache(WebCore::ServiceWorkerRegistrationIdentifier, WebCore::ServiceWorkerUpdateViaCache) final;
     void notifyClientsOfControllerChange(const HashSet<WebCore::DocumentIdentifier>& contextIdentifiers, const WebCore::ServiceWorkerData& newController);
     void registrationReady(uint64_t registrationReadyRequestIdentifier, WebCore::ServiceWorkerRegistrationData&&) final;
 
index e2f7aac..8a6006b 100644 (file)
@@ -32,6 +32,7 @@ messages -> WebSWClientConnection {
     UpdateWorkerState(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, enum WebCore::ServiceWorkerState state)
     FireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationIdentifier identifier)
     SetRegistrationLastUpdateTime(WebCore::ServiceWorkerRegistrationIdentifier identifier, WallTime lastUpdateTime)
+    SetRegistrationUpdateViaCache(WebCore::ServiceWorkerRegistrationIdentifier identifier, enum WebCore::ServiceWorkerUpdateViaCache updateViaCache);
     NotifyClientsOfControllerChange(HashSet<WebCore::DocumentIdentifier> contextIdentifiers, struct WebCore::ServiceWorkerData newController)
 
     SetSWOriginTableIsImported()