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

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

Issue 2683653004: Put the BackgroundHTMLParser on oilpan heap (Closed)
Patch Set: Save ASSERT->DCHECK for another patch 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> {
Yoav Weiss 2017/02/09 10:39:00 I don't think this needs to be Finalized, as it ha
Charlie Harrison 2017/02/13 22:55:32 It does need to be finalized, because a bunch of f
Yoav Weiss 2017/02/14 06:45:47 ok
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 ~BackgroundHTMLParser();
74 RefPtr<WebTaskRunner>); 74
75 void init(const KURL& documentURL, 75 DECLARE_TRACE();
76 std::unique_ptr<CachedDocumentParameters>,
77 const MediaValuesCached::MediaValuesCachedData&);
78 76
79 struct Checkpoint { 77 struct Checkpoint {
80 USING_FAST_MALLOC(Checkpoint); 78 USING_FAST_MALLOC(Checkpoint);
81 79
82 public: 80 public:
83 WeakPtr<HTMLDocumentParser> parser; 81 WeakPtr<HTMLDocumentParser> parser;
84 std::unique_ptr<HTMLToken> token; 82 std::unique_ptr<HTMLToken> token;
85 std::unique_ptr<HTMLTokenizer> tokenizer; 83 std::unique_ptr<HTMLTokenizer> tokenizer;
86 HTMLTreeBuilderSimulator::State treeBuilderState; 84 HTMLTreeBuilderSimulator::State treeBuilderState;
87 HTMLInputCheckpoint inputCheckpoint; 85 HTMLInputCheckpoint inputCheckpoint;
88 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; 86 TokenPreloadScannerCheckpoint preloadScannerCheckpoint;
89 String unparsedInput; 87 String unparsedInput;
90 }; 88 };
91 89
92 void appendRawBytesFromMainThread(std::unique_ptr<Vector<char>>, 90 void appendRawBytesFromMainThread(std::unique_ptr<Vector<char>>,
93 double bytesReceivedTime); 91 double bytesReceivedTime);
94 void setDecoder(std::unique_ptr<TextResourceDecoder>); 92 void setDecoder(std::unique_ptr<TextResourceDecoder>);
95 void flush(); 93 void flush();
96 void resumeFrom(std::unique_ptr<Checkpoint>); 94 void resumeFrom(std::unique_ptr<Checkpoint>);
97 void startedChunkWithCheckpoint(HTMLInputCheckpoint); 95 void startedChunkWithCheckpoint(HTMLInputCheckpoint);
98 void finish(); 96 void finish();
99 void stop();
100 97
101 void forcePlaintextForTextDocument(); 98 void forcePlaintextForTextDocument();
102
103 private: 99 private:
104 BackgroundHTMLParser(std::unique_ptr<Configuration>, RefPtr<WebTaskRunner>); 100 BackgroundHTMLParser(HTMLDocumentParser*,
105 ~BackgroundHTMLParser(); 101 std::unique_ptr<Configuration>,
102 RefPtr<WebTaskRunner>,
103 std::unique_ptr<TokenPreloadScanner>);
106 104
107 void appendDecodedBytes(const String&); 105 void appendDecodedBytes(const String&);
108 void markEndOfFile(); 106 void markEndOfFile();
109 void pumpTokenizer(); 107 void pumpTokenizer();
110 108
109 void onResumeFrom(std::unique_ptr<Checkpoint>);
110 void onFinish();
111
111 // Returns whether or not the HTMLDocumentParser should be notified of 112 // Returns whether or not the HTMLDocumentParser should be notified of
112 // pending chunks. 113 // pending chunks.
113 bool queueChunkForMainThread(); 114 bool queueChunkForMainThread();
114 void notifyMainThreadOfNewChunks(); 115 void notifyMainThreadOfNewChunks();
115 void updateDocument(const String& decodedData); 116 void updateDocument(const String& decodedData);
116 117
117 template <typename FunctionType, typename... Ps>
118 void runOnMainThread(FunctionType, Ps&&...);
119
120 WeakPtrFactory<BackgroundHTMLParser> m_weakFactory;
121 BackgroundHTMLInputStream m_input; 118 BackgroundHTMLInputStream m_input;
122 HTMLSourceTracker m_sourceTracker; 119 HTMLSourceTracker m_sourceTracker;
123 std::unique_ptr<HTMLToken> m_token; 120 std::unique_ptr<HTMLToken> m_token;
124 std::unique_ptr<HTMLTokenizer> m_tokenizer; 121 std::unique_ptr<HTMLTokenizer> m_tokenizer;
125 HTMLTreeBuilderSimulator m_treeBuilderSimulator; 122 HTMLTreeBuilderSimulator m_treeBuilderSimulator;
126 HTMLParserOptions m_options; 123 HTMLParserOptions m_options;
127 const size_t m_outstandingTokenLimit; 124 const size_t m_outstandingTokenLimit;
128 WeakPtr<HTMLDocumentParser> m_parser; 125 Member<HTMLDocumentParser> m_parser;
129 126
130 std::unique_ptr<CompactHTMLTokenStream> m_pendingTokens; 127 std::unique_ptr<CompactHTMLTokenStream> m_pendingTokens;
131 const size_t m_pendingTokenLimit; 128 const size_t m_pendingTokenLimit;
132 PreloadRequestStream m_pendingPreloads; 129 PreloadRequestStream m_pendingPreloads;
133 // Indices into |m_pendingTokens|. 130 // Indices into |m_pendingTokens|.
134 Vector<int> m_likelyDocumentWriteScriptIndices; 131 Vector<int> m_likelyDocumentWriteScriptIndices;
135 ViewportDescriptionWrapper m_viewportDescription; 132 ViewportDescriptionWrapper m_viewportDescription;
136 XSSInfoStream m_pendingXSSInfos; 133 XSSInfoStream m_pendingXSSInfos;
137 134
138 std::unique_ptr<XSSAuditor> m_xssAuditor; 135 std::unique_ptr<XSSAuditor> m_xssAuditor;
139 std::unique_ptr<TokenPreloadScanner> m_preloadScanner; 136 std::unique_ptr<TokenPreloadScanner> m_preloadScanner;
140 std::unique_ptr<TextResourceDecoder> m_decoder; 137 std::unique_ptr<TextResourceDecoder> m_decoder;
141 DocumentEncodingData m_lastSeenEncodingData; 138 DocumentEncodingData m_lastSeenEncodingData;
142 RefPtr<WebTaskRunner> m_loadingTaskRunner; 139 RefPtr<WebTaskRunner> m_loadingTaskRunner;
143 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue; 140 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue;
Yoav Weiss 2017/02/09 10:39:00 Seems like we could have moved TokenizedChunkQueue
Charlie Harrison 2017/02/13 22:55:32 We'll probably want this to be a raw pointer, and
kouhei (in TOK) 2017/02/13 23:09:14 Optional (assuming TokenizedChunkQueue to also go
Charlie Harrison 2017/02/13 23:19:31 Done.
144 141
145 // Index into |m_pendingTokens| of the last <meta> csp token found. Will be 142 // Index into |m_pendingTokens| of the last <meta> csp token found. Will be
146 // |TokenizedChunk::noPendingToken| if none have been found. 143 // |TokenizedChunk::noPendingToken| if none have been found.
147 int m_pendingCSPMetaTokenIndex; 144 int m_pendingCSPMetaTokenIndex;
148 145
149 bool m_startingScript; 146 bool m_startingScript;
150 double m_lastBytesReceivedTime; 147 double m_lastBytesReceivedTime;
151 bool m_shouldCoalesceChunks; 148 bool m_shouldCoalesceChunks;
152 }; 149 };
153 150
154 } // namespace blink 151 } // namespace blink
155 152
156 #endif 153 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698