Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 18 matching lines...) Expand all Loading... | |
| 29 #include "core/html/parser/HTMLPreloadScanner.h" | 29 #include "core/html/parser/HTMLPreloadScanner.h" |
| 30 | 30 |
| 31 #include "core/HTMLNames.h" | 31 #include "core/HTMLNames.h" |
| 32 #include "core/InputTypeNames.h" | 32 #include "core/InputTypeNames.h" |
| 33 #include "core/css/MediaList.h" | 33 #include "core/css/MediaList.h" |
| 34 #include "core/css/MediaQueryEvaluator.h" | 34 #include "core/css/MediaQueryEvaluator.h" |
| 35 #include "core/css/MediaValuesCached.h" | 35 #include "core/css/MediaValuesCached.h" |
| 36 #include "core/css/parser/SizesAttributeParser.h" | 36 #include "core/css/parser/SizesAttributeParser.h" |
| 37 #include "core/dom/Document.h" | 37 #include "core/dom/Document.h" |
| 38 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
| 39 #include "core/html/HTMLImageElement.h" | |
| 39 #include "core/html/HTMLMetaElement.h" | 40 #include "core/html/HTMLMetaElement.h" |
| 40 #include "core/html/LinkRelAttribute.h" | 41 #include "core/html/LinkRelAttribute.h" |
| 41 #include "core/html/parser/HTMLParserIdioms.h" | 42 #include "core/html/parser/HTMLParserIdioms.h" |
| 42 #include "core/html/parser/HTMLSrcsetParser.h" | 43 #include "core/html/parser/HTMLSrcsetParser.h" |
| 43 #include "core/html/parser/HTMLTokenizer.h" | 44 #include "core/html/parser/HTMLTokenizer.h" |
| 44 #include "platform/RuntimeEnabledFeatures.h" | 45 #include "platform/RuntimeEnabledFeatures.h" |
| 45 #include "platform/TraceEvent.h" | 46 #include "platform/TraceEvent.h" |
| 46 #include "wtf/MainThread.h" | 47 #include "wtf/MainThread.h" |
| 47 | 48 |
| 48 namespace blink { | 49 namespace blink { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 public: | 111 public: |
| 111 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu es) | 112 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu es) |
| 112 : m_tagImpl(tagImpl) | 113 : m_tagImpl(tagImpl) |
| 113 , m_linkIsStyleSheet(false) | 114 , m_linkIsStyleSheet(false) |
| 114 , m_linkIsPreconnect(false) | 115 , m_linkIsPreconnect(false) |
| 115 , m_matchedMediaAttribute(true) | 116 , m_matchedMediaAttribute(true) |
| 116 , m_inputIsImage(false) | 117 , m_inputIsImage(false) |
| 117 , m_sourceSize(0) | 118 , m_sourceSize(0) |
| 118 , m_sourceSizeSet(false) | 119 , m_sourceSizeSet(false) |
| 119 , m_isCORSEnabled(false) | 120 , m_isCORSEnabled(false) |
| 121 , m_widthValue(0) | |
| 122 , m_widthValueSet(false) | |
| 123 , m_widthPresent(false) | |
| 120 , m_defer(FetchRequest::NoDefer) | 124 , m_defer(FetchRequest::NoDefer) |
| 121 , m_allowCredentials(DoNotAllowStoredCredentials) | 125 , m_allowCredentials(DoNotAllowStoredCredentials) |
| 122 , m_mediaValues(mediaValues) | 126 , m_mediaValues(mediaValues) |
| 123 { | 127 { |
| 124 ASSERT(m_mediaValues->isCached()); | 128 ASSERT(m_mediaValues->isCached()); |
| 125 if (match(m_tagImpl, imgTag) | 129 if (match(m_tagImpl, imgTag) |
| 126 || match(m_tagImpl, sourceTag)) { | 130 || match(m_tagImpl, sourceTag)) { |
| 127 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length( ); | 131 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length( ); |
| 128 return; | 132 return; |
| 129 } | 133 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 if (shouldPreconnect()) | 177 if (shouldPreconnect()) |
| 174 requestType = PreloadRequest::RequestTypePreconnect; | 178 requestType = PreloadRequest::RequestTypePreconnect; |
| 175 else if (!shouldPreload() || !m_matchedMediaAttribute) | 179 else if (!shouldPreload() || !m_matchedMediaAttribute) |
| 176 return nullptr; | 180 return nullptr; |
| 177 | 181 |
| 178 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn()); | 182 TextPosition position = TextPosition(source.currentLine(), source.curren tColumn()); |
| 179 FetchRequest::ResourceWidth resourceWidth; | 183 FetchRequest::ResourceWidth resourceWidth; |
| 180 if (m_sourceSizeSet && m_srcsetImageCandidate.resourceWidth() != Uniniti alizedDescriptor) { | 184 if (m_sourceSizeSet && m_srcsetImageCandidate.resourceWidth() != Uniniti alizedDescriptor) { |
| 181 resourceWidth.width = m_sourceSize; | 185 resourceWidth.width = m_sourceSize; |
| 182 resourceWidth.isSet = true; | 186 resourceWidth.isSet = true; |
| 187 } else { | |
| 188 resourceWidth.isSet = m_widthValueSet; | |
| 189 resourceWidth.width = m_widthValue; | |
|
Mike West
2015/06/18 06:20:04
Nit: The `if` part of the clause reverses the orde
Yoav Weiss
2015/06/18 06:30:22
I'll reverse it
| |
| 183 } | 190 } |
| 191 | |
| 184 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), resourceWidth, clientHintsPreferences, requestType); | 192 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), resourceWidth, clientHintsPreferences, requestType); |
| 185 if (isCORSEnabled()) | 193 if (isCORSEnabled()) |
| 186 request->setCrossOriginEnabled(allowStoredCredentials()); | 194 request->setCrossOriginEnabled(allowStoredCredentials()); |
| 187 request->setCharset(charset()); | 195 request->setCharset(charset()); |
| 188 request->setDefer(m_defer); | 196 request->setDefer(m_defer); |
| 189 return request.release(); | 197 return request.release(); |
| 190 } | 198 } |
| 191 | 199 |
| 192 private: | 200 private: |
| 193 template<typename NameType> | 201 template<typename NameType> |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 216 m_srcsetAttributeValue = attributeValue; | 224 m_srcsetAttributeValue = attributeValue; |
| 217 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu es->devicePixelRatio(), m_sourceSize, attributeValue); | 225 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu es->devicePixelRatio(), m_sourceSize, attributeValue); |
| 218 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem ent); | 226 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem ent); |
| 219 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { | 227 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { |
| 220 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l ength(); | 228 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l ength(); |
| 221 m_sourceSizeSet = true; | 229 m_sourceSizeSet = true; |
| 222 if (!m_srcsetImageCandidate.isEmpty()) { | 230 if (!m_srcsetImageCandidate.isEmpty()) { |
| 223 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); | 231 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); |
| 224 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl acement); | 232 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl acement); |
| 225 } | 233 } |
| 234 } else if (match(attributeName, widthAttr) && !m_widthPresent) { | |
|
Mike West
2015/06/18 06:20:04
Could you drop the `widthPresent` property in favo
Yoav Weiss
2015/06/18 06:30:22
I did, but there was a bug there in cases like `<i
Mike West
2015/06/18 06:34:35
Hrm. Isn't that the opposite of how the parser wor
| |
| 235 m_widthPresent = true; | |
| 236 m_widthValue = HTMLImageElement::widthAttributeToInt(attributeValue, m_widthValueSet); | |
| 226 } | 237 } |
| 227 } | 238 } |
| 228 | 239 |
| 229 template<typename NameType> | 240 template<typename NameType> |
| 230 void processLinkAttribute(const NameType& attributeName, const String& attri buteValue) | 241 void processLinkAttribute(const NameType& attributeName, const String& attri buteValue) |
| 231 { | 242 { |
| 232 // FIXME - Don't set rel/media/crossorigin multiple times. | 243 // FIXME - Don't set rel/media/crossorigin multiple times. |
| 233 if (match(attributeName, hrefAttr)) { | 244 if (match(attributeName, hrefAttr)) { |
| 234 setUrlToLoad(attributeValue, DisallowURLReplacement); | 245 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 235 } else if (match(attributeName, relAttr)) { | 246 } else if (match(attributeName, relAttr)) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 String m_charset; | 394 String m_charset; |
| 384 bool m_linkIsStyleSheet; | 395 bool m_linkIsStyleSheet; |
| 385 bool m_linkIsPreconnect; | 396 bool m_linkIsPreconnect; |
| 386 bool m_matchedMediaAttribute; | 397 bool m_matchedMediaAttribute; |
| 387 bool m_inputIsImage; | 398 bool m_inputIsImage; |
| 388 String m_imgSrcUrl; | 399 String m_imgSrcUrl; |
| 389 String m_srcsetAttributeValue; | 400 String m_srcsetAttributeValue; |
| 390 float m_sourceSize; | 401 float m_sourceSize; |
| 391 bool m_sourceSizeSet; | 402 bool m_sourceSizeSet; |
| 392 bool m_isCORSEnabled; | 403 bool m_isCORSEnabled; |
| 404 int m_widthValue; | |
| 405 bool m_widthValueSet; | |
| 406 bool m_widthPresent; | |
| 393 FetchRequest::DeferOption m_defer; | 407 FetchRequest::DeferOption m_defer; |
| 394 StoredCredentials m_allowCredentials; | 408 StoredCredentials m_allowCredentials; |
| 395 RefPtr<MediaValues> m_mediaValues; | 409 RefPtr<MediaValues> m_mediaValues; |
| 396 }; | 410 }; |
| 397 | 411 |
| 398 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac hedDocumentParameters> documentParameters) | 412 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac hedDocumentParameters> documentParameters) |
| 399 : m_documentURL(documentURL) | 413 : m_documentURL(documentURL) |
| 400 , m_inStyle(false) | 414 , m_inStyle(false) |
| 401 , m_inPicture(false) | 415 , m_inPicture(false) |
| 402 , m_isAppCacheEnabled(false) | 416 , m_isAppCacheEnabled(false) |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 mediaValues = givenMediaValues; | 623 mediaValues = givenMediaValues; |
| 610 else | 624 else |
| 611 mediaValues = MediaValuesCached::create(*document); | 625 mediaValues = MediaValuesCached::create(*document); |
| 612 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | 626 ASSERT(mediaValues->isSafeToSendToAnotherThread()); |
| 613 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 627 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
| 614 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk(); | 628 viewportMetaZeroValuesQuirk = document->settings() && document->settings()-> viewportMetaZeroValuesQuirk(); |
| 615 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled(); | 629 viewportMetaEnabled = document->settings() && document->settings()->viewport MetaEnabled(); |
| 616 } | 630 } |
| 617 | 631 |
| 618 } | 632 } |
| OLD | NEW |