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

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

Issue 2695633007: Revert of Put the BackgroundHTMLParser on oilpan heap (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2013 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 GOOGLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE 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 GOOGLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE 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 BackgroundHTMLParser_h 26 #ifndef BackgroundHTMLParser_h
27 #define BackgroundHTMLParser_h 27 #define BackgroundHTMLParser_h
28 28
29 #include <memory>
30 #include "core/dom/DocumentEncodingData.h" 29 #include "core/dom/DocumentEncodingData.h"
31 #include "core/html/parser/BackgroundHTMLInputStream.h" 30 #include "core/html/parser/BackgroundHTMLInputStream.h"
32 #include "core/html/parser/CompactHTMLToken.h" 31 #include "core/html/parser/CompactHTMLToken.h"
33 #include "core/html/parser/HTMLParserOptions.h" 32 #include "core/html/parser/HTMLParserOptions.h"
34 #include "core/html/parser/HTMLPreloadScanner.h" 33 #include "core/html/parser/HTMLPreloadScanner.h"
35 #include "core/html/parser/HTMLSourceTracker.h" 34 #include "core/html/parser/HTMLSourceTracker.h"
36 #include "core/html/parser/HTMLTreeBuilderSimulator.h" 35 #include "core/html/parser/HTMLTreeBuilderSimulator.h"
37 #include "core/html/parser/TextResourceDecoder.h" 36 #include "core/html/parser/TextResourceDecoder.h"
37 #include "core/html/parser/TokenizedChunkQueue.h"
38 #include "core/html/parser/XSSAuditorDelegate.h" 38 #include "core/html/parser/XSSAuditorDelegate.h"
39 #include "platform/heap/GarbageCollected.h"
40 #include "wtf/WeakPtr.h" 39 #include "wtf/WeakPtr.h"
40 #include <memory>
41 41
42 namespace blink { 42 namespace blink {
43 43
44 class HTMLDocumentParser; 44 class HTMLDocumentParser;
45 class XSSAuditor; 45 class XSSAuditor;
46 class WebTaskRunner; 46 class WebTaskRunner;
47 47
48 class BackgroundHTMLParser 48 class BackgroundHTMLParser {
49 : public GarbageCollectedFinalized<BackgroundHTMLParser> { 49 USING_FAST_MALLOC(BackgroundHTMLParser);
50 WTF_MAKE_NONCOPYABLE(BackgroundHTMLParser); 50 WTF_MAKE_NONCOPYABLE(BackgroundHTMLParser);
51 51
52 public: 52 public:
53 struct Configuration { 53 struct Configuration {
54 USING_FAST_MALLOC(Configuration); 54 USING_FAST_MALLOC(Configuration);
55 55
56 public: 56 public:
57 Configuration(); 57 Configuration();
58 HTMLParserOptions options; 58 HTMLParserOptions options;
59 WeakPtr<HTMLDocumentParser> parser;
59 std::unique_ptr<XSSAuditor> xssAuditor; 60 std::unique_ptr<XSSAuditor> xssAuditor;
60 std::unique_ptr<TextResourceDecoder> decoder; 61 std::unique_ptr<TextResourceDecoder> decoder;
62 RefPtr<TokenizedChunkQueue> tokenizedChunkQueue;
61 // outstandingTokenLimit must be greater than or equal to 63 // outstandingTokenLimit must be greater than or equal to
62 // pendingTokenLimit 64 // pendingTokenLimit
63 size_t outstandingTokenLimit; 65 size_t outstandingTokenLimit;
64 size_t pendingTokenLimit; 66 size_t pendingTokenLimit;
65 bool shouldCoalesceChunks; 67 bool shouldCoalesceChunks;
66 }; 68 };
67 69
68 static BackgroundHTMLParser* create(HTMLDocumentParser*, 70 // The returned BackgroundHTMLParser should only be used on the parser
69 Document&, 71 // thread: it must first be initialized by calling init(), and free by
70 std::unique_ptr<Configuration>); 72 // calling stop().
71 ~BackgroundHTMLParser(); 73 static WeakPtr<BackgroundHTMLParser> create(std::unique_ptr<Configuration>,
72 74 RefPtr<WebTaskRunner>);
73 DECLARE_TRACE(); 75 void init(const KURL& documentURL,
76 std::unique_ptr<CachedDocumentParameters>,
77 const MediaValuesCached::MediaValuesCachedData&);
74 78
75 struct Checkpoint { 79 struct Checkpoint {
76 USING_FAST_MALLOC(Checkpoint); 80 USING_FAST_MALLOC(Checkpoint);
77 81
78 public: 82 public:
79 WeakPtr<HTMLDocumentParser> parser; 83 WeakPtr<HTMLDocumentParser> parser;
80 std::unique_ptr<HTMLToken> token; 84 std::unique_ptr<HTMLToken> token;
81 std::unique_ptr<HTMLTokenizer> tokenizer; 85 std::unique_ptr<HTMLTokenizer> tokenizer;
82 HTMLTreeBuilderSimulator::State treeBuilderState; 86 HTMLTreeBuilderSimulator::State treeBuilderState;
83 HTMLInputCheckpoint inputCheckpoint; 87 HTMLInputCheckpoint inputCheckpoint;
84 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; 88 TokenPreloadScannerCheckpoint preloadScannerCheckpoint;
85 String unparsedInput; 89 String unparsedInput;
86 }; 90 };
87 91
88 void appendRawBytesFromMainThread(std::unique_ptr<Vector<char>>, 92 void appendRawBytesFromMainThread(std::unique_ptr<Vector<char>>,
89 double bytesReceivedTime); 93 double bytesReceivedTime);
90 void setDecoder(std::unique_ptr<TextResourceDecoder>); 94 void setDecoder(std::unique_ptr<TextResourceDecoder>);
91 void flush(); 95 void flush();
92 void resumeFrom(std::unique_ptr<Checkpoint>); 96 void resumeFrom(std::unique_ptr<Checkpoint>);
93 void startedChunkWithCheckpoint(HTMLInputCheckpoint); 97 void startedChunkWithCheckpoint(HTMLInputCheckpoint);
94 void finish(); 98 void finish();
99 void stop();
95 100
96 void forcePlaintextForTextDocument(); 101 void forcePlaintextForTextDocument();
102
97 private: 103 private:
98 BackgroundHTMLParser(HTMLDocumentParser*, 104 BackgroundHTMLParser(std::unique_ptr<Configuration>, RefPtr<WebTaskRunner>);
99 std::unique_ptr<Configuration>, 105 ~BackgroundHTMLParser();
100 RefPtr<WebTaskRunner>,
101 std::unique_ptr<TokenPreloadScanner>);
102 106
103 void appendDecodedBytes(const String&); 107 void appendDecodedBytes(const String&);
104 void markEndOfFile(); 108 void markEndOfFile();
105 void pumpTokenizer(); 109 void pumpTokenizer();
106 110
107 void onResumeFrom(std::unique_ptr<Checkpoint>);
108 void onFinish();
109
110 // Returns whether or not the HTMLDocumentParser should be notified of 111 // Returns whether or not the HTMLDocumentParser should be notified of
111 // pending chunks. 112 // pending chunks.
112 bool queueChunkForMainThread(); 113 bool queueChunkForMainThread();
113 void notifyMainThreadOfNewChunks(); 114 void notifyMainThreadOfNewChunks();
114 void updateDocument(const String& decodedData); 115 void updateDocument(const String& decodedData);
115 116
117 template <typename FunctionType, typename... Ps>
118 void runOnMainThread(FunctionType, Ps&&...);
119
120 WeakPtrFactory<BackgroundHTMLParser> m_weakFactory;
116 BackgroundHTMLInputStream m_input; 121 BackgroundHTMLInputStream m_input;
117 HTMLSourceTracker m_sourceTracker; 122 HTMLSourceTracker m_sourceTracker;
118 std::unique_ptr<HTMLToken> m_token; 123 std::unique_ptr<HTMLToken> m_token;
119 std::unique_ptr<HTMLTokenizer> m_tokenizer; 124 std::unique_ptr<HTMLTokenizer> m_tokenizer;
120 HTMLTreeBuilderSimulator m_treeBuilderSimulator; 125 HTMLTreeBuilderSimulator m_treeBuilderSimulator;
121 HTMLParserOptions m_options; 126 HTMLParserOptions m_options;
122 const size_t m_outstandingTokenLimit; 127 const size_t m_outstandingTokenLimit;
123 Member<HTMLDocumentParser> m_parser; 128 WeakPtr<HTMLDocumentParser> m_parser;
124 129
125 std::unique_ptr<CompactHTMLTokenStream> m_pendingTokens; 130 std::unique_ptr<CompactHTMLTokenStream> m_pendingTokens;
126 const size_t m_pendingTokenLimit; 131 const size_t m_pendingTokenLimit;
127 PreloadRequestStream m_pendingPreloads; 132 PreloadRequestStream m_pendingPreloads;
128 // Indices into |m_pendingTokens|. 133 // Indices into |m_pendingTokens|.
129 Vector<int> m_likelyDocumentWriteScriptIndices; 134 Vector<int> m_likelyDocumentWriteScriptIndices;
130 ViewportDescriptionWrapper m_viewportDescription; 135 ViewportDescriptionWrapper m_viewportDescription;
131 XSSInfoStream m_pendingXSSInfos; 136 XSSInfoStream m_pendingXSSInfos;
132 137
133 std::unique_ptr<XSSAuditor> m_xssAuditor; 138 std::unique_ptr<XSSAuditor> m_xssAuditor;
134 std::unique_ptr<TokenPreloadScanner> m_preloadScanner; 139 std::unique_ptr<TokenPreloadScanner> m_preloadScanner;
135 std::unique_ptr<TextResourceDecoder> m_decoder; 140 std::unique_ptr<TextResourceDecoder> m_decoder;
136 DocumentEncodingData m_lastSeenEncodingData; 141 DocumentEncodingData m_lastSeenEncodingData;
137 RefPtr<WebTaskRunner> m_loadingTaskRunner; 142 RefPtr<WebTaskRunner> m_loadingTaskRunner;
143 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue;
138 144
139 // Index into |m_pendingTokens| of the last <meta> csp token found. Will be 145 // Index into |m_pendingTokens| of the last <meta> csp token found. Will be
140 // |TokenizedChunk::noPendingToken| if none have been found. 146 // |TokenizedChunk::noPendingToken| if none have been found.
141 int m_pendingCSPMetaTokenIndex; 147 int m_pendingCSPMetaTokenIndex;
142 148
143 bool m_startingScript; 149 bool m_startingScript;
144 double m_lastBytesReceivedTime; 150 double m_lastBytesReceivedTime;
145 bool m_shouldCoalesceChunks; 151 bool m_shouldCoalesceChunks;
146 }; 152 };
147 153
148 } // namespace blink 154 } // namespace blink
149 155
150 #endif 156 #endif
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/parser/BackgroundHTMLParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698