[Beacon] Add support for CORS-preflighting for WK2 / NETWORK_SESSION
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Aug 2017 05:15:47 +0000 (05:15 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Aug 2017 05:15:47 +0000 (05:15 +0000)
commite0f8d3d54d536ae420c1d897b716a15cb4f05d0a
tree5638f8db596133f0a0c5d176d0c9bf2ca1b599ba
parent14c8e623ad816a845c41fa8e4b359c973078f7c8
[Beacon] Add support for CORS-preflighting for WK2 / NETWORK_SESSION
https://bugs.webkit.org/show_bug.cgi?id=175264
<rdar://problem/33547793>

Reviewed by Youenn Fablet.

Source/WebCore:

Pass additional information when creating a PingHandle so that the PingLoad
can deal with CORS-preflighting on Network process side.

Tests: http/wpt/beacon/cors/cors-preflight-arraybufferview-failure.html
       http/wpt/beacon/cors/cors-preflight-arraybufferview-success.html
       http/wpt/beacon/cors/cors-preflight-blob-failure.html
       http/wpt/beacon/cors/cors-preflight-blob-success.html
       http/wpt/beacon/cors/cors-preflight-cookie.html

* WebCore.xcodeproj/project.pbxproj:
* loader/CrossOriginAccessControl.cpp:
(WebCore::validatePreflightResponse):
* loader/CrossOriginAccessControl.h:
* loader/CrossOriginPreflightChecker.cpp:
(WebCore::CrossOriginPreflightChecker::validatePreflightResponse):
* loader/CrossOriginPreflightResultCache.h:
* loader/LoaderStrategy.h:
* loader/PingLoader.cpp:
(WebCore::PingLoader::loadImage):
(WebCore::PingLoader::sendPing):
(WebCore::PingLoader::sendViolationReport):
(WebCore::PingLoader::startPingLoad):
* loader/PingLoader.h:
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::load):
* page/SecurityOrigin.h:

Source/WebKit:

Implement CORS-preflighting for beacons with a payload that has a non
safelisted MIME type, as per:
- https://w3c.github.io/beacon/#privacy
- https://www.w3.org/TR/beacon/#sec-processing-model

CORS-preflighting is completely handled on Network Process side because
a beacon request can outlive its page and therefore its WebContent
process. This requires us to pass a little more information to the
Network process, in particular the source origin and the corsMode.

The current implementation does not currently deal with CORS preflights
needed upon a redirect. This will be added in a follow-up.

* CMakeLists.txt:
* NetworkProcess/NetworkCORSPreflightChecker.cpp: Added.
(WebKit::NetworkCORSPreflightChecker::NetworkCORSPreflightChecker):
(WebKit::NetworkCORSPreflightChecker::~NetworkCORSPreflightChecker):
(WebKit::NetworkCORSPreflightChecker::startPreflight):
(WebKit::NetworkCORSPreflightChecker::willPerformHTTPRedirection):
(WebKit::NetworkCORSPreflightChecker::didReceiveChallenge):
(WebKit::NetworkCORSPreflightChecker::didReceiveResponseNetworkSession):
(WebKit::NetworkCORSPreflightChecker::didReceiveData):
(WebKit::NetworkCORSPreflightChecker::didCompleteWithError):
(WebKit::NetworkCORSPreflightChecker::didSendData):
(WebKit::NetworkCORSPreflightChecker::wasBlocked):
(WebKit::NetworkCORSPreflightChecker::cannotShowURL):
* NetworkProcess/NetworkCORSPreflightChecker.h: Added.
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::loadPing):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkResourceLoadParameters.cpp:
(WebKit::NetworkResourceLoadParameters::encode const):
(WebKit::NetworkResourceLoadParameters::decode):
* NetworkProcess/NetworkResourceLoadParameters.h:
* NetworkProcess/PingLoad.cpp: Added.
(WebKit::PingLoad::PingLoad):
(WebKit::PingLoad::~PingLoad):
(WebKit::PingLoad::startNetworkLoad):
(WebKit::PingLoad::willPerformHTTPRedirection):
(WebKit::PingLoad::didReceiveChallenge):
(WebKit::PingLoad::didReceiveResponseNetworkSession):
(WebKit::PingLoad::didReceiveData):
(WebKit::PingLoad::didCompleteWithError):
(WebKit::PingLoad::didSendData):
(WebKit::PingLoad::wasBlocked):
(WebKit::PingLoad::cannotShowURL):
(WebKit::PingLoad::timeoutTimerFired):
(WebKit::PingLoad::needsCORSPreflight const):
(WebKit::PingLoad::doCORSPreflight):
* NetworkProcess/PingLoad.h:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::createPingHandle):
* WebProcess/Network/WebLoaderStrategy.h:

Source/WebKitLegacy:

createPingHandle() now takes new parameters but there is currently no behavior
change on WebKit1.

* WebCoreSupport/WebResourceLoadScheduler.cpp:
(WebResourceLoadScheduler::createPingHandle):
* WebCoreSupport/WebResourceLoadScheduler.h:

LayoutTests:

Add layout test coverage.

* http/wpt/beacon/cors/cors-preflight-arraybufferview-failure-expected.txt: Added.
* http/wpt/beacon/cors/cors-preflight-arraybufferview-failure.html: Added.
* http/wpt/beacon/cors/cors-preflight-arraybufferview-success-expected.txt: Added.
* http/wpt/beacon/cors/cors-preflight-arraybufferview-success.html: Added.
* http/wpt/beacon/cors/cors-preflight-blob-failure-expected.txt: Added.
* http/wpt/beacon/cors/cors-preflight-blob-failure.html: Added.
* http/wpt/beacon/cors/cors-preflight-blob-success-expected.txt: Added.
* http/wpt/beacon/cors/cors-preflight-blob-success.html: Added.
* http/wpt/beacon/cors/cors-preflight-cookie-expected.txt: Added.
* http/wpt/beacon/cors/cors-preflight-cookie.html: Added.
* http/wpt/beacon/resources/beacon-preflight.py: Added.
(respondToCORSPreflight):
(main):
* http/wpt/beacon/resources/set-cookie.py: Added.
(main):
* platform/mac-wk1/TestExpectations:
* platform/mac-wk2/TestExpectations:
* platform/win/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220442 268f45cc-cd09-0410-ab3c-d52691b4dbfc
43 files changed:
LayoutTests/ChangeLog
LayoutTests/http/wpt/beacon/cors/cors-preflight-arraybufferview-failure-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-arraybufferview-failure.html [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-arraybufferview-success-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-arraybufferview-success.html [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-blob-failure-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-blob-failure.html [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-blob-success-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-blob-success.html [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-cookie-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/cors/cors-preflight-cookie.html [new file with mode: 0644]
LayoutTests/http/wpt/beacon/resources/beacon-preflight.py [new file with mode: 0644]
LayoutTests/http/wpt/beacon/resources/set-cookie.py [new file with mode: 0644]
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/CrossOriginAccessControl.cpp
Source/WebCore/loader/CrossOriginAccessControl.h
Source/WebCore/loader/CrossOriginPreflightChecker.cpp
Source/WebCore/loader/CrossOriginPreflightResultCache.h
Source/WebCore/loader/LoaderStrategy.h
Source/WebCore/loader/PingLoader.cpp
Source/WebCore/loader/PingLoader.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/page/SecurityOrigin.h
Source/WebKit/CMakeLists.txt
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.cpp [new file with mode: 0644]
Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.h [new file with mode: 0644]
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.cpp
Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h
Source/WebKit/NetworkProcess/PingLoad.cpp [new file with mode: 0644]
Source/WebKit/NetworkProcess/PingLoad.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
Source/WebKit/WebProcess/Network/WebLoaderStrategy.h
Source/WebKitLegacy/ChangeLog
Source/WebKitLegacy/WebCoreSupport/WebResourceLoadScheduler.cpp
Source/WebKitLegacy/WebCoreSupport/WebResourceLoadScheduler.h