| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. |
| 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) | 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) |
| 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 | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. 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 11 matching lines...) Expand all Loading... |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "platform/loader/fetch/ResourceLoader.h" | 30 #include "platform/loader/fetch/ResourceLoader.h" |
| 31 | 31 |
| 32 #include <memory> |
| 32 #include "platform/SharedBuffer.h" | 33 #include "platform/SharedBuffer.h" |
| 33 #include "platform/exported/WrappedResourceRequest.h" | 34 #include "platform/exported/WrappedResourceRequest.h" |
| 34 #include "platform/exported/WrappedResourceResponse.h" | 35 #include "platform/exported/WrappedResourceResponse.h" |
| 36 #include "platform/instrumentation/inspector/PlatformInspectorTraceEvents.h" |
| 35 #include "platform/loader/fetch/CrossOriginAccessControl.h" | 37 #include "platform/loader/fetch/CrossOriginAccessControl.h" |
| 36 #include "platform/loader/fetch/FetchContext.h" | 38 #include "platform/loader/fetch/FetchContext.h" |
| 37 #include "platform/loader/fetch/Resource.h" | 39 #include "platform/loader/fetch/Resource.h" |
| 38 #include "platform/loader/fetch/ResourceFetcher.h" | 40 #include "platform/loader/fetch/ResourceFetcher.h" |
| 39 #include "platform/network/NetworkInstrumentation.h" | 41 #include "platform/network/NetworkInstrumentation.h" |
| 40 #include "platform/network/ResourceError.h" | 42 #include "platform/network/ResourceError.h" |
| 41 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 42 #include "public/platform/WebCachePolicy.h" | 44 #include "public/platform/WebCachePolicy.h" |
| 43 #include "public/platform/WebData.h" | 45 #include "public/platform/WebData.h" |
| 44 #include "public/platform/WebURLError.h" | 46 #include "public/platform/WebURLError.h" |
| 45 #include "public/platform/WebURLRequest.h" | 47 #include "public/platform/WebURLRequest.h" |
| 46 #include "public/platform/WebURLResponse.h" | 48 #include "public/platform/WebURLResponse.h" |
| 47 #include "wtf/Assertions.h" | 49 #include "wtf/Assertions.h" |
| 48 #include "wtf/CurrentTime.h" | 50 #include "wtf/CurrentTime.h" |
| 49 #include "wtf/PtrUtil.h" | 51 #include "wtf/PtrUtil.h" |
| 50 #include "wtf/text/StringBuilder.h" | 52 #include "wtf/text/StringBuilder.h" |
| 51 #include <memory> | |
| 52 | 53 |
| 53 namespace blink { | 54 namespace blink { |
| 54 | 55 |
| 55 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, | 56 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, |
| 56 Resource* resource) { | 57 Resource* resource) { |
| 57 return new ResourceLoader(fetcher, resource); | 58 return new ResourceLoader(fetcher, resource); |
| 58 } | 59 } |
| 59 | 60 |
| 60 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) | 61 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) |
| 61 : m_fetcher(fetcher), | 62 : m_fetcher(fetcher), |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } else if (m_resource->options().corsEnabled == IsCORSEnabled) { | 365 } else if (m_resource->options().corsEnabled == IsCORSEnabled) { |
| 365 ResourceRequestBlockedReason blockedReason = | 366 ResourceRequestBlockedReason blockedReason = |
| 366 canAccessResponse(m_resource, response); | 367 canAccessResponse(m_resource, response); |
| 367 if (blockedReason != ResourceRequestBlockedReason::None) { | 368 if (blockedReason != ResourceRequestBlockedReason::None) { |
| 368 handleError(ResourceError::cancelledDueToAccessCheckError(response.url(), | 369 handleError(ResourceError::cancelledDueToAccessCheckError(response.url(), |
| 369 blockedReason)); | 370 blockedReason)); |
| 370 return; | 371 return; |
| 371 } | 372 } |
| 372 } | 373 } |
| 373 | 374 |
| 375 TRACE_EVENT1( |
| 376 "devtools.timeline", "ResourceReceiveResponse", "data", |
| 377 InspectorReceiveResponseEvent::data(m_resource->identifier(), response)); |
| 378 |
| 374 context().dispatchDidReceiveResponse( | 379 context().dispatchDidReceiveResponse( |
| 375 m_resource->identifier(), response, | 380 m_resource->identifier(), response, |
| 376 m_resource->resourceRequest().frameType(), | 381 m_resource->resourceRequest().frameType(), |
| 377 m_resource->resourceRequest().requestContext(), m_resource); | 382 m_resource->resourceRequest().requestContext(), m_resource); |
| 378 | 383 |
| 379 m_resource->responseReceived(response, std::move(handle)); | 384 m_resource->responseReceived(response, std::move(handle)); |
| 380 if (!m_resource->loader()) | 385 if (!m_resource->loader()) |
| 381 return; | 386 return; |
| 382 | 387 |
| 383 if (response.httpStatusCode() >= 400 && | 388 if (response.httpStatusCode() >= 400 && |
| 384 !m_resource->shouldIgnoreHTTPStatusCodeErrors()) | 389 !m_resource->shouldIgnoreHTTPStatusCodeErrors()) |
| 385 handleError(ResourceError::cancelledError(response.url())); | 390 handleError(ResourceError::cancelledError(response.url())); |
| 386 } | 391 } |
| 387 | 392 |
| 388 void ResourceLoader::didReceiveResponse(const WebURLResponse& response) { | 393 void ResourceLoader::didReceiveResponse(const WebURLResponse& response) { |
| 389 didReceiveResponse(response, nullptr); | 394 didReceiveResponse(response, nullptr); |
| 390 } | 395 } |
| 391 | 396 |
| 392 void ResourceLoader::didDownloadData(int length, int encodedDataLength) { | 397 void ResourceLoader::didDownloadData(int length, int encodedDataLength) { |
| 398 TRACE_EVENT1("devtools.timeline", "ResourceReceivedData", "data", |
| 399 InspectorReceiveDataEvent::data(m_resource->identifier(), |
| 400 encodedDataLength)); |
| 393 context().dispatchDidDownloadData(m_resource->identifier(), length, | 401 context().dispatchDidDownloadData(m_resource->identifier(), length, |
| 394 encodedDataLength); | 402 encodedDataLength); |
| 395 m_resource->didDownloadData(length); | 403 m_resource->didDownloadData(length); |
| 396 } | 404 } |
| 397 | 405 |
| 398 void ResourceLoader::didReceiveData(const char* data, int length) { | 406 void ResourceLoader::didReceiveData(const char* data, int length) { |
| 399 CHECK_GE(length, 0); | 407 CHECK_GE(length, 0); |
| 400 | 408 |
| 409 TRACE_EVENT1( |
| 410 "devtools.timeline", "ResourceReceivedData", "data", |
| 411 InspectorReceiveDataEvent::data(m_resource->identifier(), length)); |
| 401 context().dispatchDidReceiveData(m_resource->identifier(), data, length); | 412 context().dispatchDidReceiveData(m_resource->identifier(), data, length); |
| 402 m_resource->addToDecodedBodyLength(length); | 413 m_resource->addToDecodedBodyLength(length); |
| 403 m_resource->appendData(data, length); | 414 m_resource->appendData(data, length); |
| 404 } | 415 } |
| 405 | 416 |
| 406 void ResourceLoader::didReceiveTransferSizeUpdate(int transferSizeDiff) { | 417 void ResourceLoader::didReceiveTransferSizeUpdate(int transferSizeDiff) { |
| 407 DCHECK_GT(transferSizeDiff, 0); | 418 DCHECK_GT(transferSizeDiff, 0); |
| 408 context().dispatchDidReceiveEncodedData(m_resource->identifier(), | 419 context().dispatchDidReceiveEncodedData(m_resource->identifier(), |
| 409 transferSizeDiff); | 420 transferSizeDiff); |
| 410 } | 421 } |
| 411 | 422 |
| 412 void ResourceLoader::didFinishLoadingFirstPartInMultipart() { | 423 void ResourceLoader::didFinishLoadingFirstPartInMultipart() { |
| 424 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 425 InspectorResourceFinishEvent::data( |
| 426 m_resource->identifier(), 0, false, |
| 427 m_resource->response().encodedDataLength())); |
| 413 network_instrumentation::endResourceLoad( | 428 network_instrumentation::endResourceLoad( |
| 414 m_resource->identifier(), | 429 m_resource->identifier(), |
| 415 network_instrumentation::RequestOutcome::Success); | 430 network_instrumentation::RequestOutcome::Success); |
| 416 | 431 |
| 417 m_fetcher->handleLoaderFinish(m_resource.get(), 0, | 432 m_fetcher->handleLoaderFinish(m_resource.get(), 0, |
| 418 ResourceFetcher::DidFinishFirstPartInMultipart); | 433 ResourceFetcher::DidFinishFirstPartInMultipart); |
| 419 } | 434 } |
| 420 | 435 |
| 421 void ResourceLoader::didFinishLoading(double finishTime, | 436 void ResourceLoader::didFinishLoading(double finishTime, |
| 422 int64_t encodedDataLength, | 437 int64_t encodedDataLength, |
| 423 int64_t encodedBodyLength) { | 438 int64_t encodedBodyLength) { |
| 439 TRACE_EVENT1( |
| 440 "devtools.timeline", "ResourceFinish", "data", |
| 441 InspectorResourceFinishEvent::data(m_resource->identifier(), finishTime, |
| 442 false, encodedDataLength)); |
| 424 m_resource->setEncodedDataLength(encodedDataLength); | 443 m_resource->setEncodedDataLength(encodedDataLength); |
| 425 m_resource->addToEncodedBodyLength(encodedBodyLength); | 444 m_resource->addToEncodedBodyLength(encodedBodyLength); |
| 426 | |
| 427 m_loader.reset(); | 445 m_loader.reset(); |
| 428 | 446 |
| 429 network_instrumentation::endResourceLoad( | 447 network_instrumentation::endResourceLoad( |
| 430 m_resource->identifier(), | 448 m_resource->identifier(), |
| 431 network_instrumentation::RequestOutcome::Success); | 449 network_instrumentation::RequestOutcome::Success); |
| 432 | 450 |
| 433 m_fetcher->handleLoaderFinish(m_resource.get(), finishTime, | 451 m_fetcher->handleLoaderFinish(m_resource.get(), finishTime, |
| 434 ResourceFetcher::DidFinishLoading); | 452 ResourceFetcher::DidFinishLoading); |
| 435 } | 453 } |
| 436 | 454 |
| 437 void ResourceLoader::didFail(const WebURLError& error, | 455 void ResourceLoader::didFail(const WebURLError& error, |
| 438 int64_t encodedDataLength, | 456 int64_t encodedDataLength, |
| 439 int64_t encodedBodyLength) { | 457 int64_t encodedBodyLength) { |
| 440 m_resource->setEncodedDataLength(encodedDataLength); | 458 m_resource->setEncodedDataLength(encodedDataLength); |
| 441 m_resource->addToEncodedBodyLength(encodedBodyLength); | 459 m_resource->addToEncodedBodyLength(encodedBodyLength); |
| 442 handleError(error); | 460 handleError(error); |
| 443 } | 461 } |
| 444 | 462 |
| 445 void ResourceLoader::handleError(const ResourceError& error) { | 463 void ResourceLoader::handleError(const ResourceError& error) { |
| 446 if (m_isCacheAwareLoadingActivated && error.isCacheMiss() && | 464 if (m_isCacheAwareLoadingActivated && error.isCacheMiss() && |
| 447 context().shouldLoadNewResource(m_resource->getType())) { | 465 context().shouldLoadNewResource(m_resource->getType())) { |
| 448 m_resource->willReloadAfterDiskCacheMiss(); | 466 m_resource->willReloadAfterDiskCacheMiss(); |
| 449 m_isCacheAwareLoadingActivated = false; | 467 m_isCacheAwareLoadingActivated = false; |
| 450 restart(m_resource->resourceRequest()); | 468 restart(m_resource->resourceRequest()); |
| 451 return; | 469 return; |
| 452 } | 470 } |
| 453 | 471 |
| 472 TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
| 473 InspectorResourceFinishEvent::data( |
| 474 m_resource->identifier(), 0, true, |
| 475 m_resource->response().encodedDataLength())); |
| 454 m_loader.reset(); | 476 m_loader.reset(); |
| 455 | 477 |
| 456 network_instrumentation::endResourceLoad( | 478 network_instrumentation::endResourceLoad( |
| 457 m_resource->identifier(), network_instrumentation::RequestOutcome::Fail); | 479 m_resource->identifier(), network_instrumentation::RequestOutcome::Fail); |
| 458 | 480 |
| 459 m_fetcher->handleLoaderError(m_resource.get(), error); | 481 m_fetcher->handleLoaderError(m_resource.get(), error); |
| 460 } | 482 } |
| 461 | 483 |
| 462 void ResourceLoader::requestSynchronously(const ResourceRequest& request) { | 484 void ResourceLoader::requestSynchronously(const ResourceRequest& request) { |
| 463 // downloadToFile is not supported for synchronous requests. | 485 // downloadToFile is not supported for synchronous requests. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 return; | 543 return; |
| 522 | 544 |
| 523 // Don't activate if cache policy is explicitly set. | 545 // Don't activate if cache policy is explicitly set. |
| 524 if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy) | 546 if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy) |
| 525 return; | 547 return; |
| 526 | 548 |
| 527 m_isCacheAwareLoadingActivated = true; | 549 m_isCacheAwareLoadingActivated = true; |
| 528 } | 550 } |
| 529 | 551 |
| 530 } // namespace blink | 552 } // namespace blink |
| OLD | NEW |