2013-03-01 02:53:49 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +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/. */
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2006-03-31 08:00:42 +00:00
|
|
|
/*
|
|
|
|
* Class that represents a prefix/namespace/localName triple; a single
|
|
|
|
* nodeinfo is shared by all elements in a document that have that
|
|
|
|
* prefix, namespace, and localName.
|
|
|
|
*/
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
|
|
|
#include "mozilla/dom/NodeInfoInlines.h"
|
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-10-26 13:32:10 +00:00
|
|
|
#include "mozilla/Likely.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIAtom.h"
|
2004-04-01 19:44:17 +00:00
|
|
|
#include "nsDOMString.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2002-11-29 23:44:07 +00:00
|
|
|
#include "nsContentUtils.h"
|
2003-01-05 09:16:14 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2006-07-11 09:26:13 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2010-09-15 04:46:40 +00:00
|
|
|
#include "prprf.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2013-01-25 22:11:13 +00:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2014-06-20 02:01:40 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2006-07-11 09:26:13 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
2014-06-20 02:01:40 +00:00
|
|
|
using mozilla::dom::NodeInfo;
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::~NodeInfo()
|
2005-01-31 16:18:31 +00:00
|
|
|
{
|
2011-05-05 16:26:32 +00:00
|
|
|
mOwnerManager->RemoveNodeInfo(this);
|
2005-01-31 16:18:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::NodeInfo(nsIAtom *aName, nsIAtom *aPrefix, int32_t aNamespaceID,
|
|
|
|
uint16_t aNodeType, nsIAtom* aExtraName,
|
|
|
|
nsNodeInfoManager *aOwnerManager)
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2012-08-16 15:07:55 +00:00
|
|
|
CheckValidNodeInfo(aNodeType, aName, aNamespaceID, aExtraName);
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aOwnerManager, "Invalid aOwnerManager");
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2011-06-14 07:56:49 +00:00
|
|
|
// Initialize mInner
|
2015-04-19 15:06:54 +00:00
|
|
|
mInner.mName = aName;
|
|
|
|
mInner.mPrefix = aPrefix;
|
2000-05-08 14:29:44 +00:00
|
|
|
mInner.mNamespaceID = aNamespaceID;
|
2011-06-14 07:56:49 +00:00
|
|
|
mInner.mNodeType = aNodeType;
|
2014-04-10 14:05:20 +00:00
|
|
|
mOwnerManager = aOwnerManager;
|
2015-04-19 15:06:54 +00:00
|
|
|
mInner.mExtraName = aExtraName;
|
2011-05-05 16:26:32 +00:00
|
|
|
|
2011-06-15 00:58:57 +00:00
|
|
|
mDocument = aOwnerManager->GetDocument();
|
|
|
|
|
2011-05-05 16:26:32 +00:00
|
|
|
// Now compute our cached members.
|
|
|
|
|
|
|
|
// Qualified name. If we have no prefix, use ToString on
|
|
|
|
// mInner.mName so that we get to share its buffer.
|
|
|
|
if (aPrefix) {
|
2011-06-14 07:56:49 +00:00
|
|
|
mQualifiedName = nsDependentAtomString(mInner.mPrefix) +
|
|
|
|
NS_LITERAL_STRING(":") +
|
|
|
|
nsDependentAtomString(mInner.mName);
|
2011-05-05 16:26:32 +00:00
|
|
|
} else {
|
|
|
|
mInner.mName->ToString(mQualifiedName);
|
|
|
|
}
|
|
|
|
|
2012-10-09 12:31:24 +00:00
|
|
|
MOZ_ASSERT_IF(aNodeType != nsIDOMNode::ELEMENT_NODE &&
|
|
|
|
aNodeType != nsIDOMNode::ATTRIBUTE_NODE &&
|
|
|
|
aNodeType != UINT16_MAX,
|
|
|
|
aNamespaceID == kNameSpaceID_None && !aPrefix);
|
|
|
|
|
2011-06-14 07:56:49 +00:00
|
|
|
switch (aNodeType) {
|
|
|
|
case nsIDOMNode::ELEMENT_NODE:
|
|
|
|
case nsIDOMNode::ATTRIBUTE_NODE:
|
2011-06-14 07:56:49 +00:00
|
|
|
// Correct the case for HTML
|
|
|
|
if (aNodeType == nsIDOMNode::ELEMENT_NODE &&
|
|
|
|
aNamespaceID == kNameSpaceID_XHTML && GetDocument() &&
|
2015-03-03 11:08:59 +00:00
|
|
|
GetDocument()->IsHTMLDocument()) {
|
2011-06-14 07:56:49 +00:00
|
|
|
nsContentUtils::ASCIIToUpper(mQualifiedName, mNodeName);
|
|
|
|
} else {
|
|
|
|
mNodeName = mQualifiedName;
|
|
|
|
}
|
2011-06-14 07:56:49 +00:00
|
|
|
mInner.mName->ToString(mLocalName);
|
|
|
|
break;
|
|
|
|
case nsIDOMNode::TEXT_NODE:
|
|
|
|
case nsIDOMNode::CDATA_SECTION_NODE:
|
|
|
|
case nsIDOMNode::COMMENT_NODE:
|
|
|
|
case nsIDOMNode::DOCUMENT_NODE:
|
|
|
|
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
|
|
|
|
mInner.mName->ToString(mNodeName);
|
|
|
|
SetDOMStringToNull(mLocalName);
|
|
|
|
break;
|
|
|
|
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
|
|
|
|
case nsIDOMNode::DOCUMENT_TYPE_NODE:
|
|
|
|
mInner.mExtraName->ToString(mNodeName);
|
|
|
|
SetDOMStringToNull(mLocalName);
|
|
|
|
break;
|
|
|
|
default:
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aNodeType == UINT16_MAX, "Unknown node type");
|
2011-06-14 07:56:49 +00:00
|
|
|
}
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(NodeInfo)
|
2013-08-02 01:29:05 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(NodeInfo)
|
2009-02-27 14:48:26 +00:00
|
|
|
|
2015-06-17 10:44:27 +00:00
|
|
|
static const char* kNodeInfoNSURIs[] = {
|
2009-02-27 14:48:26 +00:00
|
|
|
" ([none])",
|
|
|
|
" (xmlns)",
|
|
|
|
" (xml)",
|
|
|
|
" (xhtml)",
|
|
|
|
" (XLink)",
|
|
|
|
" (XSLT)",
|
|
|
|
" (XBL)",
|
|
|
|
" (MathML)",
|
|
|
|
" (RDF)",
|
|
|
|
" (XUL)"
|
|
|
|
};
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(NodeInfo)
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
2009-02-27 14:48:26 +00:00
|
|
|
char name[72];
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t nsid = tmp->NamespaceID();
|
2009-02-27 14:48:26 +00:00
|
|
|
nsAtomCString localName(tmp->NameAtom());
|
2015-06-17 10:44:27 +00:00
|
|
|
if (nsid < ArrayLength(kNodeInfoNSURIs)) {
|
|
|
|
PR_snprintf(name, sizeof(name), "NodeInfo%s %s", kNodeInfoNSURIs[nsid],
|
2009-02-27 14:48:26 +00:00
|
|
|
localName.get());
|
|
|
|
}
|
|
|
|
else {
|
2014-06-20 02:01:40 +00:00
|
|
|
PR_snprintf(name, sizeof(name), "NodeInfo %s", localName.get());
|
2009-02-27 14:48:26 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 17:41:04 +00:00
|
|
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
|
2009-02-27 14:48:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(NodeInfo, tmp->mRefCnt.get())
|
2009-02-27 14:48:26 +00:00
|
|
|
}
|
|
|
|
|
2014-04-10 14:05:20 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwnerManager)
|
2008-03-28 14:09:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(NodeInfo)
|
2013-01-25 22:11:13 +00:00
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->CanSkip();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(NodeInfo)
|
2013-01-25 22:11:13 +00:00
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->CanSkip();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(NodeInfo)
|
2013-01-25 22:11:13 +00:00
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->CanSkip();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(NodeInfo, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(NodeInfo, Release)
|
|
|
|
|
|
|
|
void
|
|
|
|
NodeInfo::GetName(nsAString& aName) const
|
|
|
|
{
|
|
|
|
mInner.mName->ToString(aName);
|
|
|
|
}
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
void
|
|
|
|
NodeInfo::GetPrefix(nsAString& aPrefix) const
|
|
|
|
{
|
|
|
|
if (mInner.mPrefix) {
|
|
|
|
mInner.mPrefix->ToString(aPrefix);
|
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aPrefix);
|
|
|
|
}
|
|
|
|
}
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2013-01-29 22:53:52 +00:00
|
|
|
void
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::GetNamespaceURI(nsAString& aNameSpaceURI) const
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
|
|
|
if (mInner.mNamespaceID > 0) {
|
2013-01-29 22:53:52 +00:00
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(mInner.mNamespaceID,
|
|
|
|
aNameSpaceURI);
|
|
|
|
// How can we possibly end up with a bogus namespace ID here?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2000-05-08 14:29:44 +00:00
|
|
|
} else {
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aNameSpaceURI);
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const
|
2000-05-14 18:34:35 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nsid =
|
2005-09-11 11:24:16 +00:00
|
|
|
nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI);
|
2000-05-14 18:34:35 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
return mozilla::dom::NodeInfo::NamespaceEquals(nsid);
|
2000-05-14 18:34:35 +00:00
|
|
|
}
|
|
|
|
|
2003-10-30 13:47:29 +00:00
|
|
|
void
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::DeleteCycleCollectable()
|
2003-10-30 13:47:29 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsNodeInfoManager> kungFuDeathGrip = mOwnerManager;
|
2013-03-01 02:53:49 +00:00
|
|
|
delete this;
|
2003-10-30 13:47:29 +00:00
|
|
|
}
|
2013-01-25 22:11:13 +00:00
|
|
|
|
|
|
|
bool
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::CanSkip()
|
2013-01-25 22:11:13 +00:00
|
|
|
{
|
|
|
|
return mDocument &&
|
|
|
|
nsCCUncollectableMarker::InGeneration(mDocument->GetMarkedCCGeneration());
|
|
|
|
}
|