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

Unified Diff: third_party/WebKit/Source/core/loader/LinkLoader.cpp

Issue 2620993002: Fix HTMLPreloadScanner handling of type in link preload. (Closed)
Patch Set: Review comments Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/loader/LinkLoader.cpp
diff --git a/third_party/WebKit/Source/core/loader/LinkLoader.cpp b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
index 40707b9ad19ed2a9a69d56429e8dfa4d30987ead..9ac9dc539d17c6fe2c53f07727b9c3665345bc3e 100644
--- a/third_party/WebKit/Source/core/loader/LinkLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
@@ -182,27 +182,25 @@ static void preconnectIfNeeded(
}
}
-bool LinkLoader::getResourceTypeFromAsAttribute(const String& as,
- Resource::Type& type) {
+WTF::Optional<Resource::Type> LinkLoader::getResourceTypeFromAsAttribute(
+ const String& as) {
DCHECK_EQ(as.lower(), as);
if (as == "image") {
- type = Resource::Image;
+ return Resource::Image;
} else if (as == "script") {
- type = Resource::Script;
+ return Resource::Script;
} else if (as == "style") {
- type = Resource::CSSStyleSheet;
+ return Resource::CSSStyleSheet;
} else if (as == "media") {
- type = Resource::Media;
+ return Resource::Media;
} else if (as == "font") {
- type = Resource::Font;
+ return Resource::Font;
} else if (as == "track") {
- type = Resource::TextTrack;
- } else {
- type = Resource::Raw;
- if (!as.isEmpty())
- return false;
+ return Resource::TextTrack;
+ } else if (as.isEmpty()) {
+ return Resource::Raw;
}
- return true;
+ return WTF::nullopt;
}
void LinkLoader::createLinkPreloadResourceClient(Resource* resource) {
@@ -300,8 +298,9 @@ static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute,
}
if (caller == LinkCalledFromHeader)
UseCounter::count(document, UseCounter::LinkHeaderPreload);
- Resource::Type resourceType;
- if (!LinkLoader::getResourceTypeFromAsAttribute(as, resourceType)) {
+ Optional<Resource::Type> resourceType =
+ LinkLoader::getResourceTypeFromAsAttribute(as);
+ if (resourceType == WTF::nullopt) {
document.addConsoleMessage(ConsoleMessage::create(
OtherMessageSource, WarningMessageLevel,
String("<link rel=preload> must have a valid `as` value")));
@@ -309,15 +308,15 @@ static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute,
return nullptr;
}
- if (!isSupportedType(resourceType, mimeType)) {
+ if (!isSupportedType(resourceType.value(), mimeType)) {
document.addConsoleMessage(ConsoleMessage::create(
OtherMessageSource, WarningMessageLevel,
String("<link rel=preload> has an unsupported `type` value")));
return nullptr;
}
ResourceRequest resourceRequest(document.completeURL(href));
- ResourceFetcher::determineRequestContext(resourceRequest, resourceType,
- false);
+ ResourceFetcher::determineRequestContext(resourceRequest,
+ resourceType.value(), false);
if (referrerPolicy != ReferrerPolicyDefault) {
resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(
@@ -339,7 +338,7 @@ static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute,
}
linkRequest.setForPreload(true, monotonicallyIncreasingTime());
linkRequest.setLinkPreload(true);
- return document.loader()->startPreload(resourceType, linkRequest);
+ return document.loader()->startPreload(resourceType.value(), linkRequest);
}
static Resource* prefetchIfNeeded(Document& document,
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698