1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 let origPlatformInfo = Cc["@mozilla.org/xre/app-info;1"].getService(
9 // eslint-disable-next-line mozilla/use-services
10 let origRuntime = Cc["@mozilla.org/xre/app-info;1"].getService(
15 * Create new XULAppInfo instance with specified options.
17 * options is a object with following keys:
18 * ID: nsIXULAppInfo.ID
19 * name: nsIXULAppInfo.name
20 * version: nsIXULAppInfo.version
21 * platformVersion: nsIXULAppInfo.platformVersion
22 * OS: nsIXULRuntime.OS
23 * appBuildID: nsIXULRuntime.appBuildID
24 * lastAppBuildID: nsIXULRuntime.lastAppBuildID
25 * lastAppVersion: nsIXULRuntime.lastAppVersion
27 * crashReporter: nsICrashReporter interface is implemented if true
29 export var newAppInfo = function (options = {}) {
33 name: options.name ?? "xpcshell",
34 ID: options.ID ?? "xpcshell@tests.mozilla.org",
35 version: options.version ?? "1",
36 appBuildID: options.appBuildID ?? "20160315",
39 platformVersion: options.platformVersion ?? "p-ver",
40 platformBuildID: origPlatformInfo.platformBuildID,
45 logConsoleErrors: true,
46 OS: options.OS ?? "XPCShell",
47 XPCOMABI: "noarch-spidermonkey",
48 invalidateCachesOnRestart() {},
49 processType: origRuntime.processType,
50 uniqueProcessID: origRuntime.uniqueProcessID,
52 fissionAutostart: origRuntime.fissionAutostart,
53 sessionHistoryInParent: origRuntime.sessionHistoryInParent,
54 browserTabsRemoteAutostart: origRuntime.browserTabsRemoteAutostart,
55 get maxWebProcessCount() {
56 return origRuntime.maxWebProcessCount;
58 get launcherProcessState() {
59 return origRuntime.launcherProcessState;
63 get userCanElevate() {
68 appInfo.lastAppBuildID = options.lastAppBuildID ?? appInfo.appBuildID;
69 appInfo.lastAppVersion = options.lastAppVersion ?? appInfo.version;
77 if ("nsIWinAppHelper" in Ci) {
78 interfaces.push(Ci.nsIWinAppHelper);
82 appInfo.annotations = {};
83 appInfo.annotateCrashReport = function (key, data) {
84 if (options.crashReporter) {
85 this.annotations[key] = data;
87 throw Components.Exception("", Cr.NS_ERROR_NOT_INITIALIZED);
91 appInfo.QueryInterface = ChromeUtils.generateQI(interfaces);
96 var currentAppInfo = newAppInfo();
99 * Obtain a reference to the current object used to define XULAppInfo.
101 export var getAppInfo = function () {
102 return currentAppInfo;
106 * Update the current application info.
108 * See newAppInfo for options.
110 * To change the current XULAppInfo, simply call this function. If there was
111 * a previously registered app info object, it will be unloaded and replaced.
113 export var updateAppInfo = function (options) {
114 currentAppInfo = newAppInfo(options);
116 let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}");
117 let contractid = "@mozilla.org/xre/app-info;1";
118 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
120 // Unregister an existing factory if one exists.
122 let existing = Components.manager.getClassObjectByContractID(
126 registrar.unregisterFactory(id, existing);
130 createInstance(iid) {
131 return currentAppInfo.QueryInterface(iid);
135 Services.appinfo = currentAppInfo;
137 registrar.registerFactory(id, "XULAppInfo", contractid, factory);