Skip to content

Commit

Permalink
Register about:cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
black7375 authored and MrAlex94 committed Oct 28, 2024
1 parent ba0239b commit f2265da
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
6 changes: 5 additions & 1 deletion waterfox/browser/components/WaterfoxGlue.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
TabFeatures: 'resource:///modules/TabFeatures.sys.mjs',
setTimeout: 'resource://gre/modules/Timer.sys.mjs',
UICustomizations: 'resource:///modules/UICustomizations.sys.mjs',
AboutCfg: 'resource:///modules/AboutCfg.sys.mjs',
})

const WATERFOX_CUSTOMIZATIONS_PREF =
Expand Down Expand Up @@ -70,7 +71,10 @@ export const WaterfoxGlue = {
// Observe browser shutdown
Services.obs.addObserver(this, 'quit-application-granted')
// Listen for addon events
this.addAddonListener()
this.addAddonListener();

// Register about:cfg
lazy.AboutCfg.init();
},

async _setPrefObservers() {
Expand Down
57 changes: 57 additions & 0 deletions waterfox/browser/components/aboutcfg/AboutCfg.sys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* 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/. */

// https://github.com/earthlng/aboutconfig/blob/main/aboutcfg.jsm
const registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);

// 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;
}

function VintageAboutConfig() {}
VintageAboutConfig.prototype = {
get uri() {
const urlString = 'chrome://browser/content/aboutcfg/aboutcfg.xhtml';
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 Components.interfaces.nsIAboutModule.ALLOW_SCRIPT | Components.interfaces.nsIAboutModule.IS_SECURE_CHROME_UI;
},
getChromeURI: function (_uri) {
return this.uri;
},
QueryInterface: ChromeUtils.generateQI(['nsIAboutModule']),
};

export const AboutCfg = {
init() {
const 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
);
}
}
4 changes: 4 additions & 0 deletions waterfox/browser/components/aboutcfg/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
# 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/.

EXTRA_JS_MODULES += [
"AboutCfg.sys.mjs",
]

JAR_MANIFESTS += ["jar.mn"]

0 comments on commit f2265da

Please sign in to comment.