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

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

Issue 2483713002: Add referrerpolicy support to link prefetch (Closed)
Patch Set: -mReview nit & DCHECK Created 4 years, 1 month 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 result |= PrerenderRelTypeNext; 68 result |= PrerenderRelTypeNext;
69 UseCounter::count(document, UseCounter::LinkRelNext); 69 UseCounter::count(document, UseCounter::LinkRelNext);
70 } 70 }
71 71
72 return result; 72 return result;
73 } 73 }
74 74
75 LinkLoader::LinkLoader(LinkLoaderClient* client) 75 LinkLoader::LinkLoader(LinkLoaderClient* client)
76 : m_client(client), 76 : m_client(client),
77 m_linkLoadTimer(this, &LinkLoader::linkLoadTimerFired), 77 m_linkLoadTimer(this, &LinkLoader::linkLoadTimerFired),
78 m_linkLoadingErrorTimer(this, &LinkLoader::linkLoadingErrorTimerFired) {} 78 m_linkLoadingErrorTimer(this, &LinkLoader::linkLoadingErrorTimerFired) {
79 DCHECK(m_client);
Yoav Weiss 2016/11/08 09:27:22 Added a DCHECK here that seemed missing...
80 }
79 81
80 LinkLoader::~LinkLoader() {} 82 LinkLoader::~LinkLoader() {}
81 83
82 void LinkLoader::linkLoadTimerFired(TimerBase* timer) { 84 void LinkLoader::linkLoadTimerFired(TimerBase* timer) {
83 DCHECK_EQ(timer, &m_linkLoadTimer); 85 DCHECK_EQ(timer, &m_linkLoadTimer);
84 m_client->linkLoaded(); 86 m_client->linkLoaded();
85 } 87 }
86 88
87 void LinkLoader::linkLoadingErrorTimerFired(TimerBase* timer) { 89 void LinkLoader::linkLoadingErrorTimerFired(TimerBase* timer) {
88 DCHECK_EQ(timer, &m_linkLoadingErrorTimer); 90 DCHECK_EQ(timer, &m_linkLoadingErrorTimer);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (settings && settings->logPreload()) { 335 if (settings && settings->logPreload()) {
334 document.addConsoleMessage(ConsoleMessage::create( 336 document.addConsoleMessage(ConsoleMessage::create(
335 OtherMessageSource, DebugMessageLevel, 337 OtherMessageSource, DebugMessageLevel,
336 String("Preload triggered for " + href.host() + href.path()))); 338 String("Preload triggered for " + href.host() + href.path())));
337 } 339 }
338 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); 340 linkRequest.setForPreload(true, monotonicallyIncreasingTime());
339 linkRequest.setLinkPreload(true); 341 linkRequest.setLinkPreload(true);
340 return document.loader()->startPreload(resourceType, linkRequest); 342 return document.loader()->startPreload(resourceType, linkRequest);
341 } 343 }
342 344
345 void LinkLoader::prefetchIfNeeded(Document& document,
346 const KURL& href,
347 const LinkRelAttribute& relAttribute,
348 CrossOriginAttributeValue crossOrigin,
349 ReferrerPolicy referrerPolicy) {
350 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) {
351 UseCounter::count(document, UseCounter::LinkRelPrefetch);
352
353 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)),
354 FetchInitiatorTypeNames::link);
355 if (referrerPolicy != ReferrerPolicyDefault) {
356 linkRequest.mutableResourceRequest().setHTTPReferrer(
357 SecurityPolicy::generateReferrer(referrerPolicy, href,
358 document.outgoingReferrer()));
359 }
360 if (crossOrigin != CrossOriginAttributeNotSet) {
361 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
362 crossOrigin);
363 }
364 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest,
365 document.fetcher()));
366 }
367 }
368
343 void LinkLoader::loadLinksFromHeader( 369 void LinkLoader::loadLinksFromHeader(
344 const String& headerValue, 370 const String& headerValue,
345 const KURL& baseURL, 371 const KURL& baseURL,
346 Document* document, 372 Document* document,
347 const NetworkHintsInterface& networkHintsInterface, 373 const NetworkHintsInterface& networkHintsInterface,
348 CanLoadResources canLoadResources, 374 CanLoadResources canLoadResources,
349 MediaPreloadPolicy mediaPolicy, 375 MediaPreloadPolicy mediaPolicy,
350 ViewportDescriptionWrapper* viewportDescriptionWrapper) { 376 ViewportDescriptionWrapper* viewportDescriptionWrapper) {
351 if (!document || headerValue.isEmpty()) 377 if (!document || headerValue.isEmpty())
352 return; 378 return;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 418
393 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, 419 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute,
394 CrossOriginAttributeValue crossOrigin, 420 CrossOriginAttributeValue crossOrigin,
395 const String& type, 421 const String& type,
396 const String& as, 422 const String& as,
397 const String& media, 423 const String& media,
398 ReferrerPolicy referrerPolicy, 424 ReferrerPolicy referrerPolicy,
399 const KURL& href, 425 const KURL& href,
400 Document& document, 426 Document& document,
401 const NetworkHintsInterface& networkHintsInterface) { 427 const NetworkHintsInterface& networkHintsInterface) {
402 // TODO(yoav): Do all links need to load only after they're in document??? 428 if (!m_client->shouldLoadLink())
429 return false;
403 430
404 // TODO(yoav): Convert all uses of the CrossOriginAttribute to
405 // CrossOriginAttributeValue. crbug.com/486689
406
407 // FIXME(crbug.com/463266): We're ignoring type here, for everything but
408 // preload. Maybe we shouldn't.
409 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, 431 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface,
410 LinkCalledFromMarkup); 432 LinkCalledFromMarkup);
411 433
412 preconnectIfNeeded(relAttribute, href, document, crossOrigin, 434 preconnectIfNeeded(relAttribute, href, document, crossOrigin,
413 networkHintsInterface, LinkCalledFromMarkup); 435 networkHintsInterface, LinkCalledFromMarkup);
414 436
415 bool errorOccurred = false; 437 bool errorOccurred = false;
416 if (m_client->shouldLoadLink()) { 438 createLinkPreloadResourceClient(preloadIfNeeded(
417 createLinkPreloadResourceClient(preloadIfNeeded( 439 relAttribute, href, document, as, type, media, crossOrigin,
418 relAttribute, href, document, as, type, media, crossOrigin, 440 LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy));
419 LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy));
420 }
421 if (errorOccurred) 441 if (errorOccurred)
422 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); 442 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE);
423 443
424 if (href.isEmpty() || !href.isValid()) 444 if (href.isEmpty() || !href.isValid())
425 released(); 445 released();
426 446
427 // FIXME(crbug.com/323096): Should take care of import. 447 prefetchIfNeeded(document, href, relAttribute, crossOrigin, referrerPolicy);
428 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) {
429 if (!m_client->shouldLoadLink())
430 return false;
431 UseCounter::count(document, UseCounter::LinkRelPrefetch);
432
433 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)),
434 FetchInitiatorTypeNames::link);
435 if (crossOrigin != CrossOriginAttributeNotSet) {
436 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
437 crossOrigin);
438 }
439 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest,
440 document.fetcher()));
441 }
442 448
443 if (const unsigned prerenderRelTypes = 449 if (const unsigned prerenderRelTypes =
444 prerenderRelTypesFromRelAttribute(relAttribute, document)) { 450 prerenderRelTypesFromRelAttribute(relAttribute, document)) {
445 if (!m_prerender) { 451 if (!m_prerender) {
446 m_prerender = 452 m_prerender =
447 PrerenderHandle::create(document, this, href, prerenderRelTypes); 453 PrerenderHandle::create(document, this, href, prerenderRelTypes);
448 } else if (m_prerender->url() != href) { 454 } else if (m_prerender->url() != href) {
449 m_prerender->cancel(); 455 m_prerender->cancel();
450 m_prerender = 456 m_prerender =
451 PrerenderHandle::create(document, this, href, prerenderRelTypes); 457 PrerenderHandle::create(document, this, href, prerenderRelTypes);
(...skipping 19 matching lines...) Expand all
471 477
472 DEFINE_TRACE(LinkLoader) { 478 DEFINE_TRACE(LinkLoader) {
473 visitor->trace(m_client); 479 visitor->trace(m_client);
474 visitor->trace(m_prerender); 480 visitor->trace(m_prerender);
475 visitor->trace(m_linkPreloadResourceClient); 481 visitor->trace(m_linkPreloadResourceClient);
476 ResourceOwner<Resource, ResourceClient>::trace(visitor); 482 ResourceOwner<Resource, ResourceClient>::trace(visitor);
477 PrerenderClient::trace(visitor); 483 PrerenderClient::trace(visitor);
478 } 484 }
479 485
480 } // namespace blink 486 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | third_party/WebKit/Source/core/loader/LinkLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698