Bug 397937 - Handle view-source on malware and error pages more gracefully, r=mconnor

This commit is contained in:
Blair McBride
2009-12-23 22:03:37 -05:00
parent c9b404b824
commit e9afd84370
2 changed files with 73 additions and 6 deletions

View File

@@ -78,23 +78,32 @@
function getURL()
{
var url = document.documentURI;
var index = url.search(/u\=/);
var match = url.match(/&u=([^&]+)&/);
// index == -1 if not found; if so, return an empty string
// match == null if not found; if so, return an empty string
// instead of what would turn out to be portions of the URI
if (index == -1)
if (!match)
return "";
return decodeURIComponent(url.slice(index + 2));
url = decodeURIComponent(match[1]);
// If this is a view-source page, then get then real URI of the page
if (/^view-source\:/.test(url))
url = url.slice(12);
return url;
}
/**
* Attempt to parse the result of getURL and extract a hostname. Fail back
* Attempt to get the hostname via document.location. Fail back
* to getURL so that we always return something meaningful.
*/
function getHostString()
{
return document.location.hostname;
try {
return document.location.hostname;
} catch (e) {
return getURL();
}
}
function initPage()