2013-03-01 06:53:49 +04: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 15:12:37 +04: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 18:29:44 +04:00
|
|
|
|
2006-03-31 12:00:42 +04: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 06:01:40 +04:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
|
|
|
#include "mozilla/dom/NodeInfoInlines.h"
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2000-05-08 18:29:44 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2004-04-01 23:44:17 +04:00
|
|
|
#include "nsDOMString.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2018-01-30 07:10:53 +03:00
|
|
|
#include "nsINode.h"
|
2002-11-30 02:44:07 +03:00
|
|
|
#include "nsContentUtils.h"
|
2003-01-05 12:16:14 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2013-01-26 02:11:13 +04:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2006-07-11 13:26:13 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2014-06-20 06:01:40 +04:00
|
|
|
using mozilla::dom::NodeInfo;
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfo::~NodeInfo() {
|
2011-05-05 20:26:32 +04:00
|
|
|
mOwnerManager->RemoveNodeInfo(this);
|
2017-07-25 00:29:08 +03:00
|
|
|
|
|
|
|
// We can't use NS_IF_RELEASE because mName is const.
|
|
|
|
if (mInner.mName) {
|
|
|
|
mInner.mName->Release();
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mInner.mPrefix);
|
|
|
|
NS_IF_RELEASE(mInner.mExtraName);
|
2005-01-31 19:18:31 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
NodeInfo::NodeInfo(nsAtom* aName, nsAtom* aPrefix, int32_t aNamespaceID,
|
|
|
|
uint16_t aNodeType, nsAtom* aExtraName,
|
2014-06-20 06:01:40 +04:00
|
|
|
nsNodeInfoManager* aOwnerManager)
|
2017-07-21 22:43:18 +03:00
|
|
|
: mDocument(aOwnerManager->GetDocument()),
|
|
|
|
mInner(aName, aPrefix, aNamespaceID, aNodeType, aExtraName),
|
|
|
|
mOwnerManager(aOwnerManager) {
|
2012-08-16 19:07:55 +04:00
|
|
|
CheckValidNodeInfo(aNodeType, aName, aNamespaceID, aExtraName);
|
2011-06-15 04:58:57 +04:00
|
|
|
|
2017-07-25 00:29:08 +03:00
|
|
|
NS_IF_ADDREF(mInner.mName);
|
|
|
|
NS_IF_ADDREF(mInner.mPrefix);
|
|
|
|
NS_IF_ADDREF(mInner.mExtraName);
|
|
|
|
|
2011-05-05 20:26:32 +04: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 11:56:49 +04:00
|
|
|
mQualifiedName = nsDependentAtomString(mInner.mPrefix) +
|
|
|
|
NS_LITERAL_STRING(":") +
|
|
|
|
nsDependentAtomString(mInner.mName);
|
2011-05-05 20:26:32 +04:00
|
|
|
} else {
|
|
|
|
mInner.mName->ToString(mQualifiedName);
|
|
|
|
}
|
|
|
|
|
2018-01-30 07:10:53 +03:00
|
|
|
MOZ_ASSERT_IF(aNodeType != nsINode::ELEMENT_NODE &&
|
|
|
|
aNodeType != nsINode::ATTRIBUTE_NODE &&
|
2012-10-09 16:31:24 +04:00
|
|
|
aNodeType != UINT16_MAX,
|
|
|
|
aNamespaceID == kNameSpaceID_None && !aPrefix);
|
|
|
|
|
2011-06-14 11:56:49 +04:00
|
|
|
switch (aNodeType) {
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::ELEMENT_NODE:
|
|
|
|
case nsINode::ATTRIBUTE_NODE:
|
2011-06-14 11:56:49 +04:00
|
|
|
// Correct the case for HTML
|
2018-01-30 07:10:53 +03:00
|
|
|
if (aNodeType == nsINode::ELEMENT_NODE &&
|
2011-06-14 11:56:49 +04:00
|
|
|
aNamespaceID == kNameSpaceID_XHTML && GetDocument() &&
|
2015-03-03 14:08:59 +03:00
|
|
|
GetDocument()->IsHTMLDocument()) {
|
2011-06-14 11:56:49 +04:00
|
|
|
nsContentUtils::ASCIIToUpper(mQualifiedName, mNodeName);
|
|
|
|
} else {
|
|
|
|
mNodeName = mQualifiedName;
|
|
|
|
}
|
2011-06-14 11:56:49 +04:00
|
|
|
mInner.mName->ToString(mLocalName);
|
|
|
|
break;
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::TEXT_NODE:
|
|
|
|
case nsINode::CDATA_SECTION_NODE:
|
|
|
|
case nsINode::COMMENT_NODE:
|
|
|
|
case nsINode::DOCUMENT_NODE:
|
|
|
|
case nsINode::DOCUMENT_FRAGMENT_NODE:
|
2011-06-14 11:56:49 +04:00
|
|
|
mInner.mName->ToString(mNodeName);
|
|
|
|
SetDOMStringToNull(mLocalName);
|
|
|
|
break;
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::PROCESSING_INSTRUCTION_NODE:
|
|
|
|
case nsINode::DOCUMENT_TYPE_NODE:
|
2011-06-14 11:56:49 +04:00
|
|
|
mInner.mExtraName->ToString(mNodeName);
|
|
|
|
SetDOMStringToNull(mLocalName);
|
|
|
|
break;
|
|
|
|
default:
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aNodeType == UINT16_MAX, "Unknown node type");
|
2011-06-14 11:56:49 +04:00
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(NodeInfo)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(NodeInfo)
|
2009-02-27 17:48:26 +03:00
|
|
|
|
2015-06-17 13:44:27 +03:00
|
|
|
static const char* kNodeInfoNSURIs[] = {
|
2009-02-27 17:48:26 +03:00
|
|
|
" ([none])", " (xmlns)", " (xml)", " (xhtml)", " (XLink)",
|
|
|
|
" (XSLT)", " (XBL)", " (MathML)", " (RDF)", " (XUL)"};
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(NodeInfo)
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
2009-02-27 17:48:26 +03:00
|
|
|
char name[72];
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsid = tmp->NamespaceID();
|
2009-02-27 17:48:26 +03:00
|
|
|
nsAtomCString localName(tmp->NameAtom());
|
2015-06-17 13:44:27 +03:00
|
|
|
if (nsid < ArrayLength(kNodeInfoNSURIs)) {
|
2016-08-15 09:44:00 +03:00
|
|
|
SprintfLiteral(name, "NodeInfo%s %s", kNodeInfoNSURIs[nsid],
|
|
|
|
localName.get());
|
2009-02-27 17:48:26 +03:00
|
|
|
} else {
|
2016-08-15 09:44:00 +03:00
|
|
|
SprintfLiteral(name, "NodeInfo %s", localName.get());
|
2009-02-27 17:48:26 +03:00
|
|
|
}
|
|
|
|
|
2012-08-27 21:41:04 +04:00
|
|
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
|
2009-02-27 17:48:26 +03:00
|
|
|
} else {
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(NodeInfo, tmp->mRefCnt.get())
|
2009-02-27 17:48:26 +03:00
|
|
|
}
|
|
|
|
|
2014-04-10 18:05:20 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwnerManager)
|
2008-03-28 17:09:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(NodeInfo)
|
2013-01-26 02:11:13 +04:00
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->CanSkip();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(NodeInfo)
|
2013-01-26 02:11:13 +04:00
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->CanSkip();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(NodeInfo)
|
2013-01-26 02:11:13 +04:00
|
|
|
return nsCCUncollectableMarker::sGeneration && tmp->CanSkip();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
2014-06-20 06:01:40 +04: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 18:29:44 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
void NodeInfo::GetPrefix(nsAString& aPrefix) const {
|
|
|
|
if (mInner.mPrefix) {
|
|
|
|
mInner.mPrefix->ToString(aPrefix);
|
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aPrefix);
|
|
|
|
}
|
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
void NodeInfo::GetNamespaceURI(nsAString& aNameSpaceURI) const {
|
2000-05-08 18:29:44 +04:00
|
|
|
if (mInner.mNamespaceID > 0) {
|
2013-01-30 02:53:52 +04: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 18:29:44 +04: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 20:46:42 +04:00
|
|
|
SetDOMStringToNull(aNameSpaceURI);
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool NodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const {
|
2016-06-28 17:24:48 +03:00
|
|
|
int32_t nsid = nsContentUtils::NameSpaceManager()->GetNameSpaceID(
|
|
|
|
aNamespaceURI, nsContentUtils::IsChromeDoc(mOwnerManager->GetDocument()));
|
2000-05-14 22:34:35 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
return mozilla::dom::NodeInfo::NamespaceEquals(nsid);
|
2000-05-14 22:34:35 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
void NodeInfo::DeleteCycleCollectable() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNodeInfoManager> kungFuDeathGrip = mOwnerManager;
|
2016-08-24 21:12:09 +03:00
|
|
|
mozilla::Unused
|
|
|
|
<< kungFuDeathGrip; // Just keeping value alive for longer than this
|
2013-03-01 06:53:49 +04:00
|
|
|
delete this;
|
2003-10-30 16:47:29 +03:00
|
|
|
}
|
2013-01-26 02:11:13 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool NodeInfo::CanSkip() {
|
2013-01-26 02:11:13 +04:00
|
|
|
return mDocument && nsCCUncollectableMarker::InGeneration(
|
|
|
|
mDocument->GetMarkedCCGeneration());
|
|
|
|
}
|