Bug 1119462 - Allow unlimited quota for explicit persistent storage; r=bent

This commit is contained in:
Jan Varga 2015-01-09 16:56:23 +01:00
parent 44918c55c0
commit 8d64977501
6 changed files with 46 additions and 141 deletions

View File

@ -10852,6 +10852,14 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
return rv;
}
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
if (persistenceType == PERSISTENCE_TYPE_PERSISTENT &&
!QuotaManager::IsOriginWhitelistedForPersistentStorage(origin) &&
!isApp) {
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
}
#endif
PermissionRequestBase::PermissionValue permission;
if (QuotaManager::IsFirstPromptRequired(persistenceType, origin, isApp)) {

View File

@ -152,8 +152,6 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
[test_deleteDatabase_interactions.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
[test_disabled_quota_prompt.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
[test_error_events_abort_transactions.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
[test_event_propagation.html]

View File

@ -1,120 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<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;version=1.7">
function addDataTo(objectStore)
{
const dataSize = 51200;
let buffer = new ArrayBuffer(dataSize);
for (let view = new Uint8Array(buffer), i = 0; i < dataSize; i++) {
view[i] = parseInt(Math.random() * 255)
}
let request = objectStore.put(buffer);
request.onerror = function(event) {
is(request.error.name,
"QuotaExceededError",
"correct error set on request");
SimpleTest.expectUncaughtException(true);
event.stopPropagation();
};
request.onsuccess = function() {
is(request.error, null, "no error yet, adding another value");
addDataTo(objectStore);
};
}
function testSteps()
{
const databaseName = window.location.pathname;
const databaseVersion = 1;
const databaseStorage = "persistent";
const objectStoreName = "foo";
info("setting quota pref");
SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.warningQuota", 2]] },
continueToNextStep);
yield undefined;
info("opening database");
let request = indexedDB.open(databaseName, {version: databaseVersion,
storage: databaseStorage});
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = unexpectedSuccessHandler;
let event = yield undefined;
info("creating object store");
let db = event.target.result;
db.onerror = errorHandler;
db.onversionchange = function(event) {
is(event.oldVersion, databaseVersion, "got correct oldVersion");
is(event.newVersion, null, "got correct newVersion");
db.close();
};
let objectStore = db.createObjectStore(objectStoreName,
{ autoIncrement: true });
request.onupgradeneeded = unexpectedSuccessHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
info("making transaction");
let transaction = db.transaction(objectStoreName, "readwrite");
transaction.onabort = grabEventAndContinueHandler;
transaction.oncomplete = unexpectedSuccessHandler;
addDataTo(transaction.objectStore(objectStoreName));
info("adding until quota limit is reached");
event = yield undefined;
SimpleTest.expectUncaughtException(false);
is(transaction.error.name,
"QuotaExceededError",
"correct error set on transaction");
info("deleting database");
request = indexedDB.deleteDatabase(databaseName);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
info("resetting quota pref");
SpecialPowers.popPrefEnv(continueToNextStep);
yield undefined;
finishTest();
yield undefined;
}
</script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest(true);"></body>
</html>

View File

@ -31,6 +31,19 @@
for (let storage of storages) {
let request = indexedDB.open(name, { version: version,
storage: storage });
if (storage == "persistent" &&
SpecialPowers.Services.appinfo.widgetToolkit == "android") {
request.onerror = expectedErrorHandler("InvalidStateError");
request.onupgradeneeded = unexpectedSuccessHandler;
request.onsuccess = unexpectedSuccessHandler;
let event = yield undefined;
is(event.type, "error", "Got corrent event type");
continue;
}
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = grabEventAndContinueHandler;

View File

@ -796,20 +796,6 @@ SanitizeOriginString(nsCString& aOrigin)
aOrigin.ReplaceChar(kReplaceChars, '+');
}
// The first prompt and quota tracking is not required for these origins in
// persistent storage.
bool
IsPersistentOriginWhitelisted(const nsACString& aOrigin)
{
if (aOrigin.EqualsLiteral(kChromeOrigin) ||
aOrigin.EqualsLiteral(kAboutHomeOrigin) ||
StringBeginsWith(aOrigin, nsDependentCString(kIndexedDBOriginPrefix))) {
return true;
}
return false;
}
nsresult
CloneStoragePath(nsIFile* aBaseDir,
const nsACString& aStorageName,
@ -2721,6 +2707,21 @@ QuotaManager::GetInfoForChrome(nsACString* aGroup,
}
}
// static
bool
QuotaManager::IsOriginWhitelistedForPersistentStorage(const nsACString& aOrigin)
{
// The first prompt and quota tracking is not required for these origins in
// persistent storage.
if (aOrigin.EqualsLiteral(kChromeOrigin) ||
aOrigin.EqualsLiteral(kAboutHomeOrigin) ||
StringBeginsWith(aOrigin, nsDependentCString(kIndexedDBOriginPrefix))) {
return true;
}
return false;
}
// static
bool
QuotaManager::IsTreatedAsPersistent(PersistenceType aPersistenceType,
@ -2744,7 +2745,7 @@ QuotaManager::IsFirstPromptRequired(PersistenceType aPersistenceType,
return false;
}
return !IsPersistentOriginWhitelisted(aOrigin);
return !IsOriginWhitelistedForPersistentStorage(aOrigin);
}
// static
@ -2758,7 +2759,7 @@ QuotaManager::IsQuotaEnforced(PersistenceType aPersistenceType,
return true;
}
if (IsPersistentOriginWhitelisted(aOrigin)) {
if (IsOriginWhitelistedForPersistentStorage(aOrigin)) {
return false;
}
@ -3135,8 +3136,9 @@ QuotaManager::LockedQuotaIsLifted()
MOZ_ASSERT(mCurrentWindowIndex != BAD_TLS_INDEX);
#if 1
// XXX For now we always fail the quota prompt.
return false;
// XXX We disabled the second (quota) prompt. All related code is going away
// soon.
return true;
#else
nsPIDOMWindow* window =
static_cast<nsPIDOMWindow*>(PR_GetThreadPrivate(mCurrentWindowIndex));
@ -4776,7 +4778,8 @@ StorageDirectoryHelper::CreateOrUpgradeMetadataFiles()
}
// Move whitelisted origins to new persistent storage.
if (IsPersistentOriginWhitelisted(originProps.mSpec)) {
if (QuotaManager::IsOriginWhitelistedForPersistentStorage(
originProps.mSpec)) {
if (!permanentStorageDir) {
permanentStorageDir =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);

View File

@ -315,6 +315,9 @@ public:
bool* aIsApp,
bool* aHasUnlimStoragePerm);
static bool
IsOriginWhitelistedForPersistentStorage(const nsACString& aOrigin);
static bool
IsTreatedAsPersistent(PersistenceType aPersistenceType,
bool aIsApp);