From f58221de139ae6155124bd17db7ce92b411542de Mon Sep 17 00:00:00 2001 From: Mike West Date: Mon, 1 Jun 2020 12:59:52 -0700 Subject: [PATCH] Ensure that / navigation bypasses Service Workers. 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 https://github.com/whatwg/fetch/pull/948. Change-Id: I21a1d37da438e1d0f185696f2b3b4058bc3911fc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209456 Reviewed-by: Matt Falkenhagen Reviewed-by: Tsuyoshi Horo Reviewed-by: Kinuko Yasuda Reviewed-by: Ben Kelly Commit-Queue: Mike West Cr-Commit-Position: refs/heads/master@{#773781} --- ...-and-object-are-not-intercepted.https.html | 26 +++++++++++++++++++ ...-navigation-is-not-intercepted-iframe.html | 23 ++++++++++++++++ ...-navigation-is-not-intercepted-iframe.html | 24 +++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 service-workers/service-worker/resources/embed-navigation-is-not-intercepted-iframe.html create mode 100644 service-workers/service-worker/resources/object-navigation-is-not-intercepted-iframe.html diff --git a/service-workers/service-worker/embed-and-object-are-not-intercepted.https.html b/service-workers/service-worker/embed-and-object-are-not-intercepted.https.html index 34556a785aea68..581dbeca977226 100644 --- a/service-workers/service-worker/embed-and-object-are-not-intercepted.https.html +++ b/service-workers/service-worker/embed-and-object-are-not-intercepted.https.html @@ -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'); diff --git a/service-workers/service-worker/resources/embed-navigation-is-not-intercepted-iframe.html b/service-workers/service-worker/resources/embed-navigation-is-not-intercepted-iframe.html new file mode 100644 index 00000000000000..5e86f67735f778 --- /dev/null +++ b/service-workers/service-worker/resources/embed-navigation-is-not-intercepted-iframe.html @@ -0,0 +1,23 @@ + + +iframe for embed-and-object-are-not-intercepted test + + + + diff --git a/service-workers/service-worker/resources/object-navigation-is-not-intercepted-iframe.html b/service-workers/service-worker/resources/object-navigation-is-not-intercepted-iframe.html new file mode 100644 index 00000000000000..5c8ab79a500a93 --- /dev/null +++ b/service-workers/service-worker/resources/object-navigation-is-not-intercepted-iframe.html @@ -0,0 +1,24 @@ + + +iframe for embed-and-object-are-not-intercepted test + + + + +