|
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 #include "mozilla/Likely.h" |
|
6 |
|
7 void |
|
8 nsHtml5Tokenizer::StartPlainText() |
|
9 { |
|
10 stateSave = NS_HTML5TOKENIZER_PLAINTEXT; |
|
11 } |
|
12 |
|
13 void |
|
14 nsHtml5Tokenizer::EnableViewSource(nsHtml5Highlighter* aHighlighter) |
|
15 { |
|
16 mViewSource = aHighlighter; |
|
17 } |
|
18 |
|
19 bool |
|
20 nsHtml5Tokenizer::FlushViewSource() |
|
21 { |
|
22 return mViewSource->FlushOps(); |
|
23 } |
|
24 |
|
25 void |
|
26 nsHtml5Tokenizer::StartViewSource(const nsAutoString& aTitle) |
|
27 { |
|
28 mViewSource->Start(aTitle); |
|
29 } |
|
30 |
|
31 void |
|
32 nsHtml5Tokenizer::EndViewSource() |
|
33 { |
|
34 mViewSource->End(); |
|
35 } |
|
36 |
|
37 void |
|
38 nsHtml5Tokenizer::errWarnLtSlashInRcdata() |
|
39 { |
|
40 } |
|
41 |
|
42 // The null checks below annotated MOZ_LIKELY are not actually necessary. |
|
43 |
|
44 void |
|
45 nsHtml5Tokenizer::errUnquotedAttributeValOrNull(char16_t c) |
|
46 { |
|
47 if (MOZ_LIKELY(mViewSource)) { |
|
48 switch (c) { |
|
49 case '<': |
|
50 mViewSource->AddErrorToCurrentNode("errUnquotedAttributeLt"); |
|
51 return; |
|
52 case '`': |
|
53 mViewSource->AddErrorToCurrentNode("errUnquotedAttributeGrave"); |
|
54 return; |
|
55 case '\'': |
|
56 case '"': |
|
57 mViewSource->AddErrorToCurrentNode("errUnquotedAttributeQuote"); |
|
58 return; |
|
59 case '=': |
|
60 mViewSource->AddErrorToCurrentNode("errUnquotedAttributeEquals"); |
|
61 return; |
|
62 } |
|
63 } |
|
64 } |
|
65 |
|
66 void |
|
67 nsHtml5Tokenizer::errLtOrEqualsOrGraveInUnquotedAttributeOrNull(char16_t c) |
|
68 { |
|
69 if (MOZ_LIKELY(mViewSource)) { |
|
70 switch (c) { |
|
71 case '=': |
|
72 mViewSource->AddErrorToCurrentNode("errUnquotedAttributeStartEquals"); |
|
73 return; |
|
74 case '<': |
|
75 mViewSource->AddErrorToCurrentNode("errUnquotedAttributeStartLt"); |
|
76 return; |
|
77 case '`': |
|
78 mViewSource->AddErrorToCurrentNode("errUnquotedAttributeStartGrave"); |
|
79 return; |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 void |
|
85 nsHtml5Tokenizer::errBadCharBeforeAttributeNameOrNull(char16_t c) |
|
86 { |
|
87 if (MOZ_LIKELY(mViewSource)) { |
|
88 if (c == '<') { |
|
89 mViewSource->AddErrorToCurrentNode("errBadCharBeforeAttributeNameLt"); |
|
90 } else if (c == '=') { |
|
91 errEqualsSignBeforeAttributeName(); |
|
92 } else if (c != 0xFFFD) { |
|
93 errQuoteBeforeAttributeName(c); |
|
94 } |
|
95 } |
|
96 } |
|
97 |
|
98 void |
|
99 nsHtml5Tokenizer::errBadCharAfterLt(char16_t c) |
|
100 { |
|
101 if (MOZ_LIKELY(mViewSource)) { |
|
102 mViewSource->AddErrorToCurrentNode("errBadCharAfterLt"); |
|
103 } |
|
104 } |
|
105 |
|
106 void |
|
107 nsHtml5Tokenizer::errQuoteOrLtInAttributeNameOrNull(char16_t c) |
|
108 { |
|
109 if (MOZ_LIKELY(mViewSource)) { |
|
110 if (c == '<') { |
|
111 mViewSource->AddErrorToCurrentNode("errLtInAttributeName"); |
|
112 } else if (c != 0xFFFD) { |
|
113 mViewSource->AddErrorToCurrentNode("errQuoteInAttributeName"); |
|
114 } |
|
115 } |
|
116 } |
|
117 |
|
118 void |
|
119 nsHtml5Tokenizer::maybeErrAttributesOnEndTag(nsHtml5HtmlAttributes* attrs) |
|
120 { |
|
121 if (mViewSource && attrs->getLength() != 0) { |
|
122 /* |
|
123 * When an end tag token is emitted with attributes, that is a parse |
|
124 * error. |
|
125 */ |
|
126 mViewSource->AddErrorToCurrentRun("maybeErrAttributesOnEndTag"); |
|
127 } |
|
128 } |
|
129 |
|
130 void |
|
131 nsHtml5Tokenizer::maybeErrSlashInEndTag(bool selfClosing) |
|
132 { |
|
133 if (mViewSource && selfClosing && endTag) { |
|
134 mViewSource->AddErrorToCurrentSlash("maybeErrSlashInEndTag"); |
|
135 } |
|
136 } |
|
137 |
|
138 char16_t |
|
139 nsHtml5Tokenizer::errNcrNonCharacter(char16_t ch) |
|
140 { |
|
141 if (MOZ_UNLIKELY(mViewSource)) { |
|
142 mViewSource->AddErrorToCurrentNode("errNcrNonCharacter"); |
|
143 } |
|
144 return ch; |
|
145 } |
|
146 |
|
147 void |
|
148 nsHtml5Tokenizer::errAstralNonCharacter(int32_t ch) |
|
149 { |
|
150 if (MOZ_UNLIKELY(mViewSource)) { |
|
151 mViewSource->AddErrorToCurrentNode("errNcrNonCharacter"); |
|
152 } |
|
153 } |
|
154 |
|
155 char16_t |
|
156 nsHtml5Tokenizer::errNcrControlChar(char16_t ch) |
|
157 { |
|
158 if (MOZ_UNLIKELY(mViewSource)) { |
|
159 mViewSource->AddErrorToCurrentNode("errNcrControlChar"); |
|
160 } |
|
161 return ch; |
|
162 } |
|
163 |
|
164 void |
|
165 nsHtml5Tokenizer::errGarbageAfterLtSlash() |
|
166 { |
|
167 if (MOZ_LIKELY(mViewSource)) { |
|
168 mViewSource->AddErrorToCurrentNode("errGarbageAfterLtSlash"); |
|
169 } |
|
170 } |
|
171 |
|
172 void |
|
173 nsHtml5Tokenizer::errLtSlashGt() |
|
174 { |
|
175 if (MOZ_LIKELY(mViewSource)) { |
|
176 mViewSource->AddErrorToCurrentNode("errLtSlashGt"); |
|
177 } |
|
178 } |
|
179 |
|
180 void |
|
181 nsHtml5Tokenizer::errCharRefLacksSemicolon() |
|
182 { |
|
183 if (MOZ_UNLIKELY(mViewSource)) { |
|
184 mViewSource->AddErrorToCurrentNode("errCharRefLacksSemicolon"); |
|
185 } |
|
186 } |
|
187 |
|
188 void |
|
189 nsHtml5Tokenizer::errNoDigitsInNCR() |
|
190 { |
|
191 if (MOZ_UNLIKELY(mViewSource)) { |
|
192 mViewSource->AddErrorToCurrentNode("errNoDigitsInNCR"); |
|
193 } |
|
194 } |
|
195 |
|
196 void |
|
197 nsHtml5Tokenizer::errGtInSystemId() |
|
198 { |
|
199 if (MOZ_LIKELY(mViewSource)) { |
|
200 mViewSource->AddErrorToCurrentNode("errGtInSystemId"); |
|
201 } |
|
202 } |
|
203 |
|
204 void |
|
205 nsHtml5Tokenizer::errGtInPublicId() |
|
206 { |
|
207 if (MOZ_LIKELY(mViewSource)) { |
|
208 mViewSource->AddErrorToCurrentNode("errGtInPublicId"); |
|
209 } |
|
210 } |
|
211 |
|
212 void |
|
213 nsHtml5Tokenizer::errNamelessDoctype() |
|
214 { |
|
215 if (MOZ_LIKELY(mViewSource)) { |
|
216 mViewSource->AddErrorToCurrentNode("errNamelessDoctype"); |
|
217 } |
|
218 } |
|
219 |
|
220 void |
|
221 nsHtml5Tokenizer::errConsecutiveHyphens() |
|
222 { |
|
223 if (MOZ_UNLIKELY(mViewSource)) { |
|
224 mViewSource->AddErrorToCurrentNode("errConsecutiveHyphens"); |
|
225 } |
|
226 } |
|
227 |
|
228 void |
|
229 nsHtml5Tokenizer::errPrematureEndOfComment() |
|
230 { |
|
231 if (MOZ_LIKELY(mViewSource)) { |
|
232 mViewSource->AddErrorToCurrentNode("errPrematureEndOfComment"); |
|
233 } |
|
234 } |
|
235 |
|
236 void |
|
237 nsHtml5Tokenizer::errBogusComment() |
|
238 { |
|
239 if (MOZ_UNLIKELY(mViewSource)) { |
|
240 mViewSource->AddErrorToCurrentNode("errBogusComment"); |
|
241 } |
|
242 } |
|
243 |
|
244 void |
|
245 nsHtml5Tokenizer::errSlashNotFollowedByGt() |
|
246 { |
|
247 if (MOZ_LIKELY(mViewSource)) { |
|
248 mViewSource->AddErrorToCurrentSlash("errSlashNotFollowedByGt"); |
|
249 } |
|
250 } |
|
251 |
|
252 void |
|
253 nsHtml5Tokenizer::errNoSpaceBetweenAttributes() |
|
254 { |
|
255 if (MOZ_LIKELY(mViewSource)) { |
|
256 mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenAttributes"); |
|
257 } |
|
258 } |
|
259 |
|
260 void |
|
261 nsHtml5Tokenizer::errAttributeValueMissing() |
|
262 { |
|
263 if (MOZ_LIKELY(mViewSource)) { |
|
264 mViewSource->AddErrorToCurrentNode("errAttributeValueMissing"); |
|
265 } |
|
266 } |
|
267 |
|
268 void |
|
269 nsHtml5Tokenizer::errEqualsSignBeforeAttributeName() |
|
270 { |
|
271 if (MOZ_LIKELY(mViewSource)) { |
|
272 mViewSource->AddErrorToCurrentNode("errEqualsSignBeforeAttributeName"); |
|
273 } |
|
274 } |
|
275 |
|
276 void |
|
277 nsHtml5Tokenizer::errLtGt() |
|
278 { |
|
279 if (MOZ_LIKELY(mViewSource)) { |
|
280 mViewSource->AddErrorToCurrentNode("errLtGt"); |
|
281 } |
|
282 } |
|
283 |
|
284 void |
|
285 nsHtml5Tokenizer::errProcessingInstruction() |
|
286 { |
|
287 if (MOZ_LIKELY(mViewSource)) { |
|
288 mViewSource->AddErrorToCurrentNode("errProcessingInstruction"); |
|
289 } |
|
290 } |
|
291 |
|
292 void |
|
293 nsHtml5Tokenizer::errUnescapedAmpersandInterpretedAsCharacterReference() |
|
294 { |
|
295 if (MOZ_UNLIKELY(mViewSource)) { |
|
296 mViewSource->AddErrorToCurrentAmpersand("errUnescapedAmpersandInterpretedAsCharacterReference"); |
|
297 } |
|
298 } |
|
299 |
|
300 void |
|
301 nsHtml5Tokenizer::errNotSemicolonTerminated() |
|
302 { |
|
303 if (MOZ_UNLIKELY(mViewSource)) { |
|
304 mViewSource->AddErrorToCurrentNode("errNotSemicolonTerminated"); |
|
305 } |
|
306 } |
|
307 |
|
308 void |
|
309 nsHtml5Tokenizer::errNoNamedCharacterMatch() |
|
310 { |
|
311 if (MOZ_UNLIKELY(mViewSource)) { |
|
312 mViewSource->AddErrorToCurrentAmpersand("errNoNamedCharacterMatch"); |
|
313 } |
|
314 } |
|
315 |
|
316 void |
|
317 nsHtml5Tokenizer::errQuoteBeforeAttributeName(char16_t c) |
|
318 { |
|
319 if (MOZ_LIKELY(mViewSource)) { |
|
320 mViewSource->AddErrorToCurrentNode("errQuoteBeforeAttributeName"); |
|
321 } |
|
322 } |
|
323 |
|
324 void |
|
325 nsHtml5Tokenizer::errExpectedPublicId() |
|
326 { |
|
327 if (MOZ_LIKELY(mViewSource)) { |
|
328 mViewSource->AddErrorToCurrentNode("errExpectedPublicId"); |
|
329 } |
|
330 } |
|
331 |
|
332 void |
|
333 nsHtml5Tokenizer::errBogusDoctype() |
|
334 { |
|
335 if (MOZ_UNLIKELY(mViewSource)) { |
|
336 mViewSource->AddErrorToCurrentNode("errBogusDoctype"); |
|
337 } |
|
338 } |
|
339 |
|
340 void |
|
341 nsHtml5Tokenizer::errNcrSurrogate() |
|
342 { |
|
343 if (MOZ_UNLIKELY(mViewSource)) { |
|
344 mViewSource->AddErrorToCurrentNode("errNcrSurrogate"); |
|
345 } |
|
346 } |
|
347 |
|
348 void |
|
349 nsHtml5Tokenizer::errNcrCr() |
|
350 { |
|
351 if (MOZ_UNLIKELY(mViewSource)) { |
|
352 mViewSource->AddErrorToCurrentNode("errNcrCr"); |
|
353 } |
|
354 } |
|
355 |
|
356 void |
|
357 nsHtml5Tokenizer::errNcrInC1Range() |
|
358 { |
|
359 if (MOZ_UNLIKELY(mViewSource)) { |
|
360 mViewSource->AddErrorToCurrentNode("errNcrInC1Range"); |
|
361 } |
|
362 } |
|
363 |
|
364 void |
|
365 nsHtml5Tokenizer::errEofInPublicId() |
|
366 { |
|
367 if (MOZ_UNLIKELY(mViewSource)) { |
|
368 mViewSource->AddErrorToCurrentRun("errEofInPublicId"); |
|
369 } |
|
370 } |
|
371 |
|
372 void |
|
373 nsHtml5Tokenizer::errEofInComment() |
|
374 { |
|
375 if (MOZ_UNLIKELY(mViewSource)) { |
|
376 mViewSource->AddErrorToCurrentRun("errEofInComment"); |
|
377 } |
|
378 } |
|
379 |
|
380 void |
|
381 nsHtml5Tokenizer::errEofInDoctype() |
|
382 { |
|
383 if (MOZ_UNLIKELY(mViewSource)) { |
|
384 mViewSource->AddErrorToCurrentRun("errEofInDoctype"); |
|
385 } |
|
386 } |
|
387 |
|
388 void |
|
389 nsHtml5Tokenizer::errEofInAttributeValue() |
|
390 { |
|
391 if (MOZ_UNLIKELY(mViewSource)) { |
|
392 mViewSource->AddErrorToCurrentRun("errEofInAttributeValue"); |
|
393 } |
|
394 } |
|
395 |
|
396 void |
|
397 nsHtml5Tokenizer::errEofInAttributeName() |
|
398 { |
|
399 if (MOZ_UNLIKELY(mViewSource)) { |
|
400 mViewSource->AddErrorToCurrentRun("errEofInAttributeName"); |
|
401 } |
|
402 } |
|
403 |
|
404 void |
|
405 nsHtml5Tokenizer::errEofWithoutGt() |
|
406 { |
|
407 if (MOZ_UNLIKELY(mViewSource)) { |
|
408 mViewSource->AddErrorToCurrentRun("errEofWithoutGt"); |
|
409 } |
|
410 } |
|
411 |
|
412 void |
|
413 nsHtml5Tokenizer::errEofInTagName() |
|
414 { |
|
415 if (MOZ_UNLIKELY(mViewSource)) { |
|
416 mViewSource->AddErrorToCurrentRun("errEofInTagName"); |
|
417 } |
|
418 } |
|
419 |
|
420 void |
|
421 nsHtml5Tokenizer::errEofInEndTag() |
|
422 { |
|
423 if (MOZ_UNLIKELY(mViewSource)) { |
|
424 mViewSource->AddErrorToCurrentRun("errEofInEndTag"); |
|
425 } |
|
426 } |
|
427 |
|
428 void |
|
429 nsHtml5Tokenizer::errEofAfterLt() |
|
430 { |
|
431 if (MOZ_UNLIKELY(mViewSource)) { |
|
432 mViewSource->AddErrorToCurrentRun("errEofAfterLt"); |
|
433 } |
|
434 } |
|
435 |
|
436 void |
|
437 nsHtml5Tokenizer::errNcrOutOfRange() |
|
438 { |
|
439 if (MOZ_UNLIKELY(mViewSource)) { |
|
440 mViewSource->AddErrorToCurrentNode("errNcrOutOfRange"); |
|
441 } |
|
442 } |
|
443 |
|
444 void |
|
445 nsHtml5Tokenizer::errNcrUnassigned() |
|
446 { |
|
447 if (MOZ_UNLIKELY(mViewSource)) { |
|
448 mViewSource->AddErrorToCurrentNode("errNcrUnassigned"); |
|
449 } |
|
450 } |
|
451 |
|
452 void |
|
453 nsHtml5Tokenizer::errDuplicateAttribute() |
|
454 { |
|
455 if (MOZ_UNLIKELY(mViewSource)) { |
|
456 mViewSource->AddErrorToCurrentNode("errDuplicateAttribute"); |
|
457 } |
|
458 } |
|
459 |
|
460 void |
|
461 nsHtml5Tokenizer::errEofInSystemId() |
|
462 { |
|
463 if (MOZ_UNLIKELY(mViewSource)) { |
|
464 mViewSource->AddErrorToCurrentRun("errEofInSystemId"); |
|
465 } |
|
466 } |
|
467 |
|
468 void |
|
469 nsHtml5Tokenizer::errExpectedSystemId() |
|
470 { |
|
471 if (MOZ_LIKELY(mViewSource)) { |
|
472 mViewSource->AddErrorToCurrentNode("errExpectedSystemId"); |
|
473 } |
|
474 } |
|
475 |
|
476 void |
|
477 nsHtml5Tokenizer::errMissingSpaceBeforeDoctypeName() |
|
478 { |
|
479 if (MOZ_LIKELY(mViewSource)) { |
|
480 mViewSource->AddErrorToCurrentNode("errMissingSpaceBeforeDoctypeName"); |
|
481 } |
|
482 } |
|
483 |
|
484 void |
|
485 nsHtml5Tokenizer::errHyphenHyphenBang() |
|
486 { |
|
487 if (MOZ_LIKELY(mViewSource)) { |
|
488 mViewSource->AddErrorToCurrentNode("errHyphenHyphenBang"); |
|
489 } |
|
490 } |
|
491 |
|
492 void |
|
493 nsHtml5Tokenizer::errNcrControlChar() |
|
494 { |
|
495 if (MOZ_UNLIKELY(mViewSource)) { |
|
496 mViewSource->AddErrorToCurrentNode("errNcrControlChar"); |
|
497 } |
|
498 } |
|
499 |
|
500 void |
|
501 nsHtml5Tokenizer::errNcrZero() |
|
502 { |
|
503 if (MOZ_UNLIKELY(mViewSource)) { |
|
504 mViewSource->AddErrorToCurrentNode("errNcrZero"); |
|
505 } |
|
506 } |
|
507 |
|
508 void |
|
509 nsHtml5Tokenizer::errNoSpaceBetweenDoctypeSystemKeywordAndQuote() |
|
510 { |
|
511 if (MOZ_LIKELY(mViewSource)) { |
|
512 mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenDoctypeSystemKeywordAndQuote"); |
|
513 } |
|
514 } |
|
515 |
|
516 void |
|
517 nsHtml5Tokenizer::errNoSpaceBetweenPublicAndSystemIds() |
|
518 { |
|
519 if (MOZ_LIKELY(mViewSource)) { |
|
520 mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenPublicAndSystemIds"); |
|
521 } |
|
522 } |
|
523 |
|
524 void |
|
525 nsHtml5Tokenizer::errNoSpaceBetweenDoctypePublicKeywordAndQuote() |
|
526 { |
|
527 if (MOZ_LIKELY(mViewSource)) { |
|
528 mViewSource->AddErrorToCurrentNode("errNoSpaceBetweenDoctypePublicKeywordAndQuote"); |
|
529 } |
|
530 } |