Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 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/html/CrossOriginAttribute.h" | 41 #include "core/html/CrossOriginAttribute.h" |
| 42 #include "core/html/LinkRelAttribute.h" | 42 #include "core/html/LinkRelAttribute.h" |
| 43 #include "core/inspector/ConsoleMessage.h" | 43 #include "core/inspector/ConsoleMessage.h" |
| 44 #include "core/loader/LinkHeader.h" | 44 #include "core/loader/LinkHeader.h" |
| 45 #include "core/loader/NetworkHintsInterface.h" | |
| 45 #include "core/loader/PrerenderHandle.h" | 46 #include "core/loader/PrerenderHandle.h" |
| 46 #include "platform/Prerender.h" | 47 #include "platform/Prerender.h" |
| 47 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
| 48 #include "platform/network/NetworkHints.h" | 49 #include "platform/network/NetworkHints.h" |
| 49 #include "public/platform/WebPrerender.h" | 50 #include "public/platform/WebPrerender.h" |
| 50 | 51 |
| 51 namespace blink { | 52 namespace blink { |
| 52 | 53 |
| 53 static unsigned prerenderRelTypesFromRelAttribute(const LinkRelAttribute& relAtt ribute) | 54 static unsigned prerenderRelTypesFromRelAttribute(const LinkRelAttribute& relAtt ribute) |
| 54 { | 55 { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 void LinkLoader::didSendLoadForPrerender() | 110 void LinkLoader::didSendLoadForPrerender() |
| 110 { | 111 { |
| 111 m_client->didSendLoadForLinkPrerender(); | 112 m_client->didSendLoadForLinkPrerender(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void LinkLoader::didSendDOMContentLoadedForPrerender() | 115 void LinkLoader::didSendDOMContentLoadedForPrerender() |
| 115 { | 116 { |
| 116 m_client->didSendDOMContentLoadedForLinkPrerender(); | 117 m_client->didSendDOMContentLoadedForLinkPrerender(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL & href, Document& document) | 120 static void dnsPrefetchIfNeeded(const LinkRelAttribute& relAttribute, const KURL & href, Document& document, const NetworkHintsInterface& networkHintsInterface) |
| 120 { | 121 { |
| 121 if (relAttribute.isDNSPrefetch()) { | 122 if (relAttribute.isDNSPrefetch()) { |
| 122 Settings* settings = document.settings(); | 123 Settings* settings = document.settings(); |
| 123 // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt | 124 // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt |
| 124 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885 7>. | 125 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885 7>. |
| 125 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && ! href.isEmpty()) { | 126 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && ! href.isEmpty()) { |
| 126 if (settings->logDnsPrefetchAndPreconnect()) | 127 if (settings->logDnsPrefetchAndPreconnect()) |
| 127 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); | 128 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); |
| 128 prefetchDNS(href.host()); | 129 networkHintsInterface.dnsPrefetchHost(href.host()); |
| 129 } | 130 } |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 | 133 |
| 133 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const CrossOriginAttributeValue crossOrigin) | 134 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const CrossOriginAttributeValue crossOrigin, const Ne tworkHintsInterface& networkHintsInterface) |
| 134 { | 135 { |
| 135 if (relAttribute.isPreconnect() && href.isValid() && href.protocolIsInHTTPFa mily()) { | 136 if (relAttribute.isPreconnect() && href.isValid() && (href.protocolIsInHTTPF amily() || href.protocolIs(""))) { |
|
Mike West
2015/07/23 09:52:23
Does the spec say anything about this? I'd expect
| |
| 136 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); | 137 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); |
| 137 Settings* settings = document.settings(); | 138 Settings* settings = document.settings(); |
| 138 if (settings && settings->logDnsPrefetchAndPreconnect()) { | 139 if (settings && settings->logDnsPrefetchAndPreconnect()) { |
| 139 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for " + href.host()))); | 140 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preconnect triggered for ") + href.string())); |
| 140 if (crossOrigin != CrossOriginAttributeNotSet) { | 141 if (crossOrigin != CrossOriginAttributeNotSet) { |
| 141 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, | 142 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo urce, DebugMessageLevel, |
| 142 String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); | 143 String("Preconnect CORS setting is ") + String((crossOrigin == CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 preconnect(href, crossOrigin); | 146 KURL url = href; |
| 147 url.setPath(""); | |
| 148 networkHintsInterface.preconnectHost(url, crossOrigin); | |
| 146 } | 149 } |
| 147 } | 150 } |
| 148 | 151 |
| 149 static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& typ e) | 152 static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& typ e) |
| 150 { | 153 { |
| 151 if (as.isEmpty()) | 154 if (as.isEmpty()) |
| 152 return false; | 155 return false; |
| 153 | 156 |
| 154 if (equalIgnoringCase(as, "image")) | 157 if (equalIgnoringCase(as, "image")) |
| 155 type = Resource::Image; | 158 type = Resource::Image; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 179 } | 182 } |
| 180 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link); | 183 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link); |
| 181 linkRequest.setPriority(document.fetcher()->loadPriority(priorityType, l inkRequest)); | 184 linkRequest.setPriority(document.fetcher()->loadPriority(priorityType, l inkRequest)); |
| 182 Settings* settings = document.settings(); | 185 Settings* settings = document.settings(); |
| 183 if (settings && settings->logPreload()) | 186 if (settings && settings->logPreload()) |
| 184 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preload triggered for " + href.host() + href.path() ))); | 187 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preload triggered for " + href.host() + href.path() ))); |
| 185 setResource(LinkFetchResource::fetch(Resource::LinkPreload, linkRequest, document.fetcher())); | 188 setResource(LinkFetchResource::fetch(Resource::LinkPreload, linkRequest, document.fetcher())); |
| 186 } | 189 } |
| 187 } | 190 } |
| 188 | 191 |
| 189 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen t) | 192 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen t, const NetworkHintsInterface& networkHintsInterface) |
| 190 { | 193 { |
| 191 if (!document) | 194 if (!document) |
| 192 return false; | 195 return false; |
| 193 LinkHeaderSet headerSet(headerValue); | 196 LinkHeaderSet headerSet(headerValue); |
| 194 for (auto& header : headerSet) { | 197 for (auto& header : headerSet) { |
| 195 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) | 198 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) |
| 196 return false; | 199 return false; |
| 197 LinkRelAttribute relAttribute(header.rel()); | 200 LinkRelAttribute relAttribute(header.rel()); |
| 198 KURL url = document->completeURL(header.url()); | 201 KURL url = document->completeURL(header.url()); |
| 199 if (RuntimeEnabledFeatures::linkHeaderEnabled()) | 202 if (RuntimeEnabledFeatures::linkHeaderEnabled()) |
| 200 dnsPrefetchIfNeeded(relAttribute, url, *document); | 203 dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsInterf ace); |
| 201 | 204 |
| 202 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) | 205 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) |
| 203 preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin( )); | 206 preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin( ), networkHintsInterface); |
| 204 | 207 |
| 205 // FIXME: Add more supported headers as needed. | 208 // FIXME: Add more supported headers as needed. |
| 206 } | 209 } |
| 207 return true; | 210 return true; |
| 208 } | 211 } |
| 209 | 212 |
| 210 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc ument& document) | 213 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) |
| 211 { | 214 { |
| 212 // TODO(yoav): Do all links need to load only after they're in document??? | 215 // TODO(yoav): Do all links need to load only after they're in document??? |
| 213 | 216 |
| 214 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt tributeValue. crbug.com/486689 | 217 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt tributeValue. crbug.com/486689 |
| 215 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. | 218 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. |
| 216 dnsPrefetchIfNeeded(relAttribute, href, document); | 219 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface); |
| 217 | 220 |
| 218 preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(c rossOriginMode)); | 221 preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(c rossOriginMode), networkHintsInterface); |
| 219 | 222 |
| 220 if (m_client->shouldLoadLink()) | 223 if (m_client->shouldLoadLink()) |
| 221 preloadIfNeeded(relAttribute, href, document, as); | 224 preloadIfNeeded(relAttribute, href, document, as); |
| 222 | 225 |
| 223 // FIXME(crbug.com/323096): Should take care of import. | 226 // FIXME(crbug.com/323096): Should take care of import. |
| 224 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h ref.isValid() && document.frame()) { | 227 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h ref.isValid() && document.frame()) { |
| 225 if (!m_client->shouldLoadLink()) | 228 if (!m_client->shouldLoadLink()) |
| 226 return false; | 229 return false; |
| 227 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link Subresource : Resource::LinkPrefetch; | 230 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link Subresource : Resource::LinkPrefetch; |
| 228 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link); | 231 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe tchInitiatorTypeNames::link); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 255 m_prerender.clear(); | 258 m_prerender.clear(); |
| 256 } | 259 } |
| 257 } | 260 } |
| 258 | 261 |
| 259 DEFINE_TRACE(LinkLoader) | 262 DEFINE_TRACE(LinkLoader) |
| 260 { | 263 { |
| 261 visitor->trace(m_prerender); | 264 visitor->trace(m_prerender); |
| 262 } | 265 } |
| 263 | 266 |
| 264 } | 267 } |
| OLD | NEW |