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
|
|
|
/*
|
|
|
|
* A class for handing out nodeinfos and ensuring sharing of them as needed.
|
|
|
|
*/
|
|
|
|
|
2000-05-08 18:29:44 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2013-08-06 05:35:08 +04:00
|
|
|
|
|
|
|
#include "mozilla/DebugOnly.h"
|
2016-09-23 01:35:48 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
|
|
|
#include "mozilla/dom/NodeInfoInlines.h"
|
2000-05-08 18:29:44 +04: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 20:46:42 +04:00
|
|
|
#include "nsIDocument.h"
|
2002-07-31 01:26:32 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2003-10-22 02:11:49 +04:00
|
|
|
#include "nsIURI.h"
|
2002-11-30 02:44:07 +03:00
|
|
|
#include "nsContentUtils.h"
|
2003-09-27 08:18:26 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2006-04-04 01:20:02 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2008-01-20 19:56:39 +03:00
|
|
|
#include "nsLayoutStatics.h"
|
2008-03-28 17:09:00 +03:00
|
|
|
#include "nsBindingManager.h"
|
2010-07-23 13:49:57 +04:00
|
|
|
#include "nsHashKeys.h"
|
2012-01-07 22:57:03 +04:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2014-11-17 15:04:00 +03:00
|
|
|
#include "nsDocument.h"
|
2015-04-13 21:47:41 +03:00
|
|
|
#include "nsNullPrincipal.h"
|
2007-12-15 12:45:33 +03:00
|
|
|
|
2012-03-13 02:53:18 +04:00
|
|
|
using namespace mozilla;
|
2014-06-20 06:01:40 +04:00
|
|
|
using mozilla::dom::NodeInfo;
|
2012-03-13 02:53:18 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2008-02-08 22:55:03 +03:00
|
|
|
|
2015-11-23 22:09:25 +03:00
|
|
|
static LazyLogModule gNodeInfoManagerLeakPRLog("NodeInfoManagerLeak");
|
2008-02-08 22:55:03 +03:00
|
|
|
|
2002-01-03 07:51:02 +03:00
|
|
|
PLHashNumber
|
|
|
|
nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key)
|
|
|
|
{
|
2014-06-20 06:01:40 +04:00
|
|
|
MOZ_ASSERT(key, "Null key passed to NodeInfo::GetHashValue!");
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
auto *node = reinterpret_cast<const NodeInfo::NodeInfoInner*>(key);
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2013-11-09 03:29:09 +04:00
|
|
|
return node->mName ? node->mName->hash() : HashString(*(node->mNameString));
|
2002-01-03 07:51:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-09 11:09:40 +04:00
|
|
|
int
|
2002-01-03 07:51:02 +03:00
|
|
|
nsNodeInfoManager::NodeInfoInnerKeyCompare(const void *key1, const void *key2)
|
|
|
|
{
|
2014-06-20 06:01:40 +04:00
|
|
|
MOZ_ASSERT(key1 && key2, "Null key passed to NodeInfoInnerKeyCompare!");
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
auto *node1 = reinterpret_cast<const NodeInfo::NodeInfoInner*>(key1);
|
|
|
|
auto *node2 = reinterpret_cast<const NodeInfo::NodeInfoInner*>(key2);
|
2002-01-03 07:51:02 +03:00
|
|
|
|
2010-07-23 13:49:57 +04:00
|
|
|
if (node1->mPrefix != node2->mPrefix ||
|
2011-06-14 11:56:49 +04:00
|
|
|
node1->mNamespaceID != node2->mNamespaceID ||
|
|
|
|
node1->mNodeType != node2->mNodeType ||
|
|
|
|
node1->mExtraName != node2->mExtraName) {
|
2010-07-23 13:49:57 +04: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 07:51:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-04 16:00:07 +04:00
|
|
|
static void* PR_CALLBACK
|
2013-06-13 05:26:59 +04:00
|
|
|
AllocTable(void* pool, size_t size)
|
2013-04-04 16:00:07 +04: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 05:26:59 +04:00
|
|
|
FreeEntry(void* pool, PLHashEntry* he, unsigned flag)
|
2013-04-04 16:00:07 +04:00
|
|
|
{
|
|
|
|
if (flag == HT_FREE_ENTRY) {
|
|
|
|
free(he);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLHashAllocOps allocOps =
|
|
|
|
{ AllocTable, FreeTable, AllocEntry, FreeEntry };
|
|
|
|
|
2005-09-24 22:43:15 +04:00
|
|
|
nsNodeInfoManager::nsNodeInfoManager()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mDocument(nullptr),
|
2011-07-26 15:11:14 +04:00
|
|
|
mNonDocumentNodeInfos(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mTextNodeInfo(nullptr),
|
|
|
|
mCommentNodeInfo(nullptr),
|
2014-04-10 18:05:20 +04:00
|
|
|
mDocumentNodeInfo(nullptr)
|
2000-05-08 18:29:44 +04:00
|
|
|
{
|
2008-01-20 19:56:39 +03:00
|
|
|
nsLayoutStatics::AddRef();
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2008-02-08 22:55:03 +03:00
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug,
|
2008-02-08 22:55:03 +03:00
|
|
|
("NODEINFOMANAGER %p created", this));
|
|
|
|
|
2002-01-03 07:51:02 +03:00
|
|
|
mNodeInfoHash = PL_NewHashTable(32, GetNodeInfoInnerHashValue,
|
|
|
|
NodeInfoInnerKeyCompare,
|
2013-04-04 16:00:07 +04:00
|
|
|
PL_CompareValues, &allocOps, nullptr);
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsNodeInfoManager::~nsNodeInfoManager()
|
|
|
|
{
|
|
|
|
if (mNodeInfoHash)
|
|
|
|
PL_HashTableDestroy(mNodeInfoHash);
|
|
|
|
|
2006-04-04 01:20:02 +04:00
|
|
|
// Note: mPrincipal may be null here if we never got inited correctly
|
2014-04-10 18:05:20 +04:00
|
|
|
mPrincipal = nullptr;
|
2006-02-02 23:02:34 +03:00
|
|
|
|
2014-04-10 18:05:20 +04:00
|
|
|
mBindingManager = nullptr;
|
2008-03-28 17:09:00 +03:00
|
|
|
|
2008-02-08 22:55:03 +03:00
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug,
|
2008-02-08 22:55:03 +03:00
|
|
|
("NODEINFOMANAGER %p destroyed", this));
|
|
|
|
|
2008-01-20 19:56:39 +03:00
|
|
|
nsLayoutStatics::Release();
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsNodeInfoManager)
|
|
|
|
|
2012-11-23 23:27:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsNodeInfoManager)
|
2012-11-22 21:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsNodeInfoManager)
|
2011-07-26 15:11:14 +04:00
|
|
|
if (tmp->mNonDocumentNodeInfos) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDocument)
|
|
|
|
}
|
2014-04-10 18:05:20 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBindingManager)
|
2008-03-28 17:09:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsNodeInfoManager, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsNodeInfoManager, Release)
|
2012-06-27 00:35:29 +04:00
|
|
|
|
2014-11-17 15:04:00 +03: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 08:27:37 +03:00
|
|
|
nsresult
|
2002-11-30 02:44:07 +03:00
|
|
|
nsNodeInfoManager::Init(nsIDocument *aDocument)
|
2000-05-08 18:29:44 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mNodeInfoHash, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2006-04-04 01:20:02 +04:00
|
|
|
NS_PRECONDITION(!mPrincipal,
|
|
|
|
"Being inited when we already have a principal?");
|
2015-04-13 21:47:41 +03:00
|
|
|
|
|
|
|
mPrincipal = nsNullPrincipal::Create();
|
2006-04-04 01:20:02 +04:00
|
|
|
|
2008-03-28 17:09:00 +03:00
|
|
|
if (aDocument) {
|
|
|
|
mBindingManager = new nsBindingManager(aDocument);
|
|
|
|
}
|
|
|
|
|
2006-04-04 01:20:02 +04: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 20:46:42 +04:00
|
|
|
mDocument = aDocument;
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2008-02-08 22:55:03 +03:00
|
|
|
if (gNodeInfoManagerLeakPRLog)
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gNodeInfoManagerLeakPRLog, LogLevel::Debug,
|
2008-02-08 22:55:03 +03:00
|
|
|
("NODEINFOMANAGER %p Init document=%p", this, aDocument));
|
|
|
|
|
2000-05-08 18:29:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-15 04:58:57 +04:00
|
|
|
// static
|
2012-08-09 11:09:40 +04:00
|
|
|
int
|
|
|
|
nsNodeInfoManager::DropNodeInfoDocument(PLHashEntry *he, int hashIndex, void *arg)
|
2011-06-15 04:58:57 +04:00
|
|
|
{
|
2014-06-20 06:01:40 +04:00
|
|
|
static_cast<mozilla::dom::NodeInfo*>(he->value)->mDocument = nullptr;
|
2011-06-15 04:58:57 +04:00
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
2003-11-15 08:27:37 +03: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 20:46:42 +04:00
|
|
|
nsNodeInfoManager::DropDocumentReference()
|
|
|
|
{
|
2008-03-28 17:09:00 +03:00
|
|
|
if (mBindingManager) {
|
|
|
|
mBindingManager->DropDocumentReference();
|
|
|
|
}
|
|
|
|
|
2011-07-26 15:11:14 +04:00
|
|
|
// This is probably not needed anymore.
|
2012-07-30 18:20:58 +04:00
|
|
|
PL_HashTableEnumerateEntries(mNodeInfoHash, DropNodeInfoDocument, nullptr);
|
2011-06-15 04:58:57 +04:00
|
|
|
|
2011-07-26 15:11:14 +04:00
|
|
|
NS_ASSERTION(!mNonDocumentNodeInfos, "Shouldn't have non-document nodeinfos!");
|
2012-07-30 18:20:58 +04: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 20:46:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>
|
2000-05-08 18:29:44 +04:00
|
|
|
nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType,
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIAtom* aExtraName /* = nullptr */)
|
2000-05-08 18:29:44 +04:00
|
|
|
{
|
2012-08-16 19:07:55 +04:00
|
|
|
CheckValidNodeInfo(aNodeType, aName, aNamespaceID, aExtraName);
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfo::NodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType,
|
|
|
|
aExtraName);
|
2000-05-08 18:29:44 +04:00
|
|
|
|
|
|
|
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
|
|
|
|
|
|
|
|
if (node) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> nodeInfo = static_cast<NodeInfo*>(node);
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return nodeInfo.forget();
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> newNodeInfo =
|
2014-06-20 06:01:40 +04:00
|
|
|
new NodeInfo(aName, aPrefix, aNamespaceID, aNodeType, aExtraName, this);
|
2013-03-01 06:53:49 +04:00
|
|
|
|
2013-08-06 05:35:08 +04:00
|
|
|
DebugOnly<PLHashEntry*> he =
|
|
|
|
PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
|
2013-04-04 16:00:07 +04:00
|
|
|
MOZ_ASSERT(he, "PL_HashTableAdd() failed");
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2011-05-05 20:26:32 +04:00
|
|
|
// Have to do the swap thing, because already_AddRefed<nsNodeInfo>
|
2014-06-20 06:01:40 +04:00
|
|
|
// doesn't cast to already_AddRefed<mozilla::dom::NodeInfo>
|
2011-07-26 15:11:14 +04:00
|
|
|
++mNonDocumentNodeInfos;
|
|
|
|
if (mNonDocumentNodeInfos == 1) {
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
}
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return newNodeInfo.forget();
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-15 08:27:37 +03:00
|
|
|
nsresult
|
2002-01-03 07:51:02 +03:00
|
|
|
nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNamespaceID, uint16_t aNodeType,
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfo** aNodeInfo)
|
2000-05-08 18:29:44 +04:00
|
|
|
{
|
2011-06-14 11:56:49 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2016-03-29 02:09:43 +03:00
|
|
|
nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(aName);
|
2012-08-16 19:07:55 +04:00
|
|
|
CheckValidNodeInfo(aNodeType, nameAtom, aNamespaceID, nullptr);
|
2011-06-14 11:56:49 +04:00
|
|
|
}
|
|
|
|
#endif
|
2010-07-23 13:49:57 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfo::NodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType);
|
2010-07-23 13:49:57 +04:00
|
|
|
|
|
|
|
void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);
|
|
|
|
|
|
|
|
if (node) {
|
2016-07-21 01:18:59 +03:00
|
|
|
RefPtr<NodeInfo> nodeInfo = static_cast<NodeInfo*>(node);
|
|
|
|
nodeInfo.forget(aNodeInfo);
|
2010-07-23 13:49:57 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-29 02:09:43 +03:00
|
|
|
nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(aName);
|
2011-05-05 20:26:32 +04:00
|
|
|
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> newNodeInfo =
|
2014-06-20 06:01:40 +04:00
|
|
|
new NodeInfo(nameAtom, aPrefix, aNamespaceID, aNodeType, nullptr, this);
|
2011-05-05 20:26:32 +04:00
|
|
|
NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2010-07-23 13:49:57 +04:00
|
|
|
|
|
|
|
PLHashEntry *he;
|
|
|
|
he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
|
|
|
|
NS_ENSURE_TRUE(he, NS_ERROR_FAILURE);
|
|
|
|
|
2011-07-26 15:11:14 +04:00
|
|
|
++mNonDocumentNodeInfos;
|
|
|
|
if (mNonDocumentNodeInfos == 1) {
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
}
|
|
|
|
|
2010-07-23 13:49:57 +04:00
|
|
|
newNodeInfo.forget(aNodeInfo);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-15 08:27:37 +03:00
|
|
|
nsresult
|
2008-10-07 22:53:22 +04:00
|
|
|
nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
2002-01-03 07:51:02 +03:00
|
|
|
const nsAString& aNamespaceURI,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t aNodeType,
|
2014-06-20 06:01:40 +04:00
|
|
|
NodeInfo** aNodeInfo)
|
2000-05-15 03:45:32 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nsid = kNameSpaceID_None;
|
2000-05-15 03:45:32 +04:00
|
|
|
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aNamespaceURI.IsEmpty()) {
|
2005-09-11 14:08:43 +04:00
|
|
|
nsresult rv = nsContentUtils::NameSpaceManager()->
|
2004-02-10 13:58:13 +03:00
|
|
|
RegisterNameSpace(aNamespaceURI, nsid);
|
2000-05-15 03:45:32 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2011-06-14 11:56:49 +04:00
|
|
|
return GetNodeInfo(aName, aPrefix, nsid, aNodeType, aNodeInfo);
|
2000-05-15 03:45:32 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<NodeInfo>
|
2005-09-24 22:43:15 +04:00
|
|
|
nsNodeInfoManager::GetTextNodeInfo()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2013-04-26 15:51:07 +04:00
|
|
|
|
2005-09-24 22:43:15 +04:00
|
|
|
if (!mTextNodeInfo) {
|
2013-04-26 15:51:07 +04: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 22:43:15 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 15:51:07 +04:00
|
|
|
return nodeInfo.forget();
|
2005-09-24 22:43:15 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<NodeInfo>
|
2005-09-24 22:43:15 +04:00
|
|
|
nsNodeInfoManager::GetCommentNodeInfo()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> nodeInfo;
|
2013-04-26 15:51:07 +04:00
|
|
|
|
2005-09-24 22:43:15 +04:00
|
|
|
if (!mCommentNodeInfo) {
|
2013-04-26 15:51:07 +04: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 22:43:15 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-04-26 15:51:07 +04:00
|
|
|
nodeInfo = mCommentNodeInfo;
|
2005-09-24 22:43:15 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 15:51:07 +04:00
|
|
|
return nodeInfo.forget();
|
2005-09-24 22:43:15 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
already_AddRefed<NodeInfo>
|
2006-01-19 06:34:18 +03:00
|
|
|
nsNodeInfoManager::GetDocumentNodeInfo()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> nodeInfo;
|
2013-04-26 15:51:07 +04:00
|
|
|
|
2006-01-19 06:34:18 +03:00
|
|
|
if (!mDocumentNodeInfo) {
|
2011-07-26 15:11:14 +04:00
|
|
|
NS_ASSERTION(mDocument, "Should have mDocument!");
|
2013-04-26 15:51:07 +04: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 15:11:14 +04:00
|
|
|
--mNonDocumentNodeInfos;
|
|
|
|
if (!mNonDocumentNodeInfos) {
|
|
|
|
mDocument->Release(); // Don't set mDocument to null!
|
|
|
|
}
|
2006-01-19 06:34:18 +03:00
|
|
|
}
|
|
|
|
else {
|
2013-04-26 15:51:07 +04:00
|
|
|
nodeInfo = mDocumentNodeInfo;
|
2006-01-19 06:34:18 +03:00
|
|
|
}
|
|
|
|
|
2013-04-26 15:51:07 +04:00
|
|
|
return nodeInfo.forget();
|
2006-01-19 06:34:18 +03:00
|
|
|
}
|
2005-09-24 22:43:15 +04:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
void
|
|
|
|
nsNodeInfoManager::SetDocumentPrincipal(nsIPrincipal *aPrincipal)
|
2002-07-24 02:16:45 +04:00
|
|
|
{
|
2014-04-10 18:05:20 +04:00
|
|
|
mPrincipal = nullptr;
|
2006-04-04 01:20:02 +04:00
|
|
|
if (!aPrincipal) {
|
|
|
|
aPrincipal = mDefaultPrincipal;
|
|
|
|
}
|
2006-04-27 22:21:11 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(aPrincipal, "Must have principal by this point!");
|
2016-09-23 01:35:48 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!nsContentUtils::IsExpandedPrincipal(aPrincipal),
|
|
|
|
"Documents shouldn't have an expanded principal");
|
|
|
|
if (nsContentUtils::IsExpandedPrincipal(aPrincipal)) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DOCUMENT_WITH_EXPANDED_PRINCIPAL, 1);
|
|
|
|
}
|
2014-04-10 18:05:20 +04:00
|
|
|
|
2014-04-10 18:05:20 +04:00
|
|
|
mPrincipal = aPrincipal;
|
2002-07-24 02:16:45 +04: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 20:46:42 +04:00
|
|
|
|
2000-05-08 18:29:44 +04:00
|
|
|
void
|
2014-06-20 06:01:40 +04:00
|
|
|
nsNodeInfoManager::RemoveNodeInfo(NodeInfo *aNodeInfo)
|
2000-05-08 18:29:44 +04:00
|
|
|
{
|
2005-09-24 22:43:15 +04:00
|
|
|
NS_PRECONDITION(aNodeInfo, "Trying to remove null nodeinfo from manager!");
|
|
|
|
|
2011-07-26 15:11:14 +04:00
|
|
|
if (aNodeInfo == mDocumentNodeInfo) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocumentNodeInfo = nullptr;
|
|
|
|
mDocument = nullptr;
|
2011-07-26 15:11:14 +04: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 18:20:58 +04:00
|
|
|
mTextNodeInfo = nullptr;
|
2011-07-26 15:11:14 +04:00
|
|
|
}
|
|
|
|
else if (aNodeInfo == mCommentNodeInfo) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mCommentNodeInfo = nullptr;
|
2011-07-26 15:11:14 +04:00
|
|
|
}
|
2006-01-19 06:34:18 +03:00
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ret =
|
2003-09-27 08:18:26 +04:00
|
|
|
#endif
|
2005-09-24 22:43:15 +04:00
|
|
|
PL_HashTableRemove(mNodeInfoHash, &aNodeInfo->mInner);
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
NS_POSTCONDITION(ret, "Can't find mozilla::dom::NodeInfo to remove!!!");
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|