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

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

Issue 2424943002: Add ReferrerPolicy support to preload (Closed)
Patch Set: Created 4 years, 2 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
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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 260
261 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, 261 static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute,
262 const KURL& href, 262 const KURL& href,
263 Document& document, 263 Document& document,
264 const String& as, 264 const String& as,
265 const String& mimeType, 265 const String& mimeType,
266 const String& media, 266 const String& media,
267 CrossOriginAttributeValue crossOrigin, 267 CrossOriginAttributeValue crossOrigin,
268 LinkCaller caller, 268 LinkCaller caller,
269 bool& errorOccurred, 269 bool& errorOccurred,
270 ViewportDescription* viewportDescription) { 270 ViewportDescription* viewportDescription,
271 ReferrerPolicy referrerPolicy) {
271 if (!document.loader() || !relAttribute.isLinkPreload()) 272 if (!document.loader() || !relAttribute.isLinkPreload())
272 return nullptr; 273 return nullptr;
273 274
274 UseCounter::count(document, UseCounter::LinkRelPreload); 275 UseCounter::count(document, UseCounter::LinkRelPreload);
275 if (!href.isValid() || href.isEmpty()) { 276 if (!href.isValid() || href.isEmpty()) {
276 document.addConsoleMessage(ConsoleMessage::create( 277 document.addConsoleMessage(ConsoleMessage::create(
277 OtherMessageSource, WarningMessageLevel, 278 OtherMessageSource, WarningMessageLevel,
278 String("<link rel=preload> has an invalid `href` value"))); 279 String("<link rel=preload> has an invalid `href` value")));
279 return nullptr; 280 return nullptr;
280 } 281 }
(...skipping 25 matching lines...) Expand all
306 307
307 if (!isSupportedType(resourceType, mimeType)) { 308 if (!isSupportedType(resourceType, mimeType)) {
308 document.addConsoleMessage(ConsoleMessage::create( 309 document.addConsoleMessage(ConsoleMessage::create(
309 OtherMessageSource, WarningMessageLevel, 310 OtherMessageSource, WarningMessageLevel,
310 String("<link rel=preload> has an unsupported `type` value"))); 311 String("<link rel=preload> has an unsupported `type` value")));
311 return nullptr; 312 return nullptr;
312 } 313 }
313 ResourceRequest resourceRequest(document.completeURL(href)); 314 ResourceRequest resourceRequest(document.completeURL(href));
314 ResourceFetcher::determineRequestContext(resourceRequest, resourceType, 315 ResourceFetcher::determineRequestContext(resourceRequest, resourceType,
315 false); 316 false);
317
318 if (referrerPolicy != ReferrerPolicyDefault) {
319 resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(
320 referrerPolicy, href, document.outgoingReferrer()));
321 }
322
316 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link, 323 FetchRequest linkRequest(resourceRequest, FetchInitiatorTypeNames::link,
317 document.encodingName()); 324 document.encodingName());
318 325
319 if (crossOrigin != CrossOriginAttributeNotSet) 326 if (crossOrigin != CrossOriginAttributeNotSet)
320 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), 327 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
321 crossOrigin); 328 crossOrigin);
322 Settings* settings = document.settings(); 329 Settings* settings = document.settings();
323 if (settings && settings->logPreload()) 330 if (settings && settings->logPreload())
324 document.addConsoleMessage(ConsoleMessage::create( 331 document.addConsoleMessage(ConsoleMessage::create(
325 OtherMessageSource, DebugMessageLevel, 332 OtherMessageSource, DebugMessageLevel,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 preconnectIfNeeded(relAttribute, url, *document, 368 preconnectIfNeeded(relAttribute, url, *document,
362 crossOriginAttributeValue(header.crossOrigin()), 369 crossOriginAttributeValue(header.crossOrigin()),
363 networkHintsInterface, LinkCalledFromHeader); 370 networkHintsInterface, LinkCalledFromHeader);
364 } 371 }
365 if (canLoadResources != DoNotLoadResources) { 372 if (canLoadResources != DoNotLoadResources) {
366 bool errorOccurred = false; 373 bool errorOccurred = false;
367 ViewportDescription* viewportDescription = 374 ViewportDescription* viewportDescription =
368 (viewportDescriptionWrapper && viewportDescriptionWrapper->set) 375 (viewportDescriptionWrapper && viewportDescriptionWrapper->set)
369 ? &(viewportDescriptionWrapper->description) 376 ? &(viewportDescriptionWrapper->description)
370 : nullptr; 377 : nullptr;
378
379 ReferrerPolicy referrerPolicy = ReferrerPolicyDefault;
380 if (!header.referrerPolicy().isNull()) {
381 SecurityPolicy::referrerPolicyFromStringWithLegacyKeywords(
382 header.referrerPolicy(), &referrerPolicy);
383 }
384
371 preloadIfNeeded(relAttribute, url, *document, header.as(), 385 preloadIfNeeded(relAttribute, url, *document, header.as(),
372 header.mimeType(), header.media(), 386 header.mimeType(), header.media(),
373 crossOriginAttributeValue(header.crossOrigin()), 387 crossOriginAttributeValue(header.crossOrigin()),
374 LinkCalledFromHeader, errorOccurred, viewportDescription); 388 LinkCalledFromHeader, errorOccurred, viewportDescription,
389 referrerPolicy);
375 } 390 }
376 // TODO(yoav): Add more supported headers as needed. 391 // TODO(yoav): Add more supported headers as needed.
377 } 392 }
378 } 393 }
379 394
380 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, 395 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute,
381 CrossOriginAttributeValue crossOrigin, 396 CrossOriginAttributeValue crossOrigin,
382 const String& type, 397 const String& type,
383 const String& as, 398 const String& as,
384 const String& media, 399 const String& media,
400 const String& referrerPolicy,
385 const KURL& href, 401 const KURL& href,
386 Document& document, 402 Document& document,
387 const NetworkHintsInterface& networkHintsInterface) { 403 const NetworkHintsInterface& networkHintsInterface) {
388 // TODO(yoav): Do all links need to load only after they're in document??? 404 // TODO(yoav): Do all links need to load only after they're in document???
389 405
390 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAttr ibuteValue. crbug.com/486689 406 // TODO(yoav): Convert all uses of the CrossOriginAttribute to CrossOriginAttr ibuteValue. crbug.com/486689
391 // FIXME(crbug.com/463266): We're ignoring type here, for everything but prelo ad. Maybe we shouldn't. 407 // FIXME(crbug.com/463266): We're ignoring type here, for everything but prelo ad. Maybe we shouldn't.
392 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface, 408 dnsPrefetchIfNeeded(relAttribute, href, document, networkHintsInterface,
393 LinkCalledFromMarkup); 409 LinkCalledFromMarkup);
394 410
395 preconnectIfNeeded(relAttribute, href, document, crossOrigin, 411 preconnectIfNeeded(relAttribute, href, document, crossOrigin,
396 networkHintsInterface, LinkCalledFromMarkup); 412 networkHintsInterface, LinkCalledFromMarkup);
397 413
398 bool errorOccurred = false; 414 bool errorOccurred = false;
399 if (m_client->shouldLoadLink()) 415 if (m_client->shouldLoadLink()) {
400 createLinkPreloadResourceClient(preloadIfNeeded( 416 createLinkPreloadResourceClient(preloadIfNeeded(
401 relAttribute, href, document, as, type, media, crossOrigin, 417 relAttribute, href, document, as, type, media, crossOrigin,
402 LinkCalledFromMarkup, errorOccurred, nullptr)); 418 LinkCalledFromMarkup, errorOccurred, nullptr, ReferrerPolicyDefault));
estark 2016/10/18 04:55:54 This should be `referrerPolicy` instead of `Referr
Yoav Weiss 2016/10/20 23:01:37 yes and yes. (and now that the tests have an expec
419 }
403 if (errorOccurred) 420 if (errorOccurred)
404 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE); 421 m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE);
405 422
406 if (href.isEmpty() || !href.isValid()) 423 if (href.isEmpty() || !href.isValid())
407 released(); 424 released();
408 425
409 // FIXME(crbug.com/323096): Should take care of import. 426 // FIXME(crbug.com/323096): Should take care of import.
410 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) { 427 if (relAttribute.isLinkPrefetch() && href.isValid() && document.frame()) {
411 if (!m_client->shouldLoadLink()) 428 if (!m_client->shouldLoadLink())
412 return false; 429 return false;
413 UseCounter::count(document, UseCounter::LinkRelPrefetch); 430 UseCounter::count(document, UseCounter::LinkRelPrefetch);
414 431
415 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), 432 FetchRequest linkRequest(ResourceRequest(document.completeURL(href)),
estark 2016/10/18 04:55:54 Presumably we also want to set a referrer policy o
416 FetchInitiatorTypeNames::link); 433 FetchInitiatorTypeNames::link);
417 if (crossOrigin != CrossOriginAttributeNotSet) 434 if (crossOrigin != CrossOriginAttributeNotSet)
418 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(), 435 linkRequest.setCrossOriginAccessControl(document.getSecurityOrigin(),
419 crossOrigin); 436 crossOrigin);
420 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest, 437 setResource(LinkFetchResource::fetch(Resource::LinkPrefetch, linkRequest,
421 document.fetcher())); 438 document.fetcher()));
422 } 439 }
423 440
424 if (const unsigned prerenderRelTypes = 441 if (const unsigned prerenderRelTypes =
425 prerenderRelTypesFromRelAttribute(relAttribute, document)) { 442 prerenderRelTypesFromRelAttribute(relAttribute, document)) {
(...skipping 26 matching lines...) Expand all
452 469
453 DEFINE_TRACE(LinkLoader) { 470 DEFINE_TRACE(LinkLoader) {
454 visitor->trace(m_client); 471 visitor->trace(m_client);
455 visitor->trace(m_prerender); 472 visitor->trace(m_prerender);
456 visitor->trace(m_linkPreloadResourceClient); 473 visitor->trace(m_linkPreloadResourceClient);
457 ResourceOwner<Resource, ResourceClient>::trace(visitor); 474 ResourceOwner<Resource, ResourceClient>::trace(visitor);
458 PrerenderClient::trace(visitor); 475 PrerenderClient::trace(visitor);
459 } 476 }
460 477
461 } // namespace blink 478 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698