Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 
| 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 
| 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 
| 7 | 7 | 
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or | 
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public | 
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "core/fetch/ResourceFetcher.h" | 27 #include "core/fetch/ResourceFetcher.h" | 
| 28 | 28 | 
| 29 #include "bindings/core/v8/V8DOMActivityLogger.h" | 29 #include "bindings/core/v8/V8DOMActivityLogger.h" | 
| 30 #include "core/fetch/CrossOriginAccessControl.h" | 30 #include "core/fetch/CrossOriginAccessControl.h" | 
| 31 #include "core/fetch/FetchContext.h" | 31 #include "core/fetch/FetchContext.h" | 
| 32 #include "core/fetch/FetchInitiatorTypeNames.h" | 32 #include "core/fetch/FetchInitiatorTypeNames.h" | 
| 33 #include "core/fetch/ImageResource.h" | 33 #include "core/fetch/ImageResource.h" | 
| 34 #include "core/fetch/MemoryCache.h" | 34 #include "core/fetch/MemoryCache.h" | 
| 35 #include "core/fetch/ResourceLoader.h" | 35 #include "core/fetch/ResourceLoader.h" | 
| 36 #include "core/fetch/ResourceLoaderSet.h" | 36 #include "core/fetch/ResourceLoaderSet.h" | 
| 37 #include "core/fetch/ResourceLoadingLog.h" | |
| 37 #include "core/fetch/UniqueIdentifier.h" | 38 #include "core/fetch/UniqueIdentifier.h" | 
| 38 #include "platform/Histogram.h" | 39 #include "platform/Histogram.h" | 
| 39 #include "platform/Logging.h" | |
| 40 #include "platform/RuntimeEnabledFeatures.h" | 40 #include "platform/RuntimeEnabledFeatures.h" | 
| 41 #include "platform/TraceEvent.h" | 41 #include "platform/TraceEvent.h" | 
| 42 #include "platform/TracedValue.h" | 42 #include "platform/TracedValue.h" | 
| 43 #include "platform/mhtml/ArchiveResource.h" | 43 #include "platform/mhtml/ArchiveResource.h" | 
| 44 #include "platform/mhtml/MHTMLArchive.h" | 44 #include "platform/mhtml/MHTMLArchive.h" | 
| 45 #include "platform/network/ResourceTimingInfo.h" | 45 #include "platform/network/ResourceTimingInfo.h" | 
| 46 #include "platform/weborigin/KnownPorts.h" | 46 #include "platform/weborigin/KnownPorts.h" | 
| 47 #include "platform/weborigin/SecurityOrigin.h" | 47 #include "platform/weborigin/SecurityOrigin.h" | 
| 48 #include "platform/weborigin/SecurityPolicy.h" | 48 #include "platform/weborigin/SecurityPolicy.h" | 
| 49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" | 
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 } | 584 } | 
| 585 | 585 | 
| 586 resource->setRevalidatingRequest(revalidatingRequest); | 586 resource->setRevalidatingRequest(revalidatingRequest); | 
| 587 } | 587 } | 
| 588 | 588 | 
| 589 Resource* ResourceFetcher::createResourceForLoading(FetchRequest& request, const String& charset, const ResourceFactory& factory) | 589 Resource* ResourceFetcher::createResourceForLoading(FetchRequest& request, const String& charset, const ResourceFactory& factory) | 
| 590 { | 590 { | 
| 591 const String cacheIdentifier = getCacheIdentifier(); | 591 const String cacheIdentifier = getCacheIdentifier(); | 
| 592 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier)); | 592 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache Identifier)); | 
| 593 | 593 | 
| 594 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque st().url().elidedString().latin1().data()); | 594 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " << request.resourceRequ est().url().elidedString(); | 
| 
 
tyoshino (SeeGerritForStatus)
2016/08/12 07:32:19
oh, does this change make this line run .elidedStr
 
tkent
2016/08/12 07:43:45
Both of clang and MSVC are clever enough.  They do
 
 | |
| 595 | 595 | 
| 596 Resource* resource = factory.create(request.resourceRequest(), request.optio ns(), charset); | 596 Resource* resource = factory.create(request.resourceRequest(), request.optio ns(), charset); | 
| 597 resource->setLinkPreload(request.isLinkPreload()); | 597 resource->setLinkPreload(request.isLinkPreload()); | 
| 598 if (request.forPreload()) { | 598 if (request.forPreload()) { | 
| 599 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); | 599 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); | 
| 600 } | 600 } | 
| 601 resource->setCacheIdentifier(cacheIdentifier); | 601 resource->setCacheIdentifier(cacheIdentifier); | 
| 602 | 602 | 
| 603 // Don't add main resource to cache to prevent reuse. | 603 // Don't add main resource to cache to prevent reuse. | 
| 604 if (factory.type() != Resource::MainResource) | 604 if (factory.type() != Resource::MainResource) | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 // We already have a preload going for this URL. | 662 // We already have a preload going for this URL. | 
| 663 if (fetchRequest.forPreload() && existingResource->isPreloaded()) | 663 if (fetchRequest.forPreload() && existingResource->isPreloaded()) | 
| 664 return Use; | 664 return Use; | 
| 665 | 665 | 
| 666 // If the same URL has been loaded as a different type, we need to reload. | 666 // If the same URL has been loaded as a different type, we need to reload. | 
| 667 if (existingResource->getType() != type) { | 667 if (existingResource->getType() != type) { | 
| 668 // FIXME: If existingResource is a Preload and the new type is LinkPrefe tch | 668 // FIXME: If existingResource is a Preload and the new type is LinkPrefe tch | 
| 669 // We really should discard the new prefetch since the preload has more | 669 // We really should discard the new prefetch since the preload has more | 
| 670 // specific type information! crbug.com/379893 | 670 // specific type information! crbug.com/379893 | 
| 671 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case. | 671 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case. | 
| 672 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to type mismatch."); | 672 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPoli cy reloading due to type mismatch."; | 
| 673 return Reload; | 673 return Reload; | 
| 674 } | 674 } | 
| 675 | 675 | 
| 676 // Do not load from cache if images are not enabled. | 676 // Do not load from cache if images are not enabled. | 
| 677 // There are two general cases: | 677 // There are two general cases: | 
| 678 // 1. Images are disabled. Don't ever load images, even if the image is | 678 // 1. Images are disabled. Don't ever load images, even if the image is | 
| 679 // cached or it is a data: url. In this case, we "Reload" the image, | 679 // cached or it is a data: url. In this case, we "Reload" the image, | 
| 680 // then defer it with resourceNeedsLoad() so that it never actually | 680 // then defer it with resourceNeedsLoad() so that it never actually | 
| 681 // goes to the network. | 681 // goes to the network. | 
| 682 // 2. Images are enabled, but not loaded automatically. In this case, we | 682 // 2. Images are enabled, but not loaded automatically. In this case, we | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 if (existingResource->isPreloaded()) | 727 if (existingResource->isPreloaded()) | 
| 728 return Use; | 728 return Use; | 
| 729 | 729 | 
| 730 // CachePolicyHistoryBuffer uses the cache no matter what. | 730 // CachePolicyHistoryBuffer uses the cache no matter what. | 
| 731 CachePolicy cachePolicy = context().getCachePolicy(); | 731 CachePolicy cachePolicy = context().getCachePolicy(); | 
| 732 if (cachePolicy == CachePolicyHistoryBuffer) | 732 if (cachePolicy == CachePolicyHistoryBuffer) | 
| 733 return Use; | 733 return Use; | 
| 734 | 734 | 
| 735 // Don't reuse resources with Cache-control: no-store. | 735 // Don't reuse resources with Cache-control: no-store. | 
| 736 if (existingResource->hasCacheControlNoStoreHeader()) { | 736 if (existingResource->hasCacheControlNoStoreHeader()) { | 
| 737 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to Cache-control: no-store."); | 737 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPoli cy reloading due to Cache-control: no-store."; | 
| 738 return Reload; | 738 return Reload; | 
| 739 } | 739 } | 
| 740 | 740 | 
| 741 // If credentials were sent with the previous request and won't be | 741 // If credentials were sent with the previous request and won't be | 
| 742 // with this one, or vice versa, re-fetch the resource. | 742 // with this one, or vice versa, re-fetch the resource. | 
| 743 // | 743 // | 
| 744 // This helps with the case where the server sends back | 744 // This helps with the case where the server sends back | 
| 745 // "Access-Control-Allow-Origin: *" all the time, but some of the | 745 // "Access-Control-Allow-Origin: *" all the time, but some of the | 
| 746 // client's requests are made without CORS and some with. | 746 // client's requests are made without CORS and some with. | 
| 747 if (existingResource->resourceRequest().allowStoredCredentials() != request. allowStoredCredentials()) { | 747 if (existingResource->resourceRequest().allowStoredCredentials() != request. allowStoredCredentials()) { | 
| 748 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to difference in credentials settings."); | 748 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPoli cy reloading due to difference in credentials settings."; | 
| 749 return Reload; | 749 return Reload; | 
| 750 } | 750 } | 
| 751 | 751 | 
| 752 // During the initial load, avoid loading the same resource multiple times f or a single document, | 752 // During the initial load, avoid loading the same resource multiple times f or a single document, | 
| 753 // even if the cache policies would tell us to. | 753 // even if the cache policies would tell us to. | 
| 754 // We also group loads of the same resource together. | 754 // We also group loads of the same resource together. | 
| 755 // Raw resources are exempted, as XHRs fall into this category and may have user-set Cache-Control: | 755 // Raw resources are exempted, as XHRs fall into this category and may have user-set Cache-Control: | 
| 756 // headers or other factors that require separate requests. | 756 // headers or other factors that require separate requests. | 
| 757 if (type != Resource::Raw) { | 757 if (type != Resource::Raw) { | 
| 758 if (!context().isLoadComplete() && m_validatedURLs.contains(existingReso urce->url())) | 758 if (!context().isLoadComplete() && m_validatedURLs.contains(existingReso urce->url())) | 
| 759 return Use; | 759 return Use; | 
| 760 if (existingResource->isLoading()) | 760 if (existingResource->isLoading()) | 
| 761 return Use; | 761 return Use; | 
| 762 } | 762 } | 
| 763 | 763 | 
| 764 if (request.getCachePolicy() == WebCachePolicy::BypassingCache) | 764 if (request.getCachePolicy() == WebCachePolicy::BypassingCache) | 
| 765 return Reload; | 765 return Reload; | 
| 766 | 766 | 
| 767 // CachePolicyReload always reloads | 767 // CachePolicyReload always reloads | 
| 768 if (cachePolicy == CachePolicyReload) { | 768 if (cachePolicy == CachePolicyReload) { | 
| 769 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to CachePolicyReload."); | 769 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPoli cy reloading due to CachePolicyReload."; | 
| 770 return Reload; | 770 return Reload; | 
| 771 } | 771 } | 
| 772 | 772 | 
| 773 // We'll try to reload the resource if it failed last time. | 773 // We'll try to reload the resource if it failed last time. | 
| 774 if (existingResource->errorOccurred()) { | 774 if (existingResource->errorOccurred()) { | 
| 775 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicye reloading due to resource being in the error state"); | 775 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPoli cye reloading due to resource being in the error state"; | 
| 776 return Reload; | 776 return Reload; | 
| 777 } | 777 } | 
| 778 | 778 | 
| 779 // List of available images logic allows images to be re-used without cache validation. We restrict this only to images | 779 // List of available images logic allows images to be re-used without cache validation. We restrict this only to images | 
| 780 // from memory cache which are the same as the version in the current docume nt. | 780 // from memory cache which are the same as the version in the current docume nt. | 
| 781 if (type == Resource::Image && existingResource == cachedResource(request.ur l())) | 781 if (type == Resource::Image && existingResource == cachedResource(request.ur l())) | 
| 782 return Use; | 782 return Use; | 
| 783 | 783 | 
| 784 // Defer to the browser process cache for Vary header handling. | 784 // Defer to the browser process cache for Vary header handling. | 
| 785 if (existingResource->hasVaryHeader()) | 785 if (existingResource->hasVaryHeader()) | 
| 786 return Reload; | 786 return Reload; | 
| 787 | 787 | 
| 788 // If any of the redirects in the chain to loading the resource were not cac heable, we cannot reuse our cached resource. | 788 // If any of the redirects in the chain to loading the resource were not cac heable, we cannot reuse our cached resource. | 
| 789 if (!existingResource->canReuseRedirectChain()) { | 789 if (!existingResource->canReuseRedirectChain()) { | 
| 790 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to an uncacheable redirect"); | 790 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPoli cy reloading due to an uncacheable redirect"; | 
| 791 return Reload; | 791 return Reload; | 
| 792 } | 792 } | 
| 793 | 793 | 
| 794 // Check if the cache headers requires us to revalidate (cache expiration fo r example). | 794 // Check if the cache headers requires us to revalidate (cache expiration fo r example). | 
| 795 if (cachePolicy == CachePolicyRevalidate || existingResource->mustRevalidate DueToCacheHeaders() | 795 if (cachePolicy == CachePolicyRevalidate || existingResource->mustRevalidate DueToCacheHeaders() | 
| 796 || request.cacheControlContainsNoCache()) { | 796 || request.cacheControlContainsNoCache()) { | 
| 797 // See if the resource has usable ETag or Last-modified headers. | 797 // See if the resource has usable ETag or Last-modified headers. | 
| 798 // If the page is controlled by the ServiceWorker, we choose the Reload policy because the revalidation headers should not be exposed to the ServiceWork er.(crbug.com/429570) | 798 // If the page is controlled by the ServiceWorker, we choose the Reload policy because the revalidation headers should not be exposed to the ServiceWork er.(crbug.com/429570) | 
| 799 if (existingResource->canUseCacheValidator() && !context().isControlledB yServiceWorker()) { | 799 if (existingResource->canUseCacheValidator() && !context().isControlledB yServiceWorker()) { | 
| 800 // If the resource is already a cache validator but not started yet, | 800 // If the resource is already a cache validator but not started yet, | 
| 801 // the |Use| policy should be applied to subsequent requests. | 801 // the |Use| policy should be applied to subsequent requests. | 
| 802 if (existingResource->isCacheValidator()) { | 802 if (existingResource->isCacheValidator()) { | 
| 803 DCHECK(existingResource->stillNeedsLoad()); | 803 DCHECK(existingResource->stillNeedsLoad()); | 
| 804 return Use; | 804 return Use; | 
| 805 } | 805 } | 
| 806 return Revalidate; | 806 return Revalidate; | 
| 807 } | 807 } | 
| 808 | 808 | 
| 809 // No, must reload. | 809 // No, must reload. | 
| 810 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to missing cache validators."); | 810 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::determineRevalidationPoli cy reloading due to missing cache validators."; | 
| 811 return Reload; | 811 return Reload; | 
| 812 } | 812 } | 
| 813 | 813 | 
| 814 return Use; | 814 return Use; | 
| 815 } | 815 } | 
| 816 | 816 | 
| 817 void ResourceFetcher::setAutoLoadImages(bool enable) | 817 void ResourceFetcher::setAutoLoadImages(bool enable) | 
| 818 { | 818 { | 
| 819 if (enable == m_autoLoadImages) | 819 if (enable == m_autoLoadImages) | 
| 820 return; | 820 return; | 
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1314 visitor->trace(m_context); | 1314 visitor->trace(m_context); | 
| 1315 visitor->trace(m_archive); | 1315 visitor->trace(m_archive); | 
| 1316 visitor->trace(m_loaders); | 1316 visitor->trace(m_loaders); | 
| 1317 visitor->trace(m_nonBlockingLoaders); | 1317 visitor->trace(m_nonBlockingLoaders); | 
| 1318 visitor->trace(m_documentResources); | 1318 visitor->trace(m_documentResources); | 
| 1319 visitor->trace(m_preloads); | 1319 visitor->trace(m_preloads); | 
| 1320 visitor->trace(m_resourceTimingInfoMap); | 1320 visitor->trace(m_resourceTimingInfoMap); | 
| 1321 } | 1321 } | 
| 1322 | 1322 | 
| 1323 } // namespace blink | 1323 } // namespace blink | 
| OLD | NEW |