Skip to content

Commit

Permalink
Extrapolate and create AboutPages handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlex94 committed Oct 30, 2024
1 parent e57f0d1 commit f979615
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 63 deletions.
4 changes: 2 additions & 2 deletions waterfox/browser/components/WaterfoxGlue.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const lazy = {}

ChromeUtils.defineESModuleGetters(lazy, {
AboutPages: 'resource:///modules/AboutPages.sys.mjs',
AddonManager: 'resource://gre/modules/AddonManager.sys.mjs',
AttributionCode: 'resource:///modules/AttributionCode.sys.mjs',
BrowserUtils: 'resource:///modules/BrowserUtils.sys.mjs',
Expand All @@ -16,7 +17,6 @@ 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 @@ -74,7 +74,7 @@ export const WaterfoxGlue = {
this.addAddonListener();

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

async _setPrefObservers() {
Expand Down
57 changes: 0 additions & 57 deletions waterfox/browser/components/aboutcfg/AboutCfg.sys.mjs

This file was deleted.

4 changes: 0 additions & 4 deletions waterfox/browser/components/aboutcfg/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
# 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"]
70 changes: 70 additions & 0 deletions waterfox/browser/components/utils/AboutPages.sys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* 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/. */

const registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);

function generateFreeCID() {
let uuid = Components.ID(Services.uuid.generateUUID().toString());
while (registrar.isCIDRegistered(uuid)) {
uuid = Components.ID(Services.uuid.generateUUID().toString());
}
return uuid;
}

function AboutPage(pageInfo) {
this.pageInfo = pageInfo;
}

AboutPage.prototype = {
get uri() {
if (!this._uri) {
this._uri = Services.io.newURI(this.pageInfo.chrome);
}
return this._uri;
},
newChannel: function(_uri, loadInfo) {
const ch = Services.io.newChannelFromURIWithLoadInfo(this.uri, loadInfo);
ch.owner = Services.scriptSecurityManager.getSystemPrincipal();
return ch;
},
getURIFlags: (_uri) => Components.interfaces.nsIAboutModule.ALLOW_SCRIPT | Components.interfaces.nsIAboutModule.IS_SECURE_CHROME_UI,
getChromeURI: function(_uri) {
return this.uri;
},
QueryInterface: ChromeUtils.generateQI(['nsIAboutModule']),
};

// Define the pages to register
const ABOUT_PAGES = [
{
about: "cfg",
chrome: "chrome://browser/content/aboutcfg/aboutcfg.xhtml",
contract: "@mozilla.org/network/protocol/about;1?what=cfg"
},
{
about: "passwords",
chrome: "chrome://browser/content/passwordManager.xhtml",
contract: "@mozilla.org/network/protocol/about;1?what=passwords"
}
];

export const AboutPages = {
init() {
for (const pageInfo of ABOUT_PAGES) {
const AboutModuleFactory = {
createInstance(aIID) {
return new AboutPage(pageInfo).QueryInterface(aIID);
},
QueryInterface: ChromeUtils.generateQI(['nsIFactory']),
};

registrar.registerFactory(
generateFreeCID(),
`about:${pageInfo.about}`,
pageInfo.contract,
AboutModuleFactory
);
}
}
};
1 change: 1 addition & 0 deletions waterfox/browser/components/utils/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

EXTRA_JS_MODULES += [
"AboutPages.sys.mjs",
"BrowserUtils.sys.mjs",
"PrefUtils.sys.mjs",
]
Expand Down

0 comments on commit f979615

Please sign in to comment.