author | Marco Bonardo <mbonardo@mozilla.com> |
Wed, 16 Jun 2010 12:00:29 +0200 | |
changeset 43675 | 60a14de5241c9955a0b5e0a2181c1a88f3ee2692 |
parent 43674 | 5e6cec74c4b46c50092d61b431a3a76c45c77a84 |
child 43676 | 2e666a1a2c7ec9f8a66405d21e07554badba7e01 |
push id | 13850 |
push user | mak77@bonardo.net |
push date | Wed, 16 Jun 2010 10:01:27 +0000 |
treeherder | mozilla-central@2e666a1a2c7e [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | honzab |
bugs | 568091 |
milestone | 1.9.3a6pre |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
dom/src/storage/nsDOMStorageDBWrapper.cpp | file | annotate | diff | comparison | revisions | |
dom/tests/unit/test_domstorage_aboutpages.js | file | annotate | diff | comparison | revisions |
--- a/dom/src/storage/nsDOMStorageDBWrapper.cpp +++ b/dom/src/storage/nsDOMStorageDBWrapper.cpp @@ -301,21 +301,32 @@ nsDOMStorageDBWrapper::CreateOriginScope return NS_OK; } nsresult nsDOMStorageDBWrapper::CreateDomainScopeDBKey(nsIURI* aUri, nsACString& aKey) { nsresult rv; - nsCAutoString host; - rv = aUri->GetAsciiHost(host); + nsCAutoString domainScope; + rv = aUri->GetAsciiHost(domainScope); 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); return NS_OK; } nsresult nsDOMStorageDBWrapper::CreateDomainScopeDBKey(const nsACString& aAsciiDomain, nsACString& aKey)
new file mode 100644 --- /dev/null +++ b/dom/tests/unit/test_domstorage_aboutpages.js @@ -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); +} +