summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjaphet <japhet@chromium.org>2016-03-25 11:58:33 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-25 18:59:43 +0000
commit32360d4f64daee1daa4bb4d40d66324da0e782ba (patch)
tree16bc4574e7e9e5053df7306434bf2367c7a98006
parent4df8cbc77ab72ba4012c4d949774299352d2abb1 (diff)
downloadchromium_src-32360d4f64daee1daa4bb4d40d66324da0e782ba.zip
chromium_src-32360d4f64daee1daa4bb4d40d66324da0e782ba.tar.gz
chromium_src-32360d4f64daee1daa4bb4d40d66324da0e782ba.tar.bz2
Unify Resource loading status tracking
Resource keeps an m_loading bit as well as an m_status enum. m_loading mostly corresponds to m_status == Pending, so unify them. FontResource also keeps a separate state enum. Merge most of that into Resource::Status. Centralize image deferral logic in ResourceFetcher, rather than having ImageResource::load() and ImageResource::fetch() participate. BUG= Review URL: https://codereview.chromium.org/1802123002 Cr-Commit-Position: refs/heads/master@{#383326}
-rw-r--r--third_party/WebKit/LayoutTests/permissionclient/image-permissions-expected.txt3
-rw-r--r--third_party/WebKit/Source/bindings/core/v8/ScriptStreamerTest.cpp4
-rw-r--r--third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp2
-rw-r--r--third_party/WebKit/Source/core/fetch/CachingCorrectnessTest.cpp14
-rw-r--r--third_party/WebKit/Source/core/fetch/FontResource.cpp28
-rw-r--r--third_party/WebKit/Source/core/fetch/FontResource.h7
-rw-r--r--third_party/WebKit/Source/core/fetch/ImageResource.cpp18
-rw-r--r--third_party/WebKit/Source/core/fetch/ImageResource.h3
-rw-r--r--third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp6
-rw-r--r--third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp2
-rw-r--r--third_party/WebKit/Source/core/fetch/RawResourceTest.cpp4
-rw-r--r--third_party/WebKit/Source/core/fetch/Resource.cpp22
-rw-r--r--third_party/WebKit/Source/core/fetch/Resource.h18
-rw-r--r--third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp28
-rw-r--r--third_party/WebKit/Source/core/fetch/ResourceFetcher.h8
-rw-r--r--third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp26
-rw-r--r--third_party/WebKit/Source/core/loader/ImageLoader.cpp2
17 files changed, 86 insertions, 109 deletions
diff --git a/third_party/WebKit/LayoutTests/permissionclient/image-permissions-expected.txt b/third_party/WebKit/LayoutTests/permissionclient/image-permissions-expected.txt
index b5382ab4..22a9cd3 100644
--- a/third_party/WebKit/LayoutTests/permissionclient/image-permissions-expected.txt
+++ b/third_party/WebKit/LayoutTests/permissionclient/image-permissions-expected.txt
@@ -1,8 +1,11 @@
PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif): true
PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif): false
+PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif): false
PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif?nocache): false
PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif): false
PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif): false
+PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif): false
+PERMISSION CLIENT: allowImage((file test):permissionclient/resources/boston.gif): false
Blocked images can be reloaded, so neither onload nor onerror is called. Only check here that onload is never called when image is blocked.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptStreamerTest.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptStreamerTest.cpp
index 8f91bcf..0e2c62d 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptStreamerTest.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptStreamerTest.cpp
@@ -34,7 +34,7 @@ public:
, m_resource(ScriptResource::create(m_resourceRequest, "UTF-8"))
, m_pendingScript(PendingScript::create(0, m_resource.get()))
{
- m_resource->setLoading(true);
+ m_resource->setStatus(Resource::Pending);
m_pendingScript = PendingScript::create(0, m_resource.get());
ScriptStreamer::setSmallScriptThresholdForTesting(0);
}
@@ -68,7 +68,7 @@ protected:
void finish()
{
m_resource->finish();
- m_resource->setLoading(false);
+ m_resource->setStatus(Resource::Cached);
}
void processTasksUntilStreamingComplete()
diff --git a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp
index 10b7d91..7561d04 100644
--- a/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp
+++ b/third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp
@@ -69,7 +69,7 @@ void RemoteFontFaceSource::pruneTable()
bool RemoteFontFaceSource::isLoading() const
{
- return !m_font->stillNeedsLoad() && !m_font->isLoaded();
+ return m_font->isLoading();
}
bool RemoteFontFaceSource::isLoaded() const
diff --git a/third_party/WebKit/Source/core/fetch/CachingCorrectnessTest.cpp b/third_party/WebKit/Source/core/fetch/CachingCorrectnessTest.cpp
index eda9451..c60a235 100644
--- a/third_party/WebKit/Source/core/fetch/CachingCorrectnessTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/CachingCorrectnessTest.cpp
@@ -91,6 +91,12 @@ protected:
return nullptr;
}
resource->setResponse(response);
+ resource->finish();
+ // Because we didn't give any real data, an image will have set its
+ // status to DecodeError. Override it so the resource is cacaheable
+ // for testing purposes.
+ if (type == Resource::Image)
+ resource->setStatus(Resource::Cached);
memoryCache()->add(resource.get());
return resource;
@@ -103,6 +109,7 @@ protected:
RefPtrWillBeRawPtr<Resource> resource =
Resource::create(request, type);
resource->setResponse(ResourceResponse(KURL(ParsedURLString, kResourceURL), "text/html", 0, nullAtom, String()));
+ resource->finish();
memoryCache()->add(resource.get());
return resource;
@@ -392,6 +399,7 @@ TEST_F(CachingCorrectnessTest, FreshWithFreshRedirect)
fresh200Response.setHTTPHeaderField(HTTPNames::Expires, kOneDayAfterOriginalRequest);
firstResource->setResponse(fresh200Response);
+ firstResource->finish();
memoryCache()->add(firstResource.get());
advanceClock(500.);
@@ -426,6 +434,7 @@ TEST_F(CachingCorrectnessTest, FreshWithStaleRedirect)
fresh200Response.setHTTPHeaderField(HTTPNames::Expires, kOneDayAfterOriginalRequest);
firstResource->setResponse(fresh200Response);
+ firstResource->finish();
memoryCache()->add(firstResource.get());
advanceClock(500.);
@@ -439,7 +448,7 @@ TEST_F(CachingCorrectnessTest, PostToSameURLTwice)
ResourceRequest request1(KURL(ParsedURLString, kResourceURL));
request1.setHTTPMethod(HTTPNames::POST);
RefPtrWillBeRawPtr<Resource> resource1 = Resource::create(ResourceRequest(request1.url()), Resource::Raw);
- resource1->setLoading(true);
+ resource1->setStatus(Resource::Pending);
memoryCache()->add(resource1.get());
ResourceRequest request2(KURL(ParsedURLString, kResourceURL));
@@ -478,6 +487,7 @@ TEST_F(CachingCorrectnessTest, 302RedirectNotImplicitlyFresh)
fresh200Response.setHTTPHeaderField(HTTPNames::Expires, kOneDayAfterOriginalRequest);
firstResource->setResponse(fresh200Response);
+ firstResource->finish();
memoryCache()->add(firstResource.get());
advanceClock(500.);
@@ -513,6 +523,7 @@ TEST_F(CachingCorrectnessTest, 302RedirectExplicitlyFreshMaxAge)
fresh200Response.setHTTPHeaderField(HTTPNames::Expires, kOneDayAfterOriginalRequest);
firstResource->setResponse(fresh200Response);
+ firstResource->finish();
memoryCache()->add(firstResource.get());
advanceClock(500.);
@@ -548,6 +559,7 @@ TEST_F(CachingCorrectnessTest, 302RedirectExplicitlyFreshExpires)
fresh200Response.setHTTPHeaderField(HTTPNames::Expires, kOneDayAfterOriginalRequest);
firstResource->setResponse(fresh200Response);
+ firstResource->finish();
memoryCache()->add(firstResource.get());
advanceClock(500.);
diff --git a/third_party/WebKit/Source/core/fetch/FontResource.cpp b/third_party/WebKit/Source/core/fetch/FontResource.cpp
index 7610e63..73b1083 100644
--- a/third_party/WebKit/Source/core/fetch/FontResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/FontResource.cpp
@@ -79,7 +79,7 @@ PassRefPtrWillBeRawPtr<FontResource> FontResource::fetch(FetchRequest& request,
FontResource::FontResource(const ResourceRequest& resourceRequest, const ResourceLoaderOptions& options)
: Resource(resourceRequest, Font, options)
- , m_state(Unloaded)
+ , m_loadLimitState(UnderLimit)
, m_corsFailed(false)
, m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback)
, m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback)
@@ -92,40 +92,38 @@ FontResource::~FontResource()
void FontResource::didScheduleLoad()
{
- if (m_state == Unloaded)
- m_state = LoadScheduled;
+ if (getStatus() == NotStarted)
+ setStatus(LoadStartScheduled);
}
void FontResource::didUnscheduleLoad()
{
- if (m_state == LoadScheduled)
- m_state = Unloaded;
+ if (getStatus() == LoadStartScheduled)
+ setStatus(NotStarted);
}
void FontResource::load(ResourceFetcher*)
{
// Don't load the file yet. Wait for an access before triggering the load.
- setLoading(true);
if (!m_revalidatingRequest.isNull())
- m_state = Unloaded;
+ setStatus(NotStarted);
}
void FontResource::didAddClient(ResourceClient* c)
{
ASSERT(FontResourceClient::isExpectedType(c));
Resource::didAddClient(c);
- if (!isLoading())
+ if (isLoaded())
static_cast<FontResourceClient*>(c)->fontLoaded(this);
- if (m_state == ShortLimitExceeded || m_state == LongLimitExceeded)
+ if (m_loadLimitState == ShortLimitExceeded || m_loadLimitState == LongLimitExceeded)
static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this);
- if (m_state == LongLimitExceeded)
+ if (m_loadLimitState == LongLimitExceeded)
static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this);
}
void FontResource::beginLoadIfNeeded(ResourceFetcher* dl)
{
if (stillNeedsLoad()) {
- m_state = LoadInitiated;
Resource::load(dl);
m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_FROM_HERE);
m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FROM_HERE);
@@ -167,8 +165,8 @@ void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*)
{
if (!isLoading())
return;
- ASSERT(m_state == LoadInitiated);
- m_state = ShortLimitExceeded;
+ ASSERT(m_loadLimitState == UnderLimit);
+ m_loadLimitState = ShortLimitExceeded;
ResourceClientWalker<FontResourceClient> walker(m_clients);
while (FontResourceClient* client = walker.next())
client->fontLoadShortLimitExceeded(this);
@@ -178,8 +176,8 @@ void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*)
{
if (!isLoading())
return;
- ASSERT(m_state == ShortLimitExceeded);
- m_state = LongLimitExceeded;
+ ASSERT(m_loadLimitState == ShortLimitExceeded);
+ m_loadLimitState = LongLimitExceeded;
ResourceClientWalker<FontResourceClient> walker(m_clients);
while (FontResourceClient* client = walker.next())
client->fontLoadLongLimitExceeded(this);
diff --git a/third_party/WebKit/Source/core/fetch/FontResource.h b/third_party/WebKit/Source/core/fetch/FontResource.h
index 9fa27cb..9702c5e 100644
--- a/third_party/WebKit/Source/core/fetch/FontResource.h
+++ b/third_party/WebKit/Source/core/fetch/FontResource.h
@@ -53,9 +53,8 @@ public:
void allClientsRemoved() override;
void beginLoadIfNeeded(ResourceFetcher* dl);
- bool stillNeedsLoad() const override { return m_state < LoadInitiated; }
- bool loadScheduled() const { return m_state != Unloaded; }
+ bool loadScheduled() const { return getStatus() == LoadStartScheduled; }
void didScheduleLoad();
void didUnscheduleLoad();
@@ -86,11 +85,11 @@ private:
void fontLoadShortLimitCallback(Timer<FontResource>*);
void fontLoadLongLimitCallback(Timer<FontResource>*);
- enum State { Unloaded, LoadScheduled, LoadInitiated, ShortLimitExceeded, LongLimitExceeded };
+ enum LoadLimitState { UnderLimit, ShortLimitExceeded, LongLimitExceeded };
OwnPtr<FontCustomPlatformData> m_fontData;
String m_otsParsingMessage;
- State m_state;
+ LoadLimitState m_loadLimitState;
bool m_corsFailed;
Timer<FontResource> m_fontLoadShortLimitTimer;
Timer<FontResource> m_fontLoadLongLimitTimer;
diff --git a/third_party/WebKit/Source/core/fetch/ImageResource.cpp b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
index 499d584..bb21c47 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/ImageResource.cpp
@@ -52,9 +52,6 @@ PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request
return nullptr;
}
- if (fetcher->clientDefersImage(request.resourceRequest().url()))
- request.setDefer(FetchRequest::DeferredByClient);
-
return toImageResource(fetcher->requestResource(request, ImageResourceFactory()));
}
@@ -65,7 +62,6 @@ ImageResource::ImageResource(const ResourceRequest& resourceRequest, const Resou
, m_hasDevicePixelRatioHeaderValue(false)
{
WTF_LOG(Timers, "new ImageResource(ResourceRequest) %p", this);
- setStatus(Unknown);
setCustomAcceptHeader();
}
@@ -77,7 +73,6 @@ ImageResource::ImageResource(blink::Image* image, const ResourceLoaderOptions& o
{
WTF_LOG(Timers, "new ImageResource(Image) %p", this);
setStatus(Cached);
- setLoading(false);
setCustomAcceptHeader();
}
@@ -87,7 +82,6 @@ ImageResource::ImageResource(const ResourceRequest& resourceRequest, blink::Imag
{
WTF_LOG(Timers, "new ImageResource(ResourceRequest, Image) %p", this);
setStatus(Cached);
- setLoading(false);
setCustomAcceptHeader();
}
@@ -105,15 +99,6 @@ DEFINE_TRACE(ImageResource)
MultipartImageResourceParser::Client::trace(visitor);
}
-void ImageResource::load(ResourceFetcher* fetcher)
-{
- ASSERT(fetcher);
- if (fetcher->autoLoadImages())
- Resource::load(fetcher);
- else
- setLoading(false);
-}
-
void ImageResource::didAddClient(ResourceClient* c)
{
if (m_data && !m_image && !errorOccurred()) {
@@ -483,7 +468,8 @@ void ImageResource::onePartInMultipartReceived(const ResourceResponse& response)
if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) {
m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPart;
// Notify finished when the first part ends.
- setLoading(false);
+ if (!errorOccurred())
+ setStatus(Cached);
checkNotify();
if (m_loader)
m_loader->didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength);
diff --git a/third_party/WebKit/Source/core/fetch/ImageResource.h b/third_party/WebKit/Source/core/fetch/ImageResource.h
index d4b92c4..db8c6ab 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResource.h
+++ b/third_party/WebKit/Source/core/fetch/ImageResource.h
@@ -64,8 +64,6 @@ public:
~ImageResource() override;
- void load(ResourceFetcher*) override;
-
blink::Image* getImage(); // Returns the nullImage() if the image is not available yet.
bool hasImage() const { return m_image.get(); }
@@ -107,7 +105,6 @@ public:
bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; }
bool isImage() const override { return true; }
- bool stillNeedsLoad() const override { return !errorOccurred() && getStatus() == Unknown && !isLoading(); }
// ImageObserver
void decodedSizeChanged(const blink::Image*, int delta) override;
diff --git a/third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp b/third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp
index 12030d6..c3ecd53 100644
--- a/third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/ImageResourceTest.cpp
@@ -177,7 +177,7 @@ TEST(ImageResourceTest, CancelOnDetach)
TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
{
RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(), nullptr);
- cachedImage->setLoading(true);
+ cachedImage->setStatus(Resource::Pending);
MockImageResourceClient client(cachedImage);
@@ -210,7 +210,7 @@ TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
TEST(ImageResourceTest, UpdateBitmapImages)
{
RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(), nullptr);
- cachedImage->setLoading(true);
+ cachedImage->setStatus(Resource::Pending);
MockImageResourceClient client(cachedImage);
@@ -232,7 +232,7 @@ TEST(ImageResourceTest, ReloadIfLoFi)
KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html");
RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(ResourceRequest(testURL), nullptr);
- cachedImage->setLoading(true);
+ cachedImage->setStatus(Resource::Pending);
MockImageResourceClient client(cachedImage);
ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
diff --git a/third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp b/third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp
index d02cf52..57dcb78 100644
--- a/third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp
@@ -236,8 +236,10 @@ static void TestLiveResourceEvictionAtEndOfTask(Resource* cachedDeadResource, Re
memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity);
const char data[6] = "abcde";
cachedDeadResource->appendData(data, 3u);
+ cachedDeadResource->finish();
MockImageResourceClient client(cachedLiveResource);
cachedLiveResource->appendData(data, 4u);
+ cachedLiveResource->finish();
Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, bind(&runTask1, PassRefPtrWillBeRawPtr<Resource>(cachedLiveResource), PassRefPtrWillBeRawPtr<Resource>(cachedDeadResource)));
Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, bind(&runTask2, cachedLiveResource->encodedSize() + cachedLiveResource->overheadSize()));
diff --git a/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp b/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
index ef41529..9496674 100644
--- a/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/RawResourceTest.cpp
@@ -176,12 +176,12 @@ TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody)
TEST(RawResourceTest, AddClientDuringCallback)
{
RefPtrWillBeRawPtr<Resource> raw = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
- raw->setLoading(false);
// Create a non-null response.
ResourceResponse response = raw->response();
response.setURL(KURL(ParsedURLString, "http://600.613/"));
raw->setResponse(response);
+ raw->finish();
EXPECT_FALSE(raw->response().isNull());
OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient());
@@ -215,12 +215,12 @@ private:
TEST(RawResourceTest, RemoveClientDuringCallback)
{
RefPtrWillBeRawPtr<Resource> raw = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
- raw->setLoading(false);
// Create a non-null response.
ResourceResponse response = raw->response();
response.setURL(KURL(ParsedURLString, "http://600.613/"));
raw->setResponse(response);
+ raw->finish();
EXPECT_FALSE(raw->response().isNull());
OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient());
diff --git a/third_party/WebKit/Source/core/fetch/Resource.cpp b/third_party/WebKit/Source/core/fetch/Resource.cpp
index 84635b3..05d2e40 100644
--- a/third_party/WebKit/Source/core/fetch/Resource.cpp
+++ b/third_party/WebKit/Source/core/fetch/Resource.cpp
@@ -159,10 +159,8 @@ Resource::Resource(const ResourceRequest& request, Type type, const ResourceLoad
, m_preloadCount(0)
, m_cacheIdentifier(MemoryCache::defaultCacheIdentifier())
, m_preloadResult(PreloadNotReferenced)
- , m_requestedFromNetworkingLayer(false)
- , m_loading(false)
, m_type(type)
- , m_status(Pending)
+ , m_status(NotStarted)
, m_needsSynchronousCacheHit(false)
, m_linkPreload(false)
{
@@ -203,7 +201,6 @@ DEFINE_TRACE(Resource)
void Resource::load(ResourceFetcher* fetcher)
{
RELEASE_ASSERT(!m_loader);
- m_loading = true;
m_status = Pending;
ResourceRequest& request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest);
@@ -291,8 +288,6 @@ void Resource::error(Resource::Status status)
setStatus(status);
ASSERT(errorOccurred());
m_data.clear();
-
- setLoading(false);
checkNotify();
markClientsFinished();
}
@@ -300,11 +295,10 @@ void Resource::error(Resource::Status status)
void Resource::finish()
{
ASSERT(m_revalidatingRequest.isNull());
- setLoading(false);
- checkNotify();
- markClientsFinished();
if (!errorOccurred())
m_status = Cached;
+ checkNotify();
+ markClientsFinished();
}
AtomicString Resource::httpContentType() const
@@ -422,7 +416,6 @@ void Resource::willFollowRedirect(ResourceRequest& newRequest, const ResourceRes
{
newRequest.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredCredentials);
m_redirectChain.append(RedirectPair(newRequest, redirectResponse));
- m_requestedFromNetworkingLayer = true;
}
bool Resource::unlock()
@@ -560,7 +553,7 @@ void Resource::clearLoader()
void Resource::didAddClient(ResourceClient* c)
{
- if (!isLoading() && !stillNeedsLoad()) {
+ if (isLoaded()) {
c->notifyFinished(this);
if (m_clients.contains(c)) {
m_finishedClients.add(c);
@@ -595,7 +588,7 @@ void Resource::addClient(ResourceClient* client)
if (m_preloadResult == PreloadNotReferenced) {
if (isLoaded())
m_preloadResult = PreloadReferencedWhileComplete;
- else if (m_requestedFromNetworkingLayer)
+ else if (isLoading())
m_preloadResult = PreloadReferencedWhileLoading;
else
m_preloadResult = PreloadReferenced;
@@ -673,8 +666,7 @@ void Resource::cancelTimerFired(Timer<Resource>* timer)
return;
RefPtrWillBeRawPtr<Resource> protect(this);
m_loader->cancelIfNotFinishing();
- if (m_status != Cached)
- memoryCache()->remove(this);
+ memoryCache()->remove(this);
}
void Resource::setDecodedSize(size_t decodedSize)
@@ -865,7 +857,7 @@ bool Resource::mustRevalidateDueToCacheHeaders()
bool Resource::canUseCacheValidator()
{
- if (m_loading || errorOccurred())
+ if (isLoading() || errorOccurred())
return false;
if (hasCacheControlNoStoreHeader())
diff --git a/third_party/WebKit/Source/core/fetch/Resource.h b/third_party/WebKit/Source/core/fetch/Resource.h
index e5513fd..68d1c6b 100644
--- a/third_party/WebKit/Source/core/fetch/Resource.h
+++ b/third_party/WebKit/Source/core/fetch/Resource.h
@@ -77,9 +77,10 @@ public:
};
enum Status {
- Unknown, // let cache decide what to do with it
- Pending, // only partially loaded
- Cached, // regular case
+ NotStarted,
+ LoadStartScheduled, // scheduled but not yet started, only used by fonts.
+ Pending, // load in progress
+ Cached, // load completed successfully
LoadError,
DecodeError
};
@@ -154,11 +155,10 @@ public:
size_t decodedSize() const { return m_decodedSize; }
size_t overheadSize() const;
- bool isLoaded() const { return !m_loading; } // FIXME. Method name is inaccurate. Loading might not have started yet.
+ bool isLoaded() const { return m_status > Pending; }
- bool isLoading() const { return m_loading; }
- void setLoading(bool b) { m_loading = b; }
- virtual bool stillNeedsLoad() const { return false; }
+ bool isLoading() const { return m_status == Pending; }
+ bool stillNeedsLoad() const { return m_status < Pending; }
ResourceLoader* loader() const { return m_loader.get(); }
@@ -355,10 +355,6 @@ private:
String m_cacheIdentifier;
unsigned m_preloadResult : 2; // PreloadResult
- unsigned m_requestedFromNetworkingLayer : 1;
-
- unsigned m_loading : 1;
-
unsigned m_type : 4; // Type
unsigned m_status : 3; // Status
diff --git a/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp b/third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp
index a19aca0..a5cc982 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);
}
}
diff --git a/third_party/WebKit/Source/core/fetch/ResourceFetcher.h b/third_party/WebKit/Source/core/fetch/ResourceFetcher.h
index 54d0f8b..681692c 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceFetcher.h
+++ b/third_party/WebKit/Source/core/fetch/ResourceFetcher.h
@@ -80,13 +80,9 @@ public:
using DocumentResourceMap = WillBeHeapHashMap<String, WeakPtrWillBeWeakMember<Resource>>;
const DocumentResourceMap& allResources() const { return m_documentResources; }
- bool autoLoadImages() const { return m_autoLoadImages; }
void setAutoLoadImages(bool);
-
void setImagesEnabled(bool);
- bool shouldDeferImageLoad(const KURL&) const;
-
FetchContext& context() const { return m_context ? *m_context.get() : FetchContext::nullInstance(); }
void clearContext() { m_context.clear(); }
@@ -139,7 +135,6 @@ public:
String getCacheIdentifier() const;
- bool clientDefersImage(const KURL&) const;
static void determineRequestContext(ResourceRequest&, Resource::Type, bool isMainFrame);
void determineRequestContext(ResourceRequest&, Resource::Type);
@@ -171,7 +166,8 @@ private:
void initializeResourceRequest(ResourceRequest&, Resource::Type);
- static bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPolicy);
+ bool resourceNeedsLoad(Resource*, const FetchRequest&, RevalidationPolicy);
+ bool shouldDeferImageLoad(const KURL&) const;
void resourceTimingReportTimerFired(Timer<ResourceFetcher>*);
diff --git a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
index a2b8831..fd16eb7 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp
@@ -439,26 +439,12 @@ static void cachedResourcesForDocument(Document* document, WillBeHeapVector<RawP
if (!cachedResource)
continue;
- switch (cachedResource->getType()) {
- case Resource::Image:
- // Skip images that were not auto loaded (images disabled in the user agent).
- if (toImageResource(cachedResource)->stillNeedsLoad())
- continue;
- break;
- case Resource::Font:
- // Skip fonts that were referenced in CSS but never used/downloaded.
- if (toFontResource(cachedResource)->stillNeedsLoad())
- continue;
- break;
- case Resource::Raw:
- if (skipXHRs)
- continue;
- break;
- default:
- // All other Resource types download immediately.
- break;
- }
-
+ // Skip images that were not auto loaded (images disabled in the user agent),
+ // fonts that were referenced in CSS but never used/downloaded, etc.
+ if (cachedResource->stillNeedsLoad())
+ continue;
+ if (cachedResource->getType() == Resource::Raw && skipXHRs)
+ continue;
result.append(cachedResource);
}
}
diff --git a/third_party/WebKit/Source/core/loader/ImageLoader.cpp b/third_party/WebKit/Source/core/loader/ImageLoader.cpp
index 4cb1edf..ad037d8 100644
--- a/third_party/WebKit/Source/core/loader/ImageLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/ImageLoader.cpp
@@ -326,7 +326,7 @@ void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
newImage = ImageResource::fetch(request, document.fetcher());
if (m_loadingImageDocument && newImage)
- newImage->setLoading(true);
+ newImage->setStatus(Resource::Pending);
if (!newImage && !pageIsBeingDismissed(&document)) {
crossSiteOrCSPViolationOccurred(imageSourceURL);