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 19 matching lines...) Expand all Loading... |
30 */ | 30 */ |
31 | 31 |
32 #include "config.h" | 32 #include "config.h" |
33 #include "core/loader/LinkLoader.h" | 33 #include "core/loader/LinkLoader.h" |
34 | 34 |
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/ResourceFetcher.h" | 38 #include "core/fetch/ResourceFetcher.h" |
39 #include "core/frame/Settings.h" | 39 #include "core/frame/Settings.h" |
| 40 #include "core/html/CrossOriginAttribute.h" |
40 #include "core/html/LinkRelAttribute.h" | 41 #include "core/html/LinkRelAttribute.h" |
41 #include "core/inspector/ConsoleMessage.h" | 42 #include "core/inspector/ConsoleMessage.h" |
42 #include "core/loader/LinkHeader.h" | 43 #include "core/loader/LinkHeader.h" |
43 #include "core/loader/PrerenderHandle.h" | 44 #include "core/loader/PrerenderHandle.h" |
44 #include "platform/Prerender.h" | 45 #include "platform/Prerender.h" |
45 #include "platform/RuntimeEnabledFeatures.h" | 46 #include "platform/RuntimeEnabledFeatures.h" |
46 #include "platform/network/NetworkHints.h" | 47 #include "platform/network/NetworkHints.h" |
47 #include "public/platform/WebPrerender.h" | 48 #include "public/platform/WebPrerender.h" |
48 | 49 |
49 namespace blink { | 50 namespace blink { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // FIXME: The href attribute of the link element can be in "//hostname"
form, and we shouldn't attempt | 122 // FIXME: The href attribute of the link element can be in "//hostname"
form, and we shouldn't attempt |
122 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885
7>. | 123 // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=4885
7>. |
123 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !
href.isEmpty()) { | 124 if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !
href.isEmpty()) { |
124 if (settings->logDnsPrefetchAndPreconnect()) | 125 if (settings->logDnsPrefetchAndPreconnect()) |
125 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); | 126 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, String("DNS prefetch triggered for " + href.host()))); |
126 prefetchDNS(href.host()); | 127 prefetchDNS(href.host()); |
127 } | 128 } |
128 } | 129 } |
129 } | 130 } |
130 | 131 |
131 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
href, Document& document) | 132 static void preconnectIfNeeded(const LinkRelAttribute& relAttribute, const KURL&
href, Document& document, const CrossOriginAttributeValue crossOrigin) |
132 { | 133 { |
133 if (relAttribute.isPreconnect() && href.isValid()) { | 134 if (relAttribute.isPreconnect() && href.isValid()) { |
134 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); | 135 ASSERT(RuntimeEnabledFeatures::linkPreconnectEnabled()); |
135 Settings* settings = document.settings(); | 136 Settings* settings = document.settings(); |
136 if (settings && settings->logDnsPrefetchAndPreconnect()) | 137 if (settings && settings->logDnsPrefetchAndPreconnect()) { |
137 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for " + href.host()))); | 138 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for " + href.host()))); |
138 preconnect(href); | 139 if (crossOrigin != CrossOriginAttributeNotSet) { |
| 140 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, |
| 141 String("Preconnect CORS setting is ") + String((crossOrigin
== CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); |
| 142 } |
| 143 } |
| 144 preconnect(href, crossOrigin); |
139 } | 145 } |
140 } | 146 } |
141 | 147 |
142 // TODO(yoav): Replace Resource:Type here with some way that conveys priority bu
t not context. | 148 // TODO(yoav): Replace Resource:Type here with some way that conveys priority bu
t not context. |
143 static bool getTypeFromAsAttribute(const String& as, Resource::Type& type) | 149 static bool getTypeFromAsAttribute(const String& as, Resource::Type& type) |
144 { | 150 { |
145 if (as.isEmpty()) | 151 if (as.isEmpty()) |
146 return false; | 152 return false; |
147 // TODO(yoav): Return false also when the `as` value is not a valid one. | 153 // TODO(yoav): Return false also when the `as` value is not a valid one. |
148 // TODO(yoav): Add actual types here and make sure priorities work according
ly. | 154 // TODO(yoav): Add actual types here and make sure priorities work according
ly. |
(...skipping 29 matching lines...) Expand all Loading... |
178 LinkHeaderSet headerSet(headerValue); | 184 LinkHeaderSet headerSet(headerValue); |
179 for (auto& header : headerSet) { | 185 for (auto& header : headerSet) { |
180 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) | 186 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) |
181 return false; | 187 return false; |
182 LinkRelAttribute relAttribute(header.rel()); | 188 LinkRelAttribute relAttribute(header.rel()); |
183 KURL url = document->completeURL(header.url()); | 189 KURL url = document->completeURL(header.url()); |
184 if (RuntimeEnabledFeatures::linkHeaderEnabled()) | 190 if (RuntimeEnabledFeatures::linkHeaderEnabled()) |
185 dnsPrefetchIfNeeded(relAttribute, url, *document); | 191 dnsPrefetchIfNeeded(relAttribute, url, *document); |
186 | 192 |
187 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) | 193 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) |
188 preconnectIfNeeded(relAttribute, url, *document); | 194 preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin(
)); |
189 | 195 |
190 // FIXME: Add more supported headers as needed. | 196 // FIXME: Add more supported headers as needed. |
191 } | 197 } |
192 return true; | 198 return true; |
193 } | 199 } |
194 | 200 |
195 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri
ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc
ument& document) | 201 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicStri
ng& crossOriginMode, const String& type, const String& as, const KURL& href, Doc
ument& document) |
196 { | 202 { |
| 203 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt
tributeValue. crbug.com/486689 |
197 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. | 204 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. |
198 dnsPrefetchIfNeeded(relAttribute, href, document); | 205 dnsPrefetchIfNeeded(relAttribute, href, document); |
199 | 206 |
200 preconnectIfNeeded(relAttribute, href, document); | 207 preconnectIfNeeded(relAttribute, href, document, crossOriginAttributeValue(c
rossOriginMode)); |
201 | 208 |
202 preloadIfNeeded(relAttribute, href, document, as); | 209 preloadIfNeeded(relAttribute, href, document, as); |
203 | 210 |
204 // FIXME(crbug.com/323096): Should take care of import. | 211 // FIXME(crbug.com/323096): Should take care of import. |
205 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re
lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame(
)) { | 212 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource() || re
lAttribute.isTransitionExitingStylesheet()) && href.isValid() && document.frame(
)) { |
206 if (!m_client->shouldLoadLink()) | 213 if (!m_client->shouldLoadLink()) |
207 return false; | 214 return false; |
208 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; | 215 Resource::Type type = relAttribute.isLinkSubresource() ? Resource::Link
Subresource : Resource::LinkPrefetch; |
209 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 216 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
210 if (!crossOriginMode.isNull()) | 217 if (!crossOriginMode.isNull()) |
(...skipping 25 matching lines...) Expand all Loading... |
236 m_prerender.clear(); | 243 m_prerender.clear(); |
237 } | 244 } |
238 } | 245 } |
239 | 246 |
240 DEFINE_TRACE(LinkLoader) | 247 DEFINE_TRACE(LinkLoader) |
241 { | 248 { |
242 visitor->trace(m_prerender); | 249 visitor->trace(m_prerender); |
243 } | 250 } |
244 | 251 |
245 } | 252 } |
OLD | NEW |