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

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

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

Powered by Google App Engine
This is Rietveld 408576698