2009-06-28 22:44:22 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
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
|
|
|
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2009-06-28 22:44:22 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsNodeUtils.h"
|
2012-03-23 15:21:44 +00:00
|
|
|
#include "nsIFrame.h"
|
2012-10-26 13:32:10 +00:00
|
|
|
#include "mozilla/Likely.h"
|
2010-05-20 09:03:11 +00:00
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsHtml5OplessBuilder* aBuilder)
|
|
|
|
: scriptingEnabled(false)
|
|
|
|
, fragment(false)
|
2014-09-30 12:29:48 +00:00
|
|
|
, contextName(nullptr)
|
|
|
|
, contextNamespace(kNameSpaceID_None)
|
2014-03-05 19:38:50 +00:00
|
|
|
, contextNode(nullptr)
|
|
|
|
, formPointer(nullptr)
|
|
|
|
, headPointer(nullptr)
|
|
|
|
, mBuilder(aBuilder)
|
|
|
|
, mViewSource(nullptr)
|
|
|
|
, mOpSink(nullptr)
|
|
|
|
, mHandles(nullptr)
|
|
|
|
, mHandlesUsed(0)
|
|
|
|
, mSpeculativeLoadStage(nullptr)
|
2015-08-25 15:05:45 +00:00
|
|
|
, mBroken(NS_OK)
|
2014-03-05 19:38:50 +00:00
|
|
|
, mCurrentHtmlScriptIsAsyncOrDefer(false)
|
|
|
|
, mPreventScriptExecution(false)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mActive(false)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsHtml5TreeBuilder);
|
|
|
|
}
|
|
|
|
|
2010-02-02 07:43:18 +00:00
|
|
|
nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsAHtml5TreeOpSink* aOpSink,
|
2010-02-26 09:18:38 +00:00
|
|
|
nsHtml5TreeOpStage* aStage)
|
2011-10-17 14:59:28 +00:00
|
|
|
: scriptingEnabled(false)
|
|
|
|
, fragment(false)
|
2014-09-30 12:29:48 +00:00
|
|
|
, contextName(nullptr)
|
|
|
|
, contextNamespace(kNameSpaceID_None)
|
2012-07-30 14:20:58 +00:00
|
|
|
, contextNode(nullptr)
|
|
|
|
, formPointer(nullptr)
|
|
|
|
, headPointer(nullptr)
|
2014-03-05 19:38:50 +00:00
|
|
|
, mBuilder(nullptr)
|
2012-07-30 14:20:58 +00:00
|
|
|
, mViewSource(nullptr)
|
2009-09-21 13:18:20 +00:00
|
|
|
, mOpSink(aOpSink)
|
2009-09-21 11:43:43 +00:00
|
|
|
, mHandles(new nsIContent*[NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH])
|
|
|
|
, mHandlesUsed(0)
|
2010-02-26 09:18:38 +00:00
|
|
|
, mSpeculativeLoadStage(aStage)
|
2015-08-25 15:05:45 +00:00
|
|
|
, mBroken(NS_OK)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mCurrentHtmlScriptIsAsyncOrDefer(false)
|
2012-06-20 07:05:39 +00:00
|
|
|
, mPreventScriptExecution(false)
|
2009-06-28 22:44:22 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-17 14:59:28 +00:00
|
|
|
, mActive(false)
|
2009-06-28 22:44:22 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsHtml5TreeBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5TreeBuilder::~nsHtml5TreeBuilder()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsHtml5TreeBuilder);
|
|
|
|
NS_ASSERTION(!mActive, "nsHtml5TreeBuilder deleted without ever calling end() on it!");
|
|
|
|
mOpQueue.Clear();
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle*
|
2014-11-10 06:50:18 +00:00
|
|
|
nsHtml5TreeBuilder::createElement(int32_t aNamespace, nsIAtom* aName,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
|
|
|
nsIContentHandle* aIntendedParent)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-12 13:08:04 +00:00
|
|
|
NS_PRECONDITION(aAttributes, "Got null attributes.");
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aName, "Got null name.");
|
|
|
|
NS_PRECONDITION(aNamespace == kNameSpaceID_XHTML ||
|
|
|
|
aNamespace == kNameSpaceID_SVG ||
|
|
|
|
aNamespace == kNameSpaceID_MathML,
|
|
|
|
"Bogus namespace.");
|
2009-10-28 13:48:37 +00:00
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsCOMPtr<nsIAtom> name = nsHtml5TreeOperation::Reget(aName);
|
2014-11-10 06:50:18 +00:00
|
|
|
|
|
|
|
nsIContent* intendedParent = aIntendedParent ?
|
|
|
|
static_cast<nsIContent*>(aIntendedParent) : nullptr;
|
|
|
|
|
|
|
|
// intendedParent == nullptr is a special case where the
|
|
|
|
// intended parent is the document.
|
|
|
|
nsNodeInfoManager* nodeInfoManager = intendedParent ?
|
|
|
|
intendedParent->OwnerDoc()->NodeInfoManager() :
|
|
|
|
mBuilder->GetNodeInfoManager();
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
nsIContent* elem =
|
|
|
|
nsHtml5TreeOperation::CreateElement(aNamespace,
|
|
|
|
name,
|
|
|
|
aAttributes,
|
|
|
|
mozilla::dom::FROM_PARSER_FRAGMENT,
|
2014-11-10 06:50:18 +00:00
|
|
|
nodeInfoManager,
|
2014-03-05 19:38:50 +00:00
|
|
|
mBuilder);
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(aAttributes != tokenizer->GetAttributes() &&
|
|
|
|
aAttributes != nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES)) {
|
2014-03-05 19:38:50 +00:00
|
|
|
delete aAttributes;
|
|
|
|
}
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle* content = AllocateContentHandle();
|
2009-10-28 13:48:37 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2010-06-09 06:44:25 +00:00
|
|
|
treeOp->Init(aNamespace,
|
|
|
|
aName,
|
|
|
|
aAttributes,
|
|
|
|
content,
|
2014-11-10 06:50:18 +00:00
|
|
|
aIntendedParent,
|
2010-06-09 06:44:25 +00:00
|
|
|
!!mSpeculativeLoadStage);
|
|
|
|
// mSpeculativeLoadStage is non-null only in the off-the-main-thread
|
|
|
|
// tree builder, which handles the network stream
|
2014-12-10 23:54:00 +00:00
|
|
|
|
2009-10-28 13:48:37 +00:00
|
|
|
// Start wall of code for speculative loading and line numbers
|
2014-12-10 23:54:00 +00:00
|
|
|
|
2010-02-26 09:18:38 +00:00
|
|
|
if (mSpeculativeLoadStage) {
|
2009-10-12 13:08:04 +00:00
|
|
|
switch (aNamespace) {
|
|
|
|
case kNameSpaceID_XHTML:
|
|
|
|
if (nsHtml5Atoms::img == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_SRC);
|
2014-12-10 23:54:00 +00:00
|
|
|
nsString* srcset =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_SRCSET);
|
|
|
|
nsString* crossOrigin =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN);
|
2015-06-05 22:25:24 +00:00
|
|
|
nsString* referrerPolicy =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_REFERRER);
|
2014-12-10 23:54:00 +00:00
|
|
|
nsString* sizes =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_SIZES);
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->
|
|
|
|
InitImage(url ? *url : NullString(),
|
|
|
|
crossOrigin ? *crossOrigin : NullString(),
|
2015-06-05 22:25:24 +00:00
|
|
|
referrerPolicy ? *referrerPolicy : NullString(),
|
2014-12-10 23:54:00 +00:00
|
|
|
srcset ? *srcset : NullString(),
|
|
|
|
sizes ? *sizes : NullString());
|
|
|
|
} else if (nsHtml5Atoms::source == aName) {
|
|
|
|
nsString* srcset =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_SRCSET);
|
|
|
|
// Sources without srcset cannot be selected. The source could also be
|
|
|
|
// for a media element, but in that context doesn't use srcset. See
|
|
|
|
// comments in nsHtml5SpeculativeLoad.h about <picture> preloading
|
|
|
|
if (srcset) {
|
|
|
|
nsString* sizes =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_SIZES);
|
|
|
|
nsString* type =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_TYPE);
|
|
|
|
nsString* media =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_MEDIA);
|
2012-03-10 16:13:52 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->
|
2014-12-10 23:54:00 +00:00
|
|
|
InitPictureSource(*srcset,
|
|
|
|
sizes ? *sizes : NullString(),
|
|
|
|
type ? *type : NullString(),
|
|
|
|
media ? *media : NullString());
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::script == aName) {
|
2009-10-28 13:48:37 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 08:52:30 +00:00
|
|
|
treeOp->Init(eTreeOpSetScriptLineNumberAndFreeze, content, tokenizer->getLineNumber());
|
2009-10-28 13:48:37 +00:00
|
|
|
|
2009-10-12 13:08:04 +00:00
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_SRC);
|
|
|
|
if (url) {
|
|
|
|
nsString* charset = aAttributes->getValue(nsHtml5AttributeName::ATTR_CHARSET);
|
|
|
|
nsString* type = aAttributes->getValue(nsHtml5AttributeName::ATTR_TYPE);
|
2012-03-10 16:13:52 +00:00
|
|
|
nsString* crossOrigin =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN);
|
2015-08-13 03:19:11 +00:00
|
|
|
nsString* integrity =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_INTEGRITY);
|
2012-03-10 16:13:52 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->
|
|
|
|
InitScript(*url,
|
|
|
|
(charset) ? *charset : EmptyString(),
|
|
|
|
(type) ? *type : EmptyString(),
|
2012-12-04 23:06:29 +00:00
|
|
|
(crossOrigin) ? *crossOrigin : NullString(),
|
2015-08-13 03:19:11 +00:00
|
|
|
(integrity) ? *integrity : NullString(),
|
2012-12-04 23:06:29 +00:00
|
|
|
mode == NS_HTML5TREE_BUILDER_IN_HEAD);
|
2014-12-10 23:54:00 +00:00
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer =
|
2009-11-17 08:52:30 +00:00
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_ASYNC) ||
|
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_DEFER);
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::link == aName) {
|
|
|
|
nsString* rel = aAttributes->getValue(nsHtml5AttributeName::ATTR_REL);
|
|
|
|
// Not splitting on space here is bogus but the old parser didn't even
|
|
|
|
// do a case-insensitive check.
|
2015-05-06 00:55:18 +00:00
|
|
|
if (rel) {
|
|
|
|
if (rel->LowerCaseEqualsASCII("stylesheet")) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
|
|
|
|
if (url) {
|
|
|
|
nsString* charset = aAttributes->getValue(nsHtml5AttributeName::ATTR_CHARSET);
|
|
|
|
nsString* crossOrigin =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN);
|
2015-08-13 03:19:11 +00:00
|
|
|
nsString* integrity =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_INTEGRITY);
|
2015-05-06 00:55:18 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->
|
|
|
|
InitStyle(*url,
|
|
|
|
(charset) ? *charset : EmptyString(),
|
2015-08-13 03:19:11 +00:00
|
|
|
(crossOrigin) ? *crossOrigin : NullString(),
|
|
|
|
(integrity) ? *integrity : NullString());
|
2015-05-06 00:55:18 +00:00
|
|
|
}
|
|
|
|
} else if (rel->LowerCaseEqualsASCII("preconnect")) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
|
|
|
|
if (url) {
|
2015-06-19 21:11:42 +00:00
|
|
|
nsString* crossOrigin =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN);
|
2015-05-06 00:55:18 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->
|
2015-06-19 21:11:42 +00:00
|
|
|
InitPreconnect(*url, (crossOrigin) ? *crossOrigin : NullString());
|
2015-05-06 00:55:18 +00:00
|
|
|
}
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::video == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_POSTER);
|
|
|
|
if (url) {
|
2014-12-10 23:54:00 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitImage(*url, NullString(),
|
2015-06-05 22:25:24 +00:00
|
|
|
NullString(),
|
2014-12-10 23:54:00 +00:00
|
|
|
NullString(),
|
|
|
|
NullString());
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
2009-10-28 13:48:37 +00:00
|
|
|
} else if (nsHtml5Atoms::style == aName) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-28 13:48:37 +00:00
|
|
|
treeOp->Init(eTreeOpSetStyleLineNumber, content, tokenizer->getLineNumber());
|
2010-02-02 07:43:18 +00:00
|
|
|
} else if (nsHtml5Atoms::html == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_MANIFEST);
|
|
|
|
if (url) {
|
2010-02-26 09:18:38 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitManifest(*url);
|
2011-05-13 08:31:12 +00:00
|
|
|
} else {
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitManifest(EmptyString());
|
2010-02-02 07:43:18 +00:00
|
|
|
}
|
2011-01-03 16:18:23 +00:00
|
|
|
} else if (nsHtml5Atoms::base == aName) {
|
2010-07-26 11:18:43 +00:00
|
|
|
nsString* url =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
|
|
|
|
if (url) {
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitBase(*url);
|
|
|
|
}
|
2014-11-18 13:46:29 +00:00
|
|
|
} else if (nsHtml5Atoms::meta == aName) {
|
|
|
|
if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString(
|
|
|
|
"referrer",
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_NAME))) {
|
|
|
|
nsString* referrerPolicy = aAttributes->getValue(nsHtml5AttributeName::ATTR_CONTENT);
|
|
|
|
if (referrerPolicy) {
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitMetaReferrerPolicy(*referrerPolicy);
|
|
|
|
}
|
|
|
|
}
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kNameSpaceID_SVG:
|
|
|
|
if (nsHtml5Atoms::image == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_XLINK_HREF);
|
|
|
|
if (url) {
|
2014-12-10 23:54:00 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitImage(*url, NullString(),
|
2015-06-05 22:25:24 +00:00
|
|
|
NullString(),
|
2014-12-10 23:54:00 +00:00
|
|
|
NullString(),
|
|
|
|
NullString());
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::script == aName) {
|
2009-10-28 13:48:37 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 08:52:30 +00:00
|
|
|
treeOp->Init(eTreeOpSetScriptLineNumberAndFreeze, content, tokenizer->getLineNumber());
|
2009-10-28 13:48:37 +00:00
|
|
|
|
2009-10-12 13:08:04 +00:00
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_XLINK_HREF);
|
|
|
|
if (url) {
|
|
|
|
nsString* type = aAttributes->getValue(nsHtml5AttributeName::ATTR_TYPE);
|
2012-03-10 16:13:52 +00:00
|
|
|
nsString* crossOrigin =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN);
|
2015-08-13 03:19:11 +00:00
|
|
|
nsString* integrity =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_INTEGRITY);
|
2012-03-10 16:13:52 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->
|
|
|
|
InitScript(*url,
|
|
|
|
EmptyString(),
|
|
|
|
(type) ? *type : EmptyString(),
|
2012-12-04 23:06:29 +00:00
|
|
|
(crossOrigin) ? *crossOrigin : NullString(),
|
2015-08-13 03:19:11 +00:00
|
|
|
(integrity) ? *integrity : NullString(),
|
2012-12-04 23:06:29 +00:00
|
|
|
mode == NS_HTML5TREE_BUILDER_IN_HEAD);
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::style == aName) {
|
2009-10-28 13:48:37 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-28 13:48:37 +00:00
|
|
|
treeOp->Init(eTreeOpSetStyleLineNumber, content, tokenizer->getLineNumber());
|
|
|
|
|
2009-10-12 13:08:04 +00:00
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_XLINK_HREF);
|
|
|
|
if (url) {
|
2012-08-28 17:10:08 +00:00
|
|
|
nsString* crossOrigin =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN);
|
2015-08-13 03:19:11 +00:00
|
|
|
nsString* integrity =
|
|
|
|
aAttributes->getValue(nsHtml5AttributeName::ATTR_INTEGRITY);
|
2012-08-28 17:10:08 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->
|
|
|
|
InitStyle(*url, EmptyString(),
|
2015-08-13 03:19:11 +00:00
|
|
|
(crossOrigin) ? *crossOrigin : NullString(),
|
|
|
|
(integrity) ? *integrity : NullString());
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
2014-12-10 23:54:00 +00:00
|
|
|
}
|
2009-10-12 13:08:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-10-28 13:48:37 +00:00
|
|
|
} else if (aNamespace != kNameSpaceID_MathML) {
|
2009-11-17 08:52:30 +00:00
|
|
|
// No speculative loader--just line numbers and defer/async check
|
2009-10-28 13:48:37 +00:00
|
|
|
if (nsHtml5Atoms::style == aName) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-28 13:48:37 +00:00
|
|
|
treeOp->Init(eTreeOpSetStyleLineNumber, content, tokenizer->getLineNumber());
|
|
|
|
} else if (nsHtml5Atoms::script == aName) {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 08:52:30 +00:00
|
|
|
treeOp->Init(eTreeOpSetScriptLineNumberAndFreeze, content, tokenizer->getLineNumber());
|
2009-11-17 08:52:30 +00:00
|
|
|
if (aNamespace == kNameSpaceID_XHTML) {
|
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer =
|
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_SRC) &&
|
|
|
|
(aAttributes->contains(nsHtml5AttributeName::ATTR_ASYNC) ||
|
|
|
|
aAttributes->contains(nsHtml5AttributeName::ATTR_DEFER));
|
|
|
|
}
|
2014-09-30 09:35:17 +00:00
|
|
|
} else if (aNamespace == kNameSpaceID_XHTML) {
|
|
|
|
if (nsHtml5Atoms::html == aName) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_MANIFEST);
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
if (url) {
|
|
|
|
treeOp->Init(eTreeOpProcessOfflineManifest, *url);
|
|
|
|
} else {
|
|
|
|
treeOp->Init(eTreeOpProcessOfflineManifest, EmptyString());
|
|
|
|
}
|
|
|
|
} else if (nsHtml5Atoms::base == aName && mViewSource) {
|
|
|
|
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
|
|
|
|
if (url) {
|
|
|
|
mViewSource->AddBase(*url);
|
|
|
|
}
|
2010-02-02 07:43:18 +00:00
|
|
|
}
|
2009-10-28 13:48:37 +00:00
|
|
|
}
|
2009-10-12 13:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// End wall of code for speculative loading
|
|
|
|
|
2009-09-21 11:43:43 +00:00
|
|
|
return content;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle*
|
2014-11-10 06:50:18 +00:00
|
|
|
nsHtml5TreeBuilder::createElement(int32_t aNamespace, nsIAtom* aName,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
|
|
|
nsIContentHandle* aFormElement,
|
|
|
|
nsIContentHandle* aIntendedParent)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2014-11-10 06:50:18 +00:00
|
|
|
nsIContentHandle* content = createElement(aNamespace, aName, aAttributes,
|
|
|
|
aIntendedParent);
|
2009-06-28 22:44:22 +00:00
|
|
|
if (aFormElement) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsHtml5TreeOperation::SetFormElement(static_cast<nsIContent*>(content),
|
|
|
|
static_cast<nsIContent*>(aFormElement));
|
|
|
|
} else {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpSetFormElement, content, aFormElement);
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle*
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeBuilder::createHtmlElementSetAsRoot(nsHtml5HtmlAttributes* aAttributes)
|
|
|
|
{
|
2014-11-10 06:50:18 +00:00
|
|
|
nsIContentHandle* content = createElement(kNameSpaceID_XHTML,
|
|
|
|
nsHtml5Atoms::html,
|
|
|
|
aAttributes,
|
|
|
|
nullptr);
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::AppendToDocument(static_cast<nsIContent*>(content),
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpAppendToDocument, content);
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
2014-11-10 06:50:18 +00:00
|
|
|
nsIContentHandle*
|
|
|
|
nsHtml5TreeBuilder::createAndInsertFosterParentedElement(int32_t aNamespace, nsIAtom* aName,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
|
|
|
nsIContentHandle* aFormElement,
|
|
|
|
nsIContentHandle* aTable,
|
|
|
|
nsIContentHandle* aStackParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aTable, "Null table");
|
|
|
|
NS_PRECONDITION(aStackParent, "Null stack parent");
|
|
|
|
|
|
|
|
if (mBuilder) {
|
|
|
|
// Get the foster parent to use as the intended parent when creating
|
|
|
|
// the child element.
|
|
|
|
nsIContent* fosterParent = nsHtml5TreeOperation::GetFosterParent(
|
|
|
|
static_cast<nsIContent*>(aTable),
|
|
|
|
static_cast<nsIContent*>(aStackParent));
|
|
|
|
|
|
|
|
nsIContentHandle* child = createElement(aNamespace, aName, aAttributes,
|
|
|
|
aFormElement, fosterParent);
|
|
|
|
|
|
|
|
insertFosterParentedChild(child, aTable, aStackParent);
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tree op to get the foster parent that we use as the intended parent
|
|
|
|
// when creating the child element.
|
|
|
|
nsHtml5TreeOperation* fosterParentTreeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(fosterParentTreeOp, "Tree op allocation failed.");
|
|
|
|
nsIContentHandle* fosterParentHandle = AllocateContentHandle();
|
|
|
|
fosterParentTreeOp->Init(eTreeOpGetFosterParent, aTable,
|
|
|
|
aStackParent, fosterParentHandle);
|
|
|
|
|
|
|
|
// Create the element with the correct intended parent.
|
|
|
|
nsIContentHandle* child = createElement(aNamespace, aName, aAttributes,
|
|
|
|
aFormElement, fosterParentHandle);
|
|
|
|
|
|
|
|
// Insert the child into the foster parent.
|
|
|
|
insertFosterParentedChild(child, aTable, aStackParent);
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::detachFromParent(nsIContentHandle* aElement)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aElement, "Null element");
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsHtml5TreeOperation::Detach(static_cast<nsIContent*>(aElement),
|
|
|
|
mBuilder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 22:44:22 +00:00
|
|
|
treeOp->Init(eTreeOpDetach, aElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::appendElement(nsIContentHandle* aChild, nsIContentHandle* aParent)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aChild, "Null child");
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
2010-09-06 07:41:26 +00:00
|
|
|
if (deepTreeSurrogateParent) {
|
2010-05-20 09:03:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-03-05 19:38:50 +00:00
|
|
|
|
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::Append(static_cast<nsIContent*>(aChild),
|
|
|
|
static_cast<nsIContent*>(aParent),
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-21 13:18:20 +00:00
|
|
|
treeOp->Init(eTreeOpAppend, aChild, aParent);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::appendChildrenToNewParent(nsIContentHandle* aOldParent, nsIContentHandle* aNewParent)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aOldParent, "Null old parent");
|
|
|
|
NS_PRECONDITION(aNewParent, "Null new parent");
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::AppendChildrenToNewParent(
|
|
|
|
static_cast<nsIContent*>(aOldParent),
|
|
|
|
static_cast<nsIContent*>(aNewParent),
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 22:44:22 +00:00
|
|
|
treeOp->Init(eTreeOpAppendChildrenToNewParent, aOldParent, aNewParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::insertFosterParentedCharacters(char16_t* aBuffer, int32_t aStart, int32_t aLength, nsIContentHandle* aTable, nsIContentHandle* aStackParent)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
NS_PRECONDITION(aTable, "Null table");
|
|
|
|
NS_PRECONDITION(aStackParent, "Null stack parent");
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!aStart, "aStart must always be zero.");
|
|
|
|
|
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::FosterParentText(
|
|
|
|
static_cast<nsIContent*>(aStackParent),
|
|
|
|
aBuffer, // XXX aStart always ignored???
|
|
|
|
aLength,
|
|
|
|
static_cast<nsIContent*>(aTable),
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-10-30 11:47:17 +00:00
|
|
|
|
2015-08-25 15:05:46 +00:00
|
|
|
char16_t* bufferCopy = new (mozilla::fallible) char16_t[aLength];
|
|
|
|
if (!bufferCopy) {
|
|
|
|
// Just assigning mBroken instead of generating tree op. The caller
|
|
|
|
// of tokenizeBuffer() will call MarkAsBroken() as appropriate.
|
|
|
|
mBroken = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
requestSuspension();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(char16_t));
|
2009-09-21 11:43:43 +00:00
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 08:52:30 +00:00
|
|
|
treeOp->Init(eTreeOpFosterParentText, bufferCopy, aLength, aStackParent, aTable);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::insertFosterParentedChild(nsIContentHandle* aChild, nsIContentHandle* aTable, nsIContentHandle* aStackParent)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aChild, "Null child");
|
|
|
|
NS_PRECONDITION(aTable, "Null table");
|
|
|
|
NS_PRECONDITION(aStackParent, "Null stack parent");
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::FosterParent(
|
|
|
|
static_cast<nsIContent*>(aChild),
|
|
|
|
static_cast<nsIContent*>(aStackParent),
|
|
|
|
static_cast<nsIContent*>(aTable),
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 22:44:22 +00:00
|
|
|
treeOp->Init(eTreeOpFosterParent, aChild, aStackParent, aTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::appendCharacters(nsIContentHandle* aParent, char16_t* aBuffer, int32_t aStart, int32_t aLength)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!aStart, "aStart must always be zero.");
|
|
|
|
|
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::AppendText(
|
|
|
|
aBuffer, // XXX aStart always ignored???
|
|
|
|
aLength,
|
|
|
|
static_cast<nsIContent*>(deepTreeSurrogateParent ?
|
|
|
|
deepTreeSurrogateParent : aParent),
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-10-30 11:47:17 +00:00
|
|
|
|
2015-08-25 15:05:46 +00:00
|
|
|
char16_t* bufferCopy = new (mozilla::fallible) char16_t[aLength];
|
|
|
|
if (!bufferCopy) {
|
|
|
|
// Just assigning mBroken instead of generating tree op. The caller
|
|
|
|
// of tokenizeBuffer() will call MarkAsBroken() as appropriate.
|
|
|
|
mBroken = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
requestSuspension();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(char16_t));
|
2009-09-21 11:43:43 +00:00
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2010-05-20 09:03:11 +00:00
|
|
|
treeOp->Init(eTreeOpAppendText, bufferCopy, aLength,
|
2010-09-06 07:41:26 +00:00
|
|
|
deepTreeSurrogateParent ? deepTreeSurrogateParent : aParent);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 15:08:13 +00:00
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::appendIsindexPrompt(nsIContentHandle* aParent)
|
2010-06-11 15:08:13 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::AppendIsindexPrompt(
|
|
|
|
static_cast<nsIContent*>(aParent),
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-11 15:08:13 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpAppendIsindexPrompt, aParent);
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::appendComment(nsIContentHandle* aParent, char16_t* aBuffer, int32_t aStart, int32_t aLength)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
NS_PRECONDITION(aParent, "Null parent");
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!aStart, "aStart must always be zero.");
|
|
|
|
|
2010-09-06 07:41:26 +00:00
|
|
|
if (deepTreeSurrogateParent) {
|
2010-05-20 09:03:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-30 11:47:17 +00:00
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::AppendComment(
|
|
|
|
static_cast<nsIContent*>(aParent),
|
|
|
|
aBuffer, // XXX aStart always ignored???
|
|
|
|
aLength,
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-25 15:05:46 +00:00
|
|
|
char16_t* bufferCopy = new (mozilla::fallible) char16_t[aLength];
|
|
|
|
if (!bufferCopy) {
|
|
|
|
// Just assigning mBroken instead of generating tree op. The caller
|
|
|
|
// of tokenizeBuffer() will call MarkAsBroken() as appropriate.
|
|
|
|
mBroken = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
requestSuspension();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(char16_t));
|
2009-09-21 11:43:43 +00:00
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 08:52:30 +00:00
|
|
|
treeOp->Init(eTreeOpAppendComment, bufferCopy, aLength, aParent);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 15:02:17 +00:00
|
|
|
nsHtml5TreeBuilder::appendCommentToDocument(char16_t* aBuffer, int32_t aStart, int32_t aLength)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!aStart, "aStart must always be zero.");
|
|
|
|
|
|
|
|
if (mBuilder) {
|
|
|
|
nsresult rv = nsHtml5TreeOperation::AppendCommentToDocument(
|
|
|
|
aBuffer, // XXX aStart always ignored???
|
|
|
|
aLength,
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-10-30 11:47:17 +00:00
|
|
|
|
2015-08-25 15:05:46 +00:00
|
|
|
char16_t* bufferCopy = new (mozilla::fallible) char16_t[aLength];
|
|
|
|
if (!bufferCopy) {
|
|
|
|
// Just assigning mBroken instead of generating tree op. The caller
|
|
|
|
// of tokenizeBuffer() will call MarkAsBroken() as appropriate.
|
|
|
|
mBroken = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
requestSuspension();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
memcpy(bufferCopy, aBuffer, aLength * sizeof(char16_t));
|
2009-09-21 11:43:43 +00:00
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 08:52:30 +00:00
|
|
|
treeOp->Init(eTreeOpAppendCommentToDocument, bufferCopy, aLength);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::addAttributesToElement(nsIContentHandle* aElement, nsHtml5HtmlAttributes* aAttributes)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aElement, "Null element");
|
|
|
|
NS_PRECONDITION(aAttributes, "Null attributes");
|
|
|
|
|
2009-09-21 11:43:43 +00:00
|
|
|
if (aAttributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-05 19:38:50 +00:00
|
|
|
|
|
|
|
if (mBuilder) {
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(aAttributes == tokenizer->GetAttributes(),
|
|
|
|
"Using attribute other than the tokenizer's to add to body or html.");
|
2014-03-05 19:38:50 +00:00
|
|
|
nsresult rv = nsHtml5TreeOperation::AddAttributes(
|
|
|
|
static_cast<nsIContent*>(aElement),
|
|
|
|
aAttributes,
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-21 11:43:43 +00:00
|
|
|
treeOp->Init(aElement, aAttributes);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::markMalformedIfScript(nsIContentHandle* aElement)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aElement, "Null element");
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
2014-03-05 19:38:50 +00:00
|
|
|
nsHtml5TreeOperation::MarkMalformedIfScript(
|
|
|
|
static_cast<nsIContent*>(aElement));
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-21 11:43:43 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpMarkMalformedIfScript, aElement);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHtml5TreeBuilder::start(bool fragment)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer = false;
|
2012-07-30 14:20:58 +00:00
|
|
|
deepTreeSurrogateParent = nullptr;
|
2009-06-28 22:44:22 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-17 14:59:28 +00:00
|
|
|
mActive = true;
|
2009-06-28 22:44:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::end()
|
|
|
|
{
|
2009-08-27 07:57:57 +00:00
|
|
|
mOpQueue.Clear();
|
2009-06-28 22:44:22 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-17 14:59:28 +00:00
|
|
|
mActive = false;
|
2009-06-28 22:44:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::appendDoctypeToDocument(nsIAtom* aName, nsString* aPublicId, nsString* aSystemId)
|
|
|
|
{
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_PRECONDITION(aName, "Null name");
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsCOMPtr<nsIAtom> name = nsHtml5TreeOperation::Reget(aName);
|
|
|
|
nsresult rv =
|
|
|
|
nsHtml5TreeOperation::AppendDoctypeToDocument(name,
|
|
|
|
*aPublicId,
|
|
|
|
*aSystemId,
|
|
|
|
mBuilder);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(rv);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-11-17 08:52:30 +00:00
|
|
|
treeOp->Init(aName, *aPublicId, *aSystemId);
|
2009-06-28 22:44:22 +00:00
|
|
|
// nsXMLContentSink can flush here, but what's the point?
|
|
|
|
// It can also interrupt here, but we can't.
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::elementPushed(int32_t aNamespace, nsIAtom* aName, nsIContentHandle* aElement)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2010-02-22 12:17:33 +00:00
|
|
|
NS_ASSERTION(aNamespace == kNameSpaceID_XHTML || aNamespace == kNameSpaceID_SVG || aNamespace == kNameSpaceID_MathML, "Element isn't HTML, SVG or MathML!");
|
|
|
|
NS_ASSERTION(aName, "Element doesn't have local name!");
|
|
|
|
NS_ASSERTION(aElement, "No element!");
|
2010-05-20 09:03:11 +00:00
|
|
|
/*
|
|
|
|
* The frame constructor uses recursive algorithms, so it can't deal with
|
|
|
|
* arbitrarily deep trees. This is especially a problem on Windows where
|
|
|
|
* the permitted depth of the runtime stack is rather small.
|
|
|
|
*
|
|
|
|
* The following is a protection against author incompetence--not against
|
|
|
|
* malice. There are other ways to make the DOM deep anyway.
|
|
|
|
*
|
|
|
|
* The basic idea is that when the tree builder stack gets too deep,
|
|
|
|
* append operations no longer append to the node that the HTML parsing
|
|
|
|
* algorithm says they should but instead text nodes are append to the last
|
|
|
|
* element that was seen before a magic tree builder stack threshold was
|
|
|
|
* reached and element and comment nodes aren't appended to the DOM at all.
|
|
|
|
*
|
|
|
|
* However, for security reasons, non-child descendant text nodes inside an
|
|
|
|
* SVG script or style element should not become children. Also, non-cell
|
|
|
|
* table elements shouldn't be used as surrogate parents for user experience
|
|
|
|
* reasons.
|
|
|
|
*/
|
2012-03-23 15:21:44 +00:00
|
|
|
if (!deepTreeSurrogateParent && currentPtr >= MAX_REFLOW_DEPTH &&
|
2010-05-20 09:03:11 +00:00
|
|
|
!(aName == nsHtml5Atoms::script ||
|
|
|
|
aName == nsHtml5Atoms::table ||
|
|
|
|
aName == nsHtml5Atoms::thead ||
|
|
|
|
aName == nsHtml5Atoms::tfoot ||
|
|
|
|
aName == nsHtml5Atoms::tbody ||
|
|
|
|
aName == nsHtml5Atoms::tr ||
|
|
|
|
aName == nsHtml5Atoms::colgroup ||
|
|
|
|
aName == nsHtml5Atoms::style)) {
|
2010-09-06 07:41:26 +00:00
|
|
|
deepTreeSurrogateParent = aElement;
|
2010-05-20 09:03:11 +00:00
|
|
|
}
|
2010-02-22 12:17:33 +00:00
|
|
|
if (aNamespace != kNameSpaceID_XHTML) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::body || aName == nsHtml5Atoms::frameset) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
// InnerHTML and DOMParser shouldn't start layout anyway
|
|
|
|
return;
|
|
|
|
}
|
2010-02-22 12:17:33 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpStartLayout);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-03 13:32:31 +00:00
|
|
|
if (aName == nsHtml5Atoms::input ||
|
|
|
|
aName == nsHtml5Atoms::button) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsHtml5TreeOperation::DoneCreatingElement(static_cast<nsIContent*>(aElement));
|
|
|
|
} else {
|
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpDoneCreatingElement, aElement);
|
2012-02-03 13:32:31 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::audio ||
|
|
|
|
aName == nsHtml5Atoms::video ||
|
|
|
|
aName == nsHtml5Atoms::menuitem) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsHtml5TreeOperation::DoneCreatingElement(static_cast<nsIContent*>(aElement));
|
|
|
|
} else {
|
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpDoneCreatingElement, aElement);
|
|
|
|
}
|
2012-02-03 13:32:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-12-10 23:54:00 +00:00
|
|
|
if (mSpeculativeLoadStage && aName == nsHtml5Atoms::picture) {
|
|
|
|
// mSpeculativeLoadStage is non-null only in the off-the-main-thread
|
|
|
|
// tree builder, which handles the network stream
|
|
|
|
//
|
|
|
|
// See comments in nsHtml5SpeculativeLoad.h about <picture> preloading
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitOpenPicture();
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeBuilder::elementPopped(int32_t aNamespace, nsIAtom* aName, nsIContentHandle* aElement)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNamespace == kNameSpaceID_XHTML || aNamespace == kNameSpaceID_SVG || aNamespace == kNameSpaceID_MathML, "Element isn't HTML, SVG or MathML!");
|
|
|
|
NS_ASSERTION(aName, "Element doesn't have local name!");
|
|
|
|
NS_ASSERTION(aElement, "No element!");
|
2012-03-23 15:21:44 +00:00
|
|
|
if (deepTreeSurrogateParent && currentPtr <= MAX_REFLOW_DEPTH) {
|
2012-07-30 14:20:58 +00:00
|
|
|
deepTreeSurrogateParent = nullptr;
|
2010-05-20 09:03:11 +00:00
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
if (aNamespace == kNameSpaceID_MathML) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we now have only SVG and HTML
|
|
|
|
if (aName == nsHtml5Atoms::script) {
|
2012-06-20 07:05:39 +00:00
|
|
|
if (mPreventScriptExecution) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsHtml5TreeOperation::PreventScriptExecution(static_cast<nsIContent*>(aElement));
|
|
|
|
return;
|
|
|
|
}
|
2012-06-20 07:05:39 +00:00
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpPreventScriptExecution, aElement);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
return;
|
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
if (mCurrentHtmlScriptIsAsyncOrDefer) {
|
|
|
|
NS_ASSERTION(aNamespace == kNameSpaceID_XHTML,
|
|
|
|
"Only HTML scripts may be async/defer.");
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpRunScriptAsyncDefer, aElement);
|
2011-10-17 14:59:28 +00:00
|
|
|
mCurrentHtmlScriptIsAsyncOrDefer = false;
|
2009-11-17 08:52:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
requestSuspension();
|
2009-09-21 11:43:43 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-10-12 13:08:04 +00:00
|
|
|
treeOp->InitScript(aElement);
|
2009-06-28 22:44:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::title) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
2014-06-16 23:01:22 +00:00
|
|
|
nsHtml5TreeOperation::DoneAddingChildren(static_cast<nsIContent*>(aElement));
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 22:44:22 +00:00
|
|
|
treeOp->Init(eTreeOpDoneAddingChildren, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aName == nsHtml5Atoms::style || (aNamespace == kNameSpaceID_XHTML && aName == nsHtml5Atoms::link)) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Scripts must be blocked.");
|
|
|
|
mBuilder->UpdateStyleSheet(static_cast<nsIContent*>(aElement));
|
|
|
|
return;
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 22:44:22 +00:00
|
|
|
treeOp->Init(eTreeOpUpdateStyleSheet, aElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aNamespace == kNameSpaceID_SVG) {
|
2010-07-18 22:07:54 +00:00
|
|
|
if (aName == nsHtml5Atoms::svg) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
nsHtml5TreeOperation::SvgLoad(static_cast<nsIContent*>(aElement));
|
|
|
|
return;
|
|
|
|
}
|
2010-07-18 22:07:54 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpSvgLoad, aElement);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we now have only HTML
|
|
|
|
// Some HTML nodes need DoneAddingChildren() called to initialize
|
2009-07-15 11:30:33 +00:00
|
|
|
// properly (e.g. form state restoration).
|
2009-06-28 22:44:22 +00:00
|
|
|
// XXX expose ElementName group here and do switch
|
2010-09-03 00:03:03 +00:00
|
|
|
if (aName == nsHtml5Atoms::object ||
|
2014-06-16 23:01:22 +00:00
|
|
|
aName == nsHtml5Atoms::applet ||
|
|
|
|
aName == nsHtml5Atoms::select ||
|
|
|
|
aName == nsHtml5Atoms::textarea ||
|
|
|
|
aName == nsHtml5Atoms::output) {
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
2014-06-16 23:01:22 +00:00
|
|
|
nsHtml5TreeOperation::DoneAddingChildren(static_cast<nsIContent*>(aElement));
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
2010-01-20 13:43:58 +00:00
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 22:44:22 +00:00
|
|
|
treeOp->Init(eTreeOpDoneAddingChildren, aElement);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-05 19:38:50 +00:00
|
|
|
if (aName == nsHtml5Atoms::meta && !fragment && !mBuilder) {
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-06-28 22:44:22 +00:00
|
|
|
treeOp->Init(eTreeOpProcessMeta, aElement);
|
|
|
|
return;
|
|
|
|
}
|
2014-12-10 23:54:00 +00:00
|
|
|
if (mSpeculativeLoadStage && aName == nsHtml5Atoms::picture) {
|
|
|
|
// mSpeculativeLoadStage is non-null only in the off-the-main-thread
|
|
|
|
// tree builder, which handles the network stream
|
|
|
|
//
|
|
|
|
// See comments in nsHtml5SpeculativeLoad.h about <picture> preloading
|
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitEndPicture();
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 15:02:17 +00:00
|
|
|
nsHtml5TreeBuilder::accumulateCharacters(const char16_t* aBuf, int32_t aStart, int32_t aLength)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2015-08-25 15:05:45 +00:00
|
|
|
MOZ_ASSERT(charBufferLen + aLength <= charBuffer.length,
|
|
|
|
"About to memcpy past the end of the buffer!");
|
|
|
|
memcpy(charBuffer + charBufferLen, aBuf + aStart, sizeof(char16_t) * aLength);
|
|
|
|
charBufferLen += aLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHtml5TreeBuilder::EnsureBufferSpace(size_t aLength)
|
|
|
|
{
|
|
|
|
// TODO: Unify nsHtml5Tokenizer::strBuf and nsHtml5TreeBuilder::charBuffer
|
|
|
|
// so that this method becomes unnecessary.
|
|
|
|
size_t worstCase = size_t(charBufferLen) + aLength;
|
|
|
|
if (worstCase > INT32_MAX) {
|
|
|
|
// Since we index into the buffer using int32_t due to the Java heritage
|
|
|
|
// of the code, let's treat this as OOM.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!charBuffer) {
|
|
|
|
// Add one to round to the next power of two to avoid immediate
|
|
|
|
// reallocation once there are a few characters in the buffer.
|
|
|
|
charBuffer = jArray<char16_t,int32_t>::newFallibleJArray(mozilla::RoundUpPow2(worstCase + 1));
|
|
|
|
if (!charBuffer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (worstCase > size_t(charBuffer.length)) {
|
|
|
|
jArray<char16_t,int32_t> newBuf = jArray<char16_t,int32_t>::newFallibleJArray(mozilla::RoundUpPow2(worstCase));
|
|
|
|
if (!newBuf) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-04 15:02:17 +00:00
|
|
|
memcpy(newBuf, charBuffer, sizeof(char16_t) * charBufferLen);
|
2010-03-30 08:21:36 +00:00
|
|
|
charBuffer = newBuf;
|
|
|
|
}
|
2015-08-25 15:05:45 +00:00
|
|
|
return true;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle*
|
2009-09-21 11:43:43 +00:00
|
|
|
nsHtml5TreeBuilder::AllocateContentHandle()
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(mBuilder)) {
|
2014-04-29 03:28:54 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Must never allocate a handle with builder.");
|
2014-03-05 19:38:50 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2009-09-21 11:43:43 +00:00
|
|
|
if (mHandlesUsed == NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH) {
|
|
|
|
mOldHandles.AppendElement(mHandles.forget());
|
|
|
|
mHandles = new nsIContent*[NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH];
|
|
|
|
mHandlesUsed = 0;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2009-10-30 11:47:17 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mHandles[mHandlesUsed] = (nsIContent*)0xC0DEDBAD;
|
|
|
|
#endif
|
2009-09-21 11:43:43 +00:00
|
|
|
return &mHandles[mHandlesUsed++];
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-09-21 11:43:43 +00:00
|
|
|
nsHtml5TreeBuilder::HasScript()
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t len = mOpQueue.Length();
|
2009-09-21 11:43:43 +00:00
|
|
|
if (!len) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2009-09-21 11:43:43 +00:00
|
|
|
return mOpQueue.ElementAt(len - 1).IsRunScript();
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
|
|
|
nsHtml5TreeBuilder::Flush(bool aDiscretionary)
|
2011-05-19 08:42:01 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(mBuilder)) {
|
2014-04-29 03:28:54 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Must never flush with builder.");
|
2014-03-05 19:38:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-25 15:05:46 +00:00
|
|
|
if (NS_SUCCEEDED(mBroken)) {
|
|
|
|
if (!aDiscretionary ||
|
|
|
|
!(charBufferLen &&
|
|
|
|
currentPtr >= 0 &&
|
|
|
|
stack[currentPtr]->isFosterParenting())) {
|
|
|
|
// Don't flush text on discretionary flushes if the current element on
|
|
|
|
// the stack is a foster-parenting element and there's pending text,
|
|
|
|
// because flushing in that case would make the tree shape dependent on
|
|
|
|
// where the flush points fall.
|
|
|
|
flushCharacters();
|
|
|
|
}
|
|
|
|
FlushLoads();
|
2011-05-19 08:42:01 +00:00
|
|
|
}
|
2010-11-18 08:23:48 +00:00
|
|
|
if (mOpSink) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasOps = !mOpQueue.IsEmpty();
|
2010-11-18 08:23:48 +00:00
|
|
|
if (hasOps) {
|
2015-08-25 15:05:46 +00:00
|
|
|
// If the builder is broken and mOpQueue is not empty, there must be
|
|
|
|
// one op and it must be eTreeOpMarkAsBroken.
|
|
|
|
if (NS_FAILED(mBroken)) {
|
|
|
|
MOZ_ASSERT(mOpQueue.Length() == 1,
|
|
|
|
"Tree builder is broken with a non-empty op queue whose length isn't 1.");
|
|
|
|
MOZ_ASSERT(mOpQueue[0].IsMarkAsBroken(),
|
|
|
|
"Tree builder is broken but the op in queue is not marked as broken.");
|
|
|
|
}
|
2010-11-18 08:23:48 +00:00
|
|
|
mOpSink->MoveOpsFrom(mOpQueue);
|
|
|
|
}
|
|
|
|
return hasOps;
|
2009-11-17 08:52:30 +00:00
|
|
|
}
|
2010-11-18 08:23:48 +00:00
|
|
|
// no op sink: throw away ops
|
|
|
|
mOpQueue.Clear();
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 09:18:38 +00:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::FlushLoads()
|
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(mBuilder)) {
|
2014-04-29 03:28:54 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Must never flush loads with builder.");
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-26 09:18:38 +00:00
|
|
|
if (!mSpeculativeLoadQueue.IsEmpty()) {
|
|
|
|
mSpeculativeLoadStage->MoveSpeculativeLoadsFrom(mSpeculativeLoadQueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-21 13:18:20 +00:00
|
|
|
void
|
2010-03-09 12:39:32 +00:00
|
|
|
nsHtml5TreeBuilder::SetDocumentCharset(nsACString& aCharset,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aCharsetSource)
|
2009-09-21 13:18:20 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
mBuilder->SetDocumentCharsetAndSource(aCharset, aCharsetSource);
|
|
|
|
} else if (mSpeculativeLoadStage) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mSpeculativeLoadQueue.AppendElement()->InitSetDocumentCharset(
|
|
|
|
aCharset, aCharsetSource);
|
|
|
|
} else {
|
|
|
|
mOpQueue.AppendElement()->Init(
|
|
|
|
eTreeOpSetDocumentCharset, aCharset, aCharsetSource);
|
|
|
|
}
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::StreamEnded()
|
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!mBuilder, "Must not call StreamEnded with builder.");
|
|
|
|
MOZ_ASSERT(!fragment, "Must not parse fragments off the main thread.");
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpStreamEnded);
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-11 10:33:32 +00:00
|
|
|
nsHtml5TreeBuilder::NeedsCharsetSwitchTo(const nsACString& aCharset,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aCharsetSource,
|
|
|
|
int32_t aLineNumber)
|
2009-09-21 13:18:20 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(mBuilder)) {
|
2014-04-29 03:28:54 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Must never switch charset with builder.");
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-09-21 13:18:20 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2012-03-24 11:34:42 +00:00
|
|
|
treeOp->Init(eTreeOpNeedsCharsetSwitchTo,
|
|
|
|
aCharset,
|
|
|
|
aCharsetSource,
|
|
|
|
aLineNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::MaybeComplainAboutCharset(const char* aMsgId,
|
|
|
|
bool aError,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aLineNumber)
|
2012-03-24 11:34:42 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(mBuilder)) {
|
2014-04-29 03:28:54 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Must never complain about charset with builder.");
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-24 11:34:42 +00:00
|
|
|
mOpQueue.AppendElement()->Init(aMsgId, aError, aLineNumber);
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHtml5TreeBuilder::AddSnapshotToScript(nsAHtml5TreeBuilderState* aSnapshot, int32_t aLine)
|
2009-09-21 13:18:20 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(mBuilder)) {
|
2014-04-29 03:28:54 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Must never use snapshots with builder.");
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-09-21 13:18:20 +00:00
|
|
|
NS_PRECONDITION(HasScript(), "No script to add a snapshot to!");
|
2009-10-12 13:08:04 +00:00
|
|
|
NS_PRECONDITION(aSnapshot, "Got null snapshot.");
|
2009-10-28 13:48:37 +00:00
|
|
|
mOpQueue.ElementAt(mOpQueue.Length() - 1).SetSnapshot(aSnapshot, aLine);
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
|
|
|
|
2010-11-18 08:19:59 +00:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::DropHandles()
|
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!mBuilder, "Must not drop handles with builder.");
|
2010-11-18 08:19:59 +00:00
|
|
|
mOldHandles.Clear();
|
|
|
|
mHandlesUsed = 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 12:45:17 +00:00
|
|
|
void
|
2014-11-05 15:44:37 +00:00
|
|
|
nsHtml5TreeBuilder::MarkAsBroken(nsresult aRv)
|
2011-09-28 12:45:17 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (MOZ_UNLIKELY(mBuilder)) {
|
2014-04-29 03:28:54 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Must not call this with builder.");
|
2014-03-05 19:38:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-08-25 15:05:45 +00:00
|
|
|
mBroken = aRv;
|
2011-09-28 12:45:17 +00:00
|
|
|
mOpQueue.Clear(); // Previous ops don't matter anymore
|
2014-11-05 15:44:37 +00:00
|
|
|
mOpQueue.AppendElement()->Init(aRv);
|
2011-09-28 12:45:17 +00:00
|
|
|
}
|
|
|
|
|
2015-08-25 15:05:46 +00:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::MarkAsBrokenFromPortability(nsresult aRv)
|
|
|
|
{
|
|
|
|
if (mBuilder) {
|
|
|
|
MarkAsBrokenAndRequestSuspension(aRv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBroken = aRv;
|
|
|
|
requestSuspension();
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:44:31 +00:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::StartPlainTextViewSource(const nsAutoString& aTitle)
|
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!mBuilder, "Must not view source with builder.");
|
2011-11-30 17:44:31 +00:00
|
|
|
startTag(nsHtml5ElementName::ELT_TITLE,
|
|
|
|
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// XUL will add the "Source of: " prefix.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = aTitle.Length();
|
2012-09-28 06:57:33 +00:00
|
|
|
if (length > INT32_MAX) {
|
|
|
|
length = INT32_MAX;
|
2011-11-30 17:44:31 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
characters(aTitle.get(), 0, (int32_t)length);
|
2011-11-30 17:44:31 +00:00
|
|
|
endTag(nsHtml5ElementName::ELT_TITLE);
|
|
|
|
|
|
|
|
startTag(nsHtml5ElementName::ELT_LINK,
|
|
|
|
nsHtml5ViewSourceUtils::NewLinkAttributes(),
|
|
|
|
false);
|
|
|
|
|
|
|
|
startTag(nsHtml5ElementName::ELT_BODY,
|
|
|
|
nsHtml5ViewSourceUtils::NewBodyAttributes(),
|
|
|
|
false);
|
|
|
|
|
2013-03-07 04:45:08 +00:00
|
|
|
StartPlainTextBody();
|
2011-11-30 17:44:31 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 15:27:36 +00:00
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::StartPlainText()
|
2013-03-07 04:45:08 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!mBuilder, "Must not view source with builder.");
|
2013-03-13 19:56:24 +00:00
|
|
|
startTag(nsHtml5ElementName::ELT_LINK,
|
|
|
|
nsHtml5PlainTextUtils::NewLinkAttributes(),
|
|
|
|
false);
|
2013-03-07 04:45:08 +00:00
|
|
|
|
|
|
|
StartPlainTextBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::StartPlainTextBody()
|
2011-11-01 15:27:36 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!mBuilder, "Must not view source with builder.");
|
2011-11-01 15:27:36 +00:00
|
|
|
startTag(nsHtml5ElementName::ELT_PRE,
|
|
|
|
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES,
|
|
|
|
false);
|
|
|
|
needToDropLF = false;
|
|
|
|
}
|
|
|
|
|
2009-09-18 09:21:47 +00:00
|
|
|
// DocumentModeHandler
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::documentMode(nsHtml5DocumentMode m)
|
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
mBuilder->SetDocumentMode(m);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-18 09:21:47 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
2009-10-30 11:47:17 +00:00
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2009-09-18 09:21:47 +00:00
|
|
|
treeOp->Init(m);
|
|
|
|
}
|
2011-11-01 11:33:11 +00:00
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle*
|
|
|
|
nsHtml5TreeBuilder::getDocumentFragmentForTemplate(nsIContentHandle* aTemplate)
|
2013-03-26 07:15:23 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
if (mBuilder) {
|
|
|
|
return nsHtml5TreeOperation::GetDocumentFragmentForTemplate(static_cast<nsIContent*>(aTemplate));
|
|
|
|
}
|
2013-03-26 07:15:23 +00:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle* fragHandle = AllocateContentHandle();
|
2013-03-26 07:15:23 +00:00
|
|
|
treeOp->Init(eTreeOpGetDocumentFragmentForTemplate, aTemplate, fragHandle);
|
|
|
|
return fragHandle;
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContentHandle*
|
|
|
|
nsHtml5TreeBuilder::getFormPointerForContext(nsIContentHandle* aContext)
|
2014-01-31 23:03:24 +00:00
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(mBuilder, "Must have builder.");
|
2014-01-31 23:03:24 +00:00
|
|
|
if (!aContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
// aContext must always be an element that already exists
|
|
|
|
// in the document.
|
|
|
|
nsIContent* contextNode = static_cast<nsIContent*>(aContext);
|
2014-01-31 23:03:24 +00:00
|
|
|
nsIContent* currentAncestor = contextNode;
|
|
|
|
|
|
|
|
// We traverse the ancestors of the context node to find the nearest
|
|
|
|
// form pointer. This traversal is why aContext must not be an emtpy handle.
|
|
|
|
nsIContent* nearestForm = nullptr;
|
|
|
|
while (currentAncestor) {
|
2015-03-03 11:08:59 +00:00
|
|
|
if (currentAncestor->IsHTMLElement(nsGkAtoms::form)) {
|
2014-01-31 23:03:24 +00:00
|
|
|
nearestForm = currentAncestor;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currentAncestor = currentAncestor->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nearestForm) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
return nearestForm;
|
2014-01-31 23:03:24 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 11:33:11 +00:00
|
|
|
// Error reporting
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::EnableViewSource(nsHtml5Highlighter* aHighlighter)
|
|
|
|
{
|
2014-03-05 19:38:50 +00:00
|
|
|
MOZ_ASSERT(!mBuilder, "Must not view source with builder.");
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource = aHighlighter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStrayStartTag(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-04 13:36:29 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStrayStartTag2", aName);
|
2011-11-01 11:33:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStrayEndTag(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStrayEndTag", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHtml5TreeBuilder::errUnclosedElements(int32_t aIndex, nsIAtom* aName)
|
2011-11-01 11:33:11 +00:00
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errUnclosedElements", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHtml5TreeBuilder::errUnclosedElementsImplied(int32_t aIndex, nsIAtom* aName)
|
2011-11-01 11:33:11 +00:00
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errUnclosedElementsImplied",
|
|
|
|
aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHtml5TreeBuilder::errUnclosedElementsCell(int32_t aIndex)
|
2011-11-01 11:33:11 +00:00
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errUnclosedElementsCell");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStrayDoctype()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStrayDoctype");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errAlmostStandardsDoctype()
|
|
|
|
{
|
2013-06-29 03:13:23 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource) && !isSrcdocDocument) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errAlmostStandardsDoctype");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errQuirkyDoctype()
|
|
|
|
{
|
2013-06-29 03:13:23 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource) && !isSrcdocDocument) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errQuirkyDoctype");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNonSpaceInTrailer()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNonSpaceInTrailer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNonSpaceAfterFrameset()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNonSpaceAfterFrameset");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNonSpaceInFrameset()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNonSpaceInFrameset");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNonSpaceAfterBody()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNonSpaceAfterBody");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNonSpaceInColgroupInFragment()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNonSpaceInColgroupInFragment");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNonSpaceInNoscriptInHead()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNonSpaceInNoscriptInHead");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errFooBetweenHeadAndBody(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errFooBetweenHeadAndBody", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStartTagWithoutDoctype()
|
|
|
|
{
|
2013-06-29 03:13:23 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource) && !isSrcdocDocument) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStartTagWithoutDoctype");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNoSelectInTableScope()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNoSelectInTableScope");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStartSelectWhereEndSelectExpected()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun(
|
|
|
|
"errStartSelectWhereEndSelectExpected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStartTagWithSelectOpen(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStartTagWithSelectOpen", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errBadStartTagInHead(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-07 09:29:18 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errBadStartTagInHead2", aName);
|
2011-11-01 11:33:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errImage()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errImage");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errIsindex()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errIsindex");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errFooSeenWhenFooOpen(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errFooSeenWhenFooOpen", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errHeadingWhenHeadingOpen()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errHeadingWhenHeadingOpen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errFramesetStart()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errFramesetStart");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNoCellToClose()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNoCellToClose");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStartTagInTable(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStartTagInTable", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errFormWhenFormOpen()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errFormWhenFormOpen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errTableSeenWhileTableOpen()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errTableSeenWhileTableOpen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStartTagInTableBody(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStartTagInTableBody", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errEndTagSeenWithoutDoctype()
|
|
|
|
{
|
2013-06-29 03:13:23 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource) && !isSrcdocDocument) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errEndTagSeenWithoutDoctype");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errEndTagAfterBody()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errEndTagAfterBody");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errEndTagSeenWithSelectOpen(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errEndTagSeenWithSelectOpen",
|
|
|
|
aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errGarbageInColgroup()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errGarbageInColgroup");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errEndTagBr()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errEndTagBr");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNoElementToCloseButEndTagSeen(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun(
|
|
|
|
"errNoElementToCloseButEndTagSeen", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errHtmlStartTagInForeignContext(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errHtmlStartTagInForeignContext",
|
|
|
|
aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errTableClosedWhileCaptionOpen()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errTableClosedWhileCaptionOpen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNoTableRowToClose()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNoTableRowToClose");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNonSpaceInTable()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errNonSpaceInTable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errUnclosedChildrenInRuby()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errUnclosedChildrenInRuby");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errStartTagSeenWithoutRuby(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errStartTagSeenWithoutRuby",
|
|
|
|
aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errSelfClosing()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentSlash("errSelfClosing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errNoCheckUnclosedElementsOnStack()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun(
|
|
|
|
"errNoCheckUnclosedElementsOnStack");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errEndTagDidNotMatchCurrentOpenElement(nsIAtom* aName,
|
|
|
|
nsIAtom* aOther)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun(
|
|
|
|
"errEndTagDidNotMatchCurrentOpenElement", aName, aOther);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errEndTagViolatesNestingRules(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errEndTagViolatesNestingRules", aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeBuilder::errEndWithUnclosedElements(nsIAtom* aName)
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mViewSource)) {
|
2011-11-01 11:33:11 +00:00
|
|
|
mViewSource->AddErrorToCurrentRun("errEndWithUnclosedElements", aName);
|
|
|
|
}
|
|
|
|
}
|