content/base/src/nsNodeInfoManager.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

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.)

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * A class for handing out nodeinfos and ensuring sharing of them as needed.
michael@0 8 */
michael@0 9
michael@0 10 #ifndef nsNodeInfoManager_h___
michael@0 11 #define nsNodeInfoManager_h___
michael@0 12
michael@0 13 #include "mozilla/Attributes.h" // for MOZ_FINAL
michael@0 14 #include "nsCOMPtr.h" // for member
michael@0 15 #include "nsAutoPtr.h" // for nsRefPtr
michael@0 16 #include "nsCycleCollectionParticipant.h" // for NS_DECL_CYCLE_*
michael@0 17 #include "plhash.h" // for typedef PLHashNumber
michael@0 18
michael@0 19 class nsAString;
michael@0 20 class nsBindingManager;
michael@0 21 class nsIAtom;
michael@0 22 class nsIDocument;
michael@0 23 class nsIDOMDocumentType;
michael@0 24 class nsINodeInfo;
michael@0 25 class nsIPrincipal;
michael@0 26 class nsNodeInfo;
michael@0 27 struct PLHashEntry;
michael@0 28 struct PLHashTable;
michael@0 29 template<class T> struct already_AddRefed;
michael@0 30
michael@0 31 class nsNodeInfoManager MOZ_FINAL
michael@0 32 {
michael@0 33 public:
michael@0 34 nsNodeInfoManager();
michael@0 35 ~nsNodeInfoManager();
michael@0 36
michael@0 37 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager)
michael@0 38
michael@0 39 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsNodeInfoManager)
michael@0 40
michael@0 41 /**
michael@0 42 * Initialize the nodeinfo manager with a document.
michael@0 43 */
michael@0 44 nsresult Init(nsIDocument *aDocument);
michael@0 45
michael@0 46 /**
michael@0 47 * Release the reference to the document, this will be called when
michael@0 48 * the document is going away.
michael@0 49 */
michael@0 50 void DropDocumentReference();
michael@0 51
michael@0 52 /**
michael@0 53 * Methods for creating nodeinfo's from atoms and/or strings.
michael@0 54 */
michael@0 55 already_AddRefed<nsINodeInfo> GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
michael@0 56 int32_t aNamespaceID,
michael@0 57 uint16_t aNodeType,
michael@0 58 nsIAtom* aExtraName = nullptr);
michael@0 59 nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
michael@0 60 int32_t aNamespaceID, uint16_t aNodeType,
michael@0 61 nsINodeInfo** aNodeInfo);
michael@0 62 nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
michael@0 63 const nsAString& aNamespaceURI, uint16_t aNodeType,
michael@0 64 nsINodeInfo** aNodeInfo);
michael@0 65
michael@0 66 /**
michael@0 67 * Returns the nodeinfo for text nodes. Can return null if OOM.
michael@0 68 */
michael@0 69 already_AddRefed<nsINodeInfo> GetTextNodeInfo();
michael@0 70
michael@0 71 /**
michael@0 72 * Returns the nodeinfo for comment nodes. Can return null if OOM.
michael@0 73 */
michael@0 74 already_AddRefed<nsINodeInfo> GetCommentNodeInfo();
michael@0 75
michael@0 76 /**
michael@0 77 * Returns the nodeinfo for the document node. Can return null if OOM.
michael@0 78 */
michael@0 79 already_AddRefed<nsINodeInfo> GetDocumentNodeInfo();
michael@0 80
michael@0 81 /**
michael@0 82 * Retrieve a pointer to the document that owns this node info
michael@0 83 * manager.
michael@0 84 */
michael@0 85 nsIDocument* GetDocument() const
michael@0 86 {
michael@0 87 return mDocument;
michael@0 88 }
michael@0 89
michael@0 90 /**
michael@0 91 * Gets the principal of the document this nodeinfo manager belongs to.
michael@0 92 */
michael@0 93 nsIPrincipal *DocumentPrincipal() const {
michael@0 94 NS_ASSERTION(mPrincipal, "How'd that happen?");
michael@0 95 return mPrincipal;
michael@0 96 }
michael@0 97
michael@0 98 void RemoveNodeInfo(nsNodeInfo *aNodeInfo);
michael@0 99
michael@0 100 nsBindingManager* GetBindingManager() const
michael@0 101 {
michael@0 102 return mBindingManager;
michael@0 103 }
michael@0 104
michael@0 105 protected:
michael@0 106 friend class nsDocument;
michael@0 107 friend class nsXULPrototypeDocument;
michael@0 108 friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** ,
michael@0 109 nsNodeInfoManager *,
michael@0 110 nsIAtom *,
michael@0 111 const nsAString& ,
michael@0 112 const nsAString& ,
michael@0 113 const nsAString& );
michael@0 114
michael@0 115 /**
michael@0 116 * Sets the principal of the document this nodeinfo manager belongs to.
michael@0 117 */
michael@0 118 void SetDocumentPrincipal(nsIPrincipal *aPrincipal);
michael@0 119
michael@0 120 private:
michael@0 121 static int NodeInfoInnerKeyCompare(const void *key1, const void *key2);
michael@0 122 static PLHashNumber GetNodeInfoInnerHashValue(const void *key);
michael@0 123 static int DropNodeInfoDocument(PLHashEntry *he, int hashIndex,
michael@0 124 void *arg);
michael@0 125
michael@0 126 PLHashTable *mNodeInfoHash;
michael@0 127 nsIDocument *mDocument; // WEAK
michael@0 128 uint32_t mNonDocumentNodeInfos;
michael@0 129 nsCOMPtr<nsIPrincipal> mPrincipal; // Never null after Init() succeeds.
michael@0 130 nsCOMPtr<nsIPrincipal> mDefaultPrincipal; // Never null after Init() succeeds
michael@0 131 nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership
michael@0 132 nsINodeInfo *mCommentNodeInfo; // WEAK to avoid circular ownership
michael@0 133 nsINodeInfo *mDocumentNodeInfo; // WEAK to avoid circular ownership
michael@0 134 nsRefPtr<nsBindingManager> mBindingManager;
michael@0 135 };
michael@0 136
michael@0 137 #endif /* nsNodeInfoManager_h___ */

mercurial