Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
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 nsINodeInfo;
25 class nsIPrincipal;
26 class nsNodeInfo;
27 struct PLHashEntry;
28 struct PLHashTable;
29 template<class T> struct already_AddRefed;
31 class nsNodeInfoManager MOZ_FINAL
32 {
33 public:
34 nsNodeInfoManager();
35 ~nsNodeInfoManager();
37 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager)
39 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsNodeInfoManager)
41 /**
42 * Initialize the nodeinfo manager with a document.
43 */
44 nsresult Init(nsIDocument *aDocument);
46 /**
47 * Release the reference to the document, this will be called when
48 * the document is going away.
49 */
50 void DropDocumentReference();
52 /**
53 * Methods for creating nodeinfo's from atoms and/or strings.
54 */
55 already_AddRefed<nsINodeInfo> GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
56 int32_t aNamespaceID,
57 uint16_t aNodeType,
58 nsIAtom* aExtraName = nullptr);
59 nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
60 int32_t aNamespaceID, uint16_t aNodeType,
61 nsINodeInfo** aNodeInfo);
62 nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
63 const nsAString& aNamespaceURI, uint16_t aNodeType,
64 nsINodeInfo** aNodeInfo);
66 /**
67 * Returns the nodeinfo for text nodes. Can return null if OOM.
68 */
69 already_AddRefed<nsINodeInfo> GetTextNodeInfo();
71 /**
72 * Returns the nodeinfo for comment nodes. Can return null if OOM.
73 */
74 already_AddRefed<nsINodeInfo> GetCommentNodeInfo();
76 /**
77 * Returns the nodeinfo for the document node. Can return null if OOM.
78 */
79 already_AddRefed<nsINodeInfo> GetDocumentNodeInfo();
81 /**
82 * Retrieve a pointer to the document that owns this node info
83 * manager.
84 */
85 nsIDocument* GetDocument() const
86 {
87 return mDocument;
88 }
90 /**
91 * Gets the principal of the document this nodeinfo manager belongs to.
92 */
93 nsIPrincipal *DocumentPrincipal() const {
94 NS_ASSERTION(mPrincipal, "How'd that happen?");
95 return mPrincipal;
96 }
98 void RemoveNodeInfo(nsNodeInfo *aNodeInfo);
100 nsBindingManager* GetBindingManager() const
101 {
102 return mBindingManager;
103 }
105 protected:
106 friend class nsDocument;
107 friend class nsXULPrototypeDocument;
108 friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** ,
109 nsNodeInfoManager *,
110 nsIAtom *,
111 const nsAString& ,
112 const nsAString& ,
113 const nsAString& );
115 /**
116 * Sets the principal of the document this nodeinfo manager belongs to.
117 */
118 void SetDocumentPrincipal(nsIPrincipal *aPrincipal);
120 private:
121 static int NodeInfoInnerKeyCompare(const void *key1, const void *key2);
122 static PLHashNumber GetNodeInfoInnerHashValue(const void *key);
123 static int DropNodeInfoDocument(PLHashEntry *he, int hashIndex,
124 void *arg);
126 PLHashTable *mNodeInfoHash;
127 nsIDocument *mDocument; // WEAK
128 uint32_t mNonDocumentNodeInfos;
129 nsCOMPtr<nsIPrincipal> mPrincipal; // Never null after Init() succeeds.
130 nsCOMPtr<nsIPrincipal> mDefaultPrincipal; // Never null after Init() succeeds
131 nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership
132 nsINodeInfo *mCommentNodeInfo; // WEAK to avoid circular ownership
133 nsINodeInfo *mDocumentNodeInfo; // WEAK to avoid circular ownership
134 nsRefPtr<nsBindingManager> mBindingManager;
135 };
137 #endif /* nsNodeInfoManager_h___ */