| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 class TokenPreloadScanner::StartTagScanner { | 106 class TokenPreloadScanner::StartTagScanner { |
| 107 public: | 107 public: |
| 108 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu
es) | 108 StartTagScanner(const StringImpl* tagImpl, PassRefPtr<MediaValues> mediaValu
es) |
| 109 : m_tagImpl(tagImpl) | 109 : m_tagImpl(tagImpl) |
| 110 , m_linkIsStyleSheet(false) | 110 , m_linkIsStyleSheet(false) |
| 111 , m_matchedMediaAttribute(true) | 111 , m_matchedMediaAttribute(true) |
| 112 , m_inputIsImage(false) | 112 , m_inputIsImage(false) |
| 113 , m_sourceSize(0) | 113 , m_sourceSize(0) |
| 114 , m_sourceSizeSet(false) | 114 , m_sourceSizeSet(false) |
| 115 , m_resourceWidth(-1) |
| 115 , m_isCORSEnabled(false) | 116 , m_isCORSEnabled(false) |
| 116 , m_defer(FetchRequest::NoDefer) | 117 , m_defer(FetchRequest::NoDefer) |
| 117 , m_allowCredentials(DoNotAllowStoredCredentials) | 118 , m_allowCredentials(DoNotAllowStoredCredentials) |
| 118 , m_mediaValues(mediaValues) | 119 , m_mediaValues(mediaValues) |
| 119 { | 120 { |
| 120 if (match(m_tagImpl, imgTag) | 121 if (match(m_tagImpl, imgTag) |
| 121 || match(m_tagImpl, sourceTag)) { | 122 || match(m_tagImpl, sourceTag)) { |
| 122 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length(
); | 123 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).length(
); |
| 123 return; | 124 return; |
| 124 } | 125 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 else if (match(m_tagImpl, imgTag) && !sourceURL.isEmpty()) | 162 else if (match(m_tagImpl, imgTag) && !sourceURL.isEmpty()) |
| 162 setUrlToLoad(sourceURL, AllowURLReplacement); | 163 setUrlToLoad(sourceURL, AllowURLReplacement); |
| 163 } | 164 } |
| 164 | 165 |
| 165 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source) | 166 PassOwnPtr<PreloadRequest> createPreloadRequest(const KURL& predictedBaseURL
, const SegmentedString& source) |
| 166 { | 167 { |
| 167 if (!shouldPreload() || !m_matchedMediaAttribute) | 168 if (!shouldPreload() || !m_matchedMediaAttribute) |
| 168 return nullptr; | 169 return nullptr; |
| 169 | 170 |
| 170 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); | 171 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); |
| 171 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType()); | 172 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType(), m_resourceWidt
h); |
| 172 if (isCORSEnabled()) | 173 if (isCORSEnabled()) |
| 173 request->setCrossOriginEnabled(allowStoredCredentials()); | 174 request->setCrossOriginEnabled(allowStoredCredentials()); |
| 174 request->setCharset(charset()); | 175 request->setCharset(charset()); |
| 175 request->setDefer(m_defer); | 176 request->setDefer(m_defer); |
| 176 return request.release(); | 177 return request.release(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 private: | 180 private: |
| 180 template<typename NameType> | 181 template<typename NameType> |
| 181 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) | 182 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 202 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidate.is
Empty()) { | 203 } else if (match(attributeName, srcsetAttr) && m_srcsetImageCandidate.is
Empty()) { |
| 203 m_srcsetAttributeValue = attributeValue; | 204 m_srcsetAttributeValue = attributeValue; |
| 204 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu
es->devicePixelRatio(), m_sourceSize, attributeValue); | 205 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_mediaValu
es->devicePixelRatio(), m_sourceSize, attributeValue); |
| 205 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem
ent); | 206 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLReplacem
ent); |
| 206 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { | 207 } else if (match(attributeName, sizesAttr) && !m_sourceSizeSet) { |
| 207 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l
ength(); | 208 m_sourceSize = SizesAttributeParser(m_mediaValues, attributeValue).l
ength(); |
| 208 m_sourceSizeSet = true; | 209 m_sourceSizeSet = true; |
| 209 if (!m_srcsetImageCandidate.isEmpty()) { | 210 if (!m_srcsetImageCandidate.isEmpty()) { |
| 210 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); | 211 m_srcsetImageCandidate = bestFitSourceForSrcsetAttribute(m_media
Values->devicePixelRatio(), m_sourceSize, m_srcsetAttributeValue); |
| 211 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl
acement); | 212 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devi
cePixelRatio(), m_sourceSize, m_imgSrcUrl, m_srcsetImageCandidate), AllowURLRepl
acement); |
| 213 } else { |
| 214 m_resourceWidth = m_sourceSize; |
| 212 } | 215 } |
| 213 } | 216 } |
| 214 } | 217 } |
| 215 | 218 |
| 216 template<typename NameType> | 219 template<typename NameType> |
| 217 void processLinkAttribute(const NameType& attributeName, const String& attri
buteValue) | 220 void processLinkAttribute(const NameType& attributeName, const String& attri
buteValue) |
| 218 { | 221 { |
| 219 // FIXME - Don't set rel/media/crossorigin multiple times. | 222 // FIXME - Don't set rel/media/crossorigin multiple times. |
| 220 if (match(attributeName, hrefAttr)) | 223 if (match(attributeName, hrefAttr)) |
| 221 setUrlToLoad(attributeValue, DisallowURLReplacement); | 224 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 String m_urlToLoad; | 369 String m_urlToLoad; |
| 367 ImageCandidate m_srcsetImageCandidate; | 370 ImageCandidate m_srcsetImageCandidate; |
| 368 String m_charset; | 371 String m_charset; |
| 369 bool m_linkIsStyleSheet; | 372 bool m_linkIsStyleSheet; |
| 370 bool m_matchedMediaAttribute; | 373 bool m_matchedMediaAttribute; |
| 371 bool m_inputIsImage; | 374 bool m_inputIsImage; |
| 372 String m_imgSrcUrl; | 375 String m_imgSrcUrl; |
| 373 String m_srcsetAttributeValue; | 376 String m_srcsetAttributeValue; |
| 374 unsigned m_sourceSize; | 377 unsigned m_sourceSize; |
| 375 bool m_sourceSizeSet; | 378 bool m_sourceSizeSet; |
| 379 int m_resourceWidth; |
| 376 bool m_isCORSEnabled; | 380 bool m_isCORSEnabled; |
| 377 FetchRequest::DeferOption m_defer; | 381 FetchRequest::DeferOption m_defer; |
| 378 StoredCredentials m_allowCredentials; | 382 StoredCredentials m_allowCredentials; |
| 379 RefPtr<MediaValues> m_mediaValues; | 383 RefPtr<MediaValues> m_mediaValues; |
| 380 }; | 384 }; |
| 381 | 385 |
| 382 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med
iaValues> mediaValues) | 386 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med
iaValues> mediaValues) |
| 383 : m_documentURL(documentURL) | 387 : m_documentURL(documentURL) |
| 384 , m_inStyle(false) | 388 , m_inStyle(false) |
| 385 , m_inPicture(false) | 389 , m_inPicture(false) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (m_token.type() == HTMLToken::StartTag) | 556 if (m_token.type() == HTMLToken::StartTag) |
| 553 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 557 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
| 554 m_scanner.scan(m_token, m_source, requests); | 558 m_scanner.scan(m_token, m_source, requests); |
| 555 m_token.clear(); | 559 m_token.clear(); |
| 556 } | 560 } |
| 557 | 561 |
| 558 preloader->takeAndPreload(requests); | 562 preloader->takeAndPreload(requests); |
| 559 } | 563 } |
| 560 | 564 |
| 561 } | 565 } |
| OLD | NEW |