[Fetch API] Add support to ReferrerPolicy
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Aug 2016 07:20:23 +0000 (07:20 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Aug 2016 07:20:23 +0000 (07:20 +0000)
commit4cd46262288db313ae0a4d885693491692284c4f
tree292bbde2264975cc9b4f06a40c8cadafb77ae557
parentce4c5c7d79ca55bf75a7fff1d85b5a9dd50d25c1
[Fetch API] Add support to ReferrerPolicy
https://bugs.webkit.org/show_bug.cgi?id=160404

Patch by Youenn Fablet <youenn@apple.com> on 2016-08-02
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/basic/referrer-expected.txt: Added.
* web-platform-tests/fetch/api/basic/referrer-worker-expected.txt: Added.
* web-platform-tests/fetch/api/basic/referrer-worker.html: Added.
* web-platform-tests/fetch/api/basic/referrer.html: Added.
* web-platform-tests/fetch/api/basic/referrer.js: Added.
(runTest):
* web-platform-tests/fetch/api/cors/cors-preflight-referrer-expected.txt:
* web-platform-tests/fetch/api/cors/cors-preflight-referrer-worker-expected.txt:
* web-platform-tests/fetch/api/cors/cors-preflight-referrer.js:
(corsPreflightReferrer): fix infrastructure bug in test and fix expected referrer policy in default case.
* web-platform-tests/fetch/api/cors/cors-preflight-worker-expected.txt:

Source/WebCore:

Tests: imported/w3c/web-platform-tests/fetch/api/basic/referrer-worker.html
       imported/w3c/web-platform-tests/fetch/api/basic/referrer.html

Refactored ThreadableLoader API to take more references.

Updated loading code in CachedResource to take into account referrer policy, that can be set by fetch API.
To enable correct handling of OriginWhenCrossOrigin policy, the computation of the cross-origin status of a request is
moved from ResourceLoader to CachedResource.

Referrer is passed to the loading code through HTTP headers.
This was triggering preflighting for Workers request as WorkerThreadableLoader was setting the referrer.
It is now done in DocumentThreadableLoader::loadRequest so that preflighting is done before setting the referrer.
Note that this referrer setting is only a way to pass a specific referrer value to the loading code.
CachedResource code will compute the actual referer value based on the referrer policy.
It might be good in the future to have a different way of conveying this information to CachedResource, maybe
through CachedResourceRequest.

* Modules/fetch/FetchLoader.cpp:
(WebCore::FetchLoader::start): Refactoring of ThreadableLoader API.
* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::internalRequest): Setting referrer if it has a specific value.
* fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::start): Ractoring of ThreadableLoader API.
* loader/CrossOriginPreflightChecker.cpp:
(WebCore::CrossOriginPreflightChecker::startPreflight): Set referrer in the preflight request if any.
(WebCore::CrossOriginPreflightChecker::doPreflight): Ditto.
* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::loadResourceSynchronously): Refactoring of ThreadableLoader API.
(WebCore::DocumentThreadableLoader::create): Ditto.
(WebCore::DocumentThreadableLoader::DocumentThreadableLoader): Ditto.
(WebCore::DocumentThreadableLoader::loadRequest): Ditto.
* loader/DocumentThreadableLoader.h:
(WebCore::DocumentThreadableLoader::referrer): Storing referrer in case one is defined.
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::init): Removing of cross origin computation since it is done earlier in CachedResource.
* loader/ThreadableLoader.cpp:
(WebCore::ThreadableLoader::create): Refactoring of ThreadableLoader API.
(WebCore::ThreadableLoader::loadResourceSynchronously): Ditto.
* loader/ThreadableLoader.h:
* loader/ThreadableLoaderClientWrapper.h:
(WebCore::ThreadableLoaderClientWrapper::create): Ditto.
(WebCore::ThreadableLoaderClientWrapper::ThreadableLoaderClientWrapper): Ditto.
* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::WorkerThreadableLoader): Ditto.
(WebCore::WorkerThreadableLoader::loadResourceSynchronously): Removing setting of referrer in header and passing
it as a parameter.
(WebCore::WorkerThreadableLoader::MainThreadBridge::MainThreadBridge): Ditto.
* loader/WorkerThreadableLoader.h:
(WebCore::WorkerThreadableLoader::create): Refactoring of ThreadableLoader API.
* loader/cache/CachedResource.cpp:
(WebCore::addAdditionalRequestHeadersToRequest): Computation of referrer based on referrer policy.
(WebCore::CachedResource::addAdditionalRequestHeaders): Ditto.
(WebCore::CachedResource::load): Computation of cross origin status.
(WebCore::CachedResource::varyHeaderValuesMatch):
* loader/cache/CachedResource.h:
(WebCore::CachedResource::options):
* page/EventSource.cpp:
(WebCore::EventSource::connect): Refactoring of ThreadableLoader API.
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadSynchronously): Ditto.
(WebCore::WorkerScriptLoader::loadAsynchronously): Ditto.
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::createRequest): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204019 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/referrer-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/referrer-worker-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/referrer-worker.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/referrer.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/referrer.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-referrer-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-referrer-worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-referrer.js
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-worker-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchLoader.cpp
Source/WebCore/Modules/fetch/FetchRequest.cpp
Source/WebCore/fileapi/FileReaderLoader.cpp
Source/WebCore/loader/CrossOriginPreflightChecker.cpp
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/DocumentThreadableLoader.h
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/ThreadableLoader.cpp
Source/WebCore/loader/ThreadableLoader.h
Source/WebCore/loader/ThreadableLoaderClientWrapper.h
Source/WebCore/loader/WorkerThreadableLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/page/EventSource.cpp
Source/WebCore/workers/WorkerScriptLoader.cpp
Source/WebCore/xml/XMLHttpRequest.cpp