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
|
|
|
|
|
|
|
#include "nsHtml5TreeOperation.h"
|
2009-08-13 07:51:06 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-03-17 07:55:12 +00:00
|
|
|
#include "nsDocElementCreatedNotificationRunner.h"
|
2009-06-28 22:44:22 +00:00
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
#include "nsAttrName.h"
|
|
|
|
#include "nsHtml5TreeBuilder.h"
|
2009-08-13 07:51:06 +00:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "mozAutoDocUpdate.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
#include "nsXBLBinding.h"
|
2009-09-18 09:21:47 +00:00
|
|
|
#include "nsHtml5DocumentMode.h"
|
2009-09-21 11:43:43 +00:00
|
|
|
#include "nsHtml5HtmlAttributes.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsIScriptElement.h"
|
|
|
|
#include "nsIDTD.h"
|
2014-02-26 21:36:35 +00:00
|
|
|
#include "nsISupportsImpl.h"
|
2009-09-21 11:43:43 +00:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
2010-08-28 05:54:57 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
2009-11-17 08:52:30 +00:00
|
|
|
#include "nsIMutationObserver.h"
|
2010-02-22 12:17:30 +00:00
|
|
|
#include "nsIFormProcessor.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2010-07-30 10:08:36 +00:00
|
|
|
#include "nsEscape.h"
|
2013-04-04 12:02:22 +00:00
|
|
|
#include "mozilla/dom/Comment.h"
|
2010-08-24 07:06:07 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-06-18 12:53:23 +00:00
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
2013-03-26 07:15:23 +00:00
|
|
|
#include "mozilla/dom/HTMLTemplateElement.h"
|
2010-07-18 22:07:54 +00:00
|
|
|
#include "nsHtml5SVGLoadDispatcher.h"
|
2010-07-30 10:15:38 +00:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIProtocolHandler.h"
|
|
|
|
#include "nsNetUtil.h"
|
2012-07-01 23:45:59 +00:00
|
|
|
#include "nsIHTMLDocument.h"
|
2012-10-26 13:32:10 +00:00
|
|
|
#include "mozilla/Likely.h"
|
2013-04-04 12:01:08 +00:00
|
|
|
#include "nsTextNode.h"
|
2010-07-18 22:07:54 +00:00
|
|
|
|
2013-11-11 14:07:50 +00:00
|
|
|
using namespace mozilla;
|
2010-08-24 07:06:07 +00:00
|
|
|
|
2010-02-22 12:17:30 +00:00
|
|
|
static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID);
|
2009-06-28 22:44:22 +00:00
|
|
|
|
2009-11-11 08:37:35 +00:00
|
|
|
/**
|
|
|
|
* Helper class that opens a notification batch if the current doc
|
|
|
|
* is different from the executor doc.
|
|
|
|
*/
|
2013-04-12 03:22:09 +00:00
|
|
|
class MOZ_STACK_CLASS nsHtml5OtherDocUpdate {
|
2009-11-11 08:37:35 +00:00
|
|
|
public:
|
|
|
|
nsHtml5OtherDocUpdate(nsIDocument* aCurrentDoc, nsIDocument* aExecutorDoc)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aCurrentDoc, "Node has no doc?");
|
|
|
|
NS_PRECONDITION(aExecutorDoc, "Executor has no doc?");
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_LIKELY(aCurrentDoc == aExecutorDoc)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mDocument = nullptr;
|
2009-11-11 08:37:35 +00:00
|
|
|
} else {
|
|
|
|
mDocument = aCurrentDoc;
|
|
|
|
aCurrentDoc->BeginUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsHtml5OtherDocUpdate()
|
|
|
|
{
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mDocument)) {
|
2009-11-11 08:37:35 +00:00
|
|
|
mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2014-06-16 23:01:22 +00:00
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2009-11-11 08:37:35 +00:00
|
|
|
};
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5TreeOperation::nsHtml5TreeOperation()
|
2009-09-21 13:18:20 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
: mOpCode(eTreeOpUninitialized)
|
|
|
|
#endif
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsHtml5TreeOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5TreeOperation::~nsHtml5TreeOperation()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsHtml5TreeOperation);
|
2009-09-21 13:18:20 +00:00
|
|
|
NS_ASSERTION(mOpCode != eTreeOpUninitialized, "Uninitialized tree op.");
|
2009-09-21 11:43:43 +00:00
|
|
|
switch(mOpCode) {
|
|
|
|
case eTreeOpAddAttributes:
|
|
|
|
delete mTwo.attributes;
|
|
|
|
break;
|
2010-06-09 06:44:25 +00:00
|
|
|
case eTreeOpCreateElementNetwork:
|
|
|
|
case eTreeOpCreateElementNotNetwork:
|
2009-09-21 11:43:43 +00:00
|
|
|
delete mThree.attributes;
|
|
|
|
break;
|
2009-11-17 08:52:30 +00:00
|
|
|
case eTreeOpAppendDoctypeToDocument:
|
2009-09-21 11:43:43 +00:00
|
|
|
delete mTwo.stringPair;
|
|
|
|
break;
|
2009-11-17 08:52:30 +00:00
|
|
|
case eTreeOpFosterParentText:
|
|
|
|
case eTreeOpAppendText:
|
|
|
|
case eTreeOpAppendComment:
|
|
|
|
case eTreeOpAppendCommentToDocument:
|
2010-07-30 10:15:38 +00:00
|
|
|
case eTreeOpAddViewSourceHref:
|
2009-09-21 11:43:43 +00:00
|
|
|
delete[] mTwo.unicharPtr;
|
|
|
|
break;
|
2011-11-01 11:33:11 +00:00
|
|
|
case eTreeOpSetDocumentCharset:
|
2009-09-21 13:18:20 +00:00
|
|
|
case eTreeOpNeedsCharsetSwitchTo:
|
|
|
|
delete[] mOne.charPtr;
|
|
|
|
break;
|
2010-02-02 07:43:18 +00:00
|
|
|
case eTreeOpProcessOfflineManifest:
|
|
|
|
nsMemory::Free(mOne.unicharPtr);
|
|
|
|
break;
|
2009-09-21 11:43:43 +00:00
|
|
|
default: // keep the compiler happy
|
|
|
|
break;
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2009-11-17 08:52:30 +00:00
|
|
|
nsresult
|
2014-01-04 15:02:17 +00:00
|
|
|
nsHtml5TreeOperation::AppendTextToTextNode(const char16_t* aBuffer,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aLength,
|
2009-11-17 08:52:30 +00:00
|
|
|
nsIContent* aTextNode,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2009-11-17 08:52:30 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aTextNode, "Got null text node.");
|
2014-06-16 23:01:22 +00:00
|
|
|
MOZ_ASSERT(aBuilder);
|
|
|
|
MOZ_ASSERT(aBuilder->GetDocument() == aTextNode->OwnerDoc());
|
|
|
|
MOZ_ASSERT(aBuilder->IsInDocUpdate());
|
|
|
|
uint32_t oldLength = aTextNode->TextLength();
|
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
true,
|
|
|
|
oldLength,
|
|
|
|
oldLength,
|
|
|
|
aLength
|
|
|
|
};
|
|
|
|
nsNodeUtils::CharacterDataWillChange(aTextNode, &info);
|
|
|
|
|
|
|
|
nsresult rv = aTextNode->AppendText(aBuffer, aLength, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-17 08:52:30 +00:00
|
|
|
|
2014-06-16 23:01:22 +00:00
|
|
|
nsNodeUtils::CharacterDataChanged(aTextNode, &info);
|
|
|
|
return rv;
|
2009-11-17 08:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 15:02:17 +00:00
|
|
|
nsHtml5TreeOperation::AppendText(const char16_t* aBuffer,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aLength,
|
2009-11-17 08:52:30 +00:00
|
|
|
nsIContent* aParent,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2009-11-17 08:52:30 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIContent* lastChild = aParent->GetLastChild();
|
|
|
|
if (lastChild && lastChild->IsNodeOfType(nsINode::eTEXT)) {
|
2011-10-18 10:53:36 +00:00
|
|
|
nsHtml5OtherDocUpdate update(aParent->OwnerDoc(),
|
2009-11-17 08:52:30 +00:00
|
|
|
aBuilder->GetDocument());
|
|
|
|
return AppendTextToTextNode(aBuffer,
|
|
|
|
aLength,
|
|
|
|
lastChild,
|
|
|
|
aBuilder);
|
|
|
|
}
|
|
|
|
|
2013-04-04 12:01:08 +00:00
|
|
|
nsRefPtr<nsTextNode> text = new nsTextNode(aBuilder->GetNodeInfoManager());
|
2009-11-17 08:52:30 +00:00
|
|
|
NS_ASSERTION(text, "Infallible malloc failed?");
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = text->SetText(aBuffer, aLength, false);
|
2009-11-17 08:52:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return Append(text, aParent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::Append(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2009-11-17 08:52:30 +00:00
|
|
|
{
|
2014-06-16 23:01:22 +00:00
|
|
|
MOZ_ASSERT(aBuilder);
|
|
|
|
MOZ_ASSERT(aBuilder->IsInDocUpdate());
|
2009-11-17 08:52:30 +00:00
|
|
|
nsresult rv = NS_OK;
|
2014-06-16 23:01:22 +00:00
|
|
|
nsHtml5OtherDocUpdate update(aParent->OwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t childCount = aParent->GetChildCount();
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = aParent->AppendChildTo(aNode, false);
|
2011-07-20 20:22:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-06-16 23:01:22 +00:00
|
|
|
aNode->SetParserHasNotified();
|
2011-07-20 20:22:27 +00:00
|
|
|
nsNodeUtils::ContentAppended(aParent, aNode, childCount);
|
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendToDocument(nsIContent* aNode,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2009-11-17 08:52:30 +00:00
|
|
|
{
|
2014-06-16 23:01:22 +00:00
|
|
|
MOZ_ASSERT(aBuilder);
|
|
|
|
MOZ_ASSERT(aBuilder->GetDocument() == aNode->OwnerDoc());
|
|
|
|
MOZ_ASSERT(aBuilder->IsInDocUpdate());
|
2009-11-17 08:52:30 +00:00
|
|
|
nsresult rv = NS_OK;
|
2014-06-16 23:01:22 +00:00
|
|
|
|
2009-11-17 08:52:30 +00:00
|
|
|
nsIDocument* doc = aBuilder->GetDocument();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t childCount = doc->GetChildCount();
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = doc->AppendChildTo(aNode, false);
|
2009-11-17 08:52:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-06-16 23:01:22 +00:00
|
|
|
aNode->SetParserHasNotified();
|
2009-11-17 08:52:30 +00:00
|
|
|
nsNodeUtils::ContentInserted(doc, aNode, childCount);
|
2010-08-28 05:54:57 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Someone forgot to block scripts");
|
2011-04-08 06:07:28 +00:00
|
|
|
if (aNode->IsElement()) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsDocElementCreatedNotificationRunner(doc));
|
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-11-11 06:45:43 +00:00
|
|
|
static bool
|
|
|
|
IsElementOrTemplateContent(nsINode* aNode) {
|
|
|
|
if (aNode) {
|
|
|
|
if (aNode->IsElement()) {
|
|
|
|
return true;
|
|
|
|
} else if (aNode->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
|
|
|
|
// Check if the node is a template content.
|
|
|
|
mozilla::dom::DocumentFragment* frag =
|
|
|
|
static_cast<mozilla::dom::DocumentFragment*>(aNode);
|
|
|
|
nsIContent* fragHost = frag->GetHost();
|
|
|
|
if (fragHost && nsNodeUtils::IsTemplateElement(fragHost)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
void
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeOperation::Detach(nsIContent* aNode, nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
2014-06-16 23:01:22 +00:00
|
|
|
MOZ_ASSERT(aBuilder);
|
|
|
|
MOZ_ASSERT(aBuilder->IsInDocUpdate());
|
2014-03-05 19:38:49 +00:00
|
|
|
nsCOMPtr<nsINode> parent = aNode->GetParentNode();
|
|
|
|
if (parent) {
|
|
|
|
nsHtml5OtherDocUpdate update(parent->OwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
int32_t pos = parent->IndexOf(aNode);
|
|
|
|
NS_ASSERTION((pos >= 0), "Element not found as child of its parent");
|
|
|
|
parent->RemoveChildAt(pos, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendChildrenToNewParent(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
2014-06-16 23:01:22 +00:00
|
|
|
MOZ_ASSERT(aBuilder);
|
|
|
|
MOZ_ASSERT(aBuilder->IsInDocUpdate());
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5OtherDocUpdate update(aParent->OwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
|
|
|
uint32_t childCount = aParent->GetChildCount();
|
|
|
|
bool didAppend = false;
|
|
|
|
while (aNode->HasChildren()) {
|
|
|
|
nsCOMPtr<nsIContent> child = aNode->GetFirstChild();
|
|
|
|
aNode->RemoveChildAt(0, true);
|
|
|
|
nsresult rv = aParent->AppendChildTo(child, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
didAppend = true;
|
|
|
|
}
|
|
|
|
if (didAppend) {
|
|
|
|
nsNodeUtils::ContentAppended(aParent, aParent->GetChildAt(childCount),
|
|
|
|
childCount);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::FosterParent(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aTable,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
2014-06-16 23:01:22 +00:00
|
|
|
MOZ_ASSERT(aBuilder);
|
|
|
|
MOZ_ASSERT(aBuilder->IsInDocUpdate());
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContent* foster = aTable->GetParent();
|
|
|
|
|
|
|
|
if (IsElementOrTemplateContent(foster)) {
|
|
|
|
|
|
|
|
nsHtml5OtherDocUpdate update(foster->OwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
|
|
|
uint32_t pos = foster->IndexOf(aTable);
|
|
|
|
nsresult rv = foster->InsertChildAt(aNode, pos, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsNodeUtils::ContentInserted(foster, aNode, pos);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Append(aNode, aParent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AddAttributes(nsIContent* aNode,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
|
|
|
dom::Element* node = aNode->AsElement();
|
|
|
|
nsHtml5OtherDocUpdate update(node->OwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
|
|
|
int32_t len = aAttributes->getLength();
|
|
|
|
for (int32_t i = len; i > 0;) {
|
|
|
|
--i;
|
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
|
|
|
nsCOMPtr<nsIAtom> localName =
|
|
|
|
Reget(aAttributes->getLocalNameNoBoundsCheck(i));
|
|
|
|
int32_t nsuri = aAttributes->getURINoBoundsCheck(i);
|
|
|
|
if (!node->HasAttr(nsuri, localName)) {
|
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
|
|
|
node->SetAttr(nsuri,
|
|
|
|
localName,
|
|
|
|
aAttributes->getPrefixNoBoundsCheck(i),
|
|
|
|
*(aAttributes->getValueNoBoundsCheck(i)),
|
|
|
|
true);
|
|
|
|
// XXX what to do with nsresult?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsHtml5TreeOperation::CreateElement(int32_t aNs,
|
|
|
|
nsIAtom* aName,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
2014-03-05 19:38:50 +00:00
|
|
|
mozilla::dom::FromParser aFromParser,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
|
|
|
bool isKeygen = (aName == nsHtml5Atoms::keygen && aNs == kNameSpaceID_XHTML);
|
|
|
|
if (MOZ_UNLIKELY(isKeygen)) {
|
|
|
|
aName = nsHtml5Atoms::select;
|
|
|
|
}
|
|
|
|
|
2014-06-16 23:01:22 +00:00
|
|
|
nsCOMPtr<dom::Element> newElement;
|
2014-06-20 02:01:40 +00:00
|
|
|
nsRefPtr<dom::NodeInfo> nodeInfo = aBuilder->GetNodeInfoManager()->
|
2014-03-05 19:38:49 +00:00
|
|
|
GetNodeInfo(aName, nullptr, aNs, nsIDOMNode::ELEMENT_NODE);
|
|
|
|
NS_ASSERTION(nodeInfo, "Got null nodeinfo.");
|
2014-06-16 23:01:22 +00:00
|
|
|
NS_NewElement(getter_AddRefs(newElement),
|
2014-03-05 19:38:49 +00:00
|
|
|
nodeInfo.forget(),
|
2014-03-05 19:38:50 +00:00
|
|
|
aFromParser);
|
2014-06-16 23:01:22 +00:00
|
|
|
NS_ASSERTION(newElement, "Element creation created null pointer.");
|
2014-03-05 19:38:49 +00:00
|
|
|
|
2014-06-16 23:01:22 +00:00
|
|
|
dom::Element* newContent = newElement;
|
|
|
|
aBuilder->HoldElement(newElement.forget());
|
2014-03-05 19:38:49 +00:00
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(aName == nsHtml5Atoms::style || aName == nsHtml5Atoms::link)) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(newContent));
|
|
|
|
if (ssle) {
|
|
|
|
ssle->InitStyleLinkElement(false);
|
|
|
|
ssle->SetEnableUpdates(false);
|
|
|
|
}
|
|
|
|
} else if (MOZ_UNLIKELY(isKeygen)) {
|
|
|
|
// Adapted from CNavDTD
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFormProcessor> theFormProcessor =
|
|
|
|
do_GetService(kFormProcessorCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return newContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsString> theContent;
|
|
|
|
nsAutoString theAttribute;
|
|
|
|
|
|
|
|
(void) theFormProcessor->ProvideContent(NS_LITERAL_STRING("select"),
|
|
|
|
theContent,
|
|
|
|
theAttribute);
|
|
|
|
|
|
|
|
newContent->SetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::moztype,
|
|
|
|
nullptr,
|
|
|
|
theAttribute,
|
|
|
|
false);
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
nsRefPtr<dom::NodeInfo> optionNodeInfo =
|
2014-03-05 19:38:49 +00:00
|
|
|
aBuilder->GetNodeInfoManager()->GetNodeInfo(nsHtml5Atoms::option,
|
|
|
|
nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < theContent.Length(); ++i) {
|
|
|
|
nsCOMPtr<dom::Element> optionElt;
|
2014-06-20 02:01:40 +00:00
|
|
|
nsRefPtr<dom::NodeInfo> ni = optionNodeInfo;
|
2014-03-05 19:38:49 +00:00
|
|
|
NS_NewElement(getter_AddRefs(optionElt),
|
|
|
|
ni.forget(),
|
2014-03-05 19:38:50 +00:00
|
|
|
aFromParser);
|
2014-03-05 19:38:49 +00:00
|
|
|
nsRefPtr<nsTextNode> optionText =
|
|
|
|
new nsTextNode(aBuilder->GetNodeInfoManager());
|
|
|
|
(void) optionText->SetText(theContent[i], false);
|
|
|
|
optionElt->AppendChildTo(optionText, false);
|
|
|
|
newContent->AppendChildTo(optionElt, false);
|
2014-06-16 23:01:22 +00:00
|
|
|
// XXXsmaug Shouldn't we call this after adding all the child nodes.
|
2014-03-05 19:38:49 +00:00
|
|
|
newContent->DoneAddingChildren(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aAttributes) {
|
|
|
|
return newContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t len = aAttributes->getLength();
|
|
|
|
for (int32_t i = len; i > 0;) {
|
|
|
|
--i;
|
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
|
|
|
nsCOMPtr<nsIAtom> localName =
|
|
|
|
Reget(aAttributes->getLocalNameNoBoundsCheck(i));
|
|
|
|
nsCOMPtr<nsIAtom> prefix = aAttributes->getPrefixNoBoundsCheck(i);
|
|
|
|
int32_t nsuri = aAttributes->getURINoBoundsCheck(i);
|
|
|
|
|
|
|
|
if (aNs == kNameSpaceID_XHTML &&
|
|
|
|
nsHtml5Atoms::a == aName &&
|
|
|
|
nsHtml5Atoms::name == localName) {
|
|
|
|
// This is an HTML5-incompliant Geckoism.
|
|
|
|
// Remove when fixing bug 582361
|
|
|
|
NS_ConvertUTF16toUTF8 cname(*(aAttributes->getValueNoBoundsCheck(i)));
|
|
|
|
NS_ConvertUTF8toUTF16 uv(nsUnescape(cname.BeginWriting()));
|
|
|
|
newContent->SetAttr(nsuri,
|
|
|
|
localName,
|
|
|
|
prefix,
|
|
|
|
uv,
|
|
|
|
false);
|
|
|
|
} else {
|
|
|
|
nsString& value = *(aAttributes->getValueNoBoundsCheck(i));
|
|
|
|
newContent->SetAttr(nsuri,
|
|
|
|
localName,
|
|
|
|
prefix,
|
|
|
|
value,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Custom element prototype swizzling may be needed if there is an
|
|
|
|
// "is" attribute.
|
|
|
|
if (kNameSpaceID_None == nsuri && !prefix && nsGkAtoms::is == localName) {
|
|
|
|
ErrorResult errorResult;
|
|
|
|
newContent->OwnerDoc()->SwizzleCustomElement(newContent,
|
|
|
|
value,
|
|
|
|
newContent->GetNameSpaceID(),
|
|
|
|
errorResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeOperation::SetFormElement(nsIContent* aNode, nsIContent* aParent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(aNode));
|
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> domImageElement = do_QueryInterface(aNode);
|
|
|
|
// NS_ASSERTION(formControl, "Form-associated element did not implement nsIFormControl.");
|
|
|
|
// TODO: uncomment the above line when <keygen> (bug 101019) is supported by Gecko
|
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> formElement(do_QueryInterface(aParent));
|
|
|
|
NS_ASSERTION(formElement, "The form element doesn't implement nsIDOMHTMLFormElement.");
|
|
|
|
// avoid crashing on <keygen>
|
|
|
|
if (formControl &&
|
|
|
|
!aNode->HasAttr(kNameSpaceID_None, nsGkAtoms::form)) {
|
|
|
|
formControl->SetForm(formElement);
|
|
|
|
} else if (domImageElement) {
|
|
|
|
nsRefPtr<dom::HTMLImageElement> imageElement =
|
|
|
|
static_cast<dom::HTMLImageElement*>(domImageElement.get());
|
|
|
|
MOZ_ASSERT(imageElement);
|
|
|
|
imageElement->SetForm(formElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5TreeOperation::AppendIsindexPrompt(nsIContent* parent, nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
|
|
|
nsXPIDLString prompt;
|
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
"IsIndexPromptWithSpace", prompt);
|
|
|
|
uint32_t len = prompt.Length();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (!len) {
|
|
|
|
// Don't bother appending a zero-length text node.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return AppendText(prompt.BeginReading(), len, parent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::FosterParentText(nsIContent* aStackParent,
|
|
|
|
char16_t* aBuffer,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsIContent* aTable,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
2014-06-16 23:01:22 +00:00
|
|
|
MOZ_ASSERT(aBuilder);
|
|
|
|
MOZ_ASSERT(aBuilder->IsInDocUpdate());
|
2014-03-05 19:38:49 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIContent* foster = aTable->GetParent();
|
|
|
|
|
|
|
|
if (IsElementOrTemplateContent(foster)) {
|
|
|
|
nsHtml5OtherDocUpdate update(foster->OwnerDoc(),
|
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
|
|
|
uint32_t pos = foster->IndexOf(aTable);
|
|
|
|
|
|
|
|
nsIContent* previousSibling = aTable->GetPreviousSibling();
|
|
|
|
if (previousSibling && previousSibling->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
return AppendTextToTextNode(aBuffer,
|
|
|
|
aLength,
|
|
|
|
previousSibling,
|
|
|
|
aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsTextNode> text =
|
|
|
|
new nsTextNode(aBuilder->GetNodeInfoManager());
|
|
|
|
NS_ASSERTION(text, "Infallible malloc failed?");
|
|
|
|
rv = text->SetText(aBuffer, aLength, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = foster->InsertChildAt(text, pos, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsNodeUtils::ContentInserted(foster, text, pos);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppendText(aBuffer, aLength, aStackParent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendComment(nsIContent* aParent,
|
|
|
|
char16_t* aBuffer,
|
|
|
|
int32_t aLength,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
|
|
|
nsRefPtr<dom::Comment> comment =
|
|
|
|
new dom::Comment(aBuilder->GetNodeInfoManager());
|
|
|
|
NS_ASSERTION(comment, "Infallible malloc failed?");
|
|
|
|
nsresult rv = comment->SetText(aBuffer, aLength, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return Append(comment, aParent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendCommentToDocument(char16_t* aBuffer,
|
|
|
|
int32_t aLength,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
|
|
|
nsRefPtr<dom::Comment> comment =
|
|
|
|
new dom::Comment(aBuilder->GetNodeInfoManager());
|
|
|
|
NS_ASSERTION(comment, "Infallible malloc failed?");
|
|
|
|
nsresult rv = comment->SetText(aBuffer, aLength, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return AppendToDocument(comment, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendDoctypeToDocument(nsIAtom* aName,
|
|
|
|
const nsAString& aPublicId,
|
|
|
|
const nsAString& aSystemId,
|
2014-03-05 19:38:49 +00:00
|
|
|
nsHtml5DocumentBuilder* aBuilder)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
|
|
|
// Adapted from nsXMLContentSink
|
|
|
|
// Create a new doctype node
|
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
|
|
|
nsAutoString voidString;
|
|
|
|
voidString.SetIsVoid(true);
|
|
|
|
NS_NewDOMDocumentType(getter_AddRefs(docType),
|
|
|
|
aBuilder->GetNodeInfoManager(),
|
|
|
|
aName,
|
|
|
|
aPublicId,
|
|
|
|
aSystemId,
|
|
|
|
voidString);
|
|
|
|
NS_ASSERTION(docType, "Doctype creation failed.");
|
|
|
|
nsCOMPtr<nsIContent> asContent = do_QueryInterface(docType);
|
|
|
|
return AppendToDocument(asContent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsHtml5TreeOperation::GetDocumentFragmentForTemplate(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
dom::HTMLTemplateElement* tempElem =
|
|
|
|
static_cast<dom::HTMLTemplateElement*>(aNode);
|
|
|
|
nsRefPtr<dom::DocumentFragment> frag = tempElem->Content();
|
|
|
|
return frag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeOperation::PreventScriptExecution(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(aNode);
|
|
|
|
MOZ_ASSERT(sele);
|
|
|
|
sele->PreventExecution();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-16 23:01:22 +00:00
|
|
|
nsHtml5TreeOperation::DoneAddingChildren(nsIContent* aNode)
|
2014-03-05 19:38:49 +00:00
|
|
|
{
|
2014-06-16 23:01:22 +00:00
|
|
|
aNode->DoneAddingChildren(aNode->HasParserNotified());
|
2014-03-05 19:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeOperation::DoneCreatingElement(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
aNode->DoneCreatingElement();
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:50 +00:00
|
|
|
void
|
|
|
|
nsHtml5TreeOperation::SvgLoad(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(aNode);
|
|
|
|
if (NS_FAILED(NS_DispatchToMainThread(event))) {
|
|
|
|
NS_WARNING("failed to dispatch svg load dispatcher");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5TreeOperation::MarkMalformedIfScript(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(aNode);
|
|
|
|
if (sele) {
|
|
|
|
// Make sure to serialize this script correctly, for nice round tripping.
|
|
|
|
sele->SetIsMalformed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
nsresult
|
2009-11-06 13:06:48 +00:00
|
|
|
nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
|
|
|
|
nsIContent** aScriptElement)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
|
|
|
switch(mOpCode) {
|
|
|
|
case eTreeOpAppend: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
2009-11-17 08:52:30 +00:00
|
|
|
return Append(node, parent, aBuilder);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpDetach: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
2014-03-05 19:38:49 +00:00
|
|
|
Detach(node, aBuilder);
|
2012-03-29 21:09:07 +00:00
|
|
|
return NS_OK;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpAppendChildrenToNewParent: {
|
2011-08-23 12:57:29 +00:00
|
|
|
nsCOMPtr<nsIContent> node = *(mOne.node);
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* parent = *(mTwo.node);
|
2014-03-05 19:38:49 +00:00
|
|
|
return AppendChildrenToNewParent(node, parent, aBuilder);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpFosterParent: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
|
|
|
nsIContent* table = *(mThree.node);
|
2014-03-05 19:38:49 +00:00
|
|
|
return FosterParent(node, parent, table, aBuilder);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpAppendToDocument: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-11-17 08:52:30 +00:00
|
|
|
return AppendToDocument(node, aBuilder);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpAddAttributes: {
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-09-21 11:43:43 +00:00
|
|
|
nsHtml5HtmlAttributes* attributes = mTwo.attributes;
|
2014-03-05 19:38:49 +00:00
|
|
|
return AddAttributes(node, attributes, aBuilder);
|
2009-09-21 11:43:43 +00:00
|
|
|
}
|
2010-06-09 06:44:25 +00:00
|
|
|
case eTreeOpCreateElementNetwork:
|
|
|
|
case eTreeOpCreateElementNotNetwork: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent** target = mOne.node;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t ns = mFour.integer;
|
2009-09-21 11:43:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> name = Reget(mTwo.atom);
|
|
|
|
nsHtml5HtmlAttributes* attributes = mThree.attributes;
|
2009-10-30 08:31:57 +00:00
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
*target = CreateElement(ns,
|
|
|
|
name,
|
|
|
|
attributes,
|
2014-03-05 19:38:50 +00:00
|
|
|
mOpCode == eTreeOpCreateElementNetwork ?
|
|
|
|
dom::FROM_PARSER_NETWORK :
|
|
|
|
dom::FROM_PARSER_DOCUMENT_WRITE,
|
2014-03-05 19:38:49 +00:00
|
|
|
aBuilder);
|
|
|
|
return NS_OK;
|
2009-09-21 11:43:43 +00:00
|
|
|
}
|
|
|
|
case eTreeOpSetFormElement: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
2014-03-05 19:38:49 +00:00
|
|
|
SetFormElement(node, parent);
|
|
|
|
return NS_OK;
|
2009-09-21 11:43:43 +00:00
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
case eTreeOpAppendText: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* buffer = mTwo.unicharPtr;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = mFour.integer;
|
2009-11-17 08:52:30 +00:00
|
|
|
return AppendText(buffer, length, parent, aBuilder);
|
|
|
|
}
|
2010-06-11 15:08:13 +00:00
|
|
|
case eTreeOpAppendIsindexPrompt: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
2014-03-05 19:38:49 +00:00
|
|
|
return AppendIsindexPrompt(parent, aBuilder);
|
2010-06-11 15:08:13 +00:00
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
case eTreeOpFosterParentText: {
|
|
|
|
nsIContent* stackParent = *mOne.node;
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* buffer = mTwo.unicharPtr;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = mFour.integer;
|
2009-11-17 08:52:30 +00:00
|
|
|
nsIContent* table = *mThree.node;
|
2014-03-05 19:38:49 +00:00
|
|
|
return FosterParentText(stackParent, buffer, length, table, aBuilder);
|
2009-11-17 08:52:30 +00:00
|
|
|
}
|
|
|
|
case eTreeOpAppendComment: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* buffer = mTwo.unicharPtr;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t length = mFour.integer;
|
2014-03-05 19:38:49 +00:00
|
|
|
return AppendComment(parent, buffer, length, aBuilder);
|
2009-09-21 11:43:43 +00:00
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
case eTreeOpAppendCommentToDocument: {
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* buffer = mTwo.unicharPtr;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t length = mFour.integer;
|
2014-03-05 19:38:49 +00:00
|
|
|
return AppendCommentToDocument(buffer, length, aBuilder);
|
2009-09-21 11:43:43 +00:00
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
case eTreeOpAppendDoctypeToDocument: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> name = Reget(mOne.atom);
|
|
|
|
nsHtml5TreeOperationStringPair* pair = mTwo.stringPair;
|
|
|
|
nsString publicId;
|
|
|
|
nsString systemId;
|
|
|
|
pair->Get(publicId, systemId);
|
2014-03-05 19:38:49 +00:00
|
|
|
return AppendDoctypeToDocument(name, publicId, systemId, aBuilder);
|
2009-09-21 11:43:43 +00:00
|
|
|
}
|
2013-03-26 07:15:23 +00:00
|
|
|
case eTreeOpGetDocumentFragmentForTemplate: {
|
2014-03-05 19:38:49 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
*mTwo.node = GetDocumentFragmentForTemplate(node);
|
|
|
|
return NS_OK;
|
2013-03-26 07:15:23 +00:00
|
|
|
}
|
2011-09-28 12:45:17 +00:00
|
|
|
case eTreeOpMarkAsBroken: {
|
2012-03-21 12:39:25 +00:00
|
|
|
aBuilder->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2011-09-28 12:45:17 +00:00
|
|
|
}
|
2009-09-21 11:43:43 +00:00
|
|
|
case eTreeOpRunScript: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2009-09-21 13:18:20 +00:00
|
|
|
nsAHtml5TreeBuilderState* snapshot = mTwo.state;
|
|
|
|
if (snapshot) {
|
2011-11-01 11:33:11 +00:00
|
|
|
aBuilder->InitializeDocWriteParserState(snapshot, mFour.integer);
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
2009-11-06 13:06:48 +00:00
|
|
|
*aScriptElement = node;
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2009-12-14 13:51:15 +00:00
|
|
|
case eTreeOpRunScriptAsyncDefer: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
aBuilder->RunScript(node);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-12-14 13:51:15 +00:00
|
|
|
}
|
2012-06-20 07:05:39 +00:00
|
|
|
case eTreeOpPreventScriptExecution: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2014-03-05 19:38:49 +00:00
|
|
|
PreventScriptExecution(node);
|
|
|
|
return NS_OK;
|
2012-06-20 07:05:39 +00:00
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
case eTreeOpDoneAddingChildren: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
2014-06-16 23:01:22 +00:00
|
|
|
node->DoneAddingChildren(node->HasParserNotified());
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpDoneCreatingElement: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
2014-03-05 19:38:49 +00:00
|
|
|
DoneCreatingElement(node);
|
|
|
|
return NS_OK;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2011-11-01 11:33:11 +00:00
|
|
|
case eTreeOpSetDocumentCharset: {
|
|
|
|
char* str = mOne.charPtr;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t charsetSource = mFour.integer;
|
2011-11-01 11:33:11 +00:00
|
|
|
nsDependentCString dependentString(str);
|
|
|
|
aBuilder->SetDocumentCharsetAndSource(dependentString, charsetSource);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2011-11-01 11:33:11 +00:00
|
|
|
}
|
2009-09-21 13:18:20 +00:00
|
|
|
case eTreeOpNeedsCharsetSwitchTo: {
|
|
|
|
char* str = mOne.charPtr;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t charsetSource = mFour.integer;
|
|
|
|
int32_t lineNumber = mTwo.integer;
|
|
|
|
aBuilder->NeedsCharsetSwitchTo(str, charsetSource, (uint32_t)lineNumber);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
case eTreeOpUpdateStyleSheet: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
aBuilder->UpdateStyleSheet(node);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpProcessMeta: {
|
2009-09-21 11:43:43 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
2014-03-05 19:38:49 +00:00
|
|
|
return aBuilder->ProcessMETATag(node);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
case eTreeOpProcessOfflineManifest: {
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* str = mOne.unicharPtr;
|
2010-02-02 07:43:18 +00:00
|
|
|
nsDependentString dependentString(str);
|
|
|
|
aBuilder->ProcessOfflineManifest(dependentString);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-09-21 11:43:43 +00:00
|
|
|
}
|
|
|
|
case eTreeOpMarkMalformedIfScript: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2014-03-05 19:38:50 +00:00
|
|
|
MarkMalformedIfScript(node);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2009-09-21 13:18:20 +00:00
|
|
|
case eTreeOpStreamEnded: {
|
2011-10-17 14:59:28 +00:00
|
|
|
aBuilder->DidBuildModel(false); // this causes a notifications flush anyway
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-09-21 13:18:20 +00:00
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
case eTreeOpStartLayout: {
|
2009-11-06 13:06:48 +00:00
|
|
|
aBuilder->StartLayout(); // this causes a notification flush anyway
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
2009-09-18 09:21:47 +00:00
|
|
|
case eTreeOpDocumentMode: {
|
2010-03-15 12:04:42 +00:00
|
|
|
aBuilder->SetDocumentMode(mOne.mode);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-09-18 09:21:47 +00:00
|
|
|
}
|
2009-10-28 13:48:37 +00:00
|
|
|
case eTreeOpSetStyleLineNumber: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(node);
|
|
|
|
NS_ASSERTION(ssle, "Node didn't QI to style.");
|
2011-11-01 11:33:11 +00:00
|
|
|
ssle->SetLineNumber(mFour.integer);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-10-28 13:48:37 +00:00
|
|
|
}
|
2009-11-17 08:52:30 +00:00
|
|
|
case eTreeOpSetScriptLineNumberAndFreeze: {
|
2009-10-28 13:48:37 +00:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(node);
|
|
|
|
NS_ASSERTION(sele, "Node didn't QI to script.");
|
2011-11-01 11:33:11 +00:00
|
|
|
sele->SetScriptLineNumber(mFour.integer);
|
2009-11-17 08:52:30 +00:00
|
|
|
sele->FreezeUriAsyncDefer();
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2009-10-28 13:48:37 +00:00
|
|
|
}
|
2010-07-18 22:07:54 +00:00
|
|
|
case eTreeOpSvgLoad: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2014-03-05 19:38:50 +00:00
|
|
|
SvgLoad(node);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2010-07-18 22:07:54 +00:00
|
|
|
}
|
2012-03-24 11:34:42 +00:00
|
|
|
case eTreeOpMaybeComplainAboutCharset: {
|
|
|
|
char* msgId = mOne.charPtr;
|
|
|
|
bool error = mTwo.integer;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t lineNumber = mThree.integer;
|
|
|
|
aBuilder->MaybeComplainAboutCharset(msgId, error, (uint32_t)lineNumber);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2012-03-24 11:34:42 +00:00
|
|
|
}
|
2010-07-30 10:15:38 +00:00
|
|
|
case eTreeOpAddClass: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* str = mTwo.unicharPtr;
|
2010-07-30 10:15:38 +00:00
|
|
|
nsDependentString depStr(str);
|
2011-11-01 11:33:11 +00:00
|
|
|
// See viewsource.css for the possible classes
|
2011-11-01 11:33:11 +00:00
|
|
|
nsAutoString klass;
|
|
|
|
node->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass);
|
|
|
|
if (!klass.IsEmpty()) {
|
|
|
|
klass.Append(' ');
|
|
|
|
klass.Append(depStr);
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass, true);
|
|
|
|
} else {
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, depStr, true);
|
|
|
|
}
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2010-07-30 10:15:38 +00:00
|
|
|
}
|
2011-11-01 11:33:11 +00:00
|
|
|
case eTreeOpAddLineNumberId: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t lineNumber = mFour.integer;
|
2011-11-01 11:33:11 +00:00
|
|
|
nsAutoString val(NS_LITERAL_STRING("line"));
|
|
|
|
val.AppendInt(lineNumber);
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::id, val, true);
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK;
|
2011-11-01 11:33:11 +00:00
|
|
|
}
|
2010-07-30 10:15:38 +00:00
|
|
|
case eTreeOpAddViewSourceHref: {
|
|
|
|
nsIContent* node = *mOne.node;
|
2014-01-04 15:02:17 +00:00
|
|
|
char16_t* buffer = mTwo.unicharPtr;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t length = mFour.integer;
|
2010-07-30 10:15:38 +00:00
|
|
|
|
|
|
|
nsDependentString relative(buffer, length);
|
|
|
|
|
|
|
|
nsIDocument* doc = aBuilder->GetDocument();
|
|
|
|
|
|
|
|
const nsCString& charset = doc->GetDocumentCharacterSet();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2014-03-05 19:38:49 +00:00
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri),
|
|
|
|
relative,
|
|
|
|
charset.get(),
|
|
|
|
aBuilder->GetViewSourceBaseURI());
|
2014-02-06 14:46:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
2010-07-30 10:15:38 +00:00
|
|
|
|
|
|
|
// Reuse the fix for bug 467852
|
|
|
|
// URLs that execute script (e.g. "javascript:" URLs) should just be
|
|
|
|
// ignored. There's nothing reasonable we can do with them, and allowing
|
|
|
|
// them to execute in the context of the view-source window presents a
|
|
|
|
// security risk. Just return the empty string in this case.
|
|
|
|
bool openingExecutesScript = false;
|
|
|
|
rv = NS_URIChainHasFlags(uri,
|
|
|
|
nsIProtocolHandler::URI_OPENING_EXECUTES_SCRIPT,
|
|
|
|
&openingExecutesScript);
|
2011-11-01 11:33:11 +00:00
|
|
|
if (NS_FAILED(rv) || openingExecutesScript) {
|
2010-07-30 10:15:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString viewSourceUrl;
|
2010-07-30 10:15:38 +00:00
|
|
|
|
|
|
|
// URLs that return data (e.g. "http:" URLs) should be prefixed with
|
|
|
|
// "view-source:". URLs that don't return data should just be returned
|
|
|
|
// undecorated.
|
|
|
|
bool doesNotReturnData = false;
|
|
|
|
rv = NS_URIChainHasFlags(uri,
|
|
|
|
nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
|
|
|
|
&doesNotReturnData);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
if (!doesNotReturnData) {
|
|
|
|
viewSourceUrl.AssignLiteral("view-source:");
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString spec;
|
2010-07-30 10:15:38 +00:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
|
|
|
|
viewSourceUrl.Append(spec);
|
|
|
|
|
|
|
|
nsAutoString utf16;
|
|
|
|
CopyUTF8toUTF16(viewSourceUrl, utf16);
|
|
|
|
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::href, utf16, true);
|
|
|
|
return rv;
|
|
|
|
}
|
2011-11-01 11:33:11 +00:00
|
|
|
case eTreeOpAddError: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
char* msgId = mTwo.charPtr;
|
2011-11-01 11:33:11 +00:00
|
|
|
nsCOMPtr<nsIAtom> atom = Reget(mThree.atom);
|
|
|
|
nsCOMPtr<nsIAtom> otherAtom = Reget(mFour.atom);
|
2011-11-01 11:33:11 +00:00
|
|
|
// See viewsource.css for the possible classes in addition to "error".
|
2011-11-01 11:33:11 +00:00
|
|
|
nsAutoString klass;
|
|
|
|
node->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass);
|
|
|
|
if (!klass.IsEmpty()) {
|
2014-05-22 03:48:50 +00:00
|
|
|
klass.AppendLiteral(" error");
|
2011-11-01 11:33:11 +00:00
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass, true);
|
|
|
|
} else {
|
|
|
|
node->SetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::_class,
|
|
|
|
NS_LITERAL_STRING("error"),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:38:49 +00:00
|
|
|
nsresult rv;
|
2011-11-01 11:33:11 +00:00
|
|
|
nsXPIDLString message;
|
2011-11-01 11:33:11 +00:00
|
|
|
if (otherAtom) {
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* params[] = { atom->GetUTF16String(),
|
2011-11-01 11:33:11 +00:00
|
|
|
otherAtom->GetUTF16String() };
|
|
|
|
rv = nsContentUtils::FormatLocalizedString(
|
2012-03-09 02:22:57 +00:00
|
|
|
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, message);
|
2014-05-23 21:32:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
2011-11-01 11:33:11 +00:00
|
|
|
} else if (atom) {
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t* params[] = { atom->GetUTF16String() };
|
2011-11-01 11:33:11 +00:00
|
|
|
rv = nsContentUtils::FormatLocalizedString(
|
2012-03-09 02:22:57 +00:00
|
|
|
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, message);
|
2014-05-23 21:32:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
2011-11-01 11:33:11 +00:00
|
|
|
} else {
|
|
|
|
rv = nsContentUtils::GetLocalizedString(
|
|
|
|
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, message);
|
2014-05-23 21:32:37 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
2011-11-01 11:33:11 +00:00
|
|
|
}
|
2011-11-01 11:33:11 +00:00
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
node->GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
|
|
|
if (!title.IsEmpty()) {
|
2011-11-01 11:33:11 +00:00
|
|
|
title.Append('\n');
|
2011-11-01 11:33:11 +00:00
|
|
|
title.Append(message);
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::title, title, true);
|
|
|
|
} else {
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::title, message, true);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2009-06-28 22:44:22 +00:00
|
|
|
default: {
|
|
|
|
NS_NOTREACHED("Bogus tree op");
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 19:38:49 +00:00
|
|
|
return NS_OK; // keep compiler happy
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|