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

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

Issue 1416673008: Converge <link rel=preload> loading logic with preloadScanner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 1 month 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/loader/LinkLoader.cpp
diff --git a/third_party/WebKit/Source/core/loader/LinkLoader.cpp b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
index db207fa3e6a55fc0c825e205e71317483a89d634..a2a2329c9fdfd504ebbb89887c55916491fe0e7a 100644
--- a/third_party/WebKit/Source/core/loader/LinkLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
@@ -42,6 +42,7 @@
#include "core/html/CrossOriginAttribute.h"
#include "core/html/LinkRelAttribute.h"
#include "core/inspector/ConsoleMessage.h"
+#include "core/loader/DocumentLoader.h"
#include "core/loader/LinkHeader.h"
#include "core/loader/NetworkHintsInterface.h"
#include "core/loader/PrerenderHandle.h"
@@ -164,7 +165,7 @@ static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
}
}
-static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& type)
+static bool getTypeFromAsAttribute(const String& as, Resource::Type& type)
{
if (as.isEmpty())
return false;
@@ -181,8 +182,11 @@ static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& typ
return true;
}
-void LinkLoader::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)
{
+ if (!document.loader())
+ return;
+
if (relAttribute.isLinkPreload()) {
UseCounter::count(document, UseCounter::LinkRelPreload);
ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled());
@@ -191,17 +195,17 @@ void LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
return;
}
// TODO(yoav): Figure out a way that 'as' would be used to set request headers.
- Resource::Type priorityType;
- if (!getPriorityTypeFromAsAttribute(as, priorityType)) {
+ Resource::Type type;
+ if (!getTypeFromAsAttribute(as, type)) {
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(document.fetcher()->loadPriority(priorityType, linkRequest));
+ 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())));
- setResource(LinkFetchResource::fetch(Resource::LinkPreload, linkRequest, document.fetcher()));
+ document.loader()->startPreload(type, linkRequest);
}
}
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | third_party/WebKit/Source/core/loader/LinkLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698