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

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

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

Powered by Google App Engine
This is Rietveld 408576698