Chromium Code Reviews| 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..e5e4700e7b03f5a02316837e18e683380ce6c82c 100644 |
| --- a/Source/core/html/parser/HTMLPreloadScanner.cpp |
| +++ b/Source/core/html/parser/HTMLPreloadScanner.cpp |
| @@ -29,6 +29,7 @@ |
| #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" |
| @@ -90,10 +91,11 @@ static String initiatorFor(const StringImpl* tagImpl) |
| class TokenPreloadScanner::StartTagScanner { |
| public: |
| - explicit StartTagScanner(const StringImpl* tagImpl) |
| + explicit StartTagScanner(const StringImpl* tagImpl, float deviceScaleFactor = 1.0) |
| : m_tagImpl(tagImpl) |
| , m_linkIsStyleSheet(false) |
| , m_inputIsImage(false) |
| + , m_deviceScaleFactor(deviceScaleFactor) |
| { |
| if (!match(m_tagImpl, imgTag) |
| && !match(m_tagImpl, inputTag) |
| @@ -112,6 +114,12 @@ public: |
| String attributeValue = StringImpl::create8BitIfPossible(iter->value); |
| processAttribute(attributeName, attributeValue); |
| } |
| + |
| + // Resolve between src and srcSet if we have them. |
| + if (!m_srcSetAttribute.isEmpty()) { |
|
do-not-use
2013/09/12 08:23:53
Is it normal the one below is enabled at runtime b
Yoav Weiss
2013/09/12 09:30:20
No, it's not. Good catch! :)
|
| + String srcMatchingScale = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute); |
| + setUrlToLoad(srcMatchingScale, true); |
| + } |
| } |
| void processAttributes(const Vector<CompactHTMLToken::Attribute>& attributes) |
| @@ -120,6 +128,12 @@ public: |
| return; |
| for (Vector<CompactHTMLToken::Attribute>::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) |
| processAttribute(iter->name, iter->value); |
| + |
| + // Resolve between src and srcSet if we have them. |
| + if (RuntimeEnabledFeatures::srcsetEnabled() && !m_srcSetAttribute.isEmpty()) { |
| + String srcMatchingScale = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute); |
| + setUrlToLoad(srcMatchingScale, true); |
| + } |
| } |
| PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL, const SegmentedString& source) |
| @@ -168,13 +182,16 @@ private: |
| return rel.isStyleSheet() && !rel.isAlternate() && rel.iconType() == InvalidIcon && !rel.isDNSPrefetch(); |
| } |
| - void setUrlToLoad(const String& attributeValue) |
| + void setUrlToLoad(const String& value, bool allowReplacement = false) |
| { |
| // 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 (!allowReplacement && !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 +232,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 +325,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 +346,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)) |
| { |
| } |