2013-02-02 00:26:07 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = [
|
2016-03-16 10:58:29 +03:00
|
|
|
"newAppInfo",
|
2013-02-02 00:26:07 +04:00
|
|
|
"getAppInfo",
|
|
|
|
"updateAppInfo",
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2016-03-16 10:58:29 +03:00
|
|
|
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
|
2013-02-02 00:26:07 +04:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
2016-02-04 00:12:45 +03:00
|
|
|
let origPlatformInfo = Cc["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Ci.nsIPlatformInfo);
|
|
|
|
|
2016-03-16 10:58:29 +03:00
|
|
|
/**
|
|
|
|
* Create new XULAppInfo instance with specified options.
|
|
|
|
*
|
|
|
|
* options is a object with following keys:
|
|
|
|
* ID: nsIXULAppInfo.ID
|
|
|
|
* name: nsIXULAppInfo.name
|
|
|
|
* version: nsIXULAppInfo.version
|
|
|
|
* platformVersion: nsIXULAppInfo.platformVersion
|
|
|
|
* OS: nsIXULRuntime.OS
|
|
|
|
*
|
|
|
|
* crashReporter: nsICrashReporter interface is implemented if true
|
|
|
|
* extraProps: extra properties added to XULAppInfo
|
|
|
|
*/
|
2017-06-24 00:08:02 +03:00
|
|
|
this.newAppInfo = function(options = {}) {
|
2016-03-16 10:58:29 +03:00
|
|
|
let ID = ("ID" in options) ? options.ID : "xpcshell@tests.mozilla.org";
|
|
|
|
let name = ("name" in options) ? options.name : "xpcshell";
|
|
|
|
let version = ("version" in options) ? options.version : "1";
|
|
|
|
let platformVersion
|
|
|
|
= ("platformVersion" in options) ? options.platformVersion : "p-ver";
|
|
|
|
let OS = ("OS" in options) ? options.OS : "XPCShell";
|
|
|
|
let extraProps = ("extraProps" in options) ? options.extraProps : {};
|
|
|
|
|
|
|
|
let appInfo = {
|
|
|
|
// nsIXULAppInfo
|
|
|
|
vendor: "Mozilla",
|
2017-06-24 00:08:02 +03:00
|
|
|
name,
|
|
|
|
ID,
|
|
|
|
version,
|
2016-03-16 10:58:29 +03:00
|
|
|
appBuildID: "20160315",
|
2016-02-04 00:12:45 +03:00
|
|
|
|
|
|
|
// nsIPlatformInfo
|
2017-06-24 00:08:02 +03:00
|
|
|
platformVersion,
|
2016-02-04 00:12:45 +03:00
|
|
|
platformBuildID: origPlatformInfo.platformBuildID,
|
2016-03-16 10:58:29 +03:00
|
|
|
|
|
|
|
// nsIXULRuntime
|
|
|
|
inSafeMode: false,
|
|
|
|
logConsoleErrors: true,
|
2017-06-24 00:08:02 +03:00
|
|
|
OS,
|
2016-03-16 10:58:29 +03:00
|
|
|
XPCOMABI: "noarch-spidermonkey",
|
|
|
|
invalidateCachesOnRestart() {},
|
|
|
|
|
|
|
|
// nsIWinAppHelper
|
|
|
|
get userCanElevate() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let interfaces = [Ci.nsIXULAppInfo,
|
2016-02-04 00:12:45 +03:00
|
|
|
Ci.nsIPlatformInfo,
|
2016-03-16 10:58:29 +03:00
|
|
|
Ci.nsIXULRuntime];
|
|
|
|
if ("nsIWinAppHelper" in Ci) {
|
|
|
|
interfaces.push(Ci.nsIWinAppHelper);
|
2015-04-16 11:16:19 +03:00
|
|
|
}
|
2016-03-16 10:58:29 +03:00
|
|
|
|
|
|
|
if ("crashReporter" in options && options.crashReporter) {
|
|
|
|
// nsICrashReporter
|
|
|
|
appInfo.annotations = {};
|
|
|
|
appInfo.annotateCrashReport = function(key, data) {
|
|
|
|
this.annotations[key] = data;
|
|
|
|
};
|
|
|
|
interfaces.push(Ci.nsICrashReporter);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let key of Object.keys(extraProps)) {
|
|
|
|
appInfo.browserTabsRemoteAutostart = extraProps[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
appInfo.QueryInterface = XPCOMUtils.generateQI(interfaces);
|
|
|
|
|
|
|
|
return appInfo;
|
2013-02-02 00:26:07 +04:00
|
|
|
};
|
|
|
|
|
2016-03-16 10:58:29 +03:00
|
|
|
var currentAppInfo = newAppInfo();
|
2013-02-02 00:26:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain a reference to the current object used to define XULAppInfo.
|
|
|
|
*/
|
2017-06-24 00:08:02 +03:00
|
|
|
this.getAppInfo = function() { return currentAppInfo; };
|
2013-02-02 00:26:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the current application info.
|
|
|
|
*
|
2016-03-16 10:58:29 +03:00
|
|
|
* See newAppInfo for options.
|
2013-02-02 00:26:07 +04:00
|
|
|
*
|
|
|
|
* To change the current XULAppInfo, simply call this function. If there was
|
|
|
|
* a previously registered app info object, it will be unloaded and replaced.
|
|
|
|
*/
|
2017-06-24 00:08:02 +03:00
|
|
|
this.updateAppInfo = function(options) {
|
2016-03-16 10:58:29 +03:00
|
|
|
currentAppInfo = newAppInfo(options);
|
2013-02-02 00:26:07 +04:00
|
|
|
|
|
|
|
let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}");
|
|
|
|
let cid = "@mozilla.org/xre/app-info;1";
|
|
|
|
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
|
|
|
|
|
|
|
// Unregister an existing factory if one exists.
|
|
|
|
try {
|
|
|
|
let existing = Components.manager.getClassObjectByContractID(cid, Ci.nsIFactory);
|
|
|
|
registrar.unregisterFactory(id, existing);
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
let factory = {
|
2017-06-24 00:08:02 +03:00
|
|
|
createInstance(outer, iid) {
|
2013-02-02 00:26:07 +04:00
|
|
|
if (outer != null) {
|
|
|
|
throw Cr.NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
|
|
|
|
2016-03-16 10:58:29 +03:00
|
|
|
return currentAppInfo.QueryInterface(iid);
|
2013-02-02 00:26:07 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
registrar.registerFactory(id, "XULAppInfo", cid, factory);
|
|
|
|
};
|
|
|
|
|