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

Unified Diff: Source/core/loader/LinkLoader.cpp

Issue 1141883003: Enable `as` based priorities for <link rel=preload> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments Created 5 years, 7 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
« no previous file with comments | « Source/core/loader/FrameFetchContext.cpp ('k') | Source/core/loader/LinkLoaderTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/loader/LinkLoader.cpp
diff --git a/Source/core/loader/LinkLoader.cpp b/Source/core/loader/LinkLoader.cpp
index 2567794051a958b5d0a81bf1959c545d7655a589..42bd198557e0aa4fd47c18d758e193862e8620ed 100644
--- a/Source/core/loader/LinkLoader.cpp
+++ b/Source/core/loader/LinkLoader.cpp
@@ -145,14 +145,20 @@ static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
}
}
-// TODO(yoav): Replace Resource:Type here with some way that conveys priority but not context.
-static bool getTypeFromAsAttribute(const String& as, Resource::Type& type)
+static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& type)
{
if (as.isEmpty())
return false;
- // TODO(yoav): Return false also when the `as` value is not a valid one.
- // TODO(yoav): Add actual types here and make sure priorities work accordingly.
- type = Resource::LinkSubresource;
+
+ if (equalIgnoringCase(as, "image"))
+ type = Resource::Image;
+ else if (equalIgnoringCase(as, "script"))
+ type = Resource::Script;
+ else if (equalIgnoringCase(as, "stylesheet"))
+ type = Resource::CSSStyleSheet;
+ else
+ return false;
+
return true;
}
@@ -164,16 +170,18 @@ void LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value")));
return;
}
- Resource::Type type;
- if (!getTypeFromAsAttribute(as, type)) {
+ // TODO(yoav): Figure out a way that 'as' would be used to set request headers.
+ Resource::Type priorityType;
+ if (!getPriorityTypeFromAsAttribute(as, priorityType)) {
document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, WarningMessageLevel, String("<link rel=preload> must have a valid `as` value")));
return;
}
FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), FetchInitiatorTypeNames::link);
+ linkRequest.setPriority(ResourceFetcher::loadPriority(priorityType, linkRequest));
Settings* settings = document.settings();
if (settings && settings->logPreload())
document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path())));
- setResource(document.fetcher()->fetchLinkPreloadResource(type, linkRequest));
+ setResource(document.fetcher()->fetchLinkPreloadResource(Resource::LinkPreload, linkRequest));
}
}
@@ -200,13 +208,16 @@ bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicString& crossOriginMode, const String& type, const String& as, const KURL& href, Document& document)
{
+ // TODO(yoav): Do all links need to load only after they're in document???
+
// TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAttributeValue. crbug.com/486689
// FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't.
dnsPrefetchIfNeeded(relAttribute, href, document);
preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(crossOriginMode));
- preloadIfNeeded(relAttribute, href, document, as);
+ if (m_client->shouldLoadLink())
+ preloadIfNeeded(relAttribute, href, document, as);
// FIXME(crbug.com/323096): Should take care of import.
if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || relAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame()) {
« no previous file with comments | « Source/core/loader/FrameFetchContext.cpp ('k') | Source/core/loader/LinkLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698