| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "core/fetch/FetchInitiatorTypeNames.h" | 36 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 37 #include "core/fetch/FetchRequest.h" | 37 #include "core/fetch/FetchRequest.h" |
| 38 #include "core/fetch/LinkFetchResource.h" | 38 #include "core/fetch/LinkFetchResource.h" |
| 39 #include "core/fetch/ResourceFetcher.h" | 39 #include "core/fetch/ResourceFetcher.h" |
| 40 #include "core/frame/Settings.h" | 40 #include "core/frame/Settings.h" |
| 41 #include "core/frame/UseCounter.h" | 41 #include "core/frame/UseCounter.h" |
| 42 #include "core/html/CrossOriginAttribute.h" | 42 #include "core/html/CrossOriginAttribute.h" |
| 43 #include "core/html/LinkRelAttribute.h" | 43 #include "core/html/LinkRelAttribute.h" |
| 44 #include "core/inspector/ConsoleMessage.h" | 44 #include "core/inspector/ConsoleMessage.h" |
| 45 #include "core/loader/LinkHeader.h" | 45 #include "core/loader/LinkHeader.h" |
| 46 #include "core/loader/NetworkHintsInterface.h" |
| 46 #include "core/loader/PrerenderHandle.h" | 47 #include "core/loader/PrerenderHandle.h" |
| 47 #include "platform/Prerender.h" | 48 #include "platform/Prerender.h" |
| 48 #include "platform/RuntimeEnabledFeatures.h" | 49 #include "platform/RuntimeEnabledFeatures.h" |
| 49 #include "platform/network/NetworkHints.h" | 50 #include "platform/network/NetworkHints.h" |
| 50 #include "public/platform/WebPrerender.h" | 51 #include "public/platform/WebPrerender.h" |
| 51 | 52 |
| 52 namespace blink { | 53 namespace blink { |
| 53 | 54 |
| 54 static unsigned prerenderRelTypesFromRelAttribute(const LinkRelAttribute& relAtt
ribute) | 55 static unsigned prerenderRelTypesFromRelAttribute(const LinkRelAttribute& relAtt
ribute) |
| 55 { | 56 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 { | 117 { |
| 117 m_client->didSendDOMContentLoadedForLinkPrerender(); | 118 m_client->didSendDOMContentLoadedForLinkPrerender(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 enum LinkCaller { | 121 enum LinkCaller { |
| 121 LinkCalledFromHeader, | 122 LinkCalledFromHeader, |
| 122 LinkCalledFromMarkup, | 123 LinkCalledFromMarkup, |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 | 126 |
| 126 static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL
& href, Document& document, LinkCaller caller) | 127 static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL
& href, Document& document, const NetworkHintsInterface& networkHintsInterface,
LinkCaller caller) |
| 127 { | 128 { |
| 128 if (relAttribute.isDNSPrefetch()) { | 129 if (relAttribute.isDNSPrefetch()) { |
| 129 UseCounter::count(document, UseCounter::LinkRelDnsPrefetch); | 130 UseCounter::count(document, UseCounter::LinkRelDnsPrefetch); |
| 130 if (caller == LinkCalledFromHeader) | 131 if (caller == LinkCalledFromHeader) |
| 131 UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch); | 132 UseCounter::count(document, UseCounter::LinkHeaderDnsPrefetch); |
| 132 Settings* settings = document.settings(); | 133 Settings* settings = document.settings(); |
| 133 // FIXME: The href attribute of the link element can be in "//hostname"
form, and we shouldn't attempt | 134 // FIXME: The href attribute of the link element can be in "//hostname"
form, and we shouldn't attempt |
| 134 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885
7>. | 135 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885
7>. |
| 135 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !
href.isEmpty()) { | 136 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !
href.isEmpty()) { |
| 136 if (settings->logDnsPrefetchAndPreconnect()) | 137 if (settings->logDnsPrefetchAndPreconnect()) |
| 137 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); | 138 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); |
| 138 prefetchDNS(href.host()); | 139 networkHintsInterface.dnsPrefetchHost(href.host()); |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 } | 142 } |
| 142 | 143 |
| 143 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
href, Document& document, const CrossOriginAttributeValue crossOrigin, LinkCall
er caller) | 144 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
href, Document& document, const CrossOriginAttributeValue crossOrigin, const Ne
tworkHintsInterface& networkHintsInterface, LinkCaller caller) |
| 144 { | 145 { |
| 145 if (relAttribute.isPreconnect() && href.isValid() && href.protocolIsInHTTPFa
mily()) { | 146 if (relAttribute.isPreconnect() && href.isValid() && href.protocolIsInHTTPFa
mily()) { |
| 146 UseCounter::count(document, UseCounter::LinkRelPreconnect); | 147 UseCounter::count(document, UseCounter::LinkRelPreconnect); |
| 147 if (caller == LinkCalledFromHeader) | 148 if (caller == LinkCalledFromHeader) |
| 148 UseCounter::count(document, UseCounter::LinkHeaderPreconnect); | 149 UseCounter::count(document, UseCounter::LinkHeaderPreconnect); |
| 149 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); | 150 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); |
| 150 Settings* settings = document.settings(); | 151 Settings* settings = document.settings(); |
| 151 if (settings && settings->logDnsPrefetchAndPreconnect()) { | 152 if (settings && settings->logDnsPrefetchAndPreconnect()) { |
| 152 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for " + href.host()))); | 153 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for ") + href.string())); |
| 153 if (crossOrigin != CrossOriginAttributeNotSet) { | 154 if (crossOrigin != CrossOriginAttributeNotSet) { |
| 154 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, | 155 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, |
| 155 String("Preconnect CORS setting is ") + String((crossOrigin
== CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); | 156 String("Preconnect CORS setting is ") + String((crossOrigin
== CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 preconnect(href, crossOrigin); | 159 networkHintsInterface.preconnectHost(href, crossOrigin); |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& typ
e) | 163 static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& typ
e) |
| 163 { | 164 { |
| 164 if (as.isEmpty()) | 165 if (as.isEmpty()) |
| 165 return false; | 166 return false; |
| 166 | 167 |
| 167 if (equalIgnoringCase(as, "image")) | 168 if (equalIgnoringCase(as, "image")) |
| 168 type = Resource::Image; | 169 type = Resource::Image; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 193 } | 194 } |
| 194 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 195 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
| 195 linkRequest.setPriority(document.fetcher()->loadPriority(priorityType, l
inkRequest)); | 196 linkRequest.setPriority(document.fetcher()->loadPriority(priorityType, l
inkRequest)); |
| 196 Settings* settings = document.settings(); | 197 Settings* settings = document.settings(); |
| 197 if (settings && settings->logPreload()) | 198 if (settings && settings->logPreload()) |
| 198 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); | 199 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); |
| 199 setResource(LinkFetchResource::fetch(Resource::LinkPreload, linkRequest,
document.fetcher())); | 200 setResource(LinkFetchResource::fetch(Resource::LinkPreload, linkRequest,
document.fetcher())); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t) | 204 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t, const NetworkHintsInterface& networkHintsInterface) |
| 204 { | 205 { |
| 205 if (!document) | 206 if (!document) |
| 206 return false; | 207 return false; |
| 207 LinkHeaderSet headerSet(headerValue); | 208 LinkHeaderSet headerSet(headerValue); |
| 208 for (auto& header : headerSet) { | 209 for (auto& header : headerSet) { |
| 209 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) | 210 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) |
| 210 return false; | 211 return false; |
| 211 LinkRelAttribute relAttribute(header.rel()); | 212 LinkRelAttribute relAttribute(header.rel()); |
| 212 KURL url = document->completeURL(header.url()); | 213 KURL url = document->completeURL(header.url()); |
| 213 if (RuntimeEnabledFeatures::linkHeaderEnabled()) | 214 if (RuntimeEnabledFeatures::linkHeaderEnabled()) |
| 214 dnsPrefetchIfNeeded(relAttribute, url, *document, LinkCalledFromHead
er); | 215 dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsInterf
ace, LinkCalledFromHeader); |
| 215 | 216 |
| 216 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) | 217 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) |
| 217 preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin(
), LinkCalledFromHeader); | 218 preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin(
), networkHintsInterface, LinkCalledFromHeader); |
| 218 | 219 |
| 219 // FIXME: Add more supported headers as needed. | 220 // FIXME: Add more supported headers as needed. |
| 220 } | 221 } |
| 221 return true; | 222 return true; |
| 222 } | 223 } |
| 223 | 224 |
| 224 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri
ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc
ument& document) | 225 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri
ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc
ument& document, const NetworkHintsInterface& networkHintsInterface) |
| 225 { | 226 { |
| 226 // TODO(yoav): Do all links need to load only after they're in document??? | 227 // TODO(yoav): Do all links need to load only after they're in document??? |
| 227 | 228 |
| 228 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt
tributeValue. crbug.com/486689 | 229 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt
tributeValue. crbug.com/486689 |
| 229 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. | 230 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. |
| 230 dnsPrefetchIfNeeded(relAttribute, href, document, LinkCalledFromMarkup); | 231 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, Lin
kCalledFromMarkup); |
| 231 | 232 |
| 232 preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(c
rossOriginMode), LinkCalledFromMarkup); | 233 preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(c
rossOriginMode), networkHintsInterface, LinkCalledFromMarkup); |
| 233 | 234 |
| 234 if (m_client->shouldLoadLink()) | 235 if (m_client->shouldLoadLink()) |
| 235 preloadIfNeeded(relAttribute, href, document, as); | 236 preloadIfNeeded(relAttribute, href, document, as); |
| 236 | 237 |
| 237 // FIXME(crbug.com/323096): Should take care of import. | 238 // FIXME(crbug.com/323096): Should take care of import. |
| 238 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h
ref.isValid() && document.frame()) { | 239 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h
ref.isValid() && document.frame()) { |
| 239 if (!m_client->shouldLoadLink()) | 240 if (!m_client->shouldLoadLink()) |
| 240 return false; | 241 return false; |
| 241 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; | 242 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; |
| 242 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 243 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 269 m_prerender.clear(); | 270 m_prerender.clear(); |
| 270 } | 271 } |
| 271 } | 272 } |
| 272 | 273 |
| 273 DEFINE_TRACE(LinkLoader) | 274 DEFINE_TRACE(LinkLoader) |
| 274 { | 275 { |
| 275 visitor->trace(m_prerender); | 276 visitor->trace(m_prerender); |
| 276 } | 277 } |
| 277 | 278 |
| 278 } | 279 } |
| OLD | NEW |