-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick 757903c. rdar://problem/98144044
FetchEvent should not start its navigation preload response load if the preload was already used https://bugs.webkit.org/show_bug.cgi?id=245788 rdar://98144044 Reviewed by Alex Christensen. Creating the navigation preload promise was scheduling a load which is hitting the network if the preload is no longer in network process. This case happens if the navigation preload promise is actually used in respondWith. To circumvent this issue, we do not trigger the load if the preload is used in respondWith. Add logs to capture the fact that a load is not getting its expected preload. Drive-by fixes to actually use the current preload request and not the loader original request. This might change in case of redirections. Covered by newly added test which mirrors what we were testing for non-exposed navigation preloads. * LayoutTests/http/wpt/service-workers/fetch-service-worker-navigation-preload.https-expected.txt: Added. * LayoutTests/http/wpt/service-workers/fetch-service-worker-navigation-preload.https.html: Added. * LayoutTests/http/wpt/service-workers/fetch-service-worker-preload-worker.js: (event.event.request.url.includes): * LayoutTests/http/wpt/service-workers/resources/fetch-service-worker-preload-script.py: (main): * Source/WebCore/Modules/fetch/FetchResponse.cpp: (WebCore::FetchResponse::markAsUsedForPreload): (WebCore::FetchResponse::markAsDisturbed): Deleted. * Source/WebCore/Modules/fetch/FetchResponse.h: * Source/WebCore/workers/service/FetchEvent.cpp: (WebCore::FetchEvent::navigationPreloadIsReady): * Source/WebCore/workers/service/context/ServiceWorkerFetch.cpp: (WebCore::ServiceWorkerFetch::processResponse): * Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp: (WebKit::ServiceWorkerFetchTask::fromNavigationPreloader): (WebKit::ServiceWorkerFetchTask::ServiceWorkerFetchTask): (WebKit::ServiceWorkerFetchTask::loadBodyFromPreloader): Canonical link: https://commits.webkit.org/254992@main Canonical link: https://commits.webkit.org/252432.476@safari-7614.2.9.1-branch
- Loading branch information
Showing
9 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...Tests/http/wpt/service-workers/fetch-service-worker-navigation-preload.https-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
PASS Setup activating worker | ||
PASS Service worker preloadResponse does not trigger an additional load | ||
|
68 changes: 68 additions & 0 deletions
68
LayoutTests/http/wpt/service-workers/fetch-service-worker-navigation-preload.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="resources/routines.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
var activeWorker; | ||
var frame; | ||
const channel = new MessageChannel(); | ||
const uuid = token(); | ||
const url = "/WebKit/service-workers/resources/fetch-service-worker-preload-script.py?useNavigationPreloadPromise=true&token=" + uuid; | ||
|
||
function waitUntilActivating() | ||
{ | ||
return new Promise(resolve => { | ||
channel.port2.onmessage = (event) => { | ||
if (event.data === "activating") | ||
resolve(); | ||
}; | ||
}); | ||
} | ||
|
||
function triggerActivation() | ||
{ | ||
activeWorker.postMessage("activate"); | ||
} | ||
|
||
promise_test(async (test) => { | ||
if (window.testRunner) { | ||
testRunner.setUseSeparateServiceWorkerProcess(true); | ||
await fetch("").then(() => { }, () => { }); | ||
} | ||
|
||
let registration = await navigator.serviceWorker.register("/WebKit/service-workers/fetch-service-worker-preload-worker.js", { scope : url }); | ||
if (!registration.installing) { | ||
registration.unregister(); | ||
registration = await navigator.serviceWorker.register("/WebKit/service-workers/fetch-service-worker-preload-worker.js", { scope : url }); | ||
} | ||
|
||
activeWorker = registration.installing; | ||
activeWorker.postMessage({ port: channel.port1 }, [channel.port1]); | ||
|
||
await waitUntilActivating(); | ||
|
||
if (registration.navigationPreload) | ||
await registration.navigationPreload.enable(); | ||
|
||
triggerActivation(); | ||
}, "Setup activating worker"); | ||
|
||
promise_test(async (test) => { | ||
await fetch(url + "&value=use-preload2", { method: 'POST' }); | ||
|
||
|
||
const frame = await withIframe(url); | ||
assert_equals(frame.contentWindow.value, "use-preload2"); | ||
|
||
// We should have only one GET fetch to url: the service worker preload | ||
const response = await fetch(url + "&count=True"); | ||
assert_equals(await response.text(), "1"); | ||
}, "Service worker preloadResponse does not trigger an additional load"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters