2009-06-29 02:44:22 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005-2007 Henri Sivonen
|
2020-08-03 14:03:02 +03:00
|
|
|
* Copyright (c) 2007-2017 Mozilla Foundation
|
2016-10-19 10:38:20 +03:00
|
|
|
* Portions of comments Copyright 2004-2010 Apple Computer, Inc., Mozilla
|
2009-06-29 02:44:22 +04:00
|
|
|
* Foundation, and Opera Software ASA.
|
|
|
|
*
|
2016-10-19 10:38:20 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
2009-06-29 02:44:22 +04:00
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
2016-10-19 10:38:20 +03:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
2009-06-29 02:44:22 +04:00
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
2016-10-19 10:38:20 +03:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
2009-06-29 02:44:22 +04:00
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
|
|
|
|
* Please edit Tokenizer.java instead and regenerate.
|
|
|
|
*/
|
|
|
|
|
2013-08-23 19:07:10 +04:00
|
|
|
#ifndef nsHtml5Tokenizer_h
|
|
|
|
#define nsHtml5Tokenizer_h
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2021-08-11 11:08:52 +03:00
|
|
|
#include "jArray.h"
|
|
|
|
#include "nsAHtml5TreeBuilderState.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2021-08-11 11:08:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsHtml5ArrayCopy.h"
|
2009-09-21 15:43:43 +04:00
|
|
|
#include "nsHtml5AtomTable.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
#include "nsHtml5DocumentMode.h"
|
2021-08-11 11:08:52 +03:00
|
|
|
#include "nsHtml5Highlighter.h"
|
|
|
|
#include "nsHtml5Macros.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
#include "nsHtml5NamedCharacters.h"
|
2010-06-24 12:54:33 +04:00
|
|
|
#include "nsHtml5NamedCharactersAccel.h"
|
2021-08-11 11:08:52 +03:00
|
|
|
#include "nsHtml5String.h"
|
2011-11-01 15:33:11 +04:00
|
|
|
#include "nsHtml5TokenizerLoopPolicies.h"
|
2021-08-11 11:08:52 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsTraceRefcnt.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
class nsHtml5StreamParser;
|
2009-06-29 02:44:22 +04:00
|
|
|
|
|
|
|
class nsHtml5AttributeName;
|
|
|
|
class nsHtml5ElementName;
|
2017-04-20 10:34:32 +03:00
|
|
|
class nsHtml5TreeBuilder;
|
2009-06-29 02:44:22 +04:00
|
|
|
class nsHtml5UTF16Buffer;
|
|
|
|
class nsHtml5StateSnapshot;
|
|
|
|
class nsHtml5Portability;
|
|
|
|
|
|
|
|
class nsHtml5Tokenizer {
|
|
|
|
private:
|
2017-04-20 10:34:32 +03:00
|
|
|
static const int32_t DATA_AND_RCDATA_MASK = ~1;
|
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
public:
|
2017-04-20 10:34:32 +03:00
|
|
|
static const int32_t DATA = 0;
|
|
|
|
|
|
|
|
static const int32_t RCDATA = 1;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA = 2;
|
|
|
|
|
|
|
|
static const int32_t RAWTEXT = 3;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_ESCAPED = 4;
|
|
|
|
|
|
|
|
static const int32_t ATTRIBUTE_VALUE_DOUBLE_QUOTED = 5;
|
|
|
|
|
|
|
|
static const int32_t ATTRIBUTE_VALUE_SINGLE_QUOTED = 6;
|
|
|
|
|
|
|
|
static const int32_t ATTRIBUTE_VALUE_UNQUOTED = 7;
|
|
|
|
|
|
|
|
static const int32_t PLAINTEXT = 8;
|
|
|
|
|
|
|
|
static const int32_t TAG_OPEN = 9;
|
|
|
|
|
|
|
|
static const int32_t CLOSE_TAG_OPEN = 10;
|
|
|
|
|
|
|
|
static const int32_t TAG_NAME = 11;
|
|
|
|
|
|
|
|
static const int32_t BEFORE_ATTRIBUTE_NAME = 12;
|
|
|
|
|
|
|
|
static const int32_t ATTRIBUTE_NAME = 13;
|
|
|
|
|
|
|
|
static const int32_t AFTER_ATTRIBUTE_NAME = 14;
|
|
|
|
|
|
|
|
static const int32_t BEFORE_ATTRIBUTE_VALUE = 15;
|
|
|
|
|
|
|
|
static const int32_t AFTER_ATTRIBUTE_VALUE_QUOTED = 16;
|
|
|
|
|
|
|
|
static const int32_t BOGUS_COMMENT = 17;
|
|
|
|
|
|
|
|
static const int32_t MARKUP_DECLARATION_OPEN = 18;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE = 19;
|
|
|
|
|
|
|
|
static const int32_t BEFORE_DOCTYPE_NAME = 20;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE_NAME = 21;
|
|
|
|
|
|
|
|
static const int32_t AFTER_DOCTYPE_NAME = 22;
|
|
|
|
|
|
|
|
static const int32_t BEFORE_DOCTYPE_PUBLIC_IDENTIFIER = 23;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED = 24;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED = 25;
|
|
|
|
|
|
|
|
static const int32_t AFTER_DOCTYPE_PUBLIC_IDENTIFIER = 26;
|
|
|
|
|
|
|
|
static const int32_t BEFORE_DOCTYPE_SYSTEM_IDENTIFIER = 27;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED = 28;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED = 29;
|
|
|
|
|
|
|
|
static const int32_t AFTER_DOCTYPE_SYSTEM_IDENTIFIER = 30;
|
|
|
|
|
|
|
|
static const int32_t BOGUS_DOCTYPE = 31;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_START = 32;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_START_DASH = 33;
|
|
|
|
|
|
|
|
static const int32_t COMMENT = 34;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_END_DASH = 35;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_END = 36;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_END_BANG = 37;
|
|
|
|
|
|
|
|
static const int32_t NON_DATA_END_TAG_NAME = 38;
|
|
|
|
|
|
|
|
static const int32_t MARKUP_DECLARATION_HYPHEN = 39;
|
|
|
|
|
|
|
|
static const int32_t MARKUP_DECLARATION_OCTYPE = 40;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE_UBLIC = 41;
|
|
|
|
|
|
|
|
static const int32_t DOCTYPE_YSTEM = 42;
|
|
|
|
|
|
|
|
static const int32_t AFTER_DOCTYPE_PUBLIC_KEYWORD = 43;
|
|
|
|
|
|
|
|
static const int32_t BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS = 44;
|
|
|
|
|
|
|
|
static const int32_t AFTER_DOCTYPE_SYSTEM_KEYWORD = 45;
|
|
|
|
|
|
|
|
static const int32_t CONSUME_CHARACTER_REFERENCE = 46;
|
|
|
|
|
|
|
|
static const int32_t CONSUME_NCR = 47;
|
|
|
|
|
|
|
|
static const int32_t CHARACTER_REFERENCE_TAIL = 48;
|
|
|
|
|
|
|
|
static const int32_t HEX_NCR_LOOP = 49;
|
|
|
|
|
|
|
|
static const int32_t DECIMAL_NRC_LOOP = 50;
|
|
|
|
|
|
|
|
static const int32_t HANDLE_NCR_VALUE = 51;
|
|
|
|
|
|
|
|
static const int32_t HANDLE_NCR_VALUE_RECONSUME = 52;
|
|
|
|
|
|
|
|
static const int32_t CHARACTER_REFERENCE_HILO_LOOKUP = 53;
|
|
|
|
|
|
|
|
static const int32_t SELF_CLOSING_START_TAG = 54;
|
|
|
|
|
|
|
|
static const int32_t CDATA_START = 55;
|
|
|
|
|
|
|
|
static const int32_t CDATA_SECTION = 56;
|
|
|
|
|
|
|
|
static const int32_t CDATA_RSQB = 57;
|
|
|
|
|
|
|
|
static const int32_t CDATA_RSQB_RSQB = 58;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_LESS_THAN_SIGN = 59;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_ESCAPE_START = 60;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_ESCAPE_START_DASH = 61;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_ESCAPED_DASH = 62;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_ESCAPED_DASH_DASH = 63;
|
|
|
|
|
|
|
|
static const int32_t BOGUS_COMMENT_HYPHEN = 64;
|
|
|
|
|
|
|
|
static const int32_t RAWTEXT_RCDATA_LESS_THAN_SIGN = 65;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN = 66;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_DOUBLE_ESCAPE_START = 67;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_DOUBLE_ESCAPED = 68;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN = 69;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_DOUBLE_ESCAPED_DASH = 70;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH = 71;
|
|
|
|
|
|
|
|
static const int32_t SCRIPT_DATA_DOUBLE_ESCAPE_END = 72;
|
|
|
|
|
|
|
|
static const int32_t PROCESSING_INSTRUCTION = 73;
|
|
|
|
|
|
|
|
static const int32_t PROCESSING_INSTRUCTION_QUESTION_MARK = 74;
|
|
|
|
|
2021-08-16 08:01:09 +03:00
|
|
|
static const int32_t COMMENT_LESSTHAN = 76;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_LESSTHAN_BANG = 77;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_LESSTHAN_BANG_DASH = 78;
|
|
|
|
|
|
|
|
static const int32_t COMMENT_LESSTHAN_BANG_DASH_DASH = 79;
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
static const int32_t LEAD_OFFSET = (0xD800 - (0x10000 >> 10));
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2015-08-25 18:05:45 +03:00
|
|
|
static char16_t LT_GT[];
|
|
|
|
static char16_t LT_SOLIDUS[];
|
2016-09-27 13:47:53 +03:00
|
|
|
static char16_t RSQB_RSQB[];
|
|
|
|
static char16_t REPLACEMENT_CHARACTER[];
|
2014-01-04 19:02:17 +04:00
|
|
|
static char16_t LF[];
|
|
|
|
static char16_t CDATA_LSQB[];
|
2016-09-27 13:47:53 +03:00
|
|
|
static char16_t OCTYPE[];
|
2014-01-04 19:02:17 +04:00
|
|
|
static char16_t UBLIC[];
|
|
|
|
static char16_t YSTEM[];
|
2016-09-27 13:47:53 +03:00
|
|
|
static staticJArray<char16_t, int32_t> TITLE_ARR;
|
|
|
|
static staticJArray<char16_t, int32_t> SCRIPT_ARR;
|
|
|
|
static staticJArray<char16_t, int32_t> STYLE_ARR;
|
2014-01-04 19:02:17 +04:00
|
|
|
static staticJArray<char16_t, int32_t> PLAINTEXT_ARR;
|
2016-09-27 13:47:53 +03:00
|
|
|
static staticJArray<char16_t, int32_t> XMP_ARR;
|
|
|
|
static staticJArray<char16_t, int32_t> TEXTAREA_ARR;
|
2015-08-25 18:05:45 +03:00
|
|
|
static staticJArray<char16_t, int32_t> IFRAME_ARR;
|
|
|
|
static staticJArray<char16_t, int32_t> NOEMBED_ARR;
|
2014-01-04 19:02:17 +04:00
|
|
|
static staticJArray<char16_t, int32_t> NOSCRIPT_ARR;
|
|
|
|
static staticJArray<char16_t, int32_t> NOFRAMES_ARR;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2016-10-19 10:38:20 +03:00
|
|
|
nsHtml5TreeBuilder* tokenHandler;
|
|
|
|
nsHtml5StreamParser* encodingDeclarationHandler;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool lastCR;
|
2016-10-19 10:38:20 +03:00
|
|
|
int32_t stateSave;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-19 10:38:20 +03:00
|
|
|
private:
|
|
|
|
int32_t returnStateSave;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2016-09-27 13:47:53 +03:00
|
|
|
int32_t index;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
private:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool forceQuirks;
|
2009-06-29 02:44:22 +04:00
|
|
|
char16_t additional;
|
2010-04-16 14:52:06 +04:00
|
|
|
int32_t entCol;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t firstCharKey;
|
|
|
|
int32_t lo;
|
|
|
|
int32_t hi;
|
2010-04-16 14:52:06 +04:00
|
|
|
int32_t candidate;
|
2015-08-25 18:05:45 +03:00
|
|
|
int32_t charRefBufMark;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2015-08-25 18:05:45 +03:00
|
|
|
int32_t value;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2015-08-25 18:05:45 +03:00
|
|
|
bool seenDigits;
|
Bug 1701828 - meta charset rewrite. r=smaug
Implements https://github.com/whatwg/html/issues/6962 . Improves performance
when <meta charset> occurs in head but after the first kilobyte and aligns
behavior better with WebKit and Blink.
The main change is to avoid reloads when meta appears within head but
after the first kilobyte. Prior to this change, Gecko reloaded in that
case (in compliance with the spec!) even though WebKit and Blink did not.
Differences from WebKit and Blink:
* WebKit and Blink honor <meta charset> in <noscript>. This implementation
does not.
* WebKit and Blink look for meta as if the tree builder was unaware of
foreign content. This implementation is foreign content-aware. This
makes a difference for CDATA sections that contain a > before the meta
as well as style and script elements within foreign content. This could
happen if the CDATA section that has mysteriously been introduced around
a what looks like a meta tag also contains another prior tag-looking
run of text.
* This implementation processes rel=preload and speculative loads that are
seen before <meta charset> has been seen. WebKit and Blink instead first
look for the meta and rewind before starting speculative parsing.
* Unlike WebKit, if there is neither an honored meta nor syntax resembling
an XML declaration, detection from content takes place (as in Blink).
* Unlike Blink, if there is neither an honored meta nor syntax resembling
an XML declaration, the detection from content is not dependent of network
buffer boundaries.
* Unlike Blink, detection from content can trigger a reload at the end of
the stream if the guess made at that point differs from the first guess.
(See below for the definition of the input to the first guess.)
Differences from the old spec and Gecko previously:
* Meta inside script and RCDATA elements is no longer honored.
* Late meta is now ignored and no longer triggers a reload.
* Later meta counts as early enough meta: In addition to the previous
meta within the first 1024 bytes, now a meta that started within the first
1024 bytes counts as early enough. Additionally, if by then there hasn't
been a template start tag and head hasn't ended, meta occurring before the
earlier of the end of the head or a template start tag counts as early
enough.
* Meta now counts as not-late even if the encoding label has numeric
character reference escapes.
* Syntax resembling an XML declaration longer than a kilobyte is honored if
there is no honored meta.
* If there is neither an honored meta nor syntax resembling an XML declaration,
the initial chardetng scan is potentially longer than before: the first 1024
bytes, the token spanning the 1024-byte boundary if there is such a token,
and, if by then head hasn't ended and there hasn't been a template start tag
until the end of the template start tag or the end of the token that causes
head to end, ever comes first. However, if the token implying the end of the
head is a text token, bytes only to the end of the previous non-text token is
considered. (This definition avoids depending on network buffer boundaries.)
* XML View Source now uses the code for syntax resembling an XML declaration
instead of expat for extracting the internal encoding label.
Reftest are added as both WPT and Gecko reftests in order to test both http:
and file: URL scenarios. The Gecko tests retain the WPT <link> tags in order
to use the exact same bytes.
An encoding declaration has been added to a number of old tests that didn't
intend to test the new speculation behavior especially in the context of
https://bugzilla.mozilla.org/show_bug.cgi?id=1727750 .
Differential Revision: https://phabricator.services.mozilla.com/D125808
2021-12-08 14:34:20 +03:00
|
|
|
bool suspendAfterCurrentNonTextToken;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2014-01-04 19:02:17 +04:00
|
|
|
int32_t cstart;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2015-08-25 18:05:45 +03:00
|
|
|
nsHtml5String publicId;
|
2017-03-20 15:45:15 +03:00
|
|
|
nsHtml5String systemId;
|
2015-08-25 18:05:45 +03:00
|
|
|
autoJArray<char16_t, int32_t> strBuf;
|
|
|
|
int32_t strBufLen;
|
|
|
|
autoJArray<char16_t, int32_t> charRefBuf;
|
2009-06-29 02:44:22 +04:00
|
|
|
int32_t charRefBufLen;
|
2014-01-04 19:02:17 +04:00
|
|
|
autoJArray<char16_t, int32_t> bmpChar;
|
2015-08-25 18:05:45 +03:00
|
|
|
autoJArray<char16_t, int32_t> astralChar;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2015-08-25 18:05:45 +03:00
|
|
|
nsHtml5ElementName* endTagExpectation;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-08-25 18:05:45 +03:00
|
|
|
private:
|
|
|
|
jArray<char16_t, int32_t> endTagExpectationAsArray;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool endTag;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2015-08-25 18:05:45 +03:00
|
|
|
bool containsHyphen;
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5ElementName* tagName;
|
|
|
|
nsHtml5ElementName* nonInternedTagName;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
|
|
|
nsHtml5AttributeName* attributeName;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2017-04-13 11:14:48 +03:00
|
|
|
nsHtml5AttributeName* nonInternedAttributeName;
|
2018-11-09 16:27:10 +03:00
|
|
|
RefPtr<nsAtom> doctypeName;
|
2017-03-20 15:45:15 +03:00
|
|
|
nsHtml5String publicIdentifier;
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5String systemIdentifier;
|
2015-08-25 18:05:45 +03:00
|
|
|
nsHtml5HtmlAttributes* attributes;
|
2014-03-05 23:38:50 +04:00
|
|
|
bool newAttributesEachTime;
|
2015-08-25 18:05:45 +03:00
|
|
|
bool shouldSuspend;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool confident;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2016-09-20 17:31:57 +03:00
|
|
|
int32_t line;
|
2009-06-29 02:44:22 +04:00
|
|
|
int32_t attributeLine;
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5AtomTable* interner;
|
2011-11-01 15:33:11 +04:00
|
|
|
bool viewingXmlSource;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
public:
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5Tokenizer(nsHtml5TreeBuilder* tokenHandler, bool viewingXmlSource);
|
|
|
|
void setInterner(nsHtml5AtomTable* interner);
|
|
|
|
void initLocation(nsHtml5String newPublicId, nsHtml5String newSystemId);
|
2014-01-04 19:02:17 +04:00
|
|
|
bool isViewingXmlSource();
|
2019-07-08 10:33:59 +03:00
|
|
|
void setState(int32_t specialTokenizerState);
|
2014-01-04 19:02:17 +04:00
|
|
|
void setStateAndEndTagExpectation(int32_t specialTokenizerState,
|
|
|
|
nsHtml5ElementName* endTagExpectation);
|
2017-12-21 11:02:43 +03:00
|
|
|
|
|
|
|
private:
|
2014-01-04 19:02:17 +04:00
|
|
|
void endTagExpectationToArray();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
public:
|
2014-01-04 19:02:17 +04:00
|
|
|
void setLineNumber(int32_t line);
|
2012-08-22 19:56:38 +04:00
|
|
|
inline int32_t getLineNumber() { return line; }
|
2017-12-21 11:02:43 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsHtml5HtmlAttributes* emptyAttributes();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2014-01-04 19:02:17 +04:00
|
|
|
inline void appendCharRefBuf(char16_t c) {
|
2016-09-27 13:47:53 +03:00
|
|
|
MOZ_RELEASE_ASSERT(charRefBufLen < charRefBuf.length,
|
2014-01-04 19:02:17 +04:00
|
|
|
"Attempted to overrun charRefBuf!");
|
2009-06-29 02:44:22 +04:00
|
|
|
charRefBuf[charRefBufLen++] = c;
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void emitOrAppendCharRefBuf(int32_t returnState);
|
2009-06-29 02:44:22 +04:00
|
|
|
inline void clearStrBufAfterUse() { strBufLen = 0; }
|
2017-12-21 11:02:43 +03:00
|
|
|
|
2016-10-19 10:38:20 +03:00
|
|
|
inline void clearStrBufBeforeUse() {
|
2012-08-22 19:56:38 +04:00
|
|
|
MOZ_ASSERT(!strBufLen, "strBufLen not reset after previous use!");
|
2010-04-16 14:52:06 +04:00
|
|
|
strBufLen = 0;
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline void clearStrBufAfterOneHyphen() {
|
2009-06-29 02:44:22 +04:00
|
|
|
MOZ_ASSERT(strBufLen == 1, "strBufLen length not one!");
|
2014-01-04 19:02:17 +04:00
|
|
|
MOZ_ASSERT(strBuf[0] == '-', "strBuf does not start with a hyphen!");
|
2010-04-16 14:52:06 +04:00
|
|
|
strBufLen = 0;
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
inline void appendStrBuf(char16_t c) {
|
2016-09-27 13:47:53 +03:00
|
|
|
MOZ_ASSERT(strBufLen < strBuf.length,
|
2014-01-04 19:02:17 +04:00
|
|
|
"Previous buffer length insufficient.");
|
2009-06-29 02:44:22 +04:00
|
|
|
if (MOZ_UNLIKELY(strBufLen == strBuf.length)) {
|
2016-09-27 13:47:53 +03:00
|
|
|
if (MOZ_UNLIKELY(!EnsureBufferSpace(1))) {
|
2009-06-29 02:44:22 +04:00
|
|
|
MOZ_CRASH("Unable to recover from buffer reallocation failure");
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2016-09-27 13:47:53 +03:00
|
|
|
strBuf[strBufLen++] = c;
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 15:45:15 +03:00
|
|
|
protected:
|
|
|
|
nsHtml5String strBufToString();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-20 15:45:15 +03:00
|
|
|
private:
|
|
|
|
void strBufToDoctypeName();
|
2009-06-29 02:44:22 +04:00
|
|
|
void emitStrBuf();
|
2017-03-20 15:45:15 +03:00
|
|
|
inline void appendSecondHyphenToBogusComment() { appendStrBuf('-'); }
|
2017-12-21 11:02:43 +03:00
|
|
|
|
2021-08-16 08:01:09 +03:00
|
|
|
inline void adjustDoubleHyphenAndAppendToStrBufAndErr(
|
|
|
|
char16_t c, bool reportedConsecutiveHyphens) {
|
2015-08-25 18:05:45 +03:00
|
|
|
appendStrBuf(c);
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 15:45:15 +03:00
|
|
|
void appendStrBuf(char16_t* buffer, int32_t offset, int32_t length);
|
2015-08-25 18:05:45 +03:00
|
|
|
inline void appendCharRefBufToStrBuf() {
|
|
|
|
appendStrBuf(charRefBuf, 0, charRefBufLen);
|
2016-10-19 10:38:20 +03:00
|
|
|
charRefBufLen = 0;
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 15:45:15 +03:00
|
|
|
void emitComment(int32_t provisionalHyphens, int32_t pos);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2017-03-20 15:45:15 +03:00
|
|
|
void flushChars(char16_t* buf, int32_t pos);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
private:
|
|
|
|
void strBufToElementNameString();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t emitCurrentTagToken(bool selfClosing, int32_t pos);
|
2009-06-29 02:44:22 +04:00
|
|
|
void attributeNameComplete();
|
|
|
|
void addAttributeWithoutValue();
|
|
|
|
void addAttributeWithValue();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
public:
|
2009-06-29 02:44:22 +04:00
|
|
|
void start();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool tokenizeBuffer(nsHtml5UTF16Buffer* buffer);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2014-01-04 19:02:17 +04:00
|
|
|
template <class P>
|
|
|
|
int32_t stateLoop(int32_t state, char16_t c, int32_t pos, char16_t* buf,
|
|
|
|
bool reconsume, int32_t returnState, int32_t endPos);
|
2009-09-21 17:18:20 +04:00
|
|
|
void initDoctypeFields();
|
2015-08-25 18:05:45 +03:00
|
|
|
inline void adjustDoubleHyphenAndAppendToStrBufCarriageReturn() {
|
2009-06-29 02:44:22 +04:00
|
|
|
silentCarriageReturn();
|
2021-08-16 08:01:09 +03:00
|
|
|
adjustDoubleHyphenAndAppendToStrBufAndErr('\n', false);
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2015-08-25 18:05:45 +03:00
|
|
|
inline void adjustDoubleHyphenAndAppendToStrBufLineFeed() {
|
2009-06-29 02:44:22 +04:00
|
|
|
silentLineFeed();
|
2021-08-16 08:01:09 +03:00
|
|
|
adjustDoubleHyphenAndAppendToStrBufAndErr('\n', false);
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2015-08-25 18:05:45 +03:00
|
|
|
inline void appendStrBufLineFeed() {
|
2009-06-29 02:44:22 +04:00
|
|
|
silentLineFeed();
|
2015-08-25 18:05:45 +03:00
|
|
|
appendStrBuf('\n');
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2015-08-25 18:05:45 +03:00
|
|
|
inline void appendStrBufCarriageReturn() {
|
2009-06-29 02:44:22 +04:00
|
|
|
silentCarriageReturn();
|
2015-08-25 18:05:45 +03:00
|
|
|
appendStrBuf('\n');
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2015-08-25 18:05:45 +03:00
|
|
|
inline void silentCarriageReturn() {
|
2017-12-21 11:02:43 +03:00
|
|
|
++line;
|
2011-10-17 18:59:28 +04:00
|
|
|
lastCR = true;
|
2017-12-21 11:02:43 +03:00
|
|
|
}
|
|
|
|
|
2015-08-25 18:05:45 +03:00
|
|
|
inline void silentLineFeed() { ++line; }
|
2017-12-21 11:02:43 +03:00
|
|
|
|
|
|
|
private:
|
2014-01-04 19:02:17 +04:00
|
|
|
void emitCarriageReturn(char16_t* buf, int32_t pos);
|
|
|
|
void emitReplacementCharacter(char16_t* buf, int32_t pos);
|
2021-08-17 13:09:10 +03:00
|
|
|
void maybeEmitReplacementCharacter(char16_t* buf, int32_t pos);
|
2014-01-04 19:02:17 +04:00
|
|
|
void emitPlaintextReplacementCharacter(char16_t* buf, int32_t pos);
|
2012-08-22 19:56:38 +04:00
|
|
|
void setAdditionalAndRememberAmpersandLocation(char16_t add);
|
2009-06-29 02:44:22 +04:00
|
|
|
void bogusDoctype();
|
|
|
|
void bogusDoctypeWithoutQuirks();
|
2012-08-22 19:56:38 +04:00
|
|
|
void handleNcrValue(int32_t returnState);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
public:
|
2009-06-29 02:44:22 +04:00
|
|
|
void eof();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
void emitDoctypeToken(int32_t pos);
|
Bug 1701828 - meta charset rewrite. r=smaug
Implements https://github.com/whatwg/html/issues/6962 . Improves performance
when <meta charset> occurs in head but after the first kilobyte and aligns
behavior better with WebKit and Blink.
The main change is to avoid reloads when meta appears within head but
after the first kilobyte. Prior to this change, Gecko reloaded in that
case (in compliance with the spec!) even though WebKit and Blink did not.
Differences from WebKit and Blink:
* WebKit and Blink honor <meta charset> in <noscript>. This implementation
does not.
* WebKit and Blink look for meta as if the tree builder was unaware of
foreign content. This implementation is foreign content-aware. This
makes a difference for CDATA sections that contain a > before the meta
as well as style and script elements within foreign content. This could
happen if the CDATA section that has mysteriously been introduced around
a what looks like a meta tag also contains another prior tag-looking
run of text.
* This implementation processes rel=preload and speculative loads that are
seen before <meta charset> has been seen. WebKit and Blink instead first
look for the meta and rewind before starting speculative parsing.
* Unlike WebKit, if there is neither an honored meta nor syntax resembling
an XML declaration, detection from content takes place (as in Blink).
* Unlike Blink, if there is neither an honored meta nor syntax resembling
an XML declaration, the detection from content is not dependent of network
buffer boundaries.
* Unlike Blink, detection from content can trigger a reload at the end of
the stream if the guess made at that point differs from the first guess.
(See below for the definition of the input to the first guess.)
Differences from the old spec and Gecko previously:
* Meta inside script and RCDATA elements is no longer honored.
* Late meta is now ignored and no longer triggers a reload.
* Later meta counts as early enough meta: In addition to the previous
meta within the first 1024 bytes, now a meta that started within the first
1024 bytes counts as early enough. Additionally, if by then there hasn't
been a template start tag and head hasn't ended, meta occurring before the
earlier of the end of the head or a template start tag counts as early
enough.
* Meta now counts as not-late even if the encoding label has numeric
character reference escapes.
* Syntax resembling an XML declaration longer than a kilobyte is honored if
there is no honored meta.
* If there is neither an honored meta nor syntax resembling an XML declaration,
the initial chardetng scan is potentially longer than before: the first 1024
bytes, the token spanning the 1024-byte boundary if there is such a token,
and, if by then head hasn't ended and there hasn't been a template start tag
until the end of the template start tag or the end of the token that causes
head to end, ever comes first. However, if the token implying the end of the
head is a text token, bytes only to the end of the previous non-text token is
considered. (This definition avoids depending on network buffer boundaries.)
* XML View Source now uses the code for syntax resembling an XML declaration
instead of expat for extracting the internal encoding label.
Reftest are added as both WPT and Gecko reftests in order to test both http:
and file: URL scenarios. The Gecko tests retain the WPT <link> tags in order
to use the exact same bytes.
An encoding declaration has been added to a number of old tests that didn't
intend to test the new speculation behavior especially in the context of
https://bugzilla.mozilla.org/show_bug.cgi?id=1727750 .
Differential Revision: https://phabricator.services.mozilla.com/D125808
2021-12-08 14:34:20 +03:00
|
|
|
void suspendIfRequestedAfterCurrentNonTextToken();
|
|
|
|
void suspendAfterCurrentTokenIfNotInText();
|
|
|
|
bool suspensionAfterCurrentNonTextTokenPending();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
protected:
|
2014-01-04 19:02:17 +04:00
|
|
|
inline char16_t checkChar(char16_t* buf, int32_t pos) { return buf[pos]; }
|
2017-12-21 11:02:43 +03:00
|
|
|
|
|
|
|
public:
|
2010-04-16 14:52:06 +04:00
|
|
|
bool internalEncodingDeclaration(nsHtml5String internalCharset);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-21 11:02:43 +03:00
|
|
|
private:
|
2014-01-04 19:02:17 +04:00
|
|
|
void emitOrAppendTwo(const char16_t* val, int32_t returnState);
|
|
|
|
void emitOrAppendOne(const char16_t* val, int32_t returnState);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
public:
|
|
|
|
void end();
|
|
|
|
void requestSuspension();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isInDataState();
|
2009-09-21 17:18:20 +04:00
|
|
|
void resetToDataState();
|
|
|
|
void loadState(nsHtml5Tokenizer* other);
|
|
|
|
void initializeWithoutStarting();
|
2010-04-16 14:52:06 +04:00
|
|
|
void setEncodingDeclarationHandler(
|
|
|
|
nsHtml5StreamParser* encodingDeclarationHandler);
|
2010-11-10 13:03:48 +03:00
|
|
|
~nsHtml5Tokenizer();
|
2009-06-29 02:44:22 +04:00
|
|
|
static void initializeStatics();
|
|
|
|
static void releaseStatics();
|
2010-07-30 14:15:38 +04:00
|
|
|
|
|
|
|
#include "nsHtml5TokenizerHSupplement.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|