Implement https://fetch.spec.whatwg.org/#main-fetch default referrer policy setting
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Jan 2018 08:24:54 +0000 (08:24 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Jan 2018 08:24:54 +0000 (08:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181239

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

LayoutTests/imported/w3c:

Updated test to output more tests for better error reporting.
Also updated to relax the settings so that HTTP loads are done even though the page is HTTPS.
Updated referrer computation since it should be done based on the fetch context and not its parent context.

* web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https.html:

Source/WebCore:

Covered by updated and rebased test.

Setting the request referrer policy to the Document referrer policy if no one is set.
If Document has no referrer policy, use no-referrer-when-downgrade as per the spec.

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::updateHTTPRequestHeaders):
(WebCore::CachedResourceLoader::requestResource):
* loader/cache/CachedResourceLoader.h:
* loader/cache/CachedResourceRequest.cpp:
(WebCore::CachedResourceRequest::updateReferrerPolicy):
(WebCore::CachedResourceRequest::updateReferrerOriginAndUserAgentHeaders):
* loader/cache/CachedResourceRequest.h:

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https.html
Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/loader/cache/CachedResourceRequest.cpp
Source/WebCore/loader/cache/CachedResourceRequest.h

index 276aa56..5469960 100644 (file)
@@ -1,3 +1,17 @@
+2018-01-04  Youenn Fablet  <youenn@apple.com>
+
+        Implement  https://fetch.spec.whatwg.org/#main-fetch default referrer policy setting
+        https://bugs.webkit.org/show_bug.cgi?id=181239
+
+        Reviewed by Alex Christensen.
+
+        Updated test to output more tests for better error reporting.
+        Also updated to relax the settings so that HTTP loads are done even though the page is HTTPS.
+        Updated referrer computation since it should be done based on the fetch context and not its parent context.
+
+        * web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-event-referrer-policy.https.html:
+
 2018-01-02  Youenn Fablet  <youenn@apple.com>
 
         Memory cache should not reuse resources with different credential fetch option
index 7554564..c33b7d9 100644 (file)
@@ -1,4 +1,76 @@
+CONSOLE MESSAGE: line 32: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
 
+CONSOLE MESSAGE: line 54: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
 
-FAIL Service Worker responds to fetch event with the referrer policy assert_unreached: unexpected rejection: assert_equals: Service Worker should respond to fetch with the default referrer policy expected "ReferrerPolicy: no-referrer-when-downgrade" but got "ReferrerPolicy: " Reached unreachable code
+CONSOLE MESSAGE: line 76: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 98: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 120: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 132: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 197: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 231: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 32: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 54: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 76: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 98: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 120: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 132: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 197: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+CONSOLE MESSAGE: line 231: The page at https://localhost:9443/service-workers/service-worker/fetch-event-referrer-policy.https.html was allowed to display insecure content from http://localhost:8800/service-workers/service-worker//resources/simple.html?referrerFull.
+
+
+PASS Service Worker responds to fetch event with the referrer policy 
+PASS Service Worker should respond to fetch with the default referrer policy 
+PASS Service Worker should respond to fetch with the referrer URL when a member of RequestInit is present - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer when a member of RequestInit is present with an HTTP request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer with "" - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer with "" - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "origin" and a same origin request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "origin" and a cross origin request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer URL with "origin-when-cross-origin" and a same origin request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "origin-when-cross-origin" and a cross origin request - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and a same origin request - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and an HTTP request - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer with "unsafe-url" - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer URL with "no-referrer" - Default Referrer 
+PASS Service Worker should respond to fetch with referrer URL with "same-origin" and a same origin request - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer with "same-origin" and cross origin request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer origin  with "strict-origin" and a HTTPS cross origin request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "strict-origin" and a same origin request - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer with "strict-origin" and a HTTP request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer URL with "strict-origin-when-cross-origin" and a same origin request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "strict-origin-when-cross-origin" and a HTTPS cross origin request - Default Referrer 
+PASS Service Worker should respond to fetch with no referrer with "strict-origin-when-cross-origin" and a HTTP request - Default Referrer 
+PASS Service Worker should respond to fetch with the referrer URL when a member of RequestInit is present - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer when a member of RequestInit is present with an HTTP request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer with "" - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer with "" - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "origin" and a same origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "origin" and a cross origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer URL with "origin-when-cross-origin" and a same origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "origin-when-cross-origin" and a cross origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and a same origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer with "no-referrer-when-downgrade" and an HTTP request - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer with "unsafe-url" - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer URL with "no-referrer" - Custom Referrer 
+PASS Service Worker should respond to fetch with referrer URL with "same-origin" and a same origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer with "same-origin" and cross origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer origin  with "strict-origin" and a HTTPS cross origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "strict-origin" and a same origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer with "strict-origin" and a HTTP request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer URL with "strict-origin-when-cross-origin" and a same origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with the referrer origin with "strict-origin-when-cross-origin" and a HTTPS cross origin request - Custom Referrer 
+PASS Service Worker should respond to fetch with no referrer with "strict-origin-when-cross-origin" and a HTTP request - Custom Referrer 
 
index 9b67fac..15d4ed5 100644 (file)
@@ -7,12 +7,22 @@
 <script>
 var worker = 'resources/fetch-event-test-worker.js';
 
+if (window.internals && window.internals.settings)
+    internals.settings.setAllowDisplayOfInsecureContent(true);
+
+function do_test(referrer, value, expected, name)
+{
+    test(() => {
+          assert_equals(value, expected);
+    }, name + (referrer ? " - Custom Referrer" : " - Default Referrer"));
+}
+
 function run_referrer_policy_tests(frame, referrer, href, origin) {
     return frame.contentWindow.fetch('resources/simple.html?referrerFull',
                                      {method: "GET", referrer: referrer})
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + href + '\n' +
             'ReferrerPolicy: no-referrer-when-downgrade',
@@ -24,7 +34,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: \n' +
             'ReferrerPolicy: no-referrer-when-downgrade',
@@ -34,7 +44,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + href + '\n' +
             'ReferrerPolicy: no-referrer-when-downgrade',
@@ -46,7 +56,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: \n' +
             'ReferrerPolicy: no-referrer-when-downgrade',
@@ -56,7 +66,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + origin + '/' + '\n' +
             'ReferrerPolicy: origin',
@@ -68,7 +78,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + origin + '/' + '\n' +
             'ReferrerPolicy: origin',
@@ -78,7 +88,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + href + '\n' +
             'ReferrerPolicy: origin-when-cross-origin',
@@ -90,7 +100,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + origin + '/' + '\n' +
             'ReferrerPolicy: origin-when-cross-origin',
@@ -100,7 +110,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + href + '\n' +
             'ReferrerPolicy: no-referrer-when-downgrade',
@@ -112,7 +122,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: \n' +
             'ReferrerPolicy: no-referrer-when-downgrade',
@@ -123,7 +133,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + href + '\n' +
             'ReferrerPolicy: unsafe-url',
@@ -133,7 +143,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: \n' +
             'ReferrerPolicy: no-referrer',
@@ -143,7 +153,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + href + '\n' +
             'ReferrerPolicy: same-origin',
@@ -155,7 +165,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: \n' +
             'ReferrerPolicy: same-origin',
@@ -167,7 +177,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + origin + '/' + '\n' +
             'ReferrerPolicy: strict-origin',
@@ -177,7 +187,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + origin + '/' + '\n' +
             'ReferrerPolicy: strict-origin',
@@ -189,7 +199,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: \n' +
             'ReferrerPolicy: strict-origin',
@@ -199,7 +209,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + href + '\n' +
             'ReferrerPolicy: strict-origin-when-cross-origin',
@@ -211,7 +221,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: ' + origin + '/' + '\n' +
             'ReferrerPolicy: strict-origin-when-cross-origin',
@@ -223,7 +233,7 @@ function run_referrer_policy_tests(frame, referrer, href, origin) {
         })
       .then(function(response) { return response.text(); })
       .then(function(response_text) {
-          assert_equals(
+          do_test(referrer,
             response_text,
             'Referrer: \n' +
             'ReferrerPolicy: strict-origin-when-cross-origin',
@@ -241,17 +251,16 @@ async_test(function(t) {
       .then(function() { return with_iframe(scope); })
       .then(function(f) {
           frame = f;
-          assert_equals(
-            frame.contentDocument.body.textContent,
-            'ReferrerPolicy: no-referrer-when-downgrade',
-            'Service Worker should respond to fetch with the default referrer policy');
+          test(() => {
+            assert_equals(frame.contentDocument.body.textContent, 'ReferrerPolicy: no-referrer-when-downgrade');
+          }, 'Service Worker should respond to fetch with the default referrer policy');
           // First, run the referrer policy tests without passing a referrer in RequestInit.
           return run_referrer_policy_tests(frame, undefined, frame.contentDocument.location.href,
                                            frame.contentDocument.location.origin);
         })
       .then(function() {
           // Now, run the referrer policy tests while passing a referrer in RequestInit.
-          var referrer = get_host_info()['HTTPS_ORIGIN'] + base_path() + 'fake-referrer';
+          var referrer = get_host_info()['HTTPS_ORIGIN'] + base_path() + 'resources/fake-referrer';
           return run_referrer_policy_tests(frame, 'fake-referrer', referrer,
                                            frame.contentDocument.location.origin);
         })
index d34b9bd..da2a41c 100644 (file)
@@ -1,3 +1,24 @@
+2018-01-04  Youenn Fablet  <youenn@apple.com>
+
+        Implement  https://fetch.spec.whatwg.org/#main-fetch default referrer policy setting
+        https://bugs.webkit.org/show_bug.cgi?id=181239
+
+        Reviewed by Alex Christensen.
+
+        Covered by updated and rebased test.
+
+        Setting the request referrer policy to the Document referrer policy if no one is set.
+        If Document has no referrer policy, use no-referrer-when-downgrade as per the spec.
+
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::updateHTTPRequestHeaders):
+        (WebCore::CachedResourceLoader::requestResource):
+        * loader/cache/CachedResourceLoader.h:
+        * loader/cache/CachedResourceRequest.cpp:
+        (WebCore::CachedResourceRequest::updateReferrerPolicy):
+        (WebCore::CachedResourceRequest::updateReferrerOriginAndUserAgentHeaders):
+        * loader/cache/CachedResourceRequest.h:
+
 2018-01-03  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Attachment Support] Create attachment elements when dropping files on iOS
index 5464389..ac086da 100644 (file)
@@ -742,7 +742,7 @@ void CachedResourceLoader::updateHTTPRequestHeaders(CachedResource::Type type, C
         // In some cases we may try to load resources in frameless documents. Such loads always fail.
         // FIXME: We shouldn't need to do the check on frame.
         if (auto* frame = this->frame())
-            request.updateReferrerOriginAndUserAgentHeaders(frame->loader(), document() ? document()->referrerPolicy() : ReferrerPolicy::NoReferrerWhenDowngrade);
+            request.updateReferrerOriginAndUserAgentHeaders(frame->loader());
     }
 
     request.updateAccordingCacheMode();
@@ -750,6 +750,7 @@ void CachedResourceLoader::updateHTTPRequestHeaders(CachedResource::Type type, C
 
 ResourceErrorOr<CachedResourceHandle<CachedResource>> CachedResourceLoader::requestResource(CachedResource::Type type, CachedResourceRequest&& request, ForPreload forPreload, DeferOption defer)
 {
+    // Entry point to https://fetch.spec.whatwg.org/#main-fetch.
     std::unique_ptr<ResourceRequest> originalRequest;
     if (CachedResource::shouldUsePingLoad(type))
         originalRequest = std::make_unique<ResourceRequest>(request.resourceRequest());
@@ -757,6 +758,7 @@ ResourceErrorOr<CachedResourceHandle<CachedResource>> CachedResourceLoader::requ
     if (Document* document = this->document())
         request.upgradeInsecureRequestIfNeeded(*document);
 
+    request.updateReferrerPolicy(document() ? document()->referrerPolicy() : ReferrerPolicy::NoReferrerWhenDowngrade);
     URL url = request.resourceRequest().url();
 
     LOG(ResourceLoading, "CachedResourceLoader::requestResource '%s', charset '%s', priority=%d, forPreload=%u", url.stringCenterEllipsizedToLength().latin1().data(), request.charset().latin1().data(), request.priority() ? static_cast<int>(request.priority().value()) : -1, forPreload == ForPreload::Yes);
index 8b513c6..691af1e 100644 (file)
@@ -171,7 +171,6 @@ private:
 
     void prepareFetch(CachedResource::Type, CachedResourceRequest&);
     void updateHTTPRequestHeaders(CachedResource::Type, CachedResourceRequest&);
-    void updateReferrerOriginAndUserAgentHeaders(CachedResourceRequest&);
 
     bool canRequest(CachedResource::Type, const URL&, const CachedResourceRequest&, ForPreload);
 
index 775590b..95e668c 100644 (file)
@@ -223,7 +223,13 @@ void CachedResourceRequest::applyBlockedStatus(const ContentExtensions::BlockedS
 
 #endif
 
-void CachedResourceRequest::updateReferrerOriginAndUserAgentHeaders(FrameLoader& frameLoader, ReferrerPolicy defaultPolicy)
+void CachedResourceRequest::updateReferrerPolicy(ReferrerPolicy defaultPolicy)
+{
+    if (m_options.referrerPolicy == ReferrerPolicy::EmptyString)
+        m_options.referrerPolicy = defaultPolicy;
+}
+
+void CachedResourceRequest::updateReferrerOriginAndUserAgentHeaders(FrameLoader& frameLoader)
 {
     // Implementing step 7 to 9 of https://fetch.spec.whatwg.org/#http-network-or-cache-fetch
 
@@ -236,15 +242,7 @@ void CachedResourceRequest::updateReferrerOriginAndUserAgentHeaders(FrameLoader&
         outgoingOrigin = frameLoader.outgoingOrigin();
     }
 
-    switch (m_options.referrerPolicy) {
-    case ReferrerPolicy::EmptyString:
-        outgoingReferrer = SecurityPolicy::generateReferrerHeader(defaultPolicy, m_resourceRequest.url(), outgoingReferrer);
-        break;
-    default:
-        outgoingReferrer = SecurityPolicy::generateReferrerHeader(m_options.referrerPolicy, m_resourceRequest.url(), outgoingReferrer);
-        break;
-    };
-
+    outgoingReferrer = SecurityPolicy::generateReferrerHeader(m_options.referrerPolicy, m_resourceRequest.url(), outgoingReferrer);
     if (outgoingReferrer.isEmpty())
         m_resourceRequest.clearHTTPReferrer();
     else
index a916947..122a28a 100644 (file)
@@ -75,7 +75,8 @@ public:
     void setAsPotentiallyCrossOrigin(const String&, Document&);
     void updateForAccessControl(Document&);
 
-    void updateReferrerOriginAndUserAgentHeaders(FrameLoader&, ReferrerPolicy);
+    void updateReferrerPolicy(ReferrerPolicy);
+    void updateReferrerOriginAndUserAgentHeaders(FrameLoader&);
     void upgradeInsecureRequestIfNeeded(Document&);
     void setAcceptHeaderIfNone(CachedResource::Type);
     void updateAccordingCacheMode();