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

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

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

Powered by Google App Engine
This is Rietveld 408576698