tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsHtml5TreeOperation.h (22921B)


      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 #ifndef nsHtml5TreeOperation_h
      6 #define nsHtml5TreeOperation_h
      7 
      8 #include "nsHtml5DocumentMode.h"
      9 #include "nsHtml5HtmlAttributes.h"
     10 #include "mozilla/dom/FromParser.h"
     11 #include "mozilla/dom/ShadowRootBinding.h"
     12 #include "mozilla/NotNull.h"
     13 #include "mozilla/Variant.h"
     14 #include "nsCharsetSource.h"
     15 
     16 class nsIContent;
     17 class nsHtml5TreeOpExecutor;
     18 class nsHtml5DocumentBuilder;
     19 namespace mozilla {
     20 class Encoding;
     21 
     22 namespace dom {
     23 class Text;
     24 }  // namespace dom
     25 }  // namespace mozilla
     26 
     27 struct uninitialized {};
     28 
     29 // main HTML5 ops
     30 struct opDetach {
     31  nsIContent** mElement;
     32 
     33  explicit opDetach(nsIContentHandle* aElement) {
     34    mElement = static_cast<nsIContent**>(aElement);
     35  };
     36 };
     37 
     38 struct opAppend {
     39  nsIContent** mChild;
     40  nsIContent** mParent;
     41  mozilla::dom::FromParser mFromNetwork;
     42 
     43  explicit opAppend(nsIContentHandle* aChild, nsIContentHandle* aParent,
     44                    mozilla::dom::FromParser aFromNetwork)
     45      : mFromNetwork(aFromNetwork) {
     46    mChild = static_cast<nsIContent**>(aChild);
     47    mParent = static_cast<nsIContent**>(aParent);
     48  };
     49 };
     50 
     51 struct opAppendChildrenToNewParent {
     52  nsIContent** mOldParent;
     53  nsIContent** mNewParent;
     54 
     55  explicit opAppendChildrenToNewParent(nsIContentHandle* aOldParent,
     56                                       nsIContentHandle* aNewParent) {
     57    mOldParent = static_cast<nsIContent**>(aOldParent);
     58    mNewParent = static_cast<nsIContent**>(aNewParent);
     59  };
     60 };
     61 
     62 struct opFosterParent {
     63  nsIContent** mChild;
     64  nsIContent** mStackParent;
     65  nsIContent** mTable;
     66 
     67  explicit opFosterParent(nsIContentHandle* aChild,
     68                          nsIContentHandle* aStackParent,
     69                          nsIContentHandle* aTable) {
     70    mChild = static_cast<nsIContent**>(aChild);
     71    mStackParent = static_cast<nsIContent**>(aStackParent);
     72    mTable = static_cast<nsIContent**>(aTable);
     73  };
     74 };
     75 
     76 struct opAppendToDocument {
     77  nsIContent** mContent;
     78 
     79  explicit opAppendToDocument(nsIContentHandle* aContent) {
     80    mContent = static_cast<nsIContent**>(aContent);
     81  };
     82 };
     83 
     84 struct opAddAttributes {
     85  nsIContent** mElement;
     86  nsHtml5HtmlAttributes* mAttributes;
     87 
     88  explicit opAddAttributes(nsIContentHandle* aElement,
     89                           nsHtml5HtmlAttributes* aAttributes)
     90      : mAttributes(aAttributes) {
     91    mElement = static_cast<nsIContent**>(aElement);
     92  };
     93 };
     94 
     95 struct opCreateHTMLElement {
     96  nsIContent** mContent;
     97  nsAtom* mName;
     98  nsHtml5HtmlAttributes* mAttributes;
     99  mozilla::dom::HTMLContentCreatorFunction mCreator;
    100  nsIContent** mIntendedParent;
    101  mozilla::dom::FromParser mFromNetwork;
    102 
    103  explicit opCreateHTMLElement(
    104      nsIContentHandle* aContent, nsAtom* aName,
    105      nsHtml5HtmlAttributes* aAttributes,
    106      mozilla::dom::HTMLContentCreatorFunction aCreator,
    107      nsIContentHandle* aIntendedParent, mozilla::dom::FromParser mFromNetwork)
    108      : mName(aName),
    109        mAttributes(aAttributes),
    110        mCreator(aCreator),
    111        mFromNetwork(mFromNetwork) {
    112    mContent = static_cast<nsIContent**>(aContent);
    113    mIntendedParent = static_cast<nsIContent**>(aIntendedParent);
    114    aName->AddRef();
    115    if (mAttributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
    116      mAttributes = nullptr;
    117    }
    118  };
    119 };
    120 
    121 struct opCreateSVGElement {
    122  nsIContent** mContent;
    123  nsAtom* mName;
    124  nsHtml5HtmlAttributes* mAttributes;
    125  mozilla::dom::SVGContentCreatorFunction mCreator;
    126  nsIContent** mIntendedParent;
    127  mozilla::dom::FromParser mFromNetwork;
    128 
    129  explicit opCreateSVGElement(nsIContentHandle* aContent, nsAtom* aName,
    130                              nsHtml5HtmlAttributes* aAttributes,
    131                              mozilla::dom::SVGContentCreatorFunction aCreator,
    132                              nsIContentHandle* aIntendedParent,
    133                              mozilla::dom::FromParser mFromNetwork)
    134      : mName(aName),
    135        mAttributes(aAttributes),
    136        mCreator(aCreator),
    137        mFromNetwork(mFromNetwork) {
    138    mContent = static_cast<nsIContent**>(aContent);
    139    mIntendedParent = static_cast<nsIContent**>(aIntendedParent);
    140    aName->AddRef();
    141    if (mAttributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
    142      mAttributes = nullptr;
    143    }
    144  };
    145 };
    146 
    147 struct opCreateMathMLElement {
    148  nsIContent** mContent;
    149  nsAtom* mName;
    150  nsHtml5HtmlAttributes* mAttributes;
    151  nsIContent** mIntendedParent;
    152 
    153  explicit opCreateMathMLElement(nsIContentHandle* aContent, nsAtom* aName,
    154                                 nsHtml5HtmlAttributes* aAttributes,
    155                                 nsIContentHandle* aIntendedParent)
    156      : mName(aName), mAttributes(aAttributes) {
    157    mContent = static_cast<nsIContent**>(aContent);
    158    mIntendedParent = static_cast<nsIContent**>(aIntendedParent);
    159    aName->AddRef();
    160    if (mAttributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
    161      mAttributes = nullptr;
    162    }
    163  };
    164 };
    165 
    166 struct opSetFormElement {
    167  nsIContent** mContent;
    168  nsIContent** mFormElement;
    169  nsIContent** mIntendedParent;
    170 
    171  explicit opSetFormElement(nsIContentHandle* aContent,
    172                            nsIContentHandle* aFormElement,
    173                            nsIContentHandle* aIntendedParent) {
    174    mContent = static_cast<nsIContent**>(aContent);
    175    mFormElement = static_cast<nsIContent**>(aFormElement);
    176    mIntendedParent = static_cast<nsIContent**>(aIntendedParent);
    177  };
    178 };
    179 
    180 struct opAppendText {
    181  nsIContent** mParent;
    182  char16_t* mBuffer;
    183  int32_t mLength;
    184 
    185  explicit opAppendText(nsIContentHandle* aParent, char16_t* aBuffer,
    186                        int32_t aLength)
    187      : mBuffer(aBuffer), mLength(aLength) {
    188    mParent = static_cast<nsIContent**>(aParent);
    189  };
    190 };
    191 
    192 struct opFosterParentText {
    193  nsIContent** mStackParent;
    194  char16_t* mBuffer;
    195  nsIContent** mTable;
    196  int32_t mLength;
    197 
    198  explicit opFosterParentText(nsIContentHandle* aStackParent, char16_t* aBuffer,
    199                              nsIContentHandle* aTable, int32_t aLength)
    200      : mBuffer(aBuffer), mLength(aLength) {
    201    mStackParent = static_cast<nsIContent**>(aStackParent);
    202    mTable = static_cast<nsIContent**>(aTable);
    203  };
    204 };
    205 
    206 struct opAppendComment {
    207  nsIContent** mParent;
    208  char16_t* mBuffer;
    209  int32_t mLength;
    210 
    211  explicit opAppendComment(nsIContentHandle* aParent, char16_t* aBuffer,
    212                           int32_t aLength)
    213      : mBuffer(aBuffer), mLength(aLength) {
    214    mParent = static_cast<nsIContent**>(aParent);
    215  };
    216 };
    217 
    218 struct opAppendCommentToDocument {
    219  char16_t* mBuffer;
    220  int32_t mLength;
    221 
    222  explicit opAppendCommentToDocument(char16_t* aBuffer, int32_t aLength)
    223      : mBuffer(aBuffer), mLength(aLength) {};
    224 };
    225 
    226 class nsHtml5TreeOperationStringPair {
    227 private:
    228  nsString mPublicId;
    229  nsString mSystemId;
    230 
    231 public:
    232  nsHtml5TreeOperationStringPair(const nsAString& aPublicId,
    233                                 const nsAString& aSystemId)
    234      : mPublicId(aPublicId), mSystemId(aSystemId) {
    235    MOZ_COUNT_CTOR(nsHtml5TreeOperationStringPair);
    236  }
    237 
    238  ~nsHtml5TreeOperationStringPair() {
    239    MOZ_COUNT_DTOR(nsHtml5TreeOperationStringPair);
    240  }
    241 
    242  inline void Get(nsAString& aPublicId, nsAString& aSystemId) {
    243    aPublicId.Assign(mPublicId);
    244    aSystemId.Assign(mSystemId);
    245  }
    246 };
    247 
    248 struct opAppendDoctypeToDocument {
    249  nsAtom* mName;
    250  nsHtml5TreeOperationStringPair* mStringPair;
    251 
    252  explicit opAppendDoctypeToDocument(nsAtom* aName, const nsAString& aPublicId,
    253                                     const nsAString& aSystemId) {
    254    mName = aName;
    255    aName->AddRef();
    256    mStringPair = new nsHtml5TreeOperationStringPair(aPublicId, aSystemId);
    257  }
    258 };
    259 
    260 struct opGetDocumentFragmentForTemplate {
    261  nsIContent** mTemplate;
    262  nsIContent** mFragHandle;
    263 
    264  explicit opGetDocumentFragmentForTemplate(nsIContentHandle* aTemplate,
    265                                            nsIContentHandle* aFragHandle) {
    266    mTemplate = static_cast<nsIContent**>(aTemplate);
    267    mFragHandle = static_cast<nsIContent**>(aFragHandle);
    268  }
    269 };
    270 
    271 struct opSetDocumentFragmentForTemplate {
    272  nsIContent** mTemplate;
    273  nsIContent** mFragment;
    274 
    275  explicit opSetDocumentFragmentForTemplate(nsIContentHandle* aTemplate,
    276                                            nsIContentHandle* aFragment) {
    277    mTemplate = static_cast<nsIContent**>(aTemplate);
    278    mFragment = static_cast<nsIContent**>(aFragment);
    279  }
    280 };
    281 
    282 struct opGetShadowRootFromHost {
    283  nsIContent** mHost;
    284  nsIContent** mFragHandle;
    285  nsIContent** mTemplateNode;
    286  nsString mShadowRootReferenceTarget;
    287  mozilla::dom::ShadowRootMode mShadowRootMode;
    288  bool mShadowRootIsClonable;
    289  bool mShadowRootIsSerializable;
    290  bool mShadowRootDelegatesFocus;
    291 
    292  explicit opGetShadowRootFromHost(nsIContentHandle* aHost,
    293                                   nsIContentHandle* aFragHandle,
    294                                   nsIContentHandle* aTemplateNode,
    295                                   mozilla::dom::ShadowRootMode aShadowRootMode,
    296                                   bool aShadowRootIsClonable,
    297                                   bool aShadowRootIsSerializable,
    298                                   bool aShadowRootDelegatesFocus,
    299                                   nsAString& aShadowRootReferenceTarget) {
    300    mHost = static_cast<nsIContent**>(aHost);
    301    mFragHandle = static_cast<nsIContent**>(aFragHandle);
    302    mTemplateNode = static_cast<nsIContent**>(aTemplateNode);
    303    mShadowRootMode = aShadowRootMode;
    304    mShadowRootIsClonable = aShadowRootIsClonable;
    305    mShadowRootIsSerializable = aShadowRootIsSerializable;
    306    mShadowRootDelegatesFocus = aShadowRootDelegatesFocus;
    307    mShadowRootReferenceTarget = aShadowRootReferenceTarget;
    308  }
    309 };
    310 
    311 struct opGetFosterParent {
    312  nsIContent** mTable;
    313  nsIContent** mStackParent;
    314  nsIContent** mParentHandle;
    315 
    316  explicit opGetFosterParent(nsIContentHandle* aTable,
    317                             nsIContentHandle* aStackParent,
    318                             nsIContentHandle* aParentHandle) {
    319    mTable = static_cast<nsIContent**>(aTable);
    320    mStackParent = static_cast<nsIContent**>(aStackParent);
    321    mParentHandle = static_cast<nsIContent**>(aParentHandle);
    322  };
    323 };
    324 
    325 // Gecko-specific on-pop ops
    326 struct opMarkAsBroken {
    327  nsresult mResult;
    328 
    329  explicit opMarkAsBroken(nsresult aResult) : mResult(aResult) {};
    330 };
    331 
    332 struct opRunScriptThatMayDocumentWriteOrBlock {
    333  nsIContent** mElement;
    334  nsAHtml5TreeBuilderState* mBuilderState;
    335  int32_t mLineNumber;
    336 
    337  explicit opRunScriptThatMayDocumentWriteOrBlock(
    338      nsIContentHandle* aElement, nsAHtml5TreeBuilderState* aBuilderState)
    339      : mBuilderState(aBuilderState), mLineNumber(0) {
    340    mElement = static_cast<nsIContent**>(aElement);
    341  };
    342 };
    343 
    344 struct opRunScriptThatCannotDocumentWriteOrBlock {
    345  nsIContent** mElement;
    346 
    347  explicit opRunScriptThatCannotDocumentWriteOrBlock(
    348      nsIContentHandle* aElement) {
    349    mElement = static_cast<nsIContent**>(aElement);
    350  };
    351 };
    352 
    353 struct opPreventScriptExecution {
    354  nsIContent** mElement;
    355 
    356  explicit opPreventScriptExecution(nsIContentHandle* aElement) {
    357    mElement = static_cast<nsIContent**>(aElement);
    358  };
    359 };
    360 
    361 struct opDoneAddingChildren {
    362  nsIContent** mElement;
    363 
    364  explicit opDoneAddingChildren(nsIContentHandle* aElement) {
    365    mElement = static_cast<nsIContent**>(aElement);
    366  };
    367 };
    368 
    369 struct opDoneCreatingElement {
    370  nsIContent** mElement;
    371 
    372  explicit opDoneCreatingElement(nsIContentHandle* aElement) {
    373    mElement = static_cast<nsIContent**>(aElement);
    374  };
    375 };
    376 
    377 struct opUpdateCharsetSource {
    378  nsCharsetSource mCharsetSource;
    379 
    380  explicit opUpdateCharsetSource(nsCharsetSource aCharsetSource)
    381      : mCharsetSource(aCharsetSource) {};
    382 };
    383 
    384 struct opCharsetSwitchTo {
    385  const mozilla::Encoding* mEncoding;
    386  int32_t mCharsetSource;
    387  int32_t mLineNumber;
    388 
    389  explicit opCharsetSwitchTo(const mozilla::Encoding* aEncoding,
    390                             int32_t aCharsetSource, int32_t aLineNumber)
    391      : mEncoding(aEncoding),
    392        mCharsetSource(aCharsetSource),
    393        mLineNumber(aLineNumber) {};
    394 };
    395 
    396 struct opUpdateStyleSheet {
    397  nsIContent** mElement;
    398 
    399  explicit opUpdateStyleSheet(nsIContentHandle* aElement) {
    400    mElement = static_cast<nsIContent**>(aElement);
    401  };
    402 };
    403 
    404 struct opProcessOfflineManifest {
    405  char16_t* mUrl;
    406 
    407  explicit opProcessOfflineManifest(char16_t* aUrl) : mUrl(aUrl) {};
    408 };
    409 
    410 struct opMarkMalformedIfScript {
    411  nsIContent** mElement;
    412 
    413  explicit opMarkMalformedIfScript(nsIContentHandle* aElement) {
    414    mElement = static_cast<nsIContent**>(aElement);
    415  }
    416 };
    417 
    418 struct opStreamEnded {};
    419 
    420 struct opSetStyleLineNumber {
    421  nsIContent** mContent;
    422  int32_t mLineNumber;
    423 
    424  explicit opSetStyleLineNumber(nsIContentHandle* aContent, int32_t aLineNumber)
    425      : mLineNumber(aLineNumber) {
    426    mContent = static_cast<nsIContent**>(aContent);
    427  };
    428 };
    429 
    430 struct opSetScriptLineAndColumnNumberAndFreeze {
    431  nsIContent** mContent;
    432  int32_t mLineNumber;
    433  int32_t mColumnNumber;
    434 
    435  explicit opSetScriptLineAndColumnNumberAndFreeze(nsIContentHandle* aContent,
    436                                                   int32_t aLineNumber,
    437                                                   int32_t aColumnNumber)
    438      : mLineNumber(aLineNumber), mColumnNumber(aColumnNumber) {
    439    mContent = static_cast<nsIContent**>(aContent);
    440  };
    441 };
    442 
    443 struct opSvgLoad {
    444  nsIContent** mElement;
    445 
    446  explicit opSvgLoad(nsIContentHandle* aElement) {
    447    mElement = static_cast<nsIContent**>(aElement);
    448  };
    449 };
    450 
    451 struct opMaybeComplainAboutCharset {
    452  char* mMsgId;
    453  bool mError;
    454  int32_t mLineNumber;
    455 
    456  explicit opMaybeComplainAboutCharset(char* aMsgId, bool aError,
    457                                       int32_t aLineNumber)
    458      : mMsgId(aMsgId), mError(aError), mLineNumber(aLineNumber) {};
    459 };
    460 
    461 struct opMaybeComplainAboutDeepTree {
    462  int32_t mLineNumber;
    463 
    464  explicit opMaybeComplainAboutDeepTree(int32_t aLineNumber)
    465      : mLineNumber(aLineNumber) {};
    466 };
    467 
    468 struct opAddClass {
    469  nsIContent** mElement;
    470  char16_t* mClass;
    471 
    472  explicit opAddClass(nsIContentHandle* aElement, char16_t* aClass)
    473      : mClass(aClass) {
    474    mElement = static_cast<nsIContent**>(aElement);
    475  };
    476 };
    477 
    478 struct opAddViewSourceHref {
    479  nsIContent** mElement;
    480  char16_t* mBuffer;
    481  int32_t mLength;
    482 
    483  explicit opAddViewSourceHref(nsIContentHandle* aElement, char16_t* aBuffer,
    484                               int32_t aLength)
    485      : mBuffer(aBuffer), mLength(aLength) {
    486    mElement = static_cast<nsIContent**>(aElement);
    487  };
    488 };
    489 
    490 struct opAddViewSourceBase {
    491  char16_t* mBuffer;
    492  int32_t mLength;
    493 
    494  explicit opAddViewSourceBase(char16_t* aBuffer, int32_t aLength)
    495      : mBuffer(aBuffer), mLength(aLength) {};
    496 };
    497 
    498 struct opAddErrorType {
    499  nsIContent** mElement;
    500  char* mMsgId;
    501  nsAtom* mName;
    502  nsAtom* mOther;
    503 
    504  explicit opAddErrorType(nsIContentHandle* aElement, char* aMsgId,
    505                          nsAtom* aName = nullptr, nsAtom* aOther = nullptr)
    506      : mMsgId(aMsgId), mName(aName), mOther(aOther) {
    507    mElement = static_cast<nsIContent**>(aElement);
    508    if (aName) {
    509      aName->AddRef();
    510    }
    511    if (aOther) {
    512      aOther->AddRef();
    513    }
    514  };
    515 };
    516 
    517 struct opShallowCloneInto {
    518  nsIContent** mSrc;
    519  nsIContent** mDst;
    520  nsIContent** mIntendedParent;
    521  mozilla::dom::FromParser mFromParser;
    522 
    523  opShallowCloneInto(nsIContentHandle* aSrc, nsIContentHandle* aDst,
    524                     nsIContentHandle* aIntendedParent,
    525                     mozilla::dom::FromParser aFromParser)
    526      : mFromParser(aFromParser) {
    527    mSrc = static_cast<nsIContent**>(aSrc);
    528    mDst = static_cast<nsIContent**>(aDst);
    529    mIntendedParent = static_cast<nsIContent**>(aIntendedParent);
    530  };
    531 };
    532 
    533 struct opAddLineNumberId {
    534  nsIContent** mElement;
    535  int32_t mLineNumber;
    536 
    537  explicit opAddLineNumberId(nsIContentHandle* aElement, int32_t aLineNumber)
    538      : mLineNumber(aLineNumber) {
    539    mElement = static_cast<nsIContent**>(aElement);
    540  };
    541 };
    542 
    543 struct opStartLayout {};
    544 
    545 struct opEnableEncodingMenu {};
    546 
    547 struct opMicrotaskCheckpoint {};
    548 
    549 typedef mozilla::Variant<
    550    uninitialized,
    551    // main HTML5 ops
    552    opAppend, opDetach, opAppendChildrenToNewParent, opFosterParent,
    553    opAppendToDocument, opAddAttributes, nsHtml5DocumentMode,
    554    opCreateHTMLElement, opCreateSVGElement, opCreateMathMLElement,
    555    opSetFormElement, opAppendText, opFosterParentText, opAppendComment,
    556    opAppendCommentToDocument, opAppendDoctypeToDocument,
    557    opGetDocumentFragmentForTemplate, opSetDocumentFragmentForTemplate,
    558    opGetShadowRootFromHost, opGetFosterParent,
    559    // Gecko-specific on-pop ops
    560    opMarkAsBroken, opRunScriptThatMayDocumentWriteOrBlock,
    561    opRunScriptThatCannotDocumentWriteOrBlock, opPreventScriptExecution,
    562    opDoneAddingChildren, opDoneCreatingElement, opUpdateCharsetSource,
    563    opCharsetSwitchTo, opUpdateStyleSheet, opProcessOfflineManifest,
    564    opMarkMalformedIfScript, opStreamEnded, opSetStyleLineNumber,
    565    opSetScriptLineAndColumnNumberAndFreeze, opSvgLoad,
    566    opMaybeComplainAboutCharset, opMaybeComplainAboutDeepTree, opAddClass,
    567    opAddViewSourceHref, opAddViewSourceBase, opAddErrorType, opAddLineNumberId,
    568    opStartLayout, opEnableEncodingMenu, opMicrotaskCheckpoint,
    569    opShallowCloneInto>
    570    treeOperation;
    571 
    572 class nsHtml5TreeOperation final {
    573  template <typename T>
    574  using NotNull = mozilla::NotNull<T>;
    575  using Encoding = mozilla::Encoding;
    576 
    577 public:
    578  static nsresult AppendTextToTextNode(const char16_t* aBuffer,
    579                                       uint32_t aLength,
    580                                       mozilla::dom::Text* aTextNode,
    581                                       nsHtml5DocumentBuilder* aBuilder);
    582 
    583  static nsresult AppendText(const char16_t* aBuffer, uint32_t aLength,
    584                             nsIContent* aParent,
    585                             nsHtml5DocumentBuilder* aBuilder);
    586 
    587  static nsresult Append(nsIContent* aNode, nsIContent* aParent,
    588                         nsHtml5DocumentBuilder* aBuilder);
    589 
    590  static nsresult Append(nsIContent* aNode, nsIContent* aParent,
    591                         mozilla::dom::FromParser aFromParser,
    592                         nsHtml5DocumentBuilder* aBuilder);
    593 
    594  static nsresult AppendToDocument(nsIContent* aNode,
    595                                   nsHtml5DocumentBuilder* aBuilder);
    596 
    597  static void Detach(nsIContent* aNode, nsHtml5DocumentBuilder* aBuilder);
    598 
    599  static nsresult AppendChildrenToNewParent(nsIContent* aNode,
    600                                            nsIContent* aParent,
    601                                            nsHtml5DocumentBuilder* aBuilder);
    602 
    603  static nsresult FosterParent(nsIContent* aNode, nsIContent* aParent,
    604                               nsIContent* aTable,
    605                               nsHtml5DocumentBuilder* aBuilder);
    606 
    607  static nsresult AddAttributes(nsIContent* aNode,
    608                                nsHtml5HtmlAttributes* aAttributes,
    609                                nsHtml5DocumentBuilder* aBuilder);
    610 
    611  static void SetHTMLElementAttributes(mozilla::dom::Element* aElement,
    612                                       nsAtom* aName,
    613                                       nsHtml5HtmlAttributes* aAttributes);
    614 
    615  static nsIContent* CreateHTMLElement(
    616      nsAtom* aName, nsHtml5HtmlAttributes* aAttributes,
    617      mozilla::dom::FromParser aFromParser, nsNodeInfoManager* aNodeInfoManager,
    618      nsHtml5DocumentBuilder* aBuilder,
    619      mozilla::dom::HTMLContentCreatorFunction aCreator);
    620 
    621  static nsIContent* CreateSVGElement(
    622      nsAtom* aName, nsHtml5HtmlAttributes* aAttributes,
    623      mozilla::dom::FromParser aFromParser, nsNodeInfoManager* aNodeInfoManager,
    624      nsHtml5DocumentBuilder* aBuilder,
    625      mozilla::dom::SVGContentCreatorFunction aCreator);
    626 
    627  static nsIContent* CreateMathMLElement(nsAtom* aName,
    628                                         nsHtml5HtmlAttributes* aAttributes,
    629                                         nsNodeInfoManager* aNodeInfoManager,
    630                                         nsHtml5DocumentBuilder* aBuilder);
    631 
    632  static void SetFormElement(nsIContent* aNode, nsIContent* aForm,
    633                             nsIContent* aParent);
    634 
    635  static nsresult AppendIsindexPrompt(nsIContent* parent,
    636                                      nsHtml5DocumentBuilder* aBuilder);
    637 
    638  static nsresult FosterParentText(nsIContent* aStackParent, char16_t* aBuffer,
    639                                   uint32_t aLength, nsIContent* aTable,
    640                                   nsHtml5DocumentBuilder* aBuilder);
    641 
    642  static nsresult AppendComment(nsIContent* aParent, char16_t* aBuffer,
    643                                int32_t aLength,
    644                                nsHtml5DocumentBuilder* aBuilder);
    645 
    646  static nsresult AppendCommentToDocument(char16_t* aBuffer, int32_t aLength,
    647                                          nsHtml5DocumentBuilder* aBuilder);
    648 
    649  static nsresult AppendDoctypeToDocument(nsAtom* aName,
    650                                          const nsAString& aPublicId,
    651                                          const nsAString& aSystemId,
    652                                          nsHtml5DocumentBuilder* aBuilder);
    653 
    654  static nsIContent* GetDocumentFragmentForTemplate(nsIContent* aNode);
    655  static void SetDocumentFragmentForTemplate(nsIContent* aNode,
    656                                             nsIContent* aDocumentFragment);
    657 
    658  static nsIContent* GetFosterParent(nsIContent* aTable,
    659                                     nsIContent* aStackParent);
    660 
    661  static void PreventScriptExecution(nsIContent* aNode);
    662 
    663  static void DoneAddingChildren(nsIContent* aNode);
    664 
    665  static void DoneCreatingElement(nsIContent* aNode);
    666 
    667  static void SvgLoad(nsIContent* aNode);
    668 
    669  static void MarkMalformedIfScript(nsIContent* aNode);
    670 
    671  nsHtml5TreeOperation();
    672 
    673  ~nsHtml5TreeOperation();
    674 
    675  inline void Init(const treeOperation& aOperation) {
    676    NS_ASSERTION(mOperation.is<uninitialized>(),
    677                 "Op code must be uninitialized when initializing.");
    678    mOperation = aOperation;
    679  }
    680 
    681  inline bool IsRunScriptThatMayDocumentWriteOrBlock() {
    682    return mOperation.is<opRunScriptThatMayDocumentWriteOrBlock>();
    683  }
    684 
    685  inline bool IsMarkAsBroken() { return mOperation.is<opMarkAsBroken>(); }
    686 
    687  inline void SetSnapshot(nsAHtml5TreeBuilderState* aSnapshot, int32_t aLine) {
    688    MOZ_ASSERT(
    689        IsRunScriptThatMayDocumentWriteOrBlock(),
    690        "Setting a snapshot for a tree operation other than eTreeOpRunScript!");
    691    MOZ_ASSERT(aSnapshot, "Initialized tree op with null snapshot.");
    692    opRunScriptThatMayDocumentWriteOrBlock data =
    693        mOperation.as<opRunScriptThatMayDocumentWriteOrBlock>();
    694    data.mBuilderState = aSnapshot;
    695    data.mLineNumber = aLine;
    696    mOperation = mozilla::AsVariant(data);
    697  }
    698 
    699  nsresult Perform(nsHtml5TreeOpExecutor* aBuilder, nsIContent** aScriptElement,
    700                   bool* aInterrupted, bool* aStreamEnded);
    701 
    702 private:
    703  nsHtml5TreeOperation(const nsHtml5TreeOperation&) = delete;
    704  nsHtml5TreeOperation& operator=(const nsHtml5TreeOperation&) = delete;
    705 
    706  treeOperation mOperation;
    707 };
    708 
    709 #endif  // nsHtml5TreeOperation_h