Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: third_party/WebKit/Source/core/loader/LinkLoader.cpp

Issue 1595793002: Revert of Add <link rel=preload> onload support for scripts and styles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(const 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
101 void LinkLoader::notifyFinished(Resource* resource) 93 void LinkLoader::notifyFinished(Resource* resource)
102 { 94 {
103 ASSERT(this->resource() == resource); 95 ASSERT(this->resource() == resource);
104 96
105 triggerEvents(resource); 97 if (resource->errorOccurred())
98 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE);
99 else
100 m_linkLoadTimer.startOneShot(0, BLINK_FROM_HERE);
101
106 clearResource(); 102 clearResource();
107 } 103 }
108 104
109 void LinkLoader::didStartPrerender() 105 void LinkLoader::didStartPrerender()
110 { 106 {
111 m_client->didStartLinkPrerender(); 107 m_client->didStartLinkPrerender();
112 } 108 }
113 109
114 void LinkLoader::didStopPrerender() 110 void LinkLoader::didStopPrerender()
115 { 111 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (equalIgnoringCase(as, "font")) 177 if (equalIgnoringCase(as, "font"))
182 return Resource::Font; 178 return Resource::Font;
183 if (equalIgnoringCase(as, "track")) 179 if (equalIgnoringCase(as, "track"))
184 return Resource::TextTrack; 180 return Resource::TextTrack;
185 if (document && !as.isEmpty()) 181 if (document && !as.isEmpty())
186 document->addConsoleMessage(ConsoleMessage::create(OtherMessageSource, W arningMessageLevel, String("<link rel=preload> must have a valid `as` value"))); 182 document->addConsoleMessage(ConsoleMessage::create(OtherMessageSource, W arningMessageLevel, String("<link rel=preload> must have a valid `as` value")));
187 // TODO(yoav): Is this correct? If as is missing or invalid, it should be su bject to "connect-src" CSP directives. 183 // TODO(yoav): Is this correct? If as is missing or invalid, it should be su bject to "connect-src" CSP directives.
188 return Resource::LinkSubresource; 184 return Resource::LinkSubresource;
189 } 185 }
190 186
191 void LinkLoader::createLinkPreloadResourceClient(ResourcePtr<Resource> resource) 187 static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& hr ef, Document& document, const String& as)
192 { 188 {
193 if (!resource) 189 if (!document.loader())
194 return; 190 return;
195 switch (resource->type()) { 191
196 case Resource::Image: 192 if (relAttribute.isLinkPreload()) {
197 break; 193 UseCounter::count(document, UseCounter::LinkRelPreload);
198 case Resource::Script: 194 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled());
199 m_linkPreloadResourceClient = LinkPreloadScriptResourceClient::create(th is, toScriptResource(resource.get())); 195 if (!href.isValid() || href.isEmpty()) {
200 break; 196 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , WarningMessageLevel, String("<link rel=preload> has an invalid `href` value")) );
201 case Resource::CSSStyleSheet: 197 return;
202 m_linkPreloadResourceClient = LinkPreloadStyleResourceClient::create(thi s, toCSSStyleSheetResource(resource.get())); 198 }
203 break; 199 Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document);
204 // TODO(yoav): add support for everything below. 200 ResourceRequest resourceRequest(document.completeURL(href));
205 case Resource::Font: 201 ResourceFetcher::determineRequestContext(resourceRequest, type, false);
206 break; 202 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link) ;
207 case Resource::Media: 203
208 break; 204 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkReque st));
209 case Resource::TextTrack: 205 Settings* settings = document.settings();
210 break; 206 if (settings && settings->logPreload())
211 case Resource::Raw: 207 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource , DebugMessageLevel, String("Preload triggered for " + href.host() + href.path() )));
212 case Resource::LinkSubresource: 208 linkRequest.setForPreload(true);
213 break; 209 linkRequest.setAvoidBlockingOnLoad(true);
214 default: 210 document.loader()->startPreload(type, linkRequest);
215 ASSERT_NOT_REACHED();
216 } 211 }
217 } 212 }
218 213
219 static ResourcePtr<Resource> preloadIfNeeded(const LinkRelAttribute& relAttribut e, const KURL& href, Document& document, const String& as)
220 {
221 if (!document.loader() || !relAttribute.isLinkPreload())
222 return nullptr;
223
224 UseCounter::count(document, UseCounter::LinkRelPreload);
225 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled());
226 if (!href.isValid() || href.isEmpty()) {
227 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> has an invalid `href` value")));
228 return nullptr;
229 }
230 Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document);
231 ResourceRequest resourceRequest(document.completeURL(href));
232 ResourceFetcher::determineRequestContext(resourceRequest, type, false);
233 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link);
234
235 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkRequest)) ;
236 Settings* settings = document.settings();
237 if (settings && settings->logPreload())
238 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De bugMessageLevel, String("Preload triggered for " + href.host() + href.path())));
239 linkRequest.setForPreload(true);
240 linkRequest.setAvoidBlockingOnLoad(true);
241 return document.loader()->startPreload(type, linkRequest);
242 }
243
244 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen t, const NetworkHintsInterface& networkHintsInterface, CanLoadResources canLoadR esources) 214 bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen t, const NetworkHintsInterface& networkHintsInterface, CanLoadResources canLoadR esources)
245 { 215 {
246 if (!document) 216 if (!document)
247 return false; 217 return false;
248 LinkHeaderSet headerSet(headerValue); 218 LinkHeaderSet headerSet(headerValue);
249 for (auto& header : headerSet) { 219 for (auto& header : headerSet) {
250 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty()) 220 if (!header.valid() || header.url().isEmpty() || header.rel().isEmpty())
251 return false; 221 return false;
252 222
253 LinkRelAttribute relAttribute(header.rel()); 223 LinkRelAttribute relAttribute(header.rel());
(...skipping 17 matching lines...) Expand all
271 { 241 {
272 // TODO(yoav): Do all links need to load only after they're in document??? 242 // TODO(yoav): Do all links need to load only after they're in document???
273 243
274 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt tributeValue. crbug.com/486689 244 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt tributeValue. crbug.com/486689
275 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't. 245 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't.
276 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, Lin kCalledFromMarkup); 246 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, Lin kCalledFromMarkup);
277 247
278 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn terface, LinkCalledFromMarkup); 248 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn terface, LinkCalledFromMarkup);
279 249
280 if (m_client->shouldLoadLink()) 250 if (m_client->shouldLoadLink())
281 createLinkPreloadResourceClient(preloadIfNeeded(relAttribute, href, docu ment, as)); 251 preloadIfNeeded(relAttribute, href, document, as);
282 252
283 // FIXME(crbug.com/323096): Should take care of import. 253 // FIXME(crbug.com/323096): Should take care of import.
284 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h ref.isValid() && document.frame()) { 254 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h ref.isValid() && document.frame()) {
285 if (!m_client->shouldLoadLink()) 255 if (!m_client->shouldLoadLink())
286 return false; 256 return false;
287 Resource::Type type = Resource::LinkPrefetch; 257 Resource::Type type = Resource::LinkPrefetch;
288 if (relAttribute.isLinkSubresource()) { 258 if (relAttribute.isLinkSubresource()) {
289 type = Resource::LinkSubresource; 259 type = Resource::LinkSubresource;
290 UseCounter::count(document, UseCounter::LinkRelSubresource); 260 UseCounter::count(document, UseCounter::LinkRelSubresource);
291 } else { 261 } else {
(...skipping 27 matching lines...) Expand all
319 // atomic (dns prefetch). 289 // atomic (dns prefetch).
320 if (m_prerender) { 290 if (m_prerender) {
321 m_prerender->cancel(); 291 m_prerender->cancel();
322 m_prerender.clear(); 292 m_prerender.clear();
323 } 293 }
324 } 294 }
325 295
326 DEFINE_TRACE(LinkLoader) 296 DEFINE_TRACE(LinkLoader)
327 { 297 {
328 visitor->trace(m_prerender); 298 visitor->trace(m_prerender);
329 visitor->trace(m_linkPreloadResourceClient);
330 } 299 }
331 300
332 } 301 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | third_party/WebKit/Source/core/loader/LinkPreloadResourceClients.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698