michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * A class for handing out nodeinfos and ensuring sharing of them as needed. michael@0: */ michael@0: michael@0: #ifndef nsNodeInfoManager_h___ michael@0: #define nsNodeInfoManager_h___ michael@0: michael@0: #include "mozilla/Attributes.h" // for MOZ_FINAL michael@0: #include "nsCOMPtr.h" // for member michael@0: #include "nsAutoPtr.h" // for nsRefPtr michael@0: #include "nsCycleCollectionParticipant.h" // for NS_DECL_CYCLE_* michael@0: #include "plhash.h" // for typedef PLHashNumber michael@0: michael@0: class nsAString; michael@0: class nsBindingManager; michael@0: class nsIAtom; michael@0: class nsIDocument; michael@0: class nsIDOMDocumentType; michael@0: class nsINodeInfo; michael@0: class nsIPrincipal; michael@0: class nsNodeInfo; michael@0: struct PLHashEntry; michael@0: struct PLHashTable; michael@0: template struct already_AddRefed; michael@0: michael@0: class nsNodeInfoManager MOZ_FINAL michael@0: { michael@0: public: michael@0: nsNodeInfoManager(); michael@0: ~nsNodeInfoManager(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager) michael@0: michael@0: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsNodeInfoManager) michael@0: michael@0: /** michael@0: * Initialize the nodeinfo manager with a document. michael@0: */ michael@0: nsresult Init(nsIDocument *aDocument); michael@0: michael@0: /** michael@0: * Release the reference to the document, this will be called when michael@0: * the document is going away. michael@0: */ michael@0: void DropDocumentReference(); michael@0: michael@0: /** michael@0: * Methods for creating nodeinfo's from atoms and/or strings. michael@0: */ michael@0: already_AddRefed GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, michael@0: int32_t aNamespaceID, michael@0: uint16_t aNodeType, michael@0: nsIAtom* aExtraName = nullptr); michael@0: nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, michael@0: int32_t aNamespaceID, uint16_t aNodeType, michael@0: nsINodeInfo** aNodeInfo); michael@0: nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, michael@0: const nsAString& aNamespaceURI, uint16_t aNodeType, michael@0: nsINodeInfo** aNodeInfo); michael@0: michael@0: /** michael@0: * Returns the nodeinfo for text nodes. Can return null if OOM. michael@0: */ michael@0: already_AddRefed GetTextNodeInfo(); michael@0: michael@0: /** michael@0: * Returns the nodeinfo for comment nodes. Can return null if OOM. michael@0: */ michael@0: already_AddRefed GetCommentNodeInfo(); michael@0: michael@0: /** michael@0: * Returns the nodeinfo for the document node. Can return null if OOM. michael@0: */ michael@0: already_AddRefed GetDocumentNodeInfo(); michael@0: michael@0: /** michael@0: * Retrieve a pointer to the document that owns this node info michael@0: * manager. michael@0: */ michael@0: nsIDocument* GetDocument() const michael@0: { michael@0: return mDocument; michael@0: } michael@0: michael@0: /** michael@0: * Gets the principal of the document this nodeinfo manager belongs to. michael@0: */ michael@0: nsIPrincipal *DocumentPrincipal() const { michael@0: NS_ASSERTION(mPrincipal, "How'd that happen?"); michael@0: return mPrincipal; michael@0: } michael@0: michael@0: void RemoveNodeInfo(nsNodeInfo *aNodeInfo); michael@0: michael@0: nsBindingManager* GetBindingManager() const michael@0: { michael@0: return mBindingManager; michael@0: } michael@0: michael@0: protected: michael@0: friend class nsDocument; michael@0: friend class nsXULPrototypeDocument; michael@0: friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** , michael@0: nsNodeInfoManager *, michael@0: nsIAtom *, michael@0: const nsAString& , michael@0: const nsAString& , michael@0: const nsAString& ); michael@0: michael@0: /** michael@0: * Sets the principal of the document this nodeinfo manager belongs to. michael@0: */ michael@0: void SetDocumentPrincipal(nsIPrincipal *aPrincipal); michael@0: michael@0: private: michael@0: static int NodeInfoInnerKeyCompare(const void *key1, const void *key2); michael@0: static PLHashNumber GetNodeInfoInnerHashValue(const void *key); michael@0: static int DropNodeInfoDocument(PLHashEntry *he, int hashIndex, michael@0: void *arg); michael@0: michael@0: PLHashTable *mNodeInfoHash; michael@0: nsIDocument *mDocument; // WEAK michael@0: uint32_t mNonDocumentNodeInfos; michael@0: nsCOMPtr mPrincipal; // Never null after Init() succeeds. michael@0: nsCOMPtr mDefaultPrincipal; // Never null after Init() succeeds michael@0: nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership michael@0: nsINodeInfo *mCommentNodeInfo; // WEAK to avoid circular ownership michael@0: nsINodeInfo *mDocumentNodeInfo; // WEAK to avoid circular ownership michael@0: nsRefPtr mBindingManager; michael@0: }; michael@0: michael@0: #endif /* nsNodeInfoManager_h___ */