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

Unified Diff: Source/core/html/parser/HTMLPreloadScanner.cpp

Issue 1152043005: Add <link rel=preconnect> support to the HTMLPreloadScanner (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added HTTP family test Created 5 years, 7 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 | « no previous file | Source/core/html/parser/HTMLPreloadScannerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLPreloadScanner.cpp
diff --git a/Source/core/html/parser/HTMLPreloadScanner.cpp b/Source/core/html/parser/HTMLPreloadScanner.cpp
index ce827eea14930617ef8a4b290dead20664eee27b..198db469d2f222fd40d57dc782932981e65af34f 100644
--- a/Source/core/html/parser/HTMLPreloadScanner.cpp
+++ b/Source/core/html/parser/HTMLPreloadScanner.cpp
@@ -111,6 +111,7 @@ public:
StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValues)
: m_tagImpl(tagImpl)
, m_linkIsStyleSheet(false)
+ , m_linkIsPreconnect(false)
, m_matchedMediaAttribute(true)
, m_inputIsImage(false)
, m_sourceSize(0)
@@ -168,7 +169,10 @@ public:
PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL, const SegmentedString& source, const ClientHintsPreferences& clientHintsPreferences)
{
- if (!shouldPreload() || !m_matchedMediaAttribute)
+ PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePreload;
+ if (shouldPreconnect())
+ requestType = PreloadRequest::RequestTypePreconnect;
+ else if (!shouldPreload() || !m_matchedMediaAttribute)
return nullptr;
TextPosition position = TextPosition(source.currentLine(), source.currentColumn());
@@ -177,7 +181,7 @@ public:
resourceWidth.width = m_sourceSize;
resourceWidth.isSet = true;
}
- OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_tagImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), resourceWidth, clientHintsPreferences);
+ OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_tagImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), resourceWidth, clientHintsPreferences, requestType);
if (isCORSEnabled())
request->setCrossOriginEnabled(allowStoredCredentials());
request->setCharset(charset());
@@ -226,14 +230,17 @@ private:
void processLinkAttribute(const NameType& attributeName, const String& attributeValue)
{
// FIXME - Don't set rel/media/crossorigin multiple times.
- if (match(attributeName, hrefAttr))
+ if (match(attributeName, hrefAttr)) {
setUrlToLoad(attributeValue, DisallowURLReplacement);
- else if (match(attributeName, relAttr))
- m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue);
- else if (match(attributeName, mediaAttr))
+ } else if (match(attributeName, relAttr)) {
+ LinkRelAttribute rel(attributeValue);
+ m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel.iconType() == InvalidIcon && !rel.isDNSPrefetch();
+ m_linkIsPreconnect = rel.isPreconnect();
+ } else if (match(attributeName, mediaAttr)) {
m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attributeValue);
- else if (match(attributeName, crossoriginAttr))
+ } else if (match(attributeName, crossoriginAttr)) {
setCrossOriginAllowed(attributeValue);
+ }
}
template<typename NameType>
@@ -291,12 +298,6 @@ private:
processVideoAttribute(attributeName, attributeValue);
}
- static bool relAttributeIsStyleSheet(const String& attributeValue)
- {
- LinkRelAttribute rel(attributeValue);
- return rel.isStyleSheet() && !rel.isAlternate() && rel.iconType() == InvalidIcon && !rel.isDNSPrefetch();
- }
-
void setUrlToLoad(const String& value, URLReplacement replacement)
{
// We only respect the first src/href, per HTML5:
@@ -325,10 +326,17 @@ private:
return Resource::Image;
if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet)
return Resource::CSSStyleSheet;
+ if (m_linkIsPreconnect)
+ return Resource::Raw;
ASSERT_NOT_REACHED();
return Resource::Raw;
}
+ bool shouldPreconnect() const
+ {
+ return match(m_tagImpl, linkTag) && m_linkIsPreconnect && !m_urlToLoad.isEmpty();
+ }
+
bool shouldPreload() const
{
if (m_urlToLoad.isEmpty())
@@ -374,6 +382,7 @@ private:
ImageCandidate m_srcsetImageCandidate;
String m_charset;
bool m_linkIsStyleSheet;
+ bool m_linkIsPreconnect;
bool m_matchedMediaAttribute;
bool m_inputIsImage;
String m_imgSrcUrl;
« no previous file with comments | « no previous file | Source/core/html/parser/HTMLPreloadScannerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698