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

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

Issue 2903653005: [preload] Mandatory `as` value and related spec alignments (Closed)
Patch Set: IDL changes Created 3 years, 6 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } else if (as == "style") { 219 } else if (as == "style") {
220 return Resource::kCSSStyleSheet; 220 return Resource::kCSSStyleSheet;
221 } else if (as == "video") { 221 } else if (as == "video") {
222 return Resource::kMedia; 222 return Resource::kMedia;
223 } else if (as == "audio") { 223 } else if (as == "audio") {
224 return Resource::kMedia; 224 return Resource::kMedia;
225 } else if (as == "track") { 225 } else if (as == "track") {
226 return Resource::kTextTrack; 226 return Resource::kTextTrack;
227 } else if (as == "font") { 227 } else if (as == "font") {
228 return Resource::kFont; 228 return Resource::kFont;
229 } else if (as.IsEmpty()) { 229 } else if (as == "fetch") {
230 return Resource::kRaw; 230 return Resource::kRaw;
231 } 231 }
232 return WTF::nullopt; 232 return WTF::nullopt;
233 } 233 }
234 234
235 Resource* LinkLoader::LinkPreloadedResourceForTesting() { 235 Resource* LinkLoader::LinkPreloadedResourceForTesting() {
236 return link_preload_resource_client_ 236 return link_preload_resource_client_
237 ? link_preload_resource_client_->GetResource() 237 ? link_preload_resource_client_->GetResource()
238 : nullptr; 238 : nullptr;
239 } 239 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 295 }
296 296
297 static Resource* PreloadIfNeeded(const LinkRelAttribute& rel_attribute, 297 static Resource* PreloadIfNeeded(const LinkRelAttribute& rel_attribute,
298 const KURL& href, 298 const KURL& href,
299 Document& document, 299 Document& document,
300 const String& as, 300 const String& as,
301 const String& mime_type, 301 const String& mime_type,
302 const String& media, 302 const String& media,
303 CrossOriginAttributeValue cross_origin, 303 CrossOriginAttributeValue cross_origin,
304 LinkCaller caller, 304 LinkCaller caller,
305 bool& error_occurred,
306 ViewportDescription* viewport_description, 305 ViewportDescription* viewport_description,
307 ReferrerPolicy referrer_policy) { 306 ReferrerPolicy referrer_policy) {
308 if (!document.Loader() || !rel_attribute.IsLinkPreload()) 307 if (!document.Loader() || !rel_attribute.IsLinkPreload())
309 return nullptr; 308 return nullptr;
310 309
311 UseCounter::Count(document, UseCounter::kLinkRelPreload); 310 UseCounter::Count(document, UseCounter::kLinkRelPreload);
312 if (!href.IsValid() || href.IsEmpty()) { 311 if (!href.IsValid() || href.IsEmpty()) {
313 document.AddConsoleMessage(ConsoleMessage::Create( 312 document.AddConsoleMessage(ConsoleMessage::Create(
314 kOtherMessageSource, kWarningMessageLevel, 313 kOtherMessageSource, kWarningMessageLevel,
315 String("<link rel=preload> has an invalid `href` value"))); 314 String("<link rel=preload> has an invalid `href` value")));
(...skipping 16 matching lines...) Expand all
332 return nullptr; 331 return nullptr;
333 } 332 }
334 if (caller == kLinkCalledFromHeader) 333 if (caller == kLinkCalledFromHeader)
335 UseCounter::Count(document, UseCounter::kLinkHeaderPreload); 334 UseCounter::Count(document, UseCounter::kLinkHeaderPreload);
336 Optional<Resource::Type> resource_type = 335 Optional<Resource::Type> resource_type =
337 LinkLoader::GetResourceTypeFromAsAttribute(as); 336 LinkLoader::GetResourceTypeFromAsAttribute(as);
338 if (resource_type == WTF::nullopt) { 337 if (resource_type == WTF::nullopt) {
339 document.AddConsoleMessage(ConsoleMessage::Create( 338 document.AddConsoleMessage(ConsoleMessage::Create(
340 kOtherMessageSource, kWarningMessageLevel, 339 kOtherMessageSource, kWarningMessageLevel,
341 String("<link rel=preload> must have a valid `as` value"))); 340 String("<link rel=preload> must have a valid `as` value")));
342 error_occurred = true;
343 return nullptr; 341 return nullptr;
344 } 342 }
345 343
346 if (!IsSupportedType(resource_type.value(), mime_type)) { 344 if (!IsSupportedType(resource_type.value(), mime_type)) {
347 document.AddConsoleMessage(ConsoleMessage::Create( 345 document.AddConsoleMessage(ConsoleMessage::Create(
348 kOtherMessageSource, kWarningMessageLevel, 346 kOtherMessageSource, kWarningMessageLevel,
349 String("<link rel=preload> has an unsupported `type` value"))); 347 String("<link rel=preload> has an unsupported `type` value")));
350 return nullptr; 348 return nullptr;
351 } 349 }
352 ResourceRequest resource_request(document.CompleteURL(href)); 350 ResourceRequest resource_request(document.CompleteURL(href));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (can_load_resources != kOnlyLoadResources) { 429 if (can_load_resources != kOnlyLoadResources) {
432 DnsPrefetchIfNeeded(rel_attribute, url, document, &frame, 430 DnsPrefetchIfNeeded(rel_attribute, url, document, &frame,
433 network_hints_interface, kLinkCalledFromHeader); 431 network_hints_interface, kLinkCalledFromHeader);
434 432
435 PreconnectIfNeeded(rel_attribute, url, document, &frame, 433 PreconnectIfNeeded(rel_attribute, url, document, &frame,
436 GetCrossOriginAttributeValue(header.CrossOrigin()), 434 GetCrossOriginAttributeValue(header.CrossOrigin()),
437 network_hints_interface, kLinkCalledFromHeader); 435 network_hints_interface, kLinkCalledFromHeader);
438 } 436 }
439 if (can_load_resources != kDoNotLoadResources) { 437 if (can_load_resources != kDoNotLoadResources) {
440 DCHECK(document); 438 DCHECK(document);
441 bool error_occurred = false;
442 ViewportDescription* viewport_description = 439 ViewportDescription* viewport_description =
443 (viewport_description_wrapper && viewport_description_wrapper->set) 440 (viewport_description_wrapper && viewport_description_wrapper->set)
444 ? &(viewport_description_wrapper->description) 441 ? &(viewport_description_wrapper->description)
445 : nullptr; 442 : nullptr;
446 443
447 CrossOriginAttributeValue cross_origin = 444 CrossOriginAttributeValue cross_origin =
448 GetCrossOriginAttributeValue(header.CrossOrigin()); 445 GetCrossOriginAttributeValue(header.CrossOrigin());
449 PreloadIfNeeded(rel_attribute, url, *document, header.As(), 446 PreloadIfNeeded(rel_attribute, url, *document, header.As(),
450 header.MimeType(), header.Media(), cross_origin, 447 header.MimeType(), header.Media(), cross_origin,
451 kLinkCalledFromHeader, error_occurred, 448 kLinkCalledFromHeader, viewport_description,
452 viewport_description, kReferrerPolicyDefault); 449 kReferrerPolicyDefault);
453 PrefetchIfNeeded(*document, url, rel_attribute, cross_origin, 450 PrefetchIfNeeded(*document, url, rel_attribute, cross_origin,
454 kReferrerPolicyDefault); 451 kReferrerPolicyDefault);
455 } 452 }
456 if (rel_attribute.IsServiceWorker()) { 453 if (rel_attribute.IsServiceWorker()) {
457 UseCounter::Count(&frame, UseCounter::kLinkHeaderServiceWorker); 454 UseCounter::Count(&frame, UseCounter::kLinkHeaderServiceWorker);
458 } 455 }
459 // TODO(yoav): Add more supported headers as needed. 456 // TODO(yoav): Add more supported headers as needed.
460 } 457 }
461 } 458 }
462 459
(...skipping 10 matching lines...) Expand all
473 if (!client_->ShouldLoadLink()) 470 if (!client_->ShouldLoadLink())
474 return false; 471 return false;
475 472
476 DnsPrefetchIfNeeded(rel_attribute, href, &document, document.GetFrame(), 473 DnsPrefetchIfNeeded(rel_attribute, href, &document, document.GetFrame(),
477 network_hints_interface, kLinkCalledFromMarkup); 474 network_hints_interface, kLinkCalledFromMarkup);
478 475
479 PreconnectIfNeeded(rel_attribute, href, &document, document.GetFrame(), 476 PreconnectIfNeeded(rel_attribute, href, &document, document.GetFrame(),
480 cross_origin, network_hints_interface, 477 cross_origin, network_hints_interface,
481 kLinkCalledFromMarkup); 478 kLinkCalledFromMarkup);
482 479
483 bool error_occurred = false;
484 CreateLinkPreloadResourceClient(PreloadIfNeeded( 480 CreateLinkPreloadResourceClient(PreloadIfNeeded(
485 rel_attribute, href, document, as, type, media, cross_origin, 481 rel_attribute, href, document, as, type, media, cross_origin,
486 kLinkCalledFromMarkup, error_occurred, nullptr, referrer_policy)); 482 kLinkCalledFromMarkup, nullptr, referrer_policy));
487 if (error_occurred)
488 link_loading_error_timer_.StartOneShot(0, BLINK_FROM_HERE);
489 483
490 if (href.IsEmpty() || !href.IsValid()) 484 if (href.IsEmpty() || !href.IsValid())
491 Released(); 485 Released();
492 486
493 Resource* resource = PrefetchIfNeeded(document, href, rel_attribute, 487 Resource* resource = PrefetchIfNeeded(document, href, rel_attribute,
494 cross_origin, referrer_policy); 488 cross_origin, referrer_policy);
495 if (resource) 489 if (resource)
496 SetResource(resource); 490 SetResource(resource);
497 491
498 if (const unsigned prerender_rel_types = 492 if (const unsigned prerender_rel_types =
(...skipping 27 matching lines...) Expand all
526 520
527 DEFINE_TRACE(LinkLoader) { 521 DEFINE_TRACE(LinkLoader) {
528 visitor->Trace(client_); 522 visitor->Trace(client_);
529 visitor->Trace(prerender_); 523 visitor->Trace(prerender_);
530 visitor->Trace(link_preload_resource_client_); 524 visitor->Trace(link_preload_resource_client_);
531 ResourceOwner<Resource, ResourceClient>::Trace(visitor); 525 ResourceOwner<Resource, ResourceClient>::Trace(visitor);
532 PrerenderClient::Trace(visitor); 526 PrerenderClient::Trace(visitor);
533 } 527 }
534 528
535 } // namespace blink 529 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698