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

Side by Side Diff: Source/core/html/parser/HTMLPreloadScanner.cpp

Issue 236713005: Use SizesAttributeParser to get the right srcset resource (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sizes_parser8
Patch Set: Rebase Created 6 years, 8 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/
4 * Copyright (C) 2010 Google Inc. All Rights Reserved. 4 * Copyright (C) 2010 Google Inc. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 16 matching lines...) Expand all
27 27
28 #include "config.h" 28 #include "config.h"
29 #include "core/html/parser/HTMLPreloadScanner.h" 29 #include "core/html/parser/HTMLPreloadScanner.h"
30 30
31 #include "HTMLNames.h" 31 #include "HTMLNames.h"
32 #include "InputTypeNames.h" 32 #include "InputTypeNames.h"
33 #include "RuntimeEnabledFeatures.h" 33 #include "RuntimeEnabledFeatures.h"
34 #include "core/css/MediaList.h" 34 #include "core/css/MediaList.h"
35 #include "core/css/MediaQueryEvaluator.h" 35 #include "core/css/MediaQueryEvaluator.h"
36 #include "core/css/MediaValues.h" 36 #include "core/css/MediaValues.h"
37 #include "core/css/parser/SizesAttributeParser.h"
37 #include "core/html/LinkRelAttribute.h" 38 #include "core/html/LinkRelAttribute.h"
38 #include "core/html/parser/HTMLParserIdioms.h" 39 #include "core/html/parser/HTMLParserIdioms.h"
39 #include "core/html/parser/HTMLSrcsetParser.h" 40 #include "core/html/parser/HTMLSrcsetParser.h"
40 #include "core/html/parser/HTMLTokenizer.h" 41 #include "core/html/parser/HTMLTokenizer.h"
41 #include "platform/TraceEvent.h" 42 #include "platform/TraceEvent.h"
42 #include "wtf/MainThread.h" 43 #include "wtf/MainThread.h"
43 44
44 namespace WebCore { 45 namespace WebCore {
45 46
46 using namespace HTMLNames; 47 using namespace HTMLNames;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return mediaQueryEvaluator.eval(mediaQueries.get()); 101 return mediaQueryEvaluator.eval(mediaQueries.get());
101 } 102 }
102 103
103 class TokenPreloadScanner::StartTagScanner { 104 class TokenPreloadScanner::StartTagScanner {
104 public: 105 public:
105 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu es) 106 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu es)
106 : m_tagImpl(tagImpl) 107 : m_tagImpl(tagImpl)
107 , m_linkIsStyleSheet(false) 108 , m_linkIsStyleSheet(false)
108 , m_matchedMediaAttribute(true) 109 , m_matchedMediaAttribute(true)
109 , m_inputIsImage(false) 110 , m_inputIsImage(false)
110 , m_encounteredImgSrc(false) 111 , m_imgSourceSize(0)
111 , m_isCORSEnabled(false) 112 , m_isCORSEnabled(false)
112 , m_allowCredentials(DoNotAllowStoredCredentials) 113 , m_allowCredentials(DoNotAllowStoredCredentials)
113 , m_mediaValues(mediaValues) 114 , m_mediaValues(mediaValues)
114 { 115 {
115 if (!match(m_tagImpl, imgTag) 116 if (!match(m_tagImpl, imgTag)
116 && !match(m_tagImpl, inputTag) 117 && !match(m_tagImpl, inputTag)
117 && !match(m_tagImpl, linkTag) 118 && !match(m_tagImpl, linkTag)
118 && !match(m_tagImpl, scriptTag)) 119 && !match(m_tagImpl, scriptTag))
119 m_tagImpl = 0; 120 m_tagImpl = 0;
121 if (RuntimeEnabledFeatures::pictureSizesEnabled())
122 m_imgSourceSize = SizesAttributeParser::findEffectiveSize(String(), m_mediaValues);
120 } 123 }
121 124
122 enum URLReplacement { 125 enum URLReplacement {
123 AllowURLReplacement, 126 AllowURLReplacement,
124 DisallowURLReplacement 127 DisallowURLReplacement
125 }; 128 };
126 129
127 void processAttributes(const HTMLToken::AttributeList& attributes) 130 void processAttributes(const HTMLToken::AttributeList& attributes)
128 { 131 {
129 ASSERT(isMainThread()); 132 ASSERT(isMainThread());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 { 167 {
165 if (match(attributeName, charsetAttr)) 168 if (match(attributeName, charsetAttr))
166 m_charset = attributeValue; 169 m_charset = attributeValue;
167 170
168 if (match(m_tagImpl, scriptTag)) { 171 if (match(m_tagImpl, scriptTag)) {
169 if (match(attributeName, srcAttr)) 172 if (match(attributeName, srcAttr))
170 setUrlToLoad(attributeValue, DisallowURLReplacement); 173 setUrlToLoad(attributeValue, DisallowURLReplacement);
171 else if (match(attributeName, crossoriginAttr)) 174 else if (match(attributeName, crossoriginAttr))
172 setCrossOriginAllowed(attributeValue); 175 setCrossOriginAllowed(attributeValue);
173 } else if (match(m_tagImpl, imgTag)) { 176 } else if (match(m_tagImpl, imgTag)) {
174 int effectiveSize = -1; // FIXME - hook up the real value from `size s` 177 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) {
175 if (match(attributeName, srcAttr) && !m_encounteredImgSrc) { 178 m_imgSrcUrl = attributeValue;
176 m_encounteredImgSrc = true; 179 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi cePixelRatio(), m_imgSourceSize, attributeValue, m_srcsetImageCandidate), AllowU RLReplacement);
177 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi cePixelRatio(), effectiveSize, attributeValue, m_srcsetImageCandidate), AllowURL Replacement);
178 } else if (match(attributeName, crossoriginAttr)) { 180 } else if (match(attributeName, crossoriginAttr)) {
179 setCrossOriginAllowed(attributeValue); 181 setCrossOriginAllowed(attributeValue);
180 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidat e.isEmpty()) { 182 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidat e.isEmpty()) {
181 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media Values->devicePixelRatio(), effectiveSize, attributeValue); 183 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media Values->devicePixelRatio(), m_imgSourceSize, attributeValue);
182 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi cePixelRatio(), effectiveSize, m_urlToLoad, m_srcsetImageCandidate), AllowURLRep lacement); 184 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi cePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLR eplacement);
185 } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && match(at tributeName, sizesAttr) && m_imgSourceSize < 0) {
eseidel 2014/04/19 04:18:46 it's unsigned < 0 is impossible.
186 m_imgSourceSize = SizesAttributeParser::findEffectiveSize(attrib uteValue, m_mediaValues);
187 if (!m_srcsetImageCandidate.isEmpty())
188 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues-> devicePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), Allow URLReplacement);
183 } 189 }
184 } else if (match(m_tagImpl, linkTag)) { 190 } else if (match(m_tagImpl, linkTag)) {
185 if (match(attributeName, hrefAttr)) 191 if (match(attributeName, hrefAttr))
186 setUrlToLoad(attributeValue, DisallowURLReplacement); 192 setUrlToLoad(attributeValue, DisallowURLReplacement);
187 else if (match(attributeName, relAttr)) 193 else if (match(attributeName, relAttr))
188 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue); 194 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue);
189 else if (match(attributeName, mediaAttr)) 195 else if (match(attributeName, mediaAttr))
190 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attributeValue); 196 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attributeValue);
191 else if (match(attributeName, crossoriginAttr)) 197 else if (match(attributeName, crossoriginAttr))
192 setCrossOriginAllowed(attributeValue); 198 setCrossOriginAllowed(attributeValue);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 m_allowCredentials = DoNotAllowStoredCredentials; 272 m_allowCredentials = DoNotAllowStoredCredentials;
267 } 273 }
268 274
269 const StringImpl* m_tagImpl; 275 const StringImpl* m_tagImpl;
270 String m_urlToLoad; 276 String m_urlToLoad;
271 ImageCandidate m_srcsetImageCandidate; 277 ImageCandidate m_srcsetImageCandidate;
272 String m_charset; 278 String m_charset;
273 bool m_linkIsStyleSheet; 279 bool m_linkIsStyleSheet;
274 bool m_matchedMediaAttribute; 280 bool m_matchedMediaAttribute;
275 bool m_inputIsImage; 281 bool m_inputIsImage;
276 bool m_encounteredImgSrc; 282 String m_imgSrcUrl;
283 unsigned m_imgSourceSize;
277 bool m_isCORSEnabled; 284 bool m_isCORSEnabled;
278 StoredCredentials m_allowCredentials; 285 StoredCredentials m_allowCredentials;
279 RefPtr<MediaValues> m_mediaValues; 286 RefPtr<MediaValues> m_mediaValues;
280 }; 287 };
281 288
282 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med iaValues> mediaValues) 289 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med iaValues> mediaValues)
283 : m_documentURL(documentURL) 290 : m_documentURL(documentURL)
284 , m_inStyle(false) 291 , m_inStyle(false)
285 , m_templateCount(0) 292 , m_templateCount(0)
286 , m_mediaValues(mediaValues) 293 , m_mediaValues(mediaValues)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (m_token.type() == HTMLToken::StartTag) 422 if (m_token.type() == HTMLToken::StartTag)
416 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit)); 423 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name (), Likely8Bit));
417 m_scanner.scan(m_token, m_source, requests); 424 m_scanner.scan(m_token, m_source, requests);
418 m_token.clear(); 425 m_token.clear();
419 } 426 }
420 427
421 preloader->takeAndPreload(requests); 428 preloader->takeAndPreload(requests);
422 } 429 }
423 430
424 } 431 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698