1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * A class for handing out nodeinfos and ensuring sharing of them as needed.
10 #ifndef nsNodeInfoManager_h___
11 #define nsNodeInfoManager_h___
13 #include "mozilla/Attributes.h" // for MOZ_FINAL
14 #include "nsCOMPtr.h" // for member
15 #include "nsAutoPtr.h" // for nsRefPtr
16 #include "nsCycleCollectionParticipant.h" // for NS_DECL_CYCLE_*
17 #include "plhash.h" // for typedef PLHashNumber
20 class nsBindingManager
;
23 class nsIDOMDocumentType
;
27 template<class T
> struct already_AddRefed
;
35 class nsNodeInfoManager MOZ_FINAL
43 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager
)
45 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsNodeInfoManager
)
48 * Initialize the nodeinfo manager with a document.
50 nsresult
Init(nsIDocument
*aDocument
);
53 * Release the reference to the document, this will be called when
54 * the document is going away.
56 void DropDocumentReference();
59 * Methods for creating nodeinfo's from atoms and/or strings.
61 already_AddRefed
<mozilla::dom::NodeInfo
>
62 GetNodeInfo(nsIAtom
*aName
, nsIAtom
*aPrefix
, int32_t aNamespaceID
,
63 uint16_t aNodeType
, nsIAtom
* aExtraName
= nullptr);
64 nsresult
GetNodeInfo(const nsAString
& aName
, nsIAtom
*aPrefix
,
65 int32_t aNamespaceID
, uint16_t aNodeType
,
66 mozilla::dom::NodeInfo
** aNodeInfo
);
67 nsresult
GetNodeInfo(const nsAString
& aName
, nsIAtom
*aPrefix
,
68 const nsAString
& aNamespaceURI
, uint16_t aNodeType
,
69 mozilla::dom::NodeInfo
** aNodeInfo
);
72 * Returns the nodeinfo for text nodes. Can return null if OOM.
74 already_AddRefed
<mozilla::dom::NodeInfo
> GetTextNodeInfo();
77 * Returns the nodeinfo for comment nodes. Can return null if OOM.
79 already_AddRefed
<mozilla::dom::NodeInfo
> GetCommentNodeInfo();
82 * Returns the nodeinfo for the document node. Can return null if OOM.
84 already_AddRefed
<mozilla::dom::NodeInfo
> GetDocumentNodeInfo();
87 * Retrieve a pointer to the document that owns this node info
90 nsIDocument
* GetDocument() const
96 * Gets the principal of the document this nodeinfo manager belongs to.
98 nsIPrincipal
*DocumentPrincipal() const {
99 NS_ASSERTION(mPrincipal
, "How'd that happen?");
103 void RemoveNodeInfo(mozilla::dom::NodeInfo
*aNodeInfo
);
105 nsBindingManager
* GetBindingManager() const
107 return mBindingManager
;
111 friend class nsDocument
;
112 friend class nsXULPrototypeDocument
;
113 friend nsresult
NS_NewDOMDocumentType(nsIDOMDocumentType
** ,
121 * Sets the principal of the document this nodeinfo manager belongs to.
123 void SetDocumentPrincipal(nsIPrincipal
*aPrincipal
);
126 static int NodeInfoInnerKeyCompare(const void *key1
, const void *key2
);
127 static PLHashNumber
GetNodeInfoInnerHashValue(const void *key
);
128 static int DropNodeInfoDocument(PLHashEntry
*he
, int hashIndex
,
131 PLHashTable
*mNodeInfoHash
;
132 nsIDocument
*mDocument
; // WEAK
133 uint32_t mNonDocumentNodeInfos
;
134 nsCOMPtr
<nsIPrincipal
> mPrincipal
; // Never null after Init() succeeds.
135 nsCOMPtr
<nsIPrincipal
> mDefaultPrincipal
; // Never null after Init() succeeds
136 mozilla::dom::NodeInfo
*mTextNodeInfo
; // WEAK to avoid circular ownership
137 mozilla::dom::NodeInfo
*mCommentNodeInfo
; // WEAK to avoid circular ownership
138 mozilla::dom::NodeInfo
*mDocumentNodeInfo
; // WEAK to avoid circular ownership
139 nsRefPtr
<nsBindingManager
> mBindingManager
;
142 #endif /* nsNodeInfoManager_h___ */