DocumentLoader should interrupt ongoing load when getting a redirection from network...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jan 2018 21:26:36 +0000 (21:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jan 2018 21:26:36 +0000 (21:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182115

Patch by Youenn Fablet <youenn@apple.com> on 2018-01-25
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt:

Source/WebCore:

Covered by rebased test.

In case a navigation load is going to the network process,
we need to interrupt it if having a redirection that leads to a new request going to a service worker.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::redirectReceived):

Source/WebKit:

* WebProcess/Storage/ServiceWorkerClientFetch.cpp:
(WebKit::ServiceWorkerClientFetch::didReceiveResponse):

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Storage/ServiceWorkerClientFetch.cpp

index 0b2f9d6..4577929 100644 (file)
@@ -1,3 +1,12 @@
+2018-01-25  Youenn Fablet  <youenn@apple.com>
+
+        DocumentLoader should interrupt ongoing load when getting a redirection from network that matches a service worker
+        https://bugs.webkit.org/show_bug.cgi?id=182115
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/service-workers/service-worker/navigation-redirect.https-expected.txt:
+
 2018-01-25  Chris Dumez  <cdumez@apple.com>
 
         Registering same scope as the script directory without the last slash should fail
index 844a0d3..49c6c9d 100644 (file)
@@ -5,7 +5,7 @@ Harness Error (TIMEOUT), message = null
 PASS Normal redirect to same-origin scope. 
 PASS Normal redirect to other-origin scope. 
 PASS SW-fallbacked redirect to same-origin out-scope. 
-FAIL SW-fallbacked redirect to same-origin same-scope. assert_object_equals: Intercepted URLs should match. expected property "1" missing
+PASS SW-fallbacked redirect to same-origin same-scope. 
 PASS SW-fallbacked redirect to same-origin other-scope. 
 PASS SW-fallbacked redirect to other-origin out-scope. 
 PASS SW-fallbacked redirect to other-origin in-scope. 
index b38cc1c..3d58d41 100644 (file)
@@ -1,3 +1,18 @@
+2018-01-25  Youenn Fablet  <youenn@apple.com>
+
+        DocumentLoader should interrupt ongoing load when getting a redirection from network that matches a service worker
+        https://bugs.webkit.org/show_bug.cgi?id=182115
+
+        Reviewed by Alex Christensen.
+
+        Covered by rebased test.
+
+        In case a navigation load is going to the network process,
+        we need to interrupt it if having a redirection that leads to a new request going to a service worker.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::redirectReceived):
+
 2018-01-25  Chris Dumez  <cdumez@apple.com>
 
         Registering same scope as the script directory without the last slash should fail
index d219b5e..7c1cc08 100644 (file)
@@ -517,19 +517,22 @@ void DocumentLoader::redirectReceived(CachedResource& resource, ResourceRequest&
 {
     ASSERT_UNUSED(resource, &resource == m_mainResource);
 #if ENABLE(SERVICE_WORKER)
-    willSendRequest(WTFMove(request), redirectResponse, [completionHandler = WTFMove(completionHandler), protectedThis = makeRef(*this), this] (auto&& request) mutable {
+    bool isRedirectionFromServiceWorker = redirectResponse.source() == ResourceResponse::Source::ServiceWorker;
+    willSendRequest(WTFMove(request), redirectResponse, [isRedirectionFromServiceWorker, completionHandler = WTFMove(completionHandler), protectedThis = makeRef(*this), this] (auto&& request) mutable {
         if (request.isNull() || !m_mainDocumentError.isNull() || !m_frame) {
             completionHandler({ });
             return;
         }
         auto url = request.url();
-        matchRegistration(url, [request = WTFMove(request), completionHandler = WTFMove(completionHandler), protectedThis = WTFMove(protectedThis), this] (auto&& registrationData) mutable {
+        matchRegistration(url, [request = WTFMove(request), isRedirectionFromServiceWorker, completionHandler = WTFMove(completionHandler), protectedThis = WTFMove(protectedThis), this] (auto&& registrationData) mutable {
             if (!m_mainDocumentError.isNull() || !m_frame) {
                 completionHandler({ });
                 return;
             }
+            bool shouldContinueLoad = areRegistrationsEqual(m_serviceWorkerRegistrationData, registrationData)
+                && isRedirectionFromServiceWorker == !!registrationData;
 
-            if (areRegistrationsEqual(m_serviceWorkerRegistrationData, registrationData)) {
+            if (shouldContinueLoad) {
                 completionHandler(WTFMove(request));
                 return;
             }
index aab3f8d..5055032 100644 (file)
@@ -1,3 +1,13 @@
+2018-01-25  Youenn Fablet  <youenn@apple.com>
+
+        DocumentLoader should interrupt ongoing load when getting a redirection from network that matches a service worker
+        https://bugs.webkit.org/show_bug.cgi?id=182115
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/Storage/ServiceWorkerClientFetch.cpp:
+        (WebKit::ServiceWorkerClientFetch::didReceiveResponse):
+
 2018-01-25  Alex Christensen  <achristensen@webkit.org>
 
         Fix crash when preconnecting while closing private browsing
index 51c879a..ee05b8f 100644 (file)
@@ -108,6 +108,7 @@ void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response)
             callback(Result::Succeeded);
         return;
     }
+    response.setSource(ResourceResponse::Source::ServiceWorker);
 
     if (response.isRedirection()) {
         m_redirectionStatus = RedirectionStatus::Receiving;
@@ -134,7 +135,6 @@ void ServiceWorkerClientFetch::didReceiveResponse(ResourceResponse&& response)
             response.setTextEncodingName(ASCIILiteral("UTF-8"));
         }
     }
-    response.setSource(ResourceResponse::Source::ServiceWorker);
 
     // As per https://fetch.spec.whatwg.org/#main-fetch step 9, copy request's url list in response's url list if empty.
     if (response.url().isNull())