| 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 16 matching lines...) Expand all Loading... |
| 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 Loading... |
| 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) |
| 112 , m_sourceSizeSet(false) |
| 111 , m_isCORSEnabled(false) | 113 , m_isCORSEnabled(false) |
| 112 , m_allowCredentials(DoNotAllowStoredCredentials) | 114 , m_allowCredentials(DoNotAllowStoredCredentials) |
| 113 , m_mediaValues(mediaValues) | 115 , m_mediaValues(mediaValues) |
| 114 { | 116 { |
| 115 if (!match(m_tagImpl, imgTag) | 117 if (!match(m_tagImpl, imgTag) |
| 116 && !match(m_tagImpl, inputTag) | 118 && !match(m_tagImpl, inputTag) |
| 117 && !match(m_tagImpl, linkTag) | 119 && !match(m_tagImpl, linkTag) |
| 118 && !match(m_tagImpl, scriptTag)) | 120 && !match(m_tagImpl, scriptTag)) |
| 119 m_tagImpl = 0; | 121 m_tagImpl = 0; |
| 122 if (RuntimeEnabledFeatures::pictureSizesEnabled()) |
| 123 m_imgSourceSize = SizesAttributeParser::findEffectiveSize(String(),
m_mediaValues); |
| 120 } | 124 } |
| 121 | 125 |
| 122 enum URLReplacement { | 126 enum URLReplacement { |
| 123 AllowURLReplacement, | 127 AllowURLReplacement, |
| 124 DisallowURLReplacement | 128 DisallowURLReplacement |
| 125 }; | 129 }; |
| 126 | 130 |
| 127 void processAttributes(const HTMLToken::AttributeList& attributes) | 131 void processAttributes(const HTMLToken::AttributeList& attributes) |
| 128 { | 132 { |
| 129 ASSERT(isMainThread()); | 133 ASSERT(isMainThread()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 { | 168 { |
| 165 if (match(attributeName, charsetAttr)) | 169 if (match(attributeName, charsetAttr)) |
| 166 m_charset = attributeValue; | 170 m_charset = attributeValue; |
| 167 | 171 |
| 168 if (match(m_tagImpl, scriptTag)) { | 172 if (match(m_tagImpl, scriptTag)) { |
| 169 if (match(attributeName, srcAttr)) | 173 if (match(attributeName, srcAttr)) |
| 170 setUrlToLoad(attributeValue, DisallowURLReplacement); | 174 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 171 else if (match(attributeName, crossoriginAttr)) | 175 else if (match(attributeName, crossoriginAttr)) |
| 172 setCrossOriginAllowed(attributeValue); | 176 setCrossOriginAllowed(attributeValue); |
| 173 } else if (match(m_tagImpl, imgTag)) { | 177 } else if (match(m_tagImpl, imgTag)) { |
| 174 int effectiveSize = -1; // FIXME - hook up the real value from `size
s` | 178 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) { |
| 175 if (match(attributeName, srcAttr) && !m_encounteredImgSrc) { | 179 m_imgSrcUrl = attributeValue; |
| 176 m_encounteredImgSrc = true; | 180 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)) { | 181 } else if (match(attributeName, crossoriginAttr)) { |
| 179 setCrossOriginAllowed(attributeValue); | 182 setCrossOriginAllowed(attributeValue); |
| 180 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidat
e.isEmpty()) { | 183 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidat
e.isEmpty()) { |
| 181 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), effectiveSize, attributeValue); | 184 m_imgSrcsetAttributeValue = attributeValue; |
| 182 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), effectiveSize, m_urlToLoad, m_srcsetImageCandidate), AllowURLRep
lacement); | 185 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), m_imgSourceSize, attributeValue); |
| 186 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLR
eplacement); |
| 187 } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && match(at
tributeName, sizesAttr) && !m_sourceSizeSet) { |
| 188 m_imgSourceSize = SizesAttributeParser::findEffectiveSize(attrib
uteValue, m_mediaValues); |
| 189 m_sourceSizeSet = true; |
| 190 if (!m_srcsetImageCandidate.isEmpty()) { |
| 191 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_m
ediaValues->devicePixelRatio(), m_imgSourceSize, m_imgSrcsetAttributeValue); |
| 192 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->
devicePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), Allow
URLReplacement); |
| 193 } |
| 183 } | 194 } |
| 184 } else if (match(m_tagImpl, linkTag)) { | 195 } else if (match(m_tagImpl, linkTag)) { |
| 185 if (match(attributeName, hrefAttr)) | 196 if (match(attributeName, hrefAttr)) |
| 186 setUrlToLoad(attributeValue, DisallowURLReplacement); | 197 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 187 else if (match(attributeName, relAttr)) | 198 else if (match(attributeName, relAttr)) |
| 188 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue); | 199 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue); |
| 189 else if (match(attributeName, mediaAttr)) | 200 else if (match(attributeName, mediaAttr)) |
| 190 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues,
attributeValue); | 201 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues,
attributeValue); |
| 191 else if (match(attributeName, crossoriginAttr)) | 202 else if (match(attributeName, crossoriginAttr)) |
| 192 setCrossOriginAllowed(attributeValue); | 203 setCrossOriginAllowed(attributeValue); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 m_allowCredentials = DoNotAllowStoredCredentials; | 277 m_allowCredentials = DoNotAllowStoredCredentials; |
| 267 } | 278 } |
| 268 | 279 |
| 269 const StringImpl* m_tagImpl; | 280 const StringImpl* m_tagImpl; |
| 270 String m_urlToLoad; | 281 String m_urlToLoad; |
| 271 ImageCandidate m_srcsetImageCandidate; | 282 ImageCandidate m_srcsetImageCandidate; |
| 272 String m_charset; | 283 String m_charset; |
| 273 bool m_linkIsStyleSheet; | 284 bool m_linkIsStyleSheet; |
| 274 bool m_matchedMediaAttribute; | 285 bool m_matchedMediaAttribute; |
| 275 bool m_inputIsImage; | 286 bool m_inputIsImage; |
| 276 bool m_encounteredImgSrc; | 287 String m_imgSrcUrl; |
| 288 String m_imgSrcsetAttributeValue; |
| 289 unsigned m_imgSourceSize; |
| 290 bool m_sourceSizeSet; |
| 277 bool m_isCORSEnabled; | 291 bool m_isCORSEnabled; |
| 278 StoredCredentials m_allowCredentials; | 292 StoredCredentials m_allowCredentials; |
| 279 RefPtr<MediaValues> m_mediaValues; | 293 RefPtr<MediaValues> m_mediaValues; |
| 280 }; | 294 }; |
| 281 | 295 |
| 282 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med
iaValues> mediaValues) | 296 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med
iaValues> mediaValues) |
| 283 : m_documentURL(documentURL) | 297 : m_documentURL(documentURL) |
| 284 , m_inStyle(false) | 298 , m_inStyle(false) |
| 285 , m_templateCount(0) | 299 , m_templateCount(0) |
| 286 , m_mediaValues(mediaValues) | 300 , m_mediaValues(mediaValues) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 if (m_token.type() == HTMLToken::StartTag) | 429 if (m_token.type() == HTMLToken::StartTag) |
| 416 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 430 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
| 417 m_scanner.scan(m_token, m_source, requests); | 431 m_scanner.scan(m_token, m_source, requests); |
| 418 m_token.clear(); | 432 m_token.clear(); |
| 419 } | 433 } |
| 420 | 434 |
| 421 preloader->takeAndPreload(requests); | 435 preloader->takeAndPreload(requests); |
| 422 } | 436 } |
| 423 | 437 |
| 424 } | 438 } |
| OLD | NEW |