-
Notifications
You must be signed in to change notification settings - Fork 2
/
aboutcfg.jsm
80 lines (69 loc) · 3.12 KB
/
aboutcfg.jsm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*** register an about:cfg page ...
*
* We're not just faking it, this makes it a bona-fide about: page.
* That means you can navigate to it by just typing about:cfg in the urlbar, and the identity icon will show it as a secure system page rather than a local file.
* And about:cfg will even show up on the about:about page!
*
* This technically also makes using the aboutconfig module safer, because it denies the document access to some privileged stuff that it would have with a chrome:// URI.
*
* Optionally edit the config.xhtml file and remove line 13: title="about:config".
* That line sets the tab title to about:config, which (with this script) isn't necessary or desirable since we're changing the URL to about:cfg.
* Without the title attribute, Firefox will automatically set the title to the tab's URL, which is about:cfg.
*
* Big THANKS to @aminomancer ( https://github.com/aminomancer/ )
*
***/
(() => {
//const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
let { classes: Cc, interfaces: Ci, manager: Cm, utils: Cu, results: Cr } = Components;
const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
let dir = Services.dirsvc.get("UChrm", Ci.nsIFile);
let appendFn = (nm) => dir.append(nm);
["utils", "aboutconfig", "config.xhtml"].forEach(appendFn);
if (!dir.exists()) return;
// generate a unique ID on every app launch. protection against the very unlikely possibility that a
// future update adds a component with the same class ID, which would break the script.
function generateFreeCID() {
let uuid = Components.ID(Services.uuid.generateUUID().toString());
// I can't tell whether generateUUID is guaranteed to produce a unique ID, or just a random ID.
// so I add this loop to regenerate it in the extremely unlikely (or potentially impossible)
// event that the UUID is already registered as a CID.
while (registrar.isCIDRegistered(uuid)) {
uuid = Components.ID(Services.uuid.generateUUID().toString());
}
return uuid;
}
const urlString = 'chrome://userchromejs/content/aboutconfig/config.xhtml';
function VintageAboutConfig() {}
VintageAboutConfig.prototype = {
get uri() {
if (!urlString) return null;
return this._uri || (this._uri = Services.io.newURI(urlString));
},
newChannel: function (_uri, loadInfo) {
const ch = Services.io.newChannelFromURIWithLoadInfo(this.uri, loadInfo);
ch.owner = Services.scriptSecurityManager.getSystemPrincipal();
return ch;
},
getURIFlags: function (_uri) {
return Ci.nsIAboutModule.ALLOW_SCRIPT | Ci.nsIAboutModule.IS_SECURE_CHROME_UI;
},
getChromeURI: function (_uri) {
return this.uri;
},
QueryInterface: ChromeUtils.generateQI(["nsIAboutModule"]),
};
var AboutModuleFactory = {
createInstance(aIID) {
return new VintageAboutConfig().QueryInterface(aIID);
},
QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),
};
registrar.registerFactory(
generateFreeCID(),
'about:cfg',
'@mozilla.org/network/protocol/about;1?what=cfg',
AboutModuleFactory
);
})();
let EXPORTED_SYMBOLS = [];