Bug 568091 - DOM Storage cannot store data for about: pages. r=honzab

This commit is contained in:
Marco Bonardo 2010-06-16 12:00:29 +02:00
parent ae3e280802
commit 08afd68fed
2 changed files with 46 additions and 3 deletions

View File

@ -306,11 +306,22 @@ nsDOMStorageDBWrapper::CreateDomainScopeDBKey(nsIURI* aUri, nsACString& aKey)
{ {
nsresult rv; nsresult rv;
nsCAutoString host; nsCAutoString domainScope;
rv = aUri->GetAsciiHost(host); rv = aUri->GetAsciiHost(domainScope);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = CreateDomainScopeDBKey(host, aKey); if (domainScope.IsEmpty()) {
// About pages have an empty host but a valid path. Since they are handled
// internally by our own redirector, we can trust them and use path as key.
PRBool isAboutUrl = PR_FALSE;
if ((NS_SUCCEEDED(aUri->SchemeIs("about", &isAboutUrl)) && isAboutUrl) ||
(NS_SUCCEEDED(aUri->SchemeIs("moz-safe-about", &isAboutUrl)) && isAboutUrl)) {
rv = aUri->GetPath(domainScope);
NS_ENSURE_SUCCESS(rv, rv);
}
}
rv = CreateDomainScopeDBKey(domainScope, aKey);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return NS_OK; return NS_OK;

View File

@ -0,0 +1,32 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
Components.utils.import("resource://gre/modules/Services.jsm");
function run_test()
{
// Needs a profile folder for the database.
do_get_profile();
testURI(Services.io.newURI("about:mozilla", null, null));
testURI(Services.io.newURI("moz-safe-about:rights", null, null));
}
function testURI(aURI) {
print("Testing: " + aURI.spec);
do_check_true(/about$/.test(aURI.scheme));
let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"].
getService(Components.interfaces.nsIScriptSecurityManager).
getCodebasePrincipal(aURI);
let dsm = Components.classes["@mozilla.org/dom/storagemanager;1"].
getService(Components.interfaces.nsIDOMStorageManager);
let storage = dsm.getLocalStorageForPrincipal(principal, "");
storage.setItem("test-item", "test-value");
print("Check that our value has been correctly stored.");
do_check_eq(storage.getItem("test-item"), "test-value");
storage.removeItem("test-item");
print("Check that our value has been correctly removed.");
do_check_eq(storage.getItem("test-item"), null);
}