2 * Copyright (c) 2007 Henri Sivonen
3 * Copyright (c) 2008-2015 Mozilla Foundation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
26 * Please edit MetaScanner.java instead and regenerate.
29 #define nsHtml5MetaScanner_cpp__
32 #include "nsHtml5AtomTable.h"
33 #include "nsHtml5String.h"
34 #include "nsNameSpaceManager.h"
35 #include "nsIContent.h"
36 #include "nsTraceRefcnt.h"
38 #include "nsHtml5ArrayCopy.h"
39 #include "nsAHtml5TreeBuilderState.h"
40 #include "nsGkAtoms.h"
41 #include "nsHtml5ByteReadable.h"
42 #include "nsHtml5Macros.h"
43 #include "nsIContentHandle.h"
44 #include "nsHtml5Portability.h"
45 #include "nsHtml5ContentCreatorFunction.h"
47 #include "nsHtml5AttributeName.h"
48 #include "nsHtml5ElementName.h"
49 #include "nsHtml5Tokenizer.h"
50 #include "nsHtml5TreeBuilder.h"
51 #include "nsHtml5StackNode.h"
52 #include "nsHtml5UTF16Buffer.h"
53 #include "nsHtml5StateSnapshot.h"
54 #include "nsHtml5Portability.h"
56 #include "nsHtml5MetaScanner.h"
58 static char16_t
const CHARSET_DATA
[] = {'h', 'a', 'r', 's', 'e', 't'};
59 staticJArray
<char16_t
, int32_t> nsHtml5MetaScanner::CHARSET
= {
60 CHARSET_DATA
, MOZ_ARRAY_LENGTH(CHARSET_DATA
)};
61 static char16_t
const CONTENT_DATA
[] = {'o', 'n', 't', 'e', 'n', 't'};
62 staticJArray
<char16_t
, int32_t> nsHtml5MetaScanner::CONTENT
= {
63 CONTENT_DATA
, MOZ_ARRAY_LENGTH(CONTENT_DATA
)};
64 static char16_t
const HTTP_EQUIV_DATA
[] = {'t', 't', 'p', '-', 'e',
66 staticJArray
<char16_t
, int32_t> nsHtml5MetaScanner::HTTP_EQUIV
= {
67 HTTP_EQUIV_DATA
, MOZ_ARRAY_LENGTH(HTTP_EQUIV_DATA
)};
68 static char16_t
const CONTENT_TYPE_DATA
[] = {'c', 'o', 'n', 't', 'e', 'n',
69 't', '-', 't', 'y', 'p', 'e'};
70 staticJArray
<char16_t
, int32_t> nsHtml5MetaScanner::CONTENT_TYPE
= {
71 CONTENT_TYPE_DATA
, MOZ_ARRAY_LENGTH(CONTENT_TYPE_DATA
)};
73 nsHtml5MetaScanner::nsHtml5MetaScanner(nsHtml5TreeBuilder
* tb
)
76 contentIndex(INT32_MAX
),
77 charsetIndex(INT32_MAX
),
78 httpEquivIndex(INT32_MAX
),
79 contentTypeIndex(INT32_MAX
),
82 strBuf(jArray
<char16_t
, int32_t>::newJArray(36)),
85 httpEquivState(HTTP_EQUIV_NOT_SEEN
),
88 MOZ_COUNT_CTOR(nsHtml5MetaScanner
);
91 nsHtml5MetaScanner::~nsHtml5MetaScanner() {
92 MOZ_COUNT_DTOR(nsHtml5MetaScanner
);
97 void nsHtml5MetaScanner::stateLoop(int32_t state
) {
99 bool reconsume
= false;
112 NS_HTML5_BREAK(stateloop
);
115 state
= nsHtml5MetaScanner::TAG_OPEN
;
116 NS_HTML5_BREAK(dataloop
);
118 default: { continue; }
129 NS_HTML5_BREAK(stateloop
);
134 state
= nsHtml5MetaScanner::TAG_NAME
;
135 NS_HTML5_BREAK(tagopenloop
);
138 state
= nsHtml5MetaScanner::MARKUP_DECLARATION_OPEN
;
139 NS_HTML5_CONTINUE(stateloop
);
143 state
= nsHtml5MetaScanner::SCAN_UNTIL_GT
;
144 NS_HTML5_CONTINUE(stateloop
);
147 state
= nsHtml5MetaScanner::DATA
;
148 NS_HTML5_CONTINUE(stateloop
);
151 if ((c
>= 'A' && c
<= 'Z') || (c
>= 'a' && c
<= 'z')) {
153 state
= nsHtml5MetaScanner::TAG_NAME
;
154 NS_HTML5_BREAK(tagopenloop
);
156 state
= nsHtml5MetaScanner::DATA
;
158 NS_HTML5_CONTINUE(stateloop
);
170 NS_HTML5_BREAK(stateloop
);
176 state
= nsHtml5MetaScanner::BEFORE_ATTRIBUTE_NAME
;
177 NS_HTML5_BREAK(tagnameloop
);
180 state
= nsHtml5MetaScanner::SELF_CLOSING_START_TAG
;
181 NS_HTML5_CONTINUE(stateloop
);
184 state
= nsHtml5MetaScanner::DATA
;
185 NS_HTML5_CONTINUE(stateloop
);
189 if (metaState
== M
) {
198 if (metaState
== E
) {
207 if (metaState
== T
) {
223 case BEFORE_ATTRIBUTE_NAME
: {
232 NS_HTML5_BREAK(stateloop
);
241 state
= nsHtml5MetaScanner::SELF_CLOSING_START_TAG
;
242 NS_HTML5_CONTINUE(stateloop
);
246 NS_HTML5_BREAK(stateloop
);
249 NS_HTML5_CONTINUE(stateloop
);
255 httpEquivIndex
= INT32_MAX
;
256 contentTypeIndex
= INT32_MAX
;
257 state
= nsHtml5MetaScanner::ATTRIBUTE_NAME
;
258 NS_HTML5_BREAK(beforeattributenameloop
);
262 contentIndex
= INT32_MAX
;
263 charsetIndex
= INT32_MAX
;
265 contentTypeIndex
= INT32_MAX
;
266 state
= nsHtml5MetaScanner::ATTRIBUTE_NAME
;
267 NS_HTML5_BREAK(beforeattributenameloop
);
270 contentIndex
= INT32_MAX
;
271 charsetIndex
= INT32_MAX
;
272 httpEquivIndex
= INT32_MAX
;
273 contentTypeIndex
= INT32_MAX
;
274 state
= nsHtml5MetaScanner::ATTRIBUTE_NAME
;
275 NS_HTML5_BREAK(beforeattributenameloop
);
279 beforeattributenameloop_end
:;
282 case ATTRIBUTE_NAME
: {
287 NS_HTML5_BREAK(stateloop
);
293 state
= nsHtml5MetaScanner::AFTER_ATTRIBUTE_NAME
;
294 NS_HTML5_CONTINUE(stateloop
);
297 state
= nsHtml5MetaScanner::SELF_CLOSING_START_TAG
;
298 NS_HTML5_CONTINUE(stateloop
);
302 contentTypeIndex
= 0;
303 state
= nsHtml5MetaScanner::BEFORE_ATTRIBUTE_VALUE
;
304 NS_HTML5_BREAK(attributenameloop
);
308 NS_HTML5_BREAK(stateloop
);
310 state
= nsHtml5MetaScanner::DATA
;
311 NS_HTML5_CONTINUE(stateloop
);
314 if (metaState
== A
) {
315 if (c
>= 'A' && c
<= 'Z') {
318 if (contentIndex
< CONTENT
.length
&&
319 c
== CONTENT
[contentIndex
]) {
322 contentIndex
= INT32_MAX
;
324 if (charsetIndex
< CHARSET
.length
&&
325 c
== CHARSET
[charsetIndex
]) {
328 charsetIndex
= INT32_MAX
;
330 if (httpEquivIndex
< HTTP_EQUIV
.length
&&
331 c
== HTTP_EQUIV
[httpEquivIndex
]) {
334 httpEquivIndex
= INT32_MAX
;
341 attributenameloop_end
:;
344 case BEFORE_ATTRIBUTE_VALUE
: {
349 NS_HTML5_BREAK(stateloop
);
358 state
= nsHtml5MetaScanner::ATTRIBUTE_VALUE_DOUBLE_QUOTED
;
359 NS_HTML5_BREAK(beforeattributevalueloop
);
362 state
= nsHtml5MetaScanner::ATTRIBUTE_VALUE_SINGLE_QUOTED
;
363 NS_HTML5_CONTINUE(stateloop
);
367 NS_HTML5_BREAK(stateloop
);
369 state
= nsHtml5MetaScanner::DATA
;
370 NS_HTML5_CONTINUE(stateloop
);
373 handleCharInAttributeValue(c
);
374 state
= nsHtml5MetaScanner::ATTRIBUTE_VALUE_UNQUOTED
;
375 NS_HTML5_CONTINUE(stateloop
);
379 beforeattributevalueloop_end
:;
382 case ATTRIBUTE_VALUE_DOUBLE_QUOTED
: {
391 NS_HTML5_BREAK(stateloop
);
394 handleAttributeValue();
395 state
= nsHtml5MetaScanner::AFTER_ATTRIBUTE_VALUE_QUOTED
;
396 NS_HTML5_BREAK(attributevaluedoublequotedloop
);
399 handleCharInAttributeValue(c
);
404 attributevaluedoublequotedloop_end
:;
407 case AFTER_ATTRIBUTE_VALUE_QUOTED
: {
412 NS_HTML5_BREAK(stateloop
);
418 state
= nsHtml5MetaScanner::BEFORE_ATTRIBUTE_NAME
;
419 NS_HTML5_CONTINUE(stateloop
);
422 state
= nsHtml5MetaScanner::SELF_CLOSING_START_TAG
;
423 NS_HTML5_BREAK(afterattributevaluequotedloop
);
427 NS_HTML5_BREAK(stateloop
);
429 state
= nsHtml5MetaScanner::DATA
;
430 NS_HTML5_CONTINUE(stateloop
);
433 state
= nsHtml5MetaScanner::BEFORE_ATTRIBUTE_NAME
;
435 NS_HTML5_CONTINUE(stateloop
);
439 afterattributevaluequotedloop_end
:;
442 case SELF_CLOSING_START_TAG
: {
446 NS_HTML5_BREAK(stateloop
);
450 NS_HTML5_BREAK(stateloop
);
452 state
= nsHtml5MetaScanner::DATA
;
453 NS_HTML5_CONTINUE(stateloop
);
456 state
= nsHtml5MetaScanner::BEFORE_ATTRIBUTE_NAME
;
458 NS_HTML5_CONTINUE(stateloop
);
462 case ATTRIBUTE_VALUE_UNQUOTED
: {
471 NS_HTML5_BREAK(stateloop
);
477 handleAttributeValue();
478 state
= nsHtml5MetaScanner::BEFORE_ATTRIBUTE_NAME
;
479 NS_HTML5_CONTINUE(stateloop
);
482 handleAttributeValue();
484 NS_HTML5_BREAK(stateloop
);
486 state
= nsHtml5MetaScanner::DATA
;
487 NS_HTML5_CONTINUE(stateloop
);
490 handleCharInAttributeValue(c
);
496 case AFTER_ATTRIBUTE_NAME
: {
501 NS_HTML5_BREAK(stateloop
);
510 handleAttributeValue();
511 state
= nsHtml5MetaScanner::SELF_CLOSING_START_TAG
;
512 NS_HTML5_CONTINUE(stateloop
);
516 contentTypeIndex
= 0;
517 state
= nsHtml5MetaScanner::BEFORE_ATTRIBUTE_VALUE
;
518 NS_HTML5_CONTINUE(stateloop
);
521 handleAttributeValue();
523 NS_HTML5_BREAK(stateloop
);
525 state
= nsHtml5MetaScanner::DATA
;
526 NS_HTML5_CONTINUE(stateloop
);
532 state
= nsHtml5MetaScanner::ATTRIBUTE_NAME
;
533 NS_HTML5_CONTINUE(stateloop
);
536 contentIndex
= INT32_MAX
;
537 charsetIndex
= INT32_MAX
;
538 state
= nsHtml5MetaScanner::ATTRIBUTE_NAME
;
539 NS_HTML5_CONTINUE(stateloop
);
544 case MARKUP_DECLARATION_OPEN
: {
549 NS_HTML5_BREAK(stateloop
);
552 state
= nsHtml5MetaScanner::MARKUP_DECLARATION_HYPHEN
;
553 NS_HTML5_BREAK(markupdeclarationopenloop
);
556 state
= nsHtml5MetaScanner::SCAN_UNTIL_GT
;
558 NS_HTML5_CONTINUE(stateloop
);
562 markupdeclarationopenloop_end
:;
565 case MARKUP_DECLARATION_HYPHEN
: {
570 NS_HTML5_BREAK(stateloop
);
573 state
= nsHtml5MetaScanner::COMMENT_START
;
574 NS_HTML5_BREAK(markupdeclarationhyphenloop
);
577 state
= nsHtml5MetaScanner::SCAN_UNTIL_GT
;
579 NS_HTML5_CONTINUE(stateloop
);
583 markupdeclarationhyphenloop_end
:;
586 case COMMENT_START
: {
591 NS_HTML5_BREAK(stateloop
);
594 state
= nsHtml5MetaScanner::COMMENT_START_DASH
;
595 NS_HTML5_CONTINUE(stateloop
);
598 state
= nsHtml5MetaScanner::DATA
;
599 NS_HTML5_CONTINUE(stateloop
);
602 state
= nsHtml5MetaScanner::COMMENT
;
603 NS_HTML5_BREAK(commentstartloop
);
607 commentstartloop_end
:;
615 NS_HTML5_BREAK(stateloop
);
618 state
= nsHtml5MetaScanner::COMMENT_END_DASH
;
619 NS_HTML5_BREAK(commentloop
);
621 default: { continue; }
627 case COMMENT_END_DASH
: {
632 NS_HTML5_BREAK(stateloop
);
635 state
= nsHtml5MetaScanner::COMMENT_END
;
636 NS_HTML5_BREAK(commentenddashloop
);
639 state
= nsHtml5MetaScanner::COMMENT
;
640 NS_HTML5_CONTINUE(stateloop
);
644 commentenddashloop_end
:;
652 NS_HTML5_BREAK(stateloop
);
655 state
= nsHtml5MetaScanner::DATA
;
656 NS_HTML5_CONTINUE(stateloop
);
662 state
= nsHtml5MetaScanner::COMMENT
;
663 NS_HTML5_CONTINUE(stateloop
);
668 case COMMENT_START_DASH
: {
672 NS_HTML5_BREAK(stateloop
);
675 state
= nsHtml5MetaScanner::COMMENT_END
;
676 NS_HTML5_CONTINUE(stateloop
);
679 state
= nsHtml5MetaScanner::DATA
;
680 NS_HTML5_CONTINUE(stateloop
);
683 state
= nsHtml5MetaScanner::COMMENT
;
684 NS_HTML5_CONTINUE(stateloop
);
688 case ATTRIBUTE_VALUE_SINGLE_QUOTED
: {
697 NS_HTML5_BREAK(stateloop
);
700 handleAttributeValue();
701 state
= nsHtml5MetaScanner::AFTER_ATTRIBUTE_VALUE_QUOTED
;
702 NS_HTML5_CONTINUE(stateloop
);
705 handleCharInAttributeValue(c
);
711 case SCAN_UNTIL_GT
: {
720 NS_HTML5_BREAK(stateloop
);
723 state
= nsHtml5MetaScanner::DATA
;
724 NS_HTML5_CONTINUE(stateloop
);
726 default: { continue; }
736 void nsHtml5MetaScanner::handleCharInAttributeValue(int32_t c
) {
737 if (metaState
== A
) {
738 if (contentIndex
== CONTENT
.length
|| charsetIndex
== CHARSET
.length
) {
740 } else if (httpEquivIndex
== HTTP_EQUIV
.length
) {
741 if (contentTypeIndex
< CONTENT_TYPE
.length
&&
742 toAsciiLowerCase(c
) == CONTENT_TYPE
[contentTypeIndex
]) {
745 contentTypeIndex
= INT32_MAX
;
751 void nsHtml5MetaScanner::addToBuffer(int32_t c
) {
752 if (strBufLen
== strBuf
.length
) {
753 jArray
<char16_t
, int32_t> newBuf
= jArray
<char16_t
, int32_t>::newJArray(
754 strBuf
.length
+ (strBuf
.length
<< 1));
755 nsHtml5ArrayCopy::arraycopy(strBuf
, newBuf
, strBuf
.length
);
758 strBuf
[strBufLen
++] = (char16_t
)c
;
761 void nsHtml5MetaScanner::handleAttributeValue() {
762 if (metaState
!= A
) {
765 if (contentIndex
== CONTENT
.length
&& !content
) {
766 content
= nsHtml5Portability::newStringFromBuffer(strBuf
, 0, strBufLen
,
770 if (charsetIndex
== CHARSET
.length
&& !charset
) {
771 charset
= nsHtml5Portability::newStringFromBuffer(strBuf
, 0, strBufLen
,
775 if (httpEquivIndex
== HTTP_EQUIV
.length
&&
776 httpEquivState
== HTTP_EQUIV_NOT_SEEN
) {
777 httpEquivState
= (contentTypeIndex
== CONTENT_TYPE
.length
)
778 ? HTTP_EQUIV_CONTENT_TYPE
784 bool nsHtml5MetaScanner::handleTag() {
785 bool stop
= handleTagInner();
790 httpEquivState
= HTTP_EQUIV_NOT_SEEN
;
794 bool nsHtml5MetaScanner::handleTagInner() {
795 if (!!charset
&& tryCharset(charset
)) {
798 if (!!content
&& httpEquivState
== HTTP_EQUIV_CONTENT_TYPE
) {
799 nsHtml5String extract
=
800 nsHtml5TreeBuilder::extractCharsetFromContent(content
, treeBuilder
);
804 bool success
= tryCharset(extract
);
811 void nsHtml5MetaScanner::initializeStatics() {}
813 void nsHtml5MetaScanner::releaseStatics() {}
815 #include "nsHtml5MetaScannerCppSupplement.h"