Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / content / base / src / nsNodeInfoManager.h
blob3c05d77379bd0259a4a220970b9cccb0da3d5db1
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/. */
6 /*
7 * A class for handing out nodeinfos and ensuring sharing of them as needed.
8 */
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
19 class nsAString;
20 class nsBindingManager;
21 class nsIAtom;
22 class nsIDocument;
23 class nsIDOMDocumentType;
24 class nsIPrincipal;
25 struct PLHashEntry;
26 struct PLHashTable;
27 template<class T> struct already_AddRefed;
29 namespace mozilla {
30 namespace dom {
31 class NodeInfo;
35 class nsNodeInfoManager MOZ_FINAL
37 private:
38 ~nsNodeInfoManager();
40 public:
41 nsNodeInfoManager();
43 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager)
45 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsNodeInfoManager)
47 /**
48 * Initialize the nodeinfo manager with a document.
50 nsresult Init(nsIDocument *aDocument);
52 /**
53 * Release the reference to the document, this will be called when
54 * the document is going away.
56 void DropDocumentReference();
58 /**
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);
71 /**
72 * Returns the nodeinfo for text nodes. Can return null if OOM.
74 already_AddRefed<mozilla::dom::NodeInfo> GetTextNodeInfo();
76 /**
77 * Returns the nodeinfo for comment nodes. Can return null if OOM.
79 already_AddRefed<mozilla::dom::NodeInfo> GetCommentNodeInfo();
81 /**
82 * Returns the nodeinfo for the document node. Can return null if OOM.
84 already_AddRefed<mozilla::dom::NodeInfo> GetDocumentNodeInfo();
86 /**
87 * Retrieve a pointer to the document that owns this node info
88 * manager.
90 nsIDocument* GetDocument() const
92 return mDocument;
95 /**
96 * Gets the principal of the document this nodeinfo manager belongs to.
98 nsIPrincipal *DocumentPrincipal() const {
99 NS_ASSERTION(mPrincipal, "How'd that happen?");
100 return mPrincipal;
103 void RemoveNodeInfo(mozilla::dom::NodeInfo *aNodeInfo);
105 nsBindingManager* GetBindingManager() const
107 return mBindingManager;
110 protected:
111 friend class nsDocument;
112 friend class nsXULPrototypeDocument;
113 friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** ,
114 nsNodeInfoManager *,
115 nsIAtom *,
116 const nsAString& ,
117 const nsAString& ,
118 const nsAString& );
121 * Sets the principal of the document this nodeinfo manager belongs to.
123 void SetDocumentPrincipal(nsIPrincipal *aPrincipal);
125 private:
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,
129 void *arg);
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___ */