| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_matchedMediaAttribute(true) | 109 , m_matchedMediaAttribute(true) |
| 110 , m_inputIsImage(false) | 110 , m_inputIsImage(false) |
| 111 , m_sourceSize(0) | 111 , m_sourceSize(0) |
| 112 , m_sourceSizeSet(false) | 112 , m_sourceSizeSet(false) |
| 113 , m_isCORSEnabled(false) | 113 , m_isCORSEnabled(false) |
| 114 , m_execAsync(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, sourceTag)) { | 119 || match(m_tagImpl, sourceTag)) { |
| 119 if (RuntimeEnabledFeatures::pictureSizesEnabled()) | 120 if (RuntimeEnabledFeatures::pictureSizesEnabled()) |
| 120 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).len
gth(); | 121 m_sourceSize = SizesAttributeParser(m_mediaValues, String()).len
gth(); |
| 121 return; | 122 return; |
| 122 } | 123 } |
| 123 if ( !match(m_tagImpl, inputTag) | 124 if ( !match(m_tagImpl, inputTag) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 { | 164 { |
| 164 if (!shouldPreload() || !m_matchedMediaAttribute) | 165 if (!shouldPreload() || !m_matchedMediaAttribute) |
| 165 return nullptr; | 166 return nullptr; |
| 166 | 167 |
| 167 TRACE_EVENT_INSTANT1("net", "PreloadRequest", "url", m_urlToLoad.ascii()
); | 168 TRACE_EVENT_INSTANT1("net", "PreloadRequest", "url", m_urlToLoad.ascii()
); |
| 168 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); | 169 TextPosition position = TextPosition(source.currentLine(), source.curren
tColumn()); |
| 169 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType()); | 170 OwnPtr<PreloadRequest> request = PreloadRequest::create(initiatorFor(m_t
agImpl), position, m_urlToLoad, predictedBaseURL, resourceType()); |
| 170 if (isCORSEnabled()) | 171 if (isCORSEnabled()) |
| 171 request->setCrossOriginEnabled(allowStoredCredentials()); | 172 request->setCrossOriginEnabled(allowStoredCredentials()); |
| 172 request->setCharset(charset()); | 173 request->setCharset(charset()); |
| 174 request->setExecAsync(m_execAsync); |
| 173 return request.release(); | 175 return request.release(); |
| 174 } | 176 } |
| 175 | 177 |
| 176 private: | 178 private: |
| 177 template<typename NameType> | 179 template<typename NameType> |
| 178 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) | 180 void processScriptAttribute(const NameType& attributeName, const String& att
ributeValue) |
| 179 { | 181 { |
| 180 // FIXME - Don't set crossorigin multiple times. | 182 // FIXME - Don't set crossorigin multiple times. |
| 181 if (match(attributeName, srcAttr)) | 183 if (match(attributeName, srcAttr)) |
| 182 setUrlToLoad(attributeValue, DisallowURLReplacement); | 184 setUrlToLoad(attributeValue, DisallowURLReplacement); |
| 183 else if (match(attributeName, crossoriginAttr)) | 185 else if (match(attributeName, crossoriginAttr)) |
| 184 setCrossOriginAllowed(attributeValue); | 186 setCrossOriginAllowed(attributeValue); |
| 187 else if (match(attributeName, asyncAttr)) |
| 188 setExecAsync(true); |
| 189 else if (match(attributeName, deferAttr)) |
| 190 setExecAsync(true); |
| 185 } | 191 } |
| 186 | 192 |
| 187 template<typename NameType> | 193 template<typename NameType> |
| 188 void processImgAttribute(const NameType& attributeName, const String& attrib
uteValue) | 194 void processImgAttribute(const NameType& attributeName, const String& attrib
uteValue) |
| 189 { | 195 { |
| 190 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) { | 196 if (match(attributeName, srcAttr) && m_imgSrcUrl.isNull()) { |
| 191 m_imgSrcUrl = attributeValue; | 197 m_imgSrcUrl = attributeValue; |
| 192 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, attributeValue, m_srcsetImageCandidate), AllowURLRepla
cement); | 198 setUrlToLoad(bestFitSourceForImageAttributes(m_mediaValues->devicePi
xelRatio(), m_sourceSize, attributeValue, m_srcsetImageCandidate), AllowURLRepla
cement); |
| 193 } else if (match(attributeName, crossoriginAttr)) { | 199 } else if (match(attributeName, crossoriginAttr)) { |
| 194 setCrossOriginAllowed(attributeValue); | 200 setCrossOriginAllowed(attributeValue); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 336 |
| 331 void setCrossOriginAllowed(const String& corsSetting) | 337 void setCrossOriginAllowed(const String& corsSetting) |
| 332 { | 338 { |
| 333 m_isCORSEnabled = true; | 339 m_isCORSEnabled = true; |
| 334 if (!corsSetting.isNull() && equalIgnoringCase(stripLeadingAndTrailingHT
MLSpaces(corsSetting), "use-credentials")) | 340 if (!corsSetting.isNull() && equalIgnoringCase(stripLeadingAndTrailingHT
MLSpaces(corsSetting), "use-credentials")) |
| 335 m_allowCredentials = AllowStoredCredentials; | 341 m_allowCredentials = AllowStoredCredentials; |
| 336 else | 342 else |
| 337 m_allowCredentials = DoNotAllowStoredCredentials; | 343 m_allowCredentials = DoNotAllowStoredCredentials; |
| 338 } | 344 } |
| 339 | 345 |
| 346 void setExecAsync(const bool execAsync) |
| 347 { |
| 348 m_execAsync = execAsync; |
| 349 } |
| 350 |
| 351 bool execAsync() const |
| 352 { |
| 353 return m_execAsync; |
| 354 } |
| 355 |
| 340 const StringImpl* m_tagImpl; | 356 const StringImpl* m_tagImpl; |
| 341 String m_urlToLoad; | 357 String m_urlToLoad; |
| 342 ImageCandidate m_srcsetImageCandidate; | 358 ImageCandidate m_srcsetImageCandidate; |
| 343 String m_charset; | 359 String m_charset; |
| 344 bool m_linkIsStyleSheet; | 360 bool m_linkIsStyleSheet; |
| 345 bool m_matchedMediaAttribute; | 361 bool m_matchedMediaAttribute; |
| 346 bool m_inputIsImage; | 362 bool m_inputIsImage; |
| 347 String m_imgSrcUrl; | 363 String m_imgSrcUrl; |
| 348 String m_srcsetAttributeValue; | 364 String m_srcsetAttributeValue; |
| 349 unsigned m_sourceSize; | 365 unsigned m_sourceSize; |
| 350 bool m_sourceSizeSet; | 366 bool m_sourceSizeSet; |
| 351 bool m_isCORSEnabled; | 367 bool m_isCORSEnabled; |
| 368 bool m_execAsync; |
| 352 StoredCredentials m_allowCredentials; | 369 StoredCredentials m_allowCredentials; |
| 353 RefPtr<MediaValues> m_mediaValues; | 370 RefPtr<MediaValues> m_mediaValues; |
| 354 }; | 371 }; |
| 355 | 372 |
| 356 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med
iaValues> mediaValues) | 373 TokenPreloadScanner::TokenPreloadScanner(const KURL& documentURL, PassRefPtr<Med
iaValues> mediaValues) |
| 357 : m_documentURL(documentURL) | 374 : m_documentURL(documentURL) |
| 358 , m_inStyle(false) | 375 , m_inStyle(false) |
| 359 , m_inPicture(false) | 376 , m_inPicture(false) |
| 377 , m_isBeforeBody(true) |
| 360 , m_templateCount(0) | 378 , m_templateCount(0) |
| 361 , m_mediaValues(mediaValues) | 379 , m_mediaValues(mediaValues) |
| 362 { | 380 { |
| 363 } | 381 } |
| 364 | 382 |
| 365 TokenPreloadScanner::~TokenPreloadScanner() | 383 TokenPreloadScanner::~TokenPreloadScanner() |
| 366 { | 384 { |
| 367 } | 385 } |
| 368 | 386 |
| 369 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() | 387 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() |
| 370 { | 388 { |
| 371 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); | 389 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); |
| 372 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_temp
lateCount)); | 390 m_checkpoints.append(Checkpoint(m_predictedBaseElementURL, m_inStyle, m_isBe
foreBody, m_templateCount)); |
| 373 return checkpoint; | 391 return checkpoint; |
| 374 } | 392 } |
| 375 | 393 |
| 376 void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex
) | 394 void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex
) |
| 377 { | 395 { |
| 378 ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, che
ckpointIndex is invalid. | 396 ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, che
ckpointIndex is invalid. |
| 379 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; | 397 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; |
| 380 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; | 398 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; |
| 381 m_inStyle = checkpoint.inStyle; | 399 m_inStyle = checkpoint.inStyle; |
| 400 m_isBeforeBody = checkpoint.isBeforeBody; |
| 382 m_templateCount = checkpoint.templateCount; | 401 m_templateCount = checkpoint.templateCount; |
| 383 m_cssScanner.reset(); | 402 m_cssScanner.reset(); |
| 403 m_cssScanner.setIsBeforeBody(m_isBeforeBody); |
| 384 m_checkpoints.clear(); | 404 m_checkpoints.clear(); |
| 385 } | 405 } |
| 386 | 406 |
| 387 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests) | 407 void TokenPreloadScanner::scan(const HTMLToken& token, const SegmentedString& so
urce, PreloadRequestStream& requests) |
| 388 { | 408 { |
| 389 scanCommon(token, source, requests); | 409 scanCommon(token, source, requests); |
| 390 } | 410 } |
| 391 | 411 |
| 392 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests) | 412 void TokenPreloadScanner::scan(const CompactHTMLToken& token, const SegmentedStr
ing& source, PreloadRequestStream& requests) |
| 393 { | 413 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 return; | 446 return; |
| 427 const StringImpl* tagImpl = tagImplFor(token.data()); | 447 const StringImpl* tagImpl = tagImplFor(token.data()); |
| 428 if (match(tagImpl, templateTag)) { | 448 if (match(tagImpl, templateTag)) { |
| 429 ++m_templateCount; | 449 ++m_templateCount; |
| 430 return; | 450 return; |
| 431 } | 451 } |
| 432 if (match(tagImpl, styleTag)) { | 452 if (match(tagImpl, styleTag)) { |
| 433 m_inStyle = true; | 453 m_inStyle = true; |
| 434 return; | 454 return; |
| 435 } | 455 } |
| 456 if (m_isBeforeBody && match(tagImpl, bodyTag)) { |
| 457 m_isBeforeBody = false; |
| 458 m_cssScanner.setIsBeforeBody(m_isBeforeBody); |
| 459 } |
| 436 if (match(tagImpl, baseTag)) { | 460 if (match(tagImpl, baseTag)) { |
| 437 // The first <base> element is the one that wins. | 461 // The first <base> element is the one that wins. |
| 438 if (!m_predictedBaseElementURL.isEmpty()) | 462 if (!m_predictedBaseElementURL.isEmpty()) |
| 439 return; | 463 return; |
| 440 updatePredictedBaseURL(token); | 464 updatePredictedBaseURL(token); |
| 441 return; | 465 return; |
| 442 } | 466 } |
| 443 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT
ag))) { | 467 if (RuntimeEnabledFeatures::pictureEnabled() && (match(tagImpl, pictureT
ag))) { |
| 444 m_inPicture = true; | 468 m_inPicture = true; |
| 445 m_pictureSourceURL = String(); | 469 m_pictureSourceURL = String(); |
| 446 return; | 470 return; |
| 447 } | 471 } |
| 448 | 472 |
| 449 StartTagScanner scanner(tagImpl, m_mediaValues); | 473 StartTagScanner scanner(tagImpl, m_mediaValues); |
| 450 scanner.processAttributes(token.attributes()); | 474 scanner.processAttributes(token.attributes()); |
| 451 if (m_inPicture) | 475 if (m_inPicture) |
| 452 scanner.handlePictureSourceURL(m_pictureSourceURL); | 476 scanner.handlePictureSourceURL(m_pictureSourceURL); |
| 453 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source); | 477 OwnPtr<PreloadRequest> request = scanner.createPreloadRequest(m_predicte
dBaseElementURL, source); |
| 454 if (request) | 478 if (request) { |
| 479 request->setIsBeforeBody(m_isBeforeBody); |
| 455 requests.append(request.release()); | 480 requests.append(request.release()); |
| 481 } |
| 456 return; | 482 return; |
| 457 } | 483 } |
| 458 default: { | 484 default: { |
| 459 return; | 485 return; |
| 460 } | 486 } |
| 461 } | 487 } |
| 462 } | 488 } |
| 463 | 489 |
| 464 template<typename Token> | 490 template<typename Token> |
| 465 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) | 491 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 if (m_token.type() == HTMLToken::StartTag) | 526 if (m_token.type() == HTMLToken::StartTag) |
| 501 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); | 527 m_tokenizer->updateStateFor(attemptStaticStringCreation(m_token.name
(), Likely8Bit)); |
| 502 m_scanner.scan(m_token, m_source, requests); | 528 m_scanner.scan(m_token, m_source, requests); |
| 503 m_token.clear(); | 529 m_token.clear(); |
| 504 } | 530 } |
| 505 | 531 |
| 506 preloader->takeAndPreload(requests); | 532 preloader->takeAndPreload(requests); |
| 507 } | 533 } |
| 508 | 534 |
| 509 } | 535 } |
| OLD | NEW |