| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 RefPtrWillBeRawPtr<MediaQuerySet> mediaQueries = MediaQuerySet::createOffMai
nThread(attributeValue); | 99 RefPtrWillBeRawPtr<MediaQuerySet> mediaQueries = MediaQuerySet::createOffMai
nThread(attributeValue); |
| 100 MediaQueryEvaluator mediaQueryEvaluator("screen", mediaValues); | 100 MediaQueryEvaluator mediaQueryEvaluator("screen", mediaValues); |
| 101 return mediaQueryEvaluator.eval(mediaQueries.get()); | 101 return mediaQueryEvaluator.eval(mediaQueries.get()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 class TokenPreloadScanner::StartTagScanner { | 104 class TokenPreloadScanner::StartTagScanner { |
| 105 public: | 105 public: |
| 106 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu
es) | 106 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu
es) |
| 107 : m_tagImpl(tagImpl) | 107 : m_tagImpl(tagImpl) |
| 108 , m_linkIsStyleSheet(false) | 108 , m_linkIsStyleSheet(false) |
| 109 , m_linkIsImport(false) |
| 109 , m_matchedMediaAttribute(true) | 110 , m_matchedMediaAttribute(true) |
| 110 , m_inputIsImage(false) | 111 , m_inputIsImage(false) |
| 111 , m_imgSourceSize(0) | 112 , m_imgSourceSize(0) |
| 112 , m_sourceSizeSet(false) | 113 , m_sourceSizeSet(false) |
| 113 , m_isCORSEnabled(false) | 114 , m_isCORSEnabled(false) |
| 114 , m_allowCredentials(DoNotAllowStoredCredentials) | 115 , m_allowCredentials(DoNotAllowStoredCredentials) |
| 115 , m_mediaValues(mediaValues) | 116 , m_mediaValues(mediaValues) |
| 116 { | 117 { |
| 117 if (!match(m_tagImpl, imgTag) | 118 if (!match(m_tagImpl, imgTag) |
| 118 && !match(m_tagImpl, inputTag) | 119 && !match(m_tagImpl, inputTag) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLR
eplacement); | 187 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 } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && match(at
tributeName, sizesAttr) && !m_sourceSizeSet) { |
| 188 m_imgSourceSize = SizesAttributeParser::findEffectiveSize(attrib
uteValue, m_mediaValues); | 189 m_imgSourceSize = SizesAttributeParser::findEffectiveSize(attrib
uteValue, m_mediaValues); |
| 189 m_sourceSizeSet = true; | 190 m_sourceSizeSet = true; |
| 190 if (!m_srcsetImageCandidate.isEmpty()) { | 191 if (!m_srcsetImageCandidate.isEmpty()) { |
| 191 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_m
ediaValues->devicePixelRatio(), m_imgSourceSize, m_imgSrcsetAttributeValue); | 192 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 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->
devicePixelRatio(), m_imgSourceSize, m_imgSrcUrl, m_srcsetImageCandidate), Allow
URLReplacement); |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 } else if (match(m_tagImpl, linkTag)) { | 196 } else if (match(m_tagImpl, linkTag)) { |
| 196 if (match(attributeName, hrefAttr)) | 197 if (match(attributeName, hrefAttr)) { |
| 197 setUrlToLoad(attributeValue, DisallowURLReplacement); | 198 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 198 else if (match(attributeName, relAttr)) | 199 } else if (match(attributeName, relAttr)) { |
| 199 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue); | 200 m_linkIsStyleSheet = relAttributeIsStyleSheet(attributeValue); |
| 200 else if (match(attributeName, mediaAttr)) | 201 m_linkIsImport = RuntimeEnabledFeatures::htmlImportsEnabled() &&
relAttributeIsImport(attributeValue); |
| 202 } else if (match(attributeName, mediaAttr)) { |
| 201 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues,
attributeValue); | 203 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues,
attributeValue); |
| 202 else if (match(attributeName, crossoriginAttr)) | 204 } else if (match(attributeName, crossoriginAttr)) { |
| 203 setCrossOriginAllowed(attributeValue); | 205 setCrossOriginAllowed(attributeValue); |
| 206 } |
| 204 } else if (match(m_tagImpl, inputTag)) { | 207 } else if (match(m_tagImpl, inputTag)) { |
| 205 if (match(attributeName, srcAttr)) | 208 if (match(attributeName, srcAttr)) |
| 206 setUrlToLoad(attributeValue, DisallowURLReplacement); | 209 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 207 else if (match(attributeName, typeAttr)) | 210 else if (match(attributeName, typeAttr)) |
| 208 m_inputIsImage = equalIgnoringCase(attributeValue, InputTypeName
s::image); | 211 m_inputIsImage = equalIgnoringCase(attributeValue, InputTypeName
s::image); |
| 209 } | 212 } |
| 210 } | 213 } |
| 211 | 214 |
| 215 static bool relAttributeWillBeImmediatelyUsed(const LinkRelAttribute& rel) |
| 216 { |
| 217 return !rel.isAlternate() && rel.iconType() == InvalidIcon && !rel.isDNS
Prefetch(); |
| 218 } |
| 219 |
| 212 static bool relAttributeIsStyleSheet(const String& attributeValue) | 220 static bool relAttributeIsStyleSheet(const String& attributeValue) |
| 213 { | 221 { |
| 214 LinkRelAttribute rel(attributeValue); | 222 LinkRelAttribute rel(attributeValue); |
| 215 return rel.isStyleSheet() && !rel.isAlternate() && rel.iconType() == Inv
alidIcon && !rel.isDNSPrefetch(); | 223 return rel.isStyleSheet() && relAttributeWillBeImmediatelyUsed(rel); |
| 224 } |
| 225 |
| 226 static bool relAttributeIsImport(const String& attributeValue) |
| 227 { |
| 228 LinkRelAttribute rel(attributeValue); |
| 229 return rel.isImport() && relAttributeWillBeImmediatelyUsed(rel); |
| 216 } | 230 } |
| 217 | 231 |
| 218 void setUrlToLoad(const String& value, URLReplacement replacement) | 232 void setUrlToLoad(const String& value, URLReplacement replacement) |
| 219 { | 233 { |
| 220 // We only respect the first src/href, per HTML5: | 234 // We only respect the first src/href, per HTML5: |
| 221 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenizat
ion.html#attribute-name-state | 235 // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenizat
ion.html#attribute-name-state |
| 222 if (replacement == DisallowURLReplacement && !m_urlToLoad.isEmpty()) | 236 if (replacement == DisallowURLReplacement && !m_urlToLoad.isEmpty()) |
| 223 return; | 237 return; |
| 224 String url = stripLeadingAndTrailingHTMLSpaces(value); | 238 String url = stripLeadingAndTrailingHTMLSpaces(value); |
| 225 if (url.isEmpty()) | 239 if (url.isEmpty()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 } | 250 } |
| 237 | 251 |
| 238 Resource::Type resourceType() const | 252 Resource::Type resourceType() const |
| 239 { | 253 { |
| 240 if (match(m_tagImpl, scriptTag)) | 254 if (match(m_tagImpl, scriptTag)) |
| 241 return Resource::Script; | 255 return Resource::Script; |
| 242 if (match(m_tagImpl, imgTag) || (match(m_tagImpl, inputTag) && m_inputIs
Image)) | 256 if (match(m_tagImpl, imgTag) || (match(m_tagImpl, inputTag) && m_inputIs
Image)) |
| 243 return Resource::Image; | 257 return Resource::Image; |
| 244 if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet) | 258 if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet) |
| 245 return Resource::CSSStyleSheet; | 259 return Resource::CSSStyleSheet; |
| 260 if (match(m_tagImpl, linkTag) && m_linkIsImport) |
| 261 return Resource::ImportResource; |
| 246 ASSERT_NOT_REACHED(); | 262 ASSERT_NOT_REACHED(); |
| 247 return Resource::Raw; | 263 return Resource::Raw; |
| 248 } | 264 } |
| 249 | 265 |
| 250 bool shouldPreload() const | 266 bool shouldPreload() const |
| 251 { | 267 { |
| 252 if (m_urlToLoad.isEmpty()) | 268 if (m_urlToLoad.isEmpty()) |
| 253 return false; | 269 return false; |
| 254 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet) | 270 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport) |
| 255 return false; | 271 return false; |
| 256 if (match(m_tagImpl, inputTag) && !m_inputIsImage) | 272 if (match(m_tagImpl, inputTag) && !m_inputIsImage) |
| 257 return false; | 273 return false; |
| 258 return true; | 274 return true; |
| 259 } | 275 } |
| 260 | 276 |
| 261 bool isCORSEnabled() const | 277 bool isCORSEnabled() const |
| 262 { | 278 { |
| 263 return m_isCORSEnabled; | 279 return m_isCORSEnabled; |
| 264 } | 280 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 275 m_allowCredentials = AllowStoredCredentials; | 291 m_allowCredentials = AllowStoredCredentials; |
| 276 else | 292 else |
| 277 m_allowCredentials = DoNotAllowStoredCredentials; | 293 m_allowCredentials = DoNotAllowStoredCredentials; |
| 278 } | 294 } |
| 279 | 295 |
| 280 const StringImpl* m_tagImpl; | 296 const StringImpl* m_tagImpl; |
| 281 String m_urlToLoad; | 297 String m_urlToLoad; |
| 282 ImageCandidate m_srcsetImageCandidate; | 298 ImageCandidate m_srcsetImageCandidate; |
| 283 String m_charset; | 299 String m_charset; |
| 284 bool m_linkIsStyleSheet; | 300 bool m_linkIsStyleSheet; |
| 301 bool m_linkIsImport; |
| 285 bool m_matchedMediaAttribute; | 302 bool m_matchedMediaAttribute; |
| 286 bool m_inputIsImage; | 303 bool m_inputIsImage; |
| 287 String m_imgSrcUrl; | 304 String m_imgSrcUrl; |
| 288 String m_imgSrcsetAttributeValue; | 305 String m_imgSrcsetAttributeValue; |
| 289 unsigned m_imgSourceSize; | 306 unsigned m_imgSourceSize; |
| 290 bool m_sourceSizeSet; | 307 bool m_sourceSizeSet; |
| 291 bool m_isCORSEnabled; | 308 bool m_isCORSEnabled; |
| 292 StoredCredentials m_allowCredentials; | 309 StoredCredentials m_allowCredentials; |
| 293 RefPtr<MediaValues> m_mediaValues; | 310 RefPtr<MediaValues> m_mediaValues; |
| 294 }; | 311 }; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 if (m_token.type() == HTMLToken::StartTag) | 446 if (m_token.type() == HTMLToken::StartTag) |
| 430 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 447 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
| 431 m_scanner.scan(m_token, m_source, requests); | 448 m_scanner.scan(m_token, m_source, requests); |
| 432 m_token.clear(); | 449 m_token.clear(); |
| 433 } | 450 } |
| 434 | 451 |
| 435 preloader->takeAndPreload(requests); | 452 preloader->takeAndPreload(requests); |
| 436 } | 453 } |
| 437 | 454 |
| 438 } | 455 } |
| OLD | NEW |