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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 HTMLDocumentParser(Document&, | 163 HTMLDocumentParser(Document&, |
164 ParserContentPolicy, | 164 ParserContentPolicy, |
165 ParserSynchronizationPolicy); | 165 ParserSynchronizationPolicy); |
166 | 166 |
167 // DocumentParser | 167 // DocumentParser |
168 void detach() final; | 168 void detach() final; |
169 bool hasInsertionPoint() final; | 169 bool hasInsertionPoint() final; |
170 void prepareToStopParsing() final; | 170 void prepareToStopParsing() final; |
171 void stopParsing() final; | 171 void stopParsing() final; |
| 172 bool isPaused() const { |
| 173 return isWaitingForScripts() || m_isWaitingForStylesheets; |
| 174 } |
172 bool isWaitingForScripts() const final; | 175 bool isWaitingForScripts() const final; |
173 bool isExecutingScript() const final; | 176 bool isExecutingScript() const final; |
174 void executeScriptsWaitingForResources() final; | 177 void executeScriptsWaitingForResources() final; |
| 178 void didAddPendingStylesheetInBody() final; |
| 179 void didLoadAllBodyStylesheets() final; |
| 180 void checkIfBodyStlyesheetAdded(); |
175 void documentElementAvailable() override; | 181 void documentElementAvailable() override; |
176 | 182 |
177 // HTMLParserScriptRunnerHost | 183 // HTMLParserScriptRunnerHost |
178 void notifyScriptLoaded(PendingScript*) final; | 184 void notifyScriptLoaded(PendingScript*) final; |
179 HTMLInputStream& inputStream() final { return m_input; } | 185 HTMLInputStream& inputStream() final { return m_input; } |
180 bool hasPreloadScanner() const final { | 186 bool hasPreloadScanner() const final { |
181 return m_preloadScanner.get() && !shouldUseThreading(); | 187 return m_preloadScanner.get() && !shouldUseThreading(); |
182 } | 188 } |
183 void appendCurrentInputStreamToPreloadScannerAndScan() final; | 189 void appendCurrentInputStreamToPreloadScannerAndScan() final; |
184 | 190 |
185 void startBackgroundParser(); | 191 void startBackgroundParser(); |
186 void stopBackgroundParser(); | 192 void stopBackgroundParser(); |
187 void validateSpeculations(std::unique_ptr<TokenizedChunk> lastChunk); | 193 void validateSpeculations(std::unique_ptr<TokenizedChunk> lastChunk); |
188 void discardSpeculationsAndResumeFrom( | 194 void discardSpeculationsAndResumeFrom( |
189 std::unique_ptr<TokenizedChunk> lastChunk, | 195 std::unique_ptr<TokenizedChunk> lastChunk, |
190 std::unique_ptr<HTMLToken>, | 196 std::unique_ptr<HTMLToken>, |
191 std::unique_ptr<HTMLTokenizer>); | 197 std::unique_ptr<HTMLTokenizer>); |
192 size_t processTokenizedChunkFromBackgroundParser( | 198 size_t processTokenizedChunkFromBackgroundParser( |
193 std::unique_ptr<TokenizedChunk>); | 199 std::unique_ptr<TokenizedChunk>); |
194 void pumpPendingSpeculations(); | 200 void pumpPendingSpeculations(); |
195 | 201 |
196 bool canTakeNextToken(); | 202 bool canTakeNextToken(); |
197 void pumpTokenizer(); | 203 void pumpTokenizer(); |
198 void pumpTokenizerIfPossible(); | 204 void pumpTokenizerIfPossible(); |
199 void constructTreeFromHTMLToken(); | 205 void constructTreeFromHTMLToken(); |
200 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); | 206 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); |
201 | 207 |
202 void runScriptsForPausedTreeBuilder(); | 208 void runScriptsForPausedTreeBuilder(); |
203 void resumeParsingAfterScriptExecution(); | 209 void resumeParsingAfterPause(); |
204 | 210 |
205 void attemptToEnd(); | 211 void attemptToEnd(); |
206 void endIfDelayed(); | 212 void endIfDelayed(); |
207 void attemptToRunDeferredScriptsAndEnd(); | 213 void attemptToRunDeferredScriptsAndEnd(); |
208 void end(); | 214 void end(); |
209 | 215 |
210 bool shouldUseThreading() const { return m_shouldUseThreading; } | 216 bool shouldUseThreading() const { return m_shouldUseThreading; } |
211 | 217 |
212 bool isParsingFragment() const; | 218 bool isParsingFragment() const; |
213 bool isScheduledForResume() const; | 219 bool isScheduledForResume() const; |
214 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } | 220 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } |
215 bool shouldDelayEnd() const { | 221 bool shouldDelayEnd() const { |
216 return inPumpSession() || isWaitingForScripts() || isScheduledForResume() || | 222 return inPumpSession() || isPaused() || isScheduledForResume() || |
217 isExecutingScript(); | 223 isExecutingScript(); |
218 } | 224 } |
219 | 225 |
220 std::unique_ptr<HTMLPreloadScanner> createPreloadScanner(); | 226 std::unique_ptr<HTMLPreloadScanner> createPreloadScanner(); |
221 | 227 |
222 // Let the given HTMLPreloadScanner scan the input it has, and then preloads | 228 // Let the given HTMLPreloadScanner scan the input it has, and then preloads |
223 // resources using the resulting PreloadRequests and |m_preloader|. | 229 // resources using the resulting PreloadRequests and |m_preloader|. |
224 void scanAndPreload(HTMLPreloadScanner*); | 230 void scanAndPreload(HTMLPreloadScanner*); |
225 void fetchQueuedPreloads(); | 231 void fetchQueuedPreloads(); |
226 | 232 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // A scanner used only for input provided to the insert() method. | 264 // A scanner used only for input provided to the insert() method. |
259 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner; | 265 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner; |
260 | 266 |
261 RefPtr<WebTaskRunner> m_loadingTaskRunner; | 267 RefPtr<WebTaskRunner> m_loadingTaskRunner; |
262 Member<HTMLParserScheduler> m_parserScheduler; | 268 Member<HTMLParserScheduler> m_parserScheduler; |
263 HTMLSourceTracker m_sourceTracker; | 269 HTMLSourceTracker m_sourceTracker; |
264 TextPosition m_textPosition; | 270 TextPosition m_textPosition; |
265 XSSAuditor m_xssAuditor; | 271 XSSAuditor m_xssAuditor; |
266 XSSAuditorDelegate m_xssAuditorDelegate; | 272 XSSAuditorDelegate m_xssAuditorDelegate; |
267 | 273 |
268 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should be | 274 // FIXME: m_lastChunkBeforePause, m_tokenizer, m_token, and m_input should be |
269 // combined into a single state object so they can be set and cleared together | 275 // combined into a single state object so they can be set and cleared together |
270 // and passed between threads together. | 276 // and passed between threads together. |
271 std::unique_ptr<TokenizedChunk> m_lastChunkBeforeScript; | 277 std::unique_ptr<TokenizedChunk> m_lastChunkBeforePause; |
272 Deque<std::unique_ptr<TokenizedChunk>> m_speculations; | 278 Deque<std::unique_ptr<TokenizedChunk>> m_speculations; |
273 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; | 279 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; |
274 WeakPtr<BackgroundHTMLParser> m_backgroundParser; | 280 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
275 Member<HTMLResourcePreloader> m_preloader; | 281 Member<HTMLResourcePreloader> m_preloader; |
276 PreloadRequestStream m_queuedPreloads; | 282 PreloadRequestStream m_queuedPreloads; |
277 Vector<String> m_queuedDocumentWriteScripts; | 283 Vector<String> m_queuedDocumentWriteScripts; |
278 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue; | 284 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue; |
279 std::unique_ptr<DocumentWriteEvaluator> m_evaluator; | 285 std::unique_ptr<DocumentWriteEvaluator> m_evaluator; |
280 | 286 |
281 // If this is non-null, then there is a meta CSP token somewhere in the | 287 // If this is non-null, then there is a meta CSP token somewhere in the |
282 // speculation buffer. Preloads will be deferred until a token matching this | 288 // speculation buffer. Preloads will be deferred until a token matching this |
283 // pointer is parsed and the CSP policy is applied. Note that this pointer | 289 // pointer is parsed and the CSP policy is applied. Note that this pointer |
284 // tracks the *last* meta token in the speculation buffer, so it overestimates | 290 // tracks the *last* meta token in the speculation buffer, so it overestimates |
285 // how long to defer preloads. This is for simplicity, as the alternative | 291 // how long to defer preloads. This is for simplicity, as the alternative |
286 // would require keeping track of token positions of preload requests. | 292 // would require keeping track of token positions of preload requests. |
287 CompactHTMLToken* m_pendingCSPMetaToken; | 293 CompactHTMLToken* m_pendingCSPMetaToken; |
288 | 294 |
| 295 TaskHandle m_resumeParsingTaskHandle; |
| 296 |
289 bool m_shouldUseThreading; | 297 bool m_shouldUseThreading; |
290 bool m_endWasDelayed; | 298 bool m_endWasDelayed; |
291 bool m_haveBackgroundParser; | 299 bool m_haveBackgroundParser; |
292 bool m_tasksWereSuspended; | 300 bool m_tasksWereSuspended; |
293 unsigned m_pumpSessionNestingLevel; | 301 unsigned m_pumpSessionNestingLevel; |
294 unsigned m_pumpSpeculationsSessionNestingLevel; | 302 unsigned m_pumpSpeculationsSessionNestingLevel; |
295 bool m_isParsingAtLineNumber; | 303 bool m_isParsingAtLineNumber; |
296 bool m_triedLoadingLinkHeaders; | 304 bool m_triedLoadingLinkHeaders; |
| 305 bool m_addedPendingStylesheetInBody; |
| 306 bool m_isWaitingForStylesheets; |
297 }; | 307 }; |
298 | 308 |
299 } // namespace blink | 309 } // namespace blink |
300 | 310 |
301 #endif // HTMLDocumentParser_h | 311 #endif // HTMLDocumentParser_h |
OLD | NEW |