Skip to content

Commit

Permalink
Ensure that <object>/<embed> navigation bypasses Service Workers.
Browse files Browse the repository at this point in the history
Step 13 of https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm
should exclude `embed` and `object` requests from Service Workers. Our
implementation handles this correctly for the initial request, but failed
to bypass the Service Worker for subsequent navigations. This patch adds
a destination check to
`ServiceWorkerMainResourceLoaderInterceptor::ShouldCreateForNavigation`,
and ensures that the `destination` for a given request is set early enough
in the lifecycle to ensure that the check succeeds.

See also whatwg/fetch#948.

Change-Id: I21a1d37da438e1d0f185696f2b3b4058bc3911fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209456
Reviewed-by: Matt Falkenhagen <[email protected]>
Reviewed-by: Tsuyoshi Horo <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Ben Kelly <[email protected]>
Commit-Queue: Mike West <[email protected]>
Cr-Commit-Position: refs/heads/master@{#773781}
  • Loading branch information
mikewest authored and chromium-wpt-export-bot committed Jun 1, 2020
1 parent a0740be commit f58221d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,30 @@
});
}, 'requests for OBJECT elements of an image should not be intercepted by service workers');

promise_test(t => {
let frame;
return with_iframe('resources/object-navigation-is-not-intercepted-iframe.html')
.then(f => {
frame = f;
t.add_cleanup(() => { frame.remove(); });
return frame.contentWindow.test_promise;
})
.then(result => {
assert_equals(result, 'request for embedded content was not intercepted');
});
}, 'post-load navigation of OBJECT elements should not be intercepted by service workers');


promise_test(t => {
let frame;
return with_iframe('resources/embed-navigation-is-not-intercepted-iframe.html')
.then(f => {
frame = f;
t.add_cleanup(() => { frame.remove(); });
return frame.contentWindow.test_promise;
})
.then(result => {
assert_equals(result, 'request for embedded content was not intercepted');
});
}, 'post-load navigation of EMBED elements should not be intercepted by service workers');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>iframe for embed-and-object-are-not-intercepted test</title>
<body>
<script>
// The EMBED element will call this with the result about whether the EMBED
// request was intercepted by the service worker.
var report_result;

// Our parent (the root frame of the test) will examine this to get the result.
var test_promise = new Promise(resolve => {
report_result = resolve;
});

let el = document.createElement('embed');
el.src = "/common/blank.html";
el.addEventListener('load', _ => {
window[0].location = "/service-workers/service-worker/resources/embedded-content-from-server.html";
}, { once: true });
document.body.appendChild(el);
</script>

</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>iframe for embed-and-object-are-not-intercepted test</title>
<body>
<script>
// The OBJECT element will call this with the result about whether the OBJECT
// request was intercepted by the service worker.
var report_result;

// Our parent (the root frame of the test) will examine this to get the result.
var test_promise = new Promise(resolve => {
report_result = resolve;
});

let el = document.createElement('object');
el.data = "/common/blank.html";
el.addEventListener('load', _ => {
window[0].location = "/service-workers/service-worker/resources/embedded-content-from-server.html";
}, { once: true });
document.body.appendChild(el);
</script>

</body>

0 comments on commit f58221d

Please sign in to comment.