| 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/CrossOriginAttribute.h" |
| 39 #include "core/html/HTMLImageElement.h" | 40 #include "core/html/HTMLImageElement.h" |
| 40 #include "core/html/HTMLMetaElement.h" | 41 #include "core/html/HTMLMetaElement.h" |
| 41 #include "core/html/LinkRelAttribute.h" | 42 #include "core/html/LinkRelAttribute.h" |
| 42 #include "core/html/parser/HTMLParserIdioms.h" | 43 #include "core/html/parser/HTMLParserIdioms.h" |
| 43 #include "core/html/parser/HTMLSrcsetParser.h" | 44 #include "core/html/parser/HTMLSrcsetParser.h" |
| 44 #include "core/html/parser/HTMLTokenizer.h" | 45 #include "core/html/parser/HTMLTokenizer.h" |
| 45 #include "platform/RuntimeEnabledFeatures.h" | 46 #include "platform/RuntimeEnabledFeatures.h" |
| 46 #include "platform/TraceEvent.h" | 47 #include "platform/TraceEvent.h" |
| 47 #include "wtf/MainThread.h" | 48 #include "wtf/MainThread.h" |
| 48 | 49 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 public: | 113 public: |
| 113 StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValue
s> mediaValues) | 114 StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValue
s> mediaValues) |
| 114 : m_tagImpl(tagImpl) | 115 : m_tagImpl(tagImpl) |
| 115 , m_linkIsStyleSheet(false) | 116 , m_linkIsStyleSheet(false) |
| 116 , m_linkIsPreconnect(false) | 117 , m_linkIsPreconnect(false) |
| 117 , m_linkIsImport(false) | 118 , m_linkIsImport(false) |
| 118 , m_matchedMediaAttribute(true) | 119 , m_matchedMediaAttribute(true) |
| 119 , m_inputIsImage(false) | 120 , m_inputIsImage(false) |
| 120 , m_sourceSize(0) | 121 , m_sourceSize(0) |
| 121 , m_sourceSizeSet(false) | 122 , m_sourceSizeSet(false) |
| 122 , m_isCORSEnabled(false) | |
| 123 , m_defer(FetchRequest::NoDefer) | 123 , m_defer(FetchRequest::NoDefer) |
| 124 , m_allowCredentials(DoNotAllowStoredCredentials) | 124 , m_crossOrigin(CrossOriginAttributeNotSet) |
| 125 , m_mediaValues(mediaValues) | 125 , m_mediaValues(mediaValues) |
| 126 , m_referrerPolicySet(false) | 126 , m_referrerPolicySet(false) |
| 127 , m_referrerPolicy(ReferrerPolicyDefault) | 127 , m_referrerPolicy(ReferrerPolicyDefault) |
| 128 { | 128 { |
| 129 ASSERT(m_mediaValues->isCached()); | 129 ASSERT(m_mediaValues->isCached()); |
| 130 if (match(m_tagImpl, imgTag) | 130 if (match(m_tagImpl, imgTag) |
| 131 || match(m_tagImpl, sourceTag)) { | 131 || match(m_tagImpl, sourceTag)) { |
| 132 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length(
); | 132 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length(
); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 sourceSize = pictureData.sourceSize; | 193 sourceSize = pictureData.sourceSize; |
| 194 } | 194 } |
| 195 if (sourceSizeSet) { | 195 if (sourceSizeSet) { |
| 196 resourceWidth.width = sourceSize; | 196 resourceWidth.width = sourceSize; |
| 197 resourceWidth.isSet = true; | 197 resourceWidth.isSet = true; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // The element's 'referrerpolicy' attribute (if present) takes precedenc
e over the document's referrer policy. | 200 // The element's 'referrerpolicy' attribute (if present) takes precedenc
e over the document's referrer policy. |
| 201 ReferrerPolicy referrerPolicy = (m_referrerPolicy != ReferrerPolicyDefau
lt && RuntimeEnabledFeatures::referrerPolicyAttributeEnabled()) ? m_referrerPoli
cy : documentReferrerPolicy; | 201 ReferrerPolicy referrerPolicy = (m_referrerPolicy != ReferrerPolicyDefau
lt && RuntimeEnabledFeatures::referrerPolicyAttributeEnabled()) ? m_referrerPoli
cy : documentReferrerPolicy; |
| 202 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), referrerPolicy
, resourceWidth, clientHintsPreferences, requestType); | 202 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), referrerPolicy
, resourceWidth, clientHintsPreferences, requestType); |
| 203 if (isCORSEnabled()) | 203 request->setCrossOrigin(m_crossOrigin); |
| 204 request->setCrossOriginEnabled(allowStoredCredentials()); | |
| 205 request->setCharset(charset()); | 204 request->setCharset(charset()); |
| 206 request->setDefer(m_defer); | 205 request->setDefer(m_defer); |
| 207 return request.release(); | 206 return request.release(); |
| 208 } | 207 } |
| 209 | 208 |
| 210 private: | 209 private: |
| 211 template<typename NameType> | 210 template<typename NameType> |
| 212 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) | 211 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) |
| 213 { | 212 { |
| 214 // FIXME - Don't set crossorigin multiple times. | 213 // FIXME - Don't set crossorigin multiple times. |
| 215 if (match(attributeName, srcAttr)) | 214 if (match(attributeName, srcAttr)) |
| 216 setUrlToLoad(attributeValue, DisallowURLReplacement); | 215 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 217 else if (match(attributeName, crossoriginAttr)) | 216 else if (match(attributeName, crossoriginAttr)) |
| 218 setCrossOriginAllowed(attributeValue); | 217 setCrossOrigin(attributeValue); |
| 219 else if (match(attributeName, asyncAttr)) | 218 else if (match(attributeName, asyncAttr)) |
| 220 setDefer(FetchRequest::LazyLoad); | 219 setDefer(FetchRequest::LazyLoad); |
| 221 else if (match(attributeName, deferAttr)) | 220 else if (match(attributeName, deferAttr)) |
| 222 setDefer(FetchRequest::LazyLoad); | 221 setDefer(FetchRequest::LazyLoad); |
| 223 } | 222 } |
| 224 | 223 |
| 225 template<typename NameType> | 224 template<typename NameType> |
| 226 void processImgAttribute(const NameType& attributeName, const String& attrib
uteValue) | 225 void processImgAttribute(const NameType& attributeName, const String& attrib
uteValue) |
| 227 { | 226 { |
| 228 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) { | 227 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) { |
| 229 m_imgSrcUrl = attributeValue; | 228 m_imgSrcUrl = attributeValue; |
| 230 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, attributeValue, m_srcsetImageCandidate), AllowURLRepla
cement); | 229 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, attributeValue, m_srcsetImageCandidate), AllowURLRepla
cement); |
| 231 } else if (match(attributeName, crossoriginAttr)) { | 230 } else if (match(attributeName, crossoriginAttr)) { |
| 232 setCrossOriginAllowed(attributeValue); | 231 setCrossOrigin(attributeValue); |
| 233 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidate.is
Empty()) { | 232 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidate.is
Empty()) { |
| 234 m_srcsetAttributeValue = attributeValue; | 233 m_srcsetAttributeValue = attributeValue; |
| 235 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu
es->devicePixelRatio(), m_sourceSize, attributeValue); | 234 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu
es->devicePixelRatio(), m_sourceSize, attributeValue); |
| 236 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem
ent); | 235 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem
ent); |
| 237 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { | 236 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { |
| 238 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l
ength(); | 237 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l
ength(); |
| 239 m_sourceSizeSet = true; | 238 m_sourceSizeSet = true; |
| 240 if (!m_srcsetImageCandidate.isEmpty()) { | 239 if (!m_srcsetImageCandidate.isEmpty()) { |
| 241 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); | 240 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); |
| 242 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl
acement); | 241 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl
acement); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 254 if (match(attributeName, hrefAttr)) { | 253 if (match(attributeName, hrefAttr)) { |
| 255 setUrlToLoad(attributeValue, DisallowURLReplacement); | 254 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 256 } else if (match(attributeName, relAttr)) { | 255 } else if (match(attributeName, relAttr)) { |
| 257 LinkRelAttribute rel(attributeValue); | 256 LinkRelAttribute rel(attributeValue); |
| 258 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel
.iconType() == InvalidIcon && !rel.isDNSPrefetch(); | 257 m_linkIsStyleSheet = rel.isStyleSheet() && !rel.isAlternate() && rel
.iconType() == InvalidIcon && !rel.isDNSPrefetch(); |
| 259 m_linkIsPreconnect = rel.isPreconnect(); | 258 m_linkIsPreconnect = rel.isPreconnect(); |
| 260 m_linkIsImport = rel.isImport(); | 259 m_linkIsImport = rel.isImport(); |
| 261 } else if (match(attributeName, mediaAttr)) { | 260 } else if (match(attributeName, mediaAttr)) { |
| 262 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr
ibuteValue); | 261 m_matchedMediaAttribute = mediaAttributeMatches(*m_mediaValues, attr
ibuteValue); |
| 263 } else if (match(attributeName, crossoriginAttr)) { | 262 } else if (match(attributeName, crossoriginAttr)) { |
| 264 setCrossOriginAllowed(attributeValue); | 263 setCrossOrigin(attributeValue); |
| 265 } | 264 } |
| 266 } | 265 } |
| 267 | 266 |
| 268 template<typename NameType> | 267 template<typename NameType> |
| 269 void processInputAttribute(const NameType& attributeName, const String& attr
ibuteValue) | 268 void processInputAttribute(const NameType& attributeName, const String& attr
ibuteValue) |
| 270 { | 269 { |
| 271 // FIXME - Don't set type multiple times. | 270 // FIXME - Don't set type multiple times. |
| 272 if (match(attributeName, srcAttr)) | 271 if (match(attributeName, srcAttr)) |
| 273 setUrlToLoad(attributeValue, DisallowURLReplacement); | 272 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 274 else if (match(attributeName, typeAttr)) | 273 else if (match(attributeName, typeAttr)) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 bool shouldPreload() const | 363 bool shouldPreload() const |
| 365 { | 364 { |
| 366 if (m_urlToLoad.isEmpty()) | 365 if (m_urlToLoad.isEmpty()) |
| 367 return false; | 366 return false; |
| 368 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport) | 367 if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport) |
| 369 return false; | 368 return false; |
| 370 if (match(m_tagImpl, inputTag) && !m_inputIsImage) | 369 if (match(m_tagImpl, inputTag) && !m_inputIsImage) |
| 371 return false; | 370 return false; |
| 372 return true; | 371 return true; |
| 373 } | 372 } |
| 374 | 373 void setCrossOrigin(const String& corsSetting) |
| 375 bool isCORSEnabled() const | |
| 376 { | 374 { |
| 377 return m_isCORSEnabled; | 375 m_crossOrigin = crossOriginAttributeValue(corsSetting); |
| 378 } | |
| 379 | |
| 380 StoredCredentials allowStoredCredentials() const | |
| 381 { | |
| 382 return m_allowCredentials; | |
| 383 } | |
| 384 | |
| 385 void setCrossOriginAllowed(const String& corsSetting) | |
| 386 { | |
| 387 m_isCORSEnabled = true; | |
| 388 if (!corsSetting.isNull() && equalIgnoringCase(stripLeadingAndTrailingHT
MLSpaces(corsSetting), "use-credentials")) | |
| 389 m_allowCredentials = AllowStoredCredentials; | |
| 390 else | |
| 391 m_allowCredentials = DoNotAllowStoredCredentials; | |
| 392 } | 376 } |
| 393 | 377 |
| 394 void setDefer(FetchRequest::DeferOption defer) | 378 void setDefer(FetchRequest::DeferOption defer) |
| 395 { | 379 { |
| 396 m_defer = defer; | 380 m_defer = defer; |
| 397 } | 381 } |
| 398 | 382 |
| 399 bool defer() const | 383 bool defer() const |
| 400 { | 384 { |
| 401 return m_defer; | 385 return m_defer; |
| 402 } | 386 } |
| 403 | 387 |
| 404 const StringImpl* m_tagImpl; | 388 const StringImpl* m_tagImpl; |
| 405 String m_urlToLoad; | 389 String m_urlToLoad; |
| 406 ImageCandidate m_srcsetImageCandidate; | 390 ImageCandidate m_srcsetImageCandidate; |
| 407 String m_charset; | 391 String m_charset; |
| 408 bool m_linkIsStyleSheet; | 392 bool m_linkIsStyleSheet; |
| 409 bool m_linkIsPreconnect; | 393 bool m_linkIsPreconnect; |
| 410 bool m_linkIsImport; | 394 bool m_linkIsImport; |
| 411 bool m_matchedMediaAttribute; | 395 bool m_matchedMediaAttribute; |
| 412 bool m_inputIsImage; | 396 bool m_inputIsImage; |
| 413 String m_imgSrcUrl; | 397 String m_imgSrcUrl; |
| 414 String m_srcsetAttributeValue; | 398 String m_srcsetAttributeValue; |
| 415 float m_sourceSize; | 399 float m_sourceSize; |
| 416 bool m_sourceSizeSet; | 400 bool m_sourceSizeSet; |
| 417 bool m_isCORSEnabled; | |
| 418 FetchRequest::DeferOption m_defer; | 401 FetchRequest::DeferOption m_defer; |
| 419 StoredCredentials m_allowCredentials; | 402 CrossOriginAttributeValue m_crossOrigin; |
| 420 RefPtrWillBeMember<MediaValues> m_mediaValues; | 403 RefPtrWillBeMember<MediaValues> m_mediaValues; |
| 421 bool m_referrerPolicySet; | 404 bool m_referrerPolicySet; |
| 422 ReferrerPolicy m_referrerPolicy; | 405 ReferrerPolicy m_referrerPolicy; |
| 423 }; | 406 }; |
| 424 | 407 |
| 425 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac
hedDocumentParameters> documentParameters) | 408 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassOwnPtr<Cac
hedDocumentParameters> documentParameters) |
| 426 : m_documentURL(documentURL) | 409 : m_documentURL(documentURL) |
| 427 , m_inStyle(false) | 410 , m_inStyle(false) |
| 428 , m_inPicture(false) | 411 , m_inPicture(false) |
| 429 , m_isAppCacheEnabled(false) | 412 , m_isAppCacheEnabled(false) |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 else | 653 else |
| 671 mediaValues = MediaValuesCached::create(*document); | 654 mediaValues = MediaValuesCached::create(*document); |
| 672 ASSERT(mediaValues->isSafeToSendToAnotherThread()); | 655 ASSERT(mediaValues->isSafeToSendToAnotherThread()); |
| 673 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 656 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
| 674 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); | 657 viewportMetaZeroValuesQuirk = document->settings() && document->settings()->
viewportMetaZeroValuesQuirk(); |
| 675 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); | 658 viewportMetaEnabled = document->settings() && document->settings()->viewport
MetaEnabled(); |
| 676 referrerPolicy = ReferrerPolicyDefault; | 659 referrerPolicy = ReferrerPolicyDefault; |
| 677 } | 660 } |
| 678 | 661 |
| 679 } | 662 } |
| OLD | NEW |