Implement quota limitation for keepalive Fetch requests
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Aug 2017 02:51:13 +0000 (02:51 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Aug 2017 02:51:13 +0000 (02:51 +0000)
commitc75cded66634ea07bce8a11c8a36caf4e6c54a02
treeabf7c39d0acd9f198c330f1023bf1e5d6bd2f735
parente5f3757bbfb8f25c54954d4fef93eaf9f4a8f38b
Implement quota limitation for keepalive Fetch requests
https://bugs.webkit.org/show_bug.cgi?id=175482

Reviewed by Sam Weinig and Youenn Fablet.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/basic/scheme-about.any-expected.txt:
* web-platform-tests/fetch/api/basic/scheme-about.any.worker-expected.txt:
* web-platform-tests/fetch/api/cors/cors-multiple-origins-expected.txt:
* web-platform-tests/fetch/api/cors/cors-multiple-origins-worker-expected.txt:
* web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt:
* web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt:
* web-platform-tests/fetch/http-cache/cc-request-expected.txt:
Rebaseline tests now that we provide a more helpful error message when rejecting
the fetch() promise.

* web-platform-tests/fetch/api/request/request-keepalive-quota-expected.txt:
Rebaseline test for keepalive Fetch requests quota which is now passing.

Source/WebCore:

Implement quota limitation for keepalive Fetch requests as per:
- https://fetch.spec.whatwg.org/#http-network-or-cache-fetch (Step 9)

This partly works for Beacon as well, meaning that no Beacon with a body
over 64Kb can be sent. However, we don't keep track about wether or not
beacon loads are inflight or not.

Also update CachedResourceLoader::requestResource() so that the caller
can get a ResourceError when it returns null. This is useful for both
Fetch and Beacon to return better error messages.

Test: http/wpt/beacon/beacon-quota.html

* CMakeLists.txt:
* Modules/beacon/NavigatorBeacon.cpp:
(WebCore::NavigatorBeacon::sendBeacon):
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::BlobLoader::didReceiveResponse):
(WebCore::FetchBodyOwner::BlobLoader::didFail):
* Modules/fetch/FetchBodyOwner.h:
* Modules/fetch/FetchLoader.cpp:
(WebCore::FetchLoader::start):
(WebCore::FetchLoader::didFail):
* Modules/fetch/FetchLoaderClient.h:
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::BodyLoader::didFail):
* Modules/fetch/FetchResponse.h:
* WebCore.xcodeproj/project.pbxproj:
* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::loadRequest):
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::load):
* loader/cache/CachedResource.h:
(WebCore::CachedResource::isMainOrMediaOrIconOrRawResource const):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::createResource):
(WebCore::CachedResourceLoader::requestImage):
(WebCore::CachedResourceLoader::requestFont):
(WebCore::CachedResourceLoader::requestTextTrack):
(WebCore::CachedResourceLoader::requestCSSStyleSheet):
(WebCore::CachedResourceLoader::requestUserCSSStyleSheet):
(WebCore::CachedResourceLoader::requestScript):
(WebCore::CachedResourceLoader::requestXSLStyleSheet):
(WebCore::CachedResourceLoader::requestSVGDocument):
(WebCore::CachedResourceLoader::requestLinkResource):
(WebCore::CachedResourceLoader::requestMedia):
(WebCore::CachedResourceLoader::requestIcon):
(WebCore::CachedResourceLoader::requestRawResource):
(WebCore::CachedResourceLoader::requestBeaconResource):
(WebCore::CachedResourceLoader::requestMainResource):
(WebCore::CachedResourceLoader::requestResource):
(WebCore::CachedResourceLoader::preload):
* loader/cache/CachedResourceLoader.h:
* loader/cache/KeepaliveRequestTracker.cpp: Added.
(WebCore::KeepaliveRequestTracker::~KeepaliveRequestTracker):
(WebCore::KeepaliveRequestTracker::canLoadRequest):
(WebCore::KeepaliveRequestTracker::registerRequest):
(WebCore::KeepaliveRequestTracker::responseReceived):
(WebCore::KeepaliveRequestTracker::notifyFinished):
(WebCore::KeepaliveRequestTracker::unregisterRequest):
* loader/cache/KeepaliveRequestTracker.h: Added.
* platform/network/FormData.cpp:
(WebCore::FormDataElement::lengthInBytes const):
(WebCore::FormData::lengthInBytes const):
* platform/network/FormData.h:

LayoutTests:

* fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt:
* http/tests/contentextensions/async-xhr-onerror-expected.txt:
* http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-iframe-expected.txt:
* http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-main-frame-expected.txt:
* http/tests/security/mixedContent/insecure-xhr-in-main-frame-expected.txt:
Rebaseline a few tests now that we provide a more helpful error message when an XHR is failing synchronously.

* http/wpt/beacon/beacon-quota-expected.txt: Added.
* http/wpt/beacon/beacon-quota.html: Added.
Add layout test coverage for keepalive Fetch requests quota in the context of sendBeacon().
The second part of the test is still failing because WebCore does not currently know when
ping loads (e.g. beacon loads) complete. This will be addressed via Bug 175443.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220622 268f45cc-cd09-0410-ab3c-d52691b4dbfc
41 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt
LayoutTests/http/tests/contentextensions/async-xhr-onerror-expected.txt
LayoutTests/http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-iframe-expected.txt
LayoutTests/http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-main-frame-expected.txt
LayoutTests/http/tests/security/mixedContent/insecure-xhr-in-main-frame-expected.txt
LayoutTests/http/wpt/beacon/beacon-quota-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/beacon/beacon-quota.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-about.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-about.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-multiple-origins-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-multiple-origins-worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-keepalive-quota-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/http-cache/cc-request-expected.txt
LayoutTests/inspector/worker/resources-in-worker-expected.txt
LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-cache-only-if-cached-expected.txt
LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/http-cache/cc-request-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/beacon/NavigatorBeacon.cpp
Source/WebCore/Modules/fetch/FetchBodyOwner.cpp
Source/WebCore/Modules/fetch/FetchBodyOwner.h
Source/WebCore/Modules/fetch/FetchLoader.cpp
Source/WebCore/Modules/fetch/FetchLoaderClient.h
Source/WebCore/Modules/fetch/FetchResponse.cpp
Source/WebCore/Modules/fetch/FetchResponse.h
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/loader/cache/KeepaliveRequestTracker.cpp [new file with mode: 0644]
Source/WebCore/loader/cache/KeepaliveRequestTracker.h [new file with mode: 0644]
Source/WebCore/platform/network/FormData.cpp
Source/WebCore/platform/network/FormData.h