testing/modules/AppInfo.jsm

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 this.EXPORTED_SYMBOLS = [
michael@0 8 "getAppInfo",
michael@0 9 "updateAppInfo",
michael@0 10 ];
michael@0 11
michael@0 12
michael@0 13 const {interfaces: Ci, results: Cr, utils: Cu} = Components;
michael@0 14
michael@0 15 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 16
michael@0 17 let APP_INFO = {
michael@0 18 vendor: "Mozilla",
michael@0 19 name: "xpcshell",
michael@0 20 ID: "xpcshell@tests.mozilla.org",
michael@0 21 version: "1",
michael@0 22 appBuildID: "20121107",
michael@0 23 platformVersion: "p-ver",
michael@0 24 platformBuildID: "20121106",
michael@0 25 inSafeMode: false,
michael@0 26 logConsoleErrors: true,
michael@0 27 OS: "XPCShell",
michael@0 28 XPCOMABI: "noarch-spidermonkey",
michael@0 29 QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime]),
michael@0 30 invalidateCachesOnRestart: function() {},
michael@0 31 };
michael@0 32
michael@0 33
michael@0 34 /**
michael@0 35 * Obtain a reference to the current object used to define XULAppInfo.
michael@0 36 */
michael@0 37 this.getAppInfo = function () { return APP_INFO; }
michael@0 38
michael@0 39 /**
michael@0 40 * Update the current application info.
michael@0 41 *
michael@0 42 * If the argument is defined, it will be the object used. Else, APP_INFO is
michael@0 43 * used.
michael@0 44 *
michael@0 45 * To change the current XULAppInfo, simply call this function. If there was
michael@0 46 * a previously registered app info object, it will be unloaded and replaced.
michael@0 47 */
michael@0 48 this.updateAppInfo = function (obj) {
michael@0 49 obj = obj || APP_INFO;
michael@0 50 APP_INFO = obj;
michael@0 51
michael@0 52 let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}");
michael@0 53 let cid = "@mozilla.org/xre/app-info;1";
michael@0 54 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
michael@0 55
michael@0 56 // Unregister an existing factory if one exists.
michael@0 57 try {
michael@0 58 let existing = Components.manager.getClassObjectByContractID(cid, Ci.nsIFactory);
michael@0 59 registrar.unregisterFactory(id, existing);
michael@0 60 } catch (ex) {}
michael@0 61
michael@0 62 let factory = {
michael@0 63 createInstance: function (outer, iid) {
michael@0 64 if (outer != null) {
michael@0 65 throw Cr.NS_ERROR_NO_AGGREGATION;
michael@0 66 }
michael@0 67
michael@0 68 return obj.QueryInterface(iid);
michael@0 69 },
michael@0 70 };
michael@0 71
michael@0 72 registrar.registerFactory(id, "XULAppInfo", cid, factory);
michael@0 73 };
michael@0 74

mercurial