⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 244700 in webkit


Ignore:
Timestamp:
Apr 26, 2019, 11:10:17 AM (7 years ago)
Author:
youenn@apple.com
Message:

Use normal loading path for ping loads
https://bugs.webkit.org/show_bug.cgi?id=196807

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

  • web-platform-tests/beacon/headers/header-content-type-expected.txt:

Source/WebCore:

Make use of regular code path for ping loads and beacon.
This is done conditionally on KeepAlive flag.
The benefits are a single loading code path and service worker interception.

For that purpose, introduce a LoaderStrategy switch based on KeepAlive runtime flag.
This switch is used to use ping loads when keepAlive is set or regular loads.
In case of regular loads, the keepAlive flag should be used to extend the lifetime of the load.

Migrate ping loads to use CachedResourceLoader instead of PingLoad.
For that purpose, introduce a new Ping CachedResource type.

Covered by existing tests.

  • Modules/beacon/NavigatorBeacon.cpp:

(WebCore::NavigatorBeacon::sendBeacon):

  • inspector/agents/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::inspectorResourceType):

  • loader/LinkLoader.cpp:

(WebCore::createLinkPreloadResourceClient):

  • loader/LoaderStrategy.h:
  • loader/PingLoader.cpp:

(WebCore::PingLoader::loadImage):
(WebCore::PingLoader::sendPing):
(WebCore::PingLoader::sendViolationReport):
(WebCore::PingLoader::startPingLoad):

  • loader/PingLoader.h:
  • loader/ResourceLoadInfo.cpp:

(WebCore::toResourceType):

  • loader/SubresourceLoader.cpp:

(WebCore::logResourceLoaded):

  • loader/cache/CachedResource.cpp:

(WebCore::CachedResource::defaultPriorityForResourceType):
(WebCore::CachedResource::load):
(WebCore::CachedResource::cancelLoad):

  • loader/cache/CachedResource.h:

(WebCore::CachedResource::shouldUsePingLoad):
(WebCore::CachedResource::isMainOrMediaOrIconOrRawResource const):

  • loader/cache/CachedResourceLoader.cpp:

(WebCore::createResource):
(WebCore::CachedResourceLoader::requestPingResource):
(WebCore::contentTypeFromResourceType):
(WebCore::CachedResourceLoader::checkInsecureContent const):
(WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
(WebCore::CachedResourceLoader::canRequest):
(WebCore::isResourceSuitableForDirectReuse):
(WebCore::destinationForType):

  • loader/cache/CachedResourceLoader.h:

Source/WebKit:

In case a NetworkResourceLoader has the keepAlive option we do the following:

  • Always use NetworkLoadChecker as we might need it to do checks after the Web context is gone.
  • In case of aborting a KeepAlive loader, remove it from NetworkConnectionToWebProcess map

and add it to a kept-alive NetworkSession load set. The loader is only kept alive if it
has not yet received a response. Mark the loader as kept-alive.

  • In case loader is kept-alive, cancel the load as soon as a response is gathered.
  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::transferKeptAliveLoad):

  • NetworkProcess/NetworkConnectionToWebProcess.h:
  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::addKeptAliveLoad):
(WebKit::NetworkProcess::removeKeptAliveLoad):

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/NetworkResourceLoadMap.cpp:

(WebKit::NetworkResourceLoadMap::remove):
(WebKit::NetworkResourceLoadMap::take):

  • NetworkProcess/NetworkResourceLoadMap.h:
  • NetworkProcess/NetworkResourceLoader.cpp:

(WebKit::m_shouldCaptureExtraNetworkLoadMetrics):
(WebKit::NetworkResourceLoader::cleanup):
(WebKit::NetworkResourceLoader::abort):
(WebKit::NetworkResourceLoader::didReceiveResponse):
(WebKit::NetworkResourceLoader::continueWillSendRedirectedRequest):

  • NetworkProcess/NetworkResourceLoader.h:
  • WebProcess/Network/WebLoaderStrategy.cpp:

(WebKit::maximumBufferingTime):
(WebKit::WebLoaderStrategy::usePingLoad const):

  • WebProcess/Network/WebLoaderStrategy.h:

LayoutTests:

  • TestExpectations:
  • http/tests/blink/sendbeacon/beacon-cross-origin.https-expected.txt:
  • http/tests/blink/sendbeacon/connect-src-beacon-allowed.html:
  • http/tests/security/contentSecurityPolicy/connect-src-beacon-allowed.html:
  • http/tests/security/contentSecurityPolicy/report-only-connect-src-beacon-redirect-blocked-expected.txt:
  • http/tests/security/contentSecurityPolicy/report-only-connect-src-beacon-redirect-blocked.php:
  • http/tests/security/contentSecurityPolicy/user-style-sheet-font-crasher-expected.txt:
  • http/wpt/beacon/beacon-async-error-logging-expected.txt:
  • http/wpt/beacon/beacon-async-error-logging.html:
  • http/wpt/beacon/connect-src-beacon-redirect-blocked.sub-expected.txt:
  • http/wpt/beacon/contentextensions/beacon-redirect-blocked-expected.txt:
  • http/wpt/beacon/resources/beacon-preflight.py:

(respondToCORSPreflight):
(main):

  • platform/wk2/http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-css-in-iframe-report-only-expected.txt:
Location:
trunk
Files:
38 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r244699 r244700  
     12019-04-26  Youenn Fablet  <youenn@apple.com>
     2
     3        Use normal loading path for ping loads
     4        https://bugs.webkit.org/show_bug.cgi?id=196807
     5
     6        Reviewed by Alex Christensen.
     7
     8        * TestExpectations:
     9        * http/tests/blink/sendbeacon/beacon-cross-origin.https-expected.txt:
     10        * http/tests/blink/sendbeacon/connect-src-beacon-allowed.html:
     11        * http/tests/security/contentSecurityPolicy/connect-src-beacon-allowed.html:
     12        * http/tests/security/contentSecurityPolicy/report-only-connect-src-beacon-redirect-blocked-expected.txt:
     13        * http/tests/security/contentSecurityPolicy/report-only-connect-src-beacon-redirect-blocked.php:
     14        * http/tests/security/contentSecurityPolicy/user-style-sheet-font-crasher-expected.txt:
     15        * http/wpt/beacon/beacon-async-error-logging-expected.txt:
     16        * http/wpt/beacon/beacon-async-error-logging.html:
     17        * http/wpt/beacon/connect-src-beacon-redirect-blocked.sub-expected.txt:
     18        * http/wpt/beacon/contentextensions/beacon-redirect-blocked-expected.txt:
     19        * http/wpt/beacon/resources/beacon-preflight.py:
     20        (respondToCORSPreflight):
     21        (main):
     22        * platform/wk2/http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-css-in-iframe-report-only-expected.txt:
     23
    1242019-04-26  Youenn Fablet  <youenn@apple.com>
    225
  • trunk/LayoutTests/TestExpectations

    r244393 r244700  
    17871787imported/w3c/web-platform-tests/fetch/nosniff [ DumpJSConsoleLogInStdErr ]
    17881788imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/sandbox-ascii-case-insensitive.html [ DumpJSConsoleLogInStdErr ]
     1789
     1790http/wpt/beacon/cors/cors-preflight-blob-failure.html [ DumpJSConsoleLogInStdErr ]
     1791http/wpt/beacon/cors/cors-preflight-blob-success.html [ DumpJSConsoleLogInStdErr ]
     1792http/wpt/beacon/cors/cors-preflight-cookie.html [ DumpJSConsoleLogInStdErr ]
     1793http/wpt/beacon/cors/cors-preflight-redirect-failure.html [ DumpJSConsoleLogInStdErr ]
     1794http/wpt/beacon/cors/cors-preflight-redirect-from-crossorigin-to-sameorigin.html [ DumpJSConsoleLogInStdErr ]
     1795http/wpt/beacon/cors/cors-preflight-redirect-success.html [ DumpJSConsoleLogInStdErr ]
     1796http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html [ DumpJSConsoleLogInStdErr ]
     1797
     1798http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-css-in-iframe-report-only.html [ Pass Failure ]
    17891799
    17901800# Imported css-text test suite from WPT
  • trunk/LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin.https-expected.txt

    r220121 r244700  
     1Blocked access to external URL http://example.test:8000/blink/sendbeacon/resources/save-beacon.php?name=cross-origin
     2CONSOLE MESSAGE: line 1: Beacon API cannot load http://example.test:8000/blink/sendbeacon/resources/save-beacon.php?name=cross-origin due to access control checks.
    13Verify navigator.sendBeacon() mixed content checking.
    24
     
    46
    57
    6 FAIL navigator.sendBeacon("http://example.test:8000/blink/sendbeacon/resources/save-beacon.php?name=cross-origin", "CrossOrigin"); should be false. Was true.
     8PASS navigator.sendBeacon("http://example.test:8000/blink/sendbeacon/resources/save-beacon.php?name=cross-origin", "CrossOrigin"); is false
    79PASS successfullyParsed is true
    8 Some tests failed.
    910
    1011TEST COMPLETE
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/user-style-sheet-font-crasher-expected.txt

    r198591 r244700  
    11CONSOLE MESSAGE: Refused to load http://127.0.0.1:8000/security/contentSecurityPolicy/example_font.woff because it does not appear in the font-src directive of the Content Security Policy.
     2Blocked access to external URL http://webkit.org/report
    23CONSOLE MESSAGE: Refused to load http://127.0.0.1:8000/security/contentSecurityPolicy/example_font.woff because it does not appear in the font-src directive of the Content Security Policy.
     4Blocked access to external URL http://webkit.org/report
    35The iframe below triggers a violation report creating the initial empty document. It should not crash the web process.
    46
  • trunk/LayoutTests/http/wpt/beacon/beacon-async-error-logging-expected.txt

    r220946 r244700  
    1 CONSOLE MESSAGE: Beacon API cannot load http://invalid.localhost/. A server with the specified hostname could not be found.
     1CONSOLE MESSAGE: Beacon API cannot load http://localhost:1/. Not allowed to use restricted network port
    22
    33PASS Should log an error message in the console
  • trunk/LayoutTests/http/wpt/beacon/beacon-async-error-logging.html

    r227712 r244700  
    1515            setTimeout(function() { t.done(); }, 500);
    1616        }
    17         let invalidHost = "http://invalid.localhost";
    18         assert_true(navigator.sendBeacon(invalidHost, 'test'), "sendBeacon should return true");
     17        let hostWithInvalidPort = "http://localhost:1";
     18        assert_true(navigator.sendBeacon(hostWithInvalidPort, 'test'), "sendBeacon should return true");
    1919    }, "Should log an error message in the console");
    2020</script>
  • trunk/LayoutTests/http/wpt/beacon/connect-src-beacon-redirect-blocked.sub-expected.txt

    r232032 r244700  
     1CONSOLE MESSAGE: Refused to connect to http://127.0.0.1:8800/WebKit/beacon/resources/beacon-preflight.py?allowCors=1&cmd=put&id=2539e883-7dfb-4dde-a227-a41c670d5fe1&redirect_status=307&location=http%3A%2F%2F127.0.0.1%3A8800%2FWebKit%2Fbeacon%2Fresources%2Fbeacon-preflight.py%3FallowCors%3D1%26cmd%3Dput%26id%3D2539e883-7dfb-4dde-a227-a41c670d5fe1&count=1 because it does not appear in the connect-src directive of the Content Security Policy.
     2CONSOLE MESSAGE: Blocked by Content Security Policy.
    13CONSOLE MESSAGE: Beacon API cannot load http://127.0.0.1:8800/WebKit/beacon/resources/beacon-preflight.py?allowCors=1&cmd=put&id=2539e883-7dfb-4dde-a227-a41c670d5fe1&redirect_status=307&location=http%3A%2F%2F127.0.0.1%3A8800%2FWebKit%2Fbeacon%2Fresources%2Fbeacon-preflight.py%3FallowCors%3D1%26cmd%3Dput%26id%3D2539e883-7dfb-4dde-a227-a41c670d5fe1&count=1. Blocked by Content Security Policy.
    24
  • trunk/LayoutTests/http/wpt/beacon/contentextensions/beacon-redirect-blocked-expected.txt

    r220996 r244700  
    1 CONSOLE MESSAGE: Beacon API cannot load http://127.0.0.1:8800/WebKit/beacon/resources/beacon-preflight.py?allowCors=1&cmd=put&id=f470f43c-258c-4c82-b880-ace3bcdb211c&redirect_status=307&location=http%3A%2F%2F127.0.0.1%3A8800%2FWebKit%2Fbeacon%2Fresources%2Fbeacon-preflight.py%3FallowCors%3D1%26cmd%3Dput%26id%3Df470f43c-258c-4c82-b880-ace3bcdb211c&count=1. Blocked by content extension
     1CONSOLE MESSAGE: Content blocker prevented frame displaying http://localhost:8800/WebKit/beacon/contentextensions/beacon-redirect-blocked.html from loading a resource from http://127.0.0.1:8800/WebKit/beacon/resources/beacon-preflight.py?allowCors=1&cmd=put&id=f470f43c-258c-4c82-b880-ace3bcdb211c&redirect_status=307&location=http%3A%2F%2F127.0.0.1%3A8800%2FWebKit%2Fbeacon%2Fresources%2Fbeacon-preflight.py%3FallowCors%3D1%26cmd%3Dput%26id%3Df470f43c-258c-4c82-b880-ace3bcdb211c&count=1
     2CONSOLE MESSAGE: Beacon API cannot load http://localhost:8800/WebKit/beacon/resources/redirect.py?redirect_status=307&location=http%3A%2F%2F127.0.0.1%3A8800%2FWebKit%2Fbeacon%2Fresources%2Fbeacon-preflight.py%3FallowCors%3D1%26cmd%3Dput%26id%3Df470f43c-258c-4c82-b880-ace3bcdb211c. The URL was blocked by a content blocker
    23
    34PASS Content extensions should be able to block beacon redirects
  • trunk/LayoutTests/http/wpt/beacon/resources/beacon-preflight.py

    r220497 r244700  
    22
    33def respondToCORSPreflight(request, response):
     4  headers = [("Content-Type", "text/plain")]
    45  allow_cors = int(request.GET.first("allowCors", 0)) != 0;
    56 
    67  if not allow_cors:
    78    response.set_error(400, "Not allowed")
    8     return "ERROR: Not allowed"
     9    return headers, "ERROR: Not allowed"
    910 
    1011  if not "Access-Control-Request-Method" in request.headers:
    1112    response.set_error(400, "No Access-Control-Request-Method header")
    12     return "ERROR: No access-control-request-method in preflight!"
     13    return headers, "ERROR: No access-control-request-method in preflight!"
    1314 
    14   headers = [("Content-Type", "text/plain")]
    1515  headers.append(("Access-Control-Allow-Origin", request.headers.get("Origin", "*")))
    1616  headers.append(("Access-Control-Allow-Credentials", "true"))
     
    5252
    5353  response.set_error(400, "Bad Command")
    54   return "ERROR: Bad Command!"
     54  return [("Content-Type", "text/plain")], "ERROR: Bad Command!"
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r244689 r244700  
     12019-04-26  Youenn Fablet  <youenn@apple.com>
     2
     3        Use normal loading path for ping loads
     4        https://bugs.webkit.org/show_bug.cgi?id=196807
     5
     6        Reviewed by Alex Christensen.
     7
     8        * web-platform-tests/beacon/headers/header-content-type-expected.txt:
     9
    1102019-04-26  Youenn Fablet  <youenn@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-content-type-expected.txt

    r232641 r244700  
    11
    2 Harness Error (TIMEOUT), message = null
     2PASS Test content-type header for a body string
     3PASS Test content-type header for a body ArrayBufferView
     4PASS Test content-type header for a body ArrayBuffer
     5PASS Test content-type header for a body Blob
     6PASS Test content-type header for a body FormData
     7PASS Test content-type header for a body URLSearchParams
    38
    4 TIMEOUT Test content-type header for a body string Test timed out
    5 NOTRUN Test content-type header for a body ArrayBufferView
    6 NOTRUN Test content-type header for a body ArrayBuffer
    7 NOTRUN Test content-type header for a body Blob
    8 NOTRUN Test content-type header for a body FormData
    9 NOTRUN Test content-type header for a body URLSearchParams
    10 
  • trunk/LayoutTests/platform/wk2/http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-css-in-iframe-report-only-expected.txt

    r231450 r244700  
    99main frame - didHandleOnloadEventsForFrame
    1010frame "<!--frame1-->" - didFinishLoadForFrame
    11 main frame - didFinishLoadForFrame
    1211frame "<!--frame1-->" - didStartProvisionalLoadForFrame
    1312frame "<!--frame1-->" - didCancelClientRedirectForFrame
     
    1615frame "<!--frame1-->" - didHandleOnloadEventsForFrame
    1716frame "<!--frame1-->" - didFinishLoadForFrame
     17main frame - didFinishLoadForFrame
    1818This test loads a secure iframe that loads an insecure stylesheet. We should trigger a mixed content block even though the child frame has a report only CSP block-all-mixed-content directive because an active network attacker can use CSS3 to breach the confidentiality of the HTTPS security origin.
    1919
  • trunk/Source/WebCore/ChangeLog

    r244697 r244700  
     12019-04-26  Youenn Fablet  <youenn@apple.com>
     2
     3        Use normal loading path for ping loads
     4        https://bugs.webkit.org/show_bug.cgi?id=196807
     5
     6        Reviewed by Alex Christensen.
     7
     8        Make use of regular code path for ping loads and beacon.
     9        This is done conditionally on KeepAlive flag.
     10        The benefits are a single loading code path and service worker interception.
     11
     12        For that purpose, introduce a LoaderStrategy switch based on KeepAlive runtime flag.
     13        This switch is used to use ping loads when keepAlive is set or regular loads.
     14        In case of regular loads, the keepAlive flag should be used to extend the lifetime of the load.
     15
     16        Migrate ping loads to use CachedResourceLoader instead of PingLoad.
     17        For that purpose, introduce a new Ping CachedResource type.
     18
     19        Covered by existing tests.
     20
     21        * Modules/beacon/NavigatorBeacon.cpp:
     22        (WebCore::NavigatorBeacon::sendBeacon):
     23        * inspector/agents/InspectorPageAgent.cpp:
     24        (WebCore::InspectorPageAgent::inspectorResourceType):
     25        * loader/LinkLoader.cpp:
     26        (WebCore::createLinkPreloadResourceClient):
     27        * loader/LoaderStrategy.h:
     28        * loader/PingLoader.cpp:
     29        (WebCore::PingLoader::loadImage):
     30        (WebCore::PingLoader::sendPing):
     31        (WebCore::PingLoader::sendViolationReport):
     32        (WebCore::PingLoader::startPingLoad):
     33        * loader/PingLoader.h:
     34        * loader/ResourceLoadInfo.cpp:
     35        (WebCore::toResourceType):
     36        * loader/SubresourceLoader.cpp:
     37        (WebCore::logResourceLoaded):
     38        * loader/cache/CachedResource.cpp:
     39        (WebCore::CachedResource::defaultPriorityForResourceType):
     40        (WebCore::CachedResource::load):
     41        (WebCore::CachedResource::cancelLoad):
     42        * loader/cache/CachedResource.h:
     43        (WebCore::CachedResource::shouldUsePingLoad):
     44        (WebCore::CachedResource::isMainOrMediaOrIconOrRawResource const):
     45        * loader/cache/CachedResourceLoader.cpp:
     46        (WebCore::createResource):
     47        (WebCore::CachedResourceLoader::requestPingResource):
     48        (WebCore::contentTypeFromResourceType):
     49        (WebCore::CachedResourceLoader::checkInsecureContent const):
     50        (WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
     51        (WebCore::CachedResourceLoader::canRequest):
     52        (WebCore::isResourceSuitableForDirectReuse):
     53        (WebCore::destinationForType):
     54        * loader/cache/CachedResourceLoader.h:
     55
    1562019-04-26  Alex Christensen  <achristensen@webkit.org>
    257
  • trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp

    r240014 r244700  
    123123    request.setHTTPMethod("POST"_s);
    124124
    125     FetchOptions options;
     125    ResourceLoaderOptions options;
    126126    options.credentials = FetchOptions::Credentials::Include;
    127127    options.cache = FetchOptions::Cache::NoCache;
    128128    options.keepAlive = true;
     129    options.sendLoadCallbacks = SendCallbackPolicy::SendCallbacks;
     130
    129131    if (body) {
    130132        options.mode = FetchOptions::Mode::Cors;
  • trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp

    r243303 r244700  
    281281        return InspectorPageAgent::ApplicationManifestResource;
    282282#endif
     283    case CachedResource::Type::Ping:
     284        return InspectorPageAgent::PingResource;
    283285    case CachedResource::Type::MediaResource:
    284286    case CachedResource::Type::Icon:
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r244428 r244700  
    164164#endif
    165165    case CachedResource::Type::Beacon:
     166    case CachedResource::Type::Ping:
    166167    case CachedResource::Type::LinkPrefetch:
    167168#if ENABLE(APPLICATION_MANIFEST)
  • trunk/Source/WebCore/loader/LoaderStrategy.h

    r239634 r244700  
    6868    virtual void resumePendingRequests() = 0;
    6969
     70    virtual bool usePingLoad() const { return true; }
    7071    using PingLoadCompletionHandler = WTF::Function<void(const ResourceError&, const ResourceResponse&)>;
    7172    virtual void startPingLoad(Frame&, ResourceRequest&, const HTTPHeaderMap& originalRequestHeaders, const FetchOptions&, ContentSecurityPolicyImposition, PingLoadCompletionHandler&& = { }) = 0;
  • trunk/Source/WebCore/loader/PingLoader.cpp

    r244697 r244700  
    3535#include "PingLoader.h"
    3636
     37#include "CachedResourceLoader.h"
     38#include "CachedResourceRequest.h"
    3739#include "ContentRuleListResults.h"
    3840#include "ContentSecurityPolicy.h"
     
    105107    frame.loader().addExtraFieldsToSubresourceRequest(request);
    106108
    107     startPingLoad(frame, request, WTFMove(originalRequestHeader), ShouldFollowRedirects::Yes, ContentSecurityPolicyImposition::DoPolicyCheck);
     109    startPingLoad(frame, request, WTFMove(originalRequestHeader), ShouldFollowRedirects::Yes, ContentSecurityPolicyImposition::DoPolicyCheck, ReferrerPolicy::EmptyString);
    108110}
    109111
     
    146148    }
    147149
    148     startPingLoad(frame, request, WTFMove(originalRequestHeader), ShouldFollowRedirects::Yes, ContentSecurityPolicyImposition::DoPolicyCheck);
     150    startPingLoad(frame, request, WTFMove(originalRequestHeader), ShouldFollowRedirects::Yes, ContentSecurityPolicyImposition::DoPolicyCheck, request.httpReferrer().isEmpty() ? ReferrerPolicy::NoReferrer : ReferrerPolicy::UnsafeUrl);
    149151}
    150152
     
    187189        request.setHTTPReferrer(referrer);
    188190
    189     startPingLoad(frame, request, WTFMove(originalRequestHeader), ShouldFollowRedirects::No, ContentSecurityPolicyImposition::SkipPolicyCheck);
    190 }
    191 
    192 void PingLoader::startPingLoad(Frame& frame, ResourceRequest& request, HTTPHeaderMap&& originalRequestHeaders, ShouldFollowRedirects shouldFollowRedirects, ContentSecurityPolicyImposition policyCheck)
     191    startPingLoad(frame, request, WTFMove(originalRequestHeader), ShouldFollowRedirects::No, ContentSecurityPolicyImposition::SkipPolicyCheck, ReferrerPolicy::EmptyString);
     192}
     193
     194void PingLoader::startPingLoad(Frame& frame, ResourceRequest& request, HTTPHeaderMap&& originalRequestHeaders, ShouldFollowRedirects shouldFollowRedirects, ContentSecurityPolicyImposition policyCheck, ReferrerPolicy referrerPolicy)
    193195{
    194196    unsigned long identifier = frame.page()->progress().createUniqueIdentifier();
     
    199201    // DocumentLoader.
    200202    bool shouldUseCredentialStorage = frame.loader().client().shouldUseCredentialStorage(frame.loader().activeDocumentLoader(), identifier);
    201     FetchOptions options;
     203    ResourceLoaderOptions options;
    202204    options.credentials = shouldUseCredentialStorage ? FetchOptions::Credentials::Include : FetchOptions::Credentials::Omit;
    203205    options.redirect = shouldFollowRedirects == ShouldFollowRedirects::Yes ? FetchOptions::Redirect::Follow : FetchOptions::Redirect::Error;
    204 
    205     // FIXME: Move ping loads to normal subresource loading to get normal inspector request instrumentation hooks.
    206     InspectorInstrumentation::willSendRequestOfType(&frame, identifier, frame.loader().activeDocumentLoader(), request, InspectorInstrumentation::LoadType::Ping);
    207 
    208     platformStrategies()->loaderStrategy()->startPingLoad(frame, request, WTFMove(originalRequestHeaders), options, policyCheck, [protectedFrame = makeRef(frame), identifier] (const ResourceError& error, const ResourceResponse& response) {
    209         if (!response.isNull())
    210             InspectorInstrumentation::didReceiveResourceResponse(protectedFrame, identifier, protectedFrame->loader().activeDocumentLoader(), response, nullptr);
    211         if (error.isNull()) {
    212             NetworkLoadMetrics emptyMetrics;
    213             InspectorInstrumentation::didFinishLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, emptyMetrics, nullptr);
    214         } else
    215             InspectorInstrumentation::didFailLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, error);
    216     });
    217 }
    218 
    219 }
     206    options.keepAlive = true;
     207    options.contentSecurityPolicyImposition = policyCheck;
     208    options.referrerPolicy = referrerPolicy;
     209    options.sendLoadCallbacks = SendCallbackPolicy::SendCallbacks;
     210    options.cache = FetchOptions::Cache::NoCache;
     211
     212    // FIXME: Deprecate the ping load code path.
     213    if (platformStrategies()->loaderStrategy()->usePingLoad()) {
     214        InspectorInstrumentation::willSendRequestOfType(&frame, identifier, frame.loader().activeDocumentLoader(), request, InspectorInstrumentation::LoadType::Ping);
     215
     216        platformStrategies()->loaderStrategy()->startPingLoad(frame, request, WTFMove(originalRequestHeaders), options, policyCheck, [protectedFrame = makeRef(frame), identifier] (const ResourceError& error, const ResourceResponse& response) {
     217            if (!response.isNull())
     218                InspectorInstrumentation::didReceiveResourceResponse(protectedFrame, identifier, protectedFrame->loader().activeDocumentLoader(), response, nullptr);
     219            if (!error.isNull()) {
     220                InspectorInstrumentation::didFailLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, error);
     221                return;
     222            }
     223            InspectorInstrumentation::didFinishLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, { }, nullptr);
     224        });
     225        return;
     226    }
     227
     228    CachedResourceRequest cachedResourceRequest { ResourceRequest { request }, options };
     229    frame.document()->cachedResourceLoader().requestPingResource(WTFMove(cachedResourceRequest));
     230}
     231
     232}
  • trunk/Source/WebCore/loader/PingLoader.h

    r239634 r244700  
    3333#pragma once
    3434
     35#include "ReferrerPolicy.h"
    3536#include <wtf/Forward.h>
    3637#include <wtf/Ref.h>
     
    5859private:
    5960    enum class ShouldFollowRedirects { No, Yes };
    60     static void startPingLoad(Frame&, ResourceRequest&, HTTPHeaderMap&& originalRequestHeaders, ShouldFollowRedirects, ContentSecurityPolicyImposition);
     61    static void startPingLoad(Frame&, ResourceRequest&, HTTPHeaderMap&& originalRequestHeaders, ShouldFollowRedirects, ContentSecurityPolicyImposition, ReferrerPolicy);
    6162};
    6263
  • trunk/Source/WebCore/loader/ResourceLoadInfo.cpp

    r244695 r244700  
    6363
    6464    case CachedResource::Type::Beacon:
     65    case CachedResource::Type::Ping:
    6566    case CachedResource::Type::Icon:
    6667    case CachedResource::Type::RawResource:
  • trunk/Source/WebCore/loader/SubresourceLoader.cpp

    r244695 r244700  
    519519        break;
    520520    case CachedResource::Type::Beacon:
    521         ASSERT_NOT_REACHED();
    522         break;
     521    case CachedResource::Type::Ping:
    523522    case CachedResource::Type::MediaResource:
    524523    case CachedResource::Type::Icon:
     
    688687    LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string().latin1().data());
    689688
    690     if (m_frame->document() && error.isAccessControl())
     689    if (m_frame->document() && error.isAccessControl() && m_resource->type() != CachedResource::Type::Ping)
    691690        m_frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, error.localizedDescription());
    692 
    693691
    694692    Ref<SubresourceLoader> protectedThis(*this);
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r241121 r244700  
    9090        return ResourceLoadPriority::Low;
    9191    case Type::Beacon:
     92    case Type::Ping:
    9293        return ResourceLoadPriority::VeryLow;
    9394    case Type::LinkPrefetch:
     
    272273    }
    273274
    274     if (m_options.keepAlive) {
    275         if (!cachedResourceLoader.keepaliveRequestTracker().tryRegisterRequest(*this)) {
    276             setResourceError({ errorDomainWebKitInternal, 0, request.url(), "Reached maximum amount of queued data of 64Kb for keepalive requests"_s, ResourceError::Type::AccessControl });
    277             failBeforeStarting();
    278             return;
    279         }
    280         // FIXME: We should not special-case Beacon here.
    281         if (shouldUsePingLoad(type())) {
    282             ASSERT(m_originalRequest);
    283             CachedResourceHandle<CachedResource> protectedThis(this);
    284 
    285             // FIXME: Move beacon loads to normal subresource loading to get normal inspector request instrumentation hooks.
    286             unsigned long identifier = frame.page()->progress().createUniqueIdentifier();
    287             InspectorInstrumentation::willSendRequestOfType(&frame, identifier, frameLoader.activeDocumentLoader(), request, InspectorInstrumentation::LoadType::Beacon);
    288 
    289             platformStrategies()->loaderStrategy()->startPingLoad(frame, request, m_originalRequest->httpHeaderFields(), m_options, m_options.contentSecurityPolicyImposition, [this, protectedThis = WTFMove(protectedThis), protectedFrame = makeRef(frame), identifier] (const ResourceError& error, const ResourceResponse& response) {
    290                 if (!response.isNull())
    291                     InspectorInstrumentation::didReceiveResourceResponse(protectedFrame, identifier, protectedFrame->loader().activeDocumentLoader(), response, nullptr);
    292                 if (error.isNull()) {
    293                     finishLoading(nullptr);
    294                     NetworkLoadMetrics emptyMetrics;
    295                     InspectorInstrumentation::didFinishLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, emptyMetrics, nullptr);
    296                 } else {
    297                     setResourceError(error);
    298                     this->error(LoadError);
    299                     InspectorInstrumentation::didFailLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, error);
    300                 }
    301             });
    302             return;
    303         }
     275    if (m_options.keepAlive && type() != Type::Ping && !cachedResourceLoader.keepaliveRequestTracker().tryRegisterRequest(*this)) {
     276        setResourceError({ errorDomainWebKitInternal, 0, request.url(), "Reached maximum amount of queued data of 64Kb for keepalive requests"_s, ResourceError::Type::AccessControl });
     277        failBeforeStarting();
     278        return;
     279    }
     280
     281    // FIXME: Deprecate that code path.
     282    if (m_options.keepAlive && shouldUsePingLoad(type()) && platformStrategies()->loaderStrategy()->usePingLoad()) {
     283        ASSERT(m_originalRequest);
     284        CachedResourceHandle<CachedResource> protectedThis(this);
     285
     286        unsigned long identifier = frame.page()->progress().createUniqueIdentifier();
     287        InspectorInstrumentation::willSendRequestOfType(&frame, identifier, frameLoader.activeDocumentLoader(), request, InspectorInstrumentation::LoadType::Beacon);
     288
     289        platformStrategies()->loaderStrategy()->startPingLoad(frame, request, m_originalRequest->httpHeaderFields(), m_options, m_options.contentSecurityPolicyImposition, [this, protectedThis = WTFMove(protectedThis), protectedFrame = makeRef(frame), identifier] (const ResourceError& error, const ResourceResponse& response) {
     290            if (!response.isNull())
     291                InspectorInstrumentation::didReceiveResourceResponse(protectedFrame, identifier, protectedFrame->loader().activeDocumentLoader(), response, nullptr);
     292            if (!error.isNull()) {
     293                setResourceError(error);
     294                this->error(LoadError);
     295                InspectorInstrumentation::didFailLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, error);
     296                return;
     297            }
     298            finishLoading(nullptr);
     299            NetworkLoadMetrics emptyMetrics;
     300            InspectorInstrumentation::didFinishLoading(protectedFrame.ptr(), protectedFrame->loader().activeDocumentLoader(), identifier, emptyMetrics, nullptr);
     301        });
     302        return;
    304303    }
    305304
     
    385384        return;
    386385
    387     setStatus(LoadError);
     386    auto* documentLoader = (m_loader && m_loader->frame()) ? m_loader->frame()->loader().activeDocumentLoader() : nullptr;
     387    if (m_options.keepAlive && (!documentLoader || documentLoader->isStopping()))
     388        m_error = { };
     389    else
     390        setStatus(LoadError);
     391
    388392    setLoading(false);
    389393    checkNotify();
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r241121 r244700  
    7575        Icon,
    7676        Beacon,
     77        Ping,
    7778        SVGDocumentResource
    7879#if ENABLE(XSLT)
     
    123124    long long expectedContentLength() const { return m_response.expectedContentLength(); }
    124125
    125     static bool shouldUsePingLoad(Type type) { return type == Type::Beacon; }
     126    static bool shouldUsePingLoad(Type type) { return type == Type::Beacon || type == Type::Ping; }
    126127
    127128    ResourceLoadPriority loadPriority() const { return m_loadPriority; }
     
    169170    bool isImage() const { return type() == Type::ImageResource; }
    170171    // FIXME: CachedRawResource could be a main resource, an audio/video resource, or a raw XHR/icon resource.
    171     bool isMainOrMediaOrIconOrRawResource() const { return type() == Type::MainResource || type() == Type::MediaResource || type() == Type::Icon || type() == Type::RawResource || type() == Type::Beacon; }
     172    bool isMainOrMediaOrIconOrRawResource() const { return type() == Type::MainResource || type() == Type::MediaResource || type() == Type::Icon || type() == Type::RawResource || type() == Type::Beacon || type() == Type::Ping; }
    172173
    173174    // Whether this request should impact request counting and delay window.onload.
     
    177178            || type() == Type::MainResource
    178179            || type() == Type::LinkPrefetch
     180            || type() == Type::Beacon
     181            || type() == Type::Ping
    179182            || type() == Type::Icon
    180183            || type() == Type::RawResource;
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r244695 r244700  
    121121        return new CachedFont(WTFMove(request), sessionID, cookieJar);
    122122    case CachedResource::Type::Beacon:
     123    case CachedResource::Type::Ping:
    123124    case CachedResource::Type::MediaResource:
    124125    case CachedResource::Type::RawResource:
     
    309310}
    310311
     312ResourceErrorOr<CachedResourceHandle<CachedRawResource>> CachedResourceLoader::requestPingResource(CachedResourceRequest&& request)
     313{
     314    ASSERT(request.options().destination == FetchOptions::Destination::EmptyString);
     315    return castCachedResourceTo<CachedRawResource>(requestResource(CachedResource::Type::Ping, WTFMove(request)));
     316}
     317
    311318ResourceErrorOr<CachedResourceHandle<CachedRawResource>> CachedResourceLoader::requestMainResource(CachedResourceRequest&& request)
    312319{
     
    342349
    343350    case CachedResource::Type::Beacon:
     351    case CachedResource::Type::Ping:
    344352    case CachedResource::Type::RawResource:
    345353    case CachedResource::Type::Icon:
     
    413421    case CachedResource::Type::MainResource:
    414422    case CachedResource::Type::Beacon:
     423    case CachedResource::Type::Ping:
    415424    case CachedResource::Type::LinkPrefetch:
    416425        // Prefetch cannot affect the current document.
     
    464473        break;
    465474    case CachedResource::Type::Beacon:
     475    case CachedResource::Type::Ping:
    466476    case CachedResource::Type::RawResource:
    467477        return true;
     
    502512    }
    503513
    504     if (options.mode == FetchOptions::Mode::NoCors && options.redirect != FetchOptions::Redirect::Follow) {
     514    if (options.mode == FetchOptions::Mode::NoCors && options.redirect != FetchOptions::Redirect::Follow && type != CachedResource::Type::Ping) {
    505515        ASSERT(type != CachedResource::Type::MainResource);
    506516        frame()->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "No-Cors mode requires follow redirect mode"_s);
     
    670680        return false;
    671681
    672     if (resource.type() == CachedResource::Type::Beacon)
     682    if (resource.type() == CachedResource::Type::Beacon || resource.type() == CachedResource::Type::Ping)
    673683        return false;
    674684
     
    763773#endif
    764774    case CachedResource::Type::Beacon:
     775    case CachedResource::Type::Ping:
    765776    case CachedResource::Type::LinkPrefetch:
    766777    case CachedResource::Type::RawResource:
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.h

    r243459 r244700  
    8888    ResourceErrorOr<CachedResourceHandle<CachedRawResource>> requestIcon(CachedResourceRequest&&);
    8989    ResourceErrorOr<CachedResourceHandle<CachedRawResource>> requestBeaconResource(CachedResourceRequest&&);
     90    ResourceErrorOr<CachedResourceHandle<CachedRawResource>> requestPingResource(CachedResourceRequest&&);
    9091    ResourceErrorOr<CachedResourceHandle<CachedRawResource>> requestMainResource(CachedResourceRequest&&);
    9192    ResourceErrorOr<CachedResourceHandle<CachedSVGDocument>> requestSVGDocument(CachedResourceRequest&&);
  • trunk/Source/WebKit/ChangeLog

    r244696 r244700  
     12019-04-26  Youenn Fablet  <youenn@apple.com>
     2
     3        Use normal loading path for ping loads
     4        https://bugs.webkit.org/show_bug.cgi?id=196807
     5
     6        Reviewed by Alex Christensen.
     7
     8        In case a NetworkResourceLoader has the keepAlive option we do the following:
     9        - Always use NetworkLoadChecker as we might need it to do checks after the Web context is gone.
     10        - In case of aborting a KeepAlive loader, remove it from NetworkConnectionToWebProcess map
     11        and add it to a kept-alive NetworkSession load set. The loader is only kept alive if it
     12        has not yet received a response. Mark the loader as kept-alive.
     13        - In case loader is kept-alive, cancel the load as soon as a response is gathered.
     14
     15        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     16        (WebKit::NetworkConnectionToWebProcess::transferKeptAliveLoad):
     17        * NetworkProcess/NetworkConnectionToWebProcess.h:
     18        * NetworkProcess/NetworkProcess.cpp:
     19        (WebKit::NetworkProcess::addKeptAliveLoad):
     20        (WebKit::NetworkProcess::removeKeptAliveLoad):
     21        * NetworkProcess/NetworkProcess.h:
     22        * NetworkProcess/NetworkResourceLoadMap.cpp:
     23        (WebKit::NetworkResourceLoadMap::remove):
     24        (WebKit::NetworkResourceLoadMap::take):
     25        * NetworkProcess/NetworkResourceLoadMap.h:
     26        * NetworkProcess/NetworkResourceLoader.cpp:
     27        (WebKit::m_shouldCaptureExtraNetworkLoadMetrics):
     28        (WebKit::NetworkResourceLoader::cleanup):
     29        (WebKit::NetworkResourceLoader::abort):
     30        (WebKit::NetworkResourceLoader::didReceiveResponse):
     31        (WebKit::NetworkResourceLoader::continueWillSendRedirectedRequest):
     32        * NetworkProcess/NetworkResourceLoader.h:
     33        * WebProcess/Network/WebLoaderStrategy.cpp:
     34        (WebKit::maximumBufferingTime):
     35        (WebKit::WebLoaderStrategy::usePingLoad const):
     36        * WebProcess/Network/WebLoaderStrategy.h:
     37
    1382019-04-26  Alex Christensen  <achristensen@webkit.org>
    239
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r243671 r244700  
    112112    RELEASE_ASSERT(loader.identifier());
    113113    RELEASE_ASSERT(RunLoop::isMain());
     114
     115    if (loader.isKeptAlive()) {
     116        networkProcess().removeKeptAliveLoad(loader);
     117        return;
     118    }
     119
    114120    ASSERT(m_networkResourceLoaders.get(loader.identifier()) == &loader);
    115 
    116121    m_networkResourceLoaders.remove(loader.identifier());
     122}
     123
     124void NetworkConnectionToWebProcess::transferKeptAliveLoad(NetworkResourceLoader& loader)
     125{
     126    RELEASE_ASSERT(RunLoop::isMain());
     127    ASSERT(loader.isKeptAlive());
     128    ASSERT(m_networkResourceLoaders.get(loader.identifier()) == &loader);
     129    if (auto takenLoader = m_networkResourceLoaders.take(loader.identifier()))
     130        m_networkProcess->addKeptAliveLoad(takenLoader.releaseNonNull());
    117131}
    118132
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h

    r243671 r244700  
    8383
    8484    void didCleanupResourceLoader(NetworkResourceLoader&);
     85    void transferKeptAliveLoad(NetworkResourceLoader&);
    8586    void setOnLineState(bool);
    8687
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r244687 r244700  
    25752575}
    25762576
     2577void NetworkProcess::addKeptAliveLoad(Ref<NetworkResourceLoader>&& loader)
     2578{
     2579    if (auto session = m_networkSessions.get(loader->sessionID()))
     2580        session->addKeptAliveLoad(WTFMove(loader));
     2581}
     2582
     2583void NetworkProcess::removeKeptAliveLoad(NetworkResourceLoader& loader)
     2584{
     2585    if (auto session = m_networkSessions.get(loader.sessionID()))
     2586        session->removeKeptAliveLoad(loader);
     2587}
     2588
    25772589} // namespace WebKit
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r244659 r244700  
    9393class NetworkProcessSupplement;
    9494class NetworkProximityManager;
     95class NetworkResourceLoader;
    9596class WebSWServerConnection;
    9697class WebSWServerToContextConnection;
     
    335336    WebCore::StorageQuotaManager& storageQuotaManager(PAL::SessionID, const WebCore::ClientOrigin&);
    336337
     338    void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
     339    void removeKeptAliveLoad(NetworkResourceLoader&);
     340
    337341private:
    338342    void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadMap.cpp

    r244225 r244700  
    4747bool NetworkResourceLoadMap::remove(ResourceLoadIdentifier identifier)
    4848{
     49    return !!take(identifier);
     50}
     51
     52RefPtr<NetworkResourceLoader> NetworkResourceLoadMap::take(ResourceLoadIdentifier identifier)
     53{
    4954    auto loader = m_loaders.take(identifier);
    5055    if (!loader)
    51         return false;
     56        return nullptr;
    5257
    5358    if ((*loader)->originalRequest().hasUpload()) {
     
    5762    }
    5863
    59     return true;
     64    return WTFMove(*loader);
    6065}
    6166
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadMap.h

    r244225 r244700  
    5757    NetworkResourceLoader* get(ResourceLoadIdentifier) const;
    5858    bool remove(ResourceLoadIdentifier);
     59    RefPtr<NetworkResourceLoader> take(ResourceLoadIdentifier);
    5960
    6061private:
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp

    r244589 r244700  
    107107    ASSERT((m_parameters.webPageID && m_parameters.webFrameID) || m_parameters.clientCredentialPolicy == ClientCredentialPolicy::CannotAskClientForCredentials);
    108108
    109     if (synchronousReply || parameters.shouldRestrictHTTPResponseAccess) {
     109    if (synchronousReply || parameters.shouldRestrictHTTPResponseAccess || parameters.options.keepAlive) {
    110110        NetworkLoadChecker::LoadType requestLoadType = isMainFrameLoad() ? NetworkLoadChecker::LoadType::MainFrame : NetworkLoadChecker::LoadType::Other;
    111111        m_networkLoadChecker = std::make_unique<NetworkLoadChecker>(connection.networkProcess(), FetchOptions { m_parameters.options }, m_parameters.sessionID, m_parameters.webPageID, m_parameters.webFrameID, HTTPHeaderMap { m_parameters.originalRequestHeaders }, URL { m_parameters.request.url() }, m_parameters.sourceOrigin.copyRef(), m_parameters.preflightPolicy, originalRequest().httpReferrer(), m_parameters.isHTTPSUpgradeEnabled, shouldCaptureExtraNetworkLoadMetrics(), requestLoadType);
     
    334334        m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier);
    335335
     336    if (m_parameters.options.keepAlive && m_response.isNull() && !m_isKeptAlive) {
     337        m_isKeptAlive = true;
     338        m_connection->transferKeptAliveLoad(*this);
     339        return;
     340    }
     341
    336342    if (m_networkLoad) {
    337343        if (canUseCache(m_networkLoad->currentRequest())) {
     
    468474    bool willWaitForContinueDidReceiveResponse = isMainResource();
    469475    send(Messages::WebResourceLoader::DidReceiveResponse { response, willWaitForContinueDidReceiveResponse });
    470     if (willWaitForContinueDidReceiveResponse)
     476
     477    if (willWaitForContinueDidReceiveResponse) {
    471478        m_responseCompletionHandler = WTFMove(completionHandler);
    472     else
    473         completionHandler(PolicyAction::Use);
     479        return;
     480    }
     481
     482    if (m_isKeptAlive) {
     483        m_responseCompletionHandler = WTFMove(completionHandler);
     484        RunLoop::main().dispatch([protectedThis = makeRef(*this)] {
     485            protectedThis->didFinishLoading(NetworkLoadMetrics { });
     486        });
     487        return;
     488    }
     489
     490    completionHandler(PolicyAction::Use);
    474491}
    475492
     
    650667{
    651668    ASSERT(!isSynchronous());
     669
     670    if (m_isKeptAlive) {
     671        continueWillSendRequest(WTFMove(request), false);
     672        return;
     673    }
    652674
    653675    if (adClickConversion)
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h

    r244544 r244700  
    115115    void disableExtraNetworkLoadMetricsCapture() { m_shouldCaptureExtraNetworkLoadMetrics = false; }
    116116
     117    bool isKeptAlive() const { return m_isKeptAlive; }
     118
    117119private:
    118120    NetworkResourceLoader(NetworkResourceLoadParameters&&, NetworkConnectionToWebProcess&, Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply&&);
     
    209211    ResponseCompletionHandler m_responseCompletionHandler;
    210212    bool m_shouldCaptureExtraNetworkLoadMetrics { false };
     213    bool m_isKeptAlive { false };
    211214
    212215    Optional<NetworkActivityTracker> m_networkActivityTracker;
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r244614 r244700  
    3131#include "NetworkProcessProxyMessages.h"
    3232#include "NetworkResourceLoadParameters.h"
     33#include "NetworkResourceLoader.h"
    3334#include "PingLoad.h"
    3435#include "WebPageProxy.h"
     
    184185}
    185186
     187void NetworkSession::addKeptAliveLoad(Ref<NetworkResourceLoader>&& loader)
     188{
     189    ASSERT(m_sessionID == loader->sessionID());
     190    ASSERT(!m_keptAliveLoads.contains(loader));
     191    m_keptAliveLoads.add(WTFMove(loader));
     192}
     193
     194void NetworkSession::removeKeptAliveLoad(NetworkResourceLoader& loader)
     195{
     196    ASSERT(m_sessionID == loader.sessionID());
     197    ASSERT(m_keptAliveLoads.contains(loader));
     198    m_keptAliveLoads.remove(loader);
     199}
     200
    186201} // namespace WebKit
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.h

    r244614 r244700  
    4949class NetworkDataTask;
    5050class NetworkProcess;
     51class NetworkResourceLoader;
    5152class WebResourceLoadStatisticsStore;
    5253struct NetworkSessionCreationParameters;
     
    8990    void markAdClickAttributionsAsExpiredForTesting();
    9091
     92    void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
     93    void removeKeptAliveLoad(NetworkResourceLoader&);
     94
    9195protected:
    9296    NetworkSession(NetworkProcess&, PAL::SessionID);
     
    103107#endif
    104108    UniqueRef<AdClickAttributionManager> m_adClickAttribution;
     109
     110    HashSet<Ref<NetworkResourceLoader>> m_keptAliveLoads;
    105111};
    106112
  • trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp

    r243163 r244700  
    117117    switch (resource->type()) {
    118118    case CachedResource::Type::Beacon:
     119    case CachedResource::Type::Ping:
    119120    case CachedResource::Type::CSSStyleSheet:
    120121    case CachedResource::Type::Script:
     
    287288    if (resourceLoader.options().cspResponseHeaders)
    288289        loadParameters.cspResponseHeaders = resourceLoader.options().cspResponseHeaders;
    289     else if (document && !document->shouldBypassMainWorldContentSecurityPolicy()) {
     290    else if (document && !document->shouldBypassMainWorldContentSecurityPolicy() && resourceLoader.options().contentSecurityPolicyImposition == ContentSecurityPolicyImposition::DoPolicyCheck) {
    290291        if (auto* contentSecurityPolicy = document->contentSecurityPolicy())
    291292            loadParameters.cspResponseHeaders = contentSecurityPolicy->responseHeaders();
     
    570571    static uint64_t identifier = 0;
    571572    return ++identifier;
     573}
     574
     575bool WebLoaderStrategy::usePingLoad() const
     576{
     577    return !RuntimeEnabledFeatures::sharedFeatures().fetchAPIKeepAliveEnabled();
    572578}
    573579
  • trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h

    r239634 r244700  
    6363    void resumePendingRequests() final;
    6464
     65    bool usePingLoad() const final;
    6566    void startPingLoad(WebCore::Frame&, WebCore::ResourceRequest&, const WebCore::HTTPHeaderMap& originalRequestHeaders, const WebCore::FetchOptions&, WebCore::ContentSecurityPolicyImposition, PingLoadCompletionHandler&&) final;
    6667    void didFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError&&, WebCore::ResourceResponse&&);
Note: See TracChangeset for help on using the changeset viewer.