Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentThreadableLoader.cpp

Issue 2570473002: Enable the CORS preflight for sendBeacon()
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013, Intel Corporation 3 * Copyright (C) 2013, Intel Corporation
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/inspector/InspectorInstrumentation.h" 42 #include "core/inspector/InspectorInstrumentation.h"
43 #include "core/inspector/InspectorTraceEvents.h" 43 #include "core/inspector/InspectorTraceEvents.h"
44 #include "core/loader/CrossOriginPreflightResultCache.h" 44 #include "core/loader/CrossOriginPreflightResultCache.h"
45 #include "core/loader/DocumentThreadableLoaderClient.h" 45 #include "core/loader/DocumentThreadableLoaderClient.h"
46 #include "core/loader/FrameLoader.h" 46 #include "core/loader/FrameLoader.h"
47 #include "core/loader/FrameLoaderClient.h" 47 #include "core/loader/FrameLoaderClient.h"
48 #include "core/loader/ThreadableLoaderClient.h" 48 #include "core/loader/ThreadableLoaderClient.h"
49 #include "core/page/ChromeClient.h" 49 #include "core/page/ChromeClient.h"
50 #include "core/page/Page.h" 50 #include "core/page/Page.h"
51 #include "platform/SharedBuffer.h" 51 #include "platform/SharedBuffer.h"
52 #include "platform/WebFrameScheduler.h"
53 #include "platform/network/NetworkLog.h"
52 #include "platform/network/ResourceRequest.h" 54 #include "platform/network/ResourceRequest.h"
53 #include "platform/weborigin/SchemeRegistry.h" 55 #include "platform/weborigin/SchemeRegistry.h"
54 #include "platform/weborigin/SecurityOrigin.h" 56 #include "platform/weborigin/SecurityOrigin.h"
55 #include "platform/weborigin/SecurityPolicy.h" 57 #include "platform/weborigin/SecurityPolicy.h"
56 #include "public/platform/Platform.h" 58 #include "public/platform/Platform.h"
57 #include "public/platform/WebURLRequest.h" 59 #include "public/platform/WebURLRequest.h"
58 #include "wtf/Assertions.h" 60 #include "wtf/Assertions.h"
59 #include "wtf/PtrUtil.h" 61 #include "wtf/PtrUtil.h"
60 #include "wtf/WeakPtr.h" 62 #include "wtf/WeakPtr.h"
61 #include <memory> 63 #include <memory>
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 m_checker.responseReceived(); 691 m_checker.responseReceived();
690 692
691 if (handle) 693 if (handle)
692 m_isUsingDataConsumerHandle = true; 694 m_isUsingDataConsumerHandle = true;
693 695
694 handleResponse(resource->identifier(), response, std::move(handle)); 696 handleResponse(resource->identifier(), response, std::move(handle));
695 } 697 }
696 698
697 void DocumentThreadableLoader::handlePreflightResponse( 699 void DocumentThreadableLoader::handlePreflightResponse(
698 const ResourceResponse& response) { 700 const ResourceResponse& response) {
701 NETWORK_DVLOG(1) << this << " handlePreflightResponse()";
702
699 String accessControlErrorDescription; 703 String accessControlErrorDescription;
700 704
701 if (!passesAccessControlCheck( 705 if (!passesAccessControlCheck(
702 response, effectiveAllowCredentials(), getSecurityOrigin(), 706 response, effectiveAllowCredentials(), getSecurityOrigin(),
703 accessControlErrorDescription, m_requestContext)) { 707 accessControlErrorDescription, m_requestContext)) {
704 handlePreflightFailure( 708 handlePreflightFailure(
705 response.url().getString(), 709 response.url().getString(),
706 "Response to preflight request doesn't pass access control check: " + 710 "Response to preflight request doesn't pass access control check: " +
707 accessControlErrorDescription); 711 accessControlErrorDescription);
712 NETWORK_DVLOG(1) << this << " 2()";
708 return; 713 return;
709 } 714 }
710 715
711 if (!passesPreflightStatusCheck(response, accessControlErrorDescription)) { 716 if (!passesPreflightStatusCheck(response, accessControlErrorDescription)) {
712 handlePreflightFailure(response.url().getString(), 717 handlePreflightFailure(response.url().getString(),
713 accessControlErrorDescription); 718 accessControlErrorDescription);
719 NETWORK_DVLOG(1) << this << " 1()";
714 return; 720 return;
715 } 721 }
716 722
717 if (m_actualRequest.isExternalRequest() && 723 if (m_actualRequest.isExternalRequest() &&
718 !passesExternalPreflightCheck(response, accessControlErrorDescription)) { 724 !passesExternalPreflightCheck(response, accessControlErrorDescription)) {
719 handlePreflightFailure(response.url().getString(), 725 handlePreflightFailure(response.url().getString(),
720 accessControlErrorDescription); 726 accessControlErrorDescription);
727 NETWORK_DVLOG(1) << this << " 3()";
721 return; 728 return;
722 } 729 }
723 730
724 std::unique_ptr<CrossOriginPreflightResultCacheItem> preflightResult = 731 std::unique_ptr<CrossOriginPreflightResultCacheItem> preflightResult =
725 WTF::wrapUnique( 732 WTF::wrapUnique(
726 new CrossOriginPreflightResultCacheItem(effectiveAllowCredentials())); 733 new CrossOriginPreflightResultCacheItem(effectiveAllowCredentials()));
727 if (!preflightResult->parse(response, accessControlErrorDescription) || 734 if (!preflightResult->parse(response, accessControlErrorDescription) ||
728 !preflightResult->allowsCrossOriginMethod( 735 !preflightResult->allowsCrossOriginMethod(
729 m_actualRequest.httpMethod(), accessControlErrorDescription) || 736 m_actualRequest.httpMethod(), accessControlErrorDescription) ||
730 !preflightResult->allowsCrossOriginHeaders( 737 !preflightResult->allowsCrossOriginHeaders(
731 m_actualRequest.httpHeaderFields(), accessControlErrorDescription)) { 738 m_actualRequest.httpHeaderFields(), accessControlErrorDescription)) {
732 handlePreflightFailure(response.url().getString(), 739 handlePreflightFailure(response.url().getString(),
733 accessControlErrorDescription); 740 accessControlErrorDescription);
741 NETWORK_DVLOG(1) << this << " 4() "
742 << accessControlErrorDescription.utf8().data();
734 return; 743 return;
735 } 744 }
736 745
737 CrossOriginPreflightResultCache::shared().appendEntry( 746 CrossOriginPreflightResultCache::shared().appendEntry(
738 getSecurityOrigin()->toString(), m_actualRequest.url(), 747 getSecurityOrigin()->toString(), m_actualRequest.url(),
739 std::move(preflightResult)); 748 std::move(preflightResult));
740 } 749 }
741 750
742 void DocumentThreadableLoader::reportResponseReceived( 751 void DocumentThreadableLoader::reportResponseReceived(
743 unsigned long identifier, 752 unsigned long identifier,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // synchronously, and in such cases ThreadableLoaderClient is already 995 // synchronously, and in such cases ThreadableLoaderClient is already
987 // notified and |client| is null. 996 // notified and |client| is null.
988 if (!client) 997 if (!client)
989 return; 998 return;
990 client->didFail(ResourceError(errorDomainBlinkInternal, 0, 999 client->didFail(ResourceError(errorDomainBlinkInternal, 0,
991 request.url().getString(), 1000 request.url().getString(),
992 "Failed to start loading.")); 1001 "Failed to start loading."));
993 return; 1002 return;
994 } 1003 }
995 1004
996 if (resource()->isLoading()) { 1005 if (!resource()->isLoading()) {
997 unsigned long identifier = resource()->identifier();
998 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(
999 m_document, identifier, m_client);
1000 } else {
1001 InspectorInstrumentation:: 1006 InspectorInstrumentation::
1002 documentThreadableLoaderFailedToStartLoadingForClient(m_document, 1007 documentThreadableLoaderFailedToStartLoadingForClient(m_document,
1003 m_client); 1008 m_client);
1009 return;
1010 }
1011
1012 unsigned long identifier = resource()->identifier();
1013 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(
1014 m_document, identifier, m_client);
1015
1016 if (m_options.schedulerWaitingPolicy == PreventSchedulerFromWaiting) {
1017 LocalFrame* frame = document().frame();
1018 if (frame && frame->frameScheduler())
1019 frame->frameScheduler()->didStopLoading(identifier);
1004 } 1020 }
1005 } 1021 }
1006 1022
1007 void DocumentThreadableLoader::loadRequestSync( 1023 void DocumentThreadableLoader::loadRequestSync(
1008 const ResourceRequest& request, 1024 const ResourceRequest& request,
1009 ResourceLoaderOptions resourceLoaderOptions) { 1025 ResourceLoaderOptions resourceLoaderOptions) {
1010 FetchRequest fetchRequest(request, m_options.initiator, 1026 FetchRequest fetchRequest(request, m_options.initiator,
1011 resourceLoaderOptions); 1027 resourceLoaderOptions);
1012 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) 1028 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests)
1013 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); 1029 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 } 1132 }
1117 1133
1118 DEFINE_TRACE(DocumentThreadableLoader) { 1134 DEFINE_TRACE(DocumentThreadableLoader) {
1119 visitor->trace(m_resource); 1135 visitor->trace(m_resource);
1120 visitor->trace(m_document); 1136 visitor->trace(m_document);
1121 ThreadableLoader::trace(visitor); 1137 ThreadableLoader::trace(visitor);
1122 RawResourceClient::trace(visitor); 1138 RawResourceClient::trace(visitor);
1123 } 1139 }
1124 1140
1125 } // namespace blink 1141 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698