Bug 1386427 - Part 1: Add XRE*NativeManifests locations to dirsvc r=kmag
[gecko.git] / xpcom / build / nsXULAppAPI.h
blobe172b492dd27fa804d529b1fa915048fb60f1419
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef _nsXULAppAPI_h__
8 #define _nsXULAppAPI_h__
10 #include "nsID.h"
11 #include "xrecore.h"
12 #include "nsXPCOM.h"
13 #include "nsISupports.h"
14 #include "mozilla/Logging.h"
15 #include "mozilla/XREAppData.h"
16 #include "js/TypeDecls.h"
18 #include "mozilla/ArrayUtils.h"
19 #include "mozilla/Assertions.h"
20 #include "mozilla/Vector.h"
21 #include "mozilla/TimeStamp.h"
22 #include "XREChildData.h"
23 #include "XREShellData.h"
25 #if defined(MOZ_WIDGET_ANDROID)
26 #include <jni.h>
27 #endif
29 /**
30 * A directory service key which provides the platform-correct "application
31 * data" directory as follows, where $name and $vendor are as defined above and
32 * $vendor is optional:
34 * Windows:
35 * HOME = Documents and Settings\$USER\Application Data
36 * UAppData = $HOME[\$vendor]\$name
38 * Unix:
39 * HOME = ~
40 * UAppData = $HOME/.[$vendor/]$name
42 * Mac:
43 * HOME = ~
44 * UAppData = $HOME/Library/Application Support/$name
46 * Note that the "profile" member above will change the value of UAppData as
47 * follows:
49 * Windows:
50 * UAppData = $HOME\$profile
52 * Unix:
53 * UAppData = $HOME/.$profile
55 * Mac:
56 * UAppData = $HOME/Library/Application Support/$profile
58 #define XRE_USER_APP_DATA_DIR "UAppData"
60 /**
61 * A directory service key which provides a list of all enabled extension
62 * directories and files (packed XPIs). The list includes compatible
63 * platform-specific extension subdirectories.
65 * @note The directory list will have no members when the application is
66 * launched in safe mode.
68 #define XRE_EXTENSIONS_DIR_LIST "XREExtDL"
70 /**
71 * A directory service key which provides the executable file used to
72 * launch the current process. This is the same value returned by the
73 * XRE_GetBinaryPath function defined below.
75 #define XRE_EXECUTABLE_FILE "XREExeF"
77 /**
78 * A directory service key which specifies the profile
79 * directory. Unlike the NS_APP_USER_PROFILE_50_DIR key, this key may
80 * be available when the profile hasn't been "started", or after is
81 * has been shut down. If the application is running without a
82 * profile, such as when showing the profile manager UI, this key will
83 * not be available. This key is provided by the XUL apprunner or by
84 * the aAppDirProvider object passed to XRE_InitEmbedding.
86 #define NS_APP_PROFILE_DIR_STARTUP "ProfDS"
88 /**
89 * A directory service key which specifies the profile
90 * directory. Unlike the NS_APP_USER_PROFILE_LOCAL_50_DIR key, this key may
91 * be available when the profile hasn't been "started", or after is
92 * has been shut down. If the application is running without a
93 * profile, such as when showing the profile manager UI, this key will
94 * not be available. This key is provided by the XUL apprunner or by
95 * the aAppDirProvider object passed to XRE_InitEmbedding.
97 #define NS_APP_PROFILE_LOCAL_DIR_STARTUP "ProfLDS"
99 /**
100 * A directory service key which specifies the system extension
101 * parent directory containing platform-specific extensions.
102 * This key may not be available on all platforms.
104 #define XRE_SYS_LOCAL_EXTENSION_PARENT_DIR "XRESysLExtPD"
107 * A directory service key which specifies the system extension
108 * parent directory containing platform-independent extensions.
109 * This key may not be available on all platforms.
110 * Additionally, the directory may be equal to that returned by
111 * XRE_SYS_LOCAL_EXTENSION_PARENT_DIR on some platforms.
113 #define XRE_SYS_SHARE_EXTENSION_PARENT_DIR "XRESysSExtPD"
115 #if defined(XP_UNIX) || defined(XP_MACOSX)
117 * Directory service keys for the system-wide and user-specific
118 * directories where native manifests used by the WebExtensions
119 * native messaging and managed storage features are found.
121 #define XRE_SYS_NATIVE_MANIFESTS "XRESysNativeManifests"
122 #define XRE_USER_NATIVE_MANIFESTS "XREUserNativeManifests"
123 #endif
126 * A directory service key which specifies the user system extension
127 * parent directory.
129 #define XRE_USER_SYS_EXTENSION_DIR "XREUSysExt"
132 * A directory service key which specifies the distribution specific files for
133 * the application.
135 #define XRE_APP_DISTRIBUTION_DIR "XREAppDist"
138 * A directory service key which specifies the location for system add-ons.
140 #define XRE_APP_FEATURES_DIR "XREAppFeat"
143 * A directory service key which specifies the location for app dir add-ons.
144 * Should be a synonym for XCurProcD everywhere except in tests.
146 #define XRE_ADDON_APP_DIR "XREAddonAppDir"
149 * A directory service key which provides the update directory. Callers should
150 * fall back to appDir.
151 * Windows: If vendor name exists:
152 * Documents and Settings\<User>\Local Settings\Application Data\
153 * <vendor name>\updates\
154 * <hash of the path to XRE_EXECUTABLE_FILE’s parent directory>
156 * If vendor name doesn't exist, but product name exists:
157 * Documents and Settings\<User>\Local Settings\Application Data\
158 * <product name>\updates\
159 * <hash of the path to XRE_EXECUTABLE_FILE’s parent directory>
161 * If neither vendor nor product name exists:
162 * If app dir is under Program Files:
163 * Documents and Settings\<User>\Local Settings\Application Data\
164 * <relative path to app dir from Program Files>
166 * If app dir isn’t under Program Files:
167 * Documents and Settings\<User>\Local Settings\Application Data\
168 * <MOZ_APP_NAME>
170 * Mac: ~/Library/Caches/Mozilla/updates/<absolute path to app dir>
172 * All others: Parent directory of XRE_EXECUTABLE_FILE.
174 #define XRE_UPDATE_ROOT_DIR "UpdRootD"
177 * Begin an XUL application. Does not return until the user exits the
178 * application.
180 * @param argc/argv Command-line parameters to pass to the application. On
181 * Windows, these should be in UTF8. On unix-like platforms
182 * these are in the "native" character set.
184 * @param aConfig Information about the application to be run.
186 * @return A native result code suitable for returning from main().
188 * @note If the binary is linked against the standalone XPCOM glue,
189 * XPCOMGlueStartup() should be called before this method.
191 namespace mozilla {
192 struct BootstrapConfig;
194 XRE_API(int,
195 XRE_main, (int argc, char* argv[], const mozilla::BootstrapConfig& aConfig))
198 * Given a path relative to the current working directory (or an absolute
199 * path), return an appropriate nsIFile object.
201 * @note Pass UTF8 strings on Windows... native charset on other platforms.
203 XRE_API(nsresult,
204 XRE_GetFileFromPath, (const char* aPath, nsIFile** aResult))
207 * Get the path of the running application binary and store it in aResult.
208 * @param aArgv0 The value passed as argv[0] of main(). This value is only
209 * used on *nix, and only when other methods of determining
210 * the binary path have failed.
212 XRE_API(nsresult,
213 XRE_GetBinaryPath, (const char* aArgv0, nsIFile** aResult))
216 * Get the static module built in to libxul.
218 XRE_API(const mozilla::Module*,
219 XRE_GetStaticModule, ())
222 * Lock a profile directory using platform-specific semantics.
224 * @param aDirectory The profile directory to lock.
225 * @param aLockObject An opaque lock object. The directory will remain locked
226 * as long as the XPCOM reference is held.
228 XRE_API(nsresult,
229 XRE_LockProfileDirectory, (nsIFile* aDirectory,
230 nsISupports** aLockObject))
233 * Initialize libXUL for embedding purposes.
235 * @param aLibXULDirectory The directory in which the libXUL shared library
236 * was found.
237 * @param aAppDirectory The directory in which the application components
238 * and resources can be found. This will map to
239 * the NS_OS_CURRENT_PROCESS_DIR directory service
240 * key.
241 * @param aAppDirProvider A directory provider for the application. This
242 * provider will be aggregated by a libxul provider
243 * which will provide the base required GRE keys.
245 * @note This function must be called from the "main" thread.
247 * @note At the present time, this function may only be called once in
248 * a given process. Use XRE_TermEmbedding to clean up and free
249 * resources allocated by XRE_InitEmbedding.
252 XRE_API(nsresult,
253 XRE_InitEmbedding2, (nsIFile* aLibXULDirectory,
254 nsIFile* aAppDirectory,
255 nsIDirectoryServiceProvider* aAppDirProvider))
258 * Register static XPCOM component information.
259 * This method may be called at any time before or after XRE_main or
260 * XRE_InitEmbedding.
262 XRE_API(nsresult,
263 XRE_AddStaticComponent, (const mozilla::Module* aComponent))
266 * Register XPCOM components found in an array of files/directories.
267 * This method may be called at any time before or after XRE_main or
268 * XRE_InitEmbedding.
270 * @param aFiles An array of files or directories.
271 * @param aFileCount the number of items in the aFiles array.
272 * @note appdir/components is registered automatically.
274 * NS_APP_LOCATION specifies a location to search for binary XPCOM
275 * components as well as component/chrome manifest files.
277 * NS_EXTENSION_LOCATION excludes binary XPCOM components but allows other
278 * manifest instructions.
280 * NS_SKIN_LOCATION specifies a location to search for chrome manifest files
281 * which are only allowed to register only skin packages and style overlays.
283 enum NSLocationType
285 NS_APP_LOCATION,
286 NS_EXTENSION_LOCATION,
287 NS_SKIN_LOCATION,
288 NS_BOOTSTRAPPED_LOCATION
291 XRE_API(nsresult,
292 XRE_AddManifestLocation, (NSLocationType aType,
293 nsIFile* aLocation))
296 * Register XPCOM components found in a JAR.
297 * This is similar to XRE_AddManifestLocation except the file specified
298 * must be a zip archive with a manifest named chrome.manifest
299 * This method may be called at any time before or after XRE_main or
300 * XRE_InitEmbedding.
302 * @param aFiles An array of files or directories.
303 * @param aFileCount the number of items in the aFiles array.
304 * @note appdir/components is registered automatically.
306 * NS_COMPONENT_LOCATION specifies a location to search for binary XPCOM
307 * components as well as component/chrome manifest files.
309 * NS_SKIN_LOCATION specifies a location to search for chrome manifest files
310 * which are only allowed to register only skin packages and style overlays.
312 XRE_API(nsresult,
313 XRE_AddJarManifestLocation, (NSLocationType aType,
314 nsIFile* aLocation))
317 * Fire notifications to inform the toolkit about a new profile. This
318 * method should be called after XRE_InitEmbedding if the embedder
319 * wishes to run with a profile. Normally the embedder should call
320 * XRE_LockProfileDirectory to lock the directory before calling this
321 * method.
323 * @note There are two possibilities for selecting a profile:
325 * 1) Select the profile before calling XRE_InitEmbedding. The aAppDirProvider
326 * object passed to XRE_InitEmbedding should provide the
327 * NS_APP_USER_PROFILE_50_DIR key, and may also provide the following keys:
328 * - NS_APP_USER_PROFILE_LOCAL_50_DIR
329 * - NS_APP_PROFILE_DIR_STARTUP
330 * - NS_APP_PROFILE_LOCAL_DIR_STARTUP
331 * In this scenario XRE_NotifyProfile should be called immediately after
332 * XRE_InitEmbedding. Component registration information will be stored in
333 * the profile and JS components may be stored in the fastload cache.
335 * 2) Select a profile some time after calling XRE_InitEmbedding. In this case
336 * the embedder must install a directory service provider which provides
337 * NS_APP_USER_PROFILE_50_DIR and optionally
338 * NS_APP_USER_PROFILE_LOCAL_50_DIR. Component registration information
339 * will be stored in the application directory and JS components will not
340 * fastload.
342 XRE_API(void,
343 XRE_NotifyProfile, ())
346 * Terminate embedding started with XRE_InitEmbedding or XRE_InitEmbedding2
348 XRE_API(void,
349 XRE_TermEmbedding, ())
352 * Parse an INI file (application.ini or override.ini) into an existing
353 * nsXREAppData structure.
355 * @param aINIFile The INI file to parse
356 * @param aAppData The nsXREAppData structure to fill.
358 XRE_API(nsresult,
359 XRE_ParseAppData, (nsIFile* aINIFile,
360 mozilla::XREAppData& aAppData))
362 enum GeckoProcessType
364 GeckoProcessType_Default = 0,
366 GeckoProcessType_Plugin,
367 GeckoProcessType_Content,
369 GeckoProcessType_IPDLUnitTest,
371 GeckoProcessType_GMPlugin, // Gecko Media Plugin
373 GeckoProcessType_GPU, // GPU and compositor process
375 GeckoProcessType_End,
376 GeckoProcessType_Invalid = GeckoProcessType_End
379 static const char* const kGeckoProcessTypeString[] = {
380 "default",
381 "plugin",
382 "tab",
383 "ipdlunittest",
384 "geckomediaplugin",
385 "gpu"
388 static_assert(MOZ_ARRAY_LENGTH(kGeckoProcessTypeString) ==
389 GeckoProcessType_End,
390 "Array length mismatch");
392 XRE_API(const char*,
393 XRE_ChildProcessTypeToString, (GeckoProcessType aProcessType))
395 #if defined(MOZ_WIDGET_ANDROID)
396 XRE_API(void,
397 XRE_SetAndroidChildFds, (JNIEnv* env, int crashFd, int ipcFd))
398 #endif // defined(MOZ_WIDGET_ANDROID)
400 XRE_API(void,
401 XRE_SetProcessType, (const char* aProcessTypeString))
403 #if defined(MOZ_CRASHREPORTER)
404 // Used in the "master" parent process hosting the crash server
405 XRE_API(bool,
406 XRE_TakeMinidumpForChild, (uint32_t aChildPid, nsIFile** aDump,
407 uint32_t* aSequence))
409 // Used in child processes.
410 XRE_API(bool,
411 XRE_SetRemoteExceptionHandler, (const char* aPipe))
412 #endif
414 namespace mozilla {
415 namespace gmp {
416 class GMPLoader;
417 } // namespace gmp
418 } // namespace mozilla
420 XRE_API(nsresult,
421 XRE_InitChildProcess, (int aArgc,
422 char* aArgv[],
423 const XREChildData* aChildData))
425 XRE_API(GeckoProcessType,
426 XRE_GetProcessType, ())
429 * Returns true when called in the e10s parent process. Does *NOT* return true
430 * when called in the main process if e10s is disabled.
432 XRE_API(bool,
433 XRE_IsE10sParentProcess, ())
436 * Returns true when called in the e10s parent process or called in the main
437 * process when e10s is disabled.
439 XRE_API(bool,
440 XRE_IsParentProcess, ())
442 XRE_API(bool,
443 XRE_IsContentProcess, ())
445 XRE_API(bool,
446 XRE_IsGPUProcess, ())
449 * Returns true if the appshell should run its own native event loop. Returns
450 * false if we should rely solely on the Gecko event loop.
452 XRE_API(bool,
453 XRE_UseNativeEventProcessing, ())
455 typedef void (*MainFunction)(void* aData);
457 XRE_API(nsresult,
458 XRE_InitParentProcess, (int aArgc,
459 char* aArgv[],
460 MainFunction aMainFunction,
461 void* aMainFunctionExtraData))
463 XRE_API(int,
464 XRE_RunIPDLTest, (int aArgc,
465 char* aArgv[]))
467 XRE_API(nsresult,
468 XRE_RunAppShell, ())
470 XRE_API(nsresult,
471 XRE_InitCommandLine, (int aArgc, char* aArgv[]))
473 XRE_API(nsresult,
474 XRE_DeinitCommandLine, ())
476 class MessageLoop;
478 XRE_API(void,
479 XRE_ShutdownChildProcess, ())
481 XRE_API(MessageLoop*,
482 XRE_GetIOMessageLoop, ())
484 XRE_API(bool,
485 XRE_SendTestShellCommand, (JSContext* aCx,
486 JSString* aCommand,
487 void* aCallback))
488 XRE_API(bool,
489 XRE_ShutdownTestShell, ())
491 XRE_API(void,
492 XRE_InstallX11ErrorHandler, ())
494 XRE_API(void,
495 XRE_TelemetryAccumulate, (int aID, uint32_t aSample))
497 XRE_API(void,
498 XRE_StartupTimelineRecord, (int aEvent, mozilla::TimeStamp aWhen))
500 XRE_API(void,
501 XRE_InitOmnijar, (nsIFile* aGreOmni,
502 nsIFile* aAppOmni))
503 XRE_API(void,
504 XRE_StopLateWriteChecks, (void))
506 XRE_API(void,
507 XRE_EnableSameExecutableForContentProc, ())
509 XRE_API(int,
510 XRE_XPCShellMain, (int argc, char** argv, char** envp,
511 const XREShellData* aShellData))
513 #if MOZ_WIDGET_GTK == 2
514 XRE_API(void,
515 XRE_GlibInit, ())
516 #endif
519 #ifdef LIBFUZZER
520 #include "LibFuzzerRegistry.h"
522 XRE_API(void,
523 XRE_LibFuzzerSetDriver, (LibFuzzerDriver))
525 #endif // LIBFUZZER
527 #endif // _nsXULAppAPI_h__