/src/mozilla-central/parser/html/nsHtml5TreeBuilderHSupplement.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | 0 | #define NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH 512 |
6 | | private: |
7 | | using Encoding = mozilla::Encoding; |
8 | | template<typename T> |
9 | | using NotNull = mozilla::NotNull<T>; |
10 | | |
11 | | nsHtml5OplessBuilder* mBuilder; |
12 | | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
13 | | // If mBuilder is not null, the tree op machinery is not in use and |
14 | | // the fields below aren't in use, either. |
15 | | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
16 | | nsHtml5Highlighter* mViewSource; |
17 | | nsTArray<nsHtml5TreeOperation> mOpQueue; |
18 | | nsTArray<nsHtml5SpeculativeLoad> mSpeculativeLoadQueue; |
19 | | nsAHtml5TreeOpSink* mOpSink; |
20 | | mozilla::UniquePtr<nsIContent* []> mHandles; |
21 | | int32_t mHandlesUsed; |
22 | | nsTArray<mozilla::UniquePtr<nsIContent* []>> mOldHandles; |
23 | | nsHtml5TreeOpStage* mSpeculativeLoadStage; |
24 | | nsresult mBroken; |
25 | | bool mCurrentHtmlScriptIsAsyncOrDefer; |
26 | | bool mPreventScriptExecution; |
27 | | #ifdef DEBUG |
28 | | bool mActive; |
29 | | #endif |
30 | | |
31 | | // DocumentModeHandler |
32 | | /** |
33 | | * Tree builder uses this to report quirkiness of the document |
34 | | */ |
35 | | void |
36 | | documentMode(nsHtml5DocumentMode m); |
37 | | |
38 | | nsIContentHandle* |
39 | | getDocumentFragmentForTemplate(nsIContentHandle* aTemplate); |
40 | | |
41 | | nsIContentHandle* |
42 | | getFormPointerForContext(nsIContentHandle* aContext); |
43 | | |
44 | | /** |
45 | | * Using nsIContent** instead of nsIContent* is the parser deals with DOM |
46 | | * nodes in a way that works off the main thread. Non-main-thread code |
47 | | * can't refcount or otherwise touch nsIContent objects in any way. |
48 | | * Yet, the off-the-main-thread code needs to have a way to hold onto a |
49 | | * particular node and repeatedly operate on the same node. |
50 | | * |
51 | | * The way this works is that the off-the-main-thread code has an |
52 | | * nsIContent** for each DOM node and a given nsIContent** is only ever |
53 | | * actually dereferenced into an actual nsIContent* on the main thread. |
54 | | * When the off-the-main-thread code requests a new node, it gets an |
55 | | * nsIContent** immediately and a tree op is enqueued for later allocating |
56 | | * an actual nsIContent object and writing a pointer to it into the memory |
57 | | * location pointed to by the nsIContent**. |
58 | | * |
59 | | * Since tree ops are in a queue, the node creating tree op will always |
60 | | * run before tree ops that try to further operate on the node that the |
61 | | * nsIContent** is a handle to. |
62 | | * |
63 | | * On-the-main-thread parts of the parser use nsIContent* instead of |
64 | | * nsIContent**. Since both cases share the same parser core, the parser |
65 | | * core casts both to nsIContentHandle*. |
66 | | */ |
67 | | nsIContentHandle* |
68 | | AllocateContentHandle(); |
69 | | |
70 | | void |
71 | | accumulateCharactersForced(const char16_t* aBuf, |
72 | | int32_t aStart, |
73 | | int32_t aLength) |
74 | 0 | { |
75 | 0 | accumulateCharacters(aBuf, aStart, aLength); |
76 | 0 | } |
77 | | |
78 | | void |
79 | | MarkAsBrokenAndRequestSuspensionWithBuilder(nsresult aRv) |
80 | 0 | { |
81 | 0 | mBuilder->MarkAsBroken(aRv); |
82 | 0 | requestSuspension(); |
83 | 0 | } |
84 | | |
85 | | void |
86 | | MarkAsBrokenAndRequestSuspensionWithoutBuilder(nsresult aRv) |
87 | 0 | { |
88 | 0 | MarkAsBroken(aRv); |
89 | 0 | requestSuspension(); |
90 | 0 | } |
91 | | |
92 | | void |
93 | | MarkAsBrokenFromPortability(nsresult aRv); |
94 | | |
95 | | public: |
96 | | explicit nsHtml5TreeBuilder(nsHtml5OplessBuilder* aBuilder); |
97 | | |
98 | | nsHtml5TreeBuilder(nsAHtml5TreeOpSink* aOpSink, nsHtml5TreeOpStage* aStage); |
99 | | |
100 | | ~nsHtml5TreeBuilder(); |
101 | | |
102 | | void |
103 | | StartPlainTextViewSource(const nsAutoString& aTitle); |
104 | | |
105 | | void |
106 | | StartPlainText(); |
107 | | |
108 | | void |
109 | | StartPlainTextBody(); |
110 | | |
111 | | bool |
112 | | HasScript(); |
113 | | |
114 | | void |
115 | | SetOpSink(nsAHtml5TreeOpSink* aOpSink) |
116 | 0 | { |
117 | 0 | mOpSink = aOpSink; |
118 | 0 | } |
119 | | |
120 | | void |
121 | | ClearOps() |
122 | 0 | { |
123 | 0 | mOpQueue.Clear(); |
124 | 0 | } |
125 | | |
126 | | bool |
127 | | Flush(bool aDiscretionary = false); |
128 | | |
129 | | void |
130 | | FlushLoads(); |
131 | | |
132 | | void |
133 | | SetDocumentCharset(NotNull<const Encoding*> aEncoding, int32_t aCharsetSource); |
134 | | |
135 | | void |
136 | | StreamEnded(); |
137 | | |
138 | | void |
139 | | NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding, |
140 | | int32_t aSource, |
141 | | int32_t aLineNumber); |
142 | | |
143 | | void |
144 | | MaybeComplainAboutCharset(const char* aMsgId, bool aError, int32_t aLineNumber); |
145 | | |
146 | | void |
147 | | TryToEnableEncodingMenu(); |
148 | | |
149 | | void |
150 | | AddSnapshotToScript(nsAHtml5TreeBuilderState* aSnapshot, int32_t aLine); |
151 | | |
152 | | void |
153 | | DropHandles(); |
154 | | |
155 | | void |
156 | | SetPreventScriptExecution(bool aPrevent) |
157 | 0 | { |
158 | 0 | mPreventScriptExecution = aPrevent; |
159 | 0 | } |
160 | | |
161 | | bool |
162 | | HasBuilder() |
163 | 0 | { |
164 | 0 | return mBuilder; |
165 | 0 | } |
166 | | |
167 | | /** |
168 | | * Makes sure the buffers are large enough to be able to tokenize aLength |
169 | | * UTF-16 code units before having to make the buffers larger. |
170 | | * |
171 | | * @param aLength the number of UTF-16 code units to be tokenized before the |
172 | | * next call to this method. |
173 | | * @return true if successful; false if out of memory |
174 | | */ |
175 | | bool |
176 | | EnsureBufferSpace(int32_t aLength); |
177 | | |
178 | | void |
179 | | EnableViewSource(nsHtml5Highlighter* aHighlighter); |
180 | | |
181 | | void |
182 | | errStrayStartTag(nsAtom* aName); |
183 | | |
184 | | void |
185 | | errStrayEndTag(nsAtom* aName); |
186 | | |
187 | | void |
188 | | errUnclosedElements(int32_t aIndex, nsAtom* aName); |
189 | | |
190 | | void |
191 | | errUnclosedElementsImplied(int32_t aIndex, nsAtom* aName); |
192 | | |
193 | | void |
194 | | errUnclosedElementsCell(int32_t aIndex); |
195 | | |
196 | | void |
197 | | errStrayDoctype(); |
198 | | |
199 | | void |
200 | | errAlmostStandardsDoctype(); |
201 | | |
202 | | void |
203 | | errQuirkyDoctype(); |
204 | | |
205 | | void |
206 | | errNonSpaceInTrailer(); |
207 | | |
208 | | void |
209 | | errNonSpaceAfterFrameset(); |
210 | | |
211 | | void |
212 | | errNonSpaceInFrameset(); |
213 | | |
214 | | void |
215 | | errNonSpaceAfterBody(); |
216 | | |
217 | | void |
218 | | errNonSpaceInColgroupInFragment(); |
219 | | |
220 | | void |
221 | | errNonSpaceInNoscriptInHead(); |
222 | | |
223 | | void |
224 | | errFooBetweenHeadAndBody(nsAtom* aName); |
225 | | |
226 | | void |
227 | | errStartTagWithoutDoctype(); |
228 | | |
229 | | void |
230 | | errNoSelectInTableScope(); |
231 | | |
232 | | void |
233 | | errStartSelectWhereEndSelectExpected(); |
234 | | |
235 | | void |
236 | | errStartTagWithSelectOpen(nsAtom* aName); |
237 | | |
238 | | void |
239 | | errBadStartTagInHead(nsAtom* aName); |
240 | | |
241 | | void |
242 | | errImage(); |
243 | | |
244 | | void |
245 | | errIsindex(); |
246 | | |
247 | | void |
248 | | errFooSeenWhenFooOpen(nsAtom* aName); |
249 | | |
250 | | void |
251 | | errHeadingWhenHeadingOpen(); |
252 | | |
253 | | void |
254 | | errFramesetStart(); |
255 | | |
256 | | void |
257 | | errNoCellToClose(); |
258 | | |
259 | | void |
260 | | errStartTagInTable(nsAtom* aName); |
261 | | |
262 | | void |
263 | | errFormWhenFormOpen(); |
264 | | |
265 | | void |
266 | | errTableSeenWhileTableOpen(); |
267 | | |
268 | | void |
269 | | errStartTagInTableBody(nsAtom* aName); |
270 | | |
271 | | void |
272 | | errEndTagSeenWithoutDoctype(); |
273 | | |
274 | | void |
275 | | errEndTagAfterBody(); |
276 | | |
277 | | void |
278 | | errEndTagSeenWithSelectOpen(nsAtom* aName); |
279 | | |
280 | | void |
281 | | errGarbageInColgroup(); |
282 | | |
283 | | void |
284 | | errEndTagBr(); |
285 | | |
286 | | void |
287 | | errNoElementToCloseButEndTagSeen(nsAtom* aName); |
288 | | |
289 | | void |
290 | | errHtmlStartTagInForeignContext(nsAtom* aName); |
291 | | |
292 | | void |
293 | | errTableClosedWhileCaptionOpen(); |
294 | | |
295 | | void |
296 | | errNoTableRowToClose(); |
297 | | |
298 | | void |
299 | | errNonSpaceInTable(); |
300 | | |
301 | | void |
302 | | errUnclosedChildrenInRuby(); |
303 | | |
304 | | void |
305 | | errStartTagSeenWithoutRuby(nsAtom* aName); |
306 | | |
307 | | void |
308 | | errSelfClosing(); |
309 | | |
310 | | void |
311 | | errNoCheckUnclosedElementsOnStack(); |
312 | | |
313 | | void |
314 | | errEndTagDidNotMatchCurrentOpenElement(nsAtom* aName, nsAtom* aOther); |
315 | | |
316 | | void |
317 | | errEndTagViolatesNestingRules(nsAtom* aName); |
318 | | |
319 | | void |
320 | | errEndWithUnclosedElements(nsAtom* aName); |
321 | | |
322 | | void |
323 | | MarkAsBroken(nsresult aRv); |
324 | | |
325 | | /** |
326 | | * Checks if this parser is broken. Returns a non-NS_OK (i.e. non-0) |
327 | | * value if broken. |
328 | | */ |
329 | | nsresult |
330 | | IsBroken() |
331 | 0 | { |
332 | 0 | return mBroken; |
333 | 0 | } |