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

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