Revision control

Copy as Markdown

Other Tools

/* 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/. */
export function AboutRedirector() {}
AboutRedirector.prototype = {
QueryInterface: ChromeUtils.generateQI(["nsIAboutModule"]),
// Each entry in the map has the key as the part after the "about:" and the
// value as a record with url and flags entries. Note that each addition here
// should be coupled with a corresponding addition in mailComponents.manifest.
_redirMap: {
newserror: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
rights: {
flags:
Ci.nsIAboutModule.ALLOW_SCRIPT |
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT,
},
support: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
preferences: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
downloads: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
policies: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
accountsettings: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
accountsetup: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
addressbook: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
"3pane": {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
message: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
import: {
flags: Ci.nsIAboutModule.ALLOW_SCRIPT,
},
profiling: {
flags:
Ci.nsIAboutModule.ALLOW_SCRIPT | Ci.nsIAboutModule.IS_SECURE_CHROME_UI,
},
},
/**
* Gets the module name from the given URI.
*/
_getModuleName(aURI) {
// Strip out the first ? or #, and anything following it
const name = /[^?#]+/.exec(aURI.pathQueryRef)[0];
return name.toLowerCase();
},
getURIFlags(aURI) {
const name = this._getModuleName(aURI);
if (!(name in this._redirMap)) {
throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
}
return this._redirMap[name].flags;
},
newChannel(aURI, aLoadInfo) {
const name = this._getModuleName(aURI);
if (!(name in this._redirMap)) {
throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
}
const newURI = Services.io.newURI(this._redirMap[name].url);
const channel = Services.io.newChannelFromURIWithLoadInfo(
newURI,
aLoadInfo
);
channel.originalURI = aURI;
if (
this._redirMap[name].flags &
Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT
) {
const principal = Services.scriptSecurityManager.createContentPrincipal(
aURI,
{}
);
channel.owner = principal;
}
return channel;
},
getChromeURI(aURI) {
const name = this._getModuleName(aURI);
if (!(name in this._redirMap)) {
throw Components.Exception(`no about:${name}`, Cr.NS_ERROR_ILLEGAL_VALUE);
}
return Services.io.newURI(this._redirMap[name].url);
},
};