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: #ifndef _nsXULAppAPI_h__ michael@0: #define _nsXULAppAPI_h__ michael@0: michael@0: #include "nsID.h" michael@0: #include "xrecore.h" michael@0: #include "nsXPCOM.h" michael@0: #include "nsISupports.h" michael@0: #include "prlog.h" michael@0: #include "nsXREAppData.h" michael@0: #include "js/TypeDecls.h" michael@0: michael@0: #include "mozilla/ArrayUtils.h" michael@0: #include "mozilla/Assertions.h" michael@0: michael@0: /** michael@0: * A directory service key which provides the platform-correct "application michael@0: * data" directory as follows, where $name and $vendor are as defined above and michael@0: * $vendor is optional: michael@0: * michael@0: * Windows: michael@0: * HOME = Documents and Settings\$USER\Application Data michael@0: * UAppData = $HOME[\$vendor]\$name michael@0: * michael@0: * Unix: michael@0: * HOME = ~ michael@0: * UAppData = $HOME/.[$vendor/]$name michael@0: * michael@0: * Mac: michael@0: * HOME = ~ michael@0: * UAppData = $HOME/Library/Application Support/$name michael@0: * michael@0: * Note that the "profile" member above will change the value of UAppData as michael@0: * follows: michael@0: * michael@0: * Windows: michael@0: * UAppData = $HOME\$profile michael@0: * michael@0: * Unix: michael@0: * UAppData = $HOME/.$profile michael@0: * michael@0: * Mac: michael@0: * UAppData = $HOME/Library/Application Support/$profile michael@0: */ michael@0: #define XRE_USER_APP_DATA_DIR "UAppData" michael@0: michael@0: /** michael@0: * A directory service key which provides a list of all enabled extension michael@0: * directories and files (packed XPIs). The list includes compatible michael@0: * platform-specific extension subdirectories. michael@0: * michael@0: * @note The directory list will have no members when the application is michael@0: * launched in safe mode. michael@0: */ michael@0: #define XRE_EXTENSIONS_DIR_LIST "XREExtDL" michael@0: michael@0: /** michael@0: * A directory service key which provides the executable file used to michael@0: * launch the current process. This is the same value returned by the michael@0: * XRE_GetBinaryPath function defined below. michael@0: */ michael@0: #define XRE_EXECUTABLE_FILE "XREExeF" michael@0: michael@0: /** michael@0: * A directory service key which specifies the profile michael@0: * directory. Unlike the NS_APP_USER_PROFILE_50_DIR key, this key may michael@0: * be available when the profile hasn't been "started", or after is michael@0: * has been shut down. If the application is running without a michael@0: * profile, such as when showing the profile manager UI, this key will michael@0: * not be available. This key is provided by the XUL apprunner or by michael@0: * the aAppDirProvider object passed to XRE_InitEmbedding. michael@0: */ michael@0: #define NS_APP_PROFILE_DIR_STARTUP "ProfDS" michael@0: michael@0: /** michael@0: * A directory service key which specifies the profile michael@0: * directory. Unlike the NS_APP_USER_PROFILE_LOCAL_50_DIR key, this key may michael@0: * be available when the profile hasn't been "started", or after is michael@0: * has been shut down. If the application is running without a michael@0: * profile, such as when showing the profile manager UI, this key will michael@0: * not be available. This key is provided by the XUL apprunner or by michael@0: * the aAppDirProvider object passed to XRE_InitEmbedding. michael@0: */ michael@0: #define NS_APP_PROFILE_LOCAL_DIR_STARTUP "ProfLDS" michael@0: michael@0: /** michael@0: * A directory service key which specifies the system extension michael@0: * parent directory containing platform-specific extensions. michael@0: * This key may not be available on all platforms. michael@0: */ michael@0: #define XRE_SYS_LOCAL_EXTENSION_PARENT_DIR "XRESysLExtPD" michael@0: michael@0: /** michael@0: * A directory service key which specifies the system extension michael@0: * parent directory containing platform-independent extensions. michael@0: * This key may not be available on all platforms. michael@0: * Additionally, the directory may be equal to that returned by michael@0: * XRE_SYS_LOCAL_EXTENSION_PARENT_DIR on some platforms. michael@0: */ michael@0: #define XRE_SYS_SHARE_EXTENSION_PARENT_DIR "XRESysSExtPD" michael@0: michael@0: /** michael@0: * A directory service key which specifies the user system extension michael@0: * parent directory. michael@0: */ michael@0: #define XRE_USER_SYS_EXTENSION_DIR "XREUSysExt" michael@0: michael@0: /** michael@0: * A directory service key which specifies the distribution specific files for michael@0: * the application. michael@0: */ michael@0: #define XRE_APP_DISTRIBUTION_DIR "XREAppDist" michael@0: michael@0: /** michael@0: * A directory service key which provides the update directory. michael@0: * At present this is supported only on Windows. michael@0: * Windows: Documents and Settings\\Local Settings\Application Data\ michael@0: * \\ michael@0: * If appDir is not under the Program Files, directory service will fail. michael@0: * Callers should fallback to appDir. michael@0: */ michael@0: #define XRE_UPDATE_ROOT_DIR "UpdRootD" michael@0: michael@0: /** michael@0: * A directory service key which provides an alternate location michael@0: * to UpdRootD to to store large files. This key is currently michael@0: * only implemented in the Gonk directory service provider. michael@0: */ michael@0: michael@0: #define XRE_UPDATE_ARCHIVE_DIR "UpdArchD" michael@0: michael@0: /** michael@0: * A directory service key which provides the directory where an OS update is michael@0: * applied. michael@0: * At present this is supported only in Gonk. michael@0: */ michael@0: #define XRE_OS_UPDATE_APPLY_TO_DIR "OSUpdApplyToD" michael@0: michael@0: /** michael@0: * Platform flag values for XRE_main. michael@0: * michael@0: * XRE_MAIN_FLAG_USE_METRO - On Windows, use the winrt backend. Defaults michael@0: * to win32 backend. michael@0: */ michael@0: #define XRE_MAIN_FLAG_USE_METRO 0x01 michael@0: michael@0: /** michael@0: * Begin an XUL application. Does not return until the user exits the michael@0: * application. michael@0: * michael@0: * @param argc/argv Command-line parameters to pass to the application. On michael@0: * Windows, these should be in UTF8. On unix-like platforms michael@0: * these are in the "native" character set. michael@0: * michael@0: * @param aAppData Information about the application to be run. michael@0: * michael@0: * @param aFlags Platform specific flags. michael@0: * michael@0: * @return A native result code suitable for returning from main(). michael@0: * michael@0: * @note If the binary is linked against the standalone XPCOM glue, michael@0: * XPCOMGlueStartup() should be called before this method. michael@0: */ michael@0: XRE_API(int, michael@0: XRE_main, (int argc, char* argv[], const nsXREAppData* aAppData, michael@0: uint32_t aFlags)) michael@0: michael@0: /** michael@0: * Given a path relative to the current working directory (or an absolute michael@0: * path), return an appropriate nsIFile object. michael@0: * michael@0: * @note Pass UTF8 strings on Windows... native charset on other platforms. michael@0: */ michael@0: XRE_API(nsresult, michael@0: XRE_GetFileFromPath, (const char *aPath, nsIFile* *aResult)) michael@0: michael@0: /** michael@0: * Get the path of the running application binary and store it in aResult. michael@0: * @param argv0 The value passed as argv[0] of main(). This value is only michael@0: * used on *nix, and only when other methods of determining michael@0: * the binary path have failed. michael@0: */ michael@0: XRE_API(nsresult, michael@0: XRE_GetBinaryPath, (const char *argv0, nsIFile* *aResult)) michael@0: michael@0: /** michael@0: * Get the static module built in to libxul. michael@0: */ michael@0: XRE_API(const mozilla::Module*, michael@0: XRE_GetStaticModule, ()) michael@0: michael@0: /** michael@0: * Lock a profile directory using platform-specific semantics. michael@0: * michael@0: * @param aDirectory The profile directory to lock. michael@0: * @param aLockObject An opaque lock object. The directory will remain locked michael@0: * as long as the XPCOM reference is held. michael@0: */ michael@0: XRE_API(nsresult, michael@0: XRE_LockProfileDirectory, (nsIFile* aDirectory, michael@0: nsISupports* *aLockObject)) michael@0: michael@0: /** michael@0: * Initialize libXUL for embedding purposes. michael@0: * michael@0: * @param aLibXULDirectory The directory in which the libXUL shared library michael@0: * was found. michael@0: * @param aAppDirectory The directory in which the application components michael@0: * and resources can be found. This will map to michael@0: * the NS_OS_CURRENT_PROCESS_DIR directory service michael@0: * key. michael@0: * @param aAppDirProvider A directory provider for the application. This michael@0: * provider will be aggregated by a libxul provider michael@0: * which will provide the base required GRE keys. michael@0: * michael@0: * @note This function must be called from the "main" thread. michael@0: * michael@0: * @note At the present time, this function may only be called once in michael@0: * a given process. Use XRE_TermEmbedding to clean up and free michael@0: * resources allocated by XRE_InitEmbedding. michael@0: */ michael@0: michael@0: XRE_API(nsresult, michael@0: XRE_InitEmbedding2, (nsIFile *aLibXULDirectory, michael@0: nsIFile *aAppDirectory, michael@0: nsIDirectoryServiceProvider *aAppDirProvider)) michael@0: michael@0: /** michael@0: * Register static XPCOM component information. michael@0: * This method may be called at any time before or after XRE_main or michael@0: * XRE_InitEmbedding. michael@0: */ michael@0: XRE_API(nsresult, michael@0: XRE_AddStaticComponent, (const mozilla::Module* aComponent)) michael@0: michael@0: /** michael@0: * Register XPCOM components found in an array of files/directories. michael@0: * This method may be called at any time before or after XRE_main or michael@0: * XRE_InitEmbedding. michael@0: * michael@0: * @param aFiles An array of files or directories. michael@0: * @param aFileCount the number of items in the aFiles array. michael@0: * @note appdir/components is registered automatically. michael@0: * michael@0: * NS_COMPONENT_LOCATION specifies a location to search for binary XPCOM michael@0: * components as well as component/chrome manifest files. michael@0: * michael@0: * NS_SKIN_LOCATION specifies a location to search for chrome manifest files michael@0: * which are only allowed to register only skin packages and style overlays. michael@0: */ michael@0: enum NSLocationType michael@0: { michael@0: NS_COMPONENT_LOCATION, michael@0: NS_SKIN_LOCATION, michael@0: NS_BOOTSTRAPPED_LOCATION michael@0: }; michael@0: michael@0: XRE_API(nsresult, michael@0: XRE_AddManifestLocation, (NSLocationType aType, michael@0: nsIFile* aLocation)) michael@0: michael@0: /** michael@0: * Register XPCOM components found in a JAR. michael@0: * This is similar to XRE_AddManifestLocation except the file specified michael@0: * must be a zip archive with a manifest named chrome.manifest michael@0: * This method may be called at any time before or after XRE_main or michael@0: * XRE_InitEmbedding. michael@0: * michael@0: * @param aFiles An array of files or directories. michael@0: * @param aFileCount the number of items in the aFiles array. michael@0: * @note appdir/components is registered automatically. michael@0: * michael@0: * NS_COMPONENT_LOCATION specifies a location to search for binary XPCOM michael@0: * components as well as component/chrome manifest files. michael@0: * michael@0: * NS_SKIN_LOCATION specifies a location to search for chrome manifest files michael@0: * which are only allowed to register only skin packages and style overlays. michael@0: */ michael@0: XRE_API(nsresult, michael@0: XRE_AddJarManifestLocation, (NSLocationType aType, michael@0: nsIFile* aLocation)) michael@0: michael@0: /** michael@0: * Fire notifications to inform the toolkit about a new profile. This michael@0: * method should be called after XRE_InitEmbedding if the embedder michael@0: * wishes to run with a profile. Normally the embedder should call michael@0: * XRE_LockProfileDirectory to lock the directory before calling this michael@0: * method. michael@0: * michael@0: * @note There are two possibilities for selecting a profile: michael@0: * michael@0: * 1) Select the profile before calling XRE_InitEmbedding. The aAppDirProvider michael@0: * object passed to XRE_InitEmbedding should provide the michael@0: * NS_APP_USER_PROFILE_50_DIR key, and may also provide the following keys: michael@0: * - NS_APP_USER_PROFILE_LOCAL_50_DIR michael@0: * - NS_APP_PROFILE_DIR_STARTUP michael@0: * - NS_APP_PROFILE_LOCAL_DIR_STARTUP michael@0: * In this scenario XRE_NotifyProfile should be called immediately after michael@0: * XRE_InitEmbedding. Component registration information will be stored in michael@0: * the profile and JS components may be stored in the fastload cache. michael@0: * michael@0: * 2) Select a profile some time after calling XRE_InitEmbedding. In this case michael@0: * the embedder must install a directory service provider which provides michael@0: * NS_APP_USER_PROFILE_50_DIR and optionally michael@0: * NS_APP_USER_PROFILE_LOCAL_50_DIR. Component registration information michael@0: * will be stored in the application directory and JS components will not michael@0: * fastload. michael@0: */ michael@0: XRE_API(void, michael@0: XRE_NotifyProfile, ()) michael@0: michael@0: /** michael@0: * Terminate embedding started with XRE_InitEmbedding or XRE_InitEmbedding2 michael@0: */ michael@0: XRE_API(void, michael@0: XRE_TermEmbedding, ()) michael@0: michael@0: /** michael@0: * Create a new nsXREAppData structure from an application.ini file. michael@0: * michael@0: * @param aINIFile The application.ini file to parse. michael@0: * @param aAppData A newly-allocated nsXREAppData structure. The caller is michael@0: * responsible for freeing this structure using michael@0: * XRE_FreeAppData. michael@0: */ michael@0: XRE_API(nsresult, michael@0: XRE_CreateAppData, (nsIFile* aINIFile, michael@0: nsXREAppData **aAppData)) michael@0: michael@0: /** michael@0: * Parse an INI file (application.ini or override.ini) into an existing michael@0: * nsXREAppData structure. michael@0: * michael@0: * @param aINIFile The INI file to parse michael@0: * @param aAppData The nsXREAppData structure to fill. michael@0: */ michael@0: XRE_API(nsresult, michael@0: XRE_ParseAppData, (nsIFile* aINIFile, michael@0: nsXREAppData *aAppData)) michael@0: michael@0: /** michael@0: * Free a nsXREAppData structure that was allocated with XRE_CreateAppData. michael@0: */ michael@0: XRE_API(void, michael@0: XRE_FreeAppData, (nsXREAppData *aAppData)) michael@0: michael@0: enum GeckoProcessType { michael@0: GeckoProcessType_Default = 0, michael@0: michael@0: GeckoProcessType_Plugin, michael@0: GeckoProcessType_Content, michael@0: michael@0: GeckoProcessType_IPDLUnitTest, michael@0: michael@0: GeckoProcessType_End, michael@0: GeckoProcessType_Invalid = GeckoProcessType_End michael@0: }; michael@0: michael@0: static const char* const kGeckoProcessTypeString[] = { michael@0: "default", michael@0: "plugin", michael@0: "tab", michael@0: "ipdlunittest" michael@0: }; michael@0: michael@0: static_assert(MOZ_ARRAY_LENGTH(kGeckoProcessTypeString) == michael@0: GeckoProcessType_End, michael@0: "Array length mismatch"); michael@0: michael@0: XRE_API(const char*, michael@0: XRE_ChildProcessTypeToString, (GeckoProcessType aProcessType)) michael@0: michael@0: XRE_API(GeckoProcessType, michael@0: XRE_StringToChildProcessType, (const char* aProcessTypeString)) michael@0: michael@0: #if defined(MOZ_CRASHREPORTER) michael@0: // Used in the "master" parent process hosting the crash server michael@0: XRE_API(bool, michael@0: XRE_TakeMinidumpForChild, (uint32_t aChildPid, nsIFile** aDump, michael@0: uint32_t* aSequence)) michael@0: michael@0: // Used in child processes. michael@0: XRE_API(bool, michael@0: XRE_SetRemoteExceptionHandler, (const char* aPipe)) michael@0: #endif michael@0: michael@0: XRE_API(nsresult, michael@0: XRE_InitChildProcess, (int aArgc, michael@0: char* aArgv[], michael@0: GeckoProcessType aProcess)) michael@0: michael@0: XRE_API(GeckoProcessType, michael@0: XRE_GetProcessType, ()) michael@0: michael@0: typedef void (*MainFunction)(void* aData); michael@0: michael@0: XRE_API(nsresult, michael@0: XRE_InitParentProcess, (int aArgc, michael@0: char* aArgv[], michael@0: MainFunction aMainFunction, michael@0: void* aMainFunctionExtraData)) michael@0: michael@0: XRE_API(int, michael@0: XRE_RunIPDLTest, (int aArgc, michael@0: char* aArgv[])) michael@0: michael@0: XRE_API(nsresult, michael@0: XRE_RunAppShell, ()) michael@0: michael@0: XRE_API(nsresult, michael@0: XRE_InitCommandLine, (int aArgc, char* aArgv[])) michael@0: michael@0: XRE_API(nsresult, michael@0: XRE_DeinitCommandLine, ()) michael@0: michael@0: class MessageLoop; michael@0: michael@0: XRE_API(void, michael@0: XRE_ShutdownChildProcess, ()) michael@0: michael@0: XRE_API(MessageLoop*, michael@0: XRE_GetIOMessageLoop, ()) michael@0: michael@0: XRE_API(bool, michael@0: XRE_SendTestShellCommand, (JSContext* aCx, michael@0: JSString* aCommand, michael@0: void* aCallback)) michael@0: XRE_API(bool, michael@0: XRE_ShutdownTestShell, ()) michael@0: michael@0: XRE_API(void, michael@0: XRE_InstallX11ErrorHandler, ()) michael@0: michael@0: XRE_API(void, michael@0: XRE_TelemetryAccumulate, (int aID, uint32_t aSample)) michael@0: michael@0: XRE_API(void, michael@0: XRE_StartupTimelineRecord, (int aEvent, PRTime aWhen)) michael@0: michael@0: XRE_API(void, michael@0: XRE_InitOmnijar, (nsIFile* greOmni, michael@0: nsIFile* appOmni)) michael@0: XRE_API(void, michael@0: XRE_StopLateWriteChecks, (void)) michael@0: michael@0: #ifdef XP_WIN michael@0: /** michael@0: * Valid environment types for XRE_GetWindowsEnvironment. michael@0: */ michael@0: enum WindowsEnvironmentType { michael@0: WindowsEnvironmentType_Desktop = 0, michael@0: WindowsEnvironmentType_Metro = 1 michael@0: }; michael@0: michael@0: /** michael@0: * Retrieve the Windows desktop environment libXUL is running michael@0: * under. Valid after a call to XRE_main. michael@0: */ michael@0: XRE_API(WindowsEnvironmentType, michael@0: XRE_GetWindowsEnvironment, ()) michael@0: #endif // XP_WIN michael@0: michael@0: XRE_API(int, michael@0: XRE_XPCShellMain, (int argc, char** argv, char** envp)) michael@0: michael@0: #endif // _nsXULAppAPI_h__