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: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ michael@0: "getAppInfo", michael@0: "updateAppInfo", michael@0: ]; michael@0: michael@0: michael@0: const {interfaces: Ci, results: Cr, utils: Cu} = Components; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: let APP_INFO = { michael@0: vendor: "Mozilla", michael@0: name: "xpcshell", michael@0: ID: "xpcshell@tests.mozilla.org", michael@0: version: "1", michael@0: appBuildID: "20121107", michael@0: platformVersion: "p-ver", michael@0: platformBuildID: "20121106", michael@0: inSafeMode: false, michael@0: logConsoleErrors: true, michael@0: OS: "XPCShell", michael@0: XPCOMABI: "noarch-spidermonkey", michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]), michael@0: invalidateCachesOnRestart: function() {}, michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Obtain a reference to the current object used to define XULAppInfo. michael@0: */ michael@0: this.getAppInfo = function () { return APP_INFO; } michael@0: michael@0: /** michael@0: * Update the current application info. michael@0: * michael@0: * If the argument is defined, it will be the object used. Else, APP_INFO is michael@0: * used. michael@0: * michael@0: * To change the current XULAppInfo, simply call this function. If there was michael@0: * a previously registered app info object, it will be unloaded and replaced. michael@0: */ michael@0: this.updateAppInfo = function (obj) { michael@0: obj = obj || APP_INFO; michael@0: APP_INFO = obj; michael@0: michael@0: let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"); michael@0: let cid = "@mozilla.org/xre/app-info;1"; michael@0: let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); michael@0: michael@0: // Unregister an existing factory if one exists. michael@0: try { michael@0: let existing = Components.manager.getClassObjectByContractID(cid, Ci.nsIFactory); michael@0: registrar.unregisterFactory(id, existing); michael@0: } catch (ex) {} michael@0: michael@0: let factory = { michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) { michael@0: throw Cr.NS_ERROR_NO_AGGREGATION; michael@0: } michael@0: michael@0: return obj.QueryInterface(iid); michael@0: }, michael@0: }; michael@0: michael@0: registrar.registerFactory(id, "XULAppInfo", cid, factory); michael@0: }; michael@0: