Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 23 matching lines...) Expand all Loading... | |
| 34 #include <memory> | 34 #include <memory> |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/TaskRunnerHelper.h" | 36 #include "core/dom/TaskRunnerHelper.h" |
| 37 #include "core/frame/FrameConsole.h" | 37 #include "core/frame/FrameConsole.h" |
| 38 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
| 39 #include "core/frame/LocalFrameClient.h" | 39 #include "core/frame/LocalFrameClient.h" |
| 40 #include "core/inspector/InspectorInstrumentation.h" | 40 #include "core/inspector/InspectorInstrumentation.h" |
| 41 #include "core/inspector/InspectorTraceEvents.h" | 41 #include "core/inspector/InspectorTraceEvents.h" |
| 42 #include "core/loader/DocumentThreadableLoaderClient.h" | 42 #include "core/loader/DocumentThreadableLoaderClient.h" |
| 43 #include "core/loader/FrameLoader.h" | 43 #include "core/loader/FrameLoader.h" |
| 44 #include "core/loader/LoadingContext.h" | |
| 44 #include "core/loader/ThreadableLoaderClient.h" | 45 #include "core/loader/ThreadableLoaderClient.h" |
| 45 #include "core/loader/private/CrossOriginPreflightResultCache.h" | 46 #include "core/loader/private/CrossOriginPreflightResultCache.h" |
| 46 #include "core/page/ChromeClient.h" | 47 #include "core/page/ChromeClient.h" |
| 47 #include "core/page/Page.h" | 48 #include "core/page/Page.h" |
| 48 #include "platform/SharedBuffer.h" | 49 #include "platform/SharedBuffer.h" |
| 49 #include "platform/loader/fetch/CrossOriginAccessControl.h" | 50 #include "platform/loader/fetch/CrossOriginAccessControl.h" |
| 50 #include "platform/loader/fetch/FetchRequest.h" | 51 #include "platform/loader/fetch/FetchRequest.h" |
| 51 #include "platform/loader/fetch/FetchUtils.h" | 52 #include "platform/loader/fetch/FetchUtils.h" |
| 52 #include "platform/loader/fetch/Resource.h" | 53 #include "platform/loader/fetch/Resource.h" |
| 53 #include "platform/loader/fetch/ResourceFetcher.h" | 54 #include "platform/loader/fetch/ResourceFetcher.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 // FIXME: currently the number of redirects is counted and limited here and in | 132 // FIXME: currently the number of redirects is counted and limited here and in |
| 132 // net/url_request/url_request.cc separately. | 133 // net/url_request/url_request.cc separately. |
| 133 static const int kMaxCORSRedirects = 20; | 134 static const int kMaxCORSRedirects = 20; |
| 134 | 135 |
| 135 void DocumentThreadableLoader::loadResourceSynchronously( | 136 void DocumentThreadableLoader::loadResourceSynchronously( |
| 136 Document& document, | 137 Document& document, |
| 137 const ResourceRequest& request, | 138 const ResourceRequest& request, |
| 138 ThreadableLoaderClient& client, | 139 ThreadableLoaderClient& client, |
| 139 const ThreadableLoaderOptions& options, | 140 const ThreadableLoaderOptions& options, |
| 140 const ResourceLoaderOptions& resourceLoaderOptions) { | 141 const ResourceLoaderOptions& resourceLoaderOptions) { |
| 141 (new DocumentThreadableLoader(document, &client, LoadSynchronously, options, | 142 (new DocumentThreadableLoader(*LoadingContext::create(document), &client, |
| 143 LoadSynchronously, options, | |
| 142 resourceLoaderOptions)) | 144 resourceLoaderOptions)) |
| 143 ->start(request); | 145 ->start(request); |
| 144 } | 146 } |
| 145 | 147 |
| 146 DocumentThreadableLoader* DocumentThreadableLoader::create( | 148 DocumentThreadableLoader* DocumentThreadableLoader::create( |
|
Nate Chapin
2017/02/28 20:47:18
It's a bit confusing that this create() version an
kinuko
2017/03/01 15:08:28
Agreed, done.
| |
| 147 Document& document, | 149 Document& document, |
| 148 ThreadableLoaderClient* client, | 150 ThreadableLoaderClient* client, |
| 149 const ThreadableLoaderOptions& options, | 151 const ThreadableLoaderOptions& options, |
| 150 const ResourceLoaderOptions& resourceLoaderOptions) { | 152 const ResourceLoaderOptions& resourceLoaderOptions) { |
| 151 return new DocumentThreadableLoader(document, client, LoadAsynchronously, | 153 return new DocumentThreadableLoader(*LoadingContext::create(document), client, |
| 152 options, resourceLoaderOptions); | 154 LoadAsynchronously, options, |
| 155 resourceLoaderOptions); | |
| 156 } | |
| 157 | |
| 158 DocumentThreadableLoader* DocumentThreadableLoader::create( | |
| 159 LoadingContext& loadingContext, | |
| 160 ThreadableLoaderClient* client, | |
| 161 const ThreadableLoaderOptions& options, | |
| 162 const ResourceLoaderOptions& resourceLoaderOptions) { | |
| 163 return new DocumentThreadableLoader(loadingContext, client, | |
| 164 LoadAsynchronously, options, | |
| 165 resourceLoaderOptions); | |
| 153 } | 166 } |
| 154 | 167 |
| 155 DocumentThreadableLoader::DocumentThreadableLoader( | 168 DocumentThreadableLoader::DocumentThreadableLoader( |
| 156 Document& document, | 169 LoadingContext& loadingContext, |
| 157 ThreadableLoaderClient* client, | 170 ThreadableLoaderClient* client, |
| 158 BlockingBehavior blockingBehavior, | 171 BlockingBehavior blockingBehavior, |
| 159 const ThreadableLoaderOptions& options, | 172 const ThreadableLoaderOptions& options, |
| 160 const ResourceLoaderOptions& resourceLoaderOptions) | 173 const ResourceLoaderOptions& resourceLoaderOptions) |
| 161 : m_client(client), | 174 : m_client(client), |
| 162 m_document(&document), | 175 m_loadingContext(&loadingContext), |
| 163 m_options(options), | 176 m_options(options), |
| 164 m_resourceLoaderOptions(resourceLoaderOptions), | 177 m_resourceLoaderOptions(resourceLoaderOptions), |
| 165 m_forceDoNotAllowStoredCredentials(false), | 178 m_forceDoNotAllowStoredCredentials(false), |
| 166 m_securityOrigin(m_resourceLoaderOptions.securityOrigin), | 179 m_securityOrigin(m_resourceLoaderOptions.securityOrigin), |
| 167 m_sameOriginRequest(false), | 180 m_sameOriginRequest(false), |
| 168 m_isUsingDataConsumerHandle(false), | 181 m_isUsingDataConsumerHandle(false), |
| 169 m_async(blockingBehavior == LoadAsynchronously), | 182 m_async(blockingBehavior == LoadAsynchronously), |
| 170 m_requestContext(WebURLRequest::RequestContextUnspecified), | 183 m_requestContext(WebURLRequest::RequestContextUnspecified), |
| 171 m_timeoutTimer(TaskRunnerHelper::get(TaskType::Networking, &document), | 184 m_timeoutTimer(m_loadingContext->getTaskRunner(TaskType::Networking), |
| 172 this, | 185 this, |
| 173 &DocumentThreadableLoader::didTimeout), | 186 &DocumentThreadableLoader::didTimeout), |
| 174 m_requestStartedSeconds(0.0), | 187 m_requestStartedSeconds(0.0), |
| 175 m_corsRedirectLimit(m_options.crossOriginRequestPolicy == UseAccessControl | 188 m_corsRedirectLimit(m_options.crossOriginRequestPolicy == UseAccessControl |
| 176 ? kMaxCORSRedirects | 189 ? kMaxCORSRedirects |
| 177 : 0), | 190 : 0), |
| 178 m_redirectMode(WebURLRequest::FetchRedirectModeFollow), | 191 m_redirectMode(WebURLRequest::FetchRedirectModeFollow), |
| 179 m_overrideReferrer(false) { | 192 m_overrideReferrer(false) { |
| 180 DCHECK(client); | 193 DCHECK(client); |
| 181 } | 194 } |
| 182 | 195 |
| 183 void DocumentThreadableLoader::start(const ResourceRequest& request) { | 196 void DocumentThreadableLoader::start(const ResourceRequest& request) { |
| 184 // Setting an outgoing referer is only supported in the async code path. | 197 // Setting an outgoing referer is only supported in the async code path. |
| 185 DCHECK(m_async || request.httpReferrer().isEmpty()); | 198 DCHECK(m_async || request.httpReferrer().isEmpty()); |
| 186 | 199 |
| 187 m_sameOriginRequest = | 200 m_sameOriginRequest = |
| 188 getSecurityOrigin()->canRequestNoSuborigin(request.url()); | 201 getSecurityOrigin()->canRequestNoSuborigin(request.url()); |
| 189 m_requestContext = request.requestContext(); | 202 m_requestContext = request.requestContext(); |
| 190 m_redirectMode = request.fetchRedirectMode(); | 203 m_redirectMode = request.fetchRedirectMode(); |
| 191 | 204 |
| 192 if (!m_sameOriginRequest && | 205 if (!m_sameOriginRequest && |
| 193 m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) { | 206 m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) { |
| 194 InspectorInstrumentation:: | 207 InspectorInstrumentation:: |
| 195 documentThreadableLoaderFailedToStartLoadingForClient(m_document, | 208 documentThreadableLoaderFailedToStartLoadingForClient(document(), |
| 196 m_client); | 209 m_client); |
| 197 ThreadableLoaderClient* client = m_client; | 210 ThreadableLoaderClient* client = m_client; |
| 198 clear(); | 211 clear(); |
| 199 client->didFail(ResourceError(errorDomainBlinkInternal, 0, | 212 client->didFail(ResourceError(errorDomainBlinkInternal, 0, |
| 200 request.url().getString(), | 213 request.url().getString(), |
| 201 "Cross origin requests are not supported.")); | 214 "Cross origin requests are not supported.")); |
| 202 return; | 215 return; |
| 203 } | 216 } |
| 204 | 217 |
| 205 m_requestStartedSeconds = monotonicallyIncreasingTime(); | 218 m_requestStartedSeconds = monotonicallyIncreasingTime(); |
| 206 | 219 |
| 207 // Save any headers on the request here. If this request redirects | 220 // Save any headers on the request here. If this request redirects |
| 208 // cross-origin, we cancel the old request create a new one, and copy these | 221 // cross-origin, we cancel the old request create a new one, and copy these |
| 209 // headers. | 222 // headers. |
| 210 m_requestHeaders = request.httpHeaderFields(); | 223 m_requestHeaders = request.httpHeaderFields(); |
| 211 | 224 |
| 212 // DocumentThreadableLoader is used by all javascript initiated fetch, so we | 225 // DocumentThreadableLoader is used by all javascript initiated fetch, so we |
| 213 // use this chance to record non-GET fetch script requests. However, this is | 226 // use this chance to record non-GET fetch script requests. However, this is |
| 214 // based on the following assumptions, so please be careful when adding | 227 // based on the following assumptions, so please be careful when adding |
| 215 // similar logic: | 228 // similar logic: |
| 216 // - ThreadableLoader is used as backend for all javascript initiated network | 229 // - ThreadableLoader is used as backend for all javascript initiated network |
| 217 // fetches. | 230 // fetches. |
| 218 // - Note that ThreadableLoader is also used for non-network fetch such as | 231 // - Note that ThreadableLoader is also used for non-network fetch such as |
| 219 // FileReaderLoader. However it emulates GET method so signal is not | 232 // FileReaderLoader. However it emulates GET method so signal is not |
| 220 // recorded here. | 233 // recorded here. |
| 221 // - ThreadableLoader w/ non-GET request is only created from javascript | 234 // - ThreadableLoader w/ non-GET request is only created from javascript |
| 222 // initiated fetch. | 235 // initiated fetch. |
| 223 // - Some non-script initiated fetches such as WorkerScriptLoader also use | 236 // - Some non-script initiated fetches such as WorkerScriptLoader also use |
| 224 // ThreadableLoader, but they are guaranteed to use GET method. | 237 // ThreadableLoader, but they are guaranteed to use GET method. |
| 225 if (request.httpMethod() != HTTPNames::GET) { | 238 if (request.httpMethod() != HTTPNames::GET && document()) { |
| 226 if (Page* page = m_document->page()) | 239 if (Page* page = document()->page()) |
| 227 page->chromeClient().didObserveNonGetFetchFromScript(); | 240 page->chromeClient().didObserveNonGetFetchFromScript(); |
| 228 } | 241 } |
| 229 | 242 |
| 230 ResourceRequest newRequest(request); | 243 ResourceRequest newRequest(request); |
| 231 if (m_requestContext != WebURLRequest::RequestContextFetch) { | 244 if (m_requestContext != WebURLRequest::RequestContextFetch) { |
| 232 // When the request context is not "fetch", |crossOriginRequestPolicy| | 245 // When the request context is not "fetch", |crossOriginRequestPolicy| |
| 233 // represents the fetch request mode, and |credentialsRequested| represents | 246 // represents the fetch request mode, and |credentialsRequested| represents |
| 234 // the fetch credentials mode. So we set those flags here so that we can see | 247 // the fetch credentials mode. So we set those flags here so that we can see |
| 235 // the correct request mode and credentials mode in the service worker's | 248 // the correct request mode and credentials mode in the service worker's |
| 236 // fetch event handler. | 249 // fetch event handler. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 261 WebURLRequest::FetchCredentialsModeSameOrigin); | 274 WebURLRequest::FetchCredentialsModeSameOrigin); |
| 262 } | 275 } |
| 263 } | 276 } |
| 264 | 277 |
| 265 // We assume that ServiceWorker is skipped for sync requests and unsupported | 278 // We assume that ServiceWorker is skipped for sync requests and unsupported |
| 266 // protocol requests by content/ code. | 279 // protocol requests by content/ code. |
| 267 if (m_async && | 280 if (m_async && |
| 268 request.getServiceWorkerMode() == WebURLRequest::ServiceWorkerMode::All && | 281 request.getServiceWorkerMode() == WebURLRequest::ServiceWorkerMode::All && |
| 269 SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( | 282 SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers( |
| 270 request.url().protocol()) && | 283 request.url().protocol()) && |
| 271 m_document->fetcher()->isControlledByServiceWorker()) { | 284 m_loadingContext->getResourceFetcher()->isControlledByServiceWorker()) { |
| 272 if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS || | 285 if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS || |
| 273 newRequest.fetchRequestMode() == | 286 newRequest.fetchRequestMode() == |
| 274 WebURLRequest::FetchRequestModeCORSWithForcedPreflight) { | 287 WebURLRequest::FetchRequestModeCORSWithForcedPreflight) { |
| 275 m_fallbackRequestForServiceWorker = ResourceRequest(request); | 288 m_fallbackRequestForServiceWorker = ResourceRequest(request); |
| 276 // m_fallbackRequestForServiceWorker is used when a regular controlling | 289 // m_fallbackRequestForServiceWorker is used when a regular controlling |
| 277 // service worker doesn't handle a cross origin request. When this happens | 290 // service worker doesn't handle a cross origin request. When this happens |
| 278 // we still want to give foreign fetch a chance to handle the request, so | 291 // we still want to give foreign fetch a chance to handle the request, so |
| 279 // only skip the controlling service worker for the fallback request. This | 292 // only skip the controlling service worker for the fallback request. This |
| 280 // is currently safe because of http://crbug.com/604084 the | 293 // is currently safe because of http://crbug.com/604084 the |
| 281 // wasFallbackRequiredByServiceWorker flag is never set when foreign fetch | 294 // wasFallbackRequiredByServiceWorker flag is never set when foreign fetch |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 request.isExternalRequest()); | 332 request.isExternalRequest()); |
| 320 DCHECK(m_client); | 333 DCHECK(m_client); |
| 321 DCHECK(!resource()); | 334 DCHECK(!resource()); |
| 322 | 335 |
| 323 // Cross-origin requests are only allowed certain registered schemes. We would | 336 // Cross-origin requests are only allowed certain registered schemes. We would |
| 324 // catch this when checking response headers later, but there is no reason to | 337 // catch this when checking response headers later, but there is no reason to |
| 325 // send a request, preflighted or not, that's guaranteed to be denied. | 338 // send a request, preflighted or not, that's guaranteed to be denied. |
| 326 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled( | 339 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled( |
| 327 request.url().protocol())) { | 340 request.url().protocol())) { |
| 328 InspectorInstrumentation:: | 341 InspectorInstrumentation:: |
| 329 documentThreadableLoaderFailedToStartLoadingForClient(m_document, | 342 documentThreadableLoaderFailedToStartLoadingForClient(document(), |
| 330 m_client); | 343 m_client); |
| 331 dispatchDidFailAccessControlCheck(ResourceError( | 344 dispatchDidFailAccessControlCheck(ResourceError( |
| 332 errorDomainBlinkInternal, 0, request.url().getString(), | 345 errorDomainBlinkInternal, 0, request.url().getString(), |
| 333 "Cross origin requests are only supported for protocol schemes: " + | 346 "Cross origin requests are only supported for protocol schemes: " + |
| 334 SchemeRegistry::listOfCORSEnabledURLSchemes() + ".")); | 347 SchemeRegistry::listOfCORSEnabledURLSchemes() + ".")); |
| 335 return; | 348 return; |
| 336 } | 349 } |
| 337 | 350 |
| 338 // Non-secure origins may not make "external requests": | 351 // Non-secure origins may not make "external requests": |
| 339 // https://mikewest.github.io/cors-rfc1918/#integration-fetch | 352 // https://mikewest.github.io/cors-rfc1918/#integration-fetch |
| 340 if (!document().isSecureContext() && request.isExternalRequest()) { | 353 if (!m_loadingContext->isSecureContext() && request.isExternalRequest()) { |
| 341 dispatchDidFailAccessControlCheck( | 354 dispatchDidFailAccessControlCheck( |
| 342 ResourceError(errorDomainBlinkInternal, 0, request.url().getString(), | 355 ResourceError(errorDomainBlinkInternal, 0, request.url().getString(), |
| 343 "Requests to internal network resources are not allowed " | 356 "Requests to internal network resources are not allowed " |
| 344 "from non-secure contexts (see https://goo.gl/Y0ZkNV). " | 357 "from non-secure contexts (see https://goo.gl/Y0ZkNV). " |
| 345 "This is an experimental restriction which is part of " | 358 "This is an experimental restriction which is part of " |
| 346 "'https://mikewest.github.io/cors-rfc1918/'.")); | 359 "'https://mikewest.github.io/cors-rfc1918/'.")); |
| 347 return; | 360 return; |
| 348 } | 361 } |
| 349 | 362 |
| 350 ResourceRequest crossOriginRequest(request); | 363 ResourceRequest crossOriginRequest(request); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 380 // page when this request gets sent later. We should not send the actual | 393 // page when this request gets sent later. We should not send the actual |
| 381 // request to the SW. https://crbug.com/604583 | 394 // request to the SW. https://crbug.com/604583 |
| 382 // Similarly we don't want any requests that could involve a CORS preflight | 395 // Similarly we don't want any requests that could involve a CORS preflight |
| 383 // to get intercepted by a foreign fetch service worker, even if we have the | 396 // to get intercepted by a foreign fetch service worker, even if we have the |
| 384 // result of the preflight cached already. https://crbug.com/674370 | 397 // result of the preflight cached already. https://crbug.com/674370 |
| 385 crossOriginRequest.setServiceWorkerMode( | 398 crossOriginRequest.setServiceWorkerMode( |
| 386 WebURLRequest::ServiceWorkerMode::None); | 399 WebURLRequest::ServiceWorkerMode::None); |
| 387 | 400 |
| 388 bool shouldForcePreflight = | 401 bool shouldForcePreflight = |
| 389 request.isExternalRequest() || | 402 request.isExternalRequest() || |
| 390 InspectorInstrumentation::shouldForceCORSPreflight(m_document); | 403 InspectorInstrumentation::shouldForceCORSPreflight(document()); |
| 391 bool canSkipPreflight = | 404 bool canSkipPreflight = |
| 392 CrossOriginPreflightResultCache::shared().canSkipPreflight( | 405 CrossOriginPreflightResultCache::shared().canSkipPreflight( |
| 393 getSecurityOrigin()->toString(), crossOriginRequest.url(), | 406 getSecurityOrigin()->toString(), crossOriginRequest.url(), |
| 394 effectiveAllowCredentials(), crossOriginRequest.httpMethod(), | 407 effectiveAllowCredentials(), crossOriginRequest.httpMethod(), |
| 395 crossOriginRequest.httpHeaderFields()); | 408 crossOriginRequest.httpHeaderFields()); |
| 396 if (canSkipPreflight && !shouldForcePreflight) { | 409 if (canSkipPreflight && !shouldForcePreflight) { |
| 397 prepareCrossOriginRequest(crossOriginRequest); | 410 prepareCrossOriginRequest(crossOriginRequest); |
| 398 loadRequest(crossOriginRequest, crossOriginOptions); | 411 loadRequest(crossOriginRequest, crossOriginOptions); |
| 399 } else { | 412 } else { |
| 400 ResourceRequest preflightRequest = | 413 ResourceRequest preflightRequest = |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 | 558 |
| 546 if (m_corsRedirectLimit <= 0) { | 559 if (m_corsRedirectLimit <= 0) { |
| 547 ThreadableLoaderClient* client = m_client; | 560 ThreadableLoaderClient* client = m_client; |
| 548 clear(); | 561 clear(); |
| 549 client->didFailRedirectCheck(); | 562 client->didFailRedirectCheck(); |
| 550 return false; | 563 return false; |
| 551 } | 564 } |
| 552 | 565 |
| 553 --m_corsRedirectLimit; | 566 --m_corsRedirectLimit; |
| 554 | 567 |
| 555 InspectorInstrumentation::didReceiveCORSRedirectResponse( | 568 if (document() && document()->frame()) { |
| 556 document().frame(), resource->identifier(), | 569 InspectorInstrumentation::didReceiveCORSRedirectResponse( |
| 557 document().frame()->loader().documentLoader(), redirectResponse, | 570 document()->frame(), resource->identifier(), |
| 558 resource); | 571 document()->frame()->loader().documentLoader(), redirectResponse, |
| 572 resource); | |
| 573 } | |
| 559 | 574 |
| 560 String accessControlErrorDescription; | 575 String accessControlErrorDescription; |
| 561 | 576 |
| 562 CrossOriginAccessControl::RedirectStatus redirectStatus = | 577 CrossOriginAccessControl::RedirectStatus redirectStatus = |
| 563 CrossOriginAccessControl::checkRedirectLocation(request.url()); | 578 CrossOriginAccessControl::checkRedirectLocation(request.url()); |
| 564 bool allowRedirect = | 579 bool allowRedirect = |
| 565 redirectStatus == CrossOriginAccessControl::kRedirectSuccess; | 580 redirectStatus == CrossOriginAccessControl::kRedirectSuccess; |
| 566 if (!allowRedirect) { | 581 if (!allowRedirect) { |
| 567 StringBuilder builder; | 582 StringBuilder builder; |
| 568 builder.append("Redirect from '"); | 583 builder.append("Redirect from '"); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 } | 775 } |
| 761 | 776 |
| 762 CrossOriginPreflightResultCache::shared().appendEntry( | 777 CrossOriginPreflightResultCache::shared().appendEntry( |
| 763 getSecurityOrigin()->toString(), m_actualRequest.url(), | 778 getSecurityOrigin()->toString(), m_actualRequest.url(), |
| 764 std::move(preflightResult)); | 779 std::move(preflightResult)); |
| 765 } | 780 } |
| 766 | 781 |
| 767 void DocumentThreadableLoader::reportResponseReceived( | 782 void DocumentThreadableLoader::reportResponseReceived( |
| 768 unsigned long identifier, | 783 unsigned long identifier, |
| 769 const ResourceResponse& response) { | 784 const ResourceResponse& response) { |
| 770 LocalFrame* frame = document().frame(); | 785 LocalFrame* frame = document() ? document()->frame() : nullptr; |
| 771 // We are seeing crashes caused by nullptr (crbug.com/578849). But the frame | |
| 772 // must be set here. TODO(horo): Find the root cause of the unset frame. | |
| 773 DCHECK(frame); | |
| 774 if (!frame) | 786 if (!frame) |
| 775 return; | 787 return; |
| 776 TRACE_EVENT1( | 788 TRACE_EVENT1( |
| 777 "devtools.timeline", "ResourceReceiveResponse", "data", | 789 "devtools.timeline", "ResourceReceiveResponse", "data", |
| 778 InspectorReceiveResponseEvent::data(identifier, frame, response)); | 790 InspectorReceiveResponseEvent::data(identifier, frame, response)); |
| 779 DocumentLoader* loader = frame->loader().documentLoader(); | 791 DocumentLoader* loader = frame->loader().documentLoader(); |
| 780 InspectorInstrumentation::didReceiveResourceResponse( | 792 InspectorInstrumentation::didReceiveResourceResponse( |
| 781 frame, identifier, loader, response, resource()); | 793 frame, identifier, loader, response, resource()); |
| 782 frame->console().reportResourceResponseReceived(loader, identifier, response); | 794 frame->console().reportResourceResponseReceived(loader, identifier, response); |
| 783 } | 795 } |
| 784 | 796 |
| 785 void DocumentThreadableLoader::handleResponse( | 797 void DocumentThreadableLoader::handleResponse( |
| 786 unsigned long identifier, | 798 unsigned long identifier, |
| 787 const ResourceResponse& response, | 799 const ResourceResponse& response, |
| 788 std::unique_ptr<WebDataConsumerHandle> handle) { | 800 std::unique_ptr<WebDataConsumerHandle> handle) { |
| 789 DCHECK(m_client); | 801 DCHECK(m_client); |
| 790 | 802 |
| 791 if (!m_actualRequest.isNull()) { | 803 if (!m_actualRequest.isNull()) { |
| 792 reportResponseReceived(identifier, response); | 804 reportResponseReceived(identifier, response); |
| 793 handlePreflightResponse(response); | 805 handlePreflightResponse(response); |
| 794 return; | 806 return; |
| 795 } | 807 } |
| 796 | 808 |
| 797 if (response.wasFetchedViaServiceWorker()) { | 809 if (response.wasFetchedViaServiceWorker()) { |
| 798 if (response.wasFetchedViaForeignFetch()) | 810 if (response.wasFetchedViaForeignFetch()) |
| 799 UseCounter::count(m_document, UseCounter::ForeignFetchInterception); | 811 m_loadingContext->recordUseCount(UseCounter::ForeignFetchInterception); |
| 800 if (response.wasFallbackRequiredByServiceWorker()) { | 812 if (response.wasFallbackRequiredByServiceWorker()) { |
| 801 // At this point we must have m_fallbackRequestForServiceWorker. (For | 813 // At this point we must have m_fallbackRequestForServiceWorker. (For |
| 802 // SharedWorker the request won't be CORS or CORS-with-preflight, | 814 // SharedWorker the request won't be CORS or CORS-with-preflight, |
| 803 // therefore fallback-to-network is handled in the browser process when | 815 // therefore fallback-to-network is handled in the browser process when |
| 804 // the ServiceWorker does not call respondWith().) | 816 // the ServiceWorker does not call respondWith().) |
| 805 DCHECK(!m_fallbackRequestForServiceWorker.isNull()); | 817 DCHECK(!m_fallbackRequestForServiceWorker.isNull()); |
| 806 reportResponseReceived(identifier, response); | 818 reportResponseReceived(identifier, response); |
| 807 loadFallbackRequestForServiceWorker(); | 819 loadFallbackRequestForServiceWorker(); |
| 808 return; | 820 return; |
| 809 } | 821 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 995 if (m_options.timeoutMilliseconds > 0) { | 1007 if (m_options.timeoutMilliseconds > 0) { |
| 996 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, | 1008 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, |
| 997 BLINK_FROM_HERE); | 1009 BLINK_FROM_HERE); |
| 998 } | 1010 } |
| 999 | 1011 |
| 1000 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOptions); | 1012 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOptions); |
| 1001 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 1013 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
| 1002 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); | 1014 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); |
| 1003 DCHECK(!resource()); | 1015 DCHECK(!resource()); |
| 1004 | 1016 |
| 1017 ResourceFetcher* fetcher = m_loadingContext->getResourceFetcher(); | |
| 1005 if (request.requestContext() == WebURLRequest::RequestContextVideo || | 1018 if (request.requestContext() == WebURLRequest::RequestContextVideo || |
| 1006 request.requestContext() == WebURLRequest::RequestContextAudio) | 1019 request.requestContext() == WebURLRequest::RequestContextAudio) |
| 1007 setResource(RawResource::fetchMedia(newRequest, document().fetcher())); | 1020 setResource(RawResource::fetchMedia(newRequest, fetcher)); |
| 1008 else if (request.requestContext() == WebURLRequest::RequestContextManifest) | 1021 else if (request.requestContext() == WebURLRequest::RequestContextManifest) |
| 1009 setResource(RawResource::fetchManifest(newRequest, document().fetcher())); | 1022 setResource(RawResource::fetchManifest(newRequest, fetcher)); |
| 1010 else | 1023 else |
| 1011 setResource(RawResource::fetch(newRequest, document().fetcher())); | 1024 setResource(RawResource::fetch(newRequest, fetcher)); |
| 1012 | 1025 |
| 1013 if (!resource()) { | 1026 if (!resource()) { |
| 1014 InspectorInstrumentation:: | 1027 InspectorInstrumentation:: |
| 1015 documentThreadableLoaderFailedToStartLoadingForClient(m_document, | 1028 documentThreadableLoaderFailedToStartLoadingForClient(document(), |
| 1016 m_client); | 1029 m_client); |
| 1017 ThreadableLoaderClient* client = m_client; | 1030 ThreadableLoaderClient* client = m_client; |
| 1018 clear(); | 1031 clear(); |
| 1019 // setResource() might call notifyFinished() and thus clear() | 1032 // setResource() might call notifyFinished() and thus clear() |
| 1020 // synchronously, and in such cases ThreadableLoaderClient is already | 1033 // synchronously, and in such cases ThreadableLoaderClient is already |
| 1021 // notified and |client| is null. | 1034 // notified and |client| is null. |
| 1022 if (!client) | 1035 if (!client) |
| 1023 return; | 1036 return; |
| 1024 client->didFail(ResourceError(errorDomainBlinkInternal, 0, | 1037 client->didFail(ResourceError(errorDomainBlinkInternal, 0, |
| 1025 request.url().getString(), | 1038 request.url().getString(), |
| 1026 "Failed to start loading.")); | 1039 "Failed to start loading.")); |
| 1027 return; | 1040 return; |
| 1028 } | 1041 } |
| 1029 | 1042 |
| 1030 if (resource()->isLoading()) { | 1043 if (resource()->isLoading()) { |
| 1031 unsigned long identifier = resource()->identifier(); | 1044 unsigned long identifier = resource()->identifier(); |
| 1032 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient( | 1045 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient( |
| 1033 m_document, identifier, m_client); | 1046 document(), identifier, m_client); |
| 1034 } else { | 1047 } else { |
| 1035 InspectorInstrumentation:: | 1048 InspectorInstrumentation:: |
| 1036 documentThreadableLoaderFailedToStartLoadingForClient(m_document, | 1049 documentThreadableLoaderFailedToStartLoadingForClient(document(), |
| 1037 m_client); | 1050 m_client); |
| 1038 } | 1051 } |
| 1039 } | 1052 } |
| 1040 | 1053 |
| 1041 void DocumentThreadableLoader::loadRequestSync( | 1054 void DocumentThreadableLoader::loadRequestSync( |
| 1042 const ResourceRequest& request, | 1055 const ResourceRequest& request, |
| 1043 ResourceLoaderOptions resourceLoaderOptions) { | 1056 ResourceLoaderOptions resourceLoaderOptions) { |
| 1044 FetchRequest fetchRequest(request, m_options.initiator, | 1057 FetchRequest fetchRequest(request, m_options.initiator, |
| 1045 resourceLoaderOptions); | 1058 resourceLoaderOptions); |
| 1046 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 1059 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
| 1047 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); | 1060 fetchRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); |
| 1048 Resource* resource = | 1061 Resource* resource = RawResource::fetchSynchronously( |
| 1049 RawResource::fetchSynchronously(fetchRequest, document().fetcher()); | 1062 fetchRequest, m_loadingContext->getResourceFetcher()); |
| 1050 ResourceResponse response = | 1063 ResourceResponse response = |
| 1051 resource ? resource->response() : ResourceResponse(); | 1064 resource ? resource->response() : ResourceResponse(); |
| 1052 unsigned long identifier = resource | 1065 unsigned long identifier = resource |
| 1053 ? resource->identifier() | 1066 ? resource->identifier() |
| 1054 : std::numeric_limits<unsigned long>::max(); | 1067 : std::numeric_limits<unsigned long>::max(); |
| 1055 ResourceError error = resource ? resource->resourceError() : ResourceError(); | 1068 ResourceError error = resource ? resource->resourceError() : ResourceError(); |
| 1056 | 1069 |
| 1057 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient( | 1070 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient( |
| 1058 m_document, identifier, m_client); | 1071 document(), identifier, m_client); |
| 1059 ThreadableLoaderClient* client = m_client; | 1072 ThreadableLoaderClient* client = m_client; |
| 1060 | 1073 |
| 1061 if (!resource) { | 1074 if (!resource) { |
| 1062 m_client = nullptr; | 1075 m_client = nullptr; |
| 1063 client->didFail(error); | 1076 client->didFail(error); |
| 1064 return; | 1077 return; |
| 1065 } | 1078 } |
| 1066 | 1079 |
| 1067 const KURL& requestURL = request.url(); | 1080 const KURL& requestURL = request.url(); |
| 1068 | 1081 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1134 } | 1147 } |
| 1135 | 1148 |
| 1136 StoredCredentials DocumentThreadableLoader::effectiveAllowCredentials() const { | 1149 StoredCredentials DocumentThreadableLoader::effectiveAllowCredentials() const { |
| 1137 if (m_forceDoNotAllowStoredCredentials) | 1150 if (m_forceDoNotAllowStoredCredentials) |
| 1138 return DoNotAllowStoredCredentials; | 1151 return DoNotAllowStoredCredentials; |
| 1139 return m_resourceLoaderOptions.allowCredentials; | 1152 return m_resourceLoaderOptions.allowCredentials; |
| 1140 } | 1153 } |
| 1141 | 1154 |
| 1142 const SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const { | 1155 const SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const { |
| 1143 return m_securityOrigin ? m_securityOrigin.get() | 1156 return m_securityOrigin ? m_securityOrigin.get() |
| 1144 : document().getSecurityOrigin(); | 1157 : m_loadingContext->getSecurityOrigin(); |
| 1145 } | 1158 } |
| 1146 | 1159 |
| 1147 Document& DocumentThreadableLoader::document() const { | 1160 Document* DocumentThreadableLoader::document() const { |
| 1148 DCHECK(m_document); | 1161 DCHECK(m_loadingContext); |
| 1149 return *m_document; | 1162 return m_loadingContext->getLoadingDocument(); |
| 1150 } | 1163 } |
| 1151 | 1164 |
| 1152 DEFINE_TRACE(DocumentThreadableLoader) { | 1165 DEFINE_TRACE(DocumentThreadableLoader) { |
| 1153 visitor->trace(m_resource); | 1166 visitor->trace(m_resource); |
| 1154 visitor->trace(m_document); | 1167 visitor->trace(m_loadingContext); |
| 1155 ThreadableLoader::trace(visitor); | 1168 ThreadableLoader::trace(visitor); |
| 1156 RawResourceClient::trace(visitor); | 1169 RawResourceClient::trace(visitor); |
| 1157 } | 1170 } |
| 1158 | 1171 |
| 1159 } // namespace blink | 1172 } // namespace blink |
| OLD | NEW |