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

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

Issue 379113002: Move fetch-related predicates to core/fetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months 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 17 matching lines...) Expand all
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "core/loader/DocumentThreadableLoader.h" 33 #include "core/loader/DocumentThreadableLoader.h"
34 34
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/fetch/CrossOriginAccessControl.h" 36 #include "core/fetch/CrossOriginAccessControl.h"
37 #include "core/fetch/FetchRequest.h" 37 #include "core/fetch/FetchRequest.h"
38 #include "core/fetch/FetchUtils.h"
38 #include "core/fetch/Resource.h" 39 #include "core/fetch/Resource.h"
39 #include "core/fetch/ResourceFetcher.h" 40 #include "core/fetch/ResourceFetcher.h"
40 #include "core/frame/LocalFrame.h" 41 #include "core/frame/LocalFrame.h"
41 #include "core/frame/csp/ContentSecurityPolicy.h" 42 #include "core/frame/csp/ContentSecurityPolicy.h"
42 #include "core/inspector/InspectorInstrumentation.h" 43 #include "core/inspector/InspectorInstrumentation.h"
43 #include "core/inspector/InspectorTraceEvents.h" 44 #include "core/inspector/InspectorTraceEvents.h"
44 #include "core/loader/CrossOriginPreflightResultCache.h" 45 #include "core/loader/CrossOriginPreflightResultCache.h"
45 #include "core/loader/DocumentThreadableLoaderClient.h" 46 #include "core/loader/DocumentThreadableLoaderClient.h"
46 #include "core/loader/FrameLoader.h" 47 #include "core/loader/FrameLoader.h"
47 #include "core/loader/ThreadableLoaderClient.h" 48 #include "core/loader/ThreadableLoaderClient.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 { 84 {
84 ASSERT(client); 85 ASSERT(client);
85 // Setting an outgoing referer is only supported in the async code path. 86 // Setting an outgoing referer is only supported in the async code path.
86 ASSERT(m_async || request.httpReferrer().isEmpty()); 87 ASSERT(m_async || request.httpReferrer().isEmpty());
87 88
88 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request 89 // Save any CORS simple headers on the request here. If this request redirec ts cross-origin, we cancel the old request
89 // create a new one, and copy these headers. 90 // create a new one, and copy these headers.
90 const HTTPHeaderMap& headerMap = request.httpHeaderFields(); 91 const HTTPHeaderMap& headerMap = request.httpHeaderFields();
91 HTTPHeaderMap::const_iterator end = headerMap.end(); 92 HTTPHeaderMap::const_iterator end = headerMap.end();
92 for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) { 93 for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) {
93 if (isOnAccessControlSimpleRequestHeaderWhitelist(it->key, it->value)) 94 if (FetchUtils::isSimpleHeader(it->key, it->value))
94 m_simpleRequestHeaders.add(it->key, it->value); 95 m_simpleRequestHeaders.add(it->key, it->value);
95 } 96 }
96 97
97 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) { 98 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) {
98 loadRequest(request, m_resourceLoaderOptions); 99 loadRequest(request, m_resourceLoaderOptions);
99 return; 100 return;
100 } 101 }
101 102
102 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) { 103 if (m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) {
103 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported.")); 104 m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url ().string(), "Cross origin requests are not supported."));
104 return; 105 return;
105 } 106 }
106 107
107 makeCrossOriginAccessRequest(request); 108 makeCrossOriginAccessRequest(request);
108 } 109 }
109 110
110 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques t& request) 111 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques t& request)
111 { 112 {
112 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); 113 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
113 114
114 // Cross-origin requests are only allowed certain registered schemes. 115 // Cross-origin requests are only allowed certain registered schemes.
115 // We would catch this when checking response headers later, but there 116 // We would catch this when checking response headers later, but there
116 // is no reason to send a request, preflighted or not, that's guaranteed 117 // is no reason to send a request, preflighted or not, that's guaranteed
117 // to be denied. 118 // to be denied.
118 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protoco l())) { 119 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protoco l())) {
119 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIntern al, 0, request.url().string(), "Cross origin requests are only supported for pro tocol schemes: " + SchemeRegistry::listOfCORSEnabledURLSchemes() + ".")); 120 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIntern al, 0, request.url().string(), "Cross origin requests are only supported for pro tocol schemes: " + SchemeRegistry::listOfCORSEnabledURLSchemes() + "."));
120 return; 121 return;
121 } 122 }
122 123
123 if ((m_options.preflightPolicy == ConsiderPreflight && isSimpleCrossOriginAc cessRequest(request.httpMethod(), request.httpHeaderFields())) || m_options.pref lightPolicy == PreventPreflight) { 124 if ((m_options.preflightPolicy == ConsiderPreflight && FetchUtils::isSimpleO rForbiddenRequest(request.httpMethod(), request.httpHeaderFields())) || m_option s.preflightPolicy == PreventPreflight) {
124 ResourceRequest crossOriginRequest(request); 125 ResourceRequest crossOriginRequest(request);
125 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions); 126 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions);
126 updateRequestForAccessControl(crossOriginRequest, securityOrigin(), effe ctiveAllowCredentials()); 127 updateRequestForAccessControl(crossOriginRequest, securityOrigin(), effe ctiveAllowCredentials());
127 loadRequest(crossOriginRequest, crossOriginOptions); 128 loadRequest(crossOriginRequest, crossOriginOptions);
128 } else { 129 } else {
129 m_simpleRequest = false; 130 m_simpleRequest = false;
130 131
131 OwnPtr<ResourceRequest> crossOriginRequest = adoptPtr(new ResourceReques t(request)); 132 OwnPtr<ResourceRequest> crossOriginRequest = adoptPtr(new ResourceReques t(request));
132 OwnPtr<ResourceLoaderOptions> crossOriginOptions = adoptPtr(new Resource LoaderOptions(m_resourceLoaderOptions)); 133 OwnPtr<ResourceLoaderOptions> crossOriginOptions = adoptPtr(new Resource LoaderOptions(m_resourceLoaderOptions));
133 // Do not set the Origin header for preflight requests. 134 // Do not set the Origin header for preflight requests.
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 else 388 else
388 handleSuccessfulFinish(resource->identifier(), resource->loadFinishTime( )); 389 handleSuccessfulFinish(resource->identifier(), resource->loadFinishTime( ));
389 } 390 }
390 391
391 void DocumentThreadableLoader::handleSuccessfulFinish(unsigned long identifier, double finishTime) 392 void DocumentThreadableLoader::handleSuccessfulFinish(unsigned long identifier, double finishTime)
392 { 393 {
393 if (m_actualRequest) { 394 if (m_actualRequest) {
394 ASSERT(!m_sameOriginRequest); 395 ASSERT(!m_sameOriginRequest);
395 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); 396 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
396 loadActualRequest(); 397 loadActualRequest();
397 } else 398 } else {
398 m_client->didFinishLoading(identifier, finishTime); 399 m_client->didFinishLoading(identifier, finishTime);
400 }
399 } 401 }
400 402
401 void DocumentThreadableLoader::didTimeout(Timer<DocumentThreadableLoader>* timer ) 403 void DocumentThreadableLoader::didTimeout(Timer<DocumentThreadableLoader>* timer )
402 { 404 {
403 ASSERT_UNUSED(timer, timer == &m_timeoutTimer); 405 ASSERT_UNUSED(timer, timer == &m_timeoutTimer);
404 406
405 // Using values from net/base/net_error_list.h ERR_TIMED_OUT, 407 // Using values from net/base/net_error_list.h ERR_TIMED_OUT,
406 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable. 408 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable.
407 static const int timeoutError = -7; 409 static const int timeoutError = -7;
408 ResourceError error("net", timeoutError, resource()->url(), String()); 410 ResourceError error("net", timeoutError, resource()->url(), String());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return DoNotAllowStoredCredentials; 531 return DoNotAllowStoredCredentials;
530 return m_resourceLoaderOptions.allowCredentials; 532 return m_resourceLoaderOptions.allowCredentials;
531 } 533 }
532 534
533 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const 535 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const
534 { 536 {
535 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin (); 537 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin ();
536 } 538 }
537 539
538 } // namespace blink 540 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/CrossOriginPreflightResultCache.cpp ('k') | Source/core/xml/XMLHttpRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698