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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 using namespace HTMLNames; | 82 using namespace HTMLNames; |
83 | 83 |
84 static bool match(const StringImpl* impl, const QualifiedName& qName) { | 84 static bool match(const StringImpl* impl, const QualifiedName& qName) { |
85 return impl == qName.localName().impl(); | 85 return impl == qName.localName().impl(); |
86 } | 86 } |
87 | 87 |
88 static bool match(const AtomicString& name, const QualifiedName& qName) { | 88 static bool match(const AtomicString& name, const QualifiedName& qName) { |
89 ASSERT(isMainThread()); | 89 DCHECK(isMainThread()); |
90 return qName.localName() == name; | 90 return qName.localName() == name; |
91 } | 91 } |
92 | 92 |
93 static bool match(const String& name, const QualifiedName& qName) { | 93 static bool match(const String& name, const QualifiedName& qName) { |
94 return threadSafeMatch(name, qName); | 94 return threadSafeMatch(name, qName); |
95 } | 95 } |
96 | 96 |
97 static const StringImpl* tagImplFor(const HTMLToken::DataVector& data) { | 97 static const StringImpl* tagImplFor(const HTMLToken::DataVector& data) { |
98 AtomicString tagName(data); | 98 AtomicString tagName(data); |
99 const StringImpl* result = tagName.impl(); | 99 const StringImpl* result = tagName.impl(); |
100 if (result->isStatic()) | 100 if (result->isStatic()) |
101 return result; | 101 return result; |
102 return nullptr; | 102 return nullptr; |
103 } | 103 } |
104 | 104 |
105 static const StringImpl* tagImplFor(const String& tagName) { | 105 static const StringImpl* tagImplFor(const String& tagName) { |
106 const StringImpl* result = tagName.impl(); | 106 const StringImpl* result = tagName.impl(); |
107 if (result->isStatic()) | 107 if (result->isStatic()) |
108 return result; | 108 return result; |
109 return nullptr; | 109 return nullptr; |
110 } | 110 } |
111 | 111 |
112 static String initiatorFor(const StringImpl* tagImpl) { | 112 static String initiatorFor(const StringImpl* tagImpl) { |
113 ASSERT(tagImpl); | 113 DCHECK(tagImpl); |
114 if (match(tagImpl, imgTag)) | 114 if (match(tagImpl, imgTag)) |
115 return imgTag.localName(); | 115 return imgTag.localName(); |
116 if (match(tagImpl, inputTag)) | 116 if (match(tagImpl, inputTag)) |
117 return inputTag.localName(); | 117 return inputTag.localName(); |
118 if (match(tagImpl, linkTag)) | 118 if (match(tagImpl, linkTag)) |
119 return linkTag.localName(); | 119 return linkTag.localName(); |
120 if (match(tagImpl, scriptTag)) | 120 if (match(tagImpl, scriptTag)) |
121 return scriptTag.localName(); | 121 return scriptTag.localName(); |
122 if (match(tagImpl, videoTag)) | 122 if (match(tagImpl, videoTag)) |
123 return videoTag.localName(); | 123 return videoTag.localName(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return; | 156 return; |
157 } | 157 } |
158 if (!match(m_tagImpl, inputTag) && !match(m_tagImpl, linkTag) && | 158 if (!match(m_tagImpl, inputTag) && !match(m_tagImpl, linkTag) && |
159 !match(m_tagImpl, scriptTag) && !match(m_tagImpl, videoTag)) | 159 !match(m_tagImpl, scriptTag) && !match(m_tagImpl, videoTag)) |
160 m_tagImpl = 0; | 160 m_tagImpl = 0; |
161 } | 161 } |
162 | 162 |
163 enum URLReplacement { AllowURLReplacement, DisallowURLReplacement }; | 163 enum URLReplacement { AllowURLReplacement, DisallowURLReplacement }; |
164 | 164 |
165 void processAttributes(const HTMLToken::AttributeList& attributes) { | 165 void processAttributes(const HTMLToken::AttributeList& attributes) { |
166 ASSERT(isMainThread()); | 166 DCHECK(isMainThread()); |
167 if (!m_tagImpl) | 167 if (!m_tagImpl) |
168 return; | 168 return; |
169 for (const HTMLToken::Attribute& htmlTokenAttribute : attributes) { | 169 for (const HTMLToken::Attribute& htmlTokenAttribute : attributes) { |
170 AtomicString attributeName(htmlTokenAttribute.name()); | 170 AtomicString attributeName(htmlTokenAttribute.name()); |
171 String attributeValue = htmlTokenAttribute.value8BitIfNecessary(); | 171 String attributeValue = htmlTokenAttribute.value8BitIfNecessary(); |
172 processAttribute(attributeName, attributeValue); | 172 processAttribute(attributeName, attributeValue); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void processAttributes( | 176 void processAttributes( |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() { | 584 TokenPreloadScannerCheckpoint TokenPreloadScanner::createCheckpoint() { |
585 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); | 585 TokenPreloadScannerCheckpoint checkpoint = m_checkpoints.size(); |
586 m_checkpoints.push_back(Checkpoint(m_predictedBaseElementURL, m_inStyle, | 586 m_checkpoints.push_back(Checkpoint(m_predictedBaseElementURL, m_inStyle, |
587 m_inScript, m_templateCount)); | 587 m_inScript, m_templateCount)); |
588 return checkpoint; | 588 return checkpoint; |
589 } | 589 } |
590 | 590 |
591 void TokenPreloadScanner::rewindTo( | 591 void TokenPreloadScanner::rewindTo( |
592 TokenPreloadScannerCheckpoint checkpointIndex) { | 592 TokenPreloadScannerCheckpoint checkpointIndex) { |
593 // If this ASSERT fires, checkpointIndex is invalid. | 593 // If this ASSERT fires, checkpointIndex is invalid. |
594 ASSERT(checkpointIndex < m_checkpoints.size()); | 594 DCHECK_LT(checkpointIndex, m_checkpoints.size()); |
595 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; | 595 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; |
596 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; | 596 m_predictedBaseElementURL = checkpoint.predictedBaseElementURL; |
597 m_inStyle = checkpoint.inStyle; | 597 m_inStyle = checkpoint.inStyle; |
598 m_templateCount = checkpoint.templateCount; | 598 m_templateCount = checkpoint.templateCount; |
599 | 599 |
600 m_didRewind = true; | 600 m_didRewind = true; |
601 m_inScript = checkpoint.inScript; | 601 m_inScript = checkpoint.inScript; |
602 | 602 |
603 m_cssScanner.reset(); | 603 m_cssScanner.reset(); |
604 m_checkpoints.clear(); | 604 m_checkpoints.clear(); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 if (request) | 850 if (request) |
851 requests.push_back(std::move(request)); | 851 requests.push_back(std::move(request)); |
852 return; | 852 return; |
853 } | 853 } |
854 default: { return; } | 854 default: { return; } |
855 } | 855 } |
856 } | 856 } |
857 | 857 |
858 template <typename Token> | 858 template <typename Token> |
859 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) { | 859 void TokenPreloadScanner::updatePredictedBaseURL(const Token& token) { |
860 ASSERT(m_predictedBaseElementURL.isEmpty()); | 860 DCHECK(m_predictedBaseElementURL.isEmpty()); |
861 if (const typename Token::Attribute* hrefAttribute = | 861 if (const typename Token::Attribute* hrefAttribute = |
862 token.getAttributeItem(hrefAttr)) { | 862 token.getAttributeItem(hrefAttr)) { |
863 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces( | 863 KURL url(m_documentURL, stripLeadingAndTrailingHTMLSpaces( |
864 hrefAttribute->value8BitIfNecessary())); | 864 hrefAttribute->value8BitIfNecessary())); |
865 m_predictedBaseElementURL = | 865 m_predictedBaseElementURL = |
866 url.isValid() && !url.protocolIsData() ? url.copy() : KURL(); | 866 url.isValid() && !url.protocolIsData() ? url.copy() : KURL(); |
867 } | 867 } |
868 } | 868 } |
869 | 869 |
870 HTMLPreloadScanner::HTMLPreloadScanner( | 870 HTMLPreloadScanner::HTMLPreloadScanner( |
871 const HTMLParserOptions& options, | 871 const HTMLParserOptions& options, |
872 const KURL& documentURL, | 872 const KURL& documentURL, |
873 std::unique_ptr<CachedDocumentParameters> documentParameters, | 873 std::unique_ptr<CachedDocumentParameters> documentParameters, |
874 const MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData) | 874 const MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData) |
875 : m_scanner(documentURL, | 875 : m_scanner(documentURL, |
876 std::move(documentParameters), | 876 std::move(documentParameters), |
877 mediaValuesCachedData), | 877 mediaValuesCachedData), |
878 m_tokenizer(HTMLTokenizer::create(options)) {} | 878 m_tokenizer(HTMLTokenizer::create(options)) {} |
879 | 879 |
880 HTMLPreloadScanner::~HTMLPreloadScanner() {} | 880 HTMLPreloadScanner::~HTMLPreloadScanner() {} |
881 | 881 |
882 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) { | 882 void HTMLPreloadScanner::appendToEnd(const SegmentedString& source) { |
883 m_source.append(source); | 883 m_source.append(source); |
884 } | 884 } |
885 | 885 |
886 PreloadRequestStream HTMLPreloadScanner::scan( | 886 PreloadRequestStream HTMLPreloadScanner::scan( |
887 const KURL& startingBaseElementURL, | 887 const KURL& startingBaseElementURL, |
888 ViewportDescriptionWrapper* viewport) { | 888 ViewportDescriptionWrapper* viewport) { |
889 // HTMLTokenizer::updateStateFor only works on the main thread. | 889 // HTMLTokenizer::updateStateFor only works on the main thread. |
890 ASSERT(isMainThread()); | 890 DCHECK(isMainThread()); |
891 | 891 |
892 TRACE_EVENT1("blink", "HTMLPreloadScanner::scan", "source_length", | 892 TRACE_EVENT1("blink", "HTMLPreloadScanner::scan", "source_length", |
893 m_source.length()); | 893 m_source.length()); |
894 | 894 |
895 // When we start scanning, our best prediction of the baseElementURL is the | 895 // When we start scanning, our best prediction of the baseElementURL is the |
896 // real one! | 896 // real one! |
897 if (!startingBaseElementURL.isEmpty()) | 897 if (!startingBaseElementURL.isEmpty()) |
898 m_scanner.setPredictedBaseElementURL(startingBaseElementURL); | 898 m_scanner.setPredictedBaseElementURL(startingBaseElementURL); |
899 | 899 |
900 PreloadRequestStream requests; | 900 PreloadRequestStream requests; |
901 | 901 |
902 while (m_tokenizer->nextToken(m_source, m_token)) { | 902 while (m_tokenizer->nextToken(m_source, m_token)) { |
903 if (m_token.type() == HTMLToken::StartTag) | 903 if (m_token.type() == HTMLToken::StartTag) |
904 m_tokenizer->updateStateFor( | 904 m_tokenizer->updateStateFor( |
905 attemptStaticStringCreation(m_token.name(), Likely8Bit)); | 905 attemptStaticStringCreation(m_token.name(), Likely8Bit)); |
906 bool isCSPMetaTag = false; | 906 bool isCSPMetaTag = false; |
907 m_scanner.scan(m_token, m_source, requests, viewport, &isCSPMetaTag); | 907 m_scanner.scan(m_token, m_source, requests, viewport, &isCSPMetaTag); |
908 m_token.clear(); | 908 m_token.clear(); |
909 // Don't preload anything if a CSP meta tag is found. We should never really | 909 // Don't preload anything if a CSP meta tag is found. We should never really |
910 // find them here because the HTMLPreloadScanner is only used for | 910 // find them here because the HTMLPreloadScanner is only used for |
911 // dynamically added markup. | 911 // dynamically added markup. |
912 if (isCSPMetaTag) | 912 if (isCSPMetaTag) |
913 return requests; | 913 return requests; |
914 } | 914 } |
915 | 915 |
916 return requests; | 916 return requests; |
917 } | 917 } |
918 | 918 |
919 CachedDocumentParameters::CachedDocumentParameters(Document* document) { | 919 CachedDocumentParameters::CachedDocumentParameters(Document* document) { |
920 ASSERT(isMainThread()); | 920 DCHECK(isMainThread()); |
921 ASSERT(document); | 921 DCHECK(document); |
922 doHtmlPreloadScanning = | 922 doHtmlPreloadScanning = |
923 !document->settings() || document->settings()->getDoHtmlPreloadScanning(); | 923 !document->settings() || document->settings()->getDoHtmlPreloadScanning(); |
924 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && | 924 doDocumentWritePreloadScanning = doHtmlPreloadScanning && document->frame() && |
925 document->frame()->isMainFrame(); | 925 document->frame()->isMainFrame(); |
926 defaultViewportMinWidth = document->viewportDefaultMinWidth(); | 926 defaultViewportMinWidth = document->viewportDefaultMinWidth(); |
927 viewportMetaZeroValuesQuirk = | 927 viewportMetaZeroValuesQuirk = |
928 document->settings() && | 928 document->settings() && |
929 document->settings()->getViewportMetaZeroValuesQuirk(); | 929 document->settings()->getViewportMetaZeroValuesQuirk(); |
930 viewportMetaEnabled = | 930 viewportMetaEnabled = |
931 document->settings() && document->settings()->getViewportMetaEnabled(); | 931 document->settings() && document->settings()->getViewportMetaEnabled(); |
932 referrerPolicy = document->getReferrerPolicy(); | 932 referrerPolicy = document->getReferrerPolicy(); |
933 } | 933 } |
934 | 934 |
935 } // namespace blink | 935 } // namespace blink |
OLD | NEW |