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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ASSERT_UNUSED(timer, timer == &m_linkLoadTimer); | 83 ASSERT_UNUSED(timer, timer == &m_linkLoadTimer); |
84 m_client->linkLoaded(); | 84 m_client->linkLoaded(); |
85 } | 85 } |
86 | 86 |
87 void LinkLoader::linkLoadingErrorTimerFired(Timer<LinkLoader>* timer) | 87 void LinkLoader::linkLoadingErrorTimerFired(Timer<LinkLoader>* timer) |
88 { | 88 { |
89 ASSERT_UNUSED(timer, timer == &m_linkLoadingErrorTimer); | 89 ASSERT_UNUSED(timer, timer == &m_linkLoadingErrorTimer); |
90 m_client->linkLoadingErrored(); | 90 m_client->linkLoadingErrored(); |
91 } | 91 } |
92 | 92 |
| 93 void LinkLoader::triggerEvents(Resource* resource) |
| 94 { |
| 95 if (resource->errorOccurred()) |
| 96 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); |
| 97 else |
| 98 m_linkLoadTimer.startOneShot(0, BLINK_FROM_HERE); |
| 99 } |
| 100 |
93 void LinkLoader::notifyFinished(Resource* resource) | 101 void LinkLoader::notifyFinished(Resource* resource) |
94 { | 102 { |
95 ASSERT(this->resource() == resource); | 103 ASSERT(this->resource() == resource); |
96 | 104 |
97 if (resource->errorOccurred()) | 105 triggerEvents(resource); |
98 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); | |
99 else | |
100 m_linkLoadTimer.startOneShot(0, BLINK_FROM_HERE); | |
101 | |
102 clearResource(); | 106 clearResource(); |
103 } | 107 } |
104 | 108 |
105 void LinkLoader::didStartPrerender() | 109 void LinkLoader::didStartPrerender() |
106 { | 110 { |
107 m_client->didStartLinkPrerender(); | 111 m_client->didStartLinkPrerender(); |
108 } | 112 } |
109 | 113 |
110 void LinkLoader::didStopPrerender() | 114 void LinkLoader::didStopPrerender() |
111 { | 115 { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (equalIgnoringCase(as, "font")) | 181 if (equalIgnoringCase(as, "font")) |
178 return Resource::Font; | 182 return Resource::Font; |
179 if (equalIgnoringCase(as, "track")) | 183 if (equalIgnoringCase(as, "track")) |
180 return Resource::TextTrack; | 184 return Resource::TextTrack; |
181 if (document && !as.isEmpty()) | 185 if (document && !as.isEmpty()) |
182 document->addConsoleMessage(ConsoleMessage::create(OtherMessageSource, W
arningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); | 186 document->addConsoleMessage(ConsoleMessage::create(OtherMessageSource, W
arningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); |
183 // TODO(yoav): Is this correct? If as is missing or invalid, it should be su
bject to "connect-src" CSP directives. | 187 // TODO(yoav): Is this correct? If as is missing or invalid, it should be su
bject to "connect-src" CSP directives. |
184 return Resource::LinkSubresource; | 188 return Resource::LinkSubresource; |
185 } | 189 } |
186 | 190 |
187 static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& hr
ef, Document& document, const String& as) | 191 static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& hr
ef, Document& document, const String& as, LinkLoader* linkLoader) |
188 { | 192 { |
189 if (!document.loader()) | 193 if (!document.loader() || !relAttribute.isLinkPreload()) |
190 return; | 194 return; |
191 | 195 |
192 if (relAttribute.isLinkPreload()) { | 196 UseCounter::count(document, UseCounter::LinkRelPreload); |
193 UseCounter::count(document, UseCounter::LinkRelPreload); | 197 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); |
194 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); | 198 if (!href.isValid() || href.isEmpty()) { |
195 if (!href.isValid() || href.isEmpty()) { | 199 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa
rningMessageLevel, String("<link rel=preload> has an invalid `href` value"))); |
196 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, WarningMessageLevel, String("<link rel=preload> has an invalid `href` value"))
); | 200 return; |
197 return; | 201 } |
198 } | 202 Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document); |
199 Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document); | 203 ResourceRequest resourceRequest(document.completeURL(href)); |
200 ResourceRequest resourceRequest(document.completeURL(href)); | 204 ResourceFetcher::determineRequestContext(resourceRequest, type, false); |
201 ResourceFetcher::determineRequestContext(resourceRequest, type, false); | 205 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link); |
202 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link)
; | |
203 | 206 |
204 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkReque
st)); | 207 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkRequest))
; |
205 Settings* settings = document.settings(); | 208 Settings* settings = document.settings(); |
206 if (settings && settings->logPreload()) | 209 if (settings && settings->logPreload()) |
207 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource
, DebugMessageLevel, String("Preload triggered for " + href.host() + href.path()
))); | 210 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De
bugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); |
208 linkRequest.setForPreload(true); | 211 linkRequest.setForPreload(true); |
209 linkRequest.setAvoidBlockingOnLoad(true); | 212 linkRequest.setAvoidBlockingOnLoad(true); |
210 document.loader()->startPreload(type, linkRequest); | 213 document.loader()->startPreload(type, linkRequest, linkLoader); |
211 } | |
212 } | 214 } |
213 | 215 |
214 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t, const NetworkHintsInterface& networkHintsInterface, CanLoadResources canLoadR
esources) | 216 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
t, const NetworkHintsInterface& networkHintsInterface, CanLoadResources canLoadR
esources) |
215 { | 217 { |
216 if (!document) | 218 if (!document) |
217 return false; | 219 return false; |
218 LinkHeaderSet headerSet(headerValue); | 220 LinkHeaderSet headerSet(headerValue); |
219 for (auto& header : headerSet) { | 221 for (auto& header : headerSet) { |
220 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) | 222 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) |
221 return false; | 223 return false; |
222 | 224 |
223 LinkRelAttribute relAttribute(header.rel()); | 225 LinkRelAttribute relAttribute(header.rel()); |
224 KURL url = document->completeURL(header.url()); | 226 KURL url = document->completeURL(header.url()); |
225 if (canLoadResources == DoNotLoadResources) { | 227 if (canLoadResources == DoNotLoadResources) { |
226 if (RuntimeEnabledFeatures::linkHeaderEnabled()) | 228 if (RuntimeEnabledFeatures::linkHeaderEnabled()) |
227 dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsIn
terface, LinkCalledFromHeader); | 229 dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsIn
terface, LinkCalledFromHeader); |
228 | 230 |
229 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) | 231 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) |
230 preconnectIfNeeded(relAttribute, url, *document, header.crossOri
gin(), networkHintsInterface, LinkCalledFromHeader); | 232 preconnectIfNeeded(relAttribute, url, *document, header.crossOri
gin(), networkHintsInterface, LinkCalledFromHeader); |
231 } else { | 233 } else { |
232 if (RuntimeEnabledFeatures::linkPreloadEnabled()) | 234 if (RuntimeEnabledFeatures::linkPreloadEnabled()) |
233 preloadIfNeeded(relAttribute, url, *document, header.as()); | 235 preloadIfNeeded(relAttribute, url, *document, header.as(), nullp
tr); |
234 } | 236 } |
235 // TODO(yoav): Add more supported headers as needed. | 237 // TODO(yoav): Add more supported headers as needed. |
236 } | 238 } |
237 return true; | 239 return true; |
238 } | 240 } |
239 | 241 |
240 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttri
buteValue crossOrigin, const String& type, const String& as, const KURL& href, D
ocument& document, const NetworkHintsInterface& networkHintsInterface) | 242 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttri
buteValue crossOrigin, const String& type, const String& as, const KURL& href, D
ocument& document, const NetworkHintsInterface& networkHintsInterface) |
241 { | 243 { |
242 // TODO(yoav): Do all links need to load only after they're in document??? | 244 // TODO(yoav): Do all links need to load only after they're in document??? |
243 | 245 |
244 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt
tributeValue. crbug.com/486689 | 246 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt
tributeValue. crbug.com/486689 |
245 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. | 247 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. |
246 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, Lin
kCalledFromMarkup); | 248 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, Lin
kCalledFromMarkup); |
247 | 249 |
248 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn
terface, LinkCalledFromMarkup); | 250 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn
terface, LinkCalledFromMarkup); |
249 | 251 |
250 if (m_client->shouldLoadLink()) | 252 if (m_client->shouldLoadLink()) |
251 preloadIfNeeded(relAttribute, href, document, as); | 253 preloadIfNeeded(relAttribute, href, document, as, this); |
252 | 254 |
253 // FIXME(crbug.com/323096): Should take care of import. | 255 // FIXME(crbug.com/323096): Should take care of import. |
254 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h
ref.isValid() && document.frame()) { | 256 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h
ref.isValid() && document.frame()) { |
255 if (!m_client->shouldLoadLink()) | 257 if (!m_client->shouldLoadLink()) |
256 return false; | 258 return false; |
257 Resource::Type type = Resource::LinkPrefetch; | 259 Resource::Type type = Resource::LinkPrefetch; |
258 if (relAttribute.isLinkSubresource()) { | 260 if (relAttribute.isLinkSubresource()) { |
259 type = Resource::LinkSubresource; | 261 type = Resource::LinkSubresource; |
260 UseCounter::count(document, UseCounter::LinkRelSubresource); | 262 UseCounter::count(document, UseCounter::LinkRelSubresource); |
261 } else { | 263 } else { |
(...skipping 27 matching lines...) Expand all Loading... |
289 // atomic (dns prefetch). | 291 // atomic (dns prefetch). |
290 if (m_prerender) { | 292 if (m_prerender) { |
291 m_prerender->cancel(); | 293 m_prerender->cancel(); |
292 m_prerender.clear(); | 294 m_prerender.clear(); |
293 } | 295 } |
294 } | 296 } |
295 | 297 |
296 DEFINE_TRACE(LinkLoader) | 298 DEFINE_TRACE(LinkLoader) |
297 { | 299 { |
298 visitor->trace(m_prerender); | 300 visitor->trace(m_prerender); |
| 301 visitor->trace(m_linkPreloadResourceClient); |
299 } | 302 } |
300 | 303 |
301 } | 304 } |
OLD | NEW |