mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 599479 - Accessing window.localStorage with dom.storage.enabled=false causes NS_ERROR_DOM_SECURITY_ERR, r=jst, a2.0=jst
This commit is contained in:
parent
a346c6b678
commit
36d86d4adc
@ -234,6 +234,8 @@
|
|||||||
static PRLogModuleInfo* gDOMLeakPRLog;
|
static PRLogModuleInfo* gDOMLeakPRLog;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char kStorageEnabled[] = "dom.storage.enabled";
|
||||||
|
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
using mozilla::TimeStamp;
|
using mozilla::TimeStamp;
|
||||||
using mozilla::TimeDuration;
|
using mozilla::TimeDuration;
|
||||||
@ -7666,6 +7668,12 @@ nsGlobalWindow::GetSessionStorage(nsIDOMStorage ** aSessionStorage)
|
|||||||
nsIDocShell* docShell = GetDocShell();
|
nsIDocShell* docShell = GetDocShell();
|
||||||
|
|
||||||
if (!principal || !docShell) {
|
if (!principal || !docShell) {
|
||||||
|
*aSessionStorage = nsnull;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nsContentUtils::GetBoolPref(kStorageEnabled)) {
|
||||||
|
*aSessionStorage = nsnull;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7728,6 +7736,11 @@ nsGlobalWindow::GetGlobalStorage(nsIDOMStorageList ** aGlobalStorage)
|
|||||||
NS_ENSURE_ARG_POINTER(aGlobalStorage);
|
NS_ENSURE_ARG_POINTER(aGlobalStorage);
|
||||||
|
|
||||||
#ifdef MOZ_STORAGE
|
#ifdef MOZ_STORAGE
|
||||||
|
if (!nsContentUtils::GetBoolPref(kStorageEnabled)) {
|
||||||
|
*aGlobalStorage = nsnull;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
if (!sGlobalStorageList) {
|
if (!sGlobalStorageList) {
|
||||||
nsresult rv = NS_NewDOMStorageList(&sGlobalStorageList);
|
nsresult rv = NS_NewDOMStorageList(&sGlobalStorageList);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
@ -7749,6 +7762,11 @@ nsGlobalWindow::GetLocalStorage(nsIDOMStorage ** aLocalStorage)
|
|||||||
|
|
||||||
NS_ENSURE_ARG(aLocalStorage);
|
NS_ENSURE_ARG(aLocalStorage);
|
||||||
|
|
||||||
|
if (!nsContentUtils::GetBoolPref(kStorageEnabled)) {
|
||||||
|
*aLocalStorage = nsnull;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mLocalStorage) {
|
if (!mLocalStorage) {
|
||||||
*aLocalStorage = nsnull;
|
*aLocalStorage = nsnull;
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ _TEST_FILES = \
|
|||||||
test_localStorageBasePrivateBrowsing.html \
|
test_localStorageBasePrivateBrowsing.html \
|
||||||
test_localStorageBaseSessionOnly.html \
|
test_localStorageBaseSessionOnly.html \
|
||||||
test_localStorageCookieSettings.html \
|
test_localStorageCookieSettings.html \
|
||||||
|
test_localStorageEnablePref.html \
|
||||||
test_localStorageOriginsEquals.html \
|
test_localStorageOriginsEquals.html \
|
||||||
test_localStorageOriginsDiff.html \
|
test_localStorageOriginsDiff.html \
|
||||||
test_localStorageOriginsPortDiffs.html \
|
test_localStorageOriginsPortDiffs.html \
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>localStorage enable preference test</title>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function setDOMStorageEnabled(enabled)
|
||||||
|
{
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
|
||||||
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIPrefBranch);
|
||||||
|
prefs.setBoolPref("dom.storage.enabled", enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkException(func, exc)
|
||||||
|
{
|
||||||
|
var exceptionThrew = false;
|
||||||
|
try {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
exceptionThrew = true;
|
||||||
|
is(ex.name, exc, "Expected "+exc+" exception");
|
||||||
|
}
|
||||||
|
ok(exceptionThrew, "Exception "+exc+" threw");
|
||||||
|
}
|
||||||
|
|
||||||
|
function startTest()
|
||||||
|
{
|
||||||
|
setDOMStorageEnabled(true);
|
||||||
|
|
||||||
|
is(typeof(window.localStorage), "object", "Storage is present");
|
||||||
|
var storage = window.localStorage;
|
||||||
|
|
||||||
|
setDOMStorageEnabled(false);
|
||||||
|
|
||||||
|
is(window.localStorage, null, "Storage is null");
|
||||||
|
|
||||||
|
checkException(function() {storage.setItem("test", "value");}, "NS_ERROR_DOM_SECURITY_ERR");
|
||||||
|
|
||||||
|
setDOMStorageEnabled(true);
|
||||||
|
|
||||||
|
is(typeof(window.localStorage), "object", "Storage is present again");
|
||||||
|
storage.setItem("test", "value");
|
||||||
|
ok(storage.getItem("test"), "value", "value can be set");
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanup()
|
||||||
|
{
|
||||||
|
setDOMStorageEnabled(true);
|
||||||
|
window.localStorage.clear();
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function doTest()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
startTest();
|
||||||
|
}
|
||||||
|
catch(exc)
|
||||||
|
{
|
||||||
|
ok(false, exc+" was threw during the test")
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body onload="doTest();">
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user