[Beacon] Update sendBeacon to use the CachedResourceLoader
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 23:09:24 +0000 (23:09 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 23:09:24 +0000 (23:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175192
<rdar://problem/33725923>

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Rebaseline test as our Content-Type header has changed for ArrayBuffer / ArrayBufferView
payloads.

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

Source/WebCore:

Update sendBeacon to use the FetchRequest / CachedResourceLoader instead of
the PingLoader. This gets us closer to the specification which is based on
Fetch and reduces code duplication. This also fixes an issue where our
Origin header was not properly set on Beacon resquests.

In a follow-up, we will implement in CachedResourceLoader Fetch's quota for
inflight keepalive requests which is needed to fully support sendBeacon().

* Modules/beacon/NavigatorBeacon.cpp:
(WebCore::NavigatorBeacon::sendBeacon):
* Modules/beacon/NavigatorBeacon.h:
* loader/LinkLoader.cpp:
(WebCore::createLinkPreloadResourceClient):
* loader/PingLoader.cpp:
* loader/PingLoader.h:
* loader/ResourceLoadInfo.cpp:
(WebCore::toResourceType):
* loader/SubresourceLoader.cpp:
(WebCore::logResourceLoaded):
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::defaultPriorityForResourceType):
(WebCore::CachedResource::load):
* loader/cache/CachedResource.h:
* loader/cache/CachedResourceLoader.cpp:
(WebCore::createResource):
(WebCore::CachedResourceLoader::requestBeaconResource):
(WebCore::contentTypeFromResourceType):
(WebCore::CachedResourceLoader::checkInsecureContent const):
(WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
(WebCore::isResourceSuitableForDirectReuse):
* loader/cache/CachedResourceLoader.h:

Source/WebKit:

Deal with new Beacon CachedResource type.

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::maximumBufferingTime):

LayoutTests:

Rebaseline a few tests now that the Origin header is properly set of our Beacon
requests. This is a progression and matches the results from Blink.

Our Content-Type header for ArrayBuffer / ArrayBufferView payloads has also
changed. It is unclear which one is best but at least we are now consistent
with Fetch.

* http/tests/blink/sendbeacon/beacon-cookie-expected.txt:
* http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt:
* http/tests/blink/sendbeacon/beacon-same-origin-expected.txt:
* http/wpt/beacon/headers/header-content-type-same-origin.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@220303 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/blink/sendbeacon/beacon-cookie-expected.txt
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt
LayoutTests/http/tests/blink/sendbeacon/beacon-same-origin-expected.txt
LayoutTests/http/wpt/beacon/headers/header-content-type-same-origin.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-content-type-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/beacon/NavigatorBeacon.cpp
Source/WebCore/Modules/beacon/NavigatorBeacon.h
Source/WebCore/loader/LinkLoader.cpp
Source/WebCore/loader/PingLoader.cpp
Source/WebCore/loader/PingLoader.h
Source/WebCore/loader/ResourceLoadInfo.cpp
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp

index 141d57a..7a96ed6 100644 (file)
@@ -1,3 +1,23 @@
+2017-08-04  Chris Dumez  <cdumez@apple.com>
+
+        [Beacon] Update sendBeacon to use the CachedResourceLoader
+        https://bugs.webkit.org/show_bug.cgi?id=175192
+        <rdar://problem/33725923>
+
+        Reviewed by Youenn Fablet.
+
+        Rebaseline a few tests now that the Origin header is properly set of our Beacon
+        requests. This is a progression and matches the results from Blink.
+
+        Our Content-Type header for ArrayBuffer / ArrayBufferView payloads has also
+        changed. It is unclear which one is best but at least we are now consistent
+        with Fetch.
+
+        * http/tests/blink/sendbeacon/beacon-cookie-expected.txt:
+        * http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt:
+        * http/tests/blink/sendbeacon/beacon-same-origin-expected.txt:
+        * http/wpt/beacon/headers/header-content-type-same-origin.html:
+
 2017-08-04  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Report user interaction immediately, but only when needed
index b35b457..f1afd7f 100644 (file)
@@ -7,7 +7,7 @@ PASS navigator.sendBeacon("resources/save-beacon.php?name=cookie", "Blip"); is t
 PASS Beacon sent successfully
 PASS Content-Type: text/plain;charset=UTF-8
 PASS Cookie: hello=world
-PASS Origin: null
+PASS Origin: http://127.0.0.1:8000
 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-cookie.html
 PASS Request-Method: POST
 PASS Length: 4
index 774e1a6..76c01a5 100644 (file)
@@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 PASS navigator.sendBeacon("http://localhost:8000/blink/sendbeacon/resources/save-beacon.php?name=cross-origin", "CrossOrigin"); is true
 PASS Beacon sent successfully
 PASS Content-Type: text/plain;charset=UTF-8
-PASS Origin: null
+PASS Origin: http://127.0.0.1:8000
 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-cross-origin.html
 PASS Request-Method: POST
 PASS Length: 11
index b2e1e80..f37bc1a 100644 (file)
@@ -7,7 +7,7 @@ Sending beacon with type: [object String]
 PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload); is true
 PASS Beacon sent successfully
 PASS Content-Type: text/plain;charset=UTF-8
-PASS Origin: null
+PASS Origin: http://127.0.0.1:8000
 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html
 PASS Request-Method: POST
 PASS Length: 10
@@ -16,8 +16,8 @@ PASS
 Sending beacon with type: [object Uint32Array]
 PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload); is true
 PASS Beacon sent successfully
-PASS Content-Type: application/octet-stream
-PASS Origin: null
+PASS Content-Type: application/x-www-form-urlencoded
+PASS Origin: http://127.0.0.1:8000
 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html
 PASS Request-Method: POST
 PASS Length: 40
@@ -27,7 +27,7 @@ Sending beacon with type: [object Blob]
 PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload); is true
 PASS Beacon sent successfully
 PASS Content-Type: text/plain;from-beacon=true
-PASS Origin: null
+PASS Origin: http://127.0.0.1:8000
 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html
 PASS Request-Method: POST
 PASS Length: 11
@@ -37,7 +37,7 @@ Sending beacon with type: [object FormData]
 PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload); is true
 PASS Beacon sent successfully
 PASS Content-Type: multipart/form-data;
-PASS Origin: null
+PASS Origin: http://127.0.0.1:8000
 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html
 PASS Request-Method: POST
 PASS Length: 9
@@ -47,7 +47,7 @@ Sending beacon with type: [object URLSearchParams]
 PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload); is true
 PASS Beacon sent successfully
 PASS Content-Type: application/x-www-form-urlencoded;charset=UTF-8
-PASS Origin: null
+PASS Origin: http://127.0.0.1:8000
 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html
 PASS Request-Method: POST
 PASS Length: 7
index e24c2e7..4946e2a 100644 (file)
@@ -77,8 +77,8 @@ function stringToURLSearchParams(input)
 }
 
 testContentTypeHeader("hi!", "text/plain;charset=UTF-8", "string");
-testContentTypeHeader(stringToArrayBufferView("123"), "application/octet-stream", "ArrayBufferView"); // Specification says no content-type but browsers seem to use "application/octet-stream".
-testContentTypeHeader(stringToArrayBuffer("123"), "application/octet-stream", "ArrayBuffer"); // Specification says no content-type but browsers seem to use "application/octet-stream".
+testContentTypeHeader(stringToArrayBufferView("123"), "application/x-www-form-urlencoded", "ArrayBufferView"); // FIXME: It is unclear what the Content-Type should be here or if it should be present at all.
+testContentTypeHeader(stringToArrayBuffer("123"), "application/x-www-form-urlencoded", "ArrayBuffer"); // FIXME: It is unclear what the Content-Type should be here or if it should be present at all.
 testContentTypeHeader(stringToBlob("123"), "text/plain", "Blob");
 testContentTypeHeader(stringToFormData("qwerty"), "multipart/form-data", "FormData");
 testContentTypeHeader(stringToURLSearchParams("key1=value1&key2=value2"), "application/x-www-form-urlencoded;charset=UTF-8", "URLSearchParams");
index 93789af..63b1df7 100644 (file)
@@ -1,5 +1,18 @@
 2017-08-04  Chris Dumez  <cdumez@apple.com>
 
+        [Beacon] Update sendBeacon to use the CachedResourceLoader
+        https://bugs.webkit.org/show_bug.cgi?id=175192
+        <rdar://problem/33725923>
+
+        Reviewed by Youenn Fablet.
+
+        Rebaseline test as our Content-Type header has changed for ArrayBuffer / ArrayBufferView
+        payloads.
+
+        * web-platform-tests/beacon/headers/header-content-type-expected.txt:
+
+2017-08-04  Chris Dumez  <cdumez@apple.com>
+
         Match newly-clarified spec on textarea defaultValue/value/child text content
         https://bugs.webkit.org/show_bug.cgi?id=173878
 
index ed48fe4..27352c5 100644 (file)
@@ -1,6 +1,5 @@
-CONSOLE MESSAGE: line 35: This requests requires a CORS preflight but this is not supported yet.
 
 PASS Test content-type header for a body string 
-FAIL Test content-type header for a body ArrayBuffer assert_true: SendBeacon Succeeded expected true got false
+PASS Test content-type header for a body ArrayBuffer 
 PASS Test content-type header for a body FormData 
 
index a198e4f..84ecf3c 100644 (file)
@@ -1,3 +1,43 @@
+2017-08-04  Chris Dumez  <cdumez@apple.com>
+
+        [Beacon] Update sendBeacon to use the CachedResourceLoader
+        https://bugs.webkit.org/show_bug.cgi?id=175192
+        <rdar://problem/33725923>
+
+        Reviewed by Youenn Fablet.
+
+        Update sendBeacon to use the FetchRequest / CachedResourceLoader instead of
+        the PingLoader. This gets us closer to the specification which is based on
+        Fetch and reduces code duplication. This also fixes an issue where our
+        Origin header was not properly set on Beacon resquests.
+
+        In a follow-up, we will implement in CachedResourceLoader Fetch's quota for
+        inflight keepalive requests which is needed to fully support sendBeacon().
+
+        * Modules/beacon/NavigatorBeacon.cpp:
+        (WebCore::NavigatorBeacon::sendBeacon):
+        * Modules/beacon/NavigatorBeacon.h:
+        * loader/LinkLoader.cpp:
+        (WebCore::createLinkPreloadResourceClient):
+        * loader/PingLoader.cpp:
+        * loader/PingLoader.h:
+        * loader/ResourceLoadInfo.cpp:
+        (WebCore::toResourceType):
+        * loader/SubresourceLoader.cpp:
+        (WebCore::logResourceLoaded):
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::defaultPriorityForResourceType):
+        (WebCore::CachedResource::load):
+        * loader/cache/CachedResource.h:
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::createResource):
+        (WebCore::CachedResourceLoader::requestBeaconResource):
+        (WebCore::contentTypeFromResourceType):
+        (WebCore::CachedResourceLoader::checkInsecureContent const):
+        (WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
+        (WebCore::isResourceSuitableForDirectReuse):
+        * loader/cache/CachedResourceLoader.h:
+
 2017-08-04  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Report user interaction immediately, but only when needed
index 29f7b7c..7208bcc 100644 (file)
 #include "config.h"
 #include "NavigatorBeacon.h"
 
+#include "CachedResourceLoader.h"
 #include "Document.h"
+#include "FetchRequest.h"
 #include "Navigator.h"
 #include "URL.h"
+#include <runtime/JSCJSValue.h>
 
 namespace WebCore {
 
-ExceptionOr<bool> NavigatorBeacon::sendBeacon(Navigator&, Document& document, const String& url, std::optional<BodyInit>&& data)
+ExceptionOr<bool> NavigatorBeacon::sendBeacon(Navigator&, Document& document, const String& url, std::optional<FetchBody::Init>&& body)
 {
     URL parsedUrl = document.completeURL(url);
 
@@ -43,11 +46,31 @@ ExceptionOr<bool> NavigatorBeacon::sendBeacon(Navigator&, Document& document, co
     if (!parsedUrl.protocolIsInHTTPFamily())
         return Exception { TypeError, ASCIILiteral("Beacons can only be sent over HTTP(S)") };
 
-    auto* frame = document.frame();
-    if (!frame)
+    if (!document.frame())
         return false;
 
-    return PingLoader::sendBeacon(*frame, document, parsedUrl, WTFMove(data));
+    auto& contentSecurityPolicy = *document.contentSecurityPolicy();
+    if (!document.shouldBypassMainWorldContentSecurityPolicy() && !contentSecurityPolicy.allowConnectToSource(parsedUrl)) {
+        // We simulate a network error so we return true here. This is consistent with Blink.
+        return true;
+    }
+
+    FetchRequestInit init;
+    init.method = ASCIILiteral("POST");
+    init.body = WTFMove(body);
+    init.credentials = FetchOptions::Credentials::Include;
+    init.cache = FetchOptions::Cache::NoCache;
+    init.redirect = FetchOptions::Redirect::Follow;
+    init.keepalive = true;
+    init.window = JSC::jsNull();
+
+    auto fetchRequestResult = FetchRequest::create(document, parsedUrl.string(), WTFMove(init));
+    if (fetchRequestResult.hasException())
+        return fetchRequestResult.releaseException();
+
+    auto fetchRequest = fetchRequestResult.releaseReturnValue();
+    document.cachedResourceLoader().requestBeaconResource({ fetchRequest->internalRequest(), fetchRequest->fetchOptions() });
+    return true;
 }
 
 }
index d9cb3e5..6fdf89d 100644 (file)
@@ -26,7 +26,7 @@
 #pragma once
 
 #include "ExceptionOr.h"
-#include "PingLoader.h"
+#include "FetchBody.h"
 #include <wtf/Forward.h>
 
 namespace WebCore {
@@ -36,7 +36,7 @@ class Navigator;
 
 class NavigatorBeacon {
 public:
-    static ExceptionOr<bool> sendBeacon(Navigator&, Document&, const String& url, std::optional<BodyInit>&&);
+    static ExceptionOr<bool> sendBeacon(Navigator&, Document&, const String& url, std::optional<FetchBody::Init>&&);
 };
 
 }
index 7542bb7..6e2d4ae 100644 (file)
@@ -162,6 +162,7 @@ static std::unique_ptr<LinkPreloadResourceClient> createLinkPreloadResourceClien
 #if ENABLE(XSLT)
     case CachedResource::XSLStyleSheet:
 #endif
+    case CachedResource::Beacon:
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkSubresource:
     case CachedResource::LinkPrefetch:
index 104c3aa..865eb1c 100644 (file)
 #include "config.h"
 #include "PingLoader.h"
 
-#include "Blob.h"
 #include "ContentSecurityPolicy.h"
-#include "DOMFormData.h"
 #include "Document.h"
-#include "FormData.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
-#include "HTTPHeaderNames.h"
-#include "HTTPHeaderValues.h"
-#include "HTTPParsers.h"
 #include "InspectorInstrumentation.h"
 #include "LoaderStrategy.h"
 #include "Page.h"
-#include "ParsedContentType.h"
 #include "PlatformStrategies.h"
 #include "ProgressTracker.h"
 #include "ResourceHandle.h"
 #include "ResourceResponse.h"
 #include "SecurityOrigin.h"
 #include "SecurityPolicy.h"
-#include "URLSearchParams.h"
 #include "UserContentController.h"
-#include <runtime/ArrayBuffer.h>
-#include <runtime/ArrayBufferView.h>
-#include <runtime/JSCInlines.h>
 #include <wtf/text/CString.h>
 
 namespace WebCore {
@@ -190,87 +179,6 @@ void PingLoader::sendViolationReport(Frame& frame, const URL& reportURL, Ref<For
     startPingLoad(frame, request, ShouldFollowRedirects::No);
 }
 
-bool PingLoader::sendBeacon(Frame& frame, Document& document, const URL& url, std::optional<BodyInit>&& data)
-{
-    ResourceRequest request(url);
-    if (processContentExtensionRulesForLoad(frame, request, ResourceType::Raw))
-        return false;
-
-    auto& contentSecurityPolicy = *document.contentSecurityPolicy();
-    if (!document.shouldBypassMainWorldContentSecurityPolicy() && !contentSecurityPolicy.allowConnectToSource(url)) {
-        // We simulate a network error so we return true here. This is consistent with Blink.
-        return true;
-    }
-
-    bool noCors = true;
-    request.setHTTPMethod(ASCIILiteral("POST"));
-    // FIXME: We should restrict the size of payloads.
-    if (data) {
-        String mimeType;
-        WTF::switchOn(data.value(),
-            [&] (RefPtr<Blob>& blob) {
-                auto& blobType = blob->type();
-                if (!blobType.isEmpty() && isValidContentType(blobType))
-                    mimeType = blobType;
-                else
-                    mimeType = ASCIILiteral("application/octet-stream");
-                auto formData = FormData::create();
-                formData->appendBlob(blob->url());
-                request.setHTTPBody(WTFMove(formData));
-            },
-            [&] (RefPtr<JSC::ArrayBuffer>& buffer) {
-                mimeType = ASCIILiteral("application/octet-stream");
-                request.setHTTPBody(FormData::create(buffer->data(), buffer->byteLength()));
-            },
-            [&] (RefPtr<JSC::ArrayBufferView>& buffer) {
-                mimeType = ASCIILiteral("application/octet-stream");
-                request.setHTTPBody(FormData::create(buffer->baseAddress(), buffer->byteLength()));
-            },
-            [&] (RefPtr<DOMFormData>& domFormData) {
-                auto formData = FormData::createMultiPart(*domFormData, domFormData->encoding(), &document);
-                formData->generateFiles(&document);
-                mimeType = makeString("multipart/form-data; boundary=", formData->boundary().data());
-                request.setHTTPBody(WTFMove(formData));
-            },
-            [&] (RefPtr<URLSearchParams>& searchParams) {
-                mimeType = HTTPHeaderValues::formURLEncodedContentType();
-                request.setHTTPBody(FormData::create(searchParams->toString().utf8()));
-            },
-            [&] (String& string) {
-                mimeType = HTTPHeaderValues::textPlainContentType();
-                request.setHTTPBody(FormData::create(string.utf8()));
-            }
-        );
-        noCors = false;
-        if (!mimeType.isEmpty()) {
-            // If mimeType value is a CORS-safelisted request-header value for the Content-Type header, set corsMode to "no-cors".
-            if (isCrossOriginSafeRequestHeader(HTTPHeaderName::ContentType, mimeType))
-                noCors = true;
-            request.setHTTPContentType(mimeType);
-        }
-    }
-    request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "max-age=0");
-    frame.loader().addExtraFieldsToSubresourceRequest(request);
-
-    auto& sourceOrigin = document.securityOrigin();
-    bool isCrossOriginRequest = !sourceOrigin.canRequest(url);
-
-    // FIXME: We are supposed to do a preflight in this case but this is not supported yet.
-    if (isCrossOriginRequest && !noCors) {
-        document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, ASCIILiteral("This requests requires a CORS preflight but this is not supported yet."));
-        return false;
-    }
-
-    FrameLoader::addHTTPOriginIfNeeded(request, sourceOrigin.toString());
-    String referrer = SecurityPolicy::generateReferrerHeader(document.referrerPolicy(), url, frame.loader().outgoingReferrer());
-    if (!referrer.isEmpty())
-        request.setHTTPReferrer(referrer);
-
-    request.setAllowCookies(true); // Credentials mode: include.
-    startPingLoad(frame, request, ShouldFollowRedirects::Yes);
-    return true;
-}
-
 void PingLoader::startPingLoad(Frame& frame, ResourceRequest& request, ShouldFollowRedirects shouldFollowRedirects)
 {
     unsigned long identifier = frame.page()->progress().createUniqueIdentifier();
index 6ab5ca3..b7937de 100644 (file)
 
 #include <wtf/Forward.h>
 #include <wtf/Ref.h>
-#include <wtf/Variant.h>
-
-namespace JSC {
-
-class ArrayBuffer;
-class ArrayBufferView;
-
-}
 
 namespace WebCore {
 
-class Blob;
-class DOMFormData;
-class Document;
 class FormData;
 class Frame;
 class URL;
-class URLSearchParams;
 class ResourceRequest;
 
 enum class ViolationReportType {
@@ -59,12 +47,9 @@ enum class ViolationReportType {
     XSSAuditor,
 };
 
-using BodyInit = Variant<RefPtr<Blob>, RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, String>;
-
 class PingLoader {
 public:
     static void loadImage(Frame&, const URL&);
-    static bool sendBeacon(Frame&, Document&, const URL&, std::optional<BodyInit>&&);
     static void sendPing(Frame&, const URL& pingURL, const URL& destinationURL);
     static void sendViolationReport(Frame&, const URL& reportURL, Ref<FormData>&& report, ViolationReportType);
 
index 027b3f7..13b2ae1 100644 (file)
@@ -55,6 +55,7 @@ ResourceType toResourceType(CachedResource::Type type)
 #endif
         return ResourceType::Font;
 
+    case CachedResource::Beacon:
     case CachedResource::MediaResource:
     case CachedResource::Icon:
     case CachedResource::RawResource:
@@ -70,6 +71,7 @@ ResourceType toResourceType(CachedResource::Type type)
         ASSERT_NOT_REACHED();
 #endif
     };
+    return ResourceType::Raw;
 }
 
 uint16_t readResourceType(const String& name)
index 07fb52e..8910fab 100644 (file)
@@ -447,6 +447,9 @@ static void logResourceLoaded(Frame* frame, CachedResource::Type type)
 #endif
         resourceType = DiagnosticLoggingKeys::fontKey();
         break;
+    case CachedResource::Beacon:
+        ASSERT_NOT_REACHED();
+        break;
     case CachedResource::MediaResource:
     case CachedResource::Icon:
     case CachedResource::RawResource:
index d8d68fa..4b442f6 100644 (file)
@@ -88,6 +88,8 @@ ResourceLoadPriority CachedResource::defaultPriorityForResourceType(Type type)
 #endif
     case CachedResource::SVGDocumentResource:
         return ResourceLoadPriority::Low;
+    case CachedResource::Beacon:
+        return ResourceLoadPriority::VeryLow;
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
         return ResourceLoadPriority::VeryLow;
@@ -257,6 +259,12 @@ void CachedResource::load(CachedResourceLoader& cachedResourceLoader)
         m_fragmentIdentifierForRequest = String();
     }
 
+    // FIXME: We should not special-case Beacon here.
+    if (m_options.keepAlive && type() == CachedResource::Beacon) {
+        platformStrategies()->loaderStrategy()->createPingHandle(frame.loader().networkingContext(), request, m_options.credentials == FetchOptions::Credentials::Include, m_options.redirect == FetchOptions::Redirect::Follow);
+        return;
+    }
+
     m_loader = platformStrategies()->loaderStrategy()->loadResource(frame, *this, request, m_options);
     if (!m_loader) {
         RELEASE_LOG_IF_ALLOWED("load: Unable to create SubresourceLoader (frame = %p)", &frame);
index 242ffac..8ba98e5 100644 (file)
@@ -72,6 +72,7 @@ public:
         MediaResource,
         RawResource,
         Icon,
+        Beacon,
         SVGDocumentResource
 #if ENABLE(XSLT)
         , XSLStyleSheet
index fb3489b..830ce51 100644 (file)
@@ -108,6 +108,8 @@ static CachedResource* createResource(CachedResource::Type type, CachedResourceR
     case CachedResource::Icon:
     case CachedResource::MainResource:
         return new CachedRawResource(WTFMove(request), type, sessionID);
+    case CachedResource::Beacon:
+        return new CachedResource(WTFMove(request), CachedResource::Beacon, sessionID);
 #if ENABLE(XSLT)
     case CachedResource::XSLStyleSheet:
         return new CachedXSLStyleSheet(WTFMove(request), sessionID);
@@ -287,6 +289,11 @@ CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestRawResource
     return downcast<CachedRawResource>(requestResource(CachedResource::RawResource, WTFMove(request)).get());
 }
 
+CachedResourceHandle<CachedResource> CachedResourceLoader::requestBeaconResource(CachedResourceRequest&& request)
+{
+    return requestResource(CachedResource::Beacon, WTFMove(request)).get();
+}
+
 CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestMainResource(CachedResourceRequest&& request)
 {
     return downcast<CachedRawResource>(requestResource(CachedResource::MainResource, WTFMove(request)).get());
@@ -312,6 +319,7 @@ static MixedContentChecker::ContentType contentTypeFromResourceType(CachedResour
         return MixedContentChecker::ContentType::Active;
 #endif
 
+    case CachedResource::Beacon:
     case CachedResource::RawResource:
     case CachedResource::Icon:
     case CachedResource::SVGDocumentResource:
@@ -381,6 +389,7 @@ bool CachedResourceLoader::checkInsecureContent(CachedResource::Type type, const
         break;
     }
     case CachedResource::MainResource:
+    case CachedResource::Beacon:
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
     case CachedResource::LinkSubresource:
@@ -431,6 +440,7 @@ bool CachedResourceLoader::allowedByContentSecurityPolicy(CachedResource::Type t
         if (!m_document->contentSecurityPolicy()->allowMediaFromSource(url, redirectResponseReceived))
             return false;
         break;
+    case CachedResource::Beacon:
     case CachedResource::RawResource:
         return true;
     default:
@@ -626,6 +636,9 @@ static inline bool isResourceSuitableForDirectReuse(const CachedResource& resour
     if (resource.type() == CachedResource::Type::RawResource || resource.type() == CachedResource::Type::MediaResource)
         return false;
 
+    if (resource.type() == CachedResource::Beacon)
+        return false;
+
     return true;
 }
 
index 9e2ccf5..71a5b88 100644 (file)
@@ -78,6 +78,7 @@ public:
     CachedResourceHandle<CachedFont> requestFont(CachedResourceRequest&&, bool isSVG);
     CachedResourceHandle<CachedRawResource> requestMedia(CachedResourceRequest&&);
     CachedResourceHandle<CachedRawResource> requestIcon(CachedResourceRequest&&);
+    CachedResourceHandle<CachedResource> requestBeaconResource(CachedResourceRequest&&);
     CachedResourceHandle<CachedRawResource> requestRawResource(CachedResourceRequest&&);
     CachedResourceHandle<CachedRawResource> requestMainResource(CachedResourceRequest&&);
     CachedResourceHandle<CachedSVGDocument> requestSVGDocument(CachedResourceRequest&&);
index 18f0715..242b413 100644 (file)
@@ -1,3 +1,16 @@
+2017-08-04  Chris Dumez  <cdumez@apple.com>
+
+        [Beacon] Update sendBeacon to use the CachedResourceLoader
+        https://bugs.webkit.org/show_bug.cgi?id=175192
+        <rdar://problem/33725923>
+
+        Reviewed by Youenn Fablet.
+
+        Deal with new Beacon CachedResource type.
+
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::maximumBufferingTime):
+
 2017-08-04  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Report user interaction immediately, but only when needed
index 63fe8b5..20253cc 100644 (file)
@@ -105,6 +105,7 @@ static Seconds maximumBufferingTime(CachedResource* resource)
         return 0_s;
 
     switch (resource->type()) {
+    case CachedResource::Beacon:
     case CachedResource::CSSStyleSheet:
     case CachedResource::Script:
 #if ENABLE(SVG_FONTS)