Chromium Code Reviews| 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 }; | 530 }; |
| 531 | 531 |
| 532 TokenPreloadScanner::TokenPreloadScanner( | 532 TokenPreloadScanner::TokenPreloadScanner( |
| 533 const KURL& documentURL, | 533 const KURL& documentURL, |
| 534 std::unique_ptr<CachedDocumentParameters> documentParameters, | 534 std::unique_ptr<CachedDocumentParameters> documentParameters, |
| 535 const MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData) | 535 const MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData) |
| 536 : m_documentURL(documentURL), | 536 : m_documentURL(documentURL), |
| 537 m_inStyle(false), | 537 m_inStyle(false), |
| 538 m_inPicture(false), | 538 m_inPicture(false), |
| 539 m_inScript(false), | 539 m_inScript(false), |
| 540 m_isAppCacheEnabled(false), | |
| 540 m_templateCount(0), | 541 m_templateCount(0), |
| 541 m_documentParameters(std::move(documentParameters)), | 542 m_documentParameters(std::move(documentParameters)), |
| 542 m_mediaValues(MediaValuesCached::create(mediaValuesCachedData)), | 543 m_mediaValues(MediaValuesCached::create(mediaValuesCachedData)), |
| 543 m_didRewind(false) { | 544 m_didRewind(false) { |
| 544 DCHECK(m_documentParameters.get()); | 545 DCHECK(m_documentParameters.get()); |
| 545 DCHECK(m_mediaValues.get()); | 546 DCHECK(m_mediaValues.get()); |
| 546 DCHECK(documentURL.isValid()); | 547 DCHECK(documentURL.isValid()); |
| 547 m_cssScanner.setReferrerPolicy(m_documentParameters->referrerPolicy); | 548 m_cssScanner.setReferrerPolicy(m_documentParameters->referrerPolicy); |
| 548 } | 549 } |
| 549 | 550 |
| 550 TokenPreloadScanner::~TokenPreloadScanner() {} | 551 TokenPreloadScanner::~TokenPreloadScanner() {} |
| 551 | 552 |
| 552 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() { | 553 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() { |
| 553 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); | 554 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); |
| 554 m_checkpoints.push_back(Checkpoint(m_predictedBaseElementURL, m_inStyle, | 555 m_checkpoints.push_back(Checkpoint(m_predictedBaseElementURL, m_inStyle, |
| 555 m_inScript, m_templateCount)); | 556 m_inScript, m_isAppCacheEnabled, |
| 557 m_templateCount)); | |
| 556 return checkpoint; | 558 return checkpoint; |
| 557 } | 559 } |
| 558 | 560 |
| 559 void TokenPreloadScanner::rewindTo( | 561 void TokenPreloadScanner::rewindTo( |
| 560 TokenPreloadScannerCheckpoint checkpointIndex) { | 562 TokenPreloadScannerCheckpoint checkpointIndex) { |
| 561 // If this ASSERT fires, checkpointIndex is invalid. | 563 // If this ASSERT fires, checkpointIndex is invalid. |
| 562 ASSERT(checkpointIndex < m_checkpoints.size()); | 564 ASSERT(checkpointIndex < m_checkpoints.size()); |
| 563 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; | 565 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; |
| 564 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; | 566 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; |
| 565 m_inStyle = checkpoint.inStyle; | 567 m_inStyle = checkpoint.inStyle; |
| 568 m_isAppCacheEnabled = checkpoint.isAppCacheEnabled; | |
| 566 m_templateCount = checkpoint.templateCount; | 569 m_templateCount = checkpoint.templateCount; |
| 567 | 570 |
| 568 m_didRewind = true; | 571 m_didRewind = true; |
| 569 m_inScript = checkpoint.inScript; | 572 m_inScript = checkpoint.inScript; |
| 570 | 573 |
| 571 m_cssScanner.reset(); | 574 m_cssScanner.reset(); |
| 572 m_checkpoints.clear(); | 575 m_checkpoints.clear(); |
| 573 } | 576 } |
| 574 | 577 |
| 575 void TokenPreloadScanner::scan(const HTMLToken& token, | 578 void TokenPreloadScanner::scan(const HTMLToken& token, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 template <typename Token> | 711 template <typename Token> |
| 709 void TokenPreloadScanner::scanCommon(const Token& token, | 712 void TokenPreloadScanner::scanCommon(const Token& token, |
| 710 const SegmentedString& source, | 713 const SegmentedString& source, |
| 711 PreloadRequestStream& requests, | 714 PreloadRequestStream& requests, |
| 712 ViewportDescriptionWrapper* viewport, | 715 ViewportDescriptionWrapper* viewport, |
| 713 bool* isCSPMetaTag, | 716 bool* isCSPMetaTag, |
| 714 bool* likelyDocumentWriteScript) { | 717 bool* likelyDocumentWriteScript) { |
| 715 if (!m_documentParameters->doHtmlPreloadScanning) | 718 if (!m_documentParameters->doHtmlPreloadScanning) |
| 716 return; | 719 return; |
| 717 | 720 |
| 721 // If the document is prefetching, AppCache support has not yet been enabled, | |
| 722 // and fetches will go to the network even if there is an AppCache | |
| 723 // manifest. Therefore if a manifest is seen prefetching is stopped to avoid | |
| 724 // incorrect behavior. | |
| 725 if (m_documentParameters->isPrefetchOnly && m_isAppCacheEnabled) | |
|
michaeln
2017/03/27 23:27:44
Could this be done more directly and with less cod
| |
| 726 return; | |
| 727 | |
| 718 switch (token.type()) { | 728 switch (token.type()) { |
| 719 case HTMLToken::Character: { | 729 case HTMLToken::Character: { |
| 720 if (m_inStyle) { | 730 if (m_inStyle) { |
| 721 m_cssScanner.scan(token.data(), source, requests, | 731 m_cssScanner.scan(token.data(), source, requests, |
| 722 m_predictedBaseElementURL); | 732 m_predictedBaseElementURL); |
| 723 } else if (m_inScript && likelyDocumentWriteScript && !m_didRewind) { | 733 } else if (m_inScript && likelyDocumentWriteScript && !m_didRewind) { |
| 724 // Don't mark scripts for evaluation if the preloader rewound to a | 734 // Don't mark scripts for evaluation if the preloader rewound to a |
| 725 // previous checkpoint. This could cause re-evaluation of scripts if | 735 // previous checkpoint. This could cause re-evaluation of scripts if |
| 726 // care isn't given. | 736 // care isn't given. |
| 727 // TODO(csharrison): Revisit this if rewinds are low hanging fruit for | 737 // TODO(csharrison): Revisit this if rewinds are low hanging fruit for |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 if (match(tagImpl, scriptTag)) { | 779 if (match(tagImpl, scriptTag)) { |
| 770 m_inScript = true; | 780 m_inScript = true; |
| 771 } | 781 } |
| 772 if (match(tagImpl, baseTag)) { | 782 if (match(tagImpl, baseTag)) { |
| 773 // The first <base> element is the one that wins. | 783 // The first <base> element is the one that wins. |
| 774 if (!m_predictedBaseElementURL.isEmpty()) | 784 if (!m_predictedBaseElementURL.isEmpty()) |
| 775 return; | 785 return; |
| 776 updatePredictedBaseURL(token); | 786 updatePredictedBaseURL(token); |
| 777 return; | 787 return; |
| 778 } | 788 } |
| 789 if (match(tagImpl, htmlTag) && token.getAttributeItem(manifestAttr)) { | |
| 790 m_isAppCacheEnabled = true; | |
| 791 return; | |
| 792 } | |
| 779 if (match(tagImpl, metaTag)) { | 793 if (match(tagImpl, metaTag)) { |
| 780 const typename Token::Attribute* equivAttribute = | 794 const typename Token::Attribute* equivAttribute = |
| 781 token.getAttributeItem(http_equivAttr); | 795 token.getAttributeItem(http_equivAttr); |
| 782 if (equivAttribute) { | 796 if (equivAttribute) { |
| 783 String equivAttributeValue(equivAttribute->value()); | 797 String equivAttributeValue(equivAttribute->value()); |
| 784 if (equalIgnoringCase(equivAttributeValue, | 798 if (equalIgnoringCase(equivAttributeValue, |
| 785 "content-security-policy")) { | 799 "content-security-policy")) { |
| 786 *isCSPMetaTag = true; | 800 *isCSPMetaTag = true; |
| 787 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch")) { | 801 } else if (equalIgnoringCase(equivAttributeValue, "accept-ch")) { |
| 788 const typename Token::Attribute* contentAttribute = | 802 const typename Token::Attribute* contentAttribute = |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 !document->settings() || document->settings()->getDoHtmlPreloadScanning(); | 903 !document->settings() || document->settings()->getDoHtmlPreloadScanning(); |
| 890 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && | 904 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && |
| 891 document->frame()->isMainFrame(); | 905 document->frame()->isMainFrame(); |
| 892 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 906 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
| 893 viewportMetaZeroValuesQuirk = | 907 viewportMetaZeroValuesQuirk = |
| 894 document->settings() && | 908 document->settings() && |
| 895 document->settings()->getViewportMetaZeroValuesQuirk(); | 909 document->settings()->getViewportMetaZeroValuesQuirk(); |
| 896 viewportMetaEnabled = | 910 viewportMetaEnabled = |
| 897 document->settings() && document->settings()->getViewportMetaEnabled(); | 911 document->settings() && document->settings()->getViewportMetaEnabled(); |
| 898 referrerPolicy = document->getReferrerPolicy(); | 912 referrerPolicy = document->getReferrerPolicy(); |
| 913 isPrefetchOnly = document->isPrefetchOnly(); | |
| 899 } | 914 } |
| 900 | 915 |
| 901 } // namespace blink | 916 } // namespace blink |
| OLD | NEW |