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
|
|
|
/*
|
|
|
|
* A class for handing out nodeinfos and ensuring sharing of them as needed.
|
|
|
|
*/
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2013-08-06 01:35:08 +00:00
|
|
|
|
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-06-20 02:01:40 +00:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
|
|
|
#include "mozilla/dom/NodeInfoInlines.h"
|
2000-05-08 14:29:44 +00:00
|
|
|
#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"
|
2014-06-20 02:01:40 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2014-11-17 12:04:00 +00:00
|
|
|
#include "nsDocument.h"
|
2015-04-13 18:47:41 +00:00
|
|
|
#include "nsNullPrincipal.h"
|
2007-12-15 09:45:33 +00:00
|
|
|
|
2012-03-12 22:53:18 +00:00
|
|
|
using namespace mozilla;
|
2014-06-20 02:01:40 +00:00
|
|
|
using mozilla::dom::NodeInfo;
|
2012-03-12 22:53:18 +00:00
|
|
|
|
2015-05-19 18:15:34 +00:00
|
|
|
#include "mozilla/Logging.h"
|
2008-02-08 19:55:03 +00:00
|
|
|
|
2015-11-23 19:09:25 +00:00
|
|
|
static LazyLogModule gNodeInfoManagerLeakPRLog("NodeInfoManagerLeak");
|
2008-02-08 19:55:03 +00:00
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
PLHashNumber
|
|
|
|
nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key)
|
|
|
|
{
|
2014-06-20 02:01:40 +00:00
|
|
|
MOZ_ASSERT(key, "Null key passed to NodeInfo::GetHashValue!");
|
2002-01-03 04:51:02 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
auto *node = reinterpret_cast<const NodeInfo::NodeInfoInner*>(key);
|
2002-01-03 04:51:02 +00:00
|
|
|
|
2013-11-08 23:29:09 +00:00
|
|
|
return node->mName ? node->mName->hash() : HashString(*(node->mNameString));
|
2002-01-03 04:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-09 07:09:40 +00:00
|
|
|
int
|
2002-01-03 04:51:02 +00:00
|
|
|
nsNodeInfoManager::NodeInfoInnerKeyCompare(const void *key1, const void *key2)
|
|
|
|
{
|
2014-06-20 02:01:40 +00:00
|
|
|
MOZ_ASSERT(key1 && key2, "Null key passed to NodeInfoInnerKeyCompare!");
|
2002-01-03 04:51:02 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
auto *node1 = reinterpret_cast<const NodeInfo::NodeInfoInner*>(key1);
|
|
|
|
auto *node2 = reinterpret_cast<const NodeInfo::NodeInfoInner*>(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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-04 12:00:07 +00:00
|
|
|
static void* PR_CALLBACK
|
2013-06-13 01:26:59 +00:00
|
|
|
AllocTable(void* pool, size_t size)
|
2013-04-04 12:00:07 +00:00
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
FreeTable(void* pool, void* item)
|
|
|
|
{
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLHashEntry* PR_CALLBACK
|
|
|
|
AllocEntry(void* pool, const void* key)
|
|
|
|
{
|
|
|
|
return (PLHashEntry*)malloc(sizeof(PLHashEntry));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
2013-06-13 01:26:59 +00:00
|
|
|
FreeEntry(void* pool, PLHashEntry* he, unsigned flag)
|
2013-04-04 12:00:07 +00:00
|
|
|
{
|
|
|
|
if (flag == HT_FREE_ENTRY) {
|
|
|
|
free(he);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLHashAllocOps allocOps =
|
|
|
|
{ AllocTable, FreeTable, AllocEntry, FreeEntry };
|
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
nsNodeInfoManager::nsNodeInfoManager()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mDocument(nullptr),
|
2011-07-26 11:11:14 +00:00
|
|
|
mNonDocumentNodeInfos(0),
|
2012-07-30 14:20:58 +00:00
|
|
|
mTextNodeInfo(nullptr),
|
|
|
|
mCommentNodeInfo(nullptr),
|
2014-04-10 14:05:20 +00:00
|
|
|
mDocumentNodeInfo(nullptr)
|
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
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug,
|
2008-02-08 19:55:03 +00:00
|
|
|
("NODEINFOMANAGER %p created", this));
|
|
|
|
|
2002-01-03 04:51:02 +00:00
|
|
|
mNodeInfoHash = PL_NewHashTable(32, GetNodeInfoInnerHashValue,
|
|
|
|
NodeInfoInnerKeyCompare,
|
2013-04-04 12:00:07 +00:00
|
|
|
PL_CompareValues, &allocOps, nullptr);
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2014-04-10 14:05:20 +00:00
|
|
|
mPrincipal = nullptr;
|
2006-02-02 20:02:34 +00:00
|
|
|
|
2014-04-10 14:05:20 +00:00
|
|
|
mBindingManager = nullptr;
|
2008-03-28 14:09:00 +00:00
|
|
|
|
2008-02-08 19:55:03 +00:00
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug,
|
2008-02-08 19:55:03 +00:00
|
|
|
("NODEINFOMANAGER %p destroyed", this));
|
|
|
|
|
2008-01-20 16:56:39 +00:00
|
|
|
nsLayoutStatics::Release();
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsNodeInfoManager)
|
|
|
|
|
2012-11-23 19:27:06 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsNodeInfoManager)
|
2012-11-22 17:15:38 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsNodeInfoManager)
|
2011-07-26 11:11:14 +00:00
|
|
|
if (tmp->mNonDocumentNodeInfos) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDocument)
|
|
|
|
}
|
2014-04-10 14:05:20 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBindingManager)
|
2008-03-28 14:09:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-08-24 16:50:06 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsNodeInfoManager, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsNodeInfoManager, Release)
|
2012-06-26 20:35:29 +00:00
|
|
|
|
2014-11-17 12:04:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsNodeInfoManager)
|
|
|
|
if (tmp->mDocument) {
|
|
|
|
return NS_CYCLE_COLLECTION_PARTICIPANT(nsDocument)->CanSkip(tmp->mDocument, aRemovingAllowed);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsNodeInfoManager)
|
|
|
|
if (tmp->mDocument) {
|
|
|
|
return NS_CYCLE_COLLECTION_PARTICIPANT(nsDocument)->CanSkipInCC(tmp->mDocument);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsNodeInfoManager)
|
|
|
|
if (tmp->mDocument) {
|
|
|
|
return NS_CYCLE_COLLECTION_PARTICIPANT(nsDocument)->CanSkipThis(tmp->mDocument);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_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?");
|
2015-04-13 18:47:41 +00:00
|
|
|
|
|
|
|
mPrincipal = nsNullPrincipal::Create();
|
2006-04-03 21:20:02 +00:00
|
|
|
|
2008-03-28 14:09:00 +00:00
|
|
|
if (aDocument) {
|
|
|
|
mBindingManager = new nsBindingManager(aDocument);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug,
|
2008-02-08 19:55:03 +00:00
|
|
|
("NODEINFOMANAGER %p Init document=%p", this, aDocument));
|
|
|
|
|
2000-05-08 14:29:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-15 00:58:57 +00:00
|
|
|
// static
|
2012-08-09 07:09:40 +00:00
|
|
|
int
|
|
|
|
nsNodeInfoManager::DropNodeInfoDocument(PLHashEntry *he, int hashIndex, void *arg)
|
2011-06-15 00:58:57 +00:00
|
|
|
{
|
2014-06-20 02:01:40 +00:00
|
|
|
static_cast<mozilla::dom::NodeInfo*>(he->value)->mDocument = nullptr;
|
2011-06-15 00:58:57 +00:00
|
|
|
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.
|
2012-07-30 14:20:58 +00:00
|
|
|
PL_HashTableEnumerateEntries(mNodeInfoHash, DropNodeInfoDocument, nullptr);
|
2011-06-15 00:58:57 +00:00
|
|
|
|
2011-07-26 11:11:14 +00:00
|
|
|
NS_ASSERTION(!mNonDocumentNodeInfos, "Shouldn't have non-document nodeinfos!");
|
2012-07-30 14:20:58 +00:00
|
|
|
mDocument = nullptr;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>
|
2000-05-08 14:29:44 +00:00
|
|
|
nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType,
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIAtom* aExtraName /* = nullptr */)
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2012-08-16 15:07:55 +00:00
|
|
|
CheckValidNodeInfo(aNodeType, aName, aNamespaceID, aExtraName);
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::NodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType,
|
|
|
|
aExtraName);
|
2000-05-08 14:29:44 +00:00
|
|
|
|
|
|
|
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
|
|
|
|
|
|
|
|
if (node) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NodeInfo> nodeInfo = static_cast<NodeInfo*>(node);
|
2000-05-08 14:29:44 +00:00
|
|
|
|
2013-04-22 11:15:59 +00:00
|
|
|
return nodeInfo.forget();
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NodeInfo> newNodeInfo =
|
2014-06-20 02:01:40 +00:00
|
|
|
new NodeInfo(aName, aPrefix, aNamespaceID, aNodeType, aExtraName, this);
|
2013-03-01 02:53:49 +00:00
|
|
|
|
2013-08-06 01:35:08 +00:00
|
|
|
DebugOnly<PLHashEntry*> he =
|
|
|
|
PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
|
2013-04-04 12:00:07 +00:00
|
|
|
MOZ_ASSERT(he, "PL_HashTableAdd() failed");
|
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>
|
2014-06-20 02:01:40 +00:00
|
|
|
// doesn't cast to already_AddRefed<mozilla::dom::NodeInfo>
|
2011-07-26 11:11:14 +00:00
|
|
|
++mNonDocumentNodeInfos;
|
|
|
|
if (mNonDocumentNodeInfos == 1) {
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
}
|
|
|
|
|
2013-04-22 11:15:59 +00:00
|
|
|
return newNodeInfo.forget();
|
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,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType,
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo** aNodeInfo)
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
2011-06-14 07:56:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2016-03-28 23:09:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(aName);
|
2012-08-16 15:07:55 +00:00
|
|
|
CheckValidNodeInfo(aNodeType, nameAtom, aNamespaceID, nullptr);
|
2011-06-14 07:56:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-07-23 09:49:57 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo::NodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType);
|
2010-07-23 09:49:57 +00:00
|
|
|
|
|
|
|
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
|
|
|
|
|
|
|
|
if (node) {
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo* nodeInfo = static_cast<NodeInfo *>(node);
|
2010-07-23 09:49:57 +00:00
|
|
|
|
|
|
|
NS_ADDREF(*aNodeInfo = nodeInfo);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-28 23:09:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(aName);
|
2011-05-05 16:26:32 +00:00
|
|
|
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NodeInfo> newNodeInfo =
|
2014-06-20 02:01:40 +00:00
|
|
|
new NodeInfo(nameAtom, aPrefix, aNamespaceID, aNodeType, nullptr, 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,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t aNodeType,
|
2014-06-20 02:01:40 +00:00
|
|
|
NodeInfo** aNodeInfo)
|
2000-05-14 23:45:32 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nsid = kNameSpaceID_None;
|
2000-05-14 23:45:32 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<NodeInfo>
|
2005-09-24 18:43:15 +00:00
|
|
|
nsNodeInfoManager::GetTextNodeInfo()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2013-04-26 11:51:07 +00:00
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
if (!mTextNodeInfo) {
|
2013-04-26 11:51:07 +00:00
|
|
|
nodeInfo = GetNodeInfo(nsGkAtoms::textTagName, nullptr, kNameSpaceID_None,
|
|
|
|
nsIDOMNode::TEXT_NODE, nullptr);
|
|
|
|
// Hold a weak ref; the nodeinfo will let us know when it goes away
|
|
|
|
mTextNodeInfo = nodeInfo;
|
|
|
|
} else {
|
|
|
|
nodeInfo = mTextNodeInfo;
|
2005-09-24 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 11:51:07 +00:00
|
|
|
return nodeInfo.forget();
|
2005-09-24 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<NodeInfo>
|
2005-09-24 18:43:15 +00:00
|
|
|
nsNodeInfoManager::GetCommentNodeInfo()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NodeInfo> nodeInfo;
|
2013-04-26 11:51:07 +00:00
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
if (!mCommentNodeInfo) {
|
2013-04-26 11:51:07 +00:00
|
|
|
nodeInfo = GetNodeInfo(nsGkAtoms::commentTagName, nullptr,
|
|
|
|
kNameSpaceID_None, nsIDOMNode::COMMENT_NODE,
|
|
|
|
nullptr);
|
|
|
|
// Hold a weak ref; the nodeinfo will let us know when it goes away
|
|
|
|
mCommentNodeInfo = nodeInfo;
|
2005-09-24 18:43:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-04-26 11:51:07 +00:00
|
|
|
nodeInfo = mCommentNodeInfo;
|
2005-09-24 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 11:51:07 +00:00
|
|
|
return nodeInfo.forget();
|
2005-09-24 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<NodeInfo>
|
2006-01-19 03:34:18 +00:00
|
|
|
nsNodeInfoManager::GetDocumentNodeInfo()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<NodeInfo> nodeInfo;
|
2013-04-26 11:51:07 +00:00
|
|
|
|
2006-01-19 03:34:18 +00:00
|
|
|
if (!mDocumentNodeInfo) {
|
2011-07-26 11:11:14 +00:00
|
|
|
NS_ASSERTION(mDocument, "Should have mDocument!");
|
2013-04-26 11:51:07 +00:00
|
|
|
nodeInfo = GetNodeInfo(nsGkAtoms::documentNodeName, nullptr,
|
|
|
|
kNameSpaceID_None, nsIDOMNode::DOCUMENT_NODE,
|
|
|
|
nullptr);
|
|
|
|
// Hold a weak ref; the nodeinfo will let us know when it goes away
|
|
|
|
mDocumentNodeInfo = nodeInfo;
|
|
|
|
|
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 {
|
2013-04-26 11:51:07 +00:00
|
|
|
nodeInfo = mDocumentNodeInfo;
|
2006-01-19 03:34:18 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 11:51:07 +00:00
|
|
|
return nodeInfo.forget();
|
2006-01-19 03:34:18 +00:00
|
|
|
}
|
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
|
|
|
{
|
2014-04-10 14:05:20 +00:00
|
|
|
mPrincipal = nullptr;
|
2006-04-03 21:20:02 +00:00
|
|
|
if (!aPrincipal) {
|
|
|
|
aPrincipal = mDefaultPrincipal;
|
|
|
|
}
|
2006-04-27 18:21:11 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(aPrincipal, "Must have principal by this point!");
|
2014-04-10 14:05:20 +00:00
|
|
|
|
2014-04-10 14:05:20 +00:00
|
|
|
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
|
2014-06-20 02:01:40 +00:00
|
|
|
nsNodeInfoManager::RemoveNodeInfo(NodeInfo *aNodeInfo)
|
2000-05-08 14:29:44 +00:00
|
|
|
{
|
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) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mDocumentNodeInfo = nullptr;
|
|
|
|
mDocument = nullptr;
|
2011-07-26 11:11:14 +00: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 14:20:58 +00:00
|
|
|
mTextNodeInfo = nullptr;
|
2011-07-26 11:11:14 +00:00
|
|
|
}
|
|
|
|
else if (aNodeInfo == mCommentNodeInfo) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mCommentNodeInfo = nullptr;
|
2011-07-26 11:11:14 +00:00
|
|
|
}
|
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
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
NS_POSTCONDITION(ret, "Can't find mozilla::dom::NodeInfo to remove!!!");
|
2000-05-08 14:29:44 +00:00
|
|
|
}
|