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/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/DocumentLoader.h" |
45 #include "core/loader/LinkHeader.h" | 46 #include "core/loader/LinkHeader.h" |
46 #include "core/loader/NetworkHintsInterface.h" | 47 #include "core/loader/NetworkHintsInterface.h" |
47 #include "core/loader/PrerenderHandle.h" | 48 #include "core/loader/PrerenderHandle.h" |
48 #include "platform/Prerender.h" | 49 #include "platform/Prerender.h" |
49 #include "platform/RuntimeEnabledFeatures.h" | 50 #include "platform/RuntimeEnabledFeatures.h" |
50 #include "platform/network/NetworkHints.h" | 51 #include "platform/network/NetworkHints.h" |
51 #include "public/platform/WebPrerender.h" | 52 #include "public/platform/WebPrerender.h" |
52 | 53 |
53 namespace blink { | 54 namespace blink { |
54 | 55 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for ") + href.string())); | 158 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preconnect triggered for ") + href.string())); |
158 if (crossOrigin != CrossOriginAttributeNotSet) { | 159 if (crossOrigin != CrossOriginAttributeNotSet) { |
159 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, | 160 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSo
urce, DebugMessageLevel, |
160 String("Preconnect CORS setting is ") + String((crossOrigin
== CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); | 161 String("Preconnect CORS setting is ") + String((crossOrigin
== CrossOriginAttributeAnonymous) ? "anonymous" : "use-credentials"))); |
161 } | 162 } |
162 } | 163 } |
163 networkHintsInterface.preconnectHost(href, crossOrigin); | 164 networkHintsInterface.preconnectHost(href, crossOrigin); |
164 } | 165 } |
165 } | 166 } |
166 | 167 |
167 static bool getPriorityTypeFromAsAttribute(const String& as, Resource::Type& typ
e) | 168 static bool getTypeFromAsAttribute(const String& as, Resource::Type& type) |
168 { | 169 { |
169 if (as.isEmpty()) | 170 if (as.isEmpty()) |
170 return false; | 171 return false; |
171 | 172 |
172 if (equalIgnoringCase(as, "image")) | 173 if (equalIgnoringCase(as, "image")) |
173 type = Resource::Image; | 174 type = Resource::Image; |
174 else if (equalIgnoringCase(as, "script")) | 175 else if (equalIgnoringCase(as, "script")) |
175 type = Resource::Script; | 176 type = Resource::Script; |
176 else if (equalIgnoringCase(as, "stylesheet")) | 177 else if (equalIgnoringCase(as, "stylesheet")) |
177 type = Resource::CSSStyleSheet; | 178 type = Resource::CSSStyleSheet; |
178 else | 179 else |
179 return false; | 180 return false; |
180 | 181 |
181 return true; | 182 return true; |
182 } | 183 } |
183 | 184 |
184 void LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
L& href, Document& document, const String& as) | 185 static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& hr
ef, Document& document, const String& as) |
185 { | 186 { |
| 187 if (!document.loader()) |
| 188 return; |
| 189 |
186 if (relAttribute.isLinkPreload()) { | 190 if (relAttribute.isLinkPreload()) { |
187 UseCounter::count(document, UseCounter::LinkRelPreload); | 191 UseCounter::count(document, UseCounter::LinkRelPreload); |
188 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); | 192 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); |
189 if (!href.isValid() || href.isEmpty()) { | 193 if (!href.isValid() || href.isEmpty()) { |
190 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value"))
); | 194 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value"))
); |
191 return; | 195 return; |
192 } | 196 } |
193 // TODO(yoav): Figure out a way that 'as' would be used to set request h
eaders. | 197 // TODO(yoav): Figure out a way that 'as' would be used to set request h
eaders. |
194 Resource::Type priorityType; | 198 Resource::Type type; |
195 if (!getPriorityTypeFromAsAttribute(as, priorityType)) { | 199 if (!getTypeFromAsAttribute(as, type)) { |
196 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> must have a valid `as` value")
)); | 200 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> must have a valid `as` value")
)); |
197 return; | 201 return; |
198 } | 202 } |
199 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); | 203 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), Fe
tchInitiatorTypeNames::link); |
200 linkRequest.setPriority(document.fetcher()->loadPriority(priorityType, l
inkRequest)); | 204 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkReque
st)); |
201 Settings* settings = document.settings(); | 205 Settings* settings = document.settings(); |
202 if (settings && settings->logPreload()) | 206 if (settings && settings->logPreload()) |
203 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); | 207 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); |
204 setResource(LinkFetchResource::fetch(Resource::LinkPreload, linkRequest,
document.fetcher())); | 208 document.loader()->startPreload(type, linkRequest); |
205 } | 209 } |
206 } | 210 } |
207 | 211 |
208 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t, const NetworkHintsInterface& networkHintsInterface) | 212 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t, const NetworkHintsInterface& networkHintsInterface) |
209 { | 213 { |
210 if (!document) | 214 if (!document) |
211 return false; | 215 return false; |
212 LinkHeaderSet headerSet(headerValue); | 216 LinkHeaderSet headerSet(headerValue); |
213 for (auto& header : headerSet) { | 217 for (auto& header : headerSet) { |
214 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) | 218 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 m_prerender.clear(); | 285 m_prerender.clear(); |
282 } | 286 } |
283 } | 287 } |
284 | 288 |
285 DEFINE_TRACE(LinkLoader) | 289 DEFINE_TRACE(LinkLoader) |
286 { | 290 { |
287 visitor->trace(m_prerender); | 291 visitor->trace(m_prerender); |
288 } | 292 } |
289 | 293 |
290 } | 294 } |
OLD | NEW |