nsXULAppAPI.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef _nsXULAppAPI_h__
  6. #define _nsXULAppAPI_h__
  7. #include "nsID.h"
  8. #include "xrecore.h"
  9. #include "nsXPCOM.h"
  10. #include "nsISupports.h"
  11. #include "mozilla/Logging.h"
  12. #include "nsXREAppData.h"
  13. #include "js/TypeDecls.h"
  14. #include "mozilla/ArrayUtils.h"
  15. #include "mozilla/Assertions.h"
  16. #include "mozilla/Vector.h"
  17. #include "mozilla/TimeStamp.h"
  18. #include "XREChildData.h"
  19. /**
  20. * A directory service key which provides the platform-correct "application
  21. * data" directory as follows, where $name and $vendor are as defined above and
  22. * $vendor is optional:
  23. *
  24. * Windows:
  25. * HOME = Documents and Settings\$USER\Application Data
  26. * UAppData = $HOME[\$vendor]\$name
  27. *
  28. * Unix:
  29. * HOME = ~
  30. * UAppData = $HOME/.[$vendor/]$name
  31. *
  32. * Mac:
  33. * HOME = ~
  34. * UAppData = $HOME/Library/Application Support/$name
  35. *
  36. * Note that the "profile" member above will change the value of UAppData as
  37. * follows:
  38. *
  39. * Windows:
  40. * UAppData = $HOME\$profile
  41. *
  42. * Unix:
  43. * UAppData = $HOME/.$profile
  44. *
  45. * Mac:
  46. * UAppData = $HOME/Library/Application Support/$profile
  47. */
  48. #define XRE_USER_APP_DATA_DIR "UAppData"
  49. /**
  50. * A directory service key which provides a list of all enabled extension
  51. * directories and files (packed XPIs). The list includes compatible
  52. * platform-specific extension subdirectories.
  53. *
  54. * @note The directory list will have no members when the application is
  55. * launched in safe mode.
  56. */
  57. #define XRE_EXTENSIONS_DIR_LIST "XREExtDL"
  58. /**
  59. * A directory service key which provides the executable file used to
  60. * launch the current process. This is the same value returned by the
  61. * XRE_GetBinaryPath function defined below.
  62. */
  63. #define XRE_EXECUTABLE_FILE "XREExeF"
  64. /**
  65. * A directory service key which specifies the profile
  66. * directory. Unlike the NS_APP_USER_PROFILE_50_DIR key, this key may
  67. * be available when the profile hasn't been "started", or after is
  68. * has been shut down. If the application is running without a
  69. * profile, such as when showing the profile manager UI, this key will
  70. * not be available. This key is provided by the XUL apprunner or by
  71. * the aAppDirProvider object passed to XRE_InitEmbedding.
  72. */
  73. #define NS_APP_PROFILE_DIR_STARTUP "ProfDS"
  74. /**
  75. * A directory service key which specifies the profile
  76. * directory. Unlike the NS_APP_USER_PROFILE_LOCAL_50_DIR key, this key may
  77. * be available when the profile hasn't been "started", or after is
  78. * has been shut down. If the application is running without a
  79. * profile, such as when showing the profile manager UI, this key will
  80. * not be available. This key is provided by the XUL apprunner or by
  81. * the aAppDirProvider object passed to XRE_InitEmbedding.
  82. */
  83. #define NS_APP_PROFILE_LOCAL_DIR_STARTUP "ProfLDS"
  84. /**
  85. * A directory service key which specifies the system extension
  86. * parent directory containing platform-specific extensions.
  87. * This key may not be available on all platforms.
  88. */
  89. #define XRE_SYS_LOCAL_EXTENSION_PARENT_DIR "XRESysLExtPD"
  90. /**
  91. * A directory service key which specifies the system extension
  92. * parent directory containing platform-independent extensions.
  93. * This key may not be available on all platforms.
  94. * Additionally, the directory may be equal to that returned by
  95. * XRE_SYS_LOCAL_EXTENSION_PARENT_DIR on some platforms.
  96. */
  97. #define XRE_SYS_SHARE_EXTENSION_PARENT_DIR "XRESysSExtPD"
  98. #if defined(XP_UNIX)
  99. /**
  100. * Directory service keys for the system-wide and user-specific
  101. * directories where host manifests used by the WebExtensions
  102. * native messaging feature are found.
  103. */
  104. #define XRE_SYS_NATIVE_MESSAGING_MANIFESTS "XRESysNativeMessaging"
  105. #define XRE_USER_NATIVE_MESSAGING_MANIFESTS "XREUserNativeMessaging"
  106. #endif
  107. /**
  108. * A directory service key which specifies the user system extension
  109. * parent directory.
  110. */
  111. #define XRE_USER_SYS_EXTENSION_DIR "XREUSysExt"
  112. /**
  113. * A directory service key which specifies the distribution specific files for
  114. * the application.
  115. */
  116. #define XRE_APP_DISTRIBUTION_DIR "XREAppDist"
  117. /**
  118. * A directory service key which specifies the location for system add-ons.
  119. */
  120. #define XRE_APP_FEATURES_DIR "XREAppFeat"
  121. /**
  122. * A directory service key which specifies the location for app dir add-ons.
  123. * Should be a synonym for XCurProcD everywhere except in tests.
  124. */
  125. #define XRE_ADDON_APP_DIR "XREAddonAppDir"
  126. /**
  127. * A directory service key which provides the update directory. Callers should
  128. * fall back to appDir.
  129. * Windows: If vendor name exists:
  130. * Documents and Settings\<User>\Local Settings\Application Data\
  131. * <vendor name>\updates\
  132. * <hash of the path to XRE_EXECUTABLE_FILE’s parent directory>
  133. *
  134. * If vendor name doesn't exist, but product name exists:
  135. * Documents and Settings\<User>\Local Settings\Application Data\
  136. * <product name>\updates\
  137. * <hash of the path to XRE_EXECUTABLE_FILE’s parent directory>
  138. *
  139. * If neither vendor nor product name exists:
  140. * If app dir is under Program Files:
  141. * Documents and Settings\<User>\Local Settings\Application Data\
  142. * <relative path to app dir from Program Files>
  143. *
  144. * If app dir isn’t under Program Files:
  145. * Documents and Settings\<User>\Local Settings\Application Data\
  146. * <MOZ_APP_NAME>
  147. *
  148. * Mac: ~/Library/Caches/Mozilla/updates/<absolute path to app dir>
  149. *
  150. * Gonk: /data/local
  151. *
  152. * All others: Parent directory of XRE_EXECUTABLE_FILE.
  153. */
  154. #define XRE_UPDATE_ROOT_DIR "UpdRootD"
  155. /**
  156. * A directory service key which provides an alternate location
  157. * to UpdRootD to to store large files. This key is currently
  158. * only implemented in the Gonk directory service provider.
  159. */
  160. #define XRE_UPDATE_ARCHIVE_DIR "UpdArchD"
  161. /**
  162. * A directory service key which provides the directory where an OS update is
  163. * applied.
  164. * At present this is supported only in Gonk.
  165. */
  166. #define XRE_OS_UPDATE_APPLY_TO_DIR "OSUpdApplyToD"
  167. /**
  168. * Begin an XUL application. Does not return until the user exits the
  169. * application.
  170. *
  171. * @param argc/argv Command-line parameters to pass to the application. On
  172. * Windows, these should be in UTF8. On unix-like platforms
  173. * these are in the "native" character set.
  174. *
  175. * @param aAppData Information about the application to be run.
  176. *
  177. * @param aFlags Platform specific flags.
  178. *
  179. * @return A native result code suitable for returning from main().
  180. *
  181. * @note If the binary is linked against the standalone XPCOM glue,
  182. * XPCOMGlueStartup() should be called before this method.
  183. */
  184. XRE_API(int,
  185. XRE_main, (int argc, char* argv[], const nsXREAppData* aAppData,
  186. uint32_t aFlags))
  187. /**
  188. * Given a path relative to the current working directory (or an absolute
  189. * path), return an appropriate nsIFile object.
  190. *
  191. * @note Pass UTF8 strings on Windows... native charset on other platforms.
  192. */
  193. XRE_API(nsresult,
  194. XRE_GetFileFromPath, (const char* aPath, nsIFile** aResult))
  195. /**
  196. * Get the path of the running application binary and store it in aResult.
  197. * @param aArgv0 The value passed as argv[0] of main(). This value is only
  198. * used on *nix, and only when other methods of determining
  199. * the binary path have failed.
  200. */
  201. XRE_API(nsresult,
  202. XRE_GetBinaryPath, (const char* aArgv0, nsIFile** aResult))
  203. /**
  204. * Get the static module built in to libxul.
  205. */
  206. XRE_API(const mozilla::Module*,
  207. XRE_GetStaticModule, ())
  208. /**
  209. * Lock a profile directory using platform-specific semantics.
  210. *
  211. * @param aDirectory The profile directory to lock.
  212. * @param aLockObject An opaque lock object. The directory will remain locked
  213. * as long as the XPCOM reference is held.
  214. */
  215. XRE_API(nsresult,
  216. XRE_LockProfileDirectory, (nsIFile* aDirectory,
  217. nsISupports** aLockObject))
  218. /**
  219. * Initialize libXUL for embedding purposes.
  220. *
  221. * @param aLibXULDirectory The directory in which the libXUL shared library
  222. * was found.
  223. * @param aAppDirectory The directory in which the application components
  224. * and resources can be found. This will map to
  225. * the NS_OS_CURRENT_PROCESS_DIR directory service
  226. * key.
  227. * @param aAppDirProvider A directory provider for the application. This
  228. * provider will be aggregated by a libxul provider
  229. * which will provide the base required GRE keys.
  230. *
  231. * @note This function must be called from the "main" thread.
  232. *
  233. * @note At the present time, this function may only be called once in
  234. * a given process. Use XRE_TermEmbedding to clean up and free
  235. * resources allocated by XRE_InitEmbedding.
  236. */
  237. XRE_API(nsresult,
  238. XRE_InitEmbedding2, (nsIFile* aLibXULDirectory,
  239. nsIFile* aAppDirectory,
  240. nsIDirectoryServiceProvider* aAppDirProvider))
  241. /**
  242. * Register static XPCOM component information.
  243. * This method may be called at any time before or after XRE_main or
  244. * XRE_InitEmbedding.
  245. */
  246. XRE_API(nsresult,
  247. XRE_AddStaticComponent, (const mozilla::Module* aComponent))
  248. /**
  249. * Register XPCOM components found in an array of files/directories.
  250. * This method may be called at any time before or after XRE_main or
  251. * XRE_InitEmbedding.
  252. *
  253. * @param aFiles An array of files or directories.
  254. * @param aFileCount the number of items in the aFiles array.
  255. * @note appdir/components is registered automatically.
  256. *
  257. * NS_APP_LOCATION specifies a location to search for binary XPCOM
  258. * components as well as component/chrome manifest files.
  259. *
  260. * NS_EXTENSION_LOCATION excludes binary XPCOM components but allows other
  261. * manifest instructions.
  262. *
  263. * NS_SKIN_LOCATION specifies a location to search for chrome manifest files
  264. * which are only allowed to register only skin packages and style overlays.
  265. */
  266. enum NSLocationType
  267. {
  268. NS_APP_LOCATION,
  269. NS_EXTENSION_LOCATION,
  270. NS_SKIN_LOCATION,
  271. NS_BOOTSTRAPPED_LOCATION
  272. };
  273. XRE_API(nsresult,
  274. XRE_AddManifestLocation, (NSLocationType aType,
  275. nsIFile* aLocation))
  276. /**
  277. * Register XPCOM components found in a JAR.
  278. * This is similar to XRE_AddManifestLocation except the file specified
  279. * must be a zip archive with a manifest named chrome.manifest
  280. * This method may be called at any time before or after XRE_main or
  281. * XRE_InitEmbedding.
  282. *
  283. * @param aFiles An array of files or directories.
  284. * @param aFileCount the number of items in the aFiles array.
  285. * @note appdir/components is registered automatically.
  286. *
  287. * NS_COMPONENT_LOCATION specifies a location to search for binary XPCOM
  288. * components as well as component/chrome manifest files.
  289. *
  290. * NS_SKIN_LOCATION specifies a location to search for chrome manifest files
  291. * which are only allowed to register only skin packages and style overlays.
  292. */
  293. XRE_API(nsresult,
  294. XRE_AddJarManifestLocation, (NSLocationType aType,
  295. nsIFile* aLocation))
  296. /**
  297. * Fire notifications to inform the toolkit about a new profile. This
  298. * method should be called after XRE_InitEmbedding if the embedder
  299. * wishes to run with a profile. Normally the embedder should call
  300. * XRE_LockProfileDirectory to lock the directory before calling this
  301. * method.
  302. *
  303. * @note There are two possibilities for selecting a profile:
  304. *
  305. * 1) Select the profile before calling XRE_InitEmbedding. The aAppDirProvider
  306. * object passed to XRE_InitEmbedding should provide the
  307. * NS_APP_USER_PROFILE_50_DIR key, and may also provide the following keys:
  308. * - NS_APP_USER_PROFILE_LOCAL_50_DIR
  309. * - NS_APP_PROFILE_DIR_STARTUP
  310. * - NS_APP_PROFILE_LOCAL_DIR_STARTUP
  311. * In this scenario XRE_NotifyProfile should be called immediately after
  312. * XRE_InitEmbedding. Component registration information will be stored in
  313. * the profile and JS components may be stored in the fastload cache.
  314. *
  315. * 2) Select a profile some time after calling XRE_InitEmbedding. In this case
  316. * the embedder must install a directory service provider which provides
  317. * NS_APP_USER_PROFILE_50_DIR and optionally
  318. * NS_APP_USER_PROFILE_LOCAL_50_DIR. Component registration information
  319. * will be stored in the application directory and JS components will not
  320. * fastload.
  321. */
  322. XRE_API(void,
  323. XRE_NotifyProfile, ())
  324. /**
  325. * Terminate embedding started with XRE_InitEmbedding or XRE_InitEmbedding2
  326. */
  327. XRE_API(void,
  328. XRE_TermEmbedding, ())
  329. /**
  330. * Create a new nsXREAppData structure from an application.ini file.
  331. *
  332. * @param aINIFile The application.ini file to parse.
  333. * @param aAppData A newly-allocated nsXREAppData structure. The caller is
  334. * responsible for freeing this structure using
  335. * XRE_FreeAppData.
  336. */
  337. XRE_API(nsresult,
  338. XRE_CreateAppData, (nsIFile* aINIFile,
  339. nsXREAppData** aAppData))
  340. /**
  341. * Parse an INI file (application.ini or override.ini) into an existing
  342. * nsXREAppData structure.
  343. *
  344. * @param aINIFile The INI file to parse
  345. * @param aAppData The nsXREAppData structure to fill.
  346. */
  347. XRE_API(nsresult,
  348. XRE_ParseAppData, (nsIFile* aINIFile,
  349. nsXREAppData* aAppData))
  350. /**
  351. * Free a nsXREAppData structure that was allocated with XRE_CreateAppData.
  352. */
  353. XRE_API(void,
  354. XRE_FreeAppData, (nsXREAppData* aAppData))
  355. enum GeckoProcessType
  356. {
  357. GeckoProcessType_Default = 0,
  358. GeckoProcessType_Plugin,
  359. GeckoProcessType_Content,
  360. GeckoProcessType_IPDLUnitTest,
  361. GeckoProcessType_GMPlugin, // Gecko Media Plugin
  362. GeckoProcessType_GPU, // GPU and compositor process
  363. GeckoProcessType_End,
  364. GeckoProcessType_Invalid = GeckoProcessType_End
  365. };
  366. static const char* const kGeckoProcessTypeString[] = {
  367. "default",
  368. "plugin",
  369. "tab",
  370. "ipdlunittest",
  371. "geckomediaplugin",
  372. "gpu"
  373. };
  374. static_assert(MOZ_ARRAY_LENGTH(kGeckoProcessTypeString) ==
  375. GeckoProcessType_End,
  376. "Array length mismatch");
  377. XRE_API(const char*,
  378. XRE_ChildProcessTypeToString, (GeckoProcessType aProcessType))
  379. XRE_API(void,
  380. XRE_SetProcessType, (const char* aProcessTypeString))
  381. namespace mozilla {
  382. namespace gmp {
  383. class GMPLoader;
  384. } // namespace gmp
  385. } // namespace mozilla
  386. XRE_API(nsresult,
  387. XRE_InitChildProcess, (int aArgc,
  388. char* aArgv[],
  389. const XREChildData* aChildData))
  390. XRE_API(GeckoProcessType,
  391. XRE_GetProcessType, ())
  392. XRE_API(bool,
  393. XRE_IsParentProcess, ())
  394. XRE_API(bool,
  395. XRE_IsContentProcess, ())
  396. XRE_API(bool,
  397. XRE_IsGPUProcess, ())
  398. typedef void (*MainFunction)(void* aData);
  399. XRE_API(nsresult,
  400. XRE_InitParentProcess, (int aArgc,
  401. char* aArgv[],
  402. MainFunction aMainFunction,
  403. void* aMainFunctionExtraData))
  404. XRE_API(int,
  405. XRE_RunIPDLTest, (int aArgc,
  406. char* aArgv[]))
  407. XRE_API(nsresult,
  408. XRE_RunAppShell, ())
  409. XRE_API(nsresult,
  410. XRE_InitCommandLine, (int aArgc, char* aArgv[]))
  411. XRE_API(nsresult,
  412. XRE_DeinitCommandLine, ())
  413. class MessageLoop;
  414. XRE_API(void,
  415. XRE_ShutdownChildProcess, ())
  416. XRE_API(MessageLoop*,
  417. XRE_GetIOMessageLoop, ())
  418. XRE_API(bool,
  419. XRE_SendTestShellCommand, (JSContext* aCx,
  420. JSString* aCommand,
  421. void* aCallback))
  422. XRE_API(bool,
  423. XRE_ShutdownTestShell, ())
  424. XRE_API(void,
  425. XRE_InstallX11ErrorHandler, ())
  426. XRE_API(void,
  427. XRE_TelemetryAccumulate, (int aID, uint32_t aSample))
  428. XRE_API(void,
  429. XRE_StartupTimelineRecord, (int aEvent, mozilla::TimeStamp aWhen))
  430. XRE_API(void,
  431. XRE_InitOmnijar, (nsIFile* aGreOmni,
  432. nsIFile* aAppOmni))
  433. XRE_API(void,
  434. XRE_StopLateWriteChecks, (void))
  435. XRE_API(void,
  436. XRE_EnableSameExecutableForContentProc, ())
  437. XRE_API(int,
  438. XRE_XPCShellMain, (int argc, char** argv, char** envp))
  439. #if MOZ_WIDGET_GTK == 2
  440. XRE_API(void,
  441. XRE_GlibInit, ())
  442. #endif
  443. #ifdef LIBFUZZER
  444. #include "LibFuzzerRegistry.h"
  445. XRE_API(void,
  446. XRE_LibFuzzerSetMain, (int, char**, LibFuzzerMain))
  447. XRE_API(void,
  448. XRE_LibFuzzerGetFuncs, (const char*, LibFuzzerInitFunc*,
  449. LibFuzzerTestingFunc*))
  450. #endif // LIBFUZZER
  451. #endif // _nsXULAppAPI_h__