2009-06-28 15:44:22 -07: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 08:52:43 -07: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 15:44:22 -07:00
|
|
|
|
|
|
|
#include "nsHtml5TreeOperation.h"
|
2009-08-13 00:51:06 -07:00
|
|
|
#include "nsContentUtils.h"
|
2013-03-17 00:55:12 -07:00
|
|
|
#include "nsDocElementCreatedNotificationRunner.h"
|
2009-06-28 15:44:22 -07:00
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
#include "nsAttrName.h"
|
|
|
|
#include "nsHtml5TreeBuilder.h"
|
2009-08-13 00:51:06 -07:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "mozAutoDocUpdate.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
#include "nsXBLBinding.h"
|
2009-09-18 02:21:47 -07:00
|
|
|
#include "nsHtml5DocumentMode.h"
|
2009-09-21 04:43:43 -07:00
|
|
|
#include "nsHtml5HtmlAttributes.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsIScriptElement.h"
|
|
|
|
#include "nsIDTD.h"
|
|
|
|
#include "nsTraceRefcnt.h"
|
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
2010-08-27 22:54:57 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
2009-11-17 00:52:30 -08:00
|
|
|
#include "nsIMutationObserver.h"
|
2010-02-22 04:17:30 -08:00
|
|
|
#include "nsIFormProcessor.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2010-07-30 03:08:36 -07:00
|
|
|
#include "nsEscape.h"
|
2013-04-04 05:02:22 -07:00
|
|
|
#include "mozilla/dom/Comment.h"
|
2010-08-24 00:06:07 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-03-26 00:15:23 -07:00
|
|
|
#include "mozilla/dom/HTMLTemplateElement.h"
|
2010-07-18 15:07:54 -07:00
|
|
|
#include "nsHtml5SVGLoadDispatcher.h"
|
2010-07-30 03:15:38 -07:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIProtocolHandler.h"
|
|
|
|
#include "nsNetUtil.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "nsIHTMLDocument.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2013-04-04 05:01:08 -07:00
|
|
|
#include "nsTextNode.h"
|
2010-07-18 15:07:54 -07:00
|
|
|
|
2010-08-24 00:06:07 -07:00
|
|
|
namespace dom = mozilla::dom;
|
|
|
|
|
2010-02-22 04:17:30 -08:00
|
|
|
static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID);
|
2009-06-28 15:44:22 -07:00
|
|
|
|
2009-11-11 00:37:35 -08:00
|
|
|
/**
|
|
|
|
* Helper class that opens a notification batch if the current doc
|
|
|
|
* is different from the executor doc.
|
|
|
|
*/
|
2013-04-11 20:22:09 -07:00
|
|
|
class MOZ_STACK_CLASS nsHtml5OtherDocUpdate {
|
2009-11-11 00:37:35 -08:00
|
|
|
public:
|
|
|
|
nsHtml5OtherDocUpdate(nsIDocument* aCurrentDoc, nsIDocument* aExecutorDoc)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aCurrentDoc, "Node has no doc?");
|
|
|
|
NS_PRECONDITION(aExecutorDoc, "Executor has no doc?");
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(aCurrentDoc == aExecutorDoc)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocument = nullptr;
|
2009-11-11 00:37:35 -08:00
|
|
|
} else {
|
|
|
|
mDocument = aCurrentDoc;
|
|
|
|
aCurrentDoc->BeginUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsHtml5OtherDocUpdate()
|
|
|
|
{
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(mDocument)) {
|
2009-11-11 00:37:35 -08:00
|
|
|
mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
};
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsHtml5TreeOperation::nsHtml5TreeOperation()
|
2009-09-21 06:18:20 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
: mOpCode(eTreeOpUninitialized)
|
|
|
|
#endif
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsHtml5TreeOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5TreeOperation::~nsHtml5TreeOperation()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsHtml5TreeOperation);
|
2009-09-21 06:18:20 -07:00
|
|
|
NS_ASSERTION(mOpCode != eTreeOpUninitialized, "Uninitialized tree op.");
|
2009-09-21 04:43:43 -07:00
|
|
|
switch(mOpCode) {
|
|
|
|
case eTreeOpAddAttributes:
|
|
|
|
delete mTwo.attributes;
|
|
|
|
break;
|
2010-06-08 23:44:25 -07:00
|
|
|
case eTreeOpCreateElementNetwork:
|
|
|
|
case eTreeOpCreateElementNotNetwork:
|
2009-09-21 04:43:43 -07:00
|
|
|
delete mThree.attributes;
|
|
|
|
break;
|
2009-11-17 00:52:30 -08:00
|
|
|
case eTreeOpAppendDoctypeToDocument:
|
2009-09-21 04:43:43 -07:00
|
|
|
delete mTwo.stringPair;
|
|
|
|
break;
|
2009-11-17 00:52:30 -08:00
|
|
|
case eTreeOpFosterParentText:
|
|
|
|
case eTreeOpAppendText:
|
|
|
|
case eTreeOpAppendComment:
|
|
|
|
case eTreeOpAppendCommentToDocument:
|
2010-07-30 03:15:38 -07:00
|
|
|
case eTreeOpAddViewSourceHref:
|
2009-09-21 04:43:43 -07:00
|
|
|
delete[] mTwo.unicharPtr;
|
|
|
|
break;
|
2011-11-01 04:33:11 -07:00
|
|
|
case eTreeOpSetDocumentCharset:
|
2009-09-21 06:18:20 -07:00
|
|
|
case eTreeOpNeedsCharsetSwitchTo:
|
|
|
|
delete[] mOne.charPtr;
|
|
|
|
break;
|
2010-02-01 23:43:18 -08:00
|
|
|
case eTreeOpProcessOfflineManifest:
|
|
|
|
nsMemory::Free(mOne.unicharPtr);
|
|
|
|
break;
|
2009-09-21 04:43:43 -07:00
|
|
|
default: // keep the compiler happy
|
|
|
|
break;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
|
2009-11-17 00:52:30 -08:00
|
|
|
nsresult
|
2010-06-11 08:08:13 -07:00
|
|
|
nsHtml5TreeOperation::AppendTextToTextNode(const PRUnichar* aBuffer,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLength,
|
2009-11-17 00:52:30 -08:00
|
|
|
nsIContent* aTextNode,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aTextNode, "Got null text node.");
|
|
|
|
|
|
|
|
if (aBuilder->HaveNotified(aTextNode)) {
|
|
|
|
// This text node has already been notified on, so it's necessary to
|
|
|
|
// notify on the append
|
|
|
|
nsresult rv = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t oldLength = aTextNode->TextLength();
|
2009-11-17 00:52:30 -08:00
|
|
|
CharacterDataChangeInfo info = {
|
2011-10-17 07:59:28 -07:00
|
|
|
true,
|
2009-11-17 00:52:30 -08:00
|
|
|
oldLength,
|
|
|
|
oldLength,
|
|
|
|
aLength
|
|
|
|
};
|
|
|
|
nsNodeUtils::CharacterDataWillChange(aTextNode, &info);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = aTextNode->AppendText(aBuffer, aLength, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsNodeUtils::CharacterDataChanged(aTextNode, &info);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return aTextNode->AppendText(aBuffer, aLength, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2010-06-11 08:08:13 -07:00
|
|
|
nsHtml5TreeOperation::AppendText(const PRUnichar* aBuffer,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLength,
|
2009-11-17 00:52:30 -08:00
|
|
|
nsIContent* aParent,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIContent* lastChild = aParent->GetLastChild();
|
|
|
|
if (lastChild && lastChild->IsNodeOfType(nsINode::eTEXT)) {
|
2011-10-18 03:53:36 -07:00
|
|
|
nsHtml5OtherDocUpdate update(aParent->OwnerDoc(),
|
2009-11-17 00:52:30 -08:00
|
|
|
aBuilder->GetDocument());
|
|
|
|
return AppendTextToTextNode(aBuffer,
|
|
|
|
aLength,
|
|
|
|
lastChild,
|
|
|
|
aBuilder);
|
|
|
|
}
|
|
|
|
|
2013-04-04 05:01:08 -07:00
|
|
|
nsRefPtr<nsTextNode> text = new nsTextNode(aBuilder->GetNodeInfoManager());
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ASSERTION(text, "Infallible malloc failed?");
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = text->SetText(aBuffer, aLength, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return Append(text, aParent, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::Append(nsIContent* aNode,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIDocument* executorDoc = aBuilder->GetDocument();
|
|
|
|
NS_ASSERTION(executorDoc, "Null doc on executor");
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* parentDoc = aParent->OwnerDoc();
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ASSERTION(parentDoc, "Null owner doc on old node.");
|
|
|
|
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(executorDoc == parentDoc)) {
|
2009-11-17 00:52:30 -08:00
|
|
|
// the usual case. the parent is in the parser's doc
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = aParent->AppendChildTo(aNode, false);
|
2011-07-20 13:22:27 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aBuilder->PostPendingAppendNotification(aParent, aNode);
|
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The parent has been moved to another doc
|
|
|
|
parentDoc->BeginUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = aParent->GetChildCount();
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = aParent->AppendChildTo(aNode, false);
|
2011-07-20 13:22:27 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsNodeUtils::ContentAppended(aParent, aNode, childCount);
|
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
parentDoc->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHtml5TreeOperation::AppendToDocument(nsIContent* aNode,
|
|
|
|
nsHtml5TreeOpExecutor* aBuilder)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
|
|
|
nsIDocument* doc = aBuilder->GetDocument();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = doc->GetChildCount();
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = doc->AppendChildTo(aNode, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsNodeUtils::ContentInserted(doc, aNode, childCount);
|
2010-08-27 22:54:57 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Someone forgot to block scripts");
|
2011-04-07 23:07:28 -07:00
|
|
|
if (aNode->IsElement()) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsDocElementCreatedNotificationRunner(doc));
|
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-06-28 15:44:22 -07:00
|
|
|
nsresult
|
2009-11-06 05:06:48 -08:00
|
|
|
nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
|
|
|
|
nsIContent** aScriptElement)
|
2009-06-28 15:44:22 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
switch(mOpCode) {
|
|
|
|
case eTreeOpAppend: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
2009-11-17 00:52:30 -08:00
|
|
|
return Append(node, parent, aBuilder);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
case eTreeOpDetach: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-06-28 15:44:22 -07:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2011-08-23 05:57:29 -07:00
|
|
|
nsCOMPtr<nsIContent> parent = node->GetParent();
|
2009-06-28 15:44:22 -07:00
|
|
|
if (parent) {
|
2011-10-18 03:53:36 -07:00
|
|
|
nsHtml5OtherDocUpdate update(parent->OwnerDoc(),
|
2009-11-11 00:37:35 -08:00
|
|
|
aBuilder->GetDocument());
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pos = parent->IndexOf(node);
|
2009-06-28 15:44:22 -07:00
|
|
|
NS_ASSERTION((pos >= 0), "Element not found as child of its parent");
|
2012-03-29 14:09:07 -07:00
|
|
|
parent->RemoveChildAt(pos, true);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
2012-03-29 14:09:07 -07:00
|
|
|
return NS_OK;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
case eTreeOpAppendChildrenToNewParent: {
|
2011-08-23 05:57:29 -07:00
|
|
|
nsCOMPtr<nsIContent> node = *(mOne.node);
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* parent = *(mTwo.node);
|
2009-06-28 15:44:22 -07:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2009-11-11 00:37:35 -08:00
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsHtml5OtherDocUpdate update(parent->OwnerDoc(),
|
2009-11-11 00:37:35 -08:00
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = parent->GetChildCount();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool didAppend = false;
|
2012-01-24 23:50:07 -08:00
|
|
|
while (node->HasChildren()) {
|
|
|
|
nsCOMPtr<nsIContent> child = node->GetFirstChild();
|
2012-03-29 14:09:07 -07:00
|
|
|
node->RemoveChildAt(0, true);
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = parent->AppendChildTo(child, false);
|
2009-06-28 15:44:22 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-17 07:59:28 -07:00
|
|
|
didAppend = true;
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
if (didAppend) {
|
2010-05-10 18:12:34 -07:00
|
|
|
nsNodeUtils::ContentAppended(parent, parent->GetChildAt(childCount),
|
|
|
|
childCount);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpFosterParent: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
|
|
|
nsIContent* table = *(mThree.node);
|
|
|
|
nsIContent* foster = table->GetParent();
|
2009-11-11 00:37:35 -08:00
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
if (foster && foster->IsElement()) {
|
2009-06-28 15:44:22 -07:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2009-11-11 00:37:35 -08:00
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsHtml5OtherDocUpdate update(foster->OwnerDoc(),
|
2009-11-11 00:37:35 -08:00
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t pos = foster->IndexOf(table);
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = foster->InsertChildAt(node, pos, false);
|
2009-06-28 15:44:22 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-21 04:43:43 -07:00
|
|
|
nsNodeUtils::ContentInserted(foster, node, pos);
|
2009-11-11 00:37:35 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-11-17 00:52:30 -08:00
|
|
|
return Append(node, parent, aBuilder);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
case eTreeOpAppendToDocument: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-11-17 00:52:30 -08:00
|
|
|
return AppendToDocument(node, aBuilder);
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
case eTreeOpAddAttributes: {
|
2010-08-24 00:06:07 -07:00
|
|
|
dom::Element* node = (*(mOne.node))->AsElement();
|
2009-09-21 04:43:43 -07:00
|
|
|
nsHtml5HtmlAttributes* attributes = mTwo.attributes;
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsHtml5OtherDocUpdate update(node->OwnerDoc(),
|
2009-11-11 00:37:35 -08:00
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t len = attributes->getLength();
|
|
|
|
for (int32_t i = len; i > 0;) {
|
2009-12-23 00:32:39 -08:00
|
|
|
--i;
|
2009-09-21 04:43:43 -07:00
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
2012-10-01 01:49:01 -07:00
|
|
|
nsCOMPtr<nsIAtom> localName =
|
|
|
|
Reget(attributes->getLocalNameNoBoundsCheck(i));
|
|
|
|
int32_t nsuri = attributes->getURINoBoundsCheck(i);
|
2009-09-21 04:43:43 -07:00
|
|
|
if (!node->HasAttr(nsuri, localName)) {
|
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
2012-10-01 01:49:01 -07:00
|
|
|
node->SetAttr(nsuri,
|
|
|
|
localName,
|
|
|
|
attributes->getPrefixNoBoundsCheck(i),
|
|
|
|
*(attributes->getValueNoBoundsCheck(i)),
|
|
|
|
true);
|
2009-09-21 04:43:43 -07:00
|
|
|
// XXX what to do with nsresult?
|
2009-06-28 15:44:22 -07:00
|
|
|
}
|
|
|
|
}
|
2009-09-21 04:43:43 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2010-06-08 23:44:25 -07:00
|
|
|
case eTreeOpCreateElementNetwork:
|
|
|
|
case eTreeOpCreateElementNotNetwork: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent** target = mOne.node;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t ns = mFour.integer;
|
2009-09-21 04:43:43 -07:00
|
|
|
nsCOMPtr<nsIAtom> name = Reget(mTwo.atom);
|
|
|
|
nsHtml5HtmlAttributes* attributes = mThree.attributes;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isKeygen = (name == nsHtml5Atoms::keygen && ns == kNameSpaceID_XHTML);
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(isKeygen)) {
|
2010-02-22 04:17:30 -08:00
|
|
|
name = nsHtml5Atoms::select;
|
|
|
|
}
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
nsCOMPtr<nsIContent> newContent;
|
2011-06-14 00:56:49 -07:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo = aBuilder->GetNodeInfoManager()->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetNodeInfo(name, nullptr, ns, nsIDOMNode::ELEMENT_NODE);
|
2009-09-21 04:43:43 -07:00
|
|
|
NS_ASSERTION(nodeInfo, "Got null nodeinfo.");
|
2010-06-08 23:44:25 -07:00
|
|
|
NS_NewElement(getter_AddRefs(newContent),
|
2011-11-15 23:50:19 -08:00
|
|
|
nodeInfo.forget(),
|
2010-06-08 23:44:25 -07:00
|
|
|
(mOpCode == eTreeOpCreateElementNetwork ?
|
2010-10-25 05:17:38 -07:00
|
|
|
dom::FROM_PARSER_NETWORK
|
2012-01-20 04:03:49 -08:00
|
|
|
: (aBuilder->BelongsToStringParser() ?
|
2010-10-25 05:17:38 -07:00
|
|
|
dom::FROM_PARSER_FRAGMENT :
|
|
|
|
dom::FROM_PARSER_DOCUMENT_WRITE)));
|
2009-09-21 04:43:43 -07:00
|
|
|
NS_ASSERTION(newContent, "Element creation created null pointer.");
|
|
|
|
|
|
|
|
aBuilder->HoldElement(*target = newContent);
|
|
|
|
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(name == nsHtml5Atoms::style || name == nsHtml5Atoms::link)) {
|
2009-10-30 01:31:57 -07:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(newContent));
|
|
|
|
if (ssle) {
|
2011-10-17 07:59:28 -07:00
|
|
|
ssle->InitStyleLinkElement(false);
|
|
|
|
ssle->SetEnableUpdates(false);
|
2009-10-30 01:31:57 -07:00
|
|
|
}
|
2012-10-26 06:32:10 -07:00
|
|
|
} else if (MOZ_UNLIKELY(isKeygen)) {
|
2010-02-22 04:17:30 -08:00
|
|
|
// Adapted from CNavDTD
|
|
|
|
nsCOMPtr<nsIFormProcessor> theFormProcessor =
|
|
|
|
do_GetService(kFormProcessorCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsTArray<nsString> theContent;
|
|
|
|
nsAutoString theAttribute;
|
|
|
|
|
|
|
|
(void) theFormProcessor->ProvideContent(NS_LITERAL_STRING("select"),
|
|
|
|
theContent,
|
|
|
|
theAttribute);
|
|
|
|
|
|
|
|
newContent->SetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::moztype,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
2010-02-22 04:17:30 -08:00
|
|
|
theAttribute,
|
2011-10-17 07:59:28 -07:00
|
|
|
false);
|
2010-02-22 04:17:30 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> optionNodeInfo =
|
|
|
|
aBuilder->GetNodeInfoManager()->GetNodeInfo(nsHtml5Atoms::option,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-02-22 04:17:30 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < theContent.Length(); ++i) {
|
2010-02-22 04:17:30 -08:00
|
|
|
nsCOMPtr<nsIContent> optionElt;
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = optionNodeInfo;
|
2010-02-22 04:17:30 -08:00
|
|
|
NS_NewElement(getter_AddRefs(optionElt),
|
2010-07-23 02:49:57 -07:00
|
|
|
ni.forget(),
|
2010-10-25 05:17:38 -07:00
|
|
|
(mOpCode == eTreeOpCreateElementNetwork ?
|
|
|
|
dom::FROM_PARSER_NETWORK
|
2012-01-20 04:03:49 -08:00
|
|
|
: (aBuilder->BelongsToStringParser() ?
|
2010-10-25 05:17:38 -07:00
|
|
|
dom::FROM_PARSER_FRAGMENT :
|
|
|
|
dom::FROM_PARSER_DOCUMENT_WRITE)));
|
2013-04-04 05:01:08 -07:00
|
|
|
nsRefPtr<nsTextNode> optionText =
|
|
|
|
new nsTextNode(aBuilder->GetNodeInfoManager());
|
2011-10-17 07:59:28 -07:00
|
|
|
(void) optionText->SetText(theContent[i], false);
|
|
|
|
optionElt->AppendChildTo(optionText, false);
|
|
|
|
newContent->AppendChildTo(optionElt, false);
|
|
|
|
newContent->DoneAddingChildren(false);
|
2010-02-22 04:17:30 -08:00
|
|
|
}
|
2009-10-30 01:31:57 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
if (!attributes) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t len = attributes->getLength();
|
|
|
|
for (int32_t i = len; i > 0;) {
|
2009-12-23 00:32:39 -08:00
|
|
|
--i;
|
2009-09-21 04:43:43 -07:00
|
|
|
// prefix doesn't need regetting. it is always null or a static atom
|
|
|
|
// local name is never null
|
2012-10-01 01:49:01 -07:00
|
|
|
nsCOMPtr<nsIAtom> localName =
|
|
|
|
Reget(attributes->getLocalNameNoBoundsCheck(i));
|
2010-07-30 03:08:36 -07:00
|
|
|
if (ns == kNameSpaceID_XHTML &&
|
|
|
|
nsHtml5Atoms::a == name &&
|
|
|
|
nsHtml5Atoms::name == localName) {
|
|
|
|
// This is an HTML5-incompliant Geckoism.
|
|
|
|
// Remove when fixing bug 582361
|
2012-10-01 01:49:01 -07:00
|
|
|
NS_ConvertUTF16toUTF8 cname(*(attributes->getValueNoBoundsCheck(i)));
|
2010-07-30 03:08:36 -07:00
|
|
|
NS_ConvertUTF8toUTF16 uv(nsUnescape(cname.BeginWriting()));
|
2012-10-01 01:49:01 -07:00
|
|
|
newContent->SetAttr(attributes->getURINoBoundsCheck(i),
|
|
|
|
localName,
|
|
|
|
attributes->getPrefixNoBoundsCheck(i),
|
|
|
|
uv,
|
|
|
|
false);
|
2010-07-30 03:08:36 -07:00
|
|
|
} else {
|
2012-10-01 01:49:01 -07:00
|
|
|
newContent->SetAttr(attributes->getURINoBoundsCheck(i),
|
|
|
|
localName,
|
|
|
|
attributes->getPrefixNoBoundsCheck(i),
|
|
|
|
*(attributes->getValueNoBoundsCheck(i)),
|
|
|
|
false);
|
2010-07-30 03:08:36 -07:00
|
|
|
}
|
2009-09-21 04:43:43 -07:00
|
|
|
}
|
2010-02-22 04:17:30 -08:00
|
|
|
|
2009-09-21 04:43:43 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpSetFormElement: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsIContent* parent = *(mTwo.node);
|
|
|
|
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(node));
|
2009-10-21 05:28:18 -07:00
|
|
|
// NS_ASSERTION(formControl, "Form-associated element did not implement nsIFormControl.");
|
2010-08-23 18:11:04 -07:00
|
|
|
// TODO: uncomment the above line when <keygen> (bug 101019) is supported by Gecko
|
2009-09-21 04:43:43 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> formElement(do_QueryInterface(parent));
|
|
|
|
NS_ASSERTION(formElement, "The form element doesn't implement nsIDOMHTMLFormElement.");
|
2010-08-23 18:11:04 -07:00
|
|
|
// avoid crashing on <keygen>
|
|
|
|
if (formControl &&
|
|
|
|
!node->HasAttr(kNameSpaceID_None, nsGkAtoms::form)) {
|
2009-09-21 04:43:43 -07:00
|
|
|
formControl->SetForm(formElement);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
case eTreeOpAppendText: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = mFour.integer;
|
2009-11-17 00:52:30 -08:00
|
|
|
return AppendText(buffer, length, parent, aBuilder);
|
|
|
|
}
|
2010-06-11 08:08:13 -07:00
|
|
|
case eTreeOpAppendIsindexPrompt: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
|
|
|
nsXPIDLString prompt;
|
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
"IsIndexPromptWithSpace", prompt);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len = prompt.Length();
|
2010-06-11 08:08:13 -07:00
|
|
|
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);
|
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
case eTreeOpFosterParentText: {
|
|
|
|
nsIContent* stackParent = *mOne.node;
|
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = mFour.integer;
|
2009-11-17 00:52:30 -08:00
|
|
|
nsIContent* table = *mThree.node;
|
|
|
|
|
|
|
|
nsIContent* foster = table->GetParent();
|
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
if (foster && foster->IsElement()) {
|
2009-11-17 00:52:30 -08:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsHtml5OtherDocUpdate update(foster->OwnerDoc(),
|
2009-11-17 00:52:30 -08:00
|
|
|
aBuilder->GetDocument());
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t pos = foster->IndexOf(table);
|
2012-01-24 23:50:07 -08:00
|
|
|
|
|
|
|
nsIContent* previousSibling = table->GetPreviousSibling();
|
2009-11-17 00:52:30 -08:00
|
|
|
if (previousSibling && previousSibling->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
return AppendTextToTextNode(buffer,
|
|
|
|
length,
|
|
|
|
previousSibling,
|
|
|
|
aBuilder);
|
|
|
|
}
|
|
|
|
|
2013-04-04 05:01:08 -07:00
|
|
|
nsRefPtr<nsTextNode> text =
|
|
|
|
new nsTextNode(aBuilder->GetNodeInfoManager());
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ASSERTION(text, "Infallible malloc failed?");
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = text->SetText(buffer, length, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = foster->InsertChildAt(text, pos, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsNodeUtils::ContentInserted(foster, text, pos);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppendText(buffer, length, stackParent, aBuilder);
|
|
|
|
}
|
|
|
|
case eTreeOpAppendComment: {
|
|
|
|
nsIContent* parent = *mOne.node;
|
2009-09-21 04:43:43 -07:00
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t length = mFour.integer;
|
2009-09-21 04:43:43 -07:00
|
|
|
|
2013-04-04 05:02:22 -07:00
|
|
|
nsRefPtr<dom::Comment> comment =
|
|
|
|
new dom::Comment(aBuilder->GetNodeInfoManager());
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ASSERTION(comment, "Infallible malloc failed?");
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = comment->SetText(buffer, length, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-21 04:43:43 -07:00
|
|
|
|
2009-11-17 00:52:30 -08:00
|
|
|
return Append(comment, parent, aBuilder);
|
2009-09-21 04:43:43 -07:00
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
case eTreeOpAppendCommentToDocument: {
|
2009-09-21 04:43:43 -07:00
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t length = mFour.integer;
|
2009-09-21 04:43:43 -07:00
|
|
|
|
2013-04-04 05:02:22 -07:00
|
|
|
nsRefPtr<dom::Comment> comment =
|
|
|
|
new dom::Comment(aBuilder->GetNodeInfoManager());
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ASSERTION(comment, "Infallible malloc failed?");
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = comment->SetText(buffer, length, false);
|
2009-11-17 00:52:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-21 04:43:43 -07:00
|
|
|
|
2009-11-17 00:52:30 -08:00
|
|
|
return AppendToDocument(comment, aBuilder);
|
2009-09-21 04:43:43 -07:00
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
case eTreeOpAppendDoctypeToDocument: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsCOMPtr<nsIAtom> name = Reget(mOne.atom);
|
|
|
|
nsHtml5TreeOperationStringPair* pair = mTwo.stringPair;
|
|
|
|
nsString publicId;
|
|
|
|
nsString systemId;
|
|
|
|
pair->Get(publicId, systemId);
|
|
|
|
|
|
|
|
// Adapted from nsXMLContentSink
|
|
|
|
// Create a new doctype node
|
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
|
|
|
nsAutoString voidString;
|
2011-10-17 07:59:28 -07:00
|
|
|
voidString.SetIsVoid(true);
|
2009-09-21 04:43:43 -07:00
|
|
|
NS_NewDOMDocumentType(getter_AddRefs(docType),
|
|
|
|
aBuilder->GetNodeInfoManager(),
|
|
|
|
name,
|
|
|
|
publicId,
|
|
|
|
systemId,
|
|
|
|
voidString);
|
|
|
|
NS_ASSERTION(docType, "Doctype creation failed.");
|
|
|
|
nsCOMPtr<nsIContent> asContent = do_QueryInterface(docType);
|
2009-11-17 00:52:30 -08:00
|
|
|
return AppendToDocument(asContent, aBuilder);
|
2009-09-21 04:43:43 -07:00
|
|
|
}
|
2013-03-26 00:15:23 -07:00
|
|
|
case eTreeOpGetDocumentFragmentForTemplate: {
|
|
|
|
dom::HTMLTemplateElement* tempElem =
|
|
|
|
static_cast<dom::HTMLTemplateElement*>(*mOne.node);
|
|
|
|
nsRefPtr<dom::DocumentFragment> frag = tempElem->Content();
|
|
|
|
*mTwo.node = frag.get();
|
|
|
|
return rv;
|
|
|
|
}
|
2011-09-28 05:45:17 -07:00
|
|
|
case eTreeOpMarkAsBroken: {
|
2012-03-21 05:39:25 -07:00
|
|
|
aBuilder->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
|
2011-09-28 05:45:17 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-21 04:43:43 -07:00
|
|
|
case eTreeOpRunScript: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2009-09-21 06:18:20 -07:00
|
|
|
nsAHtml5TreeBuilderState* snapshot = mTwo.state;
|
|
|
|
if (snapshot) {
|
2011-11-01 04:33:11 -07:00
|
|
|
aBuilder->InitializeDocWriteParserState(snapshot, mFour.integer);
|
2009-09-21 06:18:20 -07:00
|
|
|
}
|
2009-11-06 05:06:48 -08:00
|
|
|
*aScriptElement = node;
|
2009-06-28 15:44:22 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-12-14 05:51:15 -08:00
|
|
|
case eTreeOpRunScriptAsyncDefer: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
aBuilder->RunScript(node);
|
|
|
|
return rv;
|
|
|
|
}
|
2012-06-20 00:05:39 -07:00
|
|
|
case eTreeOpPreventScriptExecution: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(node);
|
|
|
|
MOZ_ASSERT(sele);
|
|
|
|
sele->PreventExecution();
|
|
|
|
return rv;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
case eTreeOpDoneAddingChildren: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
node->DoneAddingChildren(aBuilder->HaveNotified(node));
|
2009-06-28 15:44:22 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpDoneCreatingElement: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
node->DoneCreatingElement();
|
2009-06-28 15:44:22 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-11-06 05:06:48 -08:00
|
|
|
case eTreeOpFlushPendingAppendNotifications: {
|
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
|
|
|
return rv;
|
|
|
|
}
|
2011-11-01 04:33:11 -07:00
|
|
|
case eTreeOpSetDocumentCharset: {
|
|
|
|
char* str = mOne.charPtr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t charsetSource = mFour.integer;
|
2011-11-01 04:33:11 -07:00
|
|
|
nsDependentCString dependentString(str);
|
|
|
|
aBuilder->SetDocumentCharsetAndSource(dependentString, charsetSource);
|
|
|
|
return rv;
|
|
|
|
}
|
2009-09-21 06:18:20 -07:00
|
|
|
case eTreeOpNeedsCharsetSwitchTo: {
|
|
|
|
char* str = mOne.charPtr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t charsetSource = mFour.integer;
|
|
|
|
int32_t lineNumber = mTwo.integer;
|
|
|
|
aBuilder->NeedsCharsetSwitchTo(str, charsetSource, (uint32_t)lineNumber);
|
2009-09-21 06:18:20 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
case eTreeOpUpdateStyleSheet: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
2009-10-30 01:31:57 -07:00
|
|
|
aBuilder->FlushPendingAppendNotifications();
|
2009-09-21 04:43:43 -07:00
|
|
|
aBuilder->UpdateStyleSheet(node);
|
2009-06-28 15:44:22 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpProcessMeta: {
|
2009-09-21 04:43:43 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
rv = aBuilder->ProcessMETATag(node);
|
2009-06-28 15:44:22 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpProcessOfflineManifest: {
|
2010-02-01 23:43:18 -08:00
|
|
|
PRUnichar* str = mOne.unicharPtr;
|
|
|
|
nsDependentString dependentString(str);
|
|
|
|
aBuilder->ProcessOfflineManifest(dependentString);
|
2009-09-21 04:43:43 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case eTreeOpMarkMalformedIfScript: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(node);
|
|
|
|
if (sele) {
|
|
|
|
// Make sure to serialize this script correctly, for nice round tripping.
|
|
|
|
sele->SetIsMalformed();
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-21 06:18:20 -07:00
|
|
|
case eTreeOpStreamEnded: {
|
2011-10-17 07:59:28 -07:00
|
|
|
aBuilder->DidBuildModel(false); // this causes a notifications flush anyway
|
2009-09-21 06:18:20 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-06-28 15:44:22 -07:00
|
|
|
case eTreeOpStartLayout: {
|
2009-11-06 05:06:48 -08:00
|
|
|
aBuilder->StartLayout(); // this causes a notification flush anyway
|
2009-06-28 15:44:22 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-18 02:21:47 -07:00
|
|
|
case eTreeOpDocumentMode: {
|
2010-03-15 05:04:42 -07:00
|
|
|
aBuilder->SetDocumentMode(mOne.mode);
|
2009-09-18 02:21:47 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-10-28 06:48:37 -07: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 04:33:11 -07:00
|
|
|
ssle->SetLineNumber(mFour.integer);
|
2009-10-28 06:48:37 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2009-11-17 00:52:30 -08:00
|
|
|
case eTreeOpSetScriptLineNumberAndFreeze: {
|
2009-10-28 06:48:37 -07:00
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(node);
|
|
|
|
NS_ASSERTION(sele, "Node didn't QI to script.");
|
2011-11-01 04:33:11 -07:00
|
|
|
sele->SetScriptLineNumber(mFour.integer);
|
2009-11-17 00:52:30 -08:00
|
|
|
sele->FreezeUriAsyncDefer();
|
2009-10-28 06:48:37 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2010-07-18 15:07:54 -07:00
|
|
|
case eTreeOpSvgLoad: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(node);
|
|
|
|
if (NS_FAILED(NS_DispatchToMainThread(event))) {
|
|
|
|
NS_WARNING("failed to dispatch svg load dispatcher");
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2012-03-24 04:34:42 -07:00
|
|
|
case eTreeOpMaybeComplainAboutCharset: {
|
|
|
|
char* msgId = mOne.charPtr;
|
|
|
|
bool error = mTwo.integer;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lineNumber = mThree.integer;
|
|
|
|
aBuilder->MaybeComplainAboutCharset(msgId, error, (uint32_t)lineNumber);
|
2012-03-24 04:34:42 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2010-07-30 03:15:38 -07:00
|
|
|
case eTreeOpAddClass: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
PRUnichar* str = mTwo.unicharPtr;
|
|
|
|
nsDependentString depStr(str);
|
2011-11-01 04:33:11 -07:00
|
|
|
// See viewsource.css for the possible classes
|
2011-11-01 04:33:11 -07: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);
|
|
|
|
}
|
2010-07-30 03:15:38 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2011-11-01 04:33:11 -07:00
|
|
|
case eTreeOpAddLineNumberId: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lineNumber = mFour.integer;
|
2011-11-01 04:33:11 -07:00
|
|
|
nsAutoString val(NS_LITERAL_STRING("line"));
|
|
|
|
val.AppendInt(lineNumber);
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::id, val, true);
|
|
|
|
return rv;
|
|
|
|
}
|
2010-07-30 03:15:38 -07:00
|
|
|
case eTreeOpAddViewSourceHref: {
|
|
|
|
nsIContent* node = *mOne.node;
|
|
|
|
PRUnichar* buffer = mTwo.unicharPtr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t length = mFour.integer;
|
2010-07-30 03:15:38 -07:00
|
|
|
|
|
|
|
nsDependentString relative(buffer, length);
|
|
|
|
|
|
|
|
nsIDocument* doc = aBuilder->GetDocument();
|
|
|
|
|
|
|
|
const nsCString& charset = doc->GetDocumentCharacterSet();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri),
|
|
|
|
relative,
|
|
|
|
charset.get(),
|
|
|
|
aBuilder->GetViewSourceBaseURI());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 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 04:33:11 -07:00
|
|
|
if (NS_FAILED(rv) || openingExecutesScript) {
|
2010-07-30 03:15:38 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString viewSourceUrl;
|
2010-07-30 03:15:38 -07: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-01 19:35:17 -07:00
|
|
|
nsAutoCString spec;
|
2010-07-30 03:15:38 -07: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 04:33:11 -07:00
|
|
|
case eTreeOpAddError: {
|
|
|
|
nsIContent* node = *(mOne.node);
|
|
|
|
char* msgId = mTwo.charPtr;
|
2011-11-01 04:33:11 -07:00
|
|
|
nsCOMPtr<nsIAtom> atom = Reget(mThree.atom);
|
|
|
|
nsCOMPtr<nsIAtom> otherAtom = Reget(mFour.atom);
|
2011-11-01 04:33:11 -07:00
|
|
|
// See viewsource.css for the possible classes in addition to "error".
|
2011-11-01 04:33:11 -07:00
|
|
|
nsAutoString klass;
|
|
|
|
node->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass);
|
|
|
|
if (!klass.IsEmpty()) {
|
|
|
|
klass.Append(NS_LITERAL_STRING(" error"));
|
|
|
|
node->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass, true);
|
|
|
|
} else {
|
|
|
|
node->SetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::_class,
|
|
|
|
NS_LITERAL_STRING("error"),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLString message;
|
2011-11-01 04:33:11 -07:00
|
|
|
if (otherAtom) {
|
|
|
|
const PRUnichar* params[] = { atom->GetUTF16String(),
|
|
|
|
otherAtom->GetUTF16String() };
|
|
|
|
rv = nsContentUtils::FormatLocalizedString(
|
2012-03-08 18:22:57 -08:00
|
|
|
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, message);
|
2011-11-01 04:33:11 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else if (atom) {
|
|
|
|
const PRUnichar* params[] = { atom->GetUTF16String() };
|
|
|
|
rv = nsContentUtils::FormatLocalizedString(
|
2012-03-08 18:22:57 -08:00
|
|
|
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, params, message);
|
2011-11-01 04:33:11 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
rv = nsContentUtils::GetLocalizedString(
|
|
|
|
nsContentUtils::eHTMLPARSER_PROPERTIES, msgId, message);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2011-11-01 04:33:11 -07:00
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
node->GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
|
|
|
if (!title.IsEmpty()) {
|
2011-11-01 04:33:11 -07:00
|
|
|
title.Append('\n');
|
2011-11-01 04:33:11 -07: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 15:44:22 -07:00
|
|
|
default: {
|
|
|
|
NS_NOTREACHED("Bogus tree op");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv; // keep compiler happy
|
|
|
|
}
|
2013-03-26 00:15:23 -07:00
|
|
|
|