-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extrapolate and create AboutPages handler.
- Loading branch information
Showing
5 changed files
with
73 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters