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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp
index a19aca0eb08c5a07fe6d24b8a7b43221772fafa0..a5cc982d7fcc701e62798a251e9f312141b72bb0 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp
+++ b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp
@@ -263,6 +263,8 @@ bool ResourceFetcher::resourceNeedsLoad(Resource* resource, const FetchRequest&
{
if (FetchRequest::DeferredByClient == request.defer())
return false;
+ if (resource->isImage() && shouldDeferImageLoad(resource->url()))
+ return false;
return policy != Use || resource->stillNeedsLoad();
}
@@ -670,10 +672,23 @@ ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy
return Reload;
}
- // Do not load from cache if images are not enabled. The load for this image will be blocked
- // in ImageResource::load.
+ // Do not load from cache if images are not enabled.
+ // There are two general cases:
+ // 1. Images are disabled. Don't ever load images, even if the image is
+ // cached or it is a data: url. In this case, we "Reload" the image,
+ // then defer it with resourceNeedsLoad() so that it never actually
+ // goes to the network.
+ // 2. Images are enabled, but not loaded automatically. In this case, we
+ // will Use cached resources or data: urls, but will similarly fall back
+ // to a deferred network load if we don't have the data available
+ // without a network request. We check allowImage() here, which is
+ // affected by m_imagesEnabled but not m_autoLoadImages, in order to
+ // allow for this differing behavior.
+ // TODO(japhet): Can we get rid of one of these settings?
if (FetchRequest::DeferredByClient == fetchRequest.defer())
return Reload;
+ if (existingResource->isImage() && !context().allowImage(m_imagesEnabled, existingResource->url()))
+ return Reload;
// Never use cache entries for downloadToFile / useStreamOnResponse
// requests. The data will be delivered through other paths.
@@ -824,14 +839,9 @@ void ResourceFetcher::setImagesEnabled(bool enable)
reloadImagesIfNotDeferred();
}
-bool ResourceFetcher::clientDefersImage(const KURL& url) const
-{
- return !context().allowImage(m_imagesEnabled, url);
-}
-
bool ResourceFetcher::shouldDeferImageLoad(const KURL& url) const
{
- return clientDefersImage(url) || !m_autoLoadImages;
+ return !context().allowImage(m_imagesEnabled, url) || !m_autoLoadImages;
}
void ResourceFetcher::reloadImagesIfNotDeferred()
@@ -841,7 +851,7 @@ void ResourceFetcher::reloadImagesIfNotDeferred()
// the resource probably won't be necesssary.
for (const auto& documentResource : m_documentResources) {
Resource* resource = documentResource.value.get();
- if (resource && resource->getType() == Resource::Image && resource->stillNeedsLoad() && !clientDefersImage(resource->url()))
+ if (resource && resource->getType() == Resource::Image && resource->stillNeedsLoad() && !shouldDeferImageLoad(resource->url()))
const_cast<Resource*>(resource)->load(this);
}
}

Powered by Google App Engine
This is Rietveld 408576698