Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.h

Issue 2683653004: Put the BackgroundHTMLParser on oilpan heap (Closed)
Patch Set: remove <memory> Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef HTMLDocumentParser_h 26 #ifndef HTMLDocumentParser_h
27 #define HTMLDocumentParser_h 27 #define HTMLDocumentParser_h
28 28
29 #include <memory>
29 #include "core/CoreExport.h" 30 #include "core/CoreExport.h"
30 #include "core/dom/ParserContentPolicy.h" 31 #include "core/dom/ParserContentPolicy.h"
31 #include "core/dom/ScriptableDocumentParser.h" 32 #include "core/dom/ScriptableDocumentParser.h"
32 #include "core/html/parser/BackgroundHTMLInputStream.h" 33 #include "core/html/parser/BackgroundHTMLInputStream.h"
33 #include "core/html/parser/HTMLInputStream.h" 34 #include "core/html/parser/HTMLInputStream.h"
34 #include "core/html/parser/HTMLParserOptions.h" 35 #include "core/html/parser/HTMLParserOptions.h"
35 #include "core/html/parser/HTMLParserReentryPermit.h" 36 #include "core/html/parser/HTMLParserReentryPermit.h"
36 #include "core/html/parser/HTMLParserScriptRunnerHost.h" 37 #include "core/html/parser/HTMLParserScriptRunnerHost.h"
37 #include "core/html/parser/HTMLPreloadScanner.h" 38 #include "core/html/parser/HTMLPreloadScanner.h"
38 #include "core/html/parser/HTMLSourceTracker.h" 39 #include "core/html/parser/HTMLSourceTracker.h"
39 #include "core/html/parser/HTMLToken.h" 40 #include "core/html/parser/HTMLToken.h"
40 #include "core/html/parser/HTMLTokenizer.h" 41 #include "core/html/parser/HTMLTokenizer.h"
41 #include "core/html/parser/HTMLTreeBuilderSimulator.h" 42 #include "core/html/parser/HTMLTreeBuilderSimulator.h"
42 #include "core/html/parser/ParserSynchronizationPolicy.h" 43 #include "core/html/parser/ParserSynchronizationPolicy.h"
43 #include "core/html/parser/PreloadRequest.h" 44 #include "core/html/parser/PreloadRequest.h"
44 #include "core/html/parser/TextResourceDecoder.h" 45 #include "core/html/parser/TextResourceDecoder.h"
45 #include "core/html/parser/XSSAuditor.h" 46 #include "core/html/parser/XSSAuditor.h"
46 #include "core/html/parser/XSSAuditorDelegate.h" 47 #include "core/html/parser/XSSAuditorDelegate.h"
47 #include "wtf/Deque.h" 48 #include "wtf/Deque.h"
48 #include "wtf/RefPtr.h" 49 #include "wtf/RefPtr.h"
49 #include "wtf/WeakPtr.h" 50 #include "wtf/WeakPtr.h"
50 #include "wtf/text/TextPosition.h" 51 #include "wtf/text/TextPosition.h"
51 #include <memory>
52 52
53 namespace blink { 53 namespace blink {
54 54
55 class BackgroundHTMLParser; 55 class BackgroundHTMLParser;
56 class CompactHTMLToken; 56 class CompactHTMLToken;
57 class Document; 57 class Document;
58 class DocumentEncodingData; 58 class DocumentEncodingData;
59 class DocumentFragment; 59 class DocumentFragment;
60 class Element; 60 class Element;
61 class HTMLDocument; 61 class HTMLDocument;
62 class HTMLParserScheduler; 62 class HTMLParserScheduler;
63 class HTMLParserScriptRunner; 63 class HTMLParserScriptRunner;
64 class HTMLPreloadScanner; 64 class HTMLPreloadScanner;
65 class HTMLResourcePreloader; 65 class HTMLResourcePreloader;
66 class HTMLTreeBuilder; 66 class HTMLTreeBuilder;
67 class SegmentedString; 67 class SegmentedString;
68 class TokenizedChunkQueue; 68 class TokenizedChunkQueue;
69 class DocumentWriteEvaluator; 69 class DocumentWriteEvaluator;
70 70
71 class CORE_EXPORT HTMLDocumentParser : public ScriptableDocumentParser, 71 class CORE_EXPORT HTMLDocumentParser : public ScriptableDocumentParser,
72 private HTMLParserScriptRunnerHost { 72 private HTMLParserScriptRunnerHost {
73 USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser); 73 USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser);
74 USING_PRE_FINALIZER(HTMLDocumentParser, dispose);
75 74
76 public: 75 public:
77 static HTMLDocumentParser* create( 76 static HTMLDocumentParser* create(
78 HTMLDocument& document, 77 HTMLDocument& document,
79 ParserSynchronizationPolicy backgroundParsingPolicy) { 78 ParserSynchronizationPolicy backgroundParsingPolicy) {
80 return new HTMLDocumentParser(document, backgroundParsingPolicy); 79 return new HTMLDocumentParser(document, backgroundParsingPolicy);
81 } 80 }
82 ~HTMLDocumentParser() override; 81 ~HTMLDocumentParser() override;
83 DECLARE_VIRTUAL_TRACE(); 82 DECLARE_VIRTUAL_TRACE();
84 83
85 // TODO(alexclarke): Remove when background parser goes away.
86 void dispose();
87
88 // Exposed for HTMLParserScheduler 84 // Exposed for HTMLParserScheduler
89 void resumeParsingAfterYield(); 85 void resumeParsingAfterYield();
90 86
91 static void parseDocumentFragment( 87 static void parseDocumentFragment(
92 const String&, 88 const String&,
93 DocumentFragment*, 89 DocumentFragment*,
94 Element* contextElement, 90 Element* contextElement,
95 ParserContentPolicy = AllowScriptingContent); 91 ParserContentPolicy = AllowScriptingContent);
96 92
97 // Exposed for testing. 93 // Exposed for testing.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 128
133 static constexpr int noPendingToken = -1; 129 static constexpr int noPendingToken = -1;
134 }; 130 };
135 void notifyPendingTokenizedChunks(); 131 void notifyPendingTokenizedChunks();
136 void didReceiveEncodingDataFromBackgroundParser(const DocumentEncodingData&); 132 void didReceiveEncodingDataFromBackgroundParser(const DocumentEncodingData&);
137 133
138 void appendBytes(const char* bytes, size_t length) override; 134 void appendBytes(const char* bytes, size_t length) override;
139 void flush() final; 135 void flush() final;
140 void setDecoder(std::unique_ptr<TextResourceDecoder>) final; 136 void setDecoder(std::unique_ptr<TextResourceDecoder>) final;
141 137
138 TokenizedChunkQueue* tokenizedChunkQueue() {
139 return m_tokenizedChunkQueue.get();
140 }
141
142 protected: 142 protected:
143 void insert(const SegmentedString&) final; 143 void insert(const SegmentedString&) final;
144 void append(const String&) override; 144 void append(const String&) override;
145 void finish() final; 145 void finish() final;
146 146
147 HTMLDocumentParser(HTMLDocument&, ParserSynchronizationPolicy); 147 HTMLDocumentParser(HTMLDocument&, ParserSynchronizationPolicy);
148 HTMLDocumentParser(DocumentFragment*, 148 HTMLDocumentParser(DocumentFragment*,
149 Element* contextElement, 149 Element* contextElement,
150 ParserContentPolicy); 150 ParserContentPolicy);
151 151
(...skipping 30 matching lines...) Expand all
182 182
183 // HTMLParserScriptRunnerHost 183 // HTMLParserScriptRunnerHost
184 void notifyScriptLoaded(PendingScript*) final; 184 void notifyScriptLoaded(PendingScript*) final;
185 HTMLInputStream& inputStream() final { return m_input; } 185 HTMLInputStream& inputStream() final { return m_input; }
186 bool hasPreloadScanner() const final { 186 bool hasPreloadScanner() const final {
187 return m_preloadScanner.get() && !shouldUseThreading(); 187 return m_preloadScanner.get() && !shouldUseThreading();
188 } 188 }
189 void appendCurrentInputStreamToPreloadScannerAndScan() final; 189 void appendCurrentInputStreamToPreloadScannerAndScan() final;
190 190
191 void startBackgroundParser(); 191 void startBackgroundParser();
192 void stopBackgroundParser();
193 void validateSpeculations(std::unique_ptr<TokenizedChunk> lastChunk); 192 void validateSpeculations(std::unique_ptr<TokenizedChunk> lastChunk);
194 void discardSpeculationsAndResumeFrom( 193 void discardSpeculationsAndResumeFrom(
195 std::unique_ptr<TokenizedChunk> lastChunk, 194 std::unique_ptr<TokenizedChunk> lastChunk,
196 std::unique_ptr<HTMLToken>, 195 std::unique_ptr<HTMLToken>,
197 std::unique_ptr<HTMLTokenizer>); 196 std::unique_ptr<HTMLTokenizer>);
198 size_t processTokenizedChunkFromBackgroundParser( 197 size_t processTokenizedChunkFromBackgroundParser(
199 std::unique_ptr<TokenizedChunk>); 198 std::unique_ptr<TokenizedChunk>);
200 void pumpPendingSpeculations(); 199 void pumpPendingSpeculations();
201 200
202 bool canTakeNextToken(); 201 bool canTakeNextToken();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 239
241 std::unique_ptr<HTMLToken> m_token; 240 std::unique_ptr<HTMLToken> m_token;
242 std::unique_ptr<HTMLTokenizer> m_tokenizer; 241 std::unique_ptr<HTMLTokenizer> m_tokenizer;
243 Member<HTMLParserScriptRunner> m_scriptRunner; 242 Member<HTMLParserScriptRunner> m_scriptRunner;
244 Member<HTMLTreeBuilder> m_treeBuilder; 243 Member<HTMLTreeBuilder> m_treeBuilder;
245 244
246 std::unique_ptr<HTMLPreloadScanner> m_preloadScanner; 245 std::unique_ptr<HTMLPreloadScanner> m_preloadScanner;
247 // A scanner used only for input provided to the insert() method. 246 // A scanner used only for input provided to the insert() method.
248 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner; 247 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner;
249 248
250 RefPtr<WebTaskRunner> m_loadingTaskRunner;
251 Member<HTMLParserScheduler> m_parserScheduler; 249 Member<HTMLParserScheduler> m_parserScheduler;
252 HTMLSourceTracker m_sourceTracker; 250 HTMLSourceTracker m_sourceTracker;
253 TextPosition m_textPosition; 251 TextPosition m_textPosition;
254 XSSAuditor m_xssAuditor; 252 XSSAuditor m_xssAuditor;
255 XSSAuditorDelegate m_xssAuditorDelegate; 253 XSSAuditorDelegate m_xssAuditorDelegate;
256 254
257 // FIXME: m_lastChunkBeforePause, m_tokenizer, m_token, and m_input should be 255 // FIXME: m_lastChunkBeforePause, m_tokenizer, m_token, and m_input should be
258 // combined into a single state object so they can be set and cleared together 256 // combined into a single state object so they can be set and cleared together
259 // and passed between threads together. 257 // and passed between threads together.
260 std::unique_ptr<TokenizedChunk> m_lastChunkBeforePause; 258 std::unique_ptr<TokenizedChunk> m_lastChunkBeforePause;
261 Deque<std::unique_ptr<TokenizedChunk>> m_speculations; 259 Deque<std::unique_ptr<TokenizedChunk>> m_speculations;
262 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; 260 Member<BackgroundHTMLParser> m_backgroundParser;
263 WeakPtr<BackgroundHTMLParser> m_backgroundParser;
264 Member<HTMLResourcePreloader> m_preloader; 261 Member<HTMLResourcePreloader> m_preloader;
265 PreloadRequestStream m_queuedPreloads; 262 PreloadRequestStream m_queuedPreloads;
266 Vector<String> m_queuedDocumentWriteScripts; 263 Vector<String> m_queuedDocumentWriteScripts;
267 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue; 264 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue;
268 std::unique_ptr<DocumentWriteEvaluator> m_evaluator; 265 std::unique_ptr<DocumentWriteEvaluator> m_evaluator;
269 266
270 // If this is non-null, then there is a meta CSP token somewhere in the 267 // If this is non-null, then there is a meta CSP token somewhere in the
271 // speculation buffer. Preloads will be deferred until a token matching this 268 // speculation buffer. Preloads will be deferred until a token matching this
272 // pointer is parsed and the CSP policy is applied. Note that this pointer 269 // pointer is parsed and the CSP policy is applied. Note that this pointer
273 // tracks the *last* meta token in the speculation buffer, so it overestimates 270 // tracks the *last* meta token in the speculation buffer, so it overestimates
274 // how long to defer preloads. This is for simplicity, as the alternative 271 // how long to defer preloads. This is for simplicity, as the alternative
275 // would require keeping track of token positions of preload requests. 272 // would require keeping track of token positions of preload requests.
276 CompactHTMLToken* m_pendingCSPMetaToken; 273 CompactHTMLToken* m_pendingCSPMetaToken;
277 274
278 TaskHandle m_resumeParsingTaskHandle; 275 TaskHandle m_resumeParsingTaskHandle;
279 276
280 bool m_shouldUseThreading; 277 bool m_shouldUseThreading;
281 bool m_endWasDelayed; 278 bool m_endWasDelayed;
282 bool m_haveBackgroundParser;
283 bool m_tasksWereSuspended; 279 bool m_tasksWereSuspended;
284 unsigned m_pumpSessionNestingLevel; 280 unsigned m_pumpSessionNestingLevel;
285 unsigned m_pumpSpeculationsSessionNestingLevel; 281 unsigned m_pumpSpeculationsSessionNestingLevel;
286 bool m_isParsingAtLineNumber; 282 bool m_isParsingAtLineNumber;
287 bool m_triedLoadingLinkHeaders; 283 bool m_triedLoadingLinkHeaders;
288 bool m_addedPendingStylesheetInBody; 284 bool m_addedPendingStylesheetInBody;
289 bool m_isWaitingForStylesheets; 285 bool m_isWaitingForStylesheets;
290 }; 286 };
291 287
292 } // namespace blink 288 } // namespace blink
293 289
294 #endif // HTMLDocumentParser_h 290 #endif // HTMLDocumentParser_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698