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

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

Powered by Google App Engine
This is Rietveld 408576698