Index: Source/core/html/parser/HTMLPreloadScanner.cpp |
diff --git a/Source/core/html/parser/HTMLPreloadScanner.cpp b/Source/core/html/parser/HTMLPreloadScanner.cpp |
index 0b51791a374d39388adc0e23565c850647be29e6..304fe2f375dafaca80859672ac1c157b1e02b989 100644 |
--- a/Source/core/html/parser/HTMLPreloadScanner.cpp |
+++ b/Source/core/html/parser/HTMLPreloadScanner.cpp |
@@ -29,9 +29,11 @@ |
#include "core/html/parser/HTMLPreloadScanner.h" |
#include "HTMLNames.h" |
+#include "RuntimeEnabledFeatures.h" |
#include "core/html/InputTypeNames.h" |
#include "core/html/LinkRelAttribute.h" |
#include "core/html/parser/HTMLParserIdioms.h" |
+#include "core/html/parser/HTMLSrcsetParser.h" |
#include "core/html/parser/HTMLTokenizer.h" |
#include "core/platform/chromium/TraceEvent.h" |
#include "wtf/MainThread.h" |
@@ -90,10 +92,11 @@ static String initiatorFor(const StringImpl* tagImpl) |
class TokenPreloadScanner::StartTagScanner { |
public: |
- explicit StartTagScanner(const StringImpl* tagImpl) |
+ explicit StartTagScanner(const StringImpl* tagImpl, float deviceScaleFactor) |
: m_tagImpl(tagImpl) |
, m_linkIsStyleSheet(false) |
, m_inputIsImage(false) |
+ , m_deviceScaleFactor(deviceScaleFactor) |
{ |
if (!match(m_tagImpl, imgTag) |
&& !match(m_tagImpl, inputTag) |
@@ -102,6 +105,16 @@ public: |
m_tagImpl = 0; |
} |
+ enum URLReplacement { URLReplacementAllow, URLReplacementDisallow }; |
abarth-chromium
2013/09/13 22:24:06
Each of these should be on its own line.
|
+ |
+ |
abarth-chromium
2013/09/13 22:24:06
Please remove this extra blank line.
|
+ void applySrcset() |
+ { |
+ // Resolve between src and srcSet if we have them. |
abarth-chromium
2013/09/13 22:24:06
This "what" comment isn't needed. Please remove i
|
+ if (RuntimeEnabledFeatures::srcsetEnabled() && match(m_tagImpl, imgTag) && !m_srcSetAttribute.isEmpty()) |
+ setUrlToLoad(bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute), URLReplacementAllow); |
+ } |
+ |
void processAttributes(const HTMLToken::AttributeList& attributes) |
{ |
ASSERT(isMainThread()); |
@@ -112,6 +125,8 @@ public: |
String attributeValue = StringImpl::create8BitIfPossible(iter->value); |
processAttribute(attributeName, attributeValue); |
} |
+ |
+ applySrcset(); |
abarth-chromium
2013/09/13 22:24:06
As I wrote before, we don't want to do any srcset
|
} |
void processAttributes(const Vector<CompactHTMLToken::Attribute>& attributes) |
@@ -120,6 +135,8 @@ public: |
return; |
for (Vector<CompactHTMLToken::Attribute>::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) |
processAttribute(iter->name, iter->value); |
+ |
+ applySrcset(); |
} |
PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL, const SegmentedString& source) |
@@ -144,19 +161,22 @@ private: |
if (match(m_tagImpl, scriptTag) || match(m_tagImpl, imgTag)) { |
if (match(attributeName, srcAttr)) |
- setUrlToLoad(attributeValue); |
+ setUrlToLoad(attributeValue, URLReplacementDisallow); |
abarth-chromium
2013/09/13 22:24:06
URLReplacementDisallow -> DisallowURLReplacement
|
else if (match(attributeName, crossoriginAttr) && !attributeValue.isNull()) |
m_crossOriginMode = stripLeadingAndTrailingHTMLSpaces(attributeValue); |
+ else if (match(m_tagImpl, imgTag) && match(attributeName, srcsetAttr)) |
+ m_srcSetAttribute = attributeValue; |
+ |
} else if (match(m_tagImpl, linkTag)) { |
if (match(attributeName, hrefAttr)) |
- setUrlToLoad(attributeValue); |
+ setUrlToLoad(attributeValue, URLReplacementDisallow); |
else if (match(attributeName, relAttr)) |
m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue); |
else if (match(attributeName, mediaAttr)) |
m_mediaAttribute = attributeValue; |
} else if (match(m_tagImpl, inputTag)) { |
if (match(attributeName, srcAttr)) |
- setUrlToLoad(attributeValue); |
+ setUrlToLoad(attributeValue, URLReplacementDisallow); |
else if (match(attributeName, typeAttr)) |
m_inputIsImage = equalIgnoringCase(attributeValue, InputTypeNames::image()); |
} |
@@ -168,13 +188,16 @@ private: |
return rel.isStyleSheet() && !rel.isAlternate() && rel.iconType() == InvalidIcon && !rel.isDNSPrefetch(); |
} |
- void setUrlToLoad(const String& attributeValue) |
+ void setUrlToLoad(const String& value, URLReplacement replacement) |
{ |
// We only respect the first src/href, per HTML5: |
// http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#attribute-name-state |
- if (!m_urlToLoad.isEmpty()) |
+ if (replacement == URLReplacementDisallow && !m_urlToLoad.isEmpty()) |
+ return; |
+ String url = stripLeadingAndTrailingHTMLSpaces(value); |
+ if (url.isEmpty()) |
return; |
- m_urlToLoad = stripLeadingAndTrailingHTMLSpaces(attributeValue); |
+ m_urlToLoad = url; |
} |
const String& charset() const |
@@ -215,16 +238,19 @@ private: |
const StringImpl* m_tagImpl; |
String m_urlToLoad; |
+ String m_srcSetAttribute; |
String m_charset; |
String m_crossOriginMode; |
bool m_linkIsStyleSheet; |
String m_mediaAttribute; |
bool m_inputIsImage; |
+ float m_deviceScaleFactor; |
}; |
-TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL) |
+TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, float deviceScaleFactor) |
: m_documentURL(documentURL) |
, m_inStyle(false) |
+ , m_deviceScaleFactor(deviceScaleFactor) |
, m_templateCount(0) |
{ |
} |
@@ -305,7 +331,7 @@ void TokenPreloadScanner::scanCommon(const Token& token, const SegmentedString& |
return; |
} |
- StartTagScanner scanner(tagImpl); |
+ StartTagScanner scanner(tagImpl, m_deviceScaleFactor); |
scanner.processAttributes(token.attributes()); |
OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predictedBaseElementURL, source); |
if (request) |
@@ -326,8 +352,8 @@ void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) |
m_predictedBaseElementURL = KURL(m_documentURL, stripLeadingAndTrailingHTMLSpaces(hrefAttribute->value)).copy(); |
} |
-HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const KURL& documentURL) |
- : m_scanner(documentURL) |
+HTMLPreloadScanner::HTMLPreloadScanner(const HTMLParserOptions& options, const KURL& documentURL, float deviceScaleFactor) |
+ : m_scanner(documentURL, deviceScaleFactor) |
, m_tokenizer(HTMLTokenizer::create(options)) |
{ |
} |