2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A class for handing out nodeinfos and ensuring sharing of them as needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsNodeInfo.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2008-01-20 08:56:39 -08:00
|
|
|
#include "nsLayoutStatics.h"
|
2008-03-28 07:09:00 -07:00
|
|
|
#include "nsBindingManager.h"
|
2010-07-23 02:49:57 -07:00
|
|
|
#include "nsHashKeys.h"
|
2012-01-07 10:57:03 -08:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2007-12-15 01:45:33 -08:00
|
|
|
|
2012-03-12 15:53:18 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2008-02-08 11:55:03 -08:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
// so we can get logging even in release builds
|
|
|
|
#define FORCE_PR_LOG 1
|
|
|
|
#endif
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gNodeInfoManagerLeakPRLog;
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PLHashNumber
|
|
|
|
nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(key, "Null key passed to nsNodeInfo::GetHashValue!");
|
|
|
|
|
|
|
|
const nsINodeInfo::nsNodeInfoInner *node =
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<const nsINodeInfo::nsNodeInfoInner *>(key);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
if (node->mName) {
|
2012-03-12 15:53:18 -07:00
|
|
|
// Ideally, we'd return node->mName->hash() here. But that doesn't work at
|
|
|
|
// the moment because node->mName->hash() is not the same as
|
|
|
|
// HashString(*(node->mNameString)). See bug 732815.
|
2010-09-04 20:41:17 -07:00
|
|
|
return HashString(nsDependentAtomString(node->mName));
|
2010-07-23 02:49:57 -07:00
|
|
|
}
|
|
|
|
return HashString(*(node->mNameString));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-09 00:09:40 -07:00
|
|
|
int
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNodeInfoManager::NodeInfoInnerKeyCompare(const void *key1, const void *key2)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(key1 && key2, "Null key passed to NodeInfoInnerKeyCompare!");
|
|
|
|
|
|
|
|
const nsINodeInfo::nsNodeInfoInner *node1 =
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<const nsINodeInfo::nsNodeInfoInner *>(key1);
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsINodeInfo::nsNodeInfoInner *node2 =
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<const nsINodeInfo::nsNodeInfoInner *>(key2);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
if (node1->mPrefix != node2->mPrefix ||
|
2011-06-14 00:56:49 -07:00
|
|
|
node1->mNamespaceID != node2->mNamespaceID ||
|
|
|
|
node1->mNodeType != node2->mNodeType ||
|
|
|
|
node1->mExtraName != node2->mExtraName) {
|
2010-07-23 02:49:57 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node1->mName) {
|
|
|
|
if (node2->mName) {
|
|
|
|
return (node1->mName == node2->mName);
|
|
|
|
}
|
|
|
|
return (node1->mName->Equals(*(node2->mNameString)));
|
|
|
|
}
|
|
|
|
if (node2->mName) {
|
|
|
|
return (node2->mName->Equals(*(node1->mNameString)));
|
|
|
|
}
|
|
|
|
return (node1->mNameString->Equals(*(node2->mNameString)));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsNodeInfoManager::nsNodeInfoManager()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mDocument(nullptr),
|
2011-07-26 04:11:14 -07:00
|
|
|
mNonDocumentNodeInfos(0),
|
2012-07-30 07:20:58 -07:00
|
|
|
mPrincipal(nullptr),
|
|
|
|
mTextNodeInfo(nullptr),
|
|
|
|
mCommentNodeInfo(nullptr),
|
|
|
|
mDocumentNodeInfo(nullptr),
|
|
|
|
mBindingManager(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-20 08:56:39 -08:00
|
|
|
nsLayoutStatics::AddRef();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-08 11:55:03 -08:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!gNodeInfoManagerLeakPRLog)
|
|
|
|
gNodeInfoManagerLeakPRLog = PR_NewLogModule("NodeInfoManagerLeak");
|
|
|
|
|
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
|
|
|
PR_LOG(gNodeInfoManagerLeakPRLog, PR_LOG_DEBUG,
|
|
|
|
("NODEINFOMANAGER %p created", this));
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mNodeInfoHash = PL_NewHashTable(32, GetNodeInfoInnerHashValue,
|
|
|
|
NodeInfoInnerKeyCompare,
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_CompareValues, nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsNodeInfoManager::~nsNodeInfoManager()
|
|
|
|
{
|
|
|
|
if (mNodeInfoHash)
|
|
|
|
PL_HashTableDestroy(mNodeInfoHash);
|
|
|
|
|
|
|
|
// Note: mPrincipal may be null here if we never got inited correctly
|
|
|
|
NS_IF_RELEASE(mPrincipal);
|
|
|
|
|
2008-03-28 07:09:00 -07:00
|
|
|
NS_IF_RELEASE(mBindingManager);
|
|
|
|
|
2008-02-08 11:55:03 -08:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
|
|
|
PR_LOG(gNodeInfoManagerLeakPRLog, PR_LOG_DEBUG,
|
|
|
|
("NODEINFOMANAGER %p destroyed", this));
|
|
|
|
#endif
|
|
|
|
|
2008-01-20 08:56:39 -08:00
|
|
|
nsLayoutStatics::Release();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-24 09:50:06 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(nsNodeInfoManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsNodeInfoManager)
|
2012-01-07 10:57:03 -08:00
|
|
|
if (tmp->mDocument &&
|
|
|
|
nsCCUncollectableMarker::InGeneration(cb,
|
|
|
|
tmp->mDocument->GetMarkedCCGeneration())) {
|
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
|
|
}
|
2011-07-26 04:11:14 -07:00
|
|
|
if (tmp->mNonDocumentNodeInfos) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDocument)
|
|
|
|
}
|
2008-03-28 07:09:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mBindingManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-08-24 09:50:06 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsNodeInfoManager, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsNodeInfoManager, Release)
|
2012-06-26 13:35:29 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsNodeInfoManager::Init(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mNodeInfoHash, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
NS_PRECONDITION(!mPrincipal,
|
|
|
|
"Being inited when we already have a principal?");
|
|
|
|
nsresult rv = CallCreateInstance("@mozilla.org/nullprincipal;1",
|
|
|
|
&mPrincipal);
|
|
|
|
NS_ENSURE_TRUE(mPrincipal, rv);
|
|
|
|
|
2008-03-28 07:09:00 -07:00
|
|
|
if (aDocument) {
|
|
|
|
mBindingManager = new nsBindingManager(aDocument);
|
|
|
|
NS_ENSURE_TRUE(mBindingManager, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
NS_ADDREF(mBindingManager);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mDefaultPrincipal = mPrincipal;
|
|
|
|
|
|
|
|
mDocument = aDocument;
|
|
|
|
|
2008-02-08 11:55:03 -08:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
|
|
|
PR_LOG(gNodeInfoManagerLeakPRLog, PR_LOG_DEBUG,
|
|
|
|
("NODEINFOMANAGER %p Init document=%p", this, aDocument));
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-14 17:58:57 -07:00
|
|
|
// static
|
2012-08-09 00:09:40 -07:00
|
|
|
int
|
|
|
|
nsNodeInfoManager::DropNodeInfoDocument(PLHashEntry *he, int hashIndex, void *arg)
|
2011-06-14 17:58:57 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<nsINodeInfo*>(he->value)->mDocument = nullptr;
|
2011-06-14 17:58:57 -07:00
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsNodeInfoManager::DropDocumentReference()
|
|
|
|
{
|
2008-03-28 07:09:00 -07:00
|
|
|
if (mBindingManager) {
|
|
|
|
mBindingManager->DropDocumentReference();
|
|
|
|
}
|
|
|
|
|
2011-07-26 04:11:14 -07:00
|
|
|
// This is probably not needed anymore.
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_HashTableEnumerateEntries(mNodeInfoHash, DropNodeInfoDocument, nullptr);
|
2011-06-14 17:58:57 -07:00
|
|
|
|
2011-07-26 04:11:14 -07:00
|
|
|
NS_ASSERTION(!mNonDocumentNodeInfos, "Shouldn't have non-document nodeinfos!");
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocument = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-12 15:32:18 -07:00
|
|
|
already_AddRefed<nsINodeInfo>
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIAtom* aExtraName /* = nullptr */)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-16 08:07:55 -07:00
|
|
|
CheckValidNodeInfo(aNodeType, aName, aNamespaceID, aExtraName);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-14 00:56:49 -07:00
|
|
|
nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType,
|
|
|
|
aExtraName);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
|
|
|
|
|
|
|
|
if (node) {
|
2008-09-12 15:32:18 -07:00
|
|
|
nsINodeInfo* nodeInfo = static_cast<nsINodeInfo *>(node);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-12 15:32:18 -07:00
|
|
|
NS_ADDREF(nodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-12 15:32:18 -07:00
|
|
|
return nodeInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-05 09:26:32 -07:00
|
|
|
nsRefPtr<nsNodeInfo> newNodeInfo =
|
2011-06-14 00:56:49 -07:00
|
|
|
nsNodeInfo::Create(aName, aPrefix, aNamespaceID, aNodeType, aExtraName,
|
|
|
|
this);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(newNodeInfo, nullptr);
|
2008-09-12 15:32:18 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PLHashEntry *he;
|
|
|
|
he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(he, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-05 09:26:32 -07:00
|
|
|
// Have to do the swap thing, because already_AddRefed<nsNodeInfo>
|
|
|
|
// doesn't cast to already_AddRefed<nsINodeInfo>
|
2011-07-26 04:11:14 -07:00
|
|
|
++mNonDocumentNodeInfos;
|
|
|
|
if (mNonDocumentNodeInfos == 1) {
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsNodeInfo *nodeInfo = nullptr;
|
2008-09-12 15:32:18 -07:00
|
|
|
newNodeInfo.swap(nodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-12 15:32:18 -07:00
|
|
|
return nodeInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType,
|
2011-06-14 00:56:49 -07:00
|
|
|
nsINodeInfo** aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-14 00:56:49 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
|
2012-08-16 08:07:55 -07:00
|
|
|
CheckValidNodeInfo(aNodeType, nameAtom, aNamespaceID, nullptr);
|
2011-06-14 00:56:49 -07:00
|
|
|
}
|
|
|
|
#endif
|
2010-07-23 02:49:57 -07:00
|
|
|
|
2011-06-14 00:56:49 -07:00
|
|
|
nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType);
|
2010-07-23 02:49:57 -07:00
|
|
|
|
|
|
|
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
|
|
|
|
|
|
|
|
if (node) {
|
|
|
|
nsINodeInfo* nodeInfo = static_cast<nsINodeInfo *>(node);
|
|
|
|
|
|
|
|
NS_ADDREF(*aNodeInfo = nodeInfo);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
|
2011-05-05 09:26:32 -07:00
|
|
|
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsRefPtr<nsNodeInfo> newNodeInfo =
|
2012-07-30 07:20:58 -07:00
|
|
|
nsNodeInfo::Create(nameAtom, aPrefix, aNamespaceID, aNodeType, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
this);
|
2011-05-05 09:26:32 -07:00
|
|
|
NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2010-07-23 02:49:57 -07:00
|
|
|
|
|
|
|
PLHashEntry *he;
|
|
|
|
he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
|
|
|
|
NS_ENSURE_TRUE(he, NS_ERROR_FAILURE);
|
|
|
|
|
2011-07-26 04:11:14 -07:00
|
|
|
++mNonDocumentNodeInfos;
|
|
|
|
if (mNonDocumentNodeInfos == 1) {
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
}
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
newNodeInfo.forget(aNodeInfo);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2008-10-07 11:53:22 -07:00
|
|
|
nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAString& aNamespaceURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t aNodeType,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINodeInfo** aNodeInfo)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nsid = kNameSpaceID_None;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!aNamespaceURI.IsEmpty()) {
|
|
|
|
nsresult rv = nsContentUtils::NameSpaceManager()->
|
|
|
|
RegisterNameSpace(aNamespaceURI, nsid);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2011-06-14 00:56:49 -07:00
|
|
|
return GetNodeInfo(aName, aPrefix, nsid, aNodeType, aNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeInfo>
|
|
|
|
nsNodeInfoManager::GetTextNodeInfo()
|
|
|
|
{
|
|
|
|
if (!mTextNodeInfo) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mTextNodeInfo = GetNodeInfo(nsGkAtoms::textTagName, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_None,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIDOMNode::TEXT_NODE, nullptr).get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(mTextNodeInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mTextNodeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeInfo>
|
|
|
|
nsNodeInfoManager::GetCommentNodeInfo()
|
|
|
|
{
|
|
|
|
if (!mCommentNodeInfo) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mCommentNodeInfo = GetNodeInfo(nsGkAtoms::commentTagName, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_None,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIDOMNode::COMMENT_NODE, nullptr).get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(mCommentNodeInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mCommentNodeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeInfo>
|
|
|
|
nsNodeInfoManager::GetDocumentNodeInfo()
|
|
|
|
{
|
|
|
|
if (!mDocumentNodeInfo) {
|
2011-07-26 04:11:14 -07:00
|
|
|
NS_ASSERTION(mDocument, "Should have mDocument!");
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocumentNodeInfo = GetNodeInfo(nsGkAtoms::documentNodeName, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_None,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIDOMNode::DOCUMENT_NODE, nullptr).get();
|
2011-07-26 04:11:14 -07:00
|
|
|
--mNonDocumentNodeInfos;
|
|
|
|
if (!mNonDocumentNodeInfos) {
|
|
|
|
mDocument->Release(); // Don't set mDocument to null!
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(mDocumentNodeInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDocumentNodeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsNodeInfoManager::SetDocumentPrincipal(nsIPrincipal *aPrincipal)
|
|
|
|
{
|
|
|
|
NS_RELEASE(mPrincipal);
|
|
|
|
if (!aPrincipal) {
|
|
|
|
aPrincipal = mDefaultPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aPrincipal, "Must have principal by this point!");
|
|
|
|
|
|
|
|
NS_ADDREF(mPrincipal = aPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsNodeInfoManager::RemoveNodeInfo(nsNodeInfo *aNodeInfo)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNodeInfo, "Trying to remove null nodeinfo from manager!");
|
|
|
|
|
2011-07-26 04:11:14 -07:00
|
|
|
if (aNodeInfo == mDocumentNodeInfo) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocumentNodeInfo = nullptr;
|
|
|
|
mDocument = nullptr;
|
2011-07-26 04:11:14 -07:00
|
|
|
} else {
|
|
|
|
if (--mNonDocumentNodeInfos == 0) {
|
|
|
|
if (mDocument) {
|
|
|
|
// Note, whoever calls this method should keep NodeInfoManager alive,
|
|
|
|
// even if mDocument gets deleted.
|
|
|
|
mDocument->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Drop weak reference if needed
|
|
|
|
if (aNodeInfo == mTextNodeInfo) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mTextNodeInfo = nullptr;
|
2011-07-26 04:11:14 -07:00
|
|
|
}
|
|
|
|
else if (aNodeInfo == mCommentNodeInfo) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mCommentNodeInfo = nullptr;
|
2011-07-26 04:11:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ret =
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
PL_HashTableRemove(mNodeInfoHash, &aNodeInfo->mInner);
|
|
|
|
|
|
|
|
NS_POSTCONDITION(ret, "Can't find nsINodeInfo to remove!!!");
|
|
|
|
}
|