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

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

Issue 1602203005: Add use counter for preload link headers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 case Resource::TextTrack: 209 case Resource::TextTrack:
210 break; 210 break;
211 case Resource::Raw: 211 case Resource::Raw:
212 case Resource::LinkSubresource: 212 case Resource::LinkSubresource:
213 break; 213 break;
214 default: 214 default:
215 ASSERT_NOT_REACHED(); 215 ASSERT_NOT_REACHED();
216 } 216 }
217 } 217 }
218 218
219 static ResourcePtr<Resource> preloadIfNeeded(const LinkRelAttribute& relAttribut e, const KURL& href, Document& document, const String& as) 219 static ResourcePtr<Resource> preloadIfNeeded(const LinkRelAttribute& relAttribut e, const KURL& href, Document& document, const String& as, LinkCaller caller)
220 { 220 {
221 if (!document.loader() || !relAttribute.isLinkPreload()) 221 if (!document.loader() || !relAttribute.isLinkPreload())
222 return nullptr; 222 return nullptr;
223 223
224 UseCounter::count(document, UseCounter::LinkRelPreload); 224 UseCounter::count(document, UseCounter::LinkRelPreload);
225 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled()); 225 ASSERT(RuntimeEnabledFeatures::linkPreloadEnabled());
226 if (!href.isValid() || href.isEmpty()) { 226 if (!href.isValid() || href.isEmpty()) {
227 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> has an invalid `href` value"))); 227 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, Wa rningMessageLevel, String("<link rel=preload> has an invalid `href` value")));
228 return nullptr; 228 return nullptr;
229 } 229 }
230 if (caller == LinkCalledFromHeader)
231 UseCounter::count(document, UseCounter::LinkHeaderPreload);
230 Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document); 232 Resource::Type type = LinkLoader::getTypeFromAsAttribute(as, &document);
231 ResourceRequest resourceRequest(document.completeURL(href)); 233 ResourceRequest resourceRequest(document.completeURL(href));
232 ResourceFetcher::determineRequestContext(resourceRequest, type, false); 234 ResourceFetcher::determineRequestContext(resourceRequest, type, false);
233 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link); 235 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link);
234 236
235 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkRequest)) ; 237 linkRequest.setPriority(document.fetcher()->loadPriority(type, linkRequest)) ;
236 Settings* settings = document.settings(); 238 Settings* settings = document.settings();
237 if (settings && settings->logPreload()) 239 if (settings && settings->logPreload())
238 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De bugMessageLevel, String("Preload triggered for " + href.host() + href.path()))); 240 document.addConsoleMessage(ConsoleMessage::create(OtherMessageSource, De bugMessageLevel, String("Preload triggered for " + href.host() + href.path())));
239 linkRequest.setForPreload(true); 241 linkRequest.setForPreload(true);
(...skipping 13 matching lines...) Expand all
253 LinkRelAttribute relAttribute(header.rel()); 255 LinkRelAttribute relAttribute(header.rel());
254 KURL url = document->completeURL(header.url()); 256 KURL url = document->completeURL(header.url());
255 if (canLoadResources == DoNotLoadResources) { 257 if (canLoadResources == DoNotLoadResources) {
256 if (RuntimeEnabledFeatures::linkHeaderEnabled()) 258 if (RuntimeEnabledFeatures::linkHeaderEnabled())
257 dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsIn terface, LinkCalledFromHeader); 259 dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsIn terface, LinkCalledFromHeader);
258 260
259 if (RuntimeEnabledFeatures::linkPreconnectEnabled()) 261 if (RuntimeEnabledFeatures::linkPreconnectEnabled())
260 preconnectIfNeeded(relAttribute, url, *document, header.crossOri gin(), networkHintsInterface, LinkCalledFromHeader); 262 preconnectIfNeeded(relAttribute, url, *document, header.crossOri gin(), networkHintsInterface, LinkCalledFromHeader);
261 } else { 263 } else {
262 if (RuntimeEnabledFeatures::linkPreloadEnabled()) 264 if (RuntimeEnabledFeatures::linkPreloadEnabled())
263 preloadIfNeeded(relAttribute, url, *document, header.as()); 265 preloadIfNeeded(relAttribute, url, *document, header.as(), LinkC alledFromHeader);
264 } 266 }
265 // TODO(yoav): Add more supported headers as needed. 267 // TODO(yoav): Add more supported headers as needed.
266 } 268 }
267 return true; 269 return true;
268 } 270 }
269 271
270 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttri buteValue crossOrigin, const String& type, const String& as, const KURL& href, D ocument& document, const NetworkHintsInterface& networkHintsInterface) 272 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttri buteValue crossOrigin, const String& type, const String& as, const KURL& href, D ocument& document, const NetworkHintsInterface& networkHintsInterface)
271 { 273 {
272 // TODO(yoav): Do all links need to load only after they're in document??? 274 // TODO(yoav): Do all links need to load only after they're in document???
273 275
274 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAt tributeValue. crbug.com/486689 276 // 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. 277 // FIXME(crbug.com/463266): We're ignoring type here. Maybe we shouldn't.
276 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, Lin kCalledFromMarkup); 278 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, Lin kCalledFromMarkup);
277 279
278 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn terface, LinkCalledFromMarkup); 280 preconnectIfNeeded(relAttribute, href, document, crossOrigin, networkHintsIn terface, LinkCalledFromMarkup);
279 281
280 if (m_client->shouldLoadLink()) 282 if (m_client->shouldLoadLink())
281 createLinkPreloadResourceClient(preloadIfNeeded(relAttribute, href, docu ment, as)); 283 createLinkPreloadResourceClient(preloadIfNeeded(relAttribute, href, docu ment, as, LinkCalledFromMarkup));
282 284
283 // FIXME(crbug.com/323096): Should take care of import. 285 // FIXME(crbug.com/323096): Should take care of import.
284 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h ref.isValid() && document.frame()) { 286 if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && h ref.isValid() && document.frame()) {
285 if (!m_client->shouldLoadLink()) 287 if (!m_client->shouldLoadLink())
286 return false; 288 return false;
287 Resource::Type type = Resource::LinkPrefetch; 289 Resource::Type type = Resource::LinkPrefetch;
288 if (relAttribute.isLinkSubresource()) { 290 if (relAttribute.isLinkSubresource()) {
289 type = Resource::LinkSubresource; 291 type = Resource::LinkSubresource;
290 UseCounter::count(document, UseCounter::LinkRelSubresource); 292 UseCounter::count(document, UseCounter::LinkRelSubresource);
291 } else { 293 } else {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 327
326 DEFINE_TRACE(LinkLoader) 328 DEFINE_TRACE(LinkLoader)
327 { 329 {
328 visitor->trace(m_client); 330 visitor->trace(m_client);
329 visitor->trace(m_prerender); 331 visitor->trace(m_prerender);
330 visitor->trace(m_linkPreloadResourceClient); 332 visitor->trace(m_linkPreloadResourceClient);
331 ResourceOwner<Resource, ResourceClient>::trace(visitor); 333 ResourceOwner<Resource, ResourceClient>::trace(visitor);
332 } 334 }
333 335
334 } 336 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698