Changeset 220303 in webkit
- Timestamp:
- Aug 4, 2017 4:09:24 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r220302 r220303 1 2017-08-04 Chris Dumez <cdumez@apple.com> 2 3 [Beacon] Update sendBeacon to use the CachedResourceLoader 4 https://bugs.webkit.org/show_bug.cgi?id=175192 5 <rdar://problem/33725923> 6 7 Reviewed by Youenn Fablet. 8 9 Rebaseline a few tests now that the Origin header is properly set of our Beacon 10 requests. This is a progression and matches the results from Blink. 11 12 Our Content-Type header for ArrayBuffer / ArrayBufferView payloads has also 13 changed. It is unclear which one is best but at least we are now consistent 14 with Fetch. 15 16 * http/tests/blink/sendbeacon/beacon-cookie-expected.txt: 17 * http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt: 18 * http/tests/blink/sendbeacon/beacon-same-origin-expected.txt: 19 * http/wpt/beacon/headers/header-content-type-same-origin.html: 20 1 21 2017-08-04 John Wilander <wilander@apple.com> 2 22 -
trunk/LayoutTests/http/tests/blink/sendbeacon/beacon-cookie-expected.txt
r220121 r220303 8 8 PASS Content-Type: text/plain;charset=UTF-8 9 9 PASS Cookie: hello=world 10 PASS Origin: null10 PASS Origin: http://127.0.0.1:8000 11 11 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-cookie.html 12 12 PASS Request-Method: POST -
trunk/LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt
r220121 r220303 7 7 PASS Beacon sent successfully 8 8 PASS Content-Type: text/plain;charset=UTF-8 9 PASS Origin: null9 PASS Origin: http://127.0.0.1:8000 10 10 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-cross-origin.html 11 11 PASS Request-Method: POST -
trunk/LayoutTests/http/tests/blink/sendbeacon/beacon-same-origin-expected.txt
r220121 r220303 8 8 PASS Beacon sent successfully 9 9 PASS Content-Type: text/plain;charset=UTF-8 10 PASS Origin: null10 PASS Origin: http://127.0.0.1:8000 11 11 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html 12 12 PASS Request-Method: POST … … 17 17 PASS navigator.sendBeacon("resources/save-beacon.php?name=same-origin", payload); is true 18 18 PASS Beacon sent successfully 19 PASS Content-Type: application/ octet-stream20 PASS Origin: null19 PASS Content-Type: application/x-www-form-urlencoded 20 PASS Origin: http://127.0.0.1:8000 21 21 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html 22 22 PASS Request-Method: POST … … 28 28 PASS Beacon sent successfully 29 29 PASS Content-Type: text/plain;from-beacon=true 30 PASS Origin: null30 PASS Origin: http://127.0.0.1:8000 31 31 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html 32 32 PASS Request-Method: POST … … 38 38 PASS Beacon sent successfully 39 39 PASS Content-Type: multipart/form-data; 40 PASS Origin: null40 PASS Origin: http://127.0.0.1:8000 41 41 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html 42 42 PASS Request-Method: POST … … 48 48 PASS Beacon sent successfully 49 49 PASS Content-Type: application/x-www-form-urlencoded;charset=UTF-8 50 PASS Origin: null50 PASS Origin: http://127.0.0.1:8000 51 51 PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-same-origin.html 52 52 PASS Request-Method: POST -
trunk/LayoutTests/http/wpt/beacon/headers/header-content-type-same-origin.html
r220121 r220303 78 78 79 79 testContentTypeHeader("hi!", "text/plain;charset=UTF-8", "string"); 80 testContentTypeHeader(stringToArrayBufferView("123"), "application/ octet-stream", "ArrayBufferView"); // Specification says no content-type but browsers seem to use "application/octet-stream".81 testContentTypeHeader(stringToArrayBuffer("123"), "application/ octet-stream", "ArrayBuffer"); // Specification says no content-type but browsers seem to use "application/octet-stream".80 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. 81 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. 82 82 testContentTypeHeader(stringToBlob("123"), "text/plain", "Blob"); 83 83 testContentTypeHeader(stringToFormData("qwerty"), "multipart/form-data", "FormData"); -
trunk/LayoutTests/imported/w3c/ChangeLog
r220290 r220303 1 2017-08-04 Chris Dumez <cdumez@apple.com> 2 3 [Beacon] Update sendBeacon to use the CachedResourceLoader 4 https://bugs.webkit.org/show_bug.cgi?id=175192 5 <rdar://problem/33725923> 6 7 Reviewed by Youenn Fablet. 8 9 Rebaseline test as our Content-Type header has changed for ArrayBuffer / ArrayBufferView 10 payloads. 11 12 * web-platform-tests/beacon/headers/header-content-type-expected.txt: 13 1 14 2017-08-04 Chris Dumez <cdumez@apple.com> 2 15 -
trunk/LayoutTests/imported/w3c/web-platform-tests/beacon/headers/header-content-type-expected.txt
r220121 r220303 1 CONSOLE MESSAGE: line 35: This requests requires a CORS preflight but this is not supported yet.2 1 3 2 PASS Test content-type header for a body string 4 FAIL Test content-type header for a body ArrayBuffer assert_true: SendBeacon Succeeded expected true got false 3 PASS Test content-type header for a body ArrayBuffer 5 4 PASS Test content-type header for a body FormData 6 5 -
trunk/Source/WebCore/ChangeLog
r220302 r220303 1 2017-08-04 Chris Dumez <cdumez@apple.com> 2 3 [Beacon] Update sendBeacon to use the CachedResourceLoader 4 https://bugs.webkit.org/show_bug.cgi?id=175192 5 <rdar://problem/33725923> 6 7 Reviewed by Youenn Fablet. 8 9 Update sendBeacon to use the FetchRequest / CachedResourceLoader instead of 10 the PingLoader. This gets us closer to the specification which is based on 11 Fetch and reduces code duplication. This also fixes an issue where our 12 Origin header was not properly set on Beacon resquests. 13 14 In a follow-up, we will implement in CachedResourceLoader Fetch's quota for 15 inflight keepalive requests which is needed to fully support sendBeacon(). 16 17 * Modules/beacon/NavigatorBeacon.cpp: 18 (WebCore::NavigatorBeacon::sendBeacon): 19 * Modules/beacon/NavigatorBeacon.h: 20 * loader/LinkLoader.cpp: 21 (WebCore::createLinkPreloadResourceClient): 22 * loader/PingLoader.cpp: 23 * loader/PingLoader.h: 24 * loader/ResourceLoadInfo.cpp: 25 (WebCore::toResourceType): 26 * loader/SubresourceLoader.cpp: 27 (WebCore::logResourceLoaded): 28 * loader/cache/CachedResource.cpp: 29 (WebCore::CachedResource::defaultPriorityForResourceType): 30 (WebCore::CachedResource::load): 31 * loader/cache/CachedResource.h: 32 * loader/cache/CachedResourceLoader.cpp: 33 (WebCore::createResource): 34 (WebCore::CachedResourceLoader::requestBeaconResource): 35 (WebCore::contentTypeFromResourceType): 36 (WebCore::CachedResourceLoader::checkInsecureContent const): 37 (WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const): 38 (WebCore::isResourceSuitableForDirectReuse): 39 * loader/cache/CachedResourceLoader.h: 40 1 41 2017-08-04 John Wilander <wilander@apple.com> 2 42 -
trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp
r220121 r220303 27 27 #include "NavigatorBeacon.h" 28 28 29 #include "CachedResourceLoader.h" 29 30 #include "Document.h" 31 #include "FetchRequest.h" 30 32 #include "Navigator.h" 31 33 #include "URL.h" 34 #include <runtime/JSCJSValue.h> 32 35 33 36 namespace WebCore { 34 37 35 ExceptionOr<bool> NavigatorBeacon::sendBeacon(Navigator&, Document& document, const String& url, std::optional< BodyInit>&& data)38 ExceptionOr<bool> NavigatorBeacon::sendBeacon(Navigator&, Document& document, const String& url, std::optional<FetchBody::Init>&& body) 36 39 { 37 40 URL parsedUrl = document.completeURL(url); … … 44 47 return Exception { TypeError, ASCIILiteral("Beacons can only be sent over HTTP(S)") }; 45 48 46 auto* frame = document.frame(); 47 if (!frame) 49 if (!document.frame()) 48 50 return false; 49 51 50 return PingLoader::sendBeacon(*frame, document, parsedUrl, WTFMove(data)); 52 auto& contentSecurityPolicy = *document.contentSecurityPolicy(); 53 if (!document.shouldBypassMainWorldContentSecurityPolicy() && !contentSecurityPolicy.allowConnectToSource(parsedUrl)) { 54 // We simulate a network error so we return true here. This is consistent with Blink. 55 return true; 56 } 57 58 FetchRequestInit init; 59 init.method = ASCIILiteral("POST"); 60 init.body = WTFMove(body); 61 init.credentials = FetchOptions::Credentials::Include; 62 init.cache = FetchOptions::Cache::NoCache; 63 init.redirect = FetchOptions::Redirect::Follow; 64 init.keepalive = true; 65 init.window = JSC::jsNull(); 66 67 auto fetchRequestResult = FetchRequest::create(document, parsedUrl.string(), WTFMove(init)); 68 if (fetchRequestResult.hasException()) 69 return fetchRequestResult.releaseException(); 70 71 auto fetchRequest = fetchRequestResult.releaseReturnValue(); 72 document.cachedResourceLoader().requestBeaconResource({ fetchRequest->internalRequest(), fetchRequest->fetchOptions() }); 73 return true; 51 74 } 52 75 -
trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.h
r220121 r220303 27 27 28 28 #include "ExceptionOr.h" 29 #include " PingLoader.h"29 #include "FetchBody.h" 30 30 #include <wtf/Forward.h> 31 31 … … 37 37 class NavigatorBeacon { 38 38 public: 39 static ExceptionOr<bool> sendBeacon(Navigator&, Document&, const String& url, std::optional< BodyInit>&&);39 static ExceptionOr<bool> sendBeacon(Navigator&, Document&, const String& url, std::optional<FetchBody::Init>&&); 40 40 }; 41 41 -
trunk/Source/WebCore/loader/LinkLoader.cpp
r219051 r220303 163 163 case CachedResource::XSLStyleSheet: 164 164 #endif 165 case CachedResource::Beacon: 165 166 #if ENABLE(LINK_PREFETCH) 166 167 case CachedResource::LinkSubresource: -
trunk/Source/WebCore/loader/PingLoader.cpp
r220208 r220303 35 35 #include "PingLoader.h" 36 36 37 #include "Blob.h"38 37 #include "ContentSecurityPolicy.h" 39 #include "DOMFormData.h"40 38 #include "Document.h" 41 #include "FormData.h"42 39 #include "Frame.h" 43 40 #include "FrameLoader.h" 44 41 #include "FrameLoaderClient.h" 45 #include "HTTPHeaderNames.h"46 #include "HTTPHeaderValues.h"47 #include "HTTPParsers.h"48 42 #include "InspectorInstrumentation.h" 49 43 #include "LoaderStrategy.h" 50 44 #include "Page.h" 51 #include "ParsedContentType.h"52 45 #include "PlatformStrategies.h" 53 46 #include "ProgressTracker.h" … … 58 51 #include "SecurityOrigin.h" 59 52 #include "SecurityPolicy.h" 60 #include "URLSearchParams.h"61 53 #include "UserContentController.h" 62 #include <runtime/ArrayBuffer.h>63 #include <runtime/ArrayBufferView.h>64 #include <runtime/JSCInlines.h>65 54 #include <wtf/text/CString.h> 66 55 … … 191 180 } 192 181 193 bool PingLoader::sendBeacon(Frame& frame, Document& document, const URL& url, std::optional<BodyInit>&& data)194 {195 ResourceRequest request(url);196 if (processContentExtensionRulesForLoad(frame, request, ResourceType::Raw))197 return false;198 199 auto& contentSecurityPolicy = *document.contentSecurityPolicy();200 if (!document.shouldBypassMainWorldContentSecurityPolicy() && !contentSecurityPolicy.allowConnectToSource(url)) {201 // We simulate a network error so we return true here. This is consistent with Blink.202 return true;203 }204 205 bool noCors = true;206 request.setHTTPMethod(ASCIILiteral("POST"));207 // FIXME: We should restrict the size of payloads.208 if (data) {209 String mimeType;210 WTF::switchOn(data.value(),211 [&] (RefPtr<Blob>& blob) {212 auto& blobType = blob->type();213 if (!blobType.isEmpty() && isValidContentType(blobType))214 mimeType = blobType;215 else216 mimeType = ASCIILiteral("application/octet-stream");217 auto formData = FormData::create();218 formData->appendBlob(blob->url());219 request.setHTTPBody(WTFMove(formData));220 },221 [&] (RefPtr<JSC::ArrayBuffer>& buffer) {222 mimeType = ASCIILiteral("application/octet-stream");223 request.setHTTPBody(FormData::create(buffer->data(), buffer->byteLength()));224 },225 [&] (RefPtr<JSC::ArrayBufferView>& buffer) {226 mimeType = ASCIILiteral("application/octet-stream");227 request.setHTTPBody(FormData::create(buffer->baseAddress(), buffer->byteLength()));228 },229 [&] (RefPtr<DOMFormData>& domFormData) {230 auto formData = FormData::createMultiPart(*domFormData, domFormData->encoding(), &document);231 formData->generateFiles(&document);232 mimeType = makeString("multipart/form-data; boundary=", formData->boundary().data());233 request.setHTTPBody(WTFMove(formData));234 },235 [&] (RefPtr<URLSearchParams>& searchParams) {236 mimeType = HTTPHeaderValues::formURLEncodedContentType();237 request.setHTTPBody(FormData::create(searchParams->toString().utf8()));238 },239 [&] (String& string) {240 mimeType = HTTPHeaderValues::textPlainContentType();241 request.setHTTPBody(FormData::create(string.utf8()));242 }243 );244 noCors = false;245 if (!mimeType.isEmpty()) {246 // If mimeType value is a CORS-safelisted request-header value for the Content-Type header, set corsMode to "no-cors".247 if (isCrossOriginSafeRequestHeader(HTTPHeaderName::ContentType, mimeType))248 noCors = true;249 request.setHTTPContentType(mimeType);250 }251 }252 request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "max-age=0");253 frame.loader().addExtraFieldsToSubresourceRequest(request);254 255 auto& sourceOrigin = document.securityOrigin();256 bool isCrossOriginRequest = !sourceOrigin.canRequest(url);257 258 // FIXME: We are supposed to do a preflight in this case but this is not supported yet.259 if (isCrossOriginRequest && !noCors) {260 document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, ASCIILiteral("This requests requires a CORS preflight but this is not supported yet."));261 return false;262 }263 264 FrameLoader::addHTTPOriginIfNeeded(request, sourceOrigin.toString());265 String referrer = SecurityPolicy::generateReferrerHeader(document.referrerPolicy(), url, frame.loader().outgoingReferrer());266 if (!referrer.isEmpty())267 request.setHTTPReferrer(referrer);268 269 request.setAllowCookies(true); // Credentials mode: include.270 startPingLoad(frame, request, ShouldFollowRedirects::Yes);271 return true;272 }273 274 182 void PingLoader::startPingLoad(Frame& frame, ResourceRequest& request, ShouldFollowRedirects shouldFollowRedirects) 275 183 { -
trunk/Source/WebCore/loader/PingLoader.h
r220121 r220303 35 35 #include <wtf/Forward.h> 36 36 #include <wtf/Ref.h> 37 #include <wtf/Variant.h>38 39 namespace JSC {40 41 class ArrayBuffer;42 class ArrayBufferView;43 44 }45 37 46 38 namespace WebCore { 47 39 48 class Blob;49 class DOMFormData;50 class Document;51 40 class FormData; 52 41 class Frame; 53 42 class URL; 54 class URLSearchParams;55 43 class ResourceRequest; 56 44 … … 60 48 }; 61 49 62 using BodyInit = Variant<RefPtr<Blob>, RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, String>;63 64 50 class PingLoader { 65 51 public: 66 52 static void loadImage(Frame&, const URL&); 67 static bool sendBeacon(Frame&, Document&, const URL&, std::optional<BodyInit>&&);68 53 static void sendPing(Frame&, const URL& pingURL, const URL& destinationURL); 69 54 static void sendViolationReport(Frame&, const URL& reportURL, Ref<FormData>&& report, ViolationReportType); -
trunk/Source/WebCore/loader/ResourceLoadInfo.cpp
r218393 r220303 56 56 return ResourceType::Font; 57 57 58 case CachedResource::Beacon: 58 59 case CachedResource::MediaResource: 59 60 case CachedResource::Icon: … … 71 72 #endif 72 73 }; 74 return ResourceType::Raw; 73 75 } 74 76 -
trunk/Source/WebCore/loader/SubresourceLoader.cpp
r219954 r220303 448 448 resourceType = DiagnosticLoggingKeys::fontKey(); 449 449 break; 450 case CachedResource::Beacon: 451 ASSERT_NOT_REACHED(); 452 break; 450 453 case CachedResource::MediaResource: 451 454 case CachedResource::Icon: -
trunk/Source/WebCore/loader/cache/CachedResource.cpp
r218393 r220303 89 89 case CachedResource::SVGDocumentResource: 90 90 return ResourceLoadPriority::Low; 91 case CachedResource::Beacon: 92 return ResourceLoadPriority::VeryLow; 91 93 #if ENABLE(LINK_PREFETCH) 92 94 case CachedResource::LinkPrefetch: … … 256 258 request.setURL(url); 257 259 m_fragmentIdentifierForRequest = String(); 260 } 261 262 // FIXME: We should not special-case Beacon here. 263 if (m_options.keepAlive && type() == CachedResource::Beacon) { 264 platformStrategies()->loaderStrategy()->createPingHandle(frame.loader().networkingContext(), request, m_options.credentials == FetchOptions::Credentials::Include, m_options.redirect == FetchOptions::Redirect::Follow); 265 return; 258 266 } 259 267 -
trunk/Source/WebCore/loader/cache/CachedResource.h
r218393 r220303 73 73 RawResource, 74 74 Icon, 75 Beacon, 75 76 SVGDocumentResource 76 77 #if ENABLE(XSLT) -
trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp
r220208 r220303 109 109 case CachedResource::MainResource: 110 110 return new CachedRawResource(WTFMove(request), type, sessionID); 111 case CachedResource::Beacon: 112 return new CachedResource(WTFMove(request), CachedResource::Beacon, sessionID); 111 113 #if ENABLE(XSLT) 112 114 case CachedResource::XSLStyleSheet: … … 288 290 } 289 291 292 CachedResourceHandle<CachedResource> CachedResourceLoader::requestBeaconResource(CachedResourceRequest&& request) 293 { 294 return requestResource(CachedResource::Beacon, WTFMove(request)).get(); 295 } 296 290 297 CachedResourceHandle<CachedRawResource> CachedResourceLoader::requestMainResource(CachedResourceRequest&& request) 291 298 { … … 313 320 #endif 314 321 322 case CachedResource::Beacon: 315 323 case CachedResource::RawResource: 316 324 case CachedResource::Icon: … … 382 390 } 383 391 case CachedResource::MainResource: 392 case CachedResource::Beacon: 384 393 #if ENABLE(LINK_PREFETCH) 385 394 case CachedResource::LinkPrefetch: … … 432 441 return false; 433 442 break; 443 case CachedResource::Beacon: 434 444 case CachedResource::RawResource: 435 445 return true; … … 625 635 // FIXME: Implement reuse of cached raw resources. 626 636 if (resource.type() == CachedResource::Type::RawResource || resource.type() == CachedResource::Type::MediaResource) 637 return false; 638 639 if (resource.type() == CachedResource::Beacon) 627 640 return false; 628 641 -
trunk/Source/WebCore/loader/cache/CachedResourceLoader.h
r219954 r220303 79 79 CachedResourceHandle<CachedRawResource> requestMedia(CachedResourceRequest&&); 80 80 CachedResourceHandle<CachedRawResource> requestIcon(CachedResourceRequest&&); 81 CachedResourceHandle<CachedResource> requestBeaconResource(CachedResourceRequest&&); 81 82 CachedResourceHandle<CachedRawResource> requestRawResource(CachedResourceRequest&&); 82 83 CachedResourceHandle<CachedRawResource> requestMainResource(CachedResourceRequest&&); -
trunk/Source/WebKit/ChangeLog
r220302 r220303 1 2017-08-04 Chris Dumez <cdumez@apple.com> 2 3 [Beacon] Update sendBeacon to use the CachedResourceLoader 4 https://bugs.webkit.org/show_bug.cgi?id=175192 5 <rdar://problem/33725923> 6 7 Reviewed by Youenn Fablet. 8 9 Deal with new Beacon CachedResource type. 10 11 * WebProcess/Network/WebLoaderStrategy.cpp: 12 (WebKit::maximumBufferingTime): 13 1 14 2017-08-04 John Wilander <wilander@apple.com> 2 15 -
trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
r220208 r220303 106 106 107 107 switch (resource->type()) { 108 case CachedResource::Beacon: 108 109 case CachedResource::CSSStyleSheet: 109 110 case CachedResource::Script:
Note: See TracChangeset
for help on using the changeset viewer.