Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013, Intel Corporation | 3 * Copyright (C) 2013, Intel Corporation |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 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 ALLOW_UNUSED_LOCAL(resource); |
|
yhirano
2016/09/12 04:33:13
ditto as Resource::cancelTimerFired.
hiroshige
2016/09/13 08:43:20
Done.
| |
| 422 ASSERT(m_async); | 422 DCHECK(resource == this->resource()); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 423 DCHECK(m_async); | |
| 423 | 424 |
| 424 m_checker.redirectReceived(); | 425 m_checker.redirectReceived(); |
| 425 | 426 |
| 426 if (!m_actualRequest.isNull()) { | 427 if (!m_actualRequest.isNull()) { |
| 427 reportResponseReceived(resource->identifier(), redirectResponse); | 428 reportResponseReceived(resource->identifier(), redirectResponse); |
| 428 | 429 |
| 429 handlePreflightFailure(redirectResponse.url().getString(), "Response for preflight is invalid (redirect)"); | 430 handlePreflightFailure(redirectResponse.url().getString(), "Response for preflight is invalid (redirect)"); |
| 430 | 431 |
| 431 request = ResourceRequest(); | 432 request = ResourceRequest(); |
| 432 | 433 |
| 433 return; | 434 return; |
| 434 } | 435 } |
| 435 | 436 |
| 436 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { | 437 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { |
| 437 // Keep |this| alive even if the client release a reference in | 438 // Keep |this| alive even if the client release a reference in |
| 438 // responseReceived(). | 439 // responseReceived(). |
| 439 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); | 440 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); |
| 440 | 441 |
| 441 // We use |m_redirectMode| to check the original redirect mode. | 442 // 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 | 443 // |request| is a new request for redirect. So we don't set the redirect |
| 443 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). | 444 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). |
| 444 ASSERT(request.useStreamOnResponse()); | 445 DCHECK(request.useStreamOnResponse()); |
| 445 // There is no need to read the body of redirect response because there | 446 // 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 | 447 // is no way to read the body of opaque-redirect filtered response's |
| 447 // internal response. | 448 // internal response. |
| 448 // TODO(horo): If we support any API which expose the internal body, we | 449 // 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 | 450 // will have to read the body. And also HTTPCache changes will be needed |
| 450 // because it doesn't store the body of redirect responses. | 451 // because it doesn't store the body of redirect responses. |
| 451 responseReceived(resource, redirectResponse, wrapUnique(new EmptyDataHan dle())); | 452 responseReceived(resource, redirectResponse, wrapUnique(new EmptyDataHan dle())); |
| 452 | 453 |
| 453 if (!self) { | 454 if (!self) { |
| 454 request = ResourceRequest(); | 455 request = ResourceRequest(); |
| 455 return; | 456 return; |
| 456 } | 457 } |
| 457 | 458 |
| 458 if (m_client) { | 459 if (m_client) { |
| 459 ASSERT(m_actualRequest.isNull()); | 460 DCHECK(m_actualRequest.isNull()); |
| 460 notifyFinished(resource); | 461 notifyFinished(resource); |
| 461 } | 462 } |
| 462 | 463 |
| 463 request = ResourceRequest(); | 464 request = ResourceRequest(); |
| 464 | 465 |
| 465 return; | 466 return; |
| 466 } | 467 } |
| 467 | 468 |
| 468 if (m_redirectMode == WebURLRequest::FetchRedirectModeError) { | 469 if (m_redirectMode == WebURLRequest::FetchRedirectModeError) { |
| 469 ThreadableLoaderClient* client = m_client; | 470 ThreadableLoaderClient* client = m_client; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 m_checker.redirectBlocked(); | 561 m_checker.redirectBlocked(); |
| 561 | 562 |
| 562 // Tells the client that a redirect was received but not followed (for an un known reason). | 563 // Tells the client that a redirect was received but not followed (for an un known reason). |
| 563 ThreadableLoaderClient* client = m_client; | 564 ThreadableLoaderClient* client = m_client; |
| 564 clear(); | 565 clear(); |
| 565 client->didFailRedirectCheck(); | 566 client->didFailRedirectCheck(); |
| 566 } | 567 } |
| 567 | 568 |
| 568 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b ytesSent, unsigned long long totalBytesToBeSent) | 569 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b ytesSent, unsigned long long totalBytesToBeSent) |
| 569 { | 570 { |
| 570 ASSERT(m_client); | 571 DCHECK(m_client); |
| 571 ASSERT_UNUSED(resource, resource == this->resource()); | 572 ALLOW_UNUSED_LOCAL(resource); |
|
yhirano
2016/09/12 04:33:13
ditto as Resource::cancelTimerFired.
hiroshige
2016/09/13 08:43:20
Done.
| |
| 572 ASSERT(m_async); | 573 DCHECK(resource == this->resource()); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 574 DCHECK(m_async); | |
| 573 | 575 |
| 574 m_checker.dataSent(); | 576 m_checker.dataSent(); |
| 575 m_client->didSendData(bytesSent, totalBytesToBeSent); | 577 m_client->didSendData(bytesSent, totalBytesToBeSent); |
| 576 } | 578 } |
| 577 | 579 |
| 578 void DocumentThreadableLoader::dataDownloaded(Resource* resource, int dataLength ) | 580 void DocumentThreadableLoader::dataDownloaded(Resource* resource, int dataLength ) |
| 579 { | 581 { |
| 580 ASSERT(m_client); | 582 DCHECK(m_client); |
| 581 ASSERT_UNUSED(resource, resource == this->resource()); | 583 ALLOW_UNUSED_LOCAL(resource); |
|
yhirano
2016/09/12 04:33:13
ditto as Resource::cancelTimerFired.
hiroshige
2016/09/13 08:43:20
Done.
| |
| 582 ASSERT(m_actualRequest.isNull()); | 584 DCHECK(resource == this->resource()); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 583 ASSERT(m_async); | 585 DCHECK(m_actualRequest.isNull()); |
| 586 DCHECK(m_async); | |
| 584 | 587 |
| 585 m_checker.dataDownloaded(); | 588 m_checker.dataDownloaded(); |
| 586 m_client->didDownloadData(dataLength); | 589 m_client->didDownloadData(dataLength); |
| 587 } | 590 } |
| 588 | 591 |
| 589 void DocumentThreadableLoader::didReceiveResourceTiming(Resource* resource, cons t ResourceTimingInfo& info) | 592 void DocumentThreadableLoader::didReceiveResourceTiming(Resource* resource, cons t ResourceTimingInfo& info) |
| 590 { | 593 { |
| 591 ASSERT(m_client); | 594 DCHECK(m_client); |
| 592 ASSERT_UNUSED(resource, resource == this->resource()); | 595 ALLOW_UNUSED_LOCAL(resource); |
|
yhirano
2016/09/12 04:33:13
ditto as Resource::cancelTimerFired.
hiroshige
2016/09/13 08:43:20
Done.
| |
| 593 ASSERT(m_async); | 596 DCHECK(resource == this->resource()); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 597 DCHECK(m_async); | |
| 594 | 598 |
| 595 m_client->didReceiveResourceTiming(info); | 599 m_client->didReceiveResourceTiming(info); |
| 596 } | 600 } |
| 597 | 601 |
| 598 void DocumentThreadableLoader::responseReceived(Resource* resource, const Resour ceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) | 602 void DocumentThreadableLoader::responseReceived(Resource* resource, const Resour ceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) |
| 599 { | 603 { |
| 600 ASSERT_UNUSED(resource, resource == this->resource()); | 604 ALLOW_UNUSED_LOCAL(resource); |
|
yhirano
2016/09/12 04:33:13
ditto as Resource::cancelTimerFired.
hiroshige
2016/09/13 08:43:20
Done.
| |
| 601 ASSERT(m_async); | 605 DCHECK(resource == this->resource()); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 606 DCHECK(m_async); | |
| 602 | 607 |
| 603 m_checker.responseReceived(); | 608 m_checker.responseReceived(); |
| 604 | 609 |
| 605 if (handle) | 610 if (handle) |
| 606 m_isUsingDataConsumerHandle = true; | 611 m_isUsingDataConsumerHandle = true; |
| 607 | 612 |
| 608 handleResponse(resource->identifier(), response, std::move(handle)); | 613 handleResponse(resource->identifier(), response, std::move(handle)); |
| 609 } | 614 } |
| 610 | 615 |
| 611 void DocumentThreadableLoader::handlePreflightResponse(const ResourceResponse& r esponse) | 616 void DocumentThreadableLoader::handlePreflightResponse(const ResourceResponse& r esponse) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 636 } | 641 } |
| 637 | 642 |
| 638 CrossOriginPreflightResultCache::shared().appendEntry(getSecurityOrigin()->t oString(), m_actualRequest.url(), std::move(preflightResult)); | 643 CrossOriginPreflightResultCache::shared().appendEntry(getSecurityOrigin()->t oString(), m_actualRequest.url(), std::move(preflightResult)); |
| 639 } | 644 } |
| 640 | 645 |
| 641 void DocumentThreadableLoader::reportResponseReceived(unsigned long identifier, const ResourceResponse& response) | 646 void DocumentThreadableLoader::reportResponseReceived(unsigned long identifier, const ResourceResponse& response) |
| 642 { | 647 { |
| 643 LocalFrame* frame = document().frame(); | 648 LocalFrame* frame = document().frame(); |
| 644 // We are seeing crashes caused by nullptr (crbug.com/578849). But the frame | 649 // 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. | 650 // must be set here. TODO(horo): Find the root cause of the unset frame. |
| 646 ASSERT(frame); | 651 DCHECK(frame); |
| 647 if (!frame) | 652 if (!frame) |
| 648 return; | 653 return; |
| 649 DocumentLoader* loader = frame->loader().documentLoader(); | 654 DocumentLoader* loader = frame->loader().documentLoader(); |
| 650 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_E VENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame , response)); | 655 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()); | 656 InspectorInstrumentation::didReceiveResourceResponse(frame, identifier, load er, response, resource()); |
| 652 frame->console().reportResourceResponseReceived(loader, identifier, response ); | 657 frame->console().reportResourceResponseReceived(loader, identifier, response ); |
| 653 } | 658 } |
| 654 | 659 |
| 655 void DocumentThreadableLoader::handleResponse(unsigned long identifier, const Re sourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) | 660 void DocumentThreadableLoader::handleResponse(unsigned long identifier, const Re sourceResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) |
| 656 { | 661 { |
| 657 ASSERT(m_client); | 662 DCHECK(m_client); |
| 658 | 663 |
| 659 if (!m_actualRequest.isNull()) { | 664 if (!m_actualRequest.isNull()) { |
| 660 reportResponseReceived(identifier, response); | 665 reportResponseReceived(identifier, response); |
| 661 handlePreflightResponse(response); | 666 handlePreflightResponse(response); |
| 662 return; | 667 return; |
| 663 } | 668 } |
| 664 | 669 |
| 665 if (response.wasFetchedViaServiceWorker()) { | 670 if (response.wasFetchedViaServiceWorker()) { |
| 666 if (response.wasFetchedViaForeignFetch()) | 671 if (response.wasFetchedViaForeignFetch()) |
| 667 UseCounter::count(m_document, UseCounter::ForeignFetchInterception); | 672 UseCounter::count(m_document, UseCounter::ForeignFetchInterception); |
| 668 if (response.wasFallbackRequiredByServiceWorker()) { | 673 if (response.wasFallbackRequiredByServiceWorker()) { |
| 669 // At this point we must have m_fallbackRequestForServiceWorker. | 674 // At this point we must have m_fallbackRequestForServiceWorker. |
| 670 // (For SharedWorker the request won't be CORS or CORS-with-prefligh t, | 675 // (For SharedWorker the request won't be CORS or CORS-with-prefligh t, |
| 671 // therefore fallback-to-network is handled in the browser process | 676 // therefore fallback-to-network is handled in the browser process |
| 672 // when the ServiceWorker does not call respondWith().) | 677 // when the ServiceWorker does not call respondWith().) |
| 673 ASSERT(!m_fallbackRequestForServiceWorker.isNull()); | 678 DCHECK(!m_fallbackRequestForServiceWorker.isNull()); |
| 674 reportResponseReceived(identifier, response); | 679 reportResponseReceived(identifier, response); |
| 675 loadFallbackRequestForServiceWorker(); | 680 loadFallbackRequestForServiceWorker(); |
| 676 return; | 681 return; |
| 677 } | 682 } |
| 678 m_fallbackRequestForServiceWorker = ResourceRequest(); | 683 m_fallbackRequestForServiceWorker = ResourceRequest(); |
| 679 m_client->didReceiveResponse(identifier, response, std::move(handle)); | 684 m_client->didReceiveResponse(identifier, response, std::move(handle)); |
| 680 return; | 685 return; |
| 681 } | 686 } |
| 682 | 687 |
| 683 // Even if the request met the conditions to get handled by a Service Worker | 688 // Even if the request met the conditions to get handled by a Service Worker |
| 684 // in the constructor of this class (and therefore | 689 // in the constructor of this class (and therefore |
| 685 // |m_fallbackRequestForServiceWorker| is set), the Service Worker may skip | 690 // |m_fallbackRequestForServiceWorker| is set), the Service Worker may skip |
| 686 // processing the request. Only if the request is same origin, the skipped | 691 // processing the request. Only if the request is same origin, the skipped |
| 687 // response may come here (wasFetchedViaServiceWorker() returns false) since | 692 // response may come here (wasFetchedViaServiceWorker() returns false) since |
| 688 // such a request doesn't have to go through the CORS algorithm by calling | 693 // such a request doesn't have to go through the CORS algorithm by calling |
| 689 // loadFallbackRequestForServiceWorker(). | 694 // loadFallbackRequestForServiceWorker(). |
| 690 // FIXME: We should use |m_sameOriginRequest| when we will support | 695 // FIXME: We should use |m_sameOriginRequest| when we will support |
| 691 // Suborigins (crbug.com/336894) for Service Worker. | 696 // Suborigins (crbug.com/336894) for Service Worker. |
| 692 ASSERT(m_fallbackRequestForServiceWorker.isNull() || getSecurityOrigin()->ca nRequest(m_fallbackRequestForServiceWorker.url())); | 697 DCHECK(m_fallbackRequestForServiceWorker.isNull() || getSecurityOrigin()->ca nRequest(m_fallbackRequestForServiceWorker.url())); |
| 693 m_fallbackRequestForServiceWorker = ResourceRequest(); | 698 m_fallbackRequestForServiceWorker = ResourceRequest(); |
| 694 | 699 |
| 695 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == UseAccessC ontrol) { | 700 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == UseAccessC ontrol) { |
| 696 String accessControlErrorDescription; | 701 String accessControlErrorDescription; |
| 697 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), get SecurityOrigin(), accessControlErrorDescription, m_requestContext)) { | 702 if (!passesAccessControlCheck(response, effectiveAllowCredentials(), get SecurityOrigin(), accessControlErrorDescription, m_requestContext)) { |
| 698 reportResponseReceived(identifier, response); | 703 reportResponseReceived(identifier, response); |
| 699 | 704 |
| 700 ThreadableLoaderClient* client = m_client; | 705 ThreadableLoaderClient* client = m_client; |
| 701 clear(); | 706 clear(); |
| 702 client->didFailAccessControlCheck(ResourceError(errorDomainBlinkInte rnal, 0, response.url().getString(), accessControlErrorDescription)); | 707 client->didFailAccessControlCheck(ResourceError(errorDomainBlinkInte rnal, 0, response.url().getString(), accessControlErrorDescription)); |
| 703 return; | 708 return; |
| 704 } | 709 } |
| 705 } | 710 } |
| 706 | 711 |
| 707 m_client->didReceiveResponse(identifier, response, std::move(handle)); | 712 m_client->didReceiveResponse(identifier, response, std::move(handle)); |
| 708 } | 713 } |
| 709 | 714 |
| 710 void DocumentThreadableLoader::setSerializedCachedMetadata(Resource*, const char * data, size_t size) | 715 void DocumentThreadableLoader::setSerializedCachedMetadata(Resource*, const char * data, size_t size) |
| 711 { | 716 { |
| 712 m_checker.setSerializedCachedMetadata(); | 717 m_checker.setSerializedCachedMetadata(); |
| 713 | 718 |
| 714 if (!m_actualRequest.isNull()) | 719 if (!m_actualRequest.isNull()) |
| 715 return; | 720 return; |
| 716 m_client->didReceiveCachedMetadata(data, size); | 721 m_client->didReceiveCachedMetadata(data, size); |
| 717 } | 722 } |
| 718 | 723 |
| 719 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data , size_t dataLength) | 724 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data , size_t dataLength) |
| 720 { | 725 { |
| 721 ASSERT_UNUSED(resource, resource == this->resource()); | 726 ALLOW_UNUSED_LOCAL(resource); |
|
yhirano
2016/09/12 04:33:12
ditto as Resource::cancelTimerFired.
hiroshige
2016/09/13 08:43:20
Done.
| |
| 722 ASSERT(m_async); | 727 DCHECK(resource == this->resource()); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 728 DCHECK(m_async); | |
| 723 | 729 |
| 724 m_checker.dataReceived(); | 730 m_checker.dataReceived(); |
| 725 | 731 |
| 726 if (m_isUsingDataConsumerHandle) | 732 if (m_isUsingDataConsumerHandle) |
| 727 return; | 733 return; |
| 728 | 734 |
| 729 // TODO(junov): Fix the ThreadableLoader ecosystem to use size_t. | 735 // TODO(junov): Fix the ThreadableLoader ecosystem to use size_t. |
| 730 // Until then, we use safeCast to trap potential overflows. | 736 // Until then, we use safeCast to trap potential overflows. |
| 731 handleReceivedData(data, safeCast<unsigned>(dataLength)); | 737 handleReceivedData(data, safeCast<unsigned>(dataLength)); |
| 732 } | 738 } |
| 733 | 739 |
| 734 void DocumentThreadableLoader::handleReceivedData(const char* data, size_t dataL ength) | 740 void DocumentThreadableLoader::handleReceivedData(const char* data, size_t dataL ength) |
| 735 { | 741 { |
| 736 ASSERT(m_client); | 742 DCHECK(m_client); |
| 737 | 743 |
| 738 // Preflight data should be invisible to clients. | 744 // Preflight data should be invisible to clients. |
| 739 if (!m_actualRequest.isNull()) | 745 if (!m_actualRequest.isNull()) |
| 740 return; | 746 return; |
| 741 | 747 |
| 742 ASSERT(m_fallbackRequestForServiceWorker.isNull()); | 748 DCHECK(m_fallbackRequestForServiceWorker.isNull()); |
| 743 | 749 |
| 744 m_client->didReceiveData(data, dataLength); | 750 m_client->didReceiveData(data, dataLength); |
| 745 } | 751 } |
| 746 | 752 |
| 747 void DocumentThreadableLoader::notifyFinished(Resource* resource) | 753 void DocumentThreadableLoader::notifyFinished(Resource* resource) |
| 748 { | 754 { |
| 749 ASSERT(m_client); | 755 DCHECK(m_client); |
| 750 ASSERT(resource == this->resource()); | 756 DCHECK(resource == this->resource()); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 751 ASSERT(m_async); | 757 DCHECK(m_async); |
| 752 | 758 |
| 753 m_checker.notifyFinished(resource); | 759 m_checker.notifyFinished(resource); |
| 754 | 760 |
| 755 if (resource->errorOccurred()) { | 761 if (resource->errorOccurred()) { |
| 756 handleError(resource->resourceError()); | 762 handleError(resource->resourceError()); |
| 757 } else { | 763 } else { |
| 758 handleSuccessfulFinish(resource->identifier(), resource->loadFinishTime( )); | 764 handleSuccessfulFinish(resource->identifier(), resource->loadFinishTime( )); |
| 759 } | 765 } |
| 760 } | 766 } |
| 761 | 767 |
| 762 void DocumentThreadableLoader::handleSuccessfulFinish(unsigned long identifier, double finishTime) | 768 void DocumentThreadableLoader::handleSuccessfulFinish(unsigned long identifier, double finishTime) |
| 763 { | 769 { |
| 764 ASSERT(m_fallbackRequestForServiceWorker.isNull()); | 770 DCHECK(m_fallbackRequestForServiceWorker.isNull()); |
| 765 | 771 |
| 766 if (!m_actualRequest.isNull()) { | 772 if (!m_actualRequest.isNull()) { |
| 767 // FIXME: Timeout should be applied to whole fetch, not for each of | 773 // FIXME: Timeout should be applied to whole fetch, not for each of |
| 768 // preflight and actual request. | 774 // preflight and actual request. |
| 769 m_timeoutTimer.stop(); | 775 m_timeoutTimer.stop(); |
| 770 ASSERT(!m_sameOriginRequest); | 776 DCHECK(!m_sameOriginRequest); |
| 771 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); | 777 DCHECK(m_options.crossOriginRequestPolicy == UseAccessControl); |
|
yhirano
2016/09/12 04:33:13
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 772 loadActualRequest(); | 778 loadActualRequest(); |
| 773 return; | 779 return; |
| 774 } | 780 } |
| 775 | 781 |
| 776 ThreadableLoaderClient* client = m_client; | 782 ThreadableLoaderClient* client = m_client; |
| 777 // Protect the resource in |didFinishLoading| in order not to release the | 783 // Protect the resource in |didFinishLoading| in order not to release the |
| 778 // downloaded file. | 784 // downloaded file. |
| 779 Persistent<Resource> protect = resource(); | 785 Persistent<Resource> protect = resource(); |
| 780 clear(); | 786 clear(); |
| 781 client->didFinishLoading(identifier, finishTime); | 787 client->didFinishLoading(identifier, finishTime); |
| 782 } | 788 } |
| 783 | 789 |
| 784 void DocumentThreadableLoader::didTimeout(TimerBase* timer) | 790 void DocumentThreadableLoader::didTimeout(TimerBase* timer) |
| 785 { | 791 { |
| 786 ASSERT_UNUSED(timer, timer == &m_timeoutTimer); | 792 ALLOW_UNUSED_LOCAL(timer); |
|
yhirano
2016/09/12 04:33:13
ditto as Resource::cancelTimerFired.
hiroshige
2016/09/13 08:43:20
Done.
| |
| 793 DCHECK(timer == &m_timeoutTimer); | |
|
yhirano
2016/09/12 04:33:12
DCHECK_EQ
hiroshige
2016/09/13 08:43:20
Done.
| |
| 787 | 794 |
| 788 // Using values from net/base/net_error_list.h ERR_TIMED_OUT, | 795 // 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. | 796 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable. |
| 790 static const int timeoutError = -7; | 797 static const int timeoutError = -7; |
| 791 ResourceError error("net", timeoutError, resource()->url(), String()); | 798 ResourceError error("net", timeoutError, resource()->url(), String()); |
| 792 error.setIsTimeout(true); | 799 error.setIsTimeout(true); |
| 793 cancelWithError(error); | 800 cancelWithError(error); |
| 794 } | 801 } |
| 795 | 802 |
| 796 void DocumentThreadableLoader::loadFallbackRequestForServiceWorker() | 803 void DocumentThreadableLoader::loadFallbackRequestForServiceWorker() |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 | 849 |
| 843 ThreadableLoaderClient* client = m_client; | 850 ThreadableLoaderClient* client = m_client; |
| 844 clear(); | 851 clear(); |
| 845 client->didFail(copiedError); | 852 client->didFail(copiedError); |
| 846 } | 853 } |
| 847 | 854 |
| 848 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Resou rceLoaderOptions resourceLoaderOptions) | 855 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Resou rceLoaderOptions resourceLoaderOptions) |
| 849 { | 856 { |
| 850 // Any credential should have been removed from the cross-site requests. | 857 // Any credential should have been removed from the cross-site requests. |
| 851 const KURL& requestURL = request.url(); | 858 const KURL& requestURL = request.url(); |
| 852 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); | 859 DCHECK(m_sameOriginRequest || requestURL.user().isEmpty()); |
| 853 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); | 860 DCHECK(m_sameOriginRequest || requestURL.pass().isEmpty()); |
| 854 | 861 |
| 855 // Update resourceLoaderOptions with enforced values. | 862 // Update resourceLoaderOptions with enforced values. |
| 856 if (m_forceDoNotAllowStoredCredentials) | 863 if (m_forceDoNotAllowStoredCredentials) |
| 857 resourceLoaderOptions.allowCredentials = DoNotAllowStoredCredentials; | 864 resourceLoaderOptions.allowCredentials = DoNotAllowStoredCredentials; |
| 858 resourceLoaderOptions.securityOrigin = m_securityOrigin; | 865 resourceLoaderOptions.securityOrigin = m_securityOrigin; |
| 859 if (m_async) { | 866 if (m_async) { |
| 860 if (!m_actualRequest.isNull()) | 867 if (!m_actualRequest.isNull()) |
| 861 resourceLoaderOptions.dataBufferingPolicy = BufferData; | 868 resourceLoaderOptions.dataBufferingPolicy = BufferData; |
| 862 | 869 |
| 863 if (m_options.timeoutMilliseconds > 0) | 870 if (m_options.timeoutMilliseconds > 0) |
| 864 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, BLINK_FROM_HERE); | 871 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0, BLINK_FROM_HERE); |
| 865 | 872 |
| 866 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti ons); | 873 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti ons); |
| 867 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 874 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
| 868 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); | 875 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); |
| 869 ASSERT(!resource()); | 876 DCHECK(!resource()); |
| 870 | 877 |
| 871 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); | 878 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); |
| 872 | 879 |
| 873 if (request.requestContext() == WebURLRequest::RequestContextVideo || re quest.requestContext() == WebURLRequest::RequestContextAudio) | 880 if (request.requestContext() == WebURLRequest::RequestContextVideo || re quest.requestContext() == WebURLRequest::RequestContextAudio) |
| 874 setResource(RawResource::fetchMedia(newRequest, document().fetcher() )); | 881 setResource(RawResource::fetchMedia(newRequest, document().fetcher() )); |
| 875 else if (request.requestContext() == WebURLRequest::RequestContextManife st) | 882 else if (request.requestContext() == WebURLRequest::RequestContextManife st) |
| 876 setResource(RawResource::fetchManifest(newRequest, document().fetche r())); | 883 setResource(RawResource::fetchManifest(newRequest, document().fetche r())); |
| 877 else | 884 else |
| 878 setResource(RawResource::fetch(newRequest, document().fetcher())); | 885 setResource(RawResource::fetch(newRequest, document().fetcher())); |
| 879 | 886 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 return m_resourceLoaderOptions.allowCredentials; | 981 return m_resourceLoaderOptions.allowCredentials; |
| 975 } | 982 } |
| 976 | 983 |
| 977 const SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const | 984 const SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const |
| 978 { | 985 { |
| 979 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin(); | 986 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri gin(); |
| 980 } | 987 } |
| 981 | 988 |
| 982 Document& DocumentThreadableLoader::document() const | 989 Document& DocumentThreadableLoader::document() const |
| 983 { | 990 { |
| 984 ASSERT(m_document); | 991 DCHECK(m_document); |
| 985 return *m_document; | 992 return *m_document; |
| 986 } | 993 } |
| 987 | 994 |
| 988 DEFINE_TRACE(DocumentThreadableLoader) | 995 DEFINE_TRACE(DocumentThreadableLoader) |
| 989 { | 996 { |
| 990 visitor->trace(m_resource); | 997 visitor->trace(m_resource); |
| 991 visitor->trace(m_document); | 998 visitor->trace(m_document); |
| 992 ThreadableLoader::trace(visitor); | 999 ThreadableLoader::trace(visitor); |
| 993 RawResourceClient::trace(visitor); | 1000 RawResourceClient::trace(visitor); |
| 994 } | 1001 } |
| 995 | 1002 |
| 996 } // namespace blink | 1003 } // namespace blink |
| OLD | NEW |