Diff
Modified: trunk/LayoutTests/ChangeLog (250377 => 250378)
--- trunk/LayoutTests/ChangeLog 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/LayoutTests/ChangeLog 2019-09-26 04:30:39 UTC (rev 250378)
@@ -1,5 +1,18 @@
2019-09-25 Chris Dumez <[email protected]>
+ Improve Service worker support for Page Caching
+ https://bugs.webkit.org/show_bug.cgi?id=202221
+
+ Reviewed by Geoffrey Garen.
+
+ Add layout test coverage.
+
+ * http/tests/workers/service/no-page-cache-when-controlled-expected.txt: Removed.
+ * http/tests/workers/service/page-caching-expected.txt: Added.
+ * http/tests/workers/service/page-caching.html: Renamed from LayoutTests/http/tests/workers/service/no-page-cache-when-controlled.html.
+
+2019-09-25 Chris Dumez <[email protected]>
+
[Cocoa] Regression(r212041) Safari adds a .dms extension automatically when downloading binaries with no extension
https://bugs.webkit.org/show_bug.cgi?id=202147
<rdar://problem/54886021>
Deleted: trunk/LayoutTests/http/tests/workers/service/no-page-cache-when-controlled-expected.txt (250377 => 250378)
--- trunk/LayoutTests/http/tests/workers/service/no-page-cache-when-controlled-expected.txt 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/LayoutTests/http/tests/workers/service/no-page-cache-when-controlled-expected.txt 2019-09-26 04:30:39 UTC (rev 250378)
@@ -1,3 +0,0 @@
-pageshow - not from page cache
-PASS: page did not enter page cache
-
Deleted: trunk/LayoutTests/http/tests/workers/service/no-page-cache-when-controlled.html (250377 => 250378)
--- trunk/LayoutTests/http/tests/workers/service/no-page-cache-when-controlled.html 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/LayoutTests/http/tests/workers/service/no-page-cache-when-controlled.html 2019-09-26 04:30:39 UTC (rev 250378)
@@ -1,57 +0,0 @@
-<html>
-<head>
-<script src=""
-</head>
-<body>
-<script>
-let initialController = null;
-
-if (window.testRunner) {
- testRunner.setCanOpenWindows();
- testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
-}
-
-window.addEventListener("pageshow", function(event) {
- log("pageshow - " + (event.persisted ? "" : "not ") + "from page cache");
- if (!window.sessionStorage.sw_page_cache_with_controller_test_started)
- return;
-
- if (event.persisted)
- log("FAIL: page entered page cache even though its iframe has a controller");
- else
- log("PASS: page did not enter page cache");
-
- finishSWTest();
-});
-
-window.addEventListener("pagehide", function(event) {
- log("pagehide - " + (event.persisted ? "" : "not ") + "entering page cache");
- if (event.persisted) {
- log("FAIL: page entering page cache even though its iframe has a controller");
- finishSWTest();
- }
-});
-
-async function test() {
- let scopeURL = "/workers/service/resources/";
- await registerAndWaitForActive("resources/updating-fetch-worker.php", scopeURL);
- let frame = await withFrame(scopeURL);
- if (frame.contentWindow.navigator.serviceWorker.controller === null) {
- log("FAIL: frame does not have a controller");
- finishSWTest();
- return;
- }
-
- log("PASS: frame has a controller");
-
- gc();
- setTimeout(function() {
- window.sessionStorage.sw_page_cache_with_controller_test_started = true;
- location.href = ""
- }, 0);
-}
-
-window._onload_ = test;
-</script>
-</body>
-</html>
Added: trunk/LayoutTests/http/tests/workers/service/page-caching-expected.txt (0 => 250378)
--- trunk/LayoutTests/http/tests/workers/service/page-caching-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/page-caching-expected.txt 2019-09-26 04:30:39 UTC (rev 250378)
@@ -0,0 +1,7 @@
+Tests that pages using service workers can enter the Page Cache.
+pageshow - not from page cache
+PASS: frame has a controller
+pagehide - entering page cache
+pageshow - from page cache
+PASS: page entered page cache
+
Copied: trunk/LayoutTests/http/tests/workers/service/page-caching.html (from rev 250377, trunk/LayoutTests/http/tests/workers/service/no-page-cache-when-controlled.html) (0 => 250378)
--- trunk/LayoutTests/http/tests/workers/service/page-caching.html (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/page-caching.html 2019-09-26 04:30:39 UTC (rev 250378)
@@ -0,0 +1,61 @@
+<!-- webkit-test-runner [ enablePageCache=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+log("Tests that pages using service workers can enter the Page Cache.");
+jsTestIsAsync = true;
+
+window.addEventListener("pageshow", function(event) {
+ log("pageshow - " + (event.persisted ? "" : "not ") + "from page cache");
+ if (!window.sessionStorage.sw_page_cache_with_controller_test_started)
+ return;
+
+ if (event.persisted)
+ log("PASS: page entered page cache");
+ else
+ log("FAIL: page did not enter page cache");
+
+ finishSWTest();
+});
+
+window.addEventListener("pagehide", function(event) {
+ log("pagehide - " + (event.persisted ? "" : "not ") + "entering page cache");
+ if (!event.persisted) {
+ log("FAIL: page failed to enter page cache");
+ finishSWTest();
+ }
+});
+
+async function test() {
+ let scopeURL = "/workers/service/resources/";
+ registration = await registerAndWaitForActive("resources/updating-fetch-worker.php", scopeURL);
+ worker = registration.active;
+ if (!worker) {
+ log("FAIL: No active service worker");
+ finishSWTest();
+ return;
+ }
+ let frame = await withFrame(scopeURL);
+ if (frame.contentWindow.navigator.serviceWorker.controller === null) {
+ log("FAIL: frame does not have a controller");
+ finishSWTest();
+ return;
+ }
+
+ log("PASS: frame has a controller");
+
+ setTimeout(function() {
+ window.sessionStorage.sw_page_cache_with_controller_test_started = true;
+ location.href = ""
+ }, 0);
+}
+
+window._onload_ = test;
+
+</script>
+</body>
+</html>
Modified: trunk/LayoutTests/platform/gtk/TestExpectations (250377 => 250378)
--- trunk/LayoutTests/platform/gtk/TestExpectations 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/LayoutTests/platform/gtk/TestExpectations 2019-09-26 04:30:39 UTC (rev 250378)
@@ -1043,7 +1043,6 @@
# Service-workers tests that fail, time out or crash.
webkit.org/b/175419 http/tests/workers/service/controller-change.html [ Skip ]
-webkit.org/b/175419 http/tests/workers/service/no-page-cache-when-controlled.html [ Skip ]
webkit.org/b/175419 http/wpt/service-workers/persistent-importScripts.html [ Failure ]
webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html [ Skip ]
webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https.html [ Skip ]
Modified: trunk/LayoutTests/platform/wpe/TestExpectations (250377 => 250378)
--- trunk/LayoutTests/platform/wpe/TestExpectations 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/LayoutTests/platform/wpe/TestExpectations 2019-09-26 04:30:39 UTC (rev 250378)
@@ -563,7 +563,6 @@
# Service-workers tests that fail, time out or crash.
webkit.org/b/175419 http/tests/workers/service/controller-change.html [ Skip ]
-webkit.org/b/175419 http/tests/workers/service/no-page-cache-when-controlled.html [ Skip ]
webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers/service-worker/activation.https.html [ Skip ]
webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers/service-worker/claim-with-redirect.https.html [ Skip ]
webkit.org/b/175419 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-within-sw.https.html [ Skip ]
Modified: trunk/Source/WebCore/ChangeLog (250377 => 250378)
--- trunk/Source/WebCore/ChangeLog 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/Source/WebCore/ChangeLog 2019-09-26 04:30:39 UTC (rev 250378)
@@ -1,5 +1,38 @@
2019-09-25 Chris Dumez <[email protected]>
+ Improve Service worker support for Page Caching
+ https://bugs.webkit.org/show_bug.cgi?id=202221
+
+ Reviewed by Geoffrey Garen.
+
+ Allow pages using service workers to enter the back / forward cache.
+ Update ServiceWorkerRegistration / ServiceWorker ActiveDOMObjects
+ to properly suspend while in PageCache. Also, let documents controlled
+ by a service worker to enter PageCache (we already unregistered it as
+ a client of the service worker while suspended).
+
+ Test: http/tests/workers/service/page-caching.html
+
+ * dom/Document.cpp:
+ (WebCore::Document::suspend):
+ (WebCore::Document::resume):
+ * history/PageCache.cpp:
+ (WebCore::canCacheFrame):
+ * workers/service/ServiceWorker.cpp:
+ (WebCore::ServiceWorker::updateState):
+ (WebCore::ServiceWorker::canSuspendForDocumentSuspension const):
+ (WebCore::ServiceWorker::suspend):
+ (WebCore::ServiceWorker::resume):
+ * workers/service/ServiceWorker.h:
+ * workers/service/ServiceWorkerRegistration.cpp:
+ (WebCore::ServiceWorkerRegistration::fireUpdateFoundEvent):
+ (WebCore::ServiceWorkerRegistration::canSuspendForDocumentSuspension const):
+ (WebCore::ServiceWorkerRegistration::suspend):
+ (WebCore::ServiceWorkerRegistration::resume):
+ * workers/service/ServiceWorkerRegistration.h:
+
+2019-09-25 Chris Dumez <[email protected]>
+
[Cocoa] Regression(r212041) Safari adds a .dms extension automatically when downloading binaries with no extension
https://bugs.webkit.org/show_bug.cgi?id=202147
<rdar://problem/54886021>
Modified: trunk/Source/WebCore/dom/Document.cpp (250377 => 250378)
--- trunk/Source/WebCore/dom/Document.cpp 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/Source/WebCore/dom/Document.cpp 2019-09-26 04:30:39 UTC (rev 250378)
@@ -5151,10 +5151,8 @@
#endif
#if ENABLE(SERVICE_WORKER)
- if (RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled() && reason == ReasonForSuspension::PageCache) {
- ASSERT_WITH_MESSAGE(!activeServiceWorker(), "Documents with an active service worker should not go into PageCache in the first place");
+ if (RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled() && reason == ReasonForSuspension::PageCache)
setServiceWorkerConnection(nullptr);
- }
#endif
suspendScheduledTasks(reason);
@@ -5198,10 +5196,8 @@
m_isSuspended = false;
#if ENABLE(SERVICE_WORKER)
- if (RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled() && reason == ReasonForSuspension::PageCache) {
- ASSERT_WITH_MESSAGE(!activeServiceWorker(), "Documents with an active service worker should not go into PageCache in the first place");
+ if (RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled() && reason == ReasonForSuspension::PageCache)
setServiceWorkerConnection(ServiceWorkerProvider::singleton().existingServiceWorkerConnection());
- }
#endif
}
Modified: trunk/Source/WebCore/history/PageCache.cpp (250377 => 250378)
--- trunk/Source/WebCore/history/PageCache.cpp 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/Source/WebCore/history/PageCache.cpp 2019-09-26 04:30:39 UTC (rev 250378)
@@ -173,13 +173,7 @@
logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::cannotSuspendActiveDOMObjectsKey());
isCacheable = false;
}
-#if ENABLE(SERVICE_WORKER)
- if (frame.document() && frame.document()->activeServiceWorker()) {
- PCLOG(" -The document has an active service worker");
- logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::serviceWorkerKey());
- isCacheable = false;
- }
-#endif
+
// FIXME: We should investigating caching frames that have an associated
// application cache. <rdar://problem/5917899> tracks that work.
if (!documentLoader->applicationCacheHost().canCacheInPageCache()) {
Modified: trunk/Source/WebCore/workers/service/ServiceWorker.cpp (250377 => 250378)
--- trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.cpp 2019-09-26 04:30:39 UTC (rev 250378)
@@ -80,6 +80,11 @@
void ServiceWorker::updateState(State state)
{
+ if (m_isSuspended) {
+ m_pendingStateChanges.append(state);
+ return;
+ }
+
WORKER_RELEASE_LOG_IF_ALLOWED("updateState: Updating service worker %llu state from %hhu to %hhu. Registration ID: %llu", identifier().toUInt64(), m_data.state, state, registrationIdentifier().toUInt64());
m_data.state = state;
if (state != State::Installing && !m_isStopped) {
@@ -141,10 +146,25 @@
bool ServiceWorker::canSuspendForDocumentSuspension() const
{
- // FIXME: We should do better as this prevents the page from entering PageCache when there is a Service Worker.
- return !hasPendingActivity();
+ return true;
}
+void ServiceWorker::suspend(ReasonForSuspension)
+{
+ m_isSuspended = true;
+}
+
+void ServiceWorker::resume()
+{
+ m_isSuspended = false;
+ if (!m_pendingStateChanges.isEmpty()) {
+ scriptExecutionContext()->postTask([this, protectedThis = makeRef(*this)](auto&) {
+ for (auto pendingStateChange : std::exchange(m_pendingStateChanges, { }))
+ updateState(pendingStateChange);
+ });
+ }
+}
+
void ServiceWorker::stop()
{
m_isStopped = true;
Modified: trunk/Source/WebCore/workers/service/ServiceWorker.h (250377 => 250378)
--- trunk/Source/WebCore/workers/service/ServiceWorker.h 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.h 2019-09-26 04:30:39 UTC (rev 250378)
@@ -77,6 +77,8 @@
// ActiveDOMObject.
const char* activeDOMObjectName() const final;
bool canSuspendForDocumentSuspension() const final;
+ void suspend(ReasonForSuspension) final;
+ void resume() final;
void stop() final;
bool isAlwaysOnLoggingAllowed() const;
@@ -83,7 +85,9 @@
ServiceWorkerData m_data;
bool m_isStopped { false };
+ bool m_isSuspended { false };
RefPtr<PendingActivity<ServiceWorker>> m_pendingActivityForEventDispatch;
+ Vector<State> m_pendingStateChanges;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (250377 => 250378)
--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp 2019-09-26 04:30:39 UTC (rev 250378)
@@ -211,6 +211,11 @@
if (m_isStopped)
return;
+ if (m_isSuspended) {
+ m_shouldFireUpdateFoundEventUponResuming = true;
+ return;
+ }
+
REGISTRATION_RELEASE_LOG_IF_ALLOWED("fireUpdateFoundEvent: Firing updatefound event for registration %llu", identifier().toUInt64());
ASSERT(m_pendingActivityForEventDispatch);
@@ -234,10 +239,25 @@
bool ServiceWorkerRegistration::canSuspendForDocumentSuspension() const
{
- // FIXME: We should do better as this prevents a page from entering PageCache when there is a service worker registration.
- return !hasPendingActivity();
+ return true;
}
+void ServiceWorkerRegistration::suspend(ReasonForSuspension)
+{
+ m_isSuspended = true;
+}
+
+void ServiceWorkerRegistration::resume()
+{
+ m_isSuspended = false;
+ if (m_shouldFireUpdateFoundEventUponResuming) {
+ m_shouldFireUpdateFoundEventUponResuming = false;
+ scriptExecutionContext()->postTask([this, protectedThis = makeRef(*this)](auto&) {
+ fireUpdateFoundEvent();
+ });
+ }
+}
+
void ServiceWorkerRegistration::stop()
{
m_isStopped = true;
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h (250377 => 250378)
--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h 2019-09-26 04:24:23 UTC (rev 250377)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.h 2019-09-26 04:30:39 UTC (rev 250378)
@@ -92,6 +92,8 @@
// ActiveDOMObject.
const char* activeDOMObjectName() const final;
bool canSuspendForDocumentSuspension() const final;
+ void suspend(ReasonForSuspension) final;
+ void resume() final;
void stop() final;
ServiceWorkerRegistrationData m_registrationData;
@@ -102,6 +104,8 @@
RefPtr<ServiceWorker> m_activeWorker;
bool m_isStopped { false };
+ bool m_isSuspended { false };
+ bool m_shouldFireUpdateFoundEventUponResuming { false };
RefPtr<PendingActivity<ServiceWorkerRegistration>> m_pendingActivityForEventDispatch;
Timer m_softUpdateTimer;
};