Chromium Code Reviews| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 if (settings && settings->logPreload()) { | 333 if (settings && settings->logPreload()) { |
| 334 document.addConsoleMessage(ConsoleMessage::create( | 334 document.addConsoleMessage(ConsoleMessage::create( |
| 335 OtherMessageSource, DebugMessageLevel, | 335 OtherMessageSource, DebugMessageLevel, |
| 336 String("Preload triggered for " + href.host() + href.path()))); | 336 String("Preload triggered for " + href.host() + href.path()))); |
| 337 } | 337 } |
| 338 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); | 338 linkRequest.setForPreload(true, monotonicallyIncreasingTime()); |
| 339 linkRequest.setLinkPreload(true); | 339 linkRequest.setLinkPreload(true); |
| 340 return document.loader()->startPreload(resourceType, linkRequest); | 340 return document.loader()->startPreload(resourceType, linkRequest); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void LinkLoader::prefetchIfNeeded(Document& document, | |
| 344 const KURL& href, | |
| 345 const LinkRelAttribute& relAttribute, | |
| 346 CrossOriginAttributeValue crossOrigin, | |
| 347 ReferrerPolicy referrerPolicy) { | |
| 348 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) { | |
| 349 UseCounter::count(document, UseCounter::LinkRelPrefetch); | |
| 350 | |
| 351 ResourceRequest resourceRequest(document.completeURL(href)); | |
|
Mike West
2016/11/07 09:52:43
You could avoid creating this intermediate object
Yoav Weiss
2016/11/08 09:23:53
Yeah, slightly simpler I guess. Changed
| |
| 352 if (referrerPolicy != ReferrerPolicyDefault) { | |
| 353 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer( | |
| 354 referrerPolicy, href, document.outgoingReferrer())); | |
| 355 } | |
| 356 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link); | |
| 357 if (crossOrigin != CrossOriginAttributeNotSet) { | |
| 358 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), | |
| 359 crossOrigin); | |
| 360 } | |
| 361 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest, | |
| 362 document.fetcher())); | |
| 363 } | |
| 364 } | |
| 365 | |
| 343 void LinkLoader::loadLinksFromHeader( | 366 void LinkLoader::loadLinksFromHeader( |
| 344 const String& headerValue, | 367 const String& headerValue, |
| 345 const KURL& baseURL, | 368 const KURL& baseURL, |
| 346 Document* document, | 369 Document* document, |
| 347 const NetworkHintsInterface& networkHintsInterface, | 370 const NetworkHintsInterface& networkHintsInterface, |
| 348 CanLoadResources canLoadResources, | 371 CanLoadResources canLoadResources, |
| 349 MediaPreloadPolicy mediaPolicy, | 372 MediaPreloadPolicy mediaPolicy, |
| 350 ViewportDescriptionWrapper* viewportDescriptionWrapper) { | 373 ViewportDescriptionWrapper* viewportDescriptionWrapper) { |
| 351 if (!document || headerValue.isEmpty()) | 374 if (!document || headerValue.isEmpty()) |
| 352 return; | 375 return; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 415 |
| 393 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, | 416 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, |
| 394 CrossOriginAttributeValue crossOrigin, | 417 CrossOriginAttributeValue crossOrigin, |
| 395 const String& type, | 418 const String& type, |
| 396 const String& as, | 419 const String& as, |
| 397 const String& media, | 420 const String& media, |
| 398 ReferrerPolicy referrerPolicy, | 421 ReferrerPolicy referrerPolicy, |
| 399 const KURL& href, | 422 const KURL& href, |
| 400 Document& document, | 423 Document& document, |
| 401 const NetworkHintsInterface& networkHintsInterface) { | 424 const NetworkHintsInterface& networkHintsInterface) { |
| 402 // TODO(yoav): Do all links need to load only after they're in document??? | 425 if (!m_client->shouldLoadLink()) |
| 426 return false; | |
| 403 | 427 |
| 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, | 428 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, |
| 410 LinkCalledFromMarkup); | 429 LinkCalledFromMarkup); |
| 411 | 430 |
| 412 preconnectIfNeeded(relAttribute, href, document, crossOrigin, | 431 preconnectIfNeeded(relAttribute, href, document, crossOrigin, |
| 413 networkHintsInterface, LinkCalledFromMarkup); | 432 networkHintsInterface, LinkCalledFromMarkup); |
| 414 | 433 |
| 415 bool errorOccurred = false; | 434 bool errorOccurred = false; |
| 416 if (m_client->shouldLoadLink()) { | 435 createLinkPreloadResourceClient(preloadIfNeeded( |
| 417 createLinkPreloadResourceClient(preloadIfNeeded( | 436 relAttribute, href, document, as, type, media, crossOrigin, |
| 418 relAttribute, href, document, as, type, media, crossOrigin, | 437 LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy)); |
| 419 LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy)); | |
| 420 } | |
| 421 if (errorOccurred) | 438 if (errorOccurred) |
| 422 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); | 439 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); |
| 423 | 440 |
| 424 if (href.isEmpty() || !href.isValid()) | 441 if (href.isEmpty() || !href.isValid()) |
| 425 released(); | 442 released(); |
| 426 | 443 |
| 427 // FIXME(crbug.com/323096): Should take care of import. | 444 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 | 445 |
| 443 if (const unsigned prerenderRelTypes = | 446 if (const unsigned prerenderRelTypes = |
| 444 prerenderRelTypesFromRelAttribute(relAttribute, document)) { | 447 prerenderRelTypesFromRelAttribute(relAttribute, document)) { |
| 445 if (!m_prerender) { | 448 if (!m_prerender) { |
| 446 m_prerender = | 449 m_prerender = |
| 447 PrerenderHandle::create(document, this, href, prerenderRelTypes); | 450 PrerenderHandle::create(document, this, href, prerenderRelTypes); |
| 448 } else if (m_prerender->url() != href) { | 451 } else if (m_prerender->url() != href) { |
| 449 m_prerender->cancel(); | 452 m_prerender->cancel(); |
| 450 m_prerender = | 453 m_prerender = |
| 451 PrerenderHandle::create(document, this, href, prerenderRelTypes); | 454 PrerenderHandle::create(document, this, href, prerenderRelTypes); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 471 | 474 |
| 472 DEFINE_TRACE(LinkLoader) { | 475 DEFINE_TRACE(LinkLoader) { |
| 473 visitor->trace(m_client); | 476 visitor->trace(m_client); |
| 474 visitor->trace(m_prerender); | 477 visitor->trace(m_prerender); |
| 475 visitor->trace(m_linkPreloadResourceClient); | 478 visitor->trace(m_linkPreloadResourceClient); |
| 476 ResourceOwner<Resource, ResourceClient>::trace(visitor); | 479 ResourceOwner<Resource, ResourceClient>::trace(visitor); |
| 477 PrerenderClient::trace(visitor); | 480 PrerenderClient::trace(visitor); |
| 478 } | 481 } |
| 479 | 482 |
| 480 } // namespace blink | 483 } // namespace blink |
| OLD | NEW |