| 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 22 matching lines...) Expand all Loading... |
| 33 #include "core/html/parser/BackgroundHTMLInputStream.h" | 33 #include "core/html/parser/BackgroundHTMLInputStream.h" |
| 34 #include "core/html/parser/CompactHTMLToken.h" | 34 #include "core/html/parser/CompactHTMLToken.h" |
| 35 #include "core/html/parser/HTMLInputStream.h" | 35 #include "core/html/parser/HTMLInputStream.h" |
| 36 #include "core/html/parser/HTMLParserOptions.h" | 36 #include "core/html/parser/HTMLParserOptions.h" |
| 37 #include "core/html/parser/HTMLPreloadScanner.h" | 37 #include "core/html/parser/HTMLPreloadScanner.h" |
| 38 #include "core/html/parser/HTMLScriptRunnerHost.h" | 38 #include "core/html/parser/HTMLScriptRunnerHost.h" |
| 39 #include "core/html/parser/HTMLSourceTracker.h" | 39 #include "core/html/parser/HTMLSourceTracker.h" |
| 40 #include "core/html/parser/HTMLToken.h" | 40 #include "core/html/parser/HTMLToken.h" |
| 41 #include "core/html/parser/HTMLTokenizer.h" | 41 #include "core/html/parser/HTMLTokenizer.h" |
| 42 #include "core/html/parser/HTMLTreeBuilderSimulator.h" | 42 #include "core/html/parser/HTMLTreeBuilderSimulator.h" |
| 43 #include "core/html/parser/ParserSynchronizationPolicy.h" |
| 43 #include "core/html/parser/TextResourceDecoder.h" | 44 #include "core/html/parser/TextResourceDecoder.h" |
| 44 #include "core/html/parser/XSSAuditor.h" | 45 #include "core/html/parser/XSSAuditor.h" |
| 45 #include "core/html/parser/XSSAuditorDelegate.h" | 46 #include "core/html/parser/XSSAuditorDelegate.h" |
| 46 #include "platform/text/SegmentedString.h" | 47 #include "platform/text/SegmentedString.h" |
| 47 #include "wtf/Deque.h" | 48 #include "wtf/Deque.h" |
| 48 #include "wtf/OwnPtr.h" | 49 #include "wtf/OwnPtr.h" |
| 49 #include "wtf/WeakPtr.h" | 50 #include "wtf/WeakPtr.h" |
| 50 #include "wtf/text/TextPosition.h" | 51 #include "wtf/text/TextPosition.h" |
| 51 | 52 |
| 52 namespace blink { | 53 namespace blink { |
| 53 | 54 |
| 54 class BackgroundHTMLParser; | 55 class BackgroundHTMLParser; |
| 55 class CompactHTMLToken; | 56 class CompactHTMLToken; |
| 56 class Document; | 57 class Document; |
| 57 class DocumentEncodingData; | 58 class DocumentEncodingData; |
| 58 class DocumentFragment; | 59 class DocumentFragment; |
| 59 class HTMLDocument; | 60 class HTMLDocument; |
| 60 class HTMLParserScheduler; | 61 class HTMLParserScheduler; |
| 61 class HTMLScriptRunner; | 62 class HTMLScriptRunner; |
| 62 class HTMLTreeBuilder; | 63 class HTMLTreeBuilder; |
| 63 class HTMLResourcePreloader; | 64 class HTMLResourcePreloader; |
| 64 | 65 |
| 65 class PumpSession; | 66 class PumpSession; |
| 66 | 67 |
| 67 class HTMLDocumentParser : public ScriptableDocumentParser, private HTMLScriptR
unnerHost { | 68 class HTMLDocumentParser : public ScriptableDocumentParser, private HTMLScriptR
unnerHost { |
| 68 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; | 69 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 69 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser); | 70 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser); |
| 70 public: | 71 public: |
| 71 static PassRefPtrWillBeRawPtr<HTMLDocumentParser> create(HTMLDocument& docum
ent, bool reportErrors) | 72 static PassRefPtrWillBeRawPtr<HTMLDocumentParser> create(HTMLDocument& docum
ent, bool reportErrors, ParserSynchronizationPolicy backgroundParsingPolicy) |
| 72 { | 73 { |
| 73 return adoptRefWillBeNoop(new HTMLDocumentParser(document, reportErrors)
); | 74 return adoptRefWillBeNoop(new HTMLDocumentParser(document, reportErrors,
backgroundParsingPolicy)); |
| 74 } | 75 } |
| 75 virtual ~HTMLDocumentParser(); | 76 virtual ~HTMLDocumentParser(); |
| 76 virtual void trace(Visitor*) override; | 77 virtual void trace(Visitor*) override; |
| 77 | 78 |
| 78 // Exposed for HTMLParserScheduler | 79 // Exposed for HTMLParserScheduler |
| 79 void resumeParsingAfterYield(); | 80 void resumeParsingAfterYield(); |
| 80 | 81 |
| 81 static void parseDocumentFragment(const String&, DocumentFragment*, Element*
contextElement, ParserContentPolicy = AllowScriptingContent); | 82 static void parseDocumentFragment(const String&, DocumentFragment*, Element*
contextElement, ParserContentPolicy = AllowScriptingContent); |
| 82 | 83 |
| 83 HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); } | 84 HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 105 virtual void flush() override final; | 106 virtual void flush() override final; |
| 106 virtual void setDecoder(PassOwnPtr<TextResourceDecoder>) override final; | 107 virtual void setDecoder(PassOwnPtr<TextResourceDecoder>) override final; |
| 107 | 108 |
| 108 UseCounter* useCounter() { return UseCounter::getFrom(contextForParsingSessi
on()); } | 109 UseCounter* useCounter() { return UseCounter::getFrom(contextForParsingSessi
on()); } |
| 109 | 110 |
| 110 protected: | 111 protected: |
| 111 virtual void insert(const SegmentedString&) override final; | 112 virtual void insert(const SegmentedString&) override final; |
| 112 virtual void append(PassRefPtr<StringImpl>) override; | 113 virtual void append(PassRefPtr<StringImpl>) override; |
| 113 virtual void finish() override final; | 114 virtual void finish() override final; |
| 114 | 115 |
| 115 HTMLDocumentParser(HTMLDocument&, bool reportErrors); | 116 HTMLDocumentParser(HTMLDocument&, bool reportErrors, ParserSynchronizationPo
licy); |
| 116 HTMLDocumentParser(DocumentFragment*, Element* contextElement, ParserContent
Policy); | 117 HTMLDocumentParser(DocumentFragment*, Element* contextElement, ParserContent
Policy); |
| 117 | 118 |
| 118 HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); } | 119 HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); } |
| 119 | 120 |
| 120 void forcePlaintextForTextDocument(); | 121 void forcePlaintextForTextDocument(); |
| 121 | 122 |
| 122 private: | 123 private: |
| 123 static PassRefPtrWillBeRawPtr<HTMLDocumentParser> create(DocumentFragment* f
ragment, Element* contextElement, ParserContentPolicy parserContentPolicy) | 124 static PassRefPtrWillBeRawPtr<HTMLDocumentParser> create(DocumentFragment* f
ragment, Element* contextElement, ParserContentPolicy parserContentPolicy) |
| 124 { | 125 { |
| 125 return adoptRefWillBeNoop(new HTMLDocumentParser(fragment, contextElemen
t, parserContentPolicy)); | 126 return adoptRefWillBeNoop(new HTMLDocumentParser(fragment, contextElemen
t, parserContentPolicy)); |
| 126 } | 127 } |
| 127 | 128 |
| 128 // DocumentParser | 129 // DocumentParser |
| 129 virtual void pinToMainThread() override final; | |
| 130 virtual void detach() override final; | 130 virtual void detach() override final; |
| 131 virtual bool hasInsertionPoint() override final; | 131 virtual bool hasInsertionPoint() override final; |
| 132 virtual bool processingData() const override final; | 132 virtual bool processingData() const override final; |
| 133 virtual void prepareToStopParsing() override final; | 133 virtual void prepareToStopParsing() override final; |
| 134 virtual void stopParsing() override final; | 134 virtual void stopParsing() override final; |
| 135 virtual bool isWaitingForScripts() const override final; | 135 virtual bool isWaitingForScripts() const override final; |
| 136 virtual bool isExecutingScript() const override final; | 136 virtual bool isExecutingScript() const override final; |
| 137 virtual void executeScriptsWaitingForResources() override final; | 137 virtual void executeScriptsWaitingForResources() override final; |
| 138 | 138 |
| 139 // HTMLScriptRunnerHost | 139 // HTMLScriptRunnerHost |
| (...skipping 18 matching lines...) Expand all Loading... |
| 158 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); | 158 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); |
| 159 | 159 |
| 160 void runScriptsForPausedTreeBuilder(); | 160 void runScriptsForPausedTreeBuilder(); |
| 161 void resumeParsingAfterScriptExecution(); | 161 void resumeParsingAfterScriptExecution(); |
| 162 | 162 |
| 163 void attemptToEnd(); | 163 void attemptToEnd(); |
| 164 void endIfDelayed(); | 164 void endIfDelayed(); |
| 165 void attemptToRunDeferredScriptsAndEnd(); | 165 void attemptToRunDeferredScriptsAndEnd(); |
| 166 void end(); | 166 void end(); |
| 167 | 167 |
| 168 bool shouldUseThreading() const { return !m_isPinnedToMainThread; } | 168 bool shouldUseThreading() const { return m_shouldUseThreading; } |
| 169 | 169 |
| 170 bool isParsingFragment() const; | 170 bool isParsingFragment() const; |
| 171 bool isScheduledForResume() const; | 171 bool isScheduledForResume() const; |
| 172 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } | 172 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } |
| 173 bool shouldDelayEnd() const { return inPumpSession() || isWaitingForScripts(
) || isScheduledForResume() || isExecutingScript(); } | 173 bool shouldDelayEnd() const { return inPumpSession() || isWaitingForScripts(
) || isScheduledForResume() || isExecutingScript(); } |
| 174 | 174 |
| 175 HTMLToken& token() { return *m_token; } | 175 HTMLToken& token() { return *m_token; } |
| 176 | 176 |
| 177 HTMLParserOptions m_options; | 177 HTMLParserOptions m_options; |
| 178 HTMLInputStream m_input; | 178 HTMLInputStream m_input; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 190 XSSAuditorDelegate m_xssAuditorDelegate; | 190 XSSAuditorDelegate m_xssAuditorDelegate; |
| 191 | 191 |
| 192 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should
be combined into a single state object | 192 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should
be combined into a single state object |
| 193 // so they can be set and cleared together and passed between threads togeth
er. | 193 // so they can be set and cleared together and passed between threads togeth
er. |
| 194 OwnPtr<ParsedChunk> m_lastChunkBeforeScript; | 194 OwnPtr<ParsedChunk> m_lastChunkBeforeScript; |
| 195 Deque<OwnPtr<ParsedChunk>> m_speculations; | 195 Deque<OwnPtr<ParsedChunk>> m_speculations; |
| 196 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; | 196 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; |
| 197 WeakPtr<BackgroundHTMLParser> m_backgroundParser; | 197 WeakPtr<BackgroundHTMLParser> m_backgroundParser; |
| 198 OwnPtrWillBeMember<HTMLResourcePreloader> m_preloader; | 198 OwnPtrWillBeMember<HTMLResourcePreloader> m_preloader; |
| 199 | 199 |
| 200 bool m_isPinnedToMainThread; | 200 bool m_shouldUseThreading; |
| 201 bool m_endWasDelayed; | 201 bool m_endWasDelayed; |
| 202 bool m_haveBackgroundParser; | 202 bool m_haveBackgroundParser; |
| 203 bool m_tasksWereSuspended; | 203 bool m_tasksWereSuspended; |
| 204 unsigned m_pumpSessionNestingLevel; | 204 unsigned m_pumpSessionNestingLevel; |
| 205 unsigned m_pumpSpeculationsSessionNestingLevel; | 205 unsigned m_pumpSpeculationsSessionNestingLevel; |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 } | 208 } |
| 209 | 209 |
| 210 #endif | 210 #endif |
| OLD | NEW |