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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp

Issue 1802123002: Unify Resource loading status tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 256
257 bool ResourceFetcher::isControlledByServiceWorker() const 257 bool ResourceFetcher::isControlledByServiceWorker() const
258 { 258 {
259 return context().isControlledByServiceWorker(); 259 return context().isControlledByServiceWorker();
260 } 260 }
261 261
262 bool ResourceFetcher::resourceNeedsLoad(Resource* resource, const FetchRequest& request, RevalidationPolicy policy) 262 bool ResourceFetcher::resourceNeedsLoad(Resource* resource, const FetchRequest& request, RevalidationPolicy policy)
263 { 263 {
264 if (FetchRequest::DeferredByClient == request.defer()) 264 if (FetchRequest::DeferredByClient == request.defer())
265 return false; 265 return false;
266 if (resource->isImage() && shouldDeferImageLoad(resource->url()))
267 return false;
266 return policy != Use || resource->stillNeedsLoad(); 268 return policy != Use || resource->stillNeedsLoad();
267 } 269 }
268 270
269 // Limit the number of URLs in m_validatedURLs to avoid memory bloat. 271 // Limit the number of URLs in m_validatedURLs to avoid memory bloat.
270 // http://crbug.com/52411 272 // http://crbug.com/52411
271 static const int kMaxValidatedURLsSize = 10000; 273 static const int kMaxValidatedURLsSize = 10000;
272 274
273 void ResourceFetcher::requestLoadStarted(Resource* resource, const FetchRequest& request, ResourceLoadStartType type, bool isStaticData) 275 void ResourceFetcher::requestLoadStarted(Resource* resource, const FetchRequest& request, ResourceLoadStartType type, bool isStaticData)
274 { 276 {
275 if (type == ResourceLoadingFromCache && resource->getStatus() == Resource::C ached && !m_validatedURLs.contains(resource->url())) 277 if (type == ResourceLoadingFromCache && resource->getStatus() == Resource::C ached && !m_validatedURLs.contains(resource->url()))
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 // If the same URL has been loaded as a different type, we need to reload. 665 // If the same URL has been loaded as a different type, we need to reload.
664 if (existingResource->getType() != type) { 666 if (existingResource->getType() != type) {
665 // FIXME: If existingResource is a Preload and the new type is LinkPrefe tch 667 // FIXME: If existingResource is a Preload and the new type is LinkPrefe tch
666 // We really should discard the new prefetch since the preload has more 668 // We really should discard the new prefetch since the preload has more
667 // specific type information! crbug.com/379893 669 // specific type information! crbug.com/379893
668 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case. 670 // fast/dom/HTMLLinkElement/link-and-subresource-test hits this case.
669 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to type mismatch."); 671 WTF_LOG(ResourceLoading, "ResourceFetcher::determineRevalidationPolicy r eloading due to type mismatch.");
670 return Reload; 672 return Reload;
671 } 673 }
672 674
673 // Do not load from cache if images are not enabled. The load for this image will be blocked 675 // Do not load from cache if images are not enabled.
674 // in ImageResource::load. 676 // There are two general cases:
677 // 1. Images are disabled. Don't ever load images, even if the image is
678 // cached or it is a data: url. In this case, we "Reload" the image,
679 // then defer it with resourceNeedsLoad() so that it never actually
680 // goes to the network.
681 // 2. Images are enabled, but not loaded automatically. In this case, we
682 // will Use cached resources or data: urls, but will similarly fall back
683 // to a deferred network load if we don't have the data available
684 // without a network request. We check allowImage() here, which is
685 // affected by m_imagesEnabled but not m_autoLoadImages, in order to
686 // allow for this differing behavior.
687 // TODO(japhet): Can we get rid of one of these settings?
675 if (FetchRequest::DeferredByClient == fetchRequest.defer()) 688 if (FetchRequest::DeferredByClient == fetchRequest.defer())
676 return Reload; 689 return Reload;
690 if (existingResource->isImage() && !context().allowImage(m_imagesEnabled, ex istingResource->url()))
691 return Reload;
677 692
678 // Never use cache entries for downloadToFile / useStreamOnResponse 693 // Never use cache entries for downloadToFile / useStreamOnResponse
679 // requests. The data will be delivered through other paths. 694 // requests. The data will be delivered through other paths.
680 if (request.downloadToFile() || request.useStreamOnResponse()) 695 if (request.downloadToFile() || request.useStreamOnResponse())
681 return Reload; 696 return Reload;
682 697
683 // If resource was populated from a SubstituteData load or data: url, use it . 698 // If resource was populated from a SubstituteData load or data: url, use it .
684 if (isStaticData) 699 if (isStaticData)
685 return Use; 700 return Use;
686 701
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 return; 832 return;
818 833
819 m_imagesEnabled = enable; 834 m_imagesEnabled = enable;
820 835
821 if (!m_imagesEnabled) 836 if (!m_imagesEnabled)
822 return; 837 return;
823 838
824 reloadImagesIfNotDeferred(); 839 reloadImagesIfNotDeferred();
825 } 840 }
826 841
827 bool ResourceFetcher::clientDefersImage(const KURL& url) const
828 {
829 return !context().allowImage(m_imagesEnabled, url);
830 }
831
832 bool ResourceFetcher::shouldDeferImageLoad(const KURL& url) const 842 bool ResourceFetcher::shouldDeferImageLoad(const KURL& url) const
833 { 843 {
834 return clientDefersImage(url) || !m_autoLoadImages; 844 return !context().allowImage(m_imagesEnabled, url) || !m_autoLoadImages;
835 } 845 }
836 846
837 void ResourceFetcher::reloadImagesIfNotDeferred() 847 void ResourceFetcher::reloadImagesIfNotDeferred()
838 { 848 {
839 // TODO(japhet): Once oilpan ships, the const auto& 849 // TODO(japhet): Once oilpan ships, the const auto&
840 // can be replaced with a Resource*. Also, null checking 850 // can be replaced with a Resource*. Also, null checking
841 // the resource probably won't be necesssary. 851 // the resource probably won't be necesssary.
842 for (const auto& documentResource : m_documentResources) { 852 for (const auto& documentResource : m_documentResources) {
843 Resource* resource = documentResource.value.get(); 853 Resource* resource = documentResource.value.get();
844 if (resource && resource->getType() == Resource::Image && resource->stil lNeedsLoad() && !clientDefersImage(resource->url())) 854 if (resource && resource->getType() == Resource::Image && resource->stil lNeedsLoad() && !shouldDeferImageLoad(resource->url()))
845 const_cast<Resource*>(resource)->load(this); 855 const_cast<Resource*>(resource)->load(this);
846 } 856 }
847 } 857 }
848 858
849 void ResourceFetcher::didLoadResource(Resource* resource) 859 void ResourceFetcher::didLoadResource(Resource* resource)
850 { 860 {
851 context().didLoadResource(resource); 861 context().didLoadResource(resource);
852 } 862 }
853 863
854 int ResourceFetcher::requestCount() const 864 int ResourceFetcher::requestCount() const
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 visitor->trace(m_loaders); 1214 visitor->trace(m_loaders);
1205 visitor->trace(m_nonBlockingLoaders); 1215 visitor->trace(m_nonBlockingLoaders);
1206 #if ENABLE(OILPAN) 1216 #if ENABLE(OILPAN)
1207 visitor->trace(m_documentResources); 1217 visitor->trace(m_documentResources);
1208 visitor->trace(m_preloads); 1218 visitor->trace(m_preloads);
1209 visitor->trace(m_resourceTimingInfoMap); 1219 visitor->trace(m_resourceTimingInfoMap);
1210 #endif 1220 #endif
1211 } 1221 }
1212 1222
1213 } // namespace blink 1223 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698