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

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

Issue 2602233002: Prefetch Link header support. (Closed)
Patch Set: Test based of perfObserver Created 3 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/loader/LinkLoader.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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (settings && settings->logPreload()) { 335 if (settings && settings->logPreload()) {
336 document.addConsoleMessage(ConsoleMessage::create( 336 document.addConsoleMessage(ConsoleMessage::create(
337 OtherMessageSource, DebugMessageLevel, 337 OtherMessageSource, DebugMessageLevel,
338 String("Preload triggered for " + href.host() + href.path()))); 338 String("Preload triggered for " + href.host() + href.path())));
339 } 339 }
340 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); 340 linkRequest.setForPreload(true, monotonicallyIncreasingTime());
341 linkRequest.setLinkPreload(true); 341 linkRequest.setLinkPreload(true);
342 return document.loader()->startPreload(resourceType, linkRequest); 342 return document.loader()->startPreload(resourceType, linkRequest);
343 } 343 }
344 344
345 void LinkLoader::prefetchIfNeeded(Document& document, 345 static Resource* prefetchIfNeeded(Document& document,
346 const KURL& href, 346 const KURL& href,
347 const LinkRelAttribute& relAttribute, 347 const LinkRelAttribute& relAttribute,
348 CrossOriginAttributeValue crossOrigin, 348 CrossOriginAttributeValue crossOrigin,
349 ReferrerPolicy referrerPolicy) { 349 ReferrerPolicy referrerPolicy) {
350 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) { 350 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) {
351 UseCounter::count(document, UseCounter::LinkRelPrefetch); 351 UseCounter::count(document, UseCounter::LinkRelPrefetch);
352 352
353 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), 353 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)),
354 FetchInitiatorTypeNames::link); 354 FetchInitiatorTypeNames::link);
355 if (referrerPolicy != ReferrerPolicyDefault) { 355 if (referrerPolicy != ReferrerPolicyDefault) {
356 linkRequest.mutableResourceRequest().setHTTPReferrer( 356 linkRequest.mutableResourceRequest().setHTTPReferrer(
357 SecurityPolicy::generateReferrer(referrerPolicy, href, 357 SecurityPolicy::generateReferrer(referrerPolicy, href,
358 document.outgoingReferrer())); 358 document.outgoingReferrer()));
359 } 359 }
360 if (crossOrigin != CrossOriginAttributeNotSet) { 360 if (crossOrigin != CrossOriginAttributeNotSet) {
361 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), 361 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
362 crossOrigin); 362 crossOrigin);
363 } 363 }
364 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest, 364 return LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest,
365 document.fetcher())); 365 document.fetcher());
366 } 366 }
367 return nullptr;
367 } 368 }
368 369
369 void LinkLoader::loadLinksFromHeader( 370 void LinkLoader::loadLinksFromHeader(
370 const String& headerValue, 371 const String& headerValue,
371 const KURL& baseURL, 372 const KURL& baseURL,
372 Document* document, 373 Document* document,
373 const NetworkHintsInterface& networkHintsInterface, 374 const NetworkHintsInterface& networkHintsInterface,
374 CanLoadResources canLoadResources, 375 CanLoadResources canLoadResources,
375 MediaPreloadPolicy mediaPolicy, 376 MediaPreloadPolicy mediaPolicy,
376 ViewportDescriptionWrapper* viewportDescriptionWrapper) { 377 ViewportDescriptionWrapper* viewportDescriptionWrapper) {
(...skipping 22 matching lines...) Expand all
399 crossOriginAttributeValue(header.crossOrigin()), 400 crossOriginAttributeValue(header.crossOrigin()),
400 networkHintsInterface, LinkCalledFromHeader); 401 networkHintsInterface, LinkCalledFromHeader);
401 } 402 }
402 if (canLoadResources != DoNotLoadResources) { 403 if (canLoadResources != DoNotLoadResources) {
403 bool errorOccurred = false; 404 bool errorOccurred = false;
404 ViewportDescription* viewportDescription = 405 ViewportDescription* viewportDescription =
405 (viewportDescriptionWrapper && viewportDescriptionWrapper->set) 406 (viewportDescriptionWrapper && viewportDescriptionWrapper->set)
406 ? &(viewportDescriptionWrapper->description) 407 ? &(viewportDescriptionWrapper->description)
407 : nullptr; 408 : nullptr;
408 409
410 CrossOriginAttributeValue crossOrigin =
411 crossOriginAttributeValue(header.crossOrigin());
409 preloadIfNeeded(relAttribute, url, *document, header.as(), 412 preloadIfNeeded(relAttribute, url, *document, header.as(),
410 header.mimeType(), header.media(), 413 header.mimeType(), header.media(), crossOrigin,
411 crossOriginAttributeValue(header.crossOrigin()),
412 LinkCalledFromHeader, errorOccurred, viewportDescription, 414 LinkCalledFromHeader, errorOccurred, viewportDescription,
413 ReferrerPolicyDefault); 415 ReferrerPolicyDefault);
416 prefetchIfNeeded(*document, url, relAttribute, crossOrigin,
417 ReferrerPolicyDefault);
414 } 418 }
415 if (relAttribute.isServiceWorker()) { 419 if (relAttribute.isServiceWorker()) {
416 UseCounter::count(*document, UseCounter::LinkHeaderServiceWorker); 420 UseCounter::count(*document, UseCounter::LinkHeaderServiceWorker);
417 } 421 }
418 // TODO(yoav): Add more supported headers as needed. 422 // TODO(yoav): Add more supported headers as needed.
419 } 423 }
420 } 424 }
421 425
422 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, 426 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute,
423 CrossOriginAttributeValue crossOrigin, 427 CrossOriginAttributeValue crossOrigin,
(...skipping 16 matching lines...) Expand all
440 bool errorOccurred = false; 444 bool errorOccurred = false;
441 createLinkPreloadResourceClient(preloadIfNeeded( 445 createLinkPreloadResourceClient(preloadIfNeeded(
442 relAttribute, href, document, as, type, media, crossOrigin, 446 relAttribute, href, document, as, type, media, crossOrigin,
443 LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy)); 447 LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy));
444 if (errorOccurred) 448 if (errorOccurred)
445 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); 449 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE);
446 450
447 if (href.isEmpty() || !href.isValid()) 451 if (href.isEmpty() || !href.isValid())
448 released(); 452 released();
449 453
450 prefetchIfNeeded(document, href, relAttribute, crossOrigin, referrerPolicy); 454 Resource* resource = prefetchIfNeeded(document, href, relAttribute,
455 crossOrigin, referrerPolicy);
456 if (resource)
457 setResource(resource);
451 458
452 if (const unsigned prerenderRelTypes = 459 if (const unsigned prerenderRelTypes =
453 prerenderRelTypesFromRelAttribute(relAttribute, document)) { 460 prerenderRelTypesFromRelAttribute(relAttribute, document)) {
454 if (!m_prerender) { 461 if (!m_prerender) {
455 m_prerender = 462 m_prerender =
456 PrerenderHandle::create(document, this, href, prerenderRelTypes); 463 PrerenderHandle::create(document, this, href, prerenderRelTypes);
457 } else if (m_prerender->url() != href) { 464 } else if (m_prerender->url() != href) {
458 m_prerender->cancel(); 465 m_prerender->cancel();
459 m_prerender = 466 m_prerender =
460 PrerenderHandle::create(document, this, href, prerenderRelTypes); 467 PrerenderHandle::create(document, this, href, prerenderRelTypes);
(...skipping 19 matching lines...) Expand all
480 487
481 DEFINE_TRACE(LinkLoader) { 488 DEFINE_TRACE(LinkLoader) {
482 visitor->trace(m_client); 489 visitor->trace(m_client);
483 visitor->trace(m_prerender); 490 visitor->trace(m_prerender);
484 visitor->trace(m_linkPreloadResourceClient); 491 visitor->trace(m_linkPreloadResourceClient);
485 ResourceOwner<Resource, ResourceClient>::trace(visitor); 492 ResourceOwner<Resource, ResourceClient>::trace(visitor);
486 PrerenderClient::trace(visitor); 493 PrerenderClient::trace(visitor);
487 } 494 }
488 495
489 } // namespace blink 496 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698