2012-05-29 15:52:43 +00: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-28 22:44:22 +00:00
|
|
|
|
2009-09-21 11:43:43 +00:00
|
|
|
#define NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH 512
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
private:
|
2011-11-01 11:33:11 +00:00
|
|
|
nsHtml5Highlighter* mViewSource;
|
2009-09-21 11:43:43 +00:00
|
|
|
nsTArray<nsHtml5TreeOperation> mOpQueue;
|
2010-02-26 09:18:38 +00:00
|
|
|
nsTArray<nsHtml5SpeculativeLoad> mSpeculativeLoadQueue;
|
2009-09-21 13:18:20 +00:00
|
|
|
nsAHtml5TreeOpSink* mOpSink;
|
2009-09-21 11:43:43 +00:00
|
|
|
nsAutoArrayPtr<nsIContent*> mHandles;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mHandlesUsed;
|
2009-10-12 13:08:04 +00:00
|
|
|
nsTArray<nsAutoArrayPtr<nsIContent*> > mOldHandles;
|
2010-02-26 09:18:38 +00:00
|
|
|
nsHtml5TreeOpStage* mSpeculativeLoadStage;
|
2010-05-20 09:03:11 +00:00
|
|
|
nsIContent** mDeepTreeSurrogateParent;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mCurrentHtmlScriptIsAsyncOrDefer;
|
2012-06-20 07:05:39 +00:00
|
|
|
bool mPreventScriptExecution;
|
2009-06-28 22:44:22 +00:00
|
|
|
#ifdef DEBUG
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mActive;
|
2009-06-28 22:44:22 +00:00
|
|
|
#endif
|
|
|
|
|
2009-09-18 09:21:47 +00:00
|
|
|
// DocumentModeHandler
|
|
|
|
/**
|
|
|
|
* Tree builder uses this to report quirkiness of the document
|
|
|
|
*/
|
|
|
|
void documentMode(nsHtml5DocumentMode m);
|
2009-09-21 11:43:43 +00:00
|
|
|
|
2011-11-01 11:33:11 +00:00
|
|
|
/**
|
|
|
|
* 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 the same mechanism in order
|
|
|
|
* to avoid having to have duplicate code paths for on-the-main-thread and
|
|
|
|
* off-the-main-thread tree builder instances.)
|
|
|
|
*/
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent** AllocateContentHandle();
|
2009-09-18 09:21:47 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void accumulateCharactersForced(const PRUnichar* aBuf, int32_t aStart, int32_t aLength)
|
2010-09-15 08:37:55 +00:00
|
|
|
{
|
|
|
|
accumulateCharacters(aBuf, aStart, aLength);
|
|
|
|
}
|
|
|
|
|
2009-09-21 11:43:43 +00:00
|
|
|
public:
|
|
|
|
|
2010-02-26 09:18:38 +00:00
|
|
|
nsHtml5TreeBuilder(nsAHtml5TreeOpSink* aOpSink,
|
|
|
|
nsHtml5TreeOpStage* aStage);
|
2009-09-21 11:43:43 +00:00
|
|
|
|
|
|
|
~nsHtml5TreeBuilder();
|
2009-09-18 09:21:47 +00:00
|
|
|
|
2011-11-30 17:44:31 +00:00
|
|
|
void StartPlainTextViewSource(const nsAutoString& aTitle);
|
|
|
|
|
2011-11-01 15:27:36 +00:00
|
|
|
void StartPlainText();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HasScript();
|
2009-09-18 09:21:47 +00:00
|
|
|
|
2009-09-21 13:18:20 +00:00
|
|
|
void SetOpSink(nsAHtml5TreeOpSink* aOpSink) {
|
|
|
|
mOpSink = aOpSink;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2009-10-30 11:47:17 +00:00
|
|
|
|
|
|
|
void ClearOps() {
|
|
|
|
mOpQueue.Clear();
|
|
|
|
}
|
2009-09-21 11:43:43 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Flush(bool aDiscretionary = false);
|
2009-09-21 13:18:20 +00:00
|
|
|
|
2010-02-26 09:18:38 +00:00
|
|
|
void FlushLoads();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetDocumentCharset(nsACString& aCharset, int32_t aCharsetSource);
|
2009-09-21 13:18:20 +00:00
|
|
|
|
|
|
|
void StreamEnded();
|
|
|
|
|
2012-03-24 11:34:42 +00:00
|
|
|
void NeedsCharsetSwitchTo(const nsACString& aEncoding,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aSource,
|
|
|
|
int32_t aLineNumber);
|
2012-03-24 11:34:42 +00:00
|
|
|
|
|
|
|
void MaybeComplainAboutCharset(const char* aMsgId,
|
|
|
|
bool aError,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aLineNumber);
|
2009-09-21 13:18:20 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void AddSnapshotToScript(nsAHtml5TreeBuilderState* aSnapshot, int32_t aLine);
|
2010-11-18 08:19:59 +00:00
|
|
|
|
|
|
|
void DropHandles();
|
2011-09-28 12:45:17 +00:00
|
|
|
|
2012-06-20 07:05:39 +00:00
|
|
|
void SetPreventScriptExecution(bool aPrevent) {
|
|
|
|
mPreventScriptExecution = aPrevent;
|
|
|
|
}
|
|
|
|
|
2011-11-01 11:33:11 +00:00
|
|
|
void EnableViewSource(nsHtml5Highlighter* aHighlighter);
|
|
|
|
|
|
|
|
void errStrayStartTag(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errStrayEndTag(nsIAtom* aName);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void errUnclosedElements(int32_t aIndex, nsIAtom* aName);
|
2011-11-01 11:33:11 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void errUnclosedElementsImplied(int32_t aIndex, nsIAtom* aName);
|
2011-11-01 11:33:11 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void errUnclosedElementsCell(int32_t aIndex);
|
2011-11-01 11:33:11 +00:00
|
|
|
|
|
|
|
void errStrayDoctype();
|
|
|
|
|
|
|
|
void errAlmostStandardsDoctype();
|
|
|
|
|
|
|
|
void errQuirkyDoctype();
|
|
|
|
|
|
|
|
void errNonSpaceInTrailer();
|
|
|
|
|
|
|
|
void errNonSpaceAfterFrameset();
|
|
|
|
|
|
|
|
void errNonSpaceInFrameset();
|
|
|
|
|
|
|
|
void errNonSpaceAfterBody();
|
|
|
|
|
|
|
|
void errNonSpaceInColgroupInFragment();
|
|
|
|
|
|
|
|
void errNonSpaceInNoscriptInHead();
|
|
|
|
|
|
|
|
void errFooBetweenHeadAndBody(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errStartTagWithoutDoctype();
|
|
|
|
|
|
|
|
void errNoSelectInTableScope();
|
|
|
|
|
|
|
|
void errStartSelectWhereEndSelectExpected();
|
|
|
|
|
|
|
|
void errStartTagWithSelectOpen(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errBadStartTagInHead(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errImage();
|
|
|
|
|
|
|
|
void errIsindex();
|
|
|
|
|
|
|
|
void errFooSeenWhenFooOpen(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errHeadingWhenHeadingOpen();
|
|
|
|
|
|
|
|
void errFramesetStart();
|
|
|
|
|
|
|
|
void errNoCellToClose();
|
|
|
|
|
|
|
|
void errStartTagInTable(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errFormWhenFormOpen();
|
|
|
|
|
|
|
|
void errTableSeenWhileTableOpen();
|
|
|
|
|
|
|
|
void errStartTagInTableBody(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errEndTagSeenWithoutDoctype();
|
|
|
|
|
|
|
|
void errEndTagAfterBody();
|
|
|
|
|
|
|
|
void errEndTagSeenWithSelectOpen(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errGarbageInColgroup();
|
|
|
|
|
|
|
|
void errEndTagBr();
|
|
|
|
|
|
|
|
void errNoElementToCloseButEndTagSeen(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errHtmlStartTagInForeignContext(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errTableClosedWhileCaptionOpen();
|
|
|
|
|
|
|
|
void errNoTableRowToClose();
|
|
|
|
|
|
|
|
void errNonSpaceInTable();
|
|
|
|
|
|
|
|
void errUnclosedChildrenInRuby();
|
|
|
|
|
|
|
|
void errStartTagSeenWithoutRuby(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errSelfClosing();
|
|
|
|
|
|
|
|
void errNoCheckUnclosedElementsOnStack();
|
|
|
|
|
|
|
|
void errEndTagDidNotMatchCurrentOpenElement(nsIAtom* aName, nsIAtom* aOther);
|
|
|
|
|
|
|
|
void errEndTagViolatesNestingRules(nsIAtom* aName);
|
|
|
|
|
|
|
|
void errEndWithUnclosedElements(nsIAtom* aName);
|
|
|
|
|
2011-09-28 12:45:17 +00:00
|
|
|
void MarkAsBroken();
|