Index: third_party/WebKit/Source/core/loader/LinkLoader.cpp |
diff --git a/third_party/WebKit/Source/core/loader/LinkLoader.cpp b/third_party/WebKit/Source/core/loader/LinkLoader.cpp |
index 7db397a9e10fbb0e983f1319cb5d23ea401af82e..f221f633fa6930e665b2abf5cbc10b986448fcd2 100644 |
--- a/third_party/WebKit/Source/core/loader/LinkLoader.cpp |
+++ b/third_party/WebKit/Source/core/loader/LinkLoader.cpp |
@@ -71,6 +71,7 @@ LinkLoader::LinkLoader(LinkLoaderClient* client) |
: m_client(client) |
, m_linkLoadTimer(this, &LinkLoader::linkLoadTimerFired) |
, m_linkLoadingErrorTimer(this, &LinkLoader::linkLoadingErrorTimerFired) |
+ , m_weakPtrFactory(this) |
{ |
} |
@@ -90,15 +91,19 @@ void LinkLoader::linkLoadingErrorTimerFired(Timer<LinkLoader>* timer) |
m_client->linkLoadingErrored(); |
} |
-void LinkLoader::notifyFinished(Resource* resource) |
+void LinkLoader::triggerEvents(Resource* resource) |
{ |
- ASSERT(this->resource() == resource); |
- |
if (resource->errorOccurred()) |
m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); |
else |
m_linkLoadTimer.startOneShot(0, BLINK_FROM_HERE); |
+} |
+ |
+void LinkLoader::notifyFinished(Resource* resource) |
+{ |
+ ASSERT(this->resource() == resource); |
+ triggerEvents(resource); |
clearResource(); |
} |
@@ -184,31 +189,29 @@ Resource::Type LinkLoader::getTypeFromAsAttribute(const String& as, Document* do |
return Resource::LinkSubresource; |
} |
-static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const String& as) |
+static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const String& as, LinkLoader* linkLoader) |
Nate Chapin
2016/01/13 23:52:23
Should this be a private member of LinkLoader if w
Yoav Weiss
2016/01/14 10:10:02
This has to remain static since it's called from l
|
{ |
- if (!document.loader()) |
+ if (!document.loader() || !relAttribute.isLinkPreload()) |
return; |
- if (relAttribute.isLinkPreload()) { |
- UseCounter::count(document, UseCounter::LinkRelPreload); |
- ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); |
- if (!href.isValid() || href.isEmpty()) { |
- document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value"))); |
- return; |
- } |
- Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document); |
- ResourceRequest resourceRequest(document.completeURL(href)); |
- ResourceFetcher::determineRequestContext(resourceRequest, type, false); |
- FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link); |
- |
- linkRequest.setPriority(document.fetcher()->loadPriority(type, linkRequest)); |
- Settings* settings = document.settings(); |
- if (settings && settings->logPreload()) |
- document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); |
- linkRequest.setForPreload(true); |
- linkRequest.setAvoidBlockingOnLoad(true); |
- document.loader()->startPreload(type, linkRequest); |
+ UseCounter::count(document, UseCounter::LinkRelPreload); |
+ ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); |
+ if (!href.isValid() || href.isEmpty()) { |
+ document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value"))); |
+ return; |
} |
+ Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document); |
+ ResourceRequest resourceRequest(document.completeURL(href)); |
+ ResourceFetcher::determineRequestContext(resourceRequest, type, false); |
+ FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link); |
+ |
+ linkRequest.setPriority(document.fetcher()->loadPriority(type, linkRequest)); |
+ Settings* settings = document.settings(); |
+ if (settings && settings->logPreload()) |
+ document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); |
+ linkRequest.setForPreload(true); |
+ linkRequest.setAvoidBlockingOnLoad(true); |
+ document.loader()->startPreload(type, linkRequest, linkLoader); |
} |
bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* document, const NetworkHintsInterface& networkHintsInterface, CanLoadResources canLoadResources) |
@@ -230,7 +233,7 @@ bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen |
preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin(), networkHintsInterface, LinkCalledFromHeader); |
} else { |
if (RuntimeEnabledFeatures::linkPreloadEnabled()) |
- preloadIfNeeded(relAttribute, url, *document, header.as()); |
+ preloadIfNeeded(relAttribute, url, *document, header.as(), nullptr); |
Nate Chapin
2016/01/13 23:52:23
Passing nullptr in this case is not immediately ob
Yoav Weiss
2016/01/14 10:10:02
If preloadIfNeeded would not be static, we wouldn'
|
} |
// TODO(yoav): Add more supported headers as needed. |
} |
@@ -248,7 +251,7 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttri |
preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsInterface, LinkCalledFromMarkup); |
if (m_client->shouldLoadLink()) |
- preloadIfNeeded(relAttribute, href, document, as); |
+ preloadIfNeeded(relAttribute, href, document, as, this); |
// FIXME(crbug.com/323096): Should take care of import. |
if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && href.isValid() && document.frame()) { |
@@ -296,6 +299,7 @@ void LinkLoader::released() |
DEFINE_TRACE(LinkLoader) |
{ |
visitor->trace(m_prerender); |
+ visitor->trace(m_linkPreloadResourceClient); |
} |
} |