Chromium Code Reviews| Index: Source/core/loader/LinkLoader.cpp |
| diff --git a/Source/core/loader/LinkLoader.cpp b/Source/core/loader/LinkLoader.cpp |
| index d14fe8b068978aad6d975157d8c1c2d37e0385eb..83abd192106cbe976a708edef95bc3daca4ac540 100644 |
| --- a/Source/core/loader/LinkLoader.cpp |
| +++ b/Source/core/loader/LinkLoader.cpp |
| @@ -42,6 +42,7 @@ |
| #include "core/html/LinkRelAttribute.h" |
| #include "core/inspector/ConsoleMessage.h" |
| #include "core/loader/LinkHeader.h" |
| +#include "core/loader/NetworkHintsInterface.h" |
| #include "core/loader/PrerenderHandle.h" |
| #include "platform/Prerender.h" |
| #include "platform/RuntimeEnabledFeatures.h" |
| @@ -116,7 +117,7 @@ void LinkLoader::didSendDOMContentLoadedForPrerender() |
| m_client->didSendDOMContentLoadedForLinkPrerender(); |
| } |
| -static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document) |
| +static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const NetworkHintsInterface& networkHintsInterface) |
| { |
| if (relAttribute.isDNSPrefetch()) { |
| Settings* settings = document.settings(); |
| @@ -125,24 +126,26 @@ static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL |
| if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty()) { |
| if (settings->logDnsPrefetchAndPreconnect()) |
| document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); |
| - prefetchDNS(href.host()); |
| + networkHintsInterface.dnsPrefetchHost(href.host()); |
| } |
| } |
| } |
| -static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const CrossOriginAttributeValue crossOrigin) |
| +static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const CrossOriginAttributeValue crossOrigin, const NetworkHintsInterface& networkHintsInterface) |
| { |
| - if (relAttribute.isPreconnect() && href.isValid() && href.protocolIsInHTTPFamily()) { |
| + if (relAttribute.isPreconnect() && href.isValid() && (href.protocolIsInHTTPFamily() || href.protocolIs(""))) { |
|
Mike West
2015/07/23 09:52:23
Does the spec say anything about this? I'd expect
|
| ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); |
| Settings* settings = document.settings(); |
| if (settings && settings->logDnsPrefetchAndPreconnect()) { |
| - document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("Preconnect triggered for " + href.host()))); |
| + document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, String("Preconnect triggered for ") + href.string())); |
| if (crossOrigin != CrossOriginAttributeNotSet) { |
| document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, DebugMessageLevel, |
| String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); |
| } |
| } |
| - preconnect(href, crossOrigin); |
| + KURL url = href; |
| + url.setPath(""); |
| + networkHintsInterface.preconnectHost(url, crossOrigin); |
| } |
| } |
| @@ -186,7 +189,7 @@ void LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR |
| } |
| } |
| -bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* document) |
| +bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* document, const NetworkHintsInterface& networkHintsInterface) |
| { |
| if (!document) |
| return false; |
| @@ -197,25 +200,25 @@ bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen |
| LinkRelAttribute relAttribute(header.rel()); |
| KURL url = document->completeURL(header.url()); |
| if (RuntimeEnabledFeatures::linkHeaderEnabled()) |
| - dnsPrefetchIfNeeded(relAttribute, url, *document); |
| + dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsInterface); |
| if (RuntimeEnabledFeatures::linkPreconnectEnabled()) |
| - preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin()); |
| + preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin(), networkHintsInterface); |
| // FIXME: Add more supported headers as needed. |
| } |
| return true; |
| } |
| -bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicString& crossOriginMode, const String& type, const String& as, const KURL& href, Document& document) |
| +bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicString& crossOriginMode, const String& type, const String& as, const KURL& href, Document& document, const NetworkHintsInterface& networkHintsInterface) |
| { |
| // 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); |
| + dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface); |
| - preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(crossOriginMode)); |
| + preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(crossOriginMode), networkHintsInterface); |
| if (m_client->shouldLoadLink()) |
| preloadIfNeeded(relAttribute, href, document, as); |