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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, | 262 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, |
263 const KURL& href, | 263 const KURL& href, |
264 Document& document, | 264 Document& document, |
265 const String& as, | 265 const String& as, |
266 const String& mimeType, | 266 const String& mimeType, |
267 const String& media, | 267 const String& media, |
268 CrossOriginAttributeValue crossOrigin, | 268 CrossOriginAttributeValue crossOrigin, |
269 LinkCaller caller, | 269 LinkCaller caller, |
270 bool& errorOccurred, | 270 bool& errorOccurred, |
271 ViewportDescription* viewportDescription) { | 271 ViewportDescription* viewportDescription, |
| 272 ReferrerPolicy referrerPolicy) { |
272 if (!document.loader() || !relAttribute.isLinkPreload()) | 273 if (!document.loader() || !relAttribute.isLinkPreload()) |
273 return nullptr; | 274 return nullptr; |
274 | 275 |
275 UseCounter::count(document, UseCounter::LinkRelPreload); | 276 UseCounter::count(document, UseCounter::LinkRelPreload); |
276 if (!href.isValid() || href.isEmpty()) { | 277 if (!href.isValid() || href.isEmpty()) { |
277 document.addConsoleMessage(ConsoleMessage::create( | 278 document.addConsoleMessage(ConsoleMessage::create( |
278 OtherMessageSource, WarningMessageLevel, | 279 OtherMessageSource, WarningMessageLevel, |
279 String("<link rel=preload> has an invalid `href` value"))); | 280 String("<link rel=preload> has an invalid `href` value"))); |
280 return nullptr; | 281 return nullptr; |
281 } | 282 } |
(...skipping 26 matching lines...) Expand all Loading... |
308 | 309 |
309 if (!isSupportedType(resourceType, mimeType)) { | 310 if (!isSupportedType(resourceType, mimeType)) { |
310 document.addConsoleMessage(ConsoleMessage::create( | 311 document.addConsoleMessage(ConsoleMessage::create( |
311 OtherMessageSource, WarningMessageLevel, | 312 OtherMessageSource, WarningMessageLevel, |
312 String("<link rel=preload> has an unsupported `type` value"))); | 313 String("<link rel=preload> has an unsupported `type` value"))); |
313 return nullptr; | 314 return nullptr; |
314 } | 315 } |
315 ResourceRequest resourceRequest(document.completeURL(href)); | 316 ResourceRequest resourceRequest(document.completeURL(href)); |
316 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, | 317 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, |
317 false); | 318 false); |
| 319 |
| 320 if (referrerPolicy != ReferrerPolicyDefault) { |
| 321 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer( |
| 322 referrerPolicy, href, document.outgoingReferrer())); |
| 323 } |
| 324 |
318 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, | 325 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, |
319 document.encodingName()); | 326 document.encodingName()); |
320 | 327 |
321 if (crossOrigin != CrossOriginAttributeNotSet) { | 328 if (crossOrigin != CrossOriginAttributeNotSet) { |
322 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), | 329 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), |
323 crossOrigin); | 330 crossOrigin); |
324 } | 331 } |
325 Settings* settings = document.settings(); | 332 Settings* settings = document.settings(); |
326 if (settings && settings->logPreload()) { | 333 if (settings && settings->logPreload()) { |
327 document.addConsoleMessage(ConsoleMessage::create( | 334 document.addConsoleMessage(ConsoleMessage::create( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 preconnectIfNeeded(relAttribute, url, *document, | 372 preconnectIfNeeded(relAttribute, url, *document, |
366 crossOriginAttributeValue(header.crossOrigin()), | 373 crossOriginAttributeValue(header.crossOrigin()), |
367 networkHintsInterface, LinkCalledFromHeader); | 374 networkHintsInterface, LinkCalledFromHeader); |
368 } | 375 } |
369 if (canLoadResources != DoNotLoadResources) { | 376 if (canLoadResources != DoNotLoadResources) { |
370 bool errorOccurred = false; | 377 bool errorOccurred = false; |
371 ViewportDescription* viewportDescription = | 378 ViewportDescription* viewportDescription = |
372 (viewportDescriptionWrapper && viewportDescriptionWrapper->set) | 379 (viewportDescriptionWrapper && viewportDescriptionWrapper->set) |
373 ? &(viewportDescriptionWrapper->description) | 380 ? &(viewportDescriptionWrapper->description) |
374 : nullptr; | 381 : nullptr; |
| 382 |
375 preloadIfNeeded(relAttribute, url, *document, header.as(), | 383 preloadIfNeeded(relAttribute, url, *document, header.as(), |
376 header.mimeType(), header.media(), | 384 header.mimeType(), header.media(), |
377 crossOriginAttributeValue(header.crossOrigin()), | 385 crossOriginAttributeValue(header.crossOrigin()), |
378 LinkCalledFromHeader, errorOccurred, viewportDescription); | 386 LinkCalledFromHeader, errorOccurred, viewportDescription, |
| 387 ReferrerPolicyDefault); |
379 } | 388 } |
380 // TODO(yoav): Add more supported headers as needed. | 389 // TODO(yoav): Add more supported headers as needed. |
381 } | 390 } |
382 } | 391 } |
383 | 392 |
384 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, | 393 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, |
385 CrossOriginAttributeValue crossOrigin, | 394 CrossOriginAttributeValue crossOrigin, |
386 const String& type, | 395 const String& type, |
387 const String& as, | 396 const String& as, |
388 const String& media, | 397 const String& media, |
| 398 ReferrerPolicy referrerPolicy, |
389 const KURL& href, | 399 const KURL& href, |
390 Document& document, | 400 Document& document, |
391 const NetworkHintsInterface& networkHintsInterface) { | 401 const NetworkHintsInterface& networkHintsInterface) { |
392 // TODO(yoav): Do all links need to load only after they're in document??? | 402 // TODO(yoav): Do all links need to load only after they're in document??? |
393 | 403 |
394 // TODO(yoav): Convert all uses of the CrossOriginAttribute to | 404 // TODO(yoav): Convert all uses of the CrossOriginAttribute to |
395 // CrossOriginAttributeValue. crbug.com/486689 | 405 // CrossOriginAttributeValue. crbug.com/486689 |
396 | 406 |
397 // FIXME(crbug.com/463266): We're ignoring type here, for everything but | 407 // FIXME(crbug.com/463266): We're ignoring type here, for everything but |
398 // preload. Maybe we shouldn't. | 408 // preload. Maybe we shouldn't. |
399 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, | 409 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, |
400 LinkCalledFromMarkup); | 410 LinkCalledFromMarkup); |
401 | 411 |
402 preconnectIfNeeded(relAttribute, href, document, crossOrigin, | 412 preconnectIfNeeded(relAttribute, href, document, crossOrigin, |
403 networkHintsInterface, LinkCalledFromMarkup); | 413 networkHintsInterface, LinkCalledFromMarkup); |
404 | 414 |
405 bool errorOccurred = false; | 415 bool errorOccurred = false; |
406 if (m_client->shouldLoadLink()) { | 416 if (m_client->shouldLoadLink()) { |
407 createLinkPreloadResourceClient(preloadIfNeeded( | 417 createLinkPreloadResourceClient(preloadIfNeeded( |
408 relAttribute, href, document, as, type, media, crossOrigin, | 418 relAttribute, href, document, as, type, media, crossOrigin, |
409 LinkCalledFromMarkup, errorOccurred, nullptr)); | 419 LinkCalledFromMarkup, errorOccurred, nullptr, referrerPolicy)); |
410 } | 420 } |
411 if (errorOccurred) | 421 if (errorOccurred) |
412 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); | 422 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); |
413 | 423 |
414 if (href.isEmpty() || !href.isValid()) | 424 if (href.isEmpty() || !href.isValid()) |
415 released(); | 425 released(); |
416 | 426 |
417 // FIXME(crbug.com/323096): Should take care of import. | 427 // FIXME(crbug.com/323096): Should take care of import. |
418 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) { | 428 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) { |
419 if (!m_client->shouldLoadLink()) | 429 if (!m_client->shouldLoadLink()) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 471 |
462 DEFINE_TRACE(LinkLoader) { | 472 DEFINE_TRACE(LinkLoader) { |
463 visitor->trace(m_client); | 473 visitor->trace(m_client); |
464 visitor->trace(m_prerender); | 474 visitor->trace(m_prerender); |
465 visitor->trace(m_linkPreloadResourceClient); | 475 visitor->trace(m_linkPreloadResourceClient); |
466 ResourceOwner<Resource, ResourceClient>::trace(visitor); | 476 ResourceOwner<Resource, ResourceClient>::trace(visitor); |
467 PrerenderClient::trace(visitor); | 477 PrerenderClient::trace(visitor); |
468 } | 478 } |
469 | 479 |
470 } // namespace blink | 480 } // namespace blink |
OLD | NEW |