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
|
|
|
|
2019-12-05 07:44:32 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2013-08-06 05:35:08 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
|
|
|
#include "mozilla/dom/NodeInfoInlines.h"
|
2020-03-17 17:52:37 +03:00
|
|
|
#include "mozilla/dom/DocGroup.h"
|
2018-07-17 22:37:48 +03:00
|
|
|
#include "mozilla/NullPrincipal.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
2000-05-08 18:29:44 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2002-07-31 01:26:32 +04:00
|
|
|
#include "nsIPrincipal.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"
|
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"
|
2018-02-16 15:02:28 +03:00
|
|
|
#include "nsWindowSizes.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");
|
2018-03-02 02:33:52 +03:00
|
|
|
static const uint32_t kInitialNodeInfoHashSize = 32;
|
2013-04-04 16:00:07 +04:00
|
|
|
|
2005-09-24 22:43:15 +04:00
|
|
|
nsNodeInfoManager::nsNodeInfoManager()
|
2018-03-02 02:33:52 +03:00
|
|
|
: mNodeInfoHash(kInitialNodeInfoHashSize),
|
|
|
|
mDocument(nullptr),
|
2011-07-26 15:11:14 +04:00
|
|
|
mNonDocumentNodeInfos(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mTextNodeInfo(nullptr),
|
|
|
|
mCommentNodeInfo(nullptr),
|
2017-04-01 05:57:35 +03:00
|
|
|
mDocumentNodeInfo(nullptr),
|
2020-03-17 17:52:37 +03:00
|
|
|
mRecentlyUsedNodeInfos(),
|
|
|
|
mArena(nullptr) {
|
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));
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsNodeInfoManager::~nsNodeInfoManager() {
|
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
|
|
|
|
2020-03-17 17:52:37 +03:00
|
|
|
mArena = nullptr;
|
|
|
|
|
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)
|
|
|
|
}
|
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) {
|
2019-06-07 17:16:59 +03:00
|
|
|
return NS_CYCLE_COLLECTION_PARTICIPANT(mozilla::dom::Document)
|
|
|
|
->CanSkip(tmp->mDocument, aRemovingAllowed);
|
2014-11-17 15:04:00 +03:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsNodeInfoManager)
|
|
|
|
if (tmp->mDocument) {
|
2019-06-07 17:16:59 +03:00
|
|
|
return NS_CYCLE_COLLECTION_PARTICIPANT(mozilla::dom::Document)
|
|
|
|
->CanSkipInCC(tmp->mDocument);
|
2014-11-17 15:04:00 +03:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsNodeInfoManager)
|
|
|
|
if (tmp->mDocument) {
|
2019-06-07 17:16:59 +03:00
|
|
|
return NS_CYCLE_COLLECTION_PARTICIPANT(mozilla::dom::Document)
|
|
|
|
->CanSkipThis(tmp->mDocument);
|
2014-11-17 15:04:00 +03:00
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
2019-06-07 17:16:59 +03:00
|
|
|
nsresult nsNodeInfoManager::Init(mozilla::dom::Document* aDocument) {
|
2006-04-04 01:20:02 +04:00
|
|
|
MOZ_ASSERT(!mPrincipal, "Being inited when we already have a principal?");
|
2015-04-13 21:47:41 +03:00
|
|
|
|
2018-03-22 21:36:20 +03:00
|
|
|
mPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void nsNodeInfoManager::DropDocumentReference() {
|
2011-07-26 15:11:14 +04:00
|
|
|
// This is probably not needed anymore.
|
2018-03-02 02:33:52 +03:00
|
|
|
for (auto iter = mNodeInfoHash.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.Data()->mDocument = 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> nsNodeInfoManager::GetNodeInfo(
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAtom* aName, nsAtom* aPrefix, int32_t aNamespaceID, uint16_t aNodeType,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aExtraName /* = nullptr */) {
|
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
|
|
|
|
2018-09-13 02:39:43 +03:00
|
|
|
auto p = mRecentlyUsedNodeInfos.Lookup(tmpKey);
|
|
|
|
if (p) {
|
|
|
|
RefPtr<NodeInfo> nodeInfo = p.Data();
|
2017-04-01 05:57:35 +03:00
|
|
|
return nodeInfo.forget();
|
|
|
|
}
|
|
|
|
|
2018-03-02 02:33:52 +03:00
|
|
|
// We don't use LookupForAdd here as that would end up storing the temporary
|
|
|
|
// key instead of using `mInner`.
|
|
|
|
RefPtr<NodeInfo> nodeInfo = mNodeInfoHash.Get(&tmpKey);
|
|
|
|
if (!nodeInfo) {
|
|
|
|
++mNonDocumentNodeInfos;
|
|
|
|
if (mNonDocumentNodeInfos == 1) {
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
}
|
2000-05-08 18:29:44 +04:00
|
|
|
|
2018-03-02 02:33:52 +03:00
|
|
|
nodeInfo =
|
|
|
|
new NodeInfo(aName, aPrefix, aNamespaceID, aNodeType, aExtraName, this);
|
|
|
|
mNodeInfoHash.Put(&nodeInfo->mInner, nodeInfo);
|
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>
|
2018-09-13 02:39:43 +03:00
|
|
|
p.Set(nodeInfo);
|
2018-03-02 02:33:52 +03:00
|
|
|
return nodeInfo.forget();
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsAtom* 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) {
|
2018-03-02 02:33:52 +03:00
|
|
|
// TODO(erahm): Combine this with the atom version.
|
2011-06-14 11:56:49 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> 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
|
|
|
|
2018-09-13 02:39:43 +03:00
|
|
|
auto p = mRecentlyUsedNodeInfos.Lookup(tmpKey);
|
|
|
|
if (p) {
|
|
|
|
RefPtr<NodeInfo> nodeInfo = p.Data();
|
2017-04-01 05:57:35 +03:00
|
|
|
nodeInfo.forget(aNodeInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-02 02:33:52 +03:00
|
|
|
RefPtr<NodeInfo> nodeInfo = mNodeInfoHash.Get(&tmpKey);
|
|
|
|
if (!nodeInfo) {
|
|
|
|
++mNonDocumentNodeInfos;
|
|
|
|
if (mNonDocumentNodeInfos == 1) {
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
}
|
2010-07-23 13:49:57 +04:00
|
|
|
|
2018-03-02 02:33:52 +03:00
|
|
|
RefPtr<nsAtom> nameAtom = NS_Atomize(aName);
|
|
|
|
nodeInfo =
|
|
|
|
new NodeInfo(nameAtom, aPrefix, aNamespaceID, aNodeType, nullptr, this);
|
|
|
|
mNodeInfoHash.Put(&nodeInfo->mInner, nodeInfo);
|
2011-07-26 15:11:14 +04:00
|
|
|
}
|
|
|
|
|
2018-09-13 02:39:43 +03:00
|
|
|
p.Set(nodeInfo);
|
2018-03-02 02:33:52 +03:00
|
|
|
nodeInfo.forget(aNodeInfo);
|
2010-07-23 13:49:57 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsAtom* 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) {
|
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()->RegisterNameSpace(
|
2004-02-10 13:58:13 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-09-24 22:43:15 +04:00
|
|
|
already_AddRefed<NodeInfo> 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,
|
2018-01-30 07:10:53 +03:00
|
|
|
nsINode::TEXT_NODE, nullptr);
|
2013-04-26 15:51:07 +04:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<NodeInfo> 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,
|
2018-01-30 07:10:53 +03:00
|
|
|
kNameSpaceID_None, nsINode::COMMENT_NODE, nullptr);
|
2013-04-26 15:51:07 +04:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2006-01-19 06:34:18 +03:00
|
|
|
already_AddRefed<NodeInfo> 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,
|
2018-01-30 07:10:53 +03:00
|
|
|
kNameSpaceID_None, nsINode::DOCUMENT_NODE, nullptr);
|
2013-04-26 15:51:07 +04:00
|
|
|
// 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
|
|
|
|
2020-03-17 17:52:37 +03:00
|
|
|
void* nsNodeInfoManager::Allocate(size_t aSize) {
|
|
|
|
if (!mHasAllocated) {
|
|
|
|
if (mozilla::StaticPrefs::dom_arena_allocator_enabled_AtStartup()) {
|
|
|
|
if (!mArena) {
|
|
|
|
mozilla::dom::DocGroup* docGroup = GetDocument()->GetDocGroupOrCreate();
|
|
|
|
if (docGroup) {
|
|
|
|
MOZ_ASSERT(!GetDocument()->HasChildren());
|
|
|
|
mArena = docGroup->ArenaAllocator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
mozilla::dom::DocGroup* docGroup = GetDocument()->GetDocGroup();
|
|
|
|
MOZ_ASSERT(docGroup);
|
|
|
|
MOZ_ASSERT(mArena == docGroup->ArenaAllocator());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
mHasAllocated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!mozilla::StaticPrefs::dom_arena_allocator_enabled_AtStartup()) {
|
|
|
|
MOZ_ASSERT(!mArena, "mArena should not set if the pref is not on");
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mArena) {
|
|
|
|
return mArena->Allocate(aSize);
|
|
|
|
}
|
|
|
|
return malloc(aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsNodeInfoManager::SetArenaAllocator(mozilla::dom::DOMArena* aArena) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT_IF(mArena, mArena == aArena);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mHasAllocated);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
mozilla::StaticPrefs::dom_arena_allocator_enabled_AtStartup());
|
|
|
|
|
|
|
|
if (!mArena) {
|
|
|
|
mArena = aArena;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
void nsNodeInfoManager::SetDocumentPrincipal(nsIPrincipal* aPrincipal) {
|
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");
|
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
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
void nsNodeInfoManager::RemoveNodeInfo(NodeInfo* aNodeInfo) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aNodeInfo, "Trying to remove null nodeinfo from manager!");
|
2005-09-24 22:43:15 +04:00
|
|
|
|
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
|
|
|
|
2018-09-13 02:39:43 +03:00
|
|
|
mRecentlyUsedNodeInfos.Remove(aNodeInfo->mInner);
|
2018-03-02 02:33:52 +03:00
|
|
|
DebugOnly<bool> ret = mNodeInfoHash.Remove(&aNodeInfo->mInner);
|
2017-11-05 08:48:48 +03:00
|
|
|
MOZ_ASSERT(ret, "Can't find mozilla::dom::NodeInfo to remove!!!");
|
2000-05-08 18:29:44 +04:00
|
|
|
}
|
2017-07-04 11:00:03 +03:00
|
|
|
|
2020-11-03 20:34:20 +03:00
|
|
|
static bool IsSystemOrAddonOrAboutPrincipal(nsIPrincipal* aPrincipal) {
|
2019-12-05 07:44:32 +03:00
|
|
|
return aPrincipal->IsSystemPrincipal() ||
|
2020-11-03 20:34:20 +03:00
|
|
|
BasePrincipal::Cast(aPrincipal)->AddonPolicy() ||
|
|
|
|
// NOTE: about:blank and about:srcdoc inherit the principal of their
|
|
|
|
// parent, so aPrincipal->SchemeIs("about") returns false for them.
|
|
|
|
aPrincipal->SchemeIs("about");
|
2019-07-09 22:58:41 +03:00
|
|
|
}
|
|
|
|
|
2017-07-04 11:00:03 +03:00
|
|
|
bool nsNodeInfoManager::InternalSVGEnabled() {
|
|
|
|
// If the svg.disabled pref. is true, convert all SVG nodes into
|
|
|
|
// disabled SVG nodes by swapping the namespace.
|
|
|
|
nsNameSpaceManager* nsmgr = nsNameSpaceManager::GetInstance();
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
bool SVGEnabled = false;
|
|
|
|
|
|
|
|
if (nsmgr && !nsmgr->mSVGDisabled) {
|
|
|
|
SVGEnabled = true;
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIChannel> channel = mDocument->GetChannel();
|
|
|
|
// We don't have a channel for SVGs constructed inside a SVG script
|
|
|
|
if (channel) {
|
2019-02-20 15:27:25 +03:00
|
|
|
loadInfo = channel->LoadInfo();
|
2017-07-04 11:00:03 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-09 22:58:41 +03:00
|
|
|
|
|
|
|
// We allow SVG (regardless of the pref) if this is a system or add-on
|
2020-11-03 20:34:20 +03:00
|
|
|
// principal or about: page, or if this load was requested for a system or
|
|
|
|
// add-on principal or about: page (e.g. a remote image being served as part
|
|
|
|
// of system or add-on UI or about: page)
|
2017-07-04 11:00:03 +03:00
|
|
|
bool conclusion =
|
2020-11-03 20:34:20 +03:00
|
|
|
(SVGEnabled || IsSystemOrAddonOrAboutPrincipal(mPrincipal) ||
|
2017-07-04 11:00:03 +03:00
|
|
|
(loadInfo &&
|
|
|
|
(loadInfo->GetExternalContentPolicyType() ==
|
|
|
|
nsIContentPolicy::TYPE_IMAGE ||
|
|
|
|
loadInfo->GetExternalContentPolicyType() ==
|
|
|
|
nsIContentPolicy::TYPE_OTHER) &&
|
2020-11-03 20:34:20 +03:00
|
|
|
(IsSystemOrAddonOrAboutPrincipal(loadInfo->GetLoadingPrincipal()) ||
|
|
|
|
IsSystemOrAddonOrAboutPrincipal(loadInfo->TriggeringPrincipal()))));
|
2019-07-10 00:19:41 +03:00
|
|
|
mSVGEnabled = Some(conclusion);
|
2017-07-04 11:00:03 +03:00
|
|
|
return conclusion;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNodeInfoManager::InternalMathMLEnabled() {
|
|
|
|
// If the mathml.disabled pref. is true, convert all MathML nodes into
|
|
|
|
// disabled MathML nodes by swapping the namespace.
|
|
|
|
nsNameSpaceManager* nsmgr = nsNameSpaceManager::GetInstance();
|
2019-12-05 07:44:32 +03:00
|
|
|
bool conclusion =
|
|
|
|
((nsmgr && !nsmgr->mMathMLDisabled) || mPrincipal->IsSystemPrincipal());
|
2019-07-10 00:19:41 +03:00
|
|
|
mMathMLEnabled = Some(conclusion);
|
2017-07-04 11:00:03 +03:00
|
|
|
return conclusion;
|
|
|
|
}
|
2018-02-16 15:02:28 +03:00
|
|
|
|
|
|
|
void nsNodeInfoManager::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const {
|
|
|
|
aSizes.mDOMOtherSize += aSizes.mState.mMallocSizeOf(this);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it
|
|
|
|
// is worthwhile:
|
|
|
|
// - mNodeInfoHash
|
|
|
|
}
|