2012-05-29 19:52:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2013-08-23 19:07:10 +04:00
|
|
|
#ifndef nsHtml5TreeOperation_h
|
|
|
|
#define nsHtml5TreeOperation_h
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2009-09-18 13:21:47 +04:00
|
|
|
#include "nsHtml5DocumentMode.h"
|
2009-09-21 15:43:43 +04:00
|
|
|
#include "nsHtml5HtmlAttributes.h"
|
2014-03-05 23:38:50 +04:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2017-06-18 14:37:50 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2010-08-24 11:06:07 +04:00
|
|
|
class nsIContent;
|
2009-09-18 13:21:47 +04:00
|
|
|
class nsHtml5TreeOpExecutor;
|
2014-03-05 23:38:49 +04:00
|
|
|
class nsHtml5DocumentBuilder;
|
2017-06-18 14:37:50 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class Encoding;
|
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2017-07-04 11:00:03 +03:00
|
|
|
enum eHtml5TreeOperation
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
eTreeOpUninitialized,
|
2009-06-29 02:44:22 +04:00
|
|
|
// main HTML5 ops
|
|
|
|
eTreeOpAppend,
|
|
|
|
eTreeOpDetach,
|
|
|
|
eTreeOpAppendChildrenToNewParent,
|
|
|
|
eTreeOpFosterParent,
|
|
|
|
eTreeOpAppendToDocument,
|
|
|
|
eTreeOpAddAttributes,
|
2009-09-18 13:21:47 +04:00
|
|
|
eTreeOpDocumentMode,
|
2017-07-04 11:00:03 +03:00
|
|
|
eTreeOpCreateHTMLElementNetwork,
|
|
|
|
eTreeOpCreateHTMLElementNotNetwork,
|
|
|
|
eTreeOpCreateSVGElementNetwork,
|
|
|
|
eTreeOpCreateSVGElementNotNetwork,
|
|
|
|
eTreeOpCreateMathMLElement,
|
2009-09-21 15:43:43 +04:00
|
|
|
eTreeOpSetFormElement,
|
2009-11-17 11:52:30 +03:00
|
|
|
eTreeOpAppendText,
|
|
|
|
eTreeOpFosterParentText,
|
|
|
|
eTreeOpAppendComment,
|
|
|
|
eTreeOpAppendCommentToDocument,
|
|
|
|
eTreeOpAppendDoctypeToDocument,
|
2013-03-26 11:15:23 +04:00
|
|
|
eTreeOpGetDocumentFragmentForTemplate,
|
2014-11-10 09:50:18 +03:00
|
|
|
eTreeOpGetFosterParent,
|
2009-06-29 02:44:22 +04:00
|
|
|
// Gecko-specific on-pop ops
|
2011-09-28 16:45:17 +04:00
|
|
|
eTreeOpMarkAsBroken,
|
2009-09-21 15:43:43 +04:00
|
|
|
eTreeOpRunScript,
|
2009-11-17 11:52:30 +03:00
|
|
|
eTreeOpRunScriptAsyncDefer,
|
2012-06-20 11:05:39 +04:00
|
|
|
eTreeOpPreventScriptExecution,
|
2009-06-29 02:44:22 +04:00
|
|
|
eTreeOpDoneAddingChildren,
|
|
|
|
eTreeOpDoneCreatingElement,
|
2011-11-01 15:33:11 +04:00
|
|
|
eTreeOpSetDocumentCharset,
|
2009-09-21 17:18:20 +04:00
|
|
|
eTreeOpNeedsCharsetSwitchTo,
|
2009-06-29 02:44:22 +04:00
|
|
|
eTreeOpUpdateStyleSheet,
|
|
|
|
eTreeOpProcessMeta,
|
|
|
|
eTreeOpProcessOfflineManifest,
|
2009-09-21 15:43:43 +04:00
|
|
|
eTreeOpMarkMalformedIfScript,
|
2009-09-21 17:18:20 +04:00
|
|
|
eTreeOpStreamEnded,
|
2009-10-28 16:48:37 +03:00
|
|
|
eTreeOpSetStyleLineNumber,
|
2009-11-17 11:52:30 +03:00
|
|
|
eTreeOpSetScriptLineNumberAndFreeze,
|
2010-07-19 02:07:54 +04:00
|
|
|
eTreeOpSvgLoad,
|
2012-03-24 15:34:42 +04:00
|
|
|
eTreeOpMaybeComplainAboutCharset,
|
2010-07-30 14:15:38 +04:00
|
|
|
eTreeOpAddClass,
|
|
|
|
eTreeOpAddViewSourceHref,
|
2014-09-30 13:35:17 +04:00
|
|
|
eTreeOpAddViewSourceBase,
|
2011-11-01 15:33:11 +04:00
|
|
|
eTreeOpAddError,
|
2011-11-01 15:33:11 +04:00
|
|
|
eTreeOpAddLineNumberId,
|
2009-06-29 02:44:22 +04:00
|
|
|
eTreeOpStartLayout
|
|
|
|
};
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
class nsHtml5TreeOperationStringPair {
|
|
|
|
private:
|
|
|
|
nsString mPublicId;
|
|
|
|
nsString mSystemId;
|
|
|
|
public:
|
|
|
|
nsHtml5TreeOperationStringPair(const nsAString& aPublicId,
|
|
|
|
const nsAString& aSystemId)
|
|
|
|
: mPublicId(aPublicId)
|
2014-03-05 23:38:50 +04:00
|
|
|
, mSystemId(aSystemId)
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
MOZ_COUNT_CTOR(nsHtml5TreeOperationStringPair);
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
~nsHtml5TreeOperationStringPair()
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
MOZ_COUNT_DTOR(nsHtml5TreeOperationStringPair);
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void Get(nsAString& aPublicId, nsAString& aSystemId)
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
aPublicId.Assign(mPublicId);
|
|
|
|
aSystemId.Assign(mSystemId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
class nsHtml5TreeOperation final {
|
|
|
|
template <typename T> using NotNull = mozilla::NotNull<T>;
|
|
|
|
using Encoding = mozilla::Encoding;
|
2009-06-29 02:44:22 +04:00
|
|
|
|
|
|
|
public:
|
2014-03-05 23:38:49 +04:00
|
|
|
/**
|
|
|
|
* Atom is used inside the parser core are either static atoms that are
|
|
|
|
* the same as Gecko-wide static atoms or they are dynamic atoms scoped by
|
|
|
|
* both thread and parser to a particular nsHtml5AtomTable. In order to
|
|
|
|
* such scoped atoms coming into contact with the rest of Gecko, atoms
|
|
|
|
* that are about to exit the parser must go through this method which
|
|
|
|
* reobtains dynamic atoms from the Gecko-global atom table.
|
|
|
|
*
|
|
|
|
* @param aAtom a potentially parser-scoped atom
|
2017-10-03 01:05:19 +03:00
|
|
|
* @return an nsAtom that's pointer comparable on the main thread with
|
2014-03-05 23:38:49 +04:00
|
|
|
* other not-parser atoms.
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
static inline already_AddRefed<nsAtom> Reget(nsAtom* aAtom)
|
2014-03-05 23:38:49 +04:00
|
|
|
{
|
|
|
|
if (!aAtom || aAtom->IsStaticAtom()) {
|
|
|
|
return dont_AddRef(aAtom);
|
|
|
|
}
|
|
|
|
nsAutoString str;
|
|
|
|
aAtom->ToString(str);
|
2017-04-03 23:13:55 +03:00
|
|
|
return NS_AtomizeMainThread(str);
|
2014-03-05 23:38:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult AppendTextToTextNode(const char16_t* aBuffer,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsIContent* aTextNode,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult AppendText(const char16_t* aBuffer,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsIContent* aParent,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult Append(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult AppendToDocument(nsIContent* aNode,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
static void Detach(nsIContent* aNode, nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult AppendChildrenToNewParent(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult FosterParent(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aTable,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult AddAttributes(nsIContent* aNode,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
2017-10-26 09:55:41 +03:00
|
|
|
static void SetHTMLElementAttributes(mozilla::dom::Element* aElement,
|
|
|
|
nsAtom* aName,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes);
|
|
|
|
|
2017-07-04 11:00:03 +03:00
|
|
|
static nsIContent* CreateHTMLElement(
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aName,
|
2017-07-04 11:00:03 +03:00
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
|
|
|
mozilla::dom::FromParser aFromParser,
|
|
|
|
nsNodeInfoManager* aNodeInfoManager,
|
|
|
|
nsHtml5DocumentBuilder* aBuilder,
|
|
|
|
mozilla::dom::HTMLContentCreatorFunction aCreator);
|
|
|
|
|
|
|
|
static nsIContent* CreateSVGElement(
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aName,
|
2017-07-04 11:00:03 +03:00
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
|
|
|
mozilla::dom::FromParser aFromParser,
|
|
|
|
nsNodeInfoManager* aNodeInfoManager,
|
|
|
|
nsHtml5DocumentBuilder* aBuilder,
|
|
|
|
mozilla::dom::SVGContentCreatorFunction aCreator);
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsIContent* CreateMathMLElement(nsAtom* aName,
|
2017-07-04 11:00:03 +03:00
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
|
|
|
nsNodeInfoManager* aNodeInfoManager,
|
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static void SetFormElement(nsIContent* aNode, nsIContent* aParent);
|
|
|
|
|
|
|
|
static nsresult AppendIsindexPrompt(nsIContent* parent,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult FosterParentText(nsIContent* aStackParent,
|
|
|
|
char16_t* aBuffer,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsIContent* aTable,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult AppendComment(nsIContent* aParent,
|
|
|
|
char16_t* aBuffer,
|
|
|
|
int32_t aLength,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsresult AppendCommentToDocument(char16_t* aBuffer,
|
|
|
|
int32_t aLength,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsresult AppendDoctypeToDocument(nsAtom* aName,
|
2014-03-05 23:38:49 +04:00
|
|
|
const nsAString& aPublicId,
|
|
|
|
const nsAString& aSystemId,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsHtml5DocumentBuilder* aBuilder);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static nsIContent* GetDocumentFragmentForTemplate(nsIContent* aNode);
|
|
|
|
|
2014-11-10 09:50:18 +03:00
|
|
|
static nsIContent* GetFosterParent(nsIContent* aTable, nsIContent* aStackParent);
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
static void PreventScriptExecution(nsIContent* aNode);
|
|
|
|
|
2014-06-17 03:01:22 +04:00
|
|
|
static void DoneAddingChildren(nsIContent* aNode);
|
2014-03-05 23:38:49 +04:00
|
|
|
|
|
|
|
static void DoneCreatingElement(nsIContent* aNode);
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
static void SvgLoad(nsIContent* aNode);
|
|
|
|
|
|
|
|
static void MarkMalformedIfScript(nsIContent* aNode);
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
nsHtml5TreeOperation();
|
|
|
|
|
|
|
|
~nsHtml5TreeOperation();
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
mOpCode = aOpCode;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode, nsIContentHandle* aNode)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aNode, "Initialized tree op with null node.");
|
2009-06-29 02:44:22 +04:00
|
|
|
mOpCode = aOpCode;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aNode);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsIContentHandle* aNode,
|
2014-03-05 23:38:50 +04:00
|
|
|
nsIContentHandle* aParent)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aNode, "Initialized tree op with null node.");
|
|
|
|
NS_PRECONDITION(aParent, "Initialized tree op with null parent.");
|
2009-06-29 02:44:22 +04:00
|
|
|
mOpCode = aOpCode;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aNode);
|
|
|
|
mTwo.node = static_cast<nsIContent**>(aParent);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2010-03-09 15:39:32 +03:00
|
|
|
|
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
|
|
|
const nsACString& aString,
|
2014-03-05 23:38:50 +04:00
|
|
|
int32_t aInt32)
|
|
|
|
{
|
2011-02-11 13:33:32 +03:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t len = aString.Length();
|
2011-02-11 13:33:32 +03:00
|
|
|
char* str = new char[len + 1];
|
|
|
|
const char* start = aString.BeginReading();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < len; ++i) {
|
2011-02-11 13:33:32 +03:00
|
|
|
str[i] = start[i];
|
|
|
|
}
|
|
|
|
str[len] = '\0';
|
|
|
|
|
|
|
|
mOpCode = aOpCode;
|
|
|
|
mOne.charPtr = str;
|
2011-11-01 15:33:11 +04:00
|
|
|
mFour.integer = aInt32;
|
2010-03-09 15:39:32 +03:00
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2012-03-24 15:34:42 +04:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
|
|
|
const nsACString& aString,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aInt32,
|
2014-03-05 23:38:50 +04:00
|
|
|
int32_t aLineNumber)
|
|
|
|
{
|
2012-03-24 15:34:42 +04:00
|
|
|
Init(aOpCode, aString, aInt32);
|
|
|
|
mTwo.integer = aLineNumber;
|
|
|
|
}
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
|
|
|
NotNull<const Encoding*> aEncoding,
|
|
|
|
int32_t aInt32)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
|
|
|
|
mOpCode = aOpCode;
|
|
|
|
mOne.encoding = aEncoding;
|
|
|
|
mFour.integer = aInt32;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
|
|
|
NotNull<const Encoding*> aEncoding,
|
|
|
|
int32_t aInt32,
|
|
|
|
int32_t aLineNumber)
|
|
|
|
{
|
|
|
|
Init(aOpCode, aEncoding, aInt32);
|
|
|
|
mTwo.integer = aLineNumber;
|
|
|
|
}
|
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsIContentHandle* aNode,
|
|
|
|
nsIContentHandle* aParent,
|
2014-03-05 23:38:50 +04:00
|
|
|
nsIContentHandle* aTable)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aNode, "Initialized tree op with null node.");
|
|
|
|
NS_PRECONDITION(aParent, "Initialized tree op with null parent.");
|
|
|
|
NS_PRECONDITION(aTable, "Initialized tree op with null table.");
|
2009-06-29 02:44:22 +04:00
|
|
|
mOpCode = aOpCode;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aNode);
|
|
|
|
mTwo.node = static_cast<nsIContent**>(aParent);
|
|
|
|
mThree.node = static_cast<nsIContent**>(aTable);
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2009-09-18 13:21:47 +04:00
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void Init(nsHtml5DocumentMode aMode)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-09-18 13:21:47 +04:00
|
|
|
mOpCode = eTreeOpDocumentMode;
|
2009-09-21 15:43:43 +04:00
|
|
|
mOne.mode = aMode;
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void InitScript(nsIContentHandle* aNode)
|
|
|
|
{
|
2009-10-12 17:08:04 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aNode, "Initialized tree op with null node.");
|
2009-10-12 17:08:04 +04:00
|
|
|
mOpCode = eTreeOpRunScript;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aNode);
|
2012-07-30 18:20:58 +04:00
|
|
|
mTwo.state = nullptr;
|
2009-10-12 17:08:04 +04:00
|
|
|
}
|
2017-07-04 11:00:03 +03:00
|
|
|
|
|
|
|
inline void Init(int32_t aNamespace,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aName,
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsIContentHandle* aTarget,
|
2014-11-10 09:50:18 +03:00
|
|
|
nsIContentHandle* aIntendedParent,
|
2017-07-04 11:00:03 +03:00
|
|
|
bool aFromNetwork,
|
|
|
|
nsHtml5ContentCreatorFunction aCreator)
|
2014-03-05 23:38:50 +04:00
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aName, "Initialized tree op with null name.");
|
|
|
|
NS_PRECONDITION(aTarget, "Initialized tree op with null target node.");
|
2017-07-04 11:00:03 +03:00
|
|
|
if (aNamespace == kNameSpaceID_XHTML) {
|
|
|
|
mOpCode = aFromNetwork ? eTreeOpCreateHTMLElementNetwork
|
|
|
|
: eTreeOpCreateHTMLElementNotNetwork;
|
|
|
|
mFour.htmlCreator = aCreator.html;
|
|
|
|
} else if (aNamespace == kNameSpaceID_SVG) {
|
|
|
|
mOpCode = aFromNetwork ? eTreeOpCreateSVGElementNetwork
|
|
|
|
: eTreeOpCreateSVGElementNotNetwork;
|
|
|
|
mFour.svgCreator = aCreator.svg;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(aNamespace == kNameSpaceID_MathML);
|
|
|
|
mOpCode = eTreeOpCreateMathMLElement;
|
|
|
|
}
|
2014-11-10 09:50:18 +03:00
|
|
|
mFive.node = static_cast<nsIContent**>(aIntendedParent);
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aTarget);
|
2009-09-21 15:43:43 +04:00
|
|
|
mTwo.atom = aName;
|
|
|
|
if (aAttributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mThree.attributes = nullptr;
|
2009-09-21 15:43:43 +04:00
|
|
|
} else {
|
|
|
|
mThree.attributes = aAttributes;
|
|
|
|
}
|
2009-09-18 13:21:47 +04:00
|
|
|
}
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* aBuffer,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aLength,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsIContentHandle* aStackParent,
|
2014-03-05 23:38:50 +04:00
|
|
|
nsIContentHandle* aTable)
|
|
|
|
{
|
2009-11-17 11:52:30 +03:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
NS_PRECONDITION(aBuffer, "Initialized tree op with null buffer.");
|
|
|
|
mOpCode = aOpCode;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aStackParent);
|
2009-11-17 11:52:30 +03:00
|
|
|
mTwo.unicharPtr = aBuffer;
|
2014-03-05 23:38:49 +04:00
|
|
|
mThree.node = static_cast<nsIContent**>(aTable);
|
2011-11-01 15:33:11 +04:00
|
|
|
mFour.integer = aLength;
|
2009-11-17 11:52:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* aBuffer,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aLength,
|
2014-03-05 23:38:50 +04:00
|
|
|
nsIContentHandle* aParent)
|
|
|
|
{
|
2009-11-17 11:52:30 +03:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
NS_PRECONDITION(aBuffer, "Initialized tree op with null buffer.");
|
|
|
|
mOpCode = aOpCode;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aParent);
|
2009-11-17 11:52:30 +03:00
|
|
|
mTwo.unicharPtr = aBuffer;
|
2011-11-01 15:33:11 +04:00
|
|
|
mFour.integer = aLength;
|
2009-11-17 11:52:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* aBuffer,
|
2014-03-05 23:38:50 +04:00
|
|
|
int32_t aLength)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aBuffer, "Initialized tree op with null buffer.");
|
2009-09-21 15:43:43 +04:00
|
|
|
mOpCode = aOpCode;
|
|
|
|
mTwo.unicharPtr = aBuffer;
|
2011-11-01 15:33:11 +04:00
|
|
|
mFour.integer = aLength;
|
2009-09-21 15:43:43 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
inline void Init(nsIContentHandle* aElement,
|
2014-03-05 23:38:50 +04:00
|
|
|
nsHtml5HtmlAttributes* aAttributes)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aElement, "Initialized tree op with null element.");
|
2009-09-21 15:43:43 +04:00
|
|
|
mOpCode = eTreeOpAddAttributes;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aElement);
|
2009-09-21 15:43:43 +04:00
|
|
|
mTwo.attributes = aAttributes;
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
inline void Init(nsAtom* aName,
|
2009-09-21 15:43:43 +04:00
|
|
|
const nsAString& aPublicId,
|
2014-03-05 23:38:50 +04:00
|
|
|
const nsAString& aSystemId)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-11-17 11:52:30 +03:00
|
|
|
mOpCode = eTreeOpAppendDoctypeToDocument;
|
2009-09-21 15:43:43 +04:00
|
|
|
mOne.atom = aName;
|
|
|
|
mTwo.stringPair = new nsHtml5TreeOperationStringPair(aPublicId, aSystemId);
|
|
|
|
}
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
inline void Init(nsIContentHandle* aElement,
|
2011-11-01 15:33:11 +04:00
|
|
|
const char* aMsgId,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAtom,
|
|
|
|
nsAtom* aOtherAtom)
|
2014-03-05 23:38:50 +04:00
|
|
|
{
|
2011-11-01 15:33:11 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
mOpCode = eTreeOpAddError;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aElement);
|
2011-11-01 15:33:11 +04:00
|
|
|
mTwo.charPtr = (char*)aMsgId;
|
2011-11-01 15:33:11 +04:00
|
|
|
mThree.atom = aAtom;
|
|
|
|
mFour.atom = aOtherAtom;
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
inline void Init(nsIContentHandle* aElement,
|
2011-11-01 15:33:11 +04:00
|
|
|
const char* aMsgId,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAtom)
|
2014-03-05 23:38:50 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
Init(aElement, aMsgId, aAtom, nullptr);
|
2011-11-01 15:33:11 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
inline void Init(nsIContentHandle* aElement,
|
2014-03-05 23:38:50 +04:00
|
|
|
const char* aMsgId)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
Init(aElement, aMsgId, nullptr, nullptr);
|
2011-11-01 15:33:11 +04:00
|
|
|
}
|
|
|
|
|
2012-03-24 15:34:42 +04:00
|
|
|
inline void Init(const char* aMsgId,
|
|
|
|
bool aError,
|
2014-03-05 23:38:50 +04:00
|
|
|
int32_t aLineNumber)
|
|
|
|
{
|
2012-03-24 15:34:42 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
mOpCode = eTreeOpMaybeComplainAboutCharset;
|
|
|
|
mOne.charPtr = const_cast<char*>(aMsgId);
|
|
|
|
mTwo.integer = aError;
|
|
|
|
mThree.integer = aLineNumber;
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode, const nsAString& aString)
|
|
|
|
{
|
2010-02-02 10:43:18 +03:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
|
2017-03-06 07:52:09 +03:00
|
|
|
char16_t* str = ToNewUnicode(aString);
|
2010-02-02 10:43:18 +03:00
|
|
|
mOpCode = aOpCode;
|
|
|
|
mOne.unicharPtr = str;
|
|
|
|
}
|
|
|
|
|
2009-10-28 16:48:37 +03:00
|
|
|
inline void Init(eHtml5TreeOperation aOpCode,
|
2014-03-05 23:38:49 +04:00
|
|
|
nsIContentHandle* aNode,
|
2014-03-05 23:38:50 +04:00
|
|
|
int32_t aInt)
|
|
|
|
{
|
2009-10-28 16:48:37 +03:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aNode, "Initialized tree op with null node.");
|
2009-10-28 16:48:37 +03:00
|
|
|
mOpCode = aOpCode;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aNode);
|
2011-11-01 15:33:11 +04:00
|
|
|
mFour.integer = aInt;
|
2009-10-28 16:48:37 +03:00
|
|
|
}
|
|
|
|
|
2014-11-05 18:44:37 +03:00
|
|
|
inline void Init(nsresult aRv)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
NS_PRECONDITION(NS_FAILED(aRv), "Initialized tree op with non-failure.");
|
|
|
|
mOpCode = eTreeOpMarkAsBroken;
|
|
|
|
mOne.result = aRv;
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void InitAddClass(nsIContentHandle* aNode, const char16_t* aClass)
|
|
|
|
{
|
2010-07-30 14:15:38 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
NS_PRECONDITION(aNode, "Initialized tree op with null node.");
|
|
|
|
NS_PRECONDITION(aClass, "Initialized tree op with null string.");
|
|
|
|
// aClass must be a literal string that does not need freeing
|
|
|
|
mOpCode = eTreeOpAddClass;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aNode);
|
2014-01-04 19:02:17 +04:00
|
|
|
mTwo.unicharPtr = (char16_t*)aClass;
|
2010-07-30 14:15:38 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
inline void InitAddLineNumberId(nsIContentHandle* aNode,
|
2014-03-05 23:38:50 +04:00
|
|
|
const int32_t aLineNumber)
|
|
|
|
{
|
2011-11-01 15:33:11 +04:00
|
|
|
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
|
|
|
"Op code must be uninitialized when initializing.");
|
|
|
|
NS_PRECONDITION(aNode, "Initialized tree op with null node.");
|
|
|
|
NS_PRECONDITION(aLineNumber > 0, "Initialized tree op with line number.");
|
|
|
|
// aClass must be a literal string that does not need freeing
|
|
|
|
mOpCode = eTreeOpAddLineNumberId;
|
2014-03-05 23:38:49 +04:00
|
|
|
mOne.node = static_cast<nsIContent**>(aNode);
|
2011-11-01 15:33:11 +04:00
|
|
|
mFour.integer = aLineNumber;
|
2011-11-01 15:33:11 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline bool IsRunScript()
|
|
|
|
{
|
2009-09-21 15:43:43 +04:00
|
|
|
return mOpCode == eTreeOpRunScript;
|
2009-06-29 02:44:22 +04:00
|
|
|
}
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2015-08-25 18:05:46 +03:00
|
|
|
inline bool IsMarkAsBroken()
|
|
|
|
{
|
|
|
|
return mOpCode == eTreeOpMarkAsBroken;
|
|
|
|
}
|
|
|
|
|
2014-03-05 23:38:50 +04:00
|
|
|
inline void SetSnapshot(nsAHtml5TreeBuilderState* aSnapshot, int32_t aLine)
|
|
|
|
{
|
2009-09-21 17:18:20 +04:00
|
|
|
NS_ASSERTION(IsRunScript(),
|
|
|
|
"Setting a snapshot for a tree operation other than eTreeOpRunScript!");
|
2009-10-30 14:47:17 +03:00
|
|
|
NS_PRECONDITION(aSnapshot, "Initialized tree op with null snapshot.");
|
2009-09-21 17:18:20 +04:00
|
|
|
mTwo.state = aSnapshot;
|
2011-11-01 15:33:11 +04:00
|
|
|
mFour.integer = aLine;
|
2009-09-21 17:18:20 +04:00
|
|
|
}
|
2009-06-29 02:44:22 +04:00
|
|
|
|
2014-03-05 23:38:49 +04:00
|
|
|
nsresult Perform(nsHtml5TreeOpExecutor* aBuilder,
|
2017-03-17 04:50:28 +03:00
|
|
|
nsIContent** aScriptElement,
|
2017-10-30 18:15:19 +03:00
|
|
|
bool* aInterrupted,
|
|
|
|
bool* aStreamEnded);
|
2014-03-06 00:26:07 +04:00
|
|
|
|
2009-06-29 02:44:22 +04:00
|
|
|
private:
|
2017-10-27 10:06:33 +03:00
|
|
|
nsHtml5TreeOperation(const nsHtml5TreeOperation&) = delete;
|
|
|
|
nsHtml5TreeOperation& operator=(const nsHtml5TreeOperation&) = delete;
|
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
// possible optimization:
|
|
|
|
// Make the queue take items the size of pointer and make the op code
|
|
|
|
// decide how many operands it dequeues after it.
|
2009-06-29 02:44:22 +04:00
|
|
|
eHtml5TreeOperation mOpCode;
|
2009-09-21 15:43:43 +04:00
|
|
|
union {
|
|
|
|
nsIContent** node;
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* atom;
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5HtmlAttributes* attributes;
|
|
|
|
nsHtml5DocumentMode mode;
|
2014-11-05 18:44:37 +03:00
|
|
|
char16_t* unicharPtr;
|
2009-09-21 17:18:20 +04:00
|
|
|
char* charPtr;
|
2009-09-21 15:43:43 +04:00
|
|
|
nsHtml5TreeOperationStringPair* stringPair;
|
2009-09-21 17:18:20 +04:00
|
|
|
nsAHtml5TreeBuilderState* state;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t integer;
|
2014-11-05 18:44:37 +03:00
|
|
|
nsresult result;
|
2017-06-18 14:37:50 +03:00
|
|
|
const Encoding* encoding;
|
2017-07-04 11:00:03 +03:00
|
|
|
mozilla::dom::HTMLContentCreatorFunction htmlCreator;
|
|
|
|
mozilla::dom::SVGContentCreatorFunction svgCreator;
|
2014-11-10 09:50:18 +03:00
|
|
|
} mOne, mTwo, mThree, mFour, mFive;
|
2009-06-29 02:44:22 +04:00
|
|
|
};
|
|
|
|
|
2013-08-23 19:07:10 +04:00
|
|
|
#endif // nsHtml5TreeOperation_h
|