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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 , m_isUsingDataConsumerHandle(false) | 146 , m_isUsingDataConsumerHandle(false) |
147 , m_async(blockingBehavior == LoadAsynchronously) | 147 , m_async(blockingBehavior == LoadAsynchronously) |
148 , m_requestContext(WebURLRequest::RequestContextUnspecified) | 148 , m_requestContext(WebURLRequest::RequestContextUnspecified) |
149 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) | 149 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) |
150 , m_requestStartedSeconds(0.0) | 150 , m_requestStartedSeconds(0.0) |
151 , m_corsRedirectLimit(m_options.crossOriginRequestPolicy == UseAccessControl
? kMaxCORSRedirects : 0) | 151 , m_corsRedirectLimit(m_options.crossOriginRequestPolicy == UseAccessControl
? kMaxCORSRedirects : 0) |
152 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow) | 152 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow) |
153 , m_didRedirect(false) | 153 , m_didRedirect(false) |
154 , m_weakFactory(this) | 154 , m_weakFactory(this) |
155 { | 155 { |
156 ASSERT(client); | 156 DCHECK(client); |
157 } | 157 } |
158 | 158 |
159 void DocumentThreadableLoader::start(const ResourceRequest& request) | 159 void DocumentThreadableLoader::start(const ResourceRequest& request) |
160 { | 160 { |
161 // Setting an outgoing referer is only supported in the async code path. | 161 // Setting an outgoing referer is only supported in the async code path. |
162 ASSERT(m_async || request.httpReferrer().isEmpty()); | 162 DCHECK(m_async || request.httpReferrer().isEmpty()); |
163 | 163 |
164 m_sameOriginRequest = getSecurityOrigin()->canRequestNoSuborigin(request.url
()); | 164 m_sameOriginRequest = getSecurityOrigin()->canRequestNoSuborigin(request.url
()); |
165 m_requestContext = request.requestContext(); | 165 m_requestContext = request.requestContext(); |
166 m_redirectMode = request.fetchRedirectMode(); | 166 m_redirectMode = request.fetchRedirectMode(); |
167 | 167 |
168 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossO
riginRequests) { | 168 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossO
riginRequests) { |
169 InspectorInstrumentation::documentThreadableLoaderFailedToStartLoadingFo
rClient(m_document, m_client); | 169 InspectorInstrumentation::documentThreadableLoaderFailedToStartLoadingFo
rClient(m_document, m_client); |
170 ThreadableLoaderClient* client = m_client; | 170 ThreadableLoaderClient* client = m_client; |
171 clear(); | 171 clear(); |
172 client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url()
.getString(), "Cross origin requests are not supported.")); | 172 client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url()
.getString(), "Cross origin requests are not supported.")); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 dispatchInitialRequest(newRequest); | 256 dispatchInitialRequest(newRequest); |
257 } | 257 } |
258 | 258 |
259 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req
uest) | 259 void DocumentThreadableLoader::dispatchInitialRequest(const ResourceRequest& req
uest) |
260 { | 260 { |
261 if (!request.isExternalRequest() && (m_sameOriginRequest || m_options.crossO
riginRequestPolicy == AllowCrossOriginRequests)) { | 261 if (!request.isExternalRequest() && (m_sameOriginRequest || m_options.crossO
riginRequestPolicy == AllowCrossOriginRequests)) { |
262 loadRequest(request, m_resourceLoaderOptions); | 262 loadRequest(request, m_resourceLoaderOptions); |
263 return; | 263 return; |
264 } | 264 } |
265 | 265 |
266 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl || request.isE
xternalRequest()); | 266 DCHECK(m_options.crossOriginRequestPolicy == UseAccessControl || request.isE
xternalRequest()); |
267 | 267 |
268 makeCrossOriginAccessRequest(request); | 268 makeCrossOriginAccessRequest(request); |
269 } | 269 } |
270 | 270 |
271 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques
t& request) | 271 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques
t& request) |
272 { | 272 { |
273 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl || request.isE
xternalRequest()); | 273 DCHECK(m_options.crossOriginRequestPolicy == UseAccessControl || request.isE
xternalRequest()); |
274 ASSERT(m_client); | 274 DCHECK(m_client); |
275 ASSERT(!resource()); | 275 DCHECK(!resource()); |
276 | 276 |
277 // Cross-origin requests are only allowed certain registered schemes. | 277 // Cross-origin requests are only allowed certain registered schemes. |
278 // We would catch this when checking response headers later, but there | 278 // We would catch this when checking response headers later, but there |
279 // is no reason to send a request, preflighted or not, that's guaranteed | 279 // is no reason to send a request, preflighted or not, that's guaranteed |
280 // to be denied. | 280 // to be denied. |
281 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protoco
l())) { | 281 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protoco
l())) { |
282 InspectorInstrumentation::documentThreadableLoaderFailedToStartLoadingFo
rClient(m_document, m_client); | 282 InspectorInstrumentation::documentThreadableLoaderFailedToStartLoadingFo
rClient(m_document, m_client); |
283 ThreadableLoaderClient* client = m_client; | 283 ThreadableLoaderClient* client = m_client; |
284 clear(); | 284 clear(); |
285 client->didFailAccessControlCheck(ResourceError(errorDomainBlinkInternal
, 0, request.url().getString(), "Cross origin requests are only supported for pr
otocol schemes: " + SchemeRegistry::listOfCORSEnabledURLSchemes() + ".")); | 285 client->didFailAccessControlCheck(ResourceError(errorDomainBlinkInternal
, 0, request.url().getString(), "Cross origin requests are only supported for pr
otocol schemes: " + SchemeRegistry::listOfCORSEnabledURLSchemes() + ".")); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 339 } |
340 | 340 |
341 DocumentThreadableLoader::~DocumentThreadableLoader() | 341 DocumentThreadableLoader::~DocumentThreadableLoader() |
342 { | 342 { |
343 CHECK(!m_client); | 343 CHECK(!m_client); |
344 DCHECK(!m_resource); | 344 DCHECK(!m_resource); |
345 } | 345 } |
346 | 346 |
347 void DocumentThreadableLoader::overrideTimeout(unsigned long timeoutMilliseconds
) | 347 void DocumentThreadableLoader::overrideTimeout(unsigned long timeoutMilliseconds
) |
348 { | 348 { |
349 ASSERT(m_async); | 349 DCHECK(m_async); |
350 | 350 |
351 // |m_requestStartedSeconds| == 0.0 indicates loading is already finished | 351 // |m_requestStartedSeconds| == 0.0 indicates loading is already finished |
352 // and |m_timeoutTimer| is already stopped, and thus we do nothing for such | 352 // and |m_timeoutTimer| is already stopped, and thus we do nothing for such |
353 // cases. See https://crbug.com/551663 for details. | 353 // cases. See https://crbug.com/551663 for details. |
354 if (m_requestStartedSeconds <= 0.0) | 354 if (m_requestStartedSeconds <= 0.0) |
355 return; | 355 return; |
356 | 356 |
357 m_timeoutTimer.stop(); | 357 m_timeoutTimer.stop(); |
358 // At the time of this method's implementation, it is only ever called by | 358 // At the time of this method's implementation, it is only ever called by |
359 // XMLHttpRequest, when the timeout attribute is set after sending the | 359 // XMLHttpRequest, when the timeout attribute is set after sending the |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 410 } |
411 | 411 |
412 // In this method, we can clear |request| to tell content::WebURLLoaderImpl of | 412 // In this method, we can clear |request| to tell content::WebURLLoaderImpl of |
413 // Chromium not to follow the redirect. This works only when this method is | 413 // Chromium not to follow the redirect. This works only when this method is |
414 // called by RawResource::willSendRequest(). If called by | 414 // called by RawResource::willSendRequest(). If called by |
415 // RawResource::didAddClient(), clearing |request| won't be propagated | 415 // RawResource::didAddClient(), clearing |request| won't be propagated |
416 // to content::WebURLLoaderImpl. So, this loader must also get detached from | 416 // to content::WebURLLoaderImpl. So, this loader must also get detached from |
417 // the resource by calling clearResource(). | 417 // the resource by calling clearResource(). |
418 void DocumentThreadableLoader::redirectReceived(Resource* resource, ResourceRequ
est& request, const ResourceResponse& redirectResponse) | 418 void DocumentThreadableLoader::redirectReceived(Resource* resource, ResourceRequ
est& request, const ResourceResponse& redirectResponse) |
419 { | 419 { |
420 ASSERT(m_client); | 420 DCHECK(m_client); |
421 ASSERT_UNUSED(resource, resource == this->resource()); | 421 DCHECK_EQ(resource, this->resource()); |
422 ASSERT(m_async); | 422 DCHECK(m_async); |
423 | 423 |
424 m_checker.redirectReceived(); | 424 m_checker.redirectReceived(); |
425 | 425 |
426 if (!m_actualRequest.isNull()) { | 426 if (!m_actualRequest.isNull()) { |
427 reportResponseReceived(resource->identifier(), redirectResponse); | 427 reportResponseReceived(resource->identifier(), redirectResponse); |
428 | 428 |
429 handlePreflightFailure(redirectResponse.url().getString(), "Response for
preflight is invalid (redirect)"); | 429 handlePreflightFailure(redirectResponse.url().getString(), "Response for
preflight is invalid (redirect)"); |
430 | 430 |
431 request = ResourceRequest(); | 431 request = ResourceRequest(); |
432 | 432 |
433 return; | 433 return; |
434 } | 434 } |
435 | 435 |
436 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { | 436 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { |
437 // Keep |this| alive even if the client release a reference in | 437 // Keep |this| alive even if the client release a reference in |
438 // responseReceived(). | 438 // responseReceived(). |
439 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); | 439 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); |
440 | 440 |
441 // We use |m_redirectMode| to check the original redirect mode. | 441 // We use |m_redirectMode| to check the original redirect mode. |
442 // |request| is a new request for redirect. So we don't set the redirect | 442 // |request| is a new request for redirect. So we don't set the redirect |
443 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). | 443 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). |
444 ASSERT(request.useStreamOnResponse()); | 444 DCHECK(request.useStreamOnResponse()); |
445 // There is no need to read the body of redirect response because there | 445 // There is no need to read the body of redirect response because there |
446 // is no way to read the body of opaque-redirect filtered response's | 446 // is no way to read the body of opaque-redirect filtered response's |
447 // internal response. | 447 // internal response. |
448 // TODO(horo): If we support any API which expose the internal body, we | 448 // TODO(horo): If we support any API which expose the internal body, we |
449 // will have to read the body. And also HTTPCache changes will be needed | 449 // will have to read the body. And also HTTPCache changes will be needed |
450 // because it doesn't store the body of redirect responses. | 450 // because it doesn't store the body of redirect responses. |
451 responseReceived(resource, redirectResponse, wrapUnique(new EmptyDataHan
dle())); | 451 responseReceived(resource, redirectResponse, wrapUnique(new EmptyDataHan
dle())); |
452 | 452 |
453 if (!self) { | 453 if (!self) { |
454 request = ResourceRequest(); | 454 request = ResourceRequest(); |
455 return; | 455 return; |
456 } | 456 } |
457 | 457 |
458 if (m_client) { | 458 if (m_client) { |
459 ASSERT(m_actualRequest.isNull()); | 459 DCHECK(m_actualRequest.isNull()); |
460 notifyFinished(resource); | 460 notifyFinished(resource); |
461 } | 461 } |
462 | 462 |
463 request = ResourceRequest(); | 463 request = ResourceRequest(); |
464 | 464 |
465 return; | 465 return; |
466 } | 466 } |
467 | 467 |
468 if (m_redirectMode == WebURLRequest::FetchRedirectModeError) { | 468 if (m_redirectMode == WebURLRequest::FetchRedirectModeError) { |
469 ThreadableLoaderClient* client = m_client; | 469 ThreadableLoaderClient* client = m_client; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 m_checker.redirectBlocked(); | 560 m_checker.redirectBlocked(); |
561 | 561 |
562 // Tells the client that a redirect was received but not followed (for an un
known reason). | 562 // Tells the client that a redirect was received but not followed (for an un
known reason). |
563 ThreadableLoaderClient* client = m_client; | 563 ThreadableLoaderClient* client = m_client; |
564 clear(); | 564 clear(); |
565 client->didFailRedirectCheck(); | 565 client->didFailRedirectCheck(); |
566 } | 566 } |
567 | 567 |
568 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b
ytesSent, unsigned long long totalBytesToBeSent) | 568 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b
ytesSent, unsigned long long totalBytesToBeSent) |
569 { | 569 { |
570 ASSERT(m_client); | 570 DCHECK(m_client); |
571 ASSERT_UNUSED(resource, resource == this->resource()); | 571 DCHECK_EQ(resource, this->resource()); |
572 ASSERT(m_async); | 572 DCHECK(m_async); |
573 | 573 |
574 m_checker.dataSent(); | 574 m_checker.dataSent(); |
575 m_client->didSendData(bytesSent, totalBytesToBeSent); | 575 m_client->didSendData(bytesSent, totalBytesToBeSent); |
576 } | 576 } |
577 | 577 |
578 void DocumentThreadableLoader::dataDownloaded(Resource* resource, int dataLength
) | 578 void DocumentThreadableLoader::dataDownloaded(Resource* resource, int dataLength
) |
579 { | 579 { |
580 ASSERT(m_client); | 580 DCHECK(m_client); |
581 ASSERT_UNUSED(resource, resource == this->resource()); | 581 DCHECK_EQ(resource, this->resource()); |
582 ASSERT(m_actualRequest.isNull()); | 582 DCHECK(m_actualRequest.isNull()); |
583 ASSERT(m_async); | 583 DCHECK(m_async); |
584 | 584 |
585 m_checker.dataDownloaded(); | 585 m_checker.dataDownloaded(); |
586 m_client->didDownloadData(dataLength); | 586 m_client->didDownloadData(dataLength); |
587 } | 587 } |
588 | 588 |
589 void DocumentThreadableLoader::didReceiveResourceTiming(Resource* resource, cons
t ResourceTimingInfo& info) | 589 void DocumentThreadableLoader::didReceiveResourceTiming(Resource* resource, cons
t ResourceTimingInfo& info) |
590 { | 590 { |
591 ASSERT(m_client); | 591 DCHECK(m_client); |
592 ASSERT_UNUSED(resource, resource == this->resource()); | 592 DCHECK_EQ(resource, this->resource()); |
593 ASSERT(m_async); | 593 DCHECK(m_async); |
594 | 594 |
595 m_client->didReceiveResourceTiming(info); | 595 m_client->didReceiveResourceTiming(info); |
596 } | 596 } |
597 | 597 |
598 void DocumentThreadableLoader::responseReceived(Resource* resource, const Resour
ceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) | 598 void DocumentThreadableLoader::responseReceived(Resource* resource, const Resour
ceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) |
599 { | 599 { |
600 ASSERT_UNUSED(resource, resource == this->resource()); | 600 DCHECK_EQ(resource, this->resource()); |
601 ASSERT(m_async); | 601 DCHECK(m_async); |
602 | 602 |
603 m_checker.responseReceived(); | 603 m_checker.responseReceived(); |
604 | 604 |
605 if (handle) | 605 if (handle) |
606 m_isUsingDataConsumerHandle = true; | 606 m_isUsingDataConsumerHandle = true; |
607 | 607 |
608 handleResponse(resource->identifier(), response, std::move(handle)); | 608 handleResponse(resource->identifier(), response, std::move(handle)); |
609 } | 609 } |
610 | 610 |
611 void DocumentThreadableLoader::handlePreflightResponse(const ResourceResponse& r
esponse) | 611 void DocumentThreadableLoader::handlePreflightResponse(const ResourceResponse& r
esponse) |
(...skipping 24 matching lines...) Expand all Loading... |
636 } | 636 } |
637 | 637 |
638 CrossOriginPreflightResultCache::shared().appendEntry(getSecurityOrigin()->t
oString(), m_actualRequest.url(), std::move(preflightResult)); | 638 CrossOriginPreflightResultCache::shared().appendEntry(getSecurityOrigin()->t
oString(), m_actualRequest.url(), std::move(preflightResult)); |
639 } | 639 } |
640 | 640 |
641 void DocumentThreadableLoader::reportResponseReceived(unsigned long identifier,
const ResourceResponse& response) | 641 void DocumentThreadableLoader::reportResponseReceived(unsigned long identifier,
const ResourceResponse& response) |
642 { | 642 { |
643 LocalFrame* frame = document().frame(); | 643 LocalFrame* frame = document().frame(); |
644 // We are seeing crashes caused by nullptr (crbug.com/578849). But the frame | 644 // We are seeing crashes caused by nullptr (crbug.com/578849). But the frame |
645 // must be set here. TODO(horo): Find the root cause of the unset frame. | 645 // must be set here. TODO(horo): Find the root cause of the unset frame. |
646 ASSERT(frame); | 646 DCHECK(frame); |
647 if (!frame) | 647 if (!frame) |
648 return; | 648 return; |
649 DocumentLoader* loader = frame->loader().documentLoader(); | 649 DocumentLoader* loader = frame->loader().documentLoader(); |
650 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_E
VENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame
, response)); | 650 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_E
VENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame
, response)); |
651 InspectorInstrumentation::didReceiveResourceResponse(frame, identifier, load
er, response, resource()); | 651 InspectorInstrumentation::didReceiveResourceResponse(frame, identifier, load
er, response, resource()); |
652 frame->console().reportResourceResponseReceived(loader, identifier, response
); | 652 frame->console().reportResourceResponseReceived(loader, identifier, response
); |
653 } | 653 } |
654 | 654 |
655 void DocumentThreadableLoader::handleResponse(unsigned long identifier, const Re
sourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) | 655 void DocumentThreadableLoader::handleResponse(unsigned long identifier, const Re
sourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) |
656 { | 656 { |
657 ASSERT(m_client); | 657 DCHECK(m_client); |
658 | 658 |
659 if (!m_actualRequest.isNull()) { | 659 if (!m_actualRequest.isNull()) { |
660 reportResponseReceived(identifier, response); | 660 reportResponseReceived(identifier, response); |
661 handlePreflightResponse(response); | 661 handlePreflightResponse(response); |
662 return; | 662 return; |
663 } | 663 } |
664 | 664 |
665 if (response.wasFetchedViaServiceWorker()) { | 665 if (response.wasFetchedViaServiceWorker()) { |
666 if (response.wasFetchedViaForeignFetch()) | 666 if (response.wasFetchedViaForeignFetch()) |
667 UseCounter::count(m_document, UseCounter::ForeignFetchInterception); | 667 UseCounter::count(m_document, UseCounter::ForeignFetchInterception); |
668 if (response.wasFallbackRequiredByServiceWorker()) { | 668 if (response.wasFallbackRequiredByServiceWorker()) { |
669 // At this point we must have m_fallbackRequestForServiceWorker. | 669 // At this point we must have m_fallbackRequestForServiceWorker. |
670 // (For SharedWorker the request won't be CORS or CORS-with-prefligh
t, | 670 // (For SharedWorker the request won't be CORS or CORS-with-prefligh
t, |
671 // therefore fallback-to-network is handled in the browser process | 671 // therefore fallback-to-network is handled in the browser process |
672 // when the ServiceWorker does not call respondWith().) | 672 // when the ServiceWorker does not call respondWith().) |
673 ASSERT(!m_fallbackRequestForServiceWorker.isNull()); | 673 DCHECK(!m_fallbackRequestForServiceWorker.isNull()); |
674 reportResponseReceived(identifier, response); | 674 reportResponseReceived(identifier, response); |
675 loadFallbackRequestForServiceWorker(); | 675 loadFallbackRequestForServiceWorker(); |
676 return; | 676 return; |
677 } | 677 } |
678 m_fallbackRequestForServiceWorker = ResourceRequest(); | 678 m_fallbackRequestForServiceWorker = ResourceRequest(); |
679 m_client->didReceiveResponse(identifier, response, std::move(handle)); | 679 m_client->didReceiveResponse(identifier, response, std::move(handle)); |
680 return; | 680 return; |
681 } | 681 } |
682 | 682 |
683 // Even if the request met the conditions to get handled by a Service Worker | 683 // Even if the request met the conditions to get handled by a Service Worker |
684 // in the constructor of this class (and therefore | 684 // in the constructor of this class (and therefore |
685 // |m_fallbackRequestForServiceWorker| is set), the Service Worker may skip | 685 // |m_fallbackRequestForServiceWorker| is set), the Service Worker may skip |
686 // processing the request. Only if the request is same origin, the skipped | 686 // processing the request. Only if the request is same origin, the skipped |
687 // response may come here (wasFetchedViaServiceWorker() returns false) since | 687 // response may come here (wasFetchedViaServiceWorker() returns false) since |
688 // such a request doesn't have to go through the CORS algorithm by calling | 688 // such a request doesn't have to go through the CORS algorithm by calling |
689 // loadFallbackRequestForServiceWorker(). | 689 // loadFallbackRequestForServiceWorker(). |
690 // FIXME: We should use |m_sameOriginRequest| when we will support | 690 // FIXME: We should use |m_sameOriginRequest| when we will support |
691 // Suborigins (crbug.com/336894) for Service Worker. | 691 // Suborigins (crbug.com/336894) for Service Worker. |
692 ASSERT(m_fallbackRequestForServiceWorker.isNull() || getSecurityOrigin()->ca
nRequest(m_fallbackRequestForServiceWorker.url())); | 692 DCHECK(m_fallbackRequestForServiceWorker.isNull() || getSecurityOrigin()->ca
nRequest(m_fallbackRequestForServiceWorker.url())); |
693 m_fallbackRequestForServiceWorker = ResourceRequest(); | 693 m_fallbackRequestForServiceWorker = ResourceRequest(); |
694 | 694 |
695 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == UseAccessC
ontrol) { | 695 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == UseAccessC
ontrol) { |
696 String accessControlErrorDescription; | 696 String accessControlErrorDescription; |
697 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), get
SecurityOrigin(), accessControlErrorDescription, m_requestContext)) { | 697 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), get
SecurityOrigin(), accessControlErrorDescription, m_requestContext)) { |
698 reportResponseReceived(identifier, response); | 698 reportResponseReceived(identifier, response); |
699 | 699 |
700 ThreadableLoaderClient* client = m_client; | 700 ThreadableLoaderClient* client = m_client; |
701 clear(); | 701 clear(); |
702 client->didFailAccessControlCheck(ResourceError(errorDomainBlinkInte
rnal, 0, response.url().getString(), accessControlErrorDescription)); | 702 client->didFailAccessControlCheck(ResourceError(errorDomainBlinkInte
rnal, 0, response.url().getString(), accessControlErrorDescription)); |
703 return; | 703 return; |
704 } | 704 } |
705 } | 705 } |
706 | 706 |
707 m_client->didReceiveResponse(identifier, response, std::move(handle)); | 707 m_client->didReceiveResponse(identifier, response, std::move(handle)); |
708 } | 708 } |
709 | 709 |
710 void DocumentThreadableLoader::setSerializedCachedMetadata(Resource*, const char
* data, size_t size) | 710 void DocumentThreadableLoader::setSerializedCachedMetadata(Resource*, const char
* data, size_t size) |
711 { | 711 { |
712 m_checker.setSerializedCachedMetadata(); | 712 m_checker.setSerializedCachedMetadata(); |
713 | 713 |
714 if (!m_actualRequest.isNull()) | 714 if (!m_actualRequest.isNull()) |
715 return; | 715 return; |
716 m_client->didReceiveCachedMetadata(data, size); | 716 m_client->didReceiveCachedMetadata(data, size); |
717 } | 717 } |
718 | 718 |
719 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data
, size_t dataLength) | 719 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data
, size_t dataLength) |
720 { | 720 { |
721 ASSERT_UNUSED(resource, resource == this->resource()); | 721 DCHECK_EQ(resource, this->resource()); |
722 ASSERT(m_async); | 722 DCHECK(m_async); |
723 | 723 |
724 m_checker.dataReceived(); | 724 m_checker.dataReceived(); |
725 | 725 |
726 if (m_isUsingDataConsumerHandle) | 726 if (m_isUsingDataConsumerHandle) |
727 return; | 727 return; |
728 | 728 |
729 // TODO(junov): Fix the ThreadableLoader ecosystem to use size_t. | 729 // TODO(junov): Fix the ThreadableLoader ecosystem to use size_t. |
730 // Until then, we use safeCast to trap potential overflows. | 730 // Until then, we use safeCast to trap potential overflows. |
731 handleReceivedData(data, safeCast<unsigned>(dataLength)); | 731 handleReceivedData(data, safeCast<unsigned>(dataLength)); |
732 } | 732 } |
733 | 733 |
734 void DocumentThreadableLoader::handleReceivedData(const char* data, size_t dataL
ength) | 734 void DocumentThreadableLoader::handleReceivedData(const char* data, size_t dataL
ength) |
735 { | 735 { |
736 ASSERT(m_client); | 736 DCHECK(m_client); |
737 | 737 |
738 // Preflight data should be invisible to clients. | 738 // Preflight data should be invisible to clients. |
739 if (!m_actualRequest.isNull()) | 739 if (!m_actualRequest.isNull()) |
740 return; | 740 return; |
741 | 741 |
742 ASSERT(m_fallbackRequestForServiceWorker.isNull()); | 742 DCHECK(m_fallbackRequestForServiceWorker.isNull()); |
743 | 743 |
744 m_client->didReceiveData(data, dataLength); | 744 m_client->didReceiveData(data, dataLength); |
745 } | 745 } |
746 | 746 |
747 void DocumentThreadableLoader::notifyFinished(Resource* resource) | 747 void DocumentThreadableLoader::notifyFinished(Resource* resource) |
748 { | 748 { |
749 ASSERT(m_client); | 749 DCHECK(m_client); |
750 ASSERT(resource == this->resource()); | 750 DCHECK_EQ(resource, this->resource()); |
751 ASSERT(m_async); | 751 DCHECK(m_async); |
752 | 752 |
753 m_checker.notifyFinished(resource); | 753 m_checker.notifyFinished(resource); |
754 | 754 |
755 if (resource->errorOccurred()) { | 755 if (resource->errorOccurred()) { |
756 handleError(resource->resourceError()); | 756 handleError(resource->resourceError()); |
757 } else { | 757 } else { |
758 handleSuccessfulFinish(resource->identifier(), resource->loadFinishTime(
)); | 758 handleSuccessfulFinish(resource->identifier(), resource->loadFinishTime(
)); |
759 } | 759 } |
760 } | 760 } |
761 | 761 |
762 void DocumentThreadableLoader::handleSuccessfulFinish(unsigned long identifier,
double finishTime) | 762 void DocumentThreadableLoader::handleSuccessfulFinish(unsigned long identifier,
double finishTime) |
763 { | 763 { |
764 ASSERT(m_fallbackRequestForServiceWorker.isNull()); | 764 DCHECK(m_fallbackRequestForServiceWorker.isNull()); |
765 | 765 |
766 if (!m_actualRequest.isNull()) { | 766 if (!m_actualRequest.isNull()) { |
767 // FIXME: Timeout should be applied to whole fetch, not for each of | 767 // FIXME: Timeout should be applied to whole fetch, not for each of |
768 // preflight and actual request. | 768 // preflight and actual request. |
769 m_timeoutTimer.stop(); | 769 m_timeoutTimer.stop(); |
770 ASSERT(!m_sameOriginRequest); | 770 DCHECK(!m_sameOriginRequest); |
771 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); | 771 DCHECK_EQ(m_options.crossOriginRequestPolicy, UseAccessControl); |
772 loadActualRequest(); | 772 loadActualRequest(); |
773 return; | 773 return; |
774 } | 774 } |
775 | 775 |
776 ThreadableLoaderClient* client = m_client; | 776 ThreadableLoaderClient* client = m_client; |
777 // Protect the resource in |didFinishLoading| in order not to release the | 777 // Protect the resource in |didFinishLoading| in order not to release the |
778 // downloaded file. | 778 // downloaded file. |
779 Persistent<Resource> protect = resource(); | 779 Persistent<Resource> protect = resource(); |
780 clear(); | 780 clear(); |
781 client->didFinishLoading(identifier, finishTime); | 781 client->didFinishLoading(identifier, finishTime); |
782 } | 782 } |
783 | 783 |
784 void DocumentThreadableLoader::didTimeout(TimerBase* timer) | 784 void DocumentThreadableLoader::didTimeout(TimerBase* timer) |
785 { | 785 { |
786 ASSERT_UNUSED(timer, timer == &m_timeoutTimer); | 786 DCHECK_EQ(timer, &m_timeoutTimer); |
787 | 787 |
788 // Using values from net/base/net_error_list.h ERR_TIMED_OUT, | 788 // Using values from net/base/net_error_list.h ERR_TIMED_OUT, |
789 // Same as existing FIXME above - this error should be coming from FrameLoad
erClient to be identifiable. | 789 // Same as existing FIXME above - this error should be coming from FrameLoad
erClient to be identifiable. |
790 static const int timeoutError = -7; | 790 static const int timeoutError = -7; |
791 ResourceError error("net", timeoutError, resource()->url(), String()); | 791 ResourceError error("net", timeoutError, resource()->url(), String()); |
792 error.setIsTimeout(true); | 792 error.setIsTimeout(true); |
793 cancelWithError(error); | 793 cancelWithError(error); |
794 } | 794 } |
795 | 795 |
796 void DocumentThreadableLoader::loadFallbackRequestForServiceWorker() | 796 void DocumentThreadableLoader::loadFallbackRequestForServiceWorker() |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 | 842 |
843 ThreadableLoaderClient* client = m_client; | 843 ThreadableLoaderClient* client = m_client; |
844 clear(); | 844 clear(); |
845 client->didFail(copiedError); | 845 client->didFail(copiedError); |
846 } | 846 } |
847 | 847 |
848 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Resou
rceLoaderOptions resourceLoaderOptions) | 848 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Resou
rceLoaderOptions resourceLoaderOptions) |
849 { | 849 { |
850 // Any credential should have been removed from the cross-site requests. | 850 // Any credential should have been removed from the cross-site requests. |
851 const KURL& requestURL = request.url(); | 851 const KURL& requestURL = request.url(); |
852 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); | 852 DCHECK(m_sameOriginRequest || requestURL.user().isEmpty()); |
853 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); | 853 DCHECK(m_sameOriginRequest || requestURL.pass().isEmpty()); |
854 | 854 |
855 // Update resourceLoaderOptions with enforced values. | 855 // Update resourceLoaderOptions with enforced values. |
856 if (m_forceDoNotAllowStoredCredentials) | 856 if (m_forceDoNotAllowStoredCredentials) |
857 resourceLoaderOptions.allowCredentials = DoNotAllowStoredCredentials; | 857 resourceLoaderOptions.allowCredentials = DoNotAllowStoredCredentials; |
858 resourceLoaderOptions.securityOrigin = m_securityOrigin; | 858 resourceLoaderOptions.securityOrigin = m_securityOrigin; |
859 if (m_async) { | 859 if (m_async) { |
860 if (!m_actualRequest.isNull()) | 860 if (!m_actualRequest.isNull()) |
861 resourceLoaderOptions.dataBufferingPolicy = BufferData; | 861 resourceLoaderOptions.dataBufferingPolicy = BufferData; |
862 | 862 |
863 if (m_options.timeoutMilliseconds > 0) | 863 if (m_options.timeoutMilliseconds > 0) |
864 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0,
BLINK_FROM_HERE); | 864 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0,
BLINK_FROM_HERE); |
865 | 865 |
866 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti
ons); | 866 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti
ons); |
867 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 867 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
868 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); | 868 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); |
869 ASSERT(!resource()); | 869 DCHECK(!resource()); |
870 | 870 |
871 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); | 871 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); |
872 | 872 |
873 if (request.requestContext() == WebURLRequest::RequestContextVideo || re
quest.requestContext() == WebURLRequest::RequestContextAudio) | 873 if (request.requestContext() == WebURLRequest::RequestContextVideo || re
quest.requestContext() == WebURLRequest::RequestContextAudio) |
874 setResource(RawResource::fetchMedia(newRequest, document().fetcher()
)); | 874 setResource(RawResource::fetchMedia(newRequest, document().fetcher()
)); |
875 else if (request.requestContext() == WebURLRequest::RequestContextManife
st) | 875 else if (request.requestContext() == WebURLRequest::RequestContextManife
st) |
876 setResource(RawResource::fetchManifest(newRequest, document().fetche
r())); | 876 setResource(RawResource::fetchManifest(newRequest, document().fetche
r())); |
877 else | 877 else |
878 setResource(RawResource::fetch(newRequest, document().fetcher())); | 878 setResource(RawResource::fetch(newRequest, document().fetcher())); |
879 | 879 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 return m_resourceLoaderOptions.allowCredentials; | 974 return m_resourceLoaderOptions.allowCredentials; |
975 } | 975 } |
976 | 976 |
977 const SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const | 977 const SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const |
978 { | 978 { |
979 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri
gin(); | 979 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri
gin(); |
980 } | 980 } |
981 | 981 |
982 Document& DocumentThreadableLoader::document() const | 982 Document& DocumentThreadableLoader::document() const |
983 { | 983 { |
984 ASSERT(m_document); | 984 DCHECK(m_document); |
985 return *m_document; | 985 return *m_document; |
986 } | 986 } |
987 | 987 |
988 DEFINE_TRACE(DocumentThreadableLoader) | 988 DEFINE_TRACE(DocumentThreadableLoader) |
989 { | 989 { |
990 visitor->trace(m_resource); | 990 visitor->trace(m_resource); |
991 visitor->trace(m_document); | 991 visitor->trace(m_document); |
992 ThreadableLoader::trace(visitor); | 992 ThreadableLoader::trace(visitor); |
993 RawResourceClient::trace(visitor); | 993 RawResourceClient::trace(visitor); |
994 } | 994 } |
995 | 995 |
996 } // namespace blink | 996 } // namespace blink |
OLD | NEW |