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
|
|
|
|
2009-09-21 15:43:43 +04:00
|
|
|
#define NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH 512
|
2018-03-16 18:26:06 +03:00
|
|
|
private:
|
|
|
|
using Encoding = mozilla::Encoding;
|
|
|
|
template<typename T>
|
|
|
|
using NotNull = mozilla::NotNull<T>;
|
|
|
|
|
|
|
|
nsHtml5OplessBuilder* mBuilder;
|
|
|
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
// If mBuilder is not null, the tree op machinery is not in use and
|
|
|
|
// the fields below aren't in use, either.
|
|
|
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
nsHtml5Highlighter* mViewSource;
|
|
|
|
nsTArray<nsHtml5TreeOperation> mOpQueue;
|
|
|
|
nsTArray<nsHtml5SpeculativeLoad> mSpeculativeLoadQueue;
|
|
|
|
nsAHtml5TreeOpSink* mOpSink;
|
|
|
|
mozilla::UniquePtr<nsIContent* []> mHandles;
|
|
|
|
int32_t mHandlesUsed;
|
|
|
|
nsTArray<mozilla::UniquePtr<nsIContent* []>> mOldHandles;
|
|
|
|
nsHtml5TreeOpStage* mSpeculativeLoadStage;
|
|
|
|
nsresult mBroken;
|
|
|
|
bool mCurrentHtmlScriptIsAsyncOrDefer;
|
|
|
|
bool mPreventScriptExecution;
|
2009-06-29 02:44:22 +04:00
|
|
|
#ifdef DEBUG
|
2018-03-16 18:26:06 +03:00
|
|
|
bool mActive;
|
2009-06-29 02:44:22 +04:00
|
|
|
#endif
|
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
// DocumentModeHandler
|
|
|
|
/**
|
|
|
|
* Tree builder uses this to report quirkiness of the document
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
documentMode(nsHtml5DocumentMode m);
|
|
|
|
|
|
|
|
nsIContentHandle*
|
|
|
|
getDocumentFragmentForTemplate(nsIContentHandle* aTemplate);
|
|
|
|
|
|
|
|
nsIContentHandle*
|
|
|
|
getFormPointerForContext(nsIContentHandle* aContext);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Using nsIContent** instead of nsIContent* is the parser deals with DOM
|
|
|
|
* nodes in a way that works off the main thread. Non-main-thread code
|
|
|
|
* can't refcount or otherwise touch nsIContent objects in any way.
|
|
|
|
* Yet, the off-the-main-thread code needs to have a way to hold onto a
|
|
|
|
* particular node and repeatedly operate on the same node.
|
|
|
|
*
|
|
|
|
* The way this works is that the off-the-main-thread code has an
|
|
|
|
* nsIContent** for each DOM node and a given nsIContent** is only ever
|
|
|
|
* actually dereferenced into an actual nsIContent* on the main thread.
|
|
|
|
* When the off-the-main-thread code requests a new node, it gets an
|
|
|
|
* nsIContent** immediately and a tree op is enqueued for later allocating
|
|
|
|
* an actual nsIContent object and writing a pointer to it into the memory
|
|
|
|
* location pointed to by the nsIContent**.
|
|
|
|
*
|
|
|
|
* Since tree ops are in a queue, the node creating tree op will always
|
|
|
|
* run before tree ops that try to further operate on the node that the
|
|
|
|
* nsIContent** is a handle to.
|
|
|
|
*
|
|
|
|
* On-the-main-thread parts of the parser use nsIContent* instead of
|
|
|
|
* nsIContent**. Since both cases share the same parser core, the parser
|
|
|
|
* core casts both to nsIContentHandle*.
|
|
|
|
*/
|
|
|
|
nsIContentHandle*
|
|
|
|
AllocateContentHandle();
|
|
|
|
|
|
|
|
void
|
|
|
|
accumulateCharactersForced(const char16_t* aBuf,
|
|
|
|
int32_t aStart,
|
|
|
|
int32_t aLength)
|
|
|
|
{
|
|
|
|
accumulateCharacters(aBuf, aStart, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkAsBrokenAndRequestSuspensionWithBuilder(nsresult aRv)
|
|
|
|
{
|
|
|
|
mBuilder->MarkAsBroken(aRv);
|
|
|
|
requestSuspension();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkAsBrokenAndRequestSuspensionWithoutBuilder(nsresult aRv)
|
|
|
|
{
|
|
|
|
MarkAsBroken(aRv);
|
|
|
|
requestSuspension();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MarkAsBrokenFromPortability(nsresult aRv);
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit nsHtml5TreeBuilder(nsHtml5OplessBuilder* aBuilder);
|
|
|
|
|
|
|
|
nsHtml5TreeBuilder(nsAHtml5TreeOpSink* aOpSink, nsHtml5TreeOpStage* aStage);
|
|
|
|
|
|
|
|
~nsHtml5TreeBuilder();
|
|
|
|
|
|
|
|
void
|
|
|
|
StartPlainTextViewSource(const nsAutoString& aTitle);
|
|
|
|
|
|
|
|
void
|
|
|
|
StartPlainText();
|
|
|
|
|
|
|
|
void
|
|
|
|
StartPlainTextBody();
|
|
|
|
|
|
|
|
bool
|
|
|
|
HasScript();
|
|
|
|
|
|
|
|
void
|
|
|
|
SetOpSink(nsAHtml5TreeOpSink* aOpSink)
|
|
|
|
{
|
|
|
|
mOpSink = aOpSink;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearOps()
|
|
|
|
{
|
|
|
|
mOpQueue.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Flush(bool aDiscretionary = false);
|
|
|
|
|
|
|
|
void
|
|
|
|
FlushLoads();
|
|
|
|
|
|
|
|
void
|
|
|
|
SetDocumentCharset(NotNull<const Encoding*> aEncoding, int32_t aCharsetSource);
|
|
|
|
|
|
|
|
void
|
|
|
|
StreamEnded();
|
|
|
|
|
|
|
|
void
|
|
|
|
NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding,
|
|
|
|
int32_t aSource,
|
|
|
|
int32_t aLineNumber);
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeComplainAboutCharset(const char* aMsgId, bool aError, int32_t aLineNumber);
|
|
|
|
|
|
|
|
void
|
2018-04-06 00:20:28 +03:00
|
|
|
TryToEnableEncodingMenu();
|
2018-03-16 18:26:06 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
AddSnapshotToScript(nsAHtml5TreeBuilderState* aSnapshot, int32_t aLine);
|
2014-03-05 23:38:50 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
DropHandles();
|
2015-08-25 18:05:46 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
SetPreventScriptExecution(bool aPrevent)
|
|
|
|
{
|
|
|
|
mPreventScriptExecution = aPrevent;
|
|
|
|
}
|
2009-09-21 15:43:43 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
bool
|
|
|
|
HasBuilder()
|
|
|
|
{
|
|
|
|
return mBuilder;
|
|
|
|
}
|
2014-03-05 23:38:50 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Makes sure the buffers are large enough to be able to tokenize aLength
|
|
|
|
* UTF-16 code units before having to make the buffers larger.
|
|
|
|
*
|
|
|
|
* @param aLength the number of UTF-16 code units to be tokenized before the
|
|
|
|
* next call to this method.
|
|
|
|
* @return true if successful; false if out of memory
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
EnsureBufferSpace(int32_t aLength);
|
2009-09-21 15:43:43 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
EnableViewSource(nsHtml5Highlighter* aHighlighter);
|
2011-11-30 21:44:31 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStrayStartTag(nsAtom* aName);
|
2011-11-01 19:27:36 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStrayEndTag(nsAtom* aName);
|
2013-03-07 08:45:08 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errUnclosedElements(int32_t aIndex, nsAtom* aName);
|
2009-10-30 14:47:17 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errUnclosedElementsImplied(int32_t aIndex, nsAtom* aName);
|
2010-02-26 12:18:38 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errUnclosedElementsCell(int32_t aIndex);
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStrayDoctype();
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errAlmostStandardsDoctype();
|
2012-03-24 15:34:42 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errQuirkyDoctype();
|
2009-09-21 17:18:20 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNonSpaceInTrailer();
|
2017-11-23 10:03:41 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNonSpaceAfterFrameset();
|
2010-11-18 11:19:59 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNonSpaceInFrameset();
|
2011-09-28 16:45:17 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNonSpaceAfterBody();
|
2012-06-20 11:05:39 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNonSpaceInColgroupInFragment();
|
2014-03-05 23:38:50 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNonSpaceInNoscriptInHead();
|
2015-08-25 18:05:45 +03:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errFooBetweenHeadAndBody(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStartTagWithoutDoctype();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNoSelectInTableScope();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStartSelectWhereEndSelectExpected();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStartTagWithSelectOpen(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errBadStartTagInHead(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errImage();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errIsindex();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errFooSeenWhenFooOpen(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errHeadingWhenHeadingOpen();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errFramesetStart();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNoCellToClose();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStartTagInTable(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errFormWhenFormOpen();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errTableSeenWhileTableOpen();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStartTagInTableBody(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errEndTagSeenWithoutDoctype();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errEndTagAfterBody();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errEndTagSeenWithSelectOpen(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errGarbageInColgroup();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errEndTagBr();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNoElementToCloseButEndTagSeen(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errHtmlStartTagInForeignContext(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errTableClosedWhileCaptionOpen();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNoTableRowToClose();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNonSpaceInTable();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errUnclosedChildrenInRuby();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errStartTagSeenWithoutRuby(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errSelfClosing();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errNoCheckUnclosedElementsOnStack();
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errEndTagDidNotMatchCurrentOpenElement(nsAtom* aName, nsAtom* aOther);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errEndTagViolatesNestingRules(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
errEndWithUnclosedElements(nsAtom* aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
void
|
|
|
|
MarkAsBroken(nsresult aRv);
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2018-03-16 18:26:06 +03:00
|
|
|
/**
|
|
|
|
* Checks if this parser is broken. Returns a non-NS_OK (i.e. non-0)
|
|
|
|
* value if broken.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
IsBroken()
|
|
|
|
{
|
|
|
|
return mBroken;
|
|
|
|
}
|