Changeset 220751 in webkit


Ignore:
Timestamp:
Aug 15, 2017 12:35:11 PM (7 years ago)
Author:
Chris Dumez
Message:

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:

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.

Location:
trunk
Files:
4 added
38 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r220750 r220751  
     12017-08-15  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement quota limitation for keepalive Fetch requests
     4        https://bugs.webkit.org/show_bug.cgi?id=175482
     5
     6        Reviewed by Sam Weinig and Youenn Fablet.
     7
     8        * fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt:
     9        * http/tests/contentextensions/async-xhr-onerror-expected.txt:
     10        * http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-iframe-expected.txt:
     11        * http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-main-frame-expected.txt:
     12        * http/tests/security/mixedContent/insecure-xhr-in-main-frame-expected.txt:
     13        Rebaseline a few tests now that we provide a more helpful error message when an XHR is failing synchronously.
     14
     15        * http/wpt/beacon/beacon-quota-expected.txt: Added.
     16        * http/wpt/beacon/beacon-quota.html: Added.
     17        Add layout test coverage for keepalive Fetch requests quota in the context of sendBeacon().
     18        The second part of the test is still failing because WebCore does not currently know when
     19        ping loads (e.g. beacon loads) complete. This will be addressed via Bug 175443.
     20
    1212017-08-15  Darin Adler  <darin@apple.com>
    222
  • trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt

    r220707 r220751  
    11CONSOLE MESSAGE: line 64: Not allowed to load local resource: nonexistent.html
    2 CONSOLE MESSAGE: line 64: XMLHttpRequest cannot load nonexistent.html due to access control checks.
     2CONSOLE MESSAGE: line 64: XMLHttpRequest cannot load nonexistent.html. Not allowed to request resource
    33
    44Bug 22475: REGRESSION: Async XMLHttpRequest never finishes on nonexistent files anymore
  • trunk/LayoutTests/http/tests/contentextensions/async-xhr-onerror-expected.txt

    r220707 r220751  
    11CONSOLE MESSAGE: line 30: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/async-xhr-onerror.html from loading a resource from http://127.0.0.1:8000/contentextensions/resources/url-blocking-test.js
    2 CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/contentextensions/resources/url-blocking-test.js due to access control checks.
     2CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/contentextensions/resources/url-blocking-test.js. Resource blocked by content blocker
    33CONSOLE MESSAGE: line 30: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/async-xhr-onerror.html from loading a resource from http://127.0.0.1:8000/contentextensions/resources/url-blocking-test.js
    4 CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/contentextensions/resources/url-blocking-test.js due to access control checks.
     4CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/contentextensions/resources/url-blocking-test.js. Resource blocked by content blocker
    55Asynchronous onreadystatechange status: 0, readyState:1, responseText:
    66Finished runTest. Waiting for callbacks
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-iframe-expected.txt

    r220707 r220751  
    33frame "<!--framePath //<!--frame0-->-->" - didCommitLoadForFrame
    44CONSOLE MESSAGE: Blocked mixed content http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi because 'block-all-mixed-content' appears in the Content Security Policy.
    5 CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi due to access control checks.
     5CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi. Not allowed to request resource
    66frame "<!--framePath //<!--frame0-->-->" - didFinishDocumentLoadForFrame
    77frame "<!--framePath //<!--frame0-->-->" - didHandleOnloadEventsForFrame
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-xhr-asynchronous-in-main-frame-expected.txt

    r220707 r220751  
    55main frame - didCommitLoadForFrame
    66CONSOLE MESSAGE: Blocked mixed content http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi because 'block-all-mixed-content' appears in the Content Security Policy.
    7 CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi due to access control checks.
     7CONSOLE MESSAGE: line 30: XMLHttpRequest cannot load http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi. Not allowed to request resource
    88main frame - didFinishDocumentLoadForFrame
    99main frame - didHandleOnloadEventsForFrame
  • trunk/LayoutTests/http/tests/security/mixedContent/insecure-xhr-in-main-frame-expected.txt

    r220707 r220751  
    11CONSOLE MESSAGE: line 28: [blocked] The page at https://127.0.0.1:8443/security/mixedContent/resources/insecure-xhr-in-main-frame-window.html was not allowed to display insecure content from http://127.0.0.1:8000/.
    22
    3 CONSOLE MESSAGE: line 28: XMLHttpRequest cannot load http://127.0.0.1:8000/ due to access control checks.
     3CONSOLE MESSAGE: line 28: XMLHttpRequest cannot load http://127.0.0.1:8000/. Not allowed to request resource
    44This test opens a HTTPS window that loads insecure data via XHR. We should trigger a mixed content callback because the main frame in the window is HTTPS but now has insecure data.
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r220733 r220751  
     12017-08-15  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement quota limitation for keepalive Fetch requests
     4        https://bugs.webkit.org/show_bug.cgi?id=175482
     5
     6        Reviewed by Sam Weinig and Youenn Fablet.
     7
     8        * web-platform-tests/fetch/api/basic/scheme-about.any-expected.txt:
     9        * web-platform-tests/fetch/api/basic/scheme-about.any.worker-expected.txt:
     10        * web-platform-tests/fetch/api/cors/cors-multiple-origins-expected.txt:
     11        * web-platform-tests/fetch/api/cors/cors-multiple-origins-worker-expected.txt:
     12        * web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt:
     13        * web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt:
     14        * web-platform-tests/fetch/http-cache/cc-request-expected.txt:
     15        Rebaseline tests now that we provide a more helpful error message when rejecting
     16        the fetch() promise.
     17
     18        * web-platform-tests/fetch/api/request/request-keepalive-quota-expected.txt:
     19        Rebaseline test for keepalive Fetch requests quota which is now passing.
     20
    1212017-08-14  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-about.any-expected.txt

    r220707 r220751  
    66CONSOLE MESSAGE: line 27: Fetch API cannot load about:unicorn. Cross origin requests are only supported for HTTP.
    77
    8 FAIL Fetching about:blank (GET) is OK promise_test: Unhandled rejection with value: object "TypeError: Type error"
    9 FAIL Fetching about:blank (PUT) is OK promise_test: Unhandled rejection with value: object "TypeError: Type error"
    10 FAIL Fetching about:blank (POST) is OK promise_test: Unhandled rejection with value: object "TypeError: Type error"
     8FAIL Fetching about:blank (GET) is OK promise_test: Unhandled rejection with value: object "TypeError: Cross origin requests are only supported for HTTP."
     9FAIL Fetching about:blank (PUT) is OK promise_test: Unhandled rejection with value: object "TypeError: Preflight response is not successful"
     10FAIL Fetching about:blank (POST) is OK promise_test: Unhandled rejection with value: object "TypeError: Cross origin requests are only supported for HTTP."
    1111PASS Fetching about:invalid.com is KO
    1212PASS Fetching about:config is KO
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/scheme-about.any.worker-expected.txt

    r220707 r220751  
    11
    2 FAIL Fetching about:blank (GET) is OK promise_test: Unhandled rejection with value: object "TypeError: Type error"
    3 FAIL Fetching about:blank (PUT) is OK promise_test: Unhandled rejection with value: object "TypeError: Type error"
    4 FAIL Fetching about:blank (POST) is OK promise_test: Unhandled rejection with value: object "TypeError: Type error"
     2FAIL Fetching about:blank (GET) is OK promise_test: Unhandled rejection with value: object "TypeError: Cross origin requests are only supported for HTTP."
     3FAIL Fetching about:blank (PUT) is OK promise_test: Unhandled rejection with value: object "TypeError: Preflight response is not successful"
     4FAIL Fetching about:blank (POST) is OK promise_test: Unhandled rejection with value: object "TypeError: Cross origin requests are only supported for HTTP."
    55PASS Fetching about:invalid.com is KO
    66PASS Fetching about:config is KO
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-multiple-origins-expected.txt

    r220707 r220751  
    1212CONSOLE MESSAGE: Fetch API cannot load http://localhost:8801/fetch/api/resources/preflight.py?origin=%2C%20http%3A%2F%2Fexample.com%2C%20https%3A%2F%2Fexample2.com. Access-Control-Allow-Origin cannot contain more than one origin.
    1313
    14 FAIL 3 origins allowed, match the 3rd (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Type error"
    15 FAIL 3 origins allowed, match the 3rd ("*") promise_test: Unhandled rejection with value: object "TypeError: Type error"
    16 FAIL 3 origins allowed, match twice (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Type error"
    17 FAIL 3 origins allowed, match twice ("*") promise_test: Unhandled rejection with value: object "TypeError: Type error"
    18 FAIL 3 origins allowed, match twice ("*" and http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Type error"
     14FAIL 3 origins allowed, match the 3rd (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     15FAIL 3 origins allowed, match the 3rd ("*") promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     16FAIL 3 origins allowed, match twice (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     17FAIL 3 origins allowed, match twice ("*") promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     18FAIL 3 origins allowed, match twice ("*" and http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
    1919PASS 3 origins allowed, no match
    2020
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-multiple-origins-worker-expected.txt

    r220707 r220751  
    66CONSOLE MESSAGE: Access-Control-Allow-Origin cannot contain more than one origin.
    77
    8 FAIL 3 origins allowed, match the 3rd (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Type error"
    9 FAIL 3 origins allowed, match the 3rd ("*") promise_test: Unhandled rejection with value: object "TypeError: Type error"
    10 FAIL 3 origins allowed, match twice (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Type error"
    11 FAIL 3 origins allowed, match twice ("*") promise_test: Unhandled rejection with value: object "TypeError: Type error"
    12 FAIL 3 origins allowed, match twice ("*" and http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Type error"
     8FAIL 3 origins allowed, match the 3rd (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     9FAIL 3 origins allowed, match the 3rd ("*") promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     10FAIL 3 origins allowed, match twice (http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     11FAIL 3 origins allowed, match twice ("*") promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
     12FAIL 3 origins allowed, match twice ("*" and http://localhost:8800) promise_test: Unhandled rejection with value: object "TypeError: Access-Control-Allow-Origin cannot contain more than one origin."
    1313PASS 3 origins allowed, no match
    1414
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt

    r220707 r220751  
    88
    99PASS CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test)
    10 FAIL CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Type error"
    11 FAIL CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Type error"
     10FAIL CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Method SUPER is not allowed by Access-Control-Allow-Methods."
     11FAIL CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Method OK is not allowed by Access-Control-Allow-Methods."
    1212PASS CORS that fails with credentials: true; method: OK (allowed: *); header: X-Test,1 (allowed: *)
    1313PASS CORS that fails with credentials: true; method: PUT (allowed: *); header: undefined (allowed: )
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt

    r220707 r220751  
    11
    22PASS CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test)
    3 FAIL CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Type error"
    4 FAIL CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Type error"
     3FAIL CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Method SUPER is not allowed by Access-Control-Allow-Methods."
     4FAIL CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Method OK is not allowed by Access-Control-Allow-Methods."
    55PASS CORS that fails with credentials: true; method: OK (allowed: *); header: X-Test,1 (allowed: *)
    66PASS CORS that fails with credentials: true; method: PUT (allowed: *); header: undefined (allowed: )
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-expected.txt

    r220707 r220751  
    11
    2 FAIL Redirect 301 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     2FAIL Redirect 301 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    33PASS Redirect 301 21 times
    4 FAIL Redirect 302 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     4FAIL Redirect 302 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    55PASS Redirect 302 21 times
    6 FAIL Redirect 303 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     6FAIL Redirect 303 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    77PASS Redirect 303 21 times
    8 FAIL Redirect 307 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     8FAIL Redirect 307 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    99PASS Redirect 307 21 times
    10 FAIL Redirect 308 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     10FAIL Redirect 308 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    1111PASS Redirect 308 21 times
    1212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-count-worker-expected.txt

    r220707 r220751  
    11
    2 FAIL Redirect 301 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     2FAIL Redirect 301 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    33PASS Redirect 301 21 times
    4 FAIL Redirect 302 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     4FAIL Redirect 302 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    55PASS Redirect 302 21 times
    6 FAIL Redirect 303 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     6FAIL Redirect 303 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    77PASS Redirect 303 21 times
    8 FAIL Redirect 307 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     8FAIL Redirect 307 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    99PASS Redirect 307 21 times
    10 FAIL Redirect 308 20 times promise_test: Unhandled rejection with value: object "TypeError: Type error"
     10FAIL Redirect 308 20 times promise_test: Unhandled rejection with value: object "TypeError: too many HTTP redirects"
    1111PASS Redirect 308 21 times
    1212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-keepalive-quota-expected.txt

    r220707 r220751  
     1CONSOLE MESSAGE: line 44: Fetch API cannot load http://localhost:8800/fetch/api/resources/trickle.py?count=1&ms=0. Reached maximum amount of queued data of 64Kb for keepalive requests
     2CONSOLE MESSAGE: line 71: Fetch API cannot load http://localhost:8800/fetch/api/resources/trickle.py?count=1&ms=0. Reached maximum amount of queued data of 64Kb for keepalive requests
     3CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: Reached maximum amount of queued data of 64Kb for keepalive requests
     4CONSOLE MESSAGE: line 88: Fetch API cannot load http://localhost:8800/fetch/api/resources/trickle.py?count=1&ms=0. Reached maximum amount of queued data of 64Kb for keepalive requests
     5
     6Harness Error (FAIL), message = Reached maximum amount of queued data of 64Kb for keepalive requests
    17
    28PASS A Keep-Alive fetch() with a small body should succeed.
    39PASS A Keep-Alive fetch() with a body at the Quota Limit should succeed.
    4 FAIL A Keep-Alive fetch() with a body over the Quota Limit should reject. assert_unreached: Should have rejected: undefined Reached unreachable code
     10PASS A Keep-Alive fetch() with a body over the Quota Limit should reject.
    511PASS A Keep-Alive fetch() should return it's allocated Quota upon promise resolution.
    612PASS A Keep-Alive fetch() should return only it's allocated Quota upon promise resolution.
    7 FAIL A Keep-Alive fetch() should not be allowed if the Quota is used up. assert_unreached: Should have rejected: undefined Reached unreachable code
     13PASS A Keep-Alive fetch() should not be allowed if the Quota is used up.
    814
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/http-cache/cc-request-expected.txt

    r220707 r220751  
    1111PASS HTTP cache validates fresh response with ETag when request contains Cache-Control: no-cache.
    1212FAIL HTTP cache doesn't reuse fresh response when request contains Cache-Control: no-store. assert_equals: Response used expected 2 but got 1
    13 FAIL HTTP cache generates 504 status code when nothing is in cache and request contains Cache-Control: only-if-cached. promise_test: Unhandled rejection with value: object "TypeError: Type error"
     13FAIL HTTP cache generates 504 status code when nothing is in cache and request contains Cache-Control: only-if-cached. promise_test: Unhandled rejection with value: object "TypeError: can’t load from network"
    1414
  • trunk/LayoutTests/inspector/worker/resources-in-worker-expected.txt

    r220707 r220751  
    1 CONSOLE MESSAGE: line 1: Unhandled Promise Rejection: TypeError: Type error
     1CONSOLE MESSAGE: line 1: Unhandled Promise Rejection: TypeError: The requested URL was not found on this server.
    22Test for Resources in a Worker.
    33
  • trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/api/request/request-cache-only-if-cached-expected.txt

    r220707 r220751  
    66PASS RequestCache "only-if-cached" mode checks the cache for previously cached content and does not go to the network if a cached response is not found with Etag and fresh response
    77PASS RequestCache "only-if-cached" mode checks the cache for previously cached content and does not go to the network if a cached response is not found with Last-Modified and fresh response
    8 FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Etag and fresh response promise_test: Unhandled rejection with value: object "TypeError: Type error"
    9 FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Last-Modified and fresh response promise_test: Unhandled rejection with value: object "TypeError: Type error"
    10 FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Etag and stale response promise_test: Unhandled rejection with value: object "TypeError: Type error"
    11 FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Last-Modified and stale response promise_test: Unhandled rejection with value: object "TypeError: Type error"
     8FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Etag and fresh response promise_test: Unhandled rejection with value: object "TypeError: resource unavailable"
     9FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Last-Modified and fresh response promise_test: Unhandled rejection with value: object "TypeError: resource unavailable"
     10FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Etag and stale response promise_test: Unhandled rejection with value: object "TypeError: resource unavailable"
     11FAIL RequestCache "only-if-cached" (with "same-origin") uses cached same-origin redirects to same-origin content with Last-Modified and stale response promise_test: Unhandled rejection with value: object "TypeError: resource unavailable"
    1212PASS RequestCache "only-if-cached" (with "same-origin") does not follow redirects across origins and rejects with Etag and fresh response
    1313PASS RequestCache "only-if-cached" (with "same-origin") does not follow redirects across origins and rejects with Last-Modified and fresh response
  • trunk/LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/fetch/http-cache/cc-request-expected.txt

    r220707 r220751  
    1111PASS HTTP cache validates fresh response with ETag when request contains Cache-Control: no-cache.
    1212PASS HTTP cache doesn't reuse fresh response when request contains Cache-Control: no-store.
    13 FAIL HTTP cache generates 504 status code when nothing is in cache and request contains Cache-Control: only-if-cached. promise_test: Unhandled rejection with value: object "TypeError: Type error"
     13FAIL HTTP cache generates 504 status code when nothing is in cache and request contains Cache-Control: only-if-cached. promise_test: Unhandled rejection with value: object "TypeError: can’t load from network"
    1414
  • trunk/Source/WebCore/CMakeLists.txt

    r220734 r220751  
    20712071    loader/cache/CachedScript.cpp
    20722072    loader/cache/CachedXSLStyleSheet.cpp
     2073    loader/cache/KeepaliveRequestTracker.cpp
    20732074    loader/cache/MemoryCache.cpp
    20742075
  • trunk/Source/WebCore/ChangeLog

    r220750 r220751  
     12017-08-15  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement quota limitation for keepalive Fetch requests
     4        https://bugs.webkit.org/show_bug.cgi?id=175482
     5
     6        Reviewed by Sam Weinig and Youenn Fablet.
     7
     8        Implement quota limitation for keepalive Fetch requests as per:
     9        - https://fetch.spec.whatwg.org/#http-network-or-cache-fetch (Step 9)
     10
     11        This partly works for Beacon as well, meaning that no Beacon with a body
     12        over 64Kb can be sent. However, we don't keep track about wether or not
     13        beacon loads are inflight or not.
     14
     15        Also update CachedResourceLoader::requestResource() so that the caller
     16        can get a ResourceError when it returns null. This is useful for both
     17        Fetch and Beacon to return better error messages.
     18
     19        Test: http/wpt/beacon/beacon-quota.html
     20
     21        * CMakeLists.txt:
     22        * Modules/beacon/NavigatorBeacon.cpp:
     23        (WebCore::NavigatorBeacon::sendBeacon):
     24        * Modules/fetch/FetchBodyOwner.cpp:
     25        (WebCore::FetchBodyOwner::BlobLoader::didReceiveResponse):
     26        (WebCore::FetchBodyOwner::BlobLoader::didFail):
     27        * Modules/fetch/FetchBodyOwner.h:
     28        * Modules/fetch/FetchLoader.cpp:
     29        (WebCore::FetchLoader::start):
     30        (WebCore::FetchLoader::didFail):
     31        * Modules/fetch/FetchLoaderClient.h:
     32        * Modules/fetch/FetchResponse.cpp:
     33        (WebCore::FetchResponse::BodyLoader::didFail):
     34        * Modules/fetch/FetchResponse.h:
     35        * WebCore.xcodeproj/project.pbxproj:
     36        * loader/DocumentThreadableLoader.cpp:
     37        (WebCore::DocumentThreadableLoader::loadRequest):
     38        * loader/cache/CachedResource.cpp:
     39        (WebCore::CachedResource::load):
     40        * loader/cache/CachedResource.h:
     41        (WebCore::CachedResource::isMainOrMediaOrIconOrRawResource const):
     42        * loader/cache/CachedResourceLoader.cpp:
     43        (WebCore::createResource):
     44        (WebCore::CachedResourceLoader::requestImage):
     45        (WebCore::CachedResourceLoader::requestFont):
     46        (WebCore::CachedResourceLoader::requestTextTrack):
     47        (WebCore::CachedResourceLoader::requestCSSStyleSheet):
     48        (WebCore::CachedResourceLoader::requestUserCSSStyleSheet):
     49        (WebCore::CachedResourceLoader::requestScript):
     50        (WebCore::CachedResourceLoader::requestXSLStyleSheet):
     51        (WebCore::CachedResourceLoader::requestSVGDocument):
     52        (WebCore::CachedResourceLoader::requestLinkResource):
     53        (WebCore::CachedResourceLoader::requestMedia):
     54        (WebCore::CachedResourceLoader::requestIcon):
     55        (WebCore::CachedResourceLoader::requestRawResource):
     56        (WebCore::CachedResourceLoader::requestBeaconResource):
     57        (WebCore::CachedResourceLoader::requestMainResource):
     58        (WebCore::CachedResourceLoader::requestResource):
     59        (WebCore::CachedResourceLoader::preload):
     60        * loader/cache/CachedResourceLoader.h:
     61        * loader/cache/KeepaliveRequestTracker.cpp: Added.
     62        (WebCore::KeepaliveRequestTracker::~KeepaliveRequestTracker):
     63        (WebCore::KeepaliveRequestTracker::canLoadRequest):
     64        (WebCore::KeepaliveRequestTracker::registerRequest):
     65        (WebCore::KeepaliveRequestTracker::responseReceived):
     66        (WebCore::KeepaliveRequestTracker::notifyFinished):
     67        (WebCore::KeepaliveRequestTracker::unregisterRequest):
     68        * loader/cache/KeepaliveRequestTracker.h: Added.
     69        * platform/network/FormData.cpp:
     70        (WebCore::FormDataElement::lengthInBytes const):
     71        (WebCore::FormData::lengthInBytes const):
     72        * platform/network/FormData.h:
     73
    1742017-08-15  Darin Adler  <darin@apple.com>
    275
  • trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp

    r220707 r220751  
    7474        }
    7575    }
    76     document.cachedResourceLoader().requestBeaconResource({ WTFMove(request), options });
     76    ResourceError error;
     77    if (!document.cachedResourceLoader().requestBeaconResource({ WTFMove(request), options }, &error)) {
     78        if (!error.isNull())
     79            document.addConsoleMessage(MessageSource::Network, MessageLevel::Error, error.localizedDescription());
     80        return false;
     81    }
    7782    return true;
    7883}
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp

    r220707 r220751  
    3333#include "HTTPParsers.h"
    3434#include "JSBlob.h"
     35#include "ResourceError.h"
    3536#include "ResourceResponse.h"
    3637
     
    278279{
    279280    if (response.httpStatusCode() != 200)
    280         didFail();
    281 }
    282 
    283 void FetchBodyOwner::BlobLoader::didFail()
     281        didFail({ });
     282}
     283
     284void FetchBodyOwner::BlobLoader::didFail(const ResourceError&)
    284285{
    285286    // didFail might be called within FetchLoader::start call.
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h

    r220707 r220751  
    8989        void didReceiveResponse(const ResourceResponse&) final;
    9090        void didReceiveData(const char* data, size_t size) final { owner.blobChunk(data, size); }
    91         void didFail() final;
     91        void didFail(const ResourceError&) final;
    9292        void didSucceed() final { owner.blobLoadingSucceeded(); }
    9393
  • trunk/Source/WebCore/Modules/fetch/FetchLoader.cpp

    r220707 r220751  
    3636#include "FetchLoaderClient.h"
    3737#include "FetchRequest.h"
     38#include "ResourceError.h"
    3839#include "ResourceRequest.h"
    3940#include "ScriptExecutionContext.h"
     
    4950    auto urlForReading = BlobURL::createPublicURL(context.securityOrigin());
    5051    if (urlForReading.isEmpty()) {
    51         m_client.didFail();
     52        m_client.didFail({ errorDomainWebKitInternal, 0, URL(), ASCIILiteral("Could not create URL for Blob") });
    5253        return;
    5354    }
     
    8990
    9091    if (!context.shouldBypassMainWorldContentSecurityPolicy() && !contentSecurityPolicy.allowConnectToSource(fetchRequest.url())) {
    91         m_client.didFail();
     92        m_client.didFail({ errorDomainWebKitInternal, 0, fetchRequest.url(), ASCIILiteral("Not allowed by ContentSecurityPolicy"), ResourceError::Type::AccessControl });
    9293        return;
    9394    }
     
    145146}
    146147
    147 void FetchLoader::didFail(const ResourceError&)
     148void FetchLoader::didFail(const ResourceError& error)
    148149{
    149     m_client.didFail();
     150    m_client.didFail(error);
    150151}
    151152
  • trunk/Source/WebCore/Modules/fetch/FetchLoaderClient.h

    r220707 r220751  
    3333namespace WebCore {
    3434
     35class ResourceError;
    3536class ResourceResponse;
    3637
     
    4445
    4546    virtual void didSucceed() = 0;
    46     virtual void didFail() = 0;
     47    virtual void didFail(const ResourceError&) = 0;
    4748};
    4849
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r220707 r220751  
    3434#include "JSBlob.h"
    3535#include "JSFetchResponse.h"
     36#include "ResourceError.h"
    3637#include "ScriptExecutionContext.h"
    3738
     
    139140}
    140141
    141 void FetchResponse::BodyLoader::didFail()
     142void FetchResponse::BodyLoader::didFail(const ResourceError& error)
    142143{
    143144    ASSERT(m_response.hasPendingActivity());
    144145    if (m_promise)
    145         std::exchange(m_promise, std::nullopt)->reject(TypeError);
     146        std::exchange(m_promise, std::nullopt)->reject(Exception { TypeError, String(error.localizedDescription()) });
    146147
    147148#if ENABLE(STREAMS_API)
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r220707 r220751  
    119119        // FetchLoaderClient API
    120120        void didSucceed() final;
    121         void didFail() final;
     121        void didFail(const ResourceError&) final;
    122122        void didReceiveResponse(const ResourceResponse&) final;
    123123        void didReceiveData(const char*, size_t) final;
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r220732 r220751  
    34733473                83A4A9F91CE7FD8100709B00 /* JSXMLDocumentCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83A4A9F81CE7FD7E00709B00 /* JSXMLDocumentCustom.cpp */; };
    34743474                83B2D1751B8BCD6A00A02E47 /* NativeNodeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E959E11B8BC22B004D9385 /* NativeNodeFilter.h */; settings = {ATTRIBUTES = (Private, ); }; };
     3475                83B74EF51F3E0BF200996BC7 /* KeepaliveRequestTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83B74EF21F3E0BD700996BC7 /* KeepaliveRequestTracker.cpp */; };
     3476                83B74EF61F3E0BF200996BC7 /* KeepaliveRequestTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 83B74EF31F3E0BD700996BC7 /* KeepaliveRequestTracker.h */; settings = {ATTRIBUTES = (Private, ); }; };
    34753477                83B9687B19F8AB83004EF7AF /* StyleBuilderConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 83B9687919F8AB83004EF7AF /* StyleBuilderConverter.h */; };
    34763478                83BB5C881D5D6F45005A71F4 /* AllDescendantsCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 83BB5C871D5D6F3A005A71F4 /* AllDescendantsCollection.h */; };
     
    1159811600                839AAFEB1A0C0C8D00605F99 /* HTMLWBRElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLWBRElement.h; sourceTree = "<group>"; };
    1159911601                83A4A9F81CE7FD7E00709B00 /* JSXMLDocumentCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSXMLDocumentCustom.cpp; sourceTree = "<group>"; };
     11602                83B74EF21F3E0BD700996BC7 /* KeepaliveRequestTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeepaliveRequestTracker.cpp; sourceTree = "<group>"; };
     11603                83B74EF31F3E0BD700996BC7 /* KeepaliveRequestTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeepaliveRequestTracker.h; sourceTree = "<group>"; };
    1160011604                83B9687919F8AB83004EF7AF /* StyleBuilderConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilderConverter.h; sourceTree = "<group>"; };
    1160111605                83BB5C871D5D6F3A005A71F4 /* AllDescendantsCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AllDescendantsCollection.h; sourceTree = "<group>"; };
     
    2238422388                                BCB16C0F0979C3BD00467741 /* CachedXSLStyleSheet.h */,
    2238522389                                F587864902DE3A9A01EA4122 /* CachePolicy.h */,
     22390                                83B74EF21F3E0BD700996BC7 /* KeepaliveRequestTracker.cpp */,
     22391                                83B74EF31F3E0BD700996BC7 /* KeepaliveRequestTracker.h */,
    2238622392                                BCB16BFE0979C3BD00467741 /* MemoryCache.cpp */,
    2238722393                                BCB16BFF0979C3BD00467741 /* MemoryCache.h */,
     
    2858528591                                1A762C7A0A074F2600989F5B /* JSXPathResult.h in Headers */,
    2858628592                                BCEFE1EB0DCA5F6400739219 /* JSXSLTProcessor.h in Headers */,
     28593                                83B74EF61F3E0BF200996BC7 /* KeepaliveRequestTracker.h in Headers */,
    2858728594                                85031B440A44EFC700F992E0 /* KeyboardEvent.h in Headers */,
    2858828595                                1AE00D59182DAC8D00087DD7 /* KeyedCoding.h in Headers */,
     
    3262632633                                A1C7FAA2133A5D3500D6732D /* JSXPathResultCustom.cpp in Sources */,
    3262732634                                BCEFE1EA0DCA5F6400739219 /* JSXSLTProcessor.cpp in Sources */,
     32635                                83B74EF51F3E0BF200996BC7 /* KeepaliveRequestTracker.cpp in Sources */,
    3262832636                                85031B430A44EFC700F992E0 /* KeyboardEvent.cpp in Sources */,
    3262932637                                517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */,
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp

    r220707 r220751  
    452452        // We create an URL here as the request will be moved in requestRawResource
    453453        URL requestUrl = newRequest.resourceRequest().url();
    454         m_resource = m_document.cachedResourceLoader().requestRawResource(WTFMove(newRequest));
     454        ResourceError error;
     455        m_resource = m_document.cachedResourceLoader().requestRawResource(WTFMove(newRequest), &error);
    455456        if (m_resource)
    456457            m_resource->addClient(*this);
    457458        else {
    458             // FIXME: Since we receive a synchronous error, this is probably due to some AccessControl checks. We should try to retrieve the actual error.
    459             logErrorAndFail(ResourceError(String(), 0, requestUrl, String(), ResourceError::Type::AccessControl));
     459            if (error.isNull()) {
     460                // FIXME: Since we receive a synchronous error, this is probably due to some AccessControl checks. We should try to retrieve the actual error.
     461                logErrorAndFail(ResourceError(String(), 0, requestUrl, String(), ResourceError::Type::AccessControl));
     462            } else
     463                logErrorAndFail(error);
    460464        }
    461465        return;
  • trunk/Source/WebCore/loader/cache/CachedRawResource.cpp

    r220707 r220751  
    9494
    9595#if USE(QUICK_LOOK)
    96     m_allowEncodedDataReplacement = !m_loader->isQuickLookResource();
     96    m_allowEncodedDataReplacement = m_loader && !m_loader->isQuickLookResource();
    9797#endif
    9898
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r220707 r220751  
    261261    }
    262262
    263     // FIXME: We should not special-case Beacon here.
    264     if (m_options.keepAlive && type() == CachedResource::Beacon) {
     263    if (m_options.keepAlive) {
     264        if (!cachedResourceLoader.keepaliveRequestTracker().tryRegisterRequest(*this)) {
     265            setResourceError({ errorDomainWebKitInternal, 0, request.url(), ASCIILiteral("Reached maximum amount of queued data of 64Kb for keepalive requests") });
     266            failBeforeStarting();
     267            return;
     268        }
     269        // FIXME: We should not special-case Beacon here.
     270        if (type() == CachedResource::Beacon) {
    265271        ASSERT(m_origin);
    266         // Beacon is not exposed to workers so it is safe to rely on the document here.
    267         auto* document = cachedResourceLoader.document();
    268         auto* contentSecurityPolicy = document && !document->shouldBypassMainWorldContentSecurityPolicy() ? document->contentSecurityPolicy() : nullptr;
    269         platformStrategies()->loaderStrategy()->createPingHandle(frame.loader().networkingContext(), request, *m_origin, contentSecurityPolicy, m_options);
    270         return;
     272            // Beacon is not exposed to workers so it is safe to rely on the document here.
     273            auto* document = cachedResourceLoader.document();
     274            auto* contentSecurityPolicy = document && !document->shouldBypassMainWorldContentSecurityPolicy() ? document->contentSecurityPolicy() : nullptr;
     275            platformStrategies()->loaderStrategy()->createPingHandle(frame.loader().networkingContext(), request, *m_origin, contentSecurityPolicy, m_options);
     276            // FIXME: We currently do not get notified when ping loads finish so we treat them as finishing right away.
     277            finishLoading(nullptr);
     278            return;
     279        }
    271280    }
    272281
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r220707 r220751  
    163163    bool isImage() const { return type() == ImageResource; }
    164164    // FIXME: CachedRawResource could be a main resource, an audio/video resource, or a raw XHR/icon resource.
    165     bool isMainOrMediaOrIconOrRawResource() const { return type() == MainResource || type() == MediaResource || type() == Icon || type() == RawResource; }
     165    bool isMainOrMediaOrIconOrRawResource() const { return type() == MainResource || type() == MediaResource || type() == Icon || type() == RawResource || type() == Beacon; }
    166166
    167167    // Whether this request should impact request counting and delay window.onload.
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r220707 r220751  
    104104    case CachedResource::FontResource:
    105105        return new CachedFont(WTFMove(request), sessionID);
     106    case CachedResource::Beacon:
    106107    case CachedResource::MediaResource:
    107108    case CachedResource::RawResource:
     
    109110    case CachedResource::MainResource:
    110111        return new CachedRawResource(WTFMove(request), type, sessionID);
    111     case CachedResource::Beacon:
    112         return new CachedResource(WTFMove(request), CachedResource::Beacon, sessionID);
    113112#if ENABLE(XSLT)
    114113    case CachedResource::XSLStyleSheet:
     
    183182}
    184183
    185 CachedResourceHandle<CachedImage> CachedResourceLoader::requestImage(CachedResourceRequest&& request)
     184CachedResourceHandle<CachedImage> CachedResourceLoader::requestImage(CachedResourceRequest&& request, ResourceError* error)
    186185{
    187186    if (Frame* frame = this->frame()) {
     
    197196
    198197    auto defer = clientDefersImage(request.resourceRequest().url()) ? DeferOption::DeferredByClient : DeferOption::NoDefer;
    199     return downcast<CachedImage>(requestResource(CachedResource::ImageResource, WTFMove(request), ForPreload::No, defer).get());
    200 }
    201 
    202 CachedResourceHandle<CachedFont> CachedResourceLoader::requestFont(CachedResourceRequest&& request, bool isSVG)
     198    return downcast<CachedImage>(requestResource(CachedResource::ImageResource, WTFMove(request), error, ForPreload::No, defer).get());
     199}
     200
     201CachedResourceHandle<CachedFont> CachedResourceLoader::requestFont(CachedResourceRequest&& request, bool isSVG, ResourceError* error)
    203202{
    204203#if ENABLE(SVG_FONTS)
    205204    if (isSVG)
    206         return downcast<CachedSVGFont>(requestResource(CachedResource::SVGFontResource, WTFMove(request)).get());
     205        return downcast<CachedSVGFont>(requestResource(CachedResource::SVGFontResource, WTFMove(request), error).get());
    207206#else
    208207    UNUSED_PARAM(isSVG);
    209208#endif
    210     return downcast<CachedFont>(requestResource(CachedResource::FontResource, WTFMove(request)).get());
     209    return downcast<CachedFont>(requestResource(CachedResource::FontResource, WTFMove(request), error).get());
    211210}
    212211
    213212#if ENABLE(VIDEO_TRACK)
    214 CachedResourceHandle<CachedTextTrack> CachedResourceLoader::requestTextTrack(CachedResourceRequest&& request)
    215 {
    216     return downcast<CachedTextTrack>(requestResource(CachedResource::TextTrackResource, WTFMove(request)).get());
    217 }
    218 #endif
    219 
    220 CachedResourceHandle<CachedCSSStyleSheet> CachedResourceLoader::requestCSSStyleSheet(CachedResourceRequest&& request)
    221 {
    222     return downcast<CachedCSSStyleSheet>(requestResource(CachedResource::CSSStyleSheet, WTFMove(request)).get());
    223 }
    224 
    225 CachedResourceHandle<CachedCSSStyleSheet> CachedResourceLoader::requestUserCSSStyleSheet(CachedResourceRequest&& request)
     213CachedResourceHandle<CachedTextTrack> CachedResourceLoader::requestTextTrack(CachedResourceRequest&& request, ResourceError* error)
     214{
     215    return downcast<CachedTextTrack>(requestResource(CachedResource::TextTrackResource, WTFMove(request), error).get());
     216}
     217#endif
     218
     219CachedResourceHandle<CachedCSSStyleSheet> CachedResourceLoader::requestCSSStyleSheet(CachedResourceRequest&& request, ResourceError* error)
     220{
     221    return downcast<CachedCSSStyleSheet>(requestResource(CachedResource::CSSStyleSheet, WTFMove(request), error).get());
     222}
     223
     224CachedResourceHandle<CachedCSSStyleSheet> CachedResourceLoader::requestUserCSSStyleSheet(CachedResourceRequest&& request, ResourceError*)
    226225{
    227226    ASSERT(document());
     
    249248}
    250249
    251 CachedResourceHandle<CachedScript> CachedResourceLoader::requestScript(CachedResourceRequest&& request)
    252 {
    253     return downcast<CachedScript>(requestResource(CachedResource::Script, WTFMove(request)).get());
     250CachedResourceHandle<CachedScript> CachedResourceLoader::requestScript(CachedResourceRequest&& request, ResourceError* error)
     251{
     252    return downcast<CachedScript>(requestResource(CachedResource::Script, WTFMove(request), error).get());
    254253}
    255254
    256255#if ENABLE(XSLT)
    257 CachedResourceHandle<CachedXSLStyleSheet> CachedResourceLoader::requestXSLStyleSheet(CachedResourceRequest&& request)
    258 {
    259     return downcast<CachedXSLStyleSheet>(requestResource(CachedResource::XSLStyleSheet, WTFMove(request)).get());
    260 }
    261 #endif
    262 
    263 CachedResourceHandle<CachedSVGDocument> CachedResourceLoader::requestSVGDocument(CachedResourceRequest&& request)
    264 {
    265     return downcast<CachedSVGDocument>(requestResource(CachedResource::SVGDocumentResource, WTFMove(request)).get());
     256CachedResourceHandle<CachedXSLStyleSheet> CachedResourceLoader::requestXSLStyleSheet(CachedResourceRequest&& request, ResourceError* error)
     257{
     258    return downcast<CachedXSLStyleSheet>(requestResource(CachedResource::XSLStyleSheet, WTFMove(request), error).get());
     259}
     260#endif
     261
     262CachedResourceHandle<CachedSVGDocument> CachedResourceLoader::requestSVGDocument(CachedResourceRequest&& request, ResourceError* error)
     263{
     264    return downcast<CachedSVGDocument>(requestResource(CachedResource::SVGDocumentResource, WTFMove(request), error).get());
    266265}
    267266
    268267#if ENABLE(LINK_PREFETCH)
    269 CachedResourceHandle<CachedResource> CachedResourceLoader::requestLinkResource(CachedResource::Type type, CachedResourceRequest&& request)
     268CachedResourceHandle<CachedResource> CachedResourceLoader::requestLinkResource(CachedResource::Type type, CachedResourceRequest&& request, ResourceError* error)
    270269{
    271270    ASSERT(frame());
    272271    ASSERT(type == CachedResource::LinkPrefetch || type == CachedResource::LinkSubresource);
    273     return requestResource(type, WTFMove(request));
    274 }
    275 #endif
    276 
    277 CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestMedia(CachedResourceRequest&& request)
    278 {
    279     return downcast<CachedRawResource>(requestResource(CachedResource::MediaResource, WTFMove(request)).get());
    280 }
    281 
    282 CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestIcon(CachedResourceRequest&& request)
    283 {
    284     return downcast<CachedRawResource>(requestResource(CachedResource::Icon, WTFMove(request)).get());
    285 }
    286 
    287 CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestRawResource(CachedResourceRequest&& request)
    288 {
    289     return downcast<CachedRawResource>(requestResource(CachedResource::RawResource, WTFMove(request)).get());
    290 }
    291 
    292 CachedResourceHandle<CachedResource> CachedResourceLoader::requestBeaconResource(CachedResourceRequest&& request)
    293 {
    294     return requestResource(CachedResource::Beacon, WTFMove(request)).get();
    295 }
    296 
    297 CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestMainResource(CachedResourceRequest&& request)
    298 {
    299     return downcast<CachedRawResource>(requestResource(CachedResource::MainResource, WTFMove(request)).get());
     272    return requestResource(type, WTFMove(request), error);
     273}
     274#endif
     275
     276CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestMedia(CachedResourceRequest&& request, ResourceError* error)
     277{
     278    return downcast<CachedRawResource>(requestResource(CachedResource::MediaResource, WTFMove(request), error).get());
     279}
     280
     281CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestIcon(CachedResourceRequest&& request, ResourceError* error)
     282{
     283    return downcast<CachedRawResource>(requestResource(CachedResource::Icon, WTFMove(request), error).get());
     284}
     285
     286CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestRawResource(CachedResourceRequest&& request, ResourceError* error)
     287{
     288    return downcast<CachedRawResource>(requestResource(CachedResource::RawResource, WTFMove(request), error).get());
     289}
     290
     291CachedResourceHandle<CachedResource> CachedResourceLoader::requestBeaconResource(CachedResourceRequest&& request, ResourceError* error)
     292{
     293    return requestResource(CachedResource::Beacon, WTFMove(request), error).get();
     294}
     295
     296CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestMainResource(CachedResourceRequest&& request, ResourceError* error)
     297{
     298    return downcast<CachedRawResource>(requestResource(CachedResource::MainResource, WTFMove(request), error).get());
    300299}
    301300
     
    690689}
    691690
    692 CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(CachedResource::Type type, CachedResourceRequest&& request, ForPreload forPreload, DeferOption defer)
     691CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(CachedResource::Type type, CachedResourceRequest&& request, ResourceError* error, ForPreload forPreload, DeferOption defer)
    693692{
    694693    if (Document* document = this->document())
     
    701700    if (!url.isValid()) {
    702701        RELEASE_LOG_IF_ALLOWED("requestResource: URL is invalid (frame = %p)", frame());
     702        if (error)
     703            *error = { errorDomainWebKitInternal, 0, url, ASCIILiteral("URL is invalid") };
    703704        return nullptr;
    704705    }
     
    709710    if (!canRequest(type, url, request, forPreload)) {
    710711        RELEASE_LOG_IF_ALLOWED("requestResource: Not allowed to request resource (frame = %p)", frame());
     712        if (error)
     713            *error = { errorDomainWebKitInternal, 0, url, ASCIILiteral("Not allowed to request resource"), ResourceError::Type::AccessControl };
    711714        return nullptr;
    712715    }
     
    726729                return resource;
    727730            }
     731            if (error)
     732                *error = { errorDomainWebKitInternal, 0, url, ASCIILiteral("Resource blocked by content blocker"), ResourceError::Type::AccessControl };
    728733            return nullptr;
    729734        }
     
    830835            if (resource->allowsCaching() && resource->inCache())
    831836                memoryCache.remove(*resource);
     837            if (error) {
     838                auto resourceError = resource->resourceError();
     839                // Synchronous cancellations are likely due to access control.
     840                *error = !resourceError.isNull() && !resourceError.isCancellation() ? resourceError : ResourceError(String(), 0, url, String(), ResourceError::Type::AccessControl);
     841            }
    832842            return nullptr;
    833843        }
     
    12461256        request.setCharset(m_document->charset());
    12471257
    1248     CachedResourceHandle<CachedResource> resource = requestResource(type, WTFMove(request), ForPreload::Yes);
     1258    CachedResourceHandle<CachedResource> resource = requestResource(type, WTFMove(request), nullptr, ForPreload::Yes);
    12491259    if (resource && (!m_preloads || !m_preloads->contains(resource.get()))) {
    12501260        // Fonts need special treatment since just creating the resource doesn't trigger a load.
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.h

    r220707 r220751  
    3131#include "CachedResourceRequest.h"
    3232#include "ContentSecurityPolicy.h"
     33#include "KeepaliveRequestTracker.h"
    3334#include "ResourceTimingInformation.h"
    3435#include "Timer.h"
     
    7273    ~CachedResourceLoader();
    7374
    74     CachedResourceHandle<CachedImage> requestImage(CachedResourceRequest&&);
    75     CachedResourceHandle<CachedCSSStyleSheet> requestCSSStyleSheet(CachedResourceRequest&&);
    76     CachedResourceHandle<CachedCSSStyleSheet> requestUserCSSStyleSheet(CachedResourceRequest&&);
    77     CachedResourceHandle<CachedScript> requestScript(CachedResourceRequest&&);
    78     CachedResourceHandle<CachedFont> requestFont(CachedResourceRequest&&, bool isSVG);
    79     CachedResourceHandle<CachedRawResource> requestMedia(CachedResourceRequest&&);
    80     CachedResourceHandle<CachedRawResource> requestIcon(CachedResourceRequest&&);
    81     CachedResourceHandle<CachedResource> requestBeaconResource(CachedResourceRequest&&);
    82     CachedResourceHandle<CachedRawResource> requestRawResource(CachedResourceRequest&&);
    83     CachedResourceHandle<CachedRawResource> requestMainResource(CachedResourceRequest&&);
    84     CachedResourceHandle<CachedSVGDocument> requestSVGDocument(CachedResourceRequest&&);
     75    CachedResourceHandle<CachedImage> requestImage(CachedResourceRequest&&, ResourceError* = nullptr);
     76    CachedResourceHandle<CachedCSSStyleSheet> requestCSSStyleSheet(CachedResourceRequest&&, ResourceError* = nullptr);
     77    CachedResourceHandle<CachedCSSStyleSheet> requestUserCSSStyleSheet(CachedResourceRequest&&, ResourceError* = nullptr);
     78    CachedResourceHandle<CachedScript> requestScript(CachedResourceRequest&&, ResourceError* = nullptr);
     79    CachedResourceHandle<CachedFont> requestFont(CachedResourceRequest&&, bool isSVG, ResourceError* = nullptr);
     80    CachedResourceHandle<CachedRawResource> requestMedia(CachedResourceRequest&&, ResourceError* = nullptr);
     81    CachedResourceHandle<CachedRawResource> requestIcon(CachedResourceRequest&&, ResourceError* = nullptr);
     82    CachedResourceHandle<CachedResource> requestBeaconResource(CachedResourceRequest&&, ResourceError* = nullptr);
     83    CachedResourceHandle<CachedRawResource> requestRawResource(CachedResourceRequest&&, ResourceError* = nullptr);
     84    CachedResourceHandle<CachedRawResource> requestMainResource(CachedResourceRequest&&, ResourceError* = nullptr);
     85    CachedResourceHandle<CachedSVGDocument> requestSVGDocument(CachedResourceRequest&&, ResourceError* = nullptr);
    8586#if ENABLE(XSLT)
    86     CachedResourceHandle<CachedXSLStyleSheet> requestXSLStyleSheet(CachedResourceRequest&&);
     87    CachedResourceHandle<CachedXSLStyleSheet> requestXSLStyleSheet(CachedResourceRequest&&, ResourceError* = nullptr);
    8788#endif
    8889#if ENABLE(LINK_PREFETCH)
    89     CachedResourceHandle<CachedResource> requestLinkResource(CachedResource::Type, CachedResourceRequest&&);
     90    CachedResourceHandle<CachedResource> requestLinkResource(CachedResource::Type, CachedResourceRequest&&, ResourceError* = nullptr);
    9091#endif
    9192#if ENABLE(VIDEO_TRACK)
    92     CachedResourceHandle<CachedTextTrack> requestTextTrack(CachedResourceRequest&&);
     93    CachedResourceHandle<CachedTextTrack> requestTextTrack(CachedResourceRequest&&, ResourceError* = nullptr);
    9394#endif
    9495
     
    147148    bool isAlwaysOnLoggingAllowed() const;
    148149
     150    KeepaliveRequestTracker& keepaliveRequestTracker() { return m_keepaliveRequestTracker; }
     151
    149152private:
    150153    explicit CachedResourceLoader(DocumentLoader*);
     
    153156    enum class DeferOption { NoDefer, DeferredByClient };
    154157
    155     CachedResourceHandle<CachedResource> requestResource(CachedResource::Type, CachedResourceRequest&&, ForPreload = ForPreload::No, DeferOption = DeferOption::NoDefer);
     158    CachedResourceHandle<CachedResource> requestResource(CachedResource::Type, CachedResourceRequest&&, ResourceError* = nullptr, ForPreload = ForPreload::No, DeferOption = DeferOption::NoDefer);
    156159    CachedResourceHandle<CachedResource> revalidateResource(CachedResourceRequest&&, CachedResource&);
    157160    CachedResourceHandle<CachedResource> loadResource(CachedResource::Type, CachedResourceRequest&&);
     
    194197
    195198    ResourceTimingInformation m_resourceTimingInfo;
     199    KeepaliveRequestTracker m_keepaliveRequestTracker;
    196200
    197201    // 29 bits left
  • trunk/Source/WebCore/platform/network/FormData.cpp

    r220707 r220751  
    3434#include "Page.h"
    3535#include "TextEncoding.h"
     36#include "ThreadableBlobRegistry.h"
    3637
    3738namespace WebCore {
     
    125126}
    126127
     128uint64_t FormDataElement::lengthInBytes() const
     129{
     130    switch (m_type) {
     131    case Type::Data:
     132        return m_data.size();
     133    case Type::EncodedFile: {
     134        if (m_fileLength != BlobDataItem::toEndOfFile)
     135            return m_fileLength;
     136        long long fileSize;
     137        if (getFileSize(m_shouldGenerateFile ? m_generatedFilename : m_filename, fileSize))
     138            return fileSize;
     139        return 0;
     140    }
     141    case Type::EncodedBlob:
     142        return blobRegistry().blobSize(m_url);
     143    }
     144    ASSERT_NOT_REACHED();
     145    return 0;
     146}
     147
    127148FormDataElement FormDataElement::isolatedCopy() const
    128149{
     
    147168{
    148169    m_elements.append(FormDataElement(filename, 0, BlobDataItem::toEndOfFile, invalidFileTime(), shouldGenerateFile));
     170    m_lengthInBytes = std::nullopt;
    149171}
    150172
     
    152174{
    153175    m_elements.append(FormDataElement(filename, start, length, expectedModificationTime, shouldGenerateFile));
     176    m_lengthInBytes = std::nullopt;
    154177}
    155178
     
    157180{
    158181    m_elements.append(FormDataElement(blobURL));
     182    m_lengthInBytes = std::nullopt;
    159183}
    160184
     
    245269char* FormData::expandDataStore(size_t size)
    246270{
     271    m_lengthInBytes = std::nullopt;
    247272    if (m_elements.isEmpty() || m_elements.last().m_type != FormDataElement::Type::Data)
    248273        m_elements.append(FormDataElement());
     
    387412}
    388413
     414uint64_t FormData::lengthInBytes() const
     415{
     416    if (!m_lengthInBytes) {
     417        uint64_t length = 0;
     418        for (auto& element : m_elements)
     419            length += element.lengthInBytes();
     420        m_lengthInBytes = length;
     421    }
     422    return *m_lengthInBytes;
     423}
     424
    389425} // namespace WebCore
  • trunk/Source/WebCore/platform/network/FormData.h

    r220707 r220751  
    7070    }
    7171
     72    uint64_t lengthInBytes() const;
     73
    7274    FormDataElement isolatedCopy() const;
    7375
     
    255257    }
    256258
     259    uint64_t lengthInBytes() const;
     260
    257261private:
    258262    FormData();
     
    270274    Vector<char> m_boundary;
    271275    bool m_containsPasswordData { false };
     276    mutable std::optional<uint64_t> m_lengthInBytes;
    272277};
    273278
Note: See TracChangeset for help on using the changeset viewer.