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

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

Issue 2018353002: Avoid downloading unsupported `<source>` types in HTMLPreloadScanner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 class TokenPreloadScanner::StartTagScanner { 136 class TokenPreloadScanner::StartTagScanner {
137 STACK_ALLOCATED(); 137 STACK_ALLOCATED();
138 public: 138 public:
139 StartTagScanner(const StringImpl* tagImpl, MediaValuesCached* mediaValues) 139 StartTagScanner(const StringImpl* tagImpl, MediaValuesCached* mediaValues)
140 : m_tagImpl(tagImpl) 140 : m_tagImpl(tagImpl)
141 , m_linkIsStyleSheet(false) 141 , m_linkIsStyleSheet(false)
142 , m_linkTypeIsMissingOrSupportedStyleSheet(true) 142 , m_linkTypeIsMissingOrSupportedStyleSheet(true)
143 , m_linkIsPreconnect(false) 143 , m_linkIsPreconnect(false)
144 , m_linkIsPreload(false) 144 , m_linkIsPreload(false)
145 , m_linkIsImport(false) 145 , m_linkIsImport(false)
146 , m_matchedMediaAttribute(true) 146 , m_matched(true)
147 , m_inputIsImage(false) 147 , m_inputIsImage(false)
148 , m_sourceSize(0) 148 , m_sourceSize(0)
149 , m_sourceSizeSet(false) 149 , m_sourceSizeSet(false)
150 , m_defer(FetchRequest::NoDefer) 150 , m_defer(FetchRequest::NoDefer)
151 , m_crossOrigin(CrossOriginAttributeNotSet) 151 , m_crossOrigin(CrossOriginAttributeNotSet)
152 , m_mediaValues(mediaValues) 152 , m_mediaValues(mediaValues)
153 , m_referrerPolicySet(false) 153 , m_referrerPolicySet(false)
154 , m_referrerPolicy(ReferrerPolicyDefault) 154 , m_referrerPolicy(ReferrerPolicyDefault)
155 { 155 {
156 if (match(m_tagImpl, imgTag) 156 if (match(m_tagImpl, imgTag)
(...skipping 28 matching lines...) Expand all
185 void processAttributes(const Vector<CompactHTMLToken::Attribute>& attributes ) 185 void processAttributes(const Vector<CompactHTMLToken::Attribute>& attributes )
186 { 186 {
187 if (!m_tagImpl) 187 if (!m_tagImpl)
188 return; 188 return;
189 for (const CompactHTMLToken::Attribute& htmlTokenAttribute : attributes) 189 for (const CompactHTMLToken::Attribute& htmlTokenAttribute : attributes)
190 processAttribute(htmlTokenAttribute.name(), htmlTokenAttribute.value ()); 190 processAttribute(htmlTokenAttribute.name(), htmlTokenAttribute.value ());
191 } 191 }
192 192
193 void handlePictureSourceURL(PictureData& pictureData) 193 void handlePictureSourceURL(PictureData& pictureData)
194 { 194 {
195 if (match(m_tagImpl, sourceTag) && m_matchedMediaAttribute && pictureDat a.sourceURL.isEmpty()) { 195 if (match(m_tagImpl, sourceTag) && m_matched && pictureData.sourceURL.is Empty()) {
196 pictureData.sourceURL = m_srcsetImageCandidate.toString(); 196 pictureData.sourceURL = m_srcsetImageCandidate.toString();
197 pictureData.sourceSizeSet = m_sourceSizeSet; 197 pictureData.sourceSizeSet = m_sourceSizeSet;
198 pictureData.sourceSize = m_sourceSize; 198 pictureData.sourceSize = m_sourceSize;
199 pictureData.picked = true; 199 pictureData.picked = true;
200 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty()) { 200 } else if (match(m_tagImpl, imgTag) && !pictureData.sourceURL.isEmpty()) {
201 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement); 201 setUrlToLoad(pictureData.sourceURL, AllowURLReplacement);
202 } 202 }
203 } 203 }
204 204
205 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL , const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer ences, const PictureData& pictureData, const ReferrerPolicy documentReferrerPoli cy) 205 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL , const SegmentedString& source, const ClientHintsPreferences& clientHintsPrefer ences, const PictureData& pictureData, const ReferrerPolicy documentReferrerPoli cy)
206 { 206 {
207 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre load; 207 PreloadRequest::RequestType requestType = PreloadRequest::RequestTypePre load;
208 if (shouldPreconnect()) { 208 if (shouldPreconnect()) {
209 requestType = PreloadRequest::RequestTypePreconnect; 209 requestType = PreloadRequest::RequestTypePreconnect;
210 } else { 210 } else {
211 if (isLinkRelPreload()) { 211 if (isLinkRelPreload()) {
212 requestType = PreloadRequest::RequestTypeLinkRelPreload; 212 requestType = PreloadRequest::RequestTypeLinkRelPreload;
213 } 213 }
214 if (!shouldPreload() || !m_matchedMediaAttribute) { 214 if (!shouldPreload() || !m_matched) {
kouhei (in TOK) 2016/05/30 10:44:31 !m_matched check should go into shouldPreload()
Yoav Weiss 2016/05/30 11:17:36 fair enough
215 return nullptr; 215 return nullptr;
216 } 216 }
217 } 217 }
218 218
219 219
220 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn()); 220 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn());
221 FetchRequest::ResourceWidth resourceWidth; 221 FetchRequest::ResourceWidth resourceWidth;
222 float sourceSize = m_sourceSize; 222 float sourceSize = m_sourceSize;
223 bool sourceSizeSet = m_sourceSizeSet; 223 bool sourceSizeSet = m_sourceSizeSet;
224 if (pictureData.picked) { 224 if (pictureData.picked) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // FIXME - Don't set rel/media/crossorigin multiple times. 300 // FIXME - Don't set rel/media/crossorigin multiple times.
301 if (match(attributeName, hrefAttr)) { 301 if (match(attributeName, hrefAttr)) {
302 setUrlToLoad(attributeValue, DisallowURLReplacement); 302 setUrlToLoad(attributeValue, DisallowURLReplacement);
303 } else if (match(attributeName, relAttr)) { 303 } else if (match(attributeName, relAttr)) {
304 LinkRelAttribute rel(attributeValue); 304 LinkRelAttribute rel(attributeValue);
305 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel .getIconType() == InvalidIcon && !rel.isDNSPrefetch(); 305 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel .getIconType() == InvalidIcon && !rel.isDNSPrefetch();
306 m_linkIsPreconnect = rel.isPreconnect(); 306 m_linkIsPreconnect = rel.isPreconnect();
307 m_linkIsPreload = rel.isLinkPreload(); 307 m_linkIsPreload = rel.isLinkPreload();
308 m_linkIsImport = rel.isImport(); 308 m_linkIsImport = rel.isImport();
309 } else if (match(attributeName, mediaAttr)) { 309 } else if (match(attributeName, mediaAttr)) {
310 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr ibuteValue); 310 m_matched = mediaAttributeMatches(*m_mediaValues, attributeValue);
311 } else if (match(attributeName, crossoriginAttr)) { 311 } else if (match(attributeName, crossoriginAttr)) {
312 setCrossOrigin(attributeValue); 312 setCrossOrigin(attributeValue);
313 } else if (match(attributeName, asAttr)) { 313 } else if (match(attributeName, asAttr)) {
314 m_asAttributeValue = attributeValue; 314 m_asAttributeValue = attributeValue;
315 } else if (match(attributeName, typeAttr)) { 315 } else if (match(attributeName, typeAttr)) {
316 m_linkTypeIsMissingOrSupportedStyleSheet = MIMETypeRegistry::isSuppo rtedStyleSheetMIMEType(ContentType(attributeValue).type()); 316 m_linkTypeIsMissingOrSupportedStyleSheet = MIMETypeRegistry::isSuppo rtedStyleSheetMIMEType(ContentType(attributeValue).type());
317 } 317 }
318 } 318 }
319 319
320 template<typename NameType> 320 template<typename NameType>
(...skipping 13 matching lines...) Expand all
334 m_srcsetAttributeValue = attributeValue; 334 m_srcsetAttributeValue = attributeValue;
335 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu es->devicePixelRatio(), m_sourceSize, attributeValue); 335 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu es->devicePixelRatio(), m_sourceSize, attributeValue);
336 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { 336 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) {
337 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l ength(); 337 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l ength();
338 m_sourceSizeSet = true; 338 m_sourceSizeSet = true;
339 if (!m_srcsetImageCandidate.isEmpty()) { 339 if (!m_srcsetImageCandidate.isEmpty()) {
340 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); 340 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue);
341 } 341 }
342 } else if (match(attributeName, mediaAttr)) { 342 } else if (match(attributeName, mediaAttr)) {
343 // FIXME - Don't match media multiple times. 343 // FIXME - Don't match media multiple times.
344 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr ibuteValue); 344 m_matched &= mediaAttributeMatches(*m_mediaValues, attributeValue);
345 } else if (match(attributeName, typeAttr)) {
346 m_matched &= MIMETypeRegistry::isSupportedImagePrefixedMIMEType(Cont entType(attributeValue).type());
345 } 347 }
346 } 348 }
347 349
348 template<typename NameType> 350 template<typename NameType>
349 void processVideoAttribute(const NameType& attributeName, const String& attr ibuteValue) 351 void processVideoAttribute(const NameType& attributeName, const String& attr ibuteValue)
350 { 352 {
351 if (match(attributeName, posterAttr)) 353 if (match(attributeName, posterAttr))
352 setUrlToLoad(attributeValue, DisallowURLReplacement); 354 setUrlToLoad(attributeValue, DisallowURLReplacement);
353 } 355 }
354 356
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 455
454 const StringImpl* m_tagImpl; 456 const StringImpl* m_tagImpl;
455 String m_urlToLoad; 457 String m_urlToLoad;
456 ImageCandidate m_srcsetImageCandidate; 458 ImageCandidate m_srcsetImageCandidate;
457 String m_charset; 459 String m_charset;
458 bool m_linkIsStyleSheet; 460 bool m_linkIsStyleSheet;
459 bool m_linkTypeIsMissingOrSupportedStyleSheet; 461 bool m_linkTypeIsMissingOrSupportedStyleSheet;
460 bool m_linkIsPreconnect; 462 bool m_linkIsPreconnect;
461 bool m_linkIsPreload; 463 bool m_linkIsPreload;
462 bool m_linkIsImport; 464 bool m_linkIsImport;
463 bool m_matchedMediaAttribute; 465 bool m_matched;
kouhei (in TOK) 2016/05/30 10:44:31 Can we use separate flags for those two. Instead o
Yoav Weiss 2016/05/30 11:17:36 We could but why? Both `media` and `type` impact w
kouhei (in TOK) 2016/05/30 11:26:22 I thought it was more verbose. The current process
464 bool m_inputIsImage; 466 bool m_inputIsImage;
465 String m_imgSrcUrl; 467 String m_imgSrcUrl;
466 String m_srcsetAttributeValue; 468 String m_srcsetAttributeValue;
467 String m_asAttributeValue; 469 String m_asAttributeValue;
468 float m_sourceSize; 470 float m_sourceSize;
469 bool m_sourceSizeSet; 471 bool m_sourceSizeSet;
470 FetchRequest::DeferOption m_defer; 472 FetchRequest::DeferOption m_defer;
471 CrossOriginAttributeValue m_crossOrigin; 473 CrossOriginAttributeValue m_crossOrigin;
472 Member<MediaValuesCached> m_mediaValues; 474 Member<MediaValuesCached> m_mediaValues;
473 bool m_referrerPolicySet; 475 bool m_referrerPolicySet;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 ASSERT(document); 805 ASSERT(document);
804 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm lPreloadScanning(); 806 doHtmlPreloadScanning = !document->settings() || document->settings()->doHtm lPreloadScanning();
805 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && document->frame()->isMainFrame(); 807 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && document->frame()->isMainFrame();
806 defaultViewportMinWidth = document->viewportDefaultMinWidth(); 808 defaultViewportMinWidth = document->viewportDefaultMinWidth();
807 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk(); 809 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk();
808 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled(); 810 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled();
809 referrerPolicy = document->getReferrerPolicy(); 811 referrerPolicy = document->getReferrerPolicy();
810 } 812 }
811 813
812 } // namespace blink 814 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698