Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsScriptNameSpaceManager Class Reference

#include <nsScriptNameSpaceManager.h>

List of all members.

Public Member Functions

 nsScriptNameSpaceManager ()
virtual ~nsScriptNameSpaceManager ()
nsresult Init ()
nsresult InitForContext (nsIScriptContext *aContext)
nsresult LookupName (const nsAString &aName, const nsGlobalNameStruct **aNameStruct, const PRUnichar **aClassName=nsnull)
nsresult RegisterClassName (const char *aClassName, PRInt32 aDOMClassInfoID)
nsresult RegisterClassProto (const char *aClassName, const nsIID *aConstructorProtoIID, PRBool *aFoundOld)
nsresult RegisterExternalInterfaces (PRBool aAsProto)
nsresult RegisterExternalClassName (const char *aClassName, nsCID &aCID)
nsresult RegisterDOMCIData (const char *aName, nsDOMClassInfoExternalConstructorFnc aConstructorFptr, const nsIID *aProtoChainInterface, const nsIID **aInterfaces, PRUint32 aScriptableFlags, PRBool aHasClassInterface, const nsCID *aConstructorCID)
nsGlobalNameStructGetConstructorProto (const nsGlobalNameStruct *aStruct)

Protected Member Functions

nsGlobalNameStructAddToHash (const char *aKey)
nsresult FillHash (nsICategoryManager *aCategoryManager, const char *aCategory, nsGlobalNameStruct::nametype aType)
nsresult FillHashWithDOMInterfaces ()
nsresult RegisterInterface (const char *aIfName, const nsIID *aIfIID, PRBool *aFoundOld)

Protected Attributes

PLDHashTable mGlobalNames
PRPackedBool mIsInitialized

Detailed Description

Definition at line 104 of file nsScriptNameSpaceManager.h.


Constructor & Destructor Documentation

Definition at line 143 of file nsScriptNameSpaceManager.cpp.

Definition at line 148 of file nsScriptNameSpaceManager.cpp.

{
  if (mIsInitialized) {
    // Destroy the hash
    PL_DHashTableFinish(&mGlobalNames);
  }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 157 of file nsScriptNameSpaceManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsScriptNameSpaceManager::FillHash ( nsICategoryManager aCategoryManager,
const char *  aCategory,
nsGlobalNameStruct::nametype  aType 
) [protected]

Definition at line 191 of file nsScriptNameSpaceManager.cpp.

{
  nsCOMPtr<nsIComponentRegistrar> registrar;
  nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsISimpleEnumerator> e;
  rv = aCategoryManager->EnumerateCategory(aCategory, getter_AddRefs(e));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString categoryEntry;
  nsXPIDLCString contractId;
  nsCOMPtr<nsISupports> entry;

  while (NS_SUCCEEDED(e->GetNext(getter_AddRefs(entry)))) {
    nsCOMPtr<nsISupportsCString> category(do_QueryInterface(entry));

    if (!category) {
      NS_WARNING("Category entry not an nsISupportsCString!");

      continue;
    }

    rv = category->GetData(categoryEntry);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = aCategoryManager->GetCategoryEntry(aCategory, categoryEntry.get(),
                                            getter_Copies(contractId));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCID *cidPtr;
    rv = registrar->ContractIDToCID(contractId, &cidPtr);

    if (NS_FAILED(rv)) {
      NS_WARNING("Bad contract id registed with the script namespace manager");

      continue;
    }

    // Copy CID onto the stack, so we can free it right away and avoid having
    // to add cleanup code at every exit point from this loop/function.
    nsCID cid = *cidPtr;
    nsMemory::Free(cidPtr);

    if (aType == nsGlobalNameStruct::eTypeExternalConstructor) {
      nsXPIDLCString constructorProto;
      rv = aCategoryManager->GetCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
                                              categoryEntry.get(),
                                              getter_Copies(constructorProto));
      if (NS_SUCCEEDED(rv)) {
        nsGlobalNameStruct *s = AddToHash(categoryEntry.get());
        NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

        if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
          s->mAlias = new nsGlobalNameStruct::ConstructorAlias;
          if (!s->mAlias) {
            // Free entry
            NS_ConvertASCIItoUCS2 key(categoryEntry);
            PL_DHashTableOperate(&mGlobalNames,
                                 &key,
                                 PL_DHASH_REMOVE);
            return NS_ERROR_OUT_OF_MEMORY;
          }
          s->mType = nsGlobalNameStruct::eTypeExternalConstructorAlias;
          s->mAlias->mCID = cid;
          AppendASCIItoUTF16(constructorProto, s->mAlias->mProtoName);
          s->mAlias->mProto = nsnull;
        } else {
          NS_WARNING("Global script name not overwritten!");
        }

        continue;
      }
    }

    nsGlobalNameStruct *s = AddToHash(categoryEntry.get());
    NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

    if (s->mType == nsGlobalNameStruct::eTypeNotInitialized) {
      s->mType = aType;
      s->mCID = cid;
    } else {
      NS_WARNING("Global script name not overwritten!");
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 292 of file nsScriptNameSpaceManager.cpp.

{
  nsCOMPtr<nsIInterfaceInfoManager> iim =
    dont_AddRef(XPTI_GetInterfaceInfoManager());
  NS_ENSURE_TRUE(iim, NS_ERROR_UNEXPECTED);

  // First look for all interfaces whose name starts with nsIDOM
  nsCOMPtr<nsIEnumerator> domInterfaces;
  nsresult rv =
    iim->EnumerateInterfacesWhoseNamesStartWith(NS_DOM_INTERFACE_PREFIX,
                                                getter_AddRefs(domInterfaces));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsISupports> entry;

  rv = domInterfaces->First();

  if (NS_FAILED(rv)) {
    // Empty interface list?

    NS_WARNING("What, no nsIDOM interfaces installed?");

    return NS_OK;
  }

  PRBool found_old;
  nsCOMPtr<nsIInterfaceInfo> if_info;
  nsXPIDLCString if_name;
  const nsIID *iid;

  for ( ; domInterfaces->IsDone() == NS_ENUMERATOR_FALSE; domInterfaces->Next()) {
    rv = domInterfaces->CurrentItem(getter_AddRefs(entry));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIInterfaceInfo> if_info(do_QueryInterface(entry));
    if_info->GetName(getter_Copies(if_name));
    if_info->GetIIDShared(&iid);
    rv = RegisterInterface(if_name.get() + sizeof(NS_DOM_INTERFACE_PREFIX) - 1,
                           iid, &found_old);

#ifdef DEBUG
    NS_ASSERTION(!found_old,
                 "Whaaa, interface name already in hash!");
#endif
  }

  // Next, look for externally registered DOM interfaces
  rv = RegisterExternalInterfaces(PR_FALSE);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 172 of file nsScriptNameSpaceManager.cpp.

{
  NS_ASSERTION(aStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias,
               "This function only works on constructor aliases!");
  if (!aStruct->mAlias->mProto) {
    GlobalNameMapEntry *proto =
      NS_STATIC_CAST(GlobalNameMapEntry *,
                     PL_DHashTableOperate(&mGlobalNames,
                                          &aStruct->mAlias->mProtoName,
                                          PL_DHASH_LOOKUP));

    if (PL_DHASH_ENTRY_IS_BUSY(proto)) {
      aStruct->mAlias->mProto = &proto->mGlobalName;
    }
  }
  return aStruct->mAlias->mProto;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 526 of file nsScriptNameSpaceManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsScriptNameSpaceManager::LookupName ( const nsAString &  aName,
const nsGlobalNameStruct **  aNameStruct,
const PRUnichar **  aClassName = nsnull 
)

Definition at line 534 of file nsScriptNameSpaceManager.cpp.

{
  GlobalNameMapEntry *entry =
    NS_STATIC_CAST(GlobalNameMapEntry *,
                   PL_DHashTableOperate(&mGlobalNames, &aName,
                                        PL_DHASH_LOOKUP));

  if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
    *aNameStruct = &entry->mGlobalName;
    if (aClassName) {
      *aClassName = entry->mKey.get();
    }
  } else {
    *aNameStruct = nsnull;
    if (aClassName) {
      *aClassName = nsnull;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsScriptNameSpaceManager::RegisterClassName ( const char *  aClassName,
PRInt32  aDOMClassInfoID 
)

Definition at line 559 of file nsScriptNameSpaceManager.cpp.

{
  if (!nsCRT::IsAscii(aClassName)) {
    NS_ERROR("Trying to register a non-ASCII class name");
    return NS_OK;
  }
  nsGlobalNameStruct *s = AddToHash(aClassName);
  NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

  if (s->mType == nsGlobalNameStruct::eTypeClassConstructor) {
    return NS_OK;
  }

  // If a external constructor is already defined with aClassName we
  // won't overwrite it.

  if (s->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
    return NS_OK;
  }

  NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
               s->mType == nsGlobalNameStruct::eTypeInterface,
               "Whaaa, JS environment name clash!");

  s->mType = nsGlobalNameStruct::eTypeClassConstructor;
  s->mDOMClassInfoID = aDOMClassInfoID;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsScriptNameSpaceManager::RegisterClassProto ( const char *  aClassName,
const nsIID aConstructorProtoIID,
PRBool aFoundOld 
)

Definition at line 591 of file nsScriptNameSpaceManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsScriptNameSpaceManager::RegisterDOMCIData ( const char *  aName,
nsDOMClassInfoExternalConstructorFnc  aConstructorFptr,
const nsIID aProtoChainInterface,
const nsIID **  aInterfaces,
PRUint32  aScriptableFlags,
PRBool  aHasClassInterface,
const nsCID aConstructorCID 
)

Definition at line 640 of file nsScriptNameSpaceManager.cpp.

{
  nsGlobalNameStruct *s = AddToHash(aName);
  NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

  // If an external constructor is already defined with aClassName we
  // won't overwrite it.

  if (s->mType == nsGlobalNameStruct::eTypeClassConstructor ||
      s->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
    return NS_OK;
  }

  // XXX Should we bail out here?
  NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
               s->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator,
               "Someone tries to register classinfo data for a class that isn't new or external!");

  s->mData = new nsExternalDOMClassInfoData;
  NS_ENSURE_TRUE(s->mData, NS_ERROR_OUT_OF_MEMORY);

  s->mType = nsGlobalNameStruct::eTypeExternalClassInfo;
  s->mData->mName = aName;
  if (aConstructorFptr)
    s->mData->u.mExternalConstructorFptr = aConstructorFptr;
  else
    // null constructor will cause us to use nsDOMGenericSH::doCreate
    s->mData->u.mExternalConstructorFptr = nsnull;
  s->mData->mCachedClassInfo = nsnull;
  s->mData->mProtoChainInterface = aProtoChainInterface;
  s->mData->mInterfaces = aInterfaces;
  s->mData->mScriptableFlags = aScriptableFlags;
  s->mData->mHasClassInterface = aHasClassInterface;
  s->mData->mConstructorCID = aConstructorCID;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 616 of file nsScriptNameSpaceManager.cpp.

{
  nsGlobalNameStruct *s = AddToHash(aClassName);
  NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

  // If an external constructor is already defined with aClassName we
  // won't overwrite it.

  if (s->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
    return NS_OK;
  }

  NS_ASSERTION(s->mType == nsGlobalNameStruct::eTypeNotInitialized ||
               s->mType == nsGlobalNameStruct::eTypeInterface,
               "Whaaa, JS environment name clash!");

  s->mType = nsGlobalNameStruct::eTypeExternalClassInfoCreator;
  s->mCID = aCID;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 345 of file nsScriptNameSpaceManager.cpp.

{
  nsresult rv;
  nsCOMPtr<nsICategoryManager> cm =
    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIInterfaceInfoManager> iim =
    dont_AddRef(XPTI_GetInterfaceInfoManager());
  NS_ENSURE_TRUE(iim, NS_ERROR_NOT_AVAILABLE);

  nsCOMPtr<nsISimpleEnumerator> enumerator;
  rv = cm->EnumerateCategory(JAVASCRIPT_DOM_INTERFACE,
                             getter_AddRefs(enumerator));
  NS_ENSURE_SUCCESS(rv, rv);

  nsXPIDLCString IID_string;
  nsCAutoString category_entry;
  const char* if_name;
  nsCOMPtr<nsISupports> entry;
  nsCOMPtr<nsIInterfaceInfo> if_info;
  PRBool found_old, dom_prefix;

  while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) {
    nsCOMPtr<nsISupportsCString> category(do_QueryInterface(entry));

    if (!category) {
      NS_WARNING("Category entry not an nsISupportsCString!");

      continue;
    }

    rv = category->GetData(category_entry);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = cm->GetCategoryEntry(JAVASCRIPT_DOM_INTERFACE, category_entry.get(),
                              getter_Copies(IID_string));
    NS_ENSURE_SUCCESS(rv, rv);

    nsIID primary_IID;
    if (!primary_IID.Parse(IID_string) ||
        primary_IID.Equals(NS_GET_IID(nsISupports))) {
      NS_ERROR("Invalid IID registered with the script namespace manager!");
      continue;
    }

    iim->GetInfoForIID(&primary_IID, getter_AddRefs(if_info));

    while (if_info) {
      const nsIID *iid;
      if_info->GetIIDShared(&iid);
      NS_ENSURE_TRUE(iid, NS_ERROR_UNEXPECTED);

      if (iid->Equals(NS_GET_IID(nsISupports))) {
        break;
      }

      if_info->GetNameShared(&if_name);
      dom_prefix = (strncmp(if_name, NS_DOM_INTERFACE_PREFIX,
                            sizeof(NS_DOM_INTERFACE_PREFIX) - 1) == 0);

      const char* name;
      if (dom_prefix) {
        if (!aAsProto) {
          // nsIDOM* interfaces have already been registered.
          break;
        }
        name = if_name + sizeof(NS_DOM_INTERFACE_PREFIX) - 1;
      } else {
        name = if_name + sizeof(NS_INTERFACE_PREFIX) - 1;
      }

      if (aAsProto) {
        RegisterClassProto(name, iid, &found_old);
      } else {
        RegisterInterface(name, iid, &found_old);
      }

      if (found_old) {
        break;
      }

      nsCOMPtr<nsIInterfaceInfo> tmp(if_info);
      tmp->GetParent(getter_AddRefs(if_info));
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsScriptNameSpaceManager::RegisterInterface ( const char *  aIfName,
const nsIID aIfIID,
PRBool aFoundOld 
) [protected]

Definition at line 436 of file nsScriptNameSpaceManager.cpp.

{
  *aFoundOld = PR_FALSE;

  nsGlobalNameStruct *s = AddToHash(aIfName);
  NS_ENSURE_TRUE(s, NS_ERROR_OUT_OF_MEMORY);

  if (s->mType != nsGlobalNameStruct::eTypeNotInitialized) {
    *aFoundOld = PR_TRUE;

    return NS_OK;
  }

  s->mType = nsGlobalNameStruct::eTypeInterface;
  s->mIID = *aIfIID;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 163 of file nsScriptNameSpaceManager.h.

Definition at line 165 of file nsScriptNameSpaceManager.h.


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