Bug 538421: Add a nsIAboutModule flag to hide 'about:' pages from about:about. r=mano, sr=bzbarsky

This commit is contained in:
Steffen Wilberg 2010-01-23 11:07:48 +01:00
parent bce967fc88
commit c762cf2060
6 changed files with 37 additions and 10 deletions

View file

@ -70,14 +70,17 @@ static RedirEntry kRedirMap[] = {
#ifdef MOZ_SAFE_BROWSING
{ "blocked", "chrome://browser/content/safebrowsing/blockedSite.xhtml",
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
nsIAboutModule::ALLOW_SCRIPT },
nsIAboutModule::ALLOW_SCRIPT |
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
#endif
{ "certerror", "chrome://browser/content/certerror/aboutCertError.xhtml",
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
nsIAboutModule::ALLOW_SCRIPT },
nsIAboutModule::ALLOW_SCRIPT |
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
{ "feeds", "chrome://browser/content/feeds/subscribe.xhtml",
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
nsIAboutModule::ALLOW_SCRIPT },
nsIAboutModule::ALLOW_SCRIPT |
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
{ "privatebrowsing", "chrome://browser/content/aboutPrivateBrowsing.xhtml",
nsIAboutModule::ALLOW_SCRIPT },
{ "rights",

View file

@ -84,7 +84,8 @@ static RedirEntry kRedirMap[] = {
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
{ "neterror", "chrome://global/content/netError.xhtml",
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
nsIAboutModule::ALLOW_SCRIPT },
nsIAboutModule::ALLOW_SCRIPT |
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
{ "memory", "chrome://global/content/aboutMemory.xhtml",
nsIAboutModule::ALLOW_SCRIPT }
};

View file

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Steffen Wilberg <steffen.wilberg@web.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -64,6 +65,12 @@ interface nsIAboutModule : nsISupports
*/
const unsigned long ALLOW_SCRIPT = (1 << 1);
/**
* A flag that indicates whether this about: URI doesn't want to be listed
* in about:about, especially if it's not useful without a query string.
*/
const unsigned long HIDE_FROM_ABOUTABOUT = (1 << 2);
/**
* A method to get the flags that apply to a given about: URI. The URI
* passed in is guaranteed to be one of the URIs that this module

View file

@ -69,7 +69,8 @@ nsAboutBlank::NewChannel(nsIURI *aURI, nsIChannel **result)
NS_IMETHODIMP
nsAboutBlank::GetURIFlags(nsIURI *aURI, PRUint32 *result)
{
*result = nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT;
*result = nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
nsIAboutModule::HIDE_FROM_ABOUTABOUT;
return NS_OK;
}

View file

@ -132,7 +132,7 @@ nsAboutCacheEntry::NewChannel(nsIURI *uri, nsIChannel **result)
NS_IMETHODIMP
nsAboutCacheEntry::GetURIFlags(nsIURI *aURI, PRUint32 *result)
{
*result = 0;
*result = nsIAboutModule::HIDE_FROM_ABOUTABOUT;
return NS_OK;
}

View file

@ -46,19 +46,34 @@
<title>&aboutAbout.title;</title>
<link rel="stylesheet" href="chrome://global/skin/about.css" type="text/css"/>
<script type="application/javascript"><![CDATA[
const Cc = Components.classes;
const Ci = Components.interfaces;
var gProtocols = [];
var gContainer;
const BLACKLIST = ["blank", "blocked", "cache-entry", "certerror", "feeds", "neterror"];
window.onload = function () {
gContainer = document.getElementById("abouts");
findAbouts();
}
function findAbouts() {
for (var cid in Components.classes) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
for (var cid in Cc) {
var result = cid.match(/@mozilla.org\/network\/protocol\/about;1\?what\=(.*)$/);
if (result && (BLACKLIST.indexOf(result[1]) == -1))
gProtocols.push(result[1]);
if (result) {
var aboutType = result[1];
var contract = "@mozilla.org/network/protocol/about;1?what=" + aboutType;
try {
var am = Cc[contract].getService(Ci.nsIAboutModule);
var uri = ios.newURI("about:"+aboutType, null, null);
var flags = am.getURIFlags(uri);
if (!(flags & Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT)) {
gProtocols.push(aboutType);
}
} catch (e) {
// getService might have thrown if the component doesn't actually
// implement nsIAboutModule
}
}
}
gProtocols.sort().forEach(createProtocolListing);
}