OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "core/html/parser/HTMLSourceTracker.h" | 40 #include "core/html/parser/HTMLSourceTracker.h" |
41 #include "core/html/parser/HTMLToken.h" | 41 #include "core/html/parser/HTMLToken.h" |
42 #include "core/html/parser/HTMLTokenizer.h" | 42 #include "core/html/parser/HTMLTokenizer.h" |
43 #include "core/html/parser/HTMLTreeBuilderSimulator.h" | 43 #include "core/html/parser/HTMLTreeBuilderSimulator.h" |
44 #include "core/html/parser/ParserSynchronizationPolicy.h" | 44 #include "core/html/parser/ParserSynchronizationPolicy.h" |
45 #include "core/html/parser/TextResourceDecoder.h" | 45 #include "core/html/parser/TextResourceDecoder.h" |
46 #include "core/html/parser/XSSAuditor.h" | 46 #include "core/html/parser/XSSAuditor.h" |
47 #include "core/html/parser/XSSAuditorDelegate.h" | 47 #include "core/html/parser/XSSAuditorDelegate.h" |
48 #include "platform/text/SegmentedString.h" | 48 #include "platform/text/SegmentedString.h" |
49 #include "wtf/Deque.h" | 49 #include "wtf/Deque.h" |
50 #include "wtf/OwnPtr.h" | |
51 #include "wtf/WeakPtr.h" | 50 #include "wtf/WeakPtr.h" |
52 #include "wtf/text/TextPosition.h" | 51 #include "wtf/text/TextPosition.h" |
| 52 #include <memory> |
53 | 53 |
54 namespace blink { | 54 namespace blink { |
55 | 55 |
56 class BackgroundHTMLParser; | 56 class BackgroundHTMLParser; |
57 class CompactHTMLToken; | 57 class CompactHTMLToken; |
58 class Document; | 58 class Document; |
59 class DocumentEncodingData; | 59 class DocumentEncodingData; |
60 class DocumentFragment; | 60 class DocumentFragment; |
61 class Element; | 61 class Element; |
62 class HTMLDocument; | 62 class HTMLDocument; |
(...skipping 24 matching lines...) Expand all Loading... |
87 TextPosition textPosition() const final; | 87 TextPosition textPosition() const final; |
88 bool isParsingAtLineNumber() const final; | 88 bool isParsingAtLineNumber() const final; |
89 OrdinalNumber lineNumber() const final; | 89 OrdinalNumber lineNumber() const final; |
90 | 90 |
91 void suspendScheduledTasks() final; | 91 void suspendScheduledTasks() final; |
92 void resumeScheduledTasks() final; | 92 void resumeScheduledTasks() final; |
93 | 93 |
94 struct ParsedChunk { | 94 struct ParsedChunk { |
95 USING_FAST_MALLOC(ParsedChunk); | 95 USING_FAST_MALLOC(ParsedChunk); |
96 public: | 96 public: |
97 OwnPtr<CompactHTMLTokenStream> tokens; | 97 std::unique_ptr<CompactHTMLTokenStream> tokens; |
98 PreloadRequestStream preloads; | 98 PreloadRequestStream preloads; |
99 ViewportDescriptionWrapper viewport; | 99 ViewportDescriptionWrapper viewport; |
100 XSSInfoStream xssInfos; | 100 XSSInfoStream xssInfos; |
101 HTMLTokenizer::State tokenizerState; | 101 HTMLTokenizer::State tokenizerState; |
102 HTMLTreeBuilderSimulator::State treeBuilderState; | 102 HTMLTreeBuilderSimulator::State treeBuilderState; |
103 HTMLInputCheckpoint inputCheckpoint; | 103 HTMLInputCheckpoint inputCheckpoint; |
104 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; | 104 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; |
105 bool startingScript; | 105 bool startingScript; |
106 // Indices into |tokens|. | 106 // Indices into |tokens|. |
107 Vector<int> likelyDocumentWriteScriptIndices; | 107 Vector<int> likelyDocumentWriteScriptIndices; |
108 }; | 108 }; |
109 void notifyPendingParsedChunks(); | 109 void notifyPendingParsedChunks(); |
110 void didReceiveEncodingDataFromBackgroundParser(const DocumentEncodingData&)
; | 110 void didReceiveEncodingDataFromBackgroundParser(const DocumentEncodingData&)
; |
111 | 111 |
112 void appendBytes(const char* bytes, size_t length) override; | 112 void appendBytes(const char* bytes, size_t length) override; |
113 void flush() final; | 113 void flush() final; |
114 void setDecoder(PassOwnPtr<TextResourceDecoder>) final; | 114 void setDecoder(std::unique_ptr<TextResourceDecoder>) final; |
115 | 115 |
116 protected: | 116 protected: |
117 void insert(const SegmentedString&) final; | 117 void insert(const SegmentedString&) final; |
118 void append(const String&) override; | 118 void append(const String&) override; |
119 void finish() final; | 119 void finish() final; |
120 | 120 |
121 HTMLDocumentParser(HTMLDocument&, ParserSynchronizationPolicy); | 121 HTMLDocumentParser(HTMLDocument&, ParserSynchronizationPolicy); |
122 HTMLDocumentParser(DocumentFragment*, Element* contextElement, ParserContent
Policy); | 122 HTMLDocumentParser(DocumentFragment*, Element* contextElement, ParserContent
Policy); |
123 | 123 |
124 HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); } | 124 HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); } |
(...skipping 17 matching lines...) Expand all Loading... |
142 void documentElementAvailable() override; | 142 void documentElementAvailable() override; |
143 | 143 |
144 // HTMLScriptRunnerHost | 144 // HTMLScriptRunnerHost |
145 void notifyScriptLoaded(Resource*) final; | 145 void notifyScriptLoaded(Resource*) final; |
146 HTMLInputStream& inputStream() final { return m_input; } | 146 HTMLInputStream& inputStream() final { return m_input; } |
147 bool hasPreloadScanner() const final { return m_preloadScanner.get() && !sho
uldUseThreading(); } | 147 bool hasPreloadScanner() const final { return m_preloadScanner.get() && !sho
uldUseThreading(); } |
148 void appendCurrentInputStreamToPreloadScannerAndScan() final; | 148 void appendCurrentInputStreamToPreloadScannerAndScan() final; |
149 | 149 |
150 void startBackgroundParser(); | 150 void startBackgroundParser(); |
151 void stopBackgroundParser(); | 151 void stopBackgroundParser(); |
152 void validateSpeculations(PassOwnPtr<ParsedChunk> lastChunk); | 152 void validateSpeculations(std::unique_ptr<ParsedChunk> lastChunk); |
153 void discardSpeculationsAndResumeFrom(PassOwnPtr<ParsedChunk> lastChunk, Pas
sOwnPtr<HTMLToken>, PassOwnPtr<HTMLTokenizer>); | 153 void discardSpeculationsAndResumeFrom(std::unique_ptr<ParsedChunk> lastChunk
, std::unique_ptr<HTMLToken>, std::unique_ptr<HTMLTokenizer>); |
154 size_t processParsedChunkFromBackgroundParser(PassOwnPtr<ParsedChunk>); | 154 size_t processParsedChunkFromBackgroundParser(std::unique_ptr<ParsedChunk>); |
155 void pumpPendingSpeculations(); | 155 void pumpPendingSpeculations(); |
156 | 156 |
157 bool canTakeNextToken(); | 157 bool canTakeNextToken(); |
158 void pumpTokenizer(); | 158 void pumpTokenizer(); |
159 void pumpTokenizerIfPossible(); | 159 void pumpTokenizerIfPossible(); |
160 void constructTreeFromHTMLToken(); | 160 void constructTreeFromHTMLToken(); |
161 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); | 161 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); |
162 | 162 |
163 void runScriptsForPausedTreeBuilder(); | 163 void runScriptsForPausedTreeBuilder(); |
164 void resumeParsingAfterScriptExecution(); | 164 void resumeParsingAfterScriptExecution(); |
165 | 165 |
166 void attemptToEnd(); | 166 void attemptToEnd(); |
167 void endIfDelayed(); | 167 void endIfDelayed(); |
168 void attemptToRunDeferredScriptsAndEnd(); | 168 void attemptToRunDeferredScriptsAndEnd(); |
169 void end(); | 169 void end(); |
170 | 170 |
171 bool shouldUseThreading() const { return m_shouldUseThreading; } | 171 bool shouldUseThreading() const { return m_shouldUseThreading; } |
172 | 172 |
173 bool isParsingFragment() const; | 173 bool isParsingFragment() const; |
174 bool isScheduledForResume() const; | 174 bool isScheduledForResume() const; |
175 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } | 175 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } |
176 bool shouldDelayEnd() const { return inPumpSession() || isWaitingForScripts(
) || isScheduledForResume() || isExecutingScript(); } | 176 bool shouldDelayEnd() const { return inPumpSession() || isWaitingForScripts(
) || isScheduledForResume() || isExecutingScript(); } |
177 | 177 |
178 PassOwnPtr<HTMLPreloadScanner> createPreloadScanner(); | 178 std::unique_ptr<HTMLPreloadScanner> createPreloadScanner(); |
179 | 179 |
180 int preloadInsertion(const SegmentedString& source); | 180 int preloadInsertion(const SegmentedString& source); |
181 void evaluateAndPreloadScriptForDocumentWrite(const String& source); | 181 void evaluateAndPreloadScriptForDocumentWrite(const String& source); |
182 | 182 |
183 HTMLToken& token() { return *m_token; } | 183 HTMLToken& token() { return *m_token; } |
184 | 184 |
185 HTMLParserOptions m_options; | 185 HTMLParserOptions m_options; |
186 HTMLInputStream m_input; | 186 HTMLInputStream m_input; |
187 | 187 |
188 OwnPtr<HTMLToken> m_token; | 188 std::unique_ptr<HTMLToken> m_token; |
189 OwnPtr<HTMLTokenizer> m_tokenizer; | 189 std::unique_ptr<HTMLTokenizer> m_tokenizer; |
190 Member<HTMLScriptRunner> m_scriptRunner; | 190 Member<HTMLScriptRunner> m_scriptRunner; |
191 Member<HTMLTreeBuilder> m_treeBuilder; | 191 Member<HTMLTreeBuilder> m_treeBuilder; |
192 OwnPtr<HTMLPreloadScanner> m_preloadScanner; | 192 std::unique_ptr<HTMLPreloadScanner> m_preloadScanner; |
193 OwnPtr<HTMLPreloadScanner> m_insertionPreloadScanner; | 193 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner; |
194 OwnPtr<WebTaskRunner> m_loadingTaskRunner; | 194 std::unique_ptr<WebTaskRunner> m_loadingTaskRunner; |
195 Member<HTMLParserScheduler> m_parserScheduler; | 195 Member<HTMLParserScheduler> m_parserScheduler; |
196 HTMLSourceTracker m_sourceTracker; | 196 HTMLSourceTracker m_sourceTracker; |
197 TextPosition m_textPosition; | 197 TextPosition m_textPosition; |
198 XSSAuditor m_xssAuditor; | 198 XSSAuditor m_xssAuditor; |
199 XSSAuditorDelegate m_xssAuditorDelegate; | 199 XSSAuditorDelegate m_xssAuditorDelegate; |
200 | 200 |
201 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should
be combined into a single state object | 201 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should
be combined into a single state object |
202 // so they can be set and cleared together and passed between threads togeth
er. | 202 // so they can be set and cleared together and passed between threads togeth
er. |
203 OwnPtr<ParsedChunk> m_lastChunkBeforeScript; | 203 std::unique_ptr<ParsedChunk> m_lastChunkBeforeScript; |
204 Deque<OwnPtr<ParsedChunk>> m_speculations; | 204 Deque<std::unique_ptr<ParsedChunk>> m_speculations; |
205 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; | 205 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; |
206 WeakPtr<BackgroundHTMLParser> m_backgroundParser; | 206 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
207 Member<HTMLResourcePreloader> m_preloader; | 207 Member<HTMLResourcePreloader> m_preloader; |
208 PreloadRequestStream m_queuedPreloads; | 208 PreloadRequestStream m_queuedPreloads; |
209 Vector<String> m_queuedDocumentWriteScripts; | 209 Vector<String> m_queuedDocumentWriteScripts; |
210 RefPtr<ParsedChunkQueue> m_parsedChunkQueue; | 210 RefPtr<ParsedChunkQueue> m_parsedChunkQueue; |
211 OwnPtr<DocumentWriteEvaluator> m_evaluator; | 211 std::unique_ptr<DocumentWriteEvaluator> m_evaluator; |
212 | 212 |
213 bool m_shouldUseThreading; | 213 bool m_shouldUseThreading; |
214 bool m_endWasDelayed; | 214 bool m_endWasDelayed; |
215 bool m_haveBackgroundParser; | 215 bool m_haveBackgroundParser; |
216 bool m_tasksWereSuspended; | 216 bool m_tasksWereSuspended; |
217 unsigned m_pumpSessionNestingLevel; | 217 unsigned m_pumpSessionNestingLevel; |
218 unsigned m_pumpSpeculationsSessionNestingLevel; | 218 unsigned m_pumpSpeculationsSessionNestingLevel; |
219 bool m_isParsingAtLineNumber; | 219 bool m_isParsingAtLineNumber; |
220 bool m_triedLoadingLinkHeaders; | 220 bool m_triedLoadingLinkHeaders; |
221 }; | 221 }; |
222 | 222 |
223 } // namespace blink | 223 } // namespace blink |
224 | 224 |
225 #endif | 225 #endif |
OLD | NEW |