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