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