Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsEmbedFunctions.cpp File Reference
#include "nsXULAppAPI.h"
#include <stdlib.h>
#include "nsIAppStartupNotifier.h"
#include "nsIDirectoryService.h"
#include "nsIEventQueueService.h"
#include "nsILocalFile.h"
#include "nsIToolkitChromeRegistry.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsArrayEnumerator.h"
#include "nsCOMArray.h"
#include "nsDirectoryServiceDefs.h"
#include "nsEnumeratorUtils.h"
#include "nsStaticComponents.h"
#include "nsString.h"

Go to the source code of this file.


class  nsEmbeddingDirProvider


 NS_IMPL_ISUPPORTS2 (nsEmbeddingDirProvider, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2) NS_IMETHODIMP nsEmbeddingDirProvider
void XRE_GetStaticComponents (nsStaticModuleInfo const **aStaticComponents, PRUint32 *aComponentCount)
 Get the static components built in to libxul.
nsresult XRE_InitEmbedding (nsILocalFile *aLibXULDirectory, nsILocalFile *aAppDirectory, nsIDirectoryServiceProvider *aAppDirProvider, nsStaticModuleInfo const *aStaticComponents, PRUint32 aStaticComponentCount)
 Initialize libXUL for embedding purposes.
void XRE_TermEmbedding ()


static nsStaticModuleInfosCombined
static PRInt32 sInitCounter

Function Documentation

Definition at line 76 of file nsEmbedFunctions.cpp.

  nsresult rv;

  if (mAppProvider) {
    rv = mAppProvider->GetFile(aProperty, aPersistent, aFile);
    if (NS_SUCCEEDED(rv) && *aFile)
      return rv;

  if (!strcmp(aProperty, NS_OS_CURRENT_PROCESS_DIR) ||
      !strcmp(aProperty, NS_APP_INSTALL_CLEANUP_DIR)) {
    // NOTE: this is *different* than NS_XPCOM_CURRENT_PROCESS_DIR. This points
    // to the application dir. NS_XPCOM_CURRENT_PROCESS_DIR points to the toolkit.
    return mAppDir->Clone(aFile);

  if (!strcmp(aProperty, NS_GRE_DIR)) {
    return mGREDir->Clone(aFile);

  if (!strcmp(aProperty, NS_APP_PREF_DEFAULTS_50_DIR))
    nsCOMPtr<nsIFile> file;
    rv = mAppDir->Clone(getter_AddRefs(file));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = file->AppendNative(NS_LITERAL_CSTRING("defaults"));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = file->AppendNative(NS_LITERAL_CSTRING("pref"));
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ADDREF(*aFile = file);
    return NS_OK;


Here is the call graph for this function:

void XRE_GetStaticComponents ( nsStaticModuleInfo const **  aStaticComponents,
PRUint32 aComponentCount 

Get the static components built in to libxul.

Definition at line 175 of file nsEmbedFunctions.cpp.

  *aStaticComponents = kPStaticModules;
  *aComponentCount = kStaticModuleCount;

Here is the caller graph for this function:

nsresult XRE_InitEmbedding ( nsILocalFile aLibXULDirectory,
nsILocalFile aAppDirectory,
nsIDirectoryServiceProvider aAppDirProvider = nsnull,
nsStaticModuleInfo const aStaticComponents = nsnull,
PRUint32  aStaticComponentCount = 0 

Initialize libXUL for embedding purposes.

aLibXULDirectoryThe directory in which the libXUL shared library was found.
aAppDirectoryThe directory in which the application components and resources can be found. This will map to the "resource:app" directory service key.
aAppDirProviderA directory provider for the application. This provider will be aggregated by a libxul provider which will provide the base required GRE keys.
aStaticComponentsStatic components provided by the embedding application. This should not include the components from XRE_GetStaticComponents. May be null if there are no static components.
aStaticComponentCountthe number of static components in aStaticComponents
This function must be called from the "main" thread.
At the present time, this function may only be called once in a given process. Use XRE_TermEmbedding to clean up and free resources allocated by XRE_InitEmbedding.

Definition at line 186 of file nsEmbedFunctions.cpp.

  if (++sInitCounter > 1)
    return NS_OK;


  nsresult rv;

  nsCOMPtr<nsIDirectoryServiceProvider> dirSvc
    (new nsEmbeddingDirProvider(aLibXULDirectory,
  if (!dirSvc)

  // Combine the toolkit static components and the app components.
  PRUint32 combinedCount = kStaticModuleCount + aStaticComponentCount;

  sCombined = new nsStaticModuleInfo[combinedCount];
  if (!sCombined)

  memcpy(sCombined, kPStaticModules,
         sizeof(nsStaticModuleInfo) * kStaticModuleCount);
  memcpy(sCombined + kStaticModuleCount, aStaticComponents,
         sizeof(nsStaticModuleInfo) * aStaticComponentCount);

  rv = NS_InitXPCOM3(nsnull, aAppDirectory, dirSvc,
                     sCombined, combinedCount);
  if (NS_FAILED(rv))
    return rv;

  // We do not need to autoregister components here. The CheckUpdateFile()
  // bits in NS_InitXPCOM3 check for an .autoreg file. If the app wants
  // to autoregister every time (for instance, if it's debug), it can do
  // so after we return from this function.

  nsCOMPtr<nsIEventQueueService> eventQService
  if (NS_FAILED(rv))
    return rv;

  rv = eventQService->CreateThreadEventQueue();
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIObserver> startupNotifier
  if (!startupNotifier)
    return NS_ERROR_FAILURE;

  startupNotifier->Observe(nsnull, APPSTARTUP_TOPIC, nsnull);

  return NS_OK;

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 249 of file nsEmbedFunctions.cpp.

  if (--sInitCounter != 0)

  delete [] sCombined;

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

Definition at line 182 of file nsEmbedFunctions.cpp.

Definition at line 183 of file nsEmbedFunctions.cpp.