2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A class for handing out nodeinfos and ensuring sharing of them as needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsNodeInfoManager_h___
|
|
|
|
#define nsNodeInfoManager_h___
|
|
|
|
|
2012-08-06 05:02:08 -07:00
|
|
|
#include "mozilla/Attributes.h" // for MOZ_FINAL
|
|
|
|
#include "nsCOMPtr.h" // for member
|
|
|
|
#include "nsCycleCollectionParticipant.h" // for NS_DECL_CYCLE_*
|
|
|
|
#include "plhash.h" // for typedef PLHashNumber
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-06 05:02:08 -07:00
|
|
|
class nsAString;
|
|
|
|
class nsBindingManager;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIAtom;
|
|
|
|
class nsIDocument;
|
2012-08-06 05:02:08 -07:00
|
|
|
class nsIDOMDocumentType;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsINodeInfo;
|
|
|
|
class nsIPrincipal;
|
2012-08-06 05:02:08 -07:00
|
|
|
class nsNodeInfo;
|
|
|
|
struct PLHashEntry;
|
|
|
|
struct PLHashTable;
|
|
|
|
template<class T> struct already_AddRefed;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-10 21:06:42 -07:00
|
|
|
class nsNodeInfoManager MOZ_FINAL : public nsISupports
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsNodeInfoManager();
|
|
|
|
~nsNodeInfoManager();
|
|
|
|
|
2012-06-26 13:35:29 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsNodeInfoManager)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the nodeinfo manager with a document.
|
|
|
|
*/
|
|
|
|
nsresult Init(nsIDocument *aDocument);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release the reference to the document, this will be called when
|
|
|
|
* the document is going away.
|
|
|
|
*/
|
|
|
|
void DropDocumentReference();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Methods for creating nodeinfo's from atoms and/or strings.
|
|
|
|
*/
|
2008-09-12 15:32:18 -07:00
|
|
|
already_AddRefed<nsINodeInfo> GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
|
2011-06-14 00:56:49 -07:00
|
|
|
PRInt32 aNamespaceID,
|
|
|
|
PRUint16 aNodeType,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIAtom* aExtraName = nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
2011-06-14 00:56:49 -07:00
|
|
|
PRInt32 aNamespaceID, PRUint16 aNodeType,
|
|
|
|
nsINodeInfo** aNodeInfo);
|
2008-10-07 11:53:22 -07:00
|
|
|
nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
|
2011-06-14 00:56:49 -07:00
|
|
|
const nsAString& aNamespaceURI, PRUint16 aNodeType,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINodeInfo** aNodeInfo);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the nodeinfo for text nodes. Can return null if OOM.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsINodeInfo> GetTextNodeInfo();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the nodeinfo for comment nodes. Can return null if OOM.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsINodeInfo> GetCommentNodeInfo();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the nodeinfo for the document node. Can return null if OOM.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsINodeInfo> GetDocumentNodeInfo();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a pointer to the document that owns this node info
|
|
|
|
* manager.
|
|
|
|
*/
|
|
|
|
nsIDocument* GetDocument() const
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the principal of the document this nodeinfo manager belongs to.
|
|
|
|
*/
|
|
|
|
nsIPrincipal *DocumentPrincipal() const {
|
|
|
|
NS_ASSERTION(mPrincipal, "How'd that happen?");
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveNodeInfo(nsNodeInfo *aNodeInfo);
|
|
|
|
|
2008-03-28 07:09:00 -07:00
|
|
|
nsBindingManager* GetBindingManager() const
|
|
|
|
{
|
|
|
|
return mBindingManager;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
friend class nsDocument;
|
|
|
|
friend class nsXULPrototypeDocument;
|
|
|
|
friend nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** ,
|
|
|
|
nsNodeInfoManager *,
|
|
|
|
nsIAtom *,
|
|
|
|
const nsAString& ,
|
|
|
|
const nsAString& ,
|
|
|
|
const nsAString& );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the principal of the document this nodeinfo manager belongs to.
|
|
|
|
*/
|
|
|
|
void SetDocumentPrincipal(nsIPrincipal *aPrincipal);
|
|
|
|
|
|
|
|
private:
|
2008-10-10 08:04:34 -07:00
|
|
|
static PRIntn NodeInfoInnerKeyCompare(const void *key1, const void *key2);
|
|
|
|
static PLHashNumber GetNodeInfoInnerHashValue(const void *key);
|
2011-06-14 17:58:57 -07:00
|
|
|
static PRIntn DropNodeInfoDocument(PLHashEntry *he, PRIntn hashIndex,
|
|
|
|
void *arg);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PLHashTable *mNodeInfoHash;
|
|
|
|
nsIDocument *mDocument; // WEAK
|
2011-07-26 04:11:14 -07:00
|
|
|
PRUint32 mNonDocumentNodeInfos;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPrincipal *mPrincipal; // STRONG, but not nsCOMPtr to avoid include hell
|
|
|
|
// while inlining DocumentPrincipal(). Never null
|
|
|
|
// after Init() succeeds.
|
|
|
|
nsCOMPtr<nsIPrincipal> mDefaultPrincipal; // Never null after Init() succeeds
|
|
|
|
nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership
|
|
|
|
nsINodeInfo *mCommentNodeInfo; // WEAK to avoid circular ownership
|
|
|
|
nsINodeInfo *mDocumentNodeInfo; // WEAK to avoid circular ownership
|
2008-03-28 07:09:00 -07:00
|
|
|
nsBindingManager* mBindingManager; // STRONG, but not nsCOMPtr to avoid
|
|
|
|
// include hell while inlining
|
|
|
|
// GetBindingManager().
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsNodeInfoManager_h___ */
|