Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
nsNodeInfoManager Class Reference

#include <nsNodeInfoManager.h>

Collaboration diagram for nsNodeInfoManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsNodeInfoManager ()
 ~nsNodeInfoManager ()
nsrefcnt AddRef (void)
nsrefcnt Release (void)
nsresult Init (nsIDocument *aDocument)
 Initialize the nodeinfo manager with a document.
void DropDocumentReference ()
 Release the reference to the document, this will be called when the document is going away.
nsresult GetNodeInfo (nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, nsINodeInfo **aNodeInfo)
 Methods for creating nodeinfo's from atoms and/or strings.
nsresult GetNodeInfo (const nsAString &aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, nsINodeInfo **aNodeInfo)
nsresult GetNodeInfo (const nsAString &aQualifiedName, const nsAString &aNamespaceURI, nsINodeInfo **aNodeInfo)
nsIDocumentGetDocument () const
 Retrieve a pointer to the document that owns this node info manager.
nsIPrincipalGetDocumentPrincipal ()
 Gets the principal of the document associated with this.
void SetDocumentPrincipal (nsIPrincipal *aPrincipal)
 Sets the principal of the nodeinfo manager.
nsresult GetNodeInfos (nsCOMArray< nsINodeInfo > *aArray)
 Populate the given nsCOMArray with all of the nsINodeInfos managed by this manager.
void RemoveNodeInfo (nsNodeInfo *aNodeInfo)

Static Private Member Functions

static PRIntn PR_CALLBACK NodeInfoInnerKeyCompare (const void *key1, const void *key2)
static PLHashNumber PR_CALLBACK GetNodeInfoInnerHashValue (const void *key)

Private Attributes

nsAutoRefCnt mRefCnt
NS_DECL_OWNINGTHREAD PLHashTablemNodeInfoHash
nsIDocumentmDocument
nsCOMPtr< nsIPrincipalmPrincipal

Static Private Attributes

static PRUint32 gNodeManagerCount

Detailed Description

Definition at line 52 of file nsNodeInfoManager.h.


Constructor & Destructor Documentation

Definition at line 81 of file nsNodeInfoManager.cpp.

Here is the call graph for this function:

Definition at line 95 of file nsNodeInfoManager.cpp.

{
  --gNodeManagerCount;

  if (mNodeInfoHash)
    PL_HashTableDestroy(mNodeInfoHash);


  if (gNodeManagerCount == 0) {
    nsNodeInfo::ClearCache();
  }

#ifdef DEBUG_jst
  printf ("Removing NodeInfoManager, gcount = %d\n", gNodeManagerCount);
#endif
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 114 of file nsNodeInfoManager.cpp.

{
  NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");

  nsrefcnt count = PR_AtomicIncrement((PRInt32*)&mRefCnt);
  NS_LOG_ADDREF(this, count, "nsNodeInfoManager", sizeof(*this));

  return count;
}

Here is the call graph for this function:

Release the reference to the document, this will be called when the document is going away.

Definition at line 153 of file nsNodeInfoManager.cpp.

{
  if (mDocument) {
    // If the document has a uri we'll ask for it's principal. Otherwise we'll
    // consider this document 'anonymous'. We don't want to call GetPrincipal
    // on a document that doesn't have a URI since that'll give an assertion
    // that we're creating a principal without having a uri.
    // This happens in a few cases where a document is created and then
    // immediately dropped without ever getting a URI.
    if (mDocument->GetDocumentURI()) {
      mPrincipal = mDocument->GetPrincipal();
    }
  }
  mDocument = nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve a pointer to the document that owns this node info manager.

Definition at line 87 of file nsNodeInfoManager.h.

  {
    return mDocument;
  }

Here is the caller graph for this function:

Gets the principal of the document associated with this.

Definition at line 261 of file nsNodeInfoManager.cpp.

{
  NS_ASSERTION(!mDocument || !mPrincipal,
               "how'd we end up with both a document and a principal?");

  if (mDocument) {
    // If the document has a uri we'll ask for it's principal. Otherwise we'll
    // consider this document 'anonymous'
    if (!mDocument->GetDocumentURI()) {
      return nsnull;
    }

    return mDocument->GetPrincipal();
  }

  return mPrincipal;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNodeInfoManager::GetNodeInfo ( nsIAtom aName,
nsIAtom aPrefix,
PRInt32  aNamespaceID,
nsINodeInfo **  aNodeInfo 
)

Methods for creating nodeinfo's from atoms and/or strings.

Definition at line 171 of file nsNodeInfoManager.cpp.

{
  NS_ENSURE_ARG_POINTER(aName);
  NS_ASSERTION(!aName->Equals(EmptyString()),
               "Don't pass an empty string to GetNodeInfo, fix caller.");

  nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID);

  void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);

  if (node) {
    *aNodeInfo = NS_STATIC_CAST(nsINodeInfo *, node);

    NS_ADDREF(*aNodeInfo);

    return NS_OK;
  }

  nsNodeInfo *newNodeInfo = nsNodeInfo::Create();
  NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY);

  NS_ADDREF(newNodeInfo);

  nsresult rv = newNodeInfo->Init(aName, aPrefix, aNamespaceID, this);
  NS_ENSURE_SUCCESS(rv, rv);

  PLHashEntry *he;
  he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
  NS_ENSURE_TRUE(he, NS_ERROR_OUT_OF_MEMORY);

  *aNodeInfo = newNodeInfo;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNodeInfoManager::GetNodeInfo ( const nsAString &  aName,
nsIAtom aPrefix,
PRInt32  aNamespaceID,
nsINodeInfo **  aNodeInfo 
)

Definition at line 209 of file nsNodeInfoManager.cpp.

{
  nsCOMPtr<nsIAtom> name = do_GetAtom(aName);
  return nsNodeInfoManager::GetNodeInfo(name, aPrefix, aNamespaceID,
                                        aNodeInfo);
}

Here is the call graph for this function:

nsresult nsNodeInfoManager::GetNodeInfo ( const nsAString &  aQualifiedName,
const nsAString &  aNamespaceURI,
nsINodeInfo **  aNodeInfo 
)

Definition at line 219 of file nsNodeInfoManager.cpp.

{
  NS_ENSURE_ARG(!aQualifiedName.IsEmpty());

  nsAString::const_iterator start, end;
  aQualifiedName.BeginReading(start);
  aQualifiedName.EndReading(end);

  nsCOMPtr<nsIAtom> prefixAtom;

  nsAString::const_iterator iter(start);

  if (FindCharInReadable(':', iter, end)) {
    prefixAtom = do_GetAtom(Substring(start, iter));
    NS_ENSURE_TRUE(prefixAtom, NS_ERROR_OUT_OF_MEMORY);

    start = ++iter; // step over the ':'

    if (iter == end) {
      // No data after the ':'.

      return NS_ERROR_INVALID_ARG;
    }
  }

  nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(Substring(start, end));
  NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);

  PRInt32 nsid = kNameSpaceID_None;

  if (!aNamespaceURI.IsEmpty()) {
    nsresult rv = nsContentUtils::GetNSManagerWeakRef()->
      RegisterNameSpace(aNamespaceURI, nsid);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return GetNodeInfo(nameAtom, prefixAtom, nsid, aNodeInfo);
}

Here is the call graph for this function:

Definition at line 53 of file nsNodeInfoManager.cpp.

{
  NS_ASSERTION(key, "Null key passed to nsNodeInfo::GetHashValue!");

  const nsINodeInfo::nsNodeInfoInner *node =
    NS_REINTERPRET_CAST(const nsINodeInfo::nsNodeInfoInner *, key);

  // Is this an acceptable hash value?
  return (PLHashNumber(NS_PTR_TO_INT32(node->mName)) & 0xffff) >> 8;
}

Here is the caller graph for this function:

Populate the given nsCOMArray with all of the nsINodeInfos managed by this manager.

Initialize the nodeinfo manager with a document.

Definition at line 140 of file nsNodeInfoManager.cpp.

{
  NS_ENSURE_TRUE(mNodeInfoHash, NS_ERROR_OUT_OF_MEMORY);

  mDocument = aDocument;
  if (aDocument) {
    mPrincipal = nsnull;
  }

  return NS_OK;
}
PRIntn nsNodeInfoManager::NodeInfoInnerKeyCompare ( const void key1,
const void key2 
) [static, private]

Definition at line 66 of file nsNodeInfoManager.cpp.

{
  NS_ASSERTION(key1 && key2, "Null key passed to NodeInfoInnerKeyCompare!");

  const nsINodeInfo::nsNodeInfoInner *node1 =
    NS_REINTERPRET_CAST(const nsINodeInfo::nsNodeInfoInner *, key1);
  const nsINodeInfo::nsNodeInfoInner *node2 =
    NS_REINTERPRET_CAST(const nsINodeInfo::nsNodeInfoInner *, key2);

  return (node1->mName == node2->mName &&
          node1->mPrefix == node2->mPrefix &&
          node1->mNamespaceID == node2->mNamespaceID);
}

Here is the caller graph for this function:

Definition at line 125 of file nsNodeInfoManager.cpp.

{
  NS_PRECONDITION(0 != mRefCnt, "dup release");

  nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mRefCnt);
  NS_LOG_RELEASE(this, count, "nsNodeInfoManager");
  if (count == 0) {
    mRefCnt = 1; /* stabilize */
    delete this;
  }

  return count;
}

Here is the call graph for this function:

Definition at line 290 of file nsNodeInfoManager.cpp.

{
  NS_WARN_IF_FALSE(aNodeInfo, "Trying to remove null nodeinfo from manager!");

  if (aNodeInfo) {
#ifdef DEBUG
    PRBool ret =
#endif
    PL_HashTableRemove(mNodeInfoHash, &aNodeInfo->mInner);

    NS_WARN_IF_FALSE(ret, "Can't find nsINodeInfo to remove!!!");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Sets the principal of the nodeinfo manager.

This should only be called when this nodeinfo manager isn't connected to an nsIDocument.

Definition at line 280 of file nsNodeInfoManager.cpp.

{
  NS_ASSERTION(!mDocument,
               "Don't set a principal, we already have a document.");
  if (!mDocument) {
    mPrincipal = aPrincipal;
  }
}

Member Data Documentation

Definition at line 123 of file nsNodeInfoManager.h.

Definition at line 120 of file nsNodeInfoManager.h.

Definition at line 119 of file nsNodeInfoManager.h.

Definition at line 121 of file nsNodeInfoManager.h.

Definition at line 116 of file nsNodeInfoManager.h.


The documentation for this class was generated from the following files: