| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 63 class HTMLParserScheduler; | 63 class HTMLParserScheduler; |
| 64 class HTMLResourcePreloader; | 64 class HTMLResourcePreloader; |
| 65 class HTMLScriptRunner; | 65 class HTMLScriptRunner; |
| 66 class HTMLTreeBuilder; | 66 class HTMLTreeBuilder; |
| 67 class ParsedChunkQueue; | |
| 68 class PumpSession; | 67 class PumpSession; |
| 68 class TokenizedChunkQueue; |
| 69 | 69 |
| 70 class HTMLDocumentParser : public ScriptableDocumentParser, private HTMLScriptR
unnerHost { | 70 class HTMLDocumentParser : public ScriptableDocumentParser, private HTMLScriptR
unnerHost { |
| 71 USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser); | 71 USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser); |
| 72 public: | 72 public: |
| 73 static HTMLDocumentParser* create(HTMLDocument& document, ParserSynchronizat
ionPolicy backgroundParsingPolicy) | 73 static HTMLDocumentParser* create(HTMLDocument& document, ParserSynchronizat
ionPolicy backgroundParsingPolicy) |
| 74 { | 74 { |
| 75 return new HTMLDocumentParser(document, backgroundParsingPolicy); | 75 return new HTMLDocumentParser(document, backgroundParsingPolicy); |
| 76 } | 76 } |
| 77 ~HTMLDocumentParser() override; | 77 ~HTMLDocumentParser() override; |
| 78 DECLARE_VIRTUAL_TRACE(); | 78 DECLARE_VIRTUAL_TRACE(); |
| 79 | 79 |
| 80 // Exposed for HTMLParserScheduler | 80 // Exposed for HTMLParserScheduler |
| 81 void resumeParsingAfterYield(); | 81 void resumeParsingAfterYield(); |
| 82 | 82 |
| 83 static void parseDocumentFragment(const String&, DocumentFragment*, Element*
contextElement, ParserContentPolicy = AllowScriptingContent); | 83 static void parseDocumentFragment(const String&, DocumentFragment*, Element*
contextElement, ParserContentPolicy = AllowScriptingContent); |
| 84 | 84 |
| 85 HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); } | 85 HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); } |
| 86 | 86 |
| 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 TokenizedChunk { |
| 95 USING_FAST_MALLOC(ParsedChunk); | 95 USING_FAST_MALLOC(TokenizedChunk); |
| 96 public: | 96 public: |
| 97 std::unique_ptr<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 notifyPendingTokenizedChunks(); |
| 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(std::unique_ptr<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; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 143 void documentElementAvailable() override; | 143 void documentElementAvailable() override; |
| 144 | 144 |
| 145 // HTMLScriptRunnerHost | 145 // HTMLScriptRunnerHost |
| 146 void notifyScriptLoaded(Resource*) final; | 146 void notifyScriptLoaded(Resource*) final; |
| 147 HTMLInputStream& inputStream() final { return m_input; } | 147 HTMLInputStream& inputStream() final { return m_input; } |
| 148 bool hasPreloadScanner() const final { return m_preloadScanner.get() && !sho
uldUseThreading(); } | 148 bool hasPreloadScanner() const final { return m_preloadScanner.get() && !sho
uldUseThreading(); } |
| 149 void appendCurrentInputStreamToPreloadScannerAndScan() final; | 149 void appendCurrentInputStreamToPreloadScannerAndScan() final; |
| 150 | 150 |
| 151 void startBackgroundParser(); | 151 void startBackgroundParser(); |
| 152 void stopBackgroundParser(); | 152 void stopBackgroundParser(); |
| 153 void validateSpeculations(std::unique_ptr<ParsedChunk> lastChunk); | 153 void validateSpeculations(std::unique_ptr<TokenizedChunk> lastChunk); |
| 154 void discardSpeculationsAndResumeFrom(std::unique_ptr<ParsedChunk> lastChunk
, std::unique_ptr<HTMLToken>, std::unique_ptr<HTMLTokenizer>); | 154 void discardSpeculationsAndResumeFrom(std::unique_ptr<TokenizedChunk> lastCh
unk, std::unique_ptr<HTMLToken>, std::unique_ptr<HTMLTokenizer>); |
| 155 size_t processParsedChunkFromBackgroundParser(std::unique_ptr<ParsedChunk>); | 155 size_t processTokenizedChunkFromBackgroundParser(std::unique_ptr<TokenizedCh
unk>); |
| 156 void pumpPendingSpeculations(); | 156 void pumpPendingSpeculations(); |
| 157 | 157 |
| 158 bool canTakeNextToken(); | 158 bool canTakeNextToken(); |
| 159 void pumpTokenizer(); | 159 void pumpTokenizer(); |
| 160 void pumpTokenizerIfPossible(); | 160 void pumpTokenizerIfPossible(); |
| 161 void constructTreeFromHTMLToken(); | 161 void constructTreeFromHTMLToken(); |
| 162 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); | 162 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); |
| 163 | 163 |
| 164 void runScriptsForPausedTreeBuilder(); | 164 void runScriptsForPausedTreeBuilder(); |
| 165 void resumeParsingAfterScriptExecution(); | 165 void resumeParsingAfterScriptExecution(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner; | 209 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner; |
| 210 std::unique_ptr<WebTaskRunner> m_loadingTaskRunner; | 210 std::unique_ptr<WebTaskRunner> m_loadingTaskRunner; |
| 211 Member<HTMLParserScheduler> m_parserScheduler; | 211 Member<HTMLParserScheduler> m_parserScheduler; |
| 212 HTMLSourceTracker m_sourceTracker; | 212 HTMLSourceTracker m_sourceTracker; |
| 213 TextPosition m_textPosition; | 213 TextPosition m_textPosition; |
| 214 XSSAuditor m_xssAuditor; | 214 XSSAuditor m_xssAuditor; |
| 215 XSSAuditorDelegate m_xssAuditorDelegate; | 215 XSSAuditorDelegate m_xssAuditorDelegate; |
| 216 | 216 |
| 217 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should
be combined into a single state object | 217 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should
be combined into a single state object |
| 218 // so they can be set and cleared together and passed between threads togeth
er. | 218 // so they can be set and cleared together and passed between threads togeth
er. |
| 219 std::unique_ptr<ParsedChunk> m_lastChunkBeforeScript; | 219 std::unique_ptr<TokenizedChunk> m_lastChunkBeforeScript; |
| 220 Deque<std::unique_ptr<ParsedChunk>> m_speculations; | 220 Deque<std::unique_ptr<TokenizedChunk>> m_speculations; |
| 221 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; | 221 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; |
| 222 WeakPtr<BackgroundHTMLParser> m_backgroundParser; | 222 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
| 223 Member<HTMLResourcePreloader> m_preloader; | 223 Member<HTMLResourcePreloader> m_preloader; |
| 224 PreloadRequestStream m_queuedPreloads; | 224 PreloadRequestStream m_queuedPreloads; |
| 225 Vector<String> m_queuedDocumentWriteScripts; | 225 Vector<String> m_queuedDocumentWriteScripts; |
| 226 RefPtr<ParsedChunkQueue> m_parsedChunkQueue; | 226 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue; |
| 227 std::unique_ptr<DocumentWriteEvaluator> m_evaluator; | 227 std::unique_ptr<DocumentWriteEvaluator> m_evaluator; |
| 228 | 228 |
| 229 bool m_shouldUseThreading; | 229 bool m_shouldUseThreading; |
| 230 bool m_endWasDelayed; | 230 bool m_endWasDelayed; |
| 231 bool m_haveBackgroundParser; | 231 bool m_haveBackgroundParser; |
| 232 bool m_tasksWereSuspended; | 232 bool m_tasksWereSuspended; |
| 233 unsigned m_pumpSessionNestingLevel; | 233 unsigned m_pumpSessionNestingLevel; |
| 234 unsigned m_pumpSpeculationsSessionNestingLevel; | 234 unsigned m_pumpSpeculationsSessionNestingLevel; |
| 235 bool m_isParsingAtLineNumber; | 235 bool m_isParsingAtLineNumber; |
| 236 bool m_triedLoadingLinkHeaders; | 236 bool m_triedLoadingLinkHeaders; |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 } // namespace blink | 239 } // namespace blink |
| 240 | 240 |
| 241 #endif | 241 #endif |
| OLD | NEW |