Backed out changeset 4b41b425c4fa

This commit is contained in:
Marco Bonardo 2010-09-09 13:29:56 +02:00
Родитель 897cda976f
Коммит c85fdb88cb
7 изменённых файлов: 29 добавлений и 153 удалений

Просмотреть файл

@ -183,20 +183,16 @@ IsOfflineAllowed(const nsACString &aDomain)
// Returns two quotas - A hard limit for which adding data will be an error,
// and a limit after which a warning event will be sent to the observer
// service. The warn limit may be -1, in which case there will be no warning.
// If aOverrideQuota is set, the larger offline apps quota is used and no
// warning is sent.
static PRUint32
GetQuota(const nsACString &aDomain, PRInt32 *aQuota, PRInt32 *aWarnQuota,
bool aOverrideQuota)
GetQuota(const nsACString &aDomain, PRInt32 *aQuota, PRInt32 *aWarnQuota)
{
PRUint32 perm = GetOfflinePermission(aDomain);
if (IS_PERMISSION_ALLOWED(perm) || aOverrideQuota) {
if (IS_PERMISSION_ALLOWED(perm)) {
// This is an offline app, give more space by default.
*aQuota = ((PRInt32)nsContentUtils::GetIntPref(kOfflineAppQuota,
DEFAULT_OFFLINE_APP_QUOTA) * 1024);
if (perm == nsIOfflineCacheUpdateService::ALLOW_NO_WARN ||
aOverrideQuota) {
if (perm == nsIOfflineCacheUpdateService::ALLOW_NO_WARN) {
*aWarnQuota = -1;
} else {
*aWarnQuota = ((PRInt32)nsContentUtils::GetIntPref(kOfflineAppWarnQuota,
@ -579,7 +575,6 @@ nsDOMStorage::nsDOMStorage(nsDOMStorage& aThat)
, mScopeDBKey(aThat.mScopeDBKey)
#endif
, mEventBroadcaster(nsnull)
, mCanUseChromePersist(false)
{
mSecurityChecker = this;
mItems.Init(8);
@ -682,15 +677,6 @@ nsDOMStorage::InitAsLocalStorage(nsIPrincipal *aPrincipal, const nsSubstring &aD
#endif
mStorageType = LocalStorage;
nsCOMPtr<nsIURI> URI;
if (NS_SUCCEEDED(aPrincipal->GetURI(getter_AddRefs(URI))) && URI) {
PRBool isAbout;
mCanUseChromePersist =
(NS_SUCCEEDED(URI->SchemeIs("moz-safe-about", &isAbout) && isAbout)) ||
(NS_SUCCEEDED(URI->SchemeIs("about", &isAbout), && isAbout));
}
return NS_OK;
}
@ -824,11 +810,6 @@ nsDOMStorage::CacheStoragePermissions()
return mSecurityChecker->CanAccess(subjectPrincipal);
}
bool
nsDOMStorage::CanUseChromePersist()
{
return mCanUseChromePersist;
}
class ItemCounterState
{
@ -1271,8 +1252,7 @@ nsDOMStorage::SetDBValue(const nsAString& aKey,
PRInt32 offlineAppPermission;
PRInt32 quota;
PRInt32 warnQuota;
offlineAppPermission = GetQuota(mDomain, &quota, &warnQuota,
CanUseChromePersist());
offlineAppPermission = GetQuota(mDomain, &quota, &warnQuota);
PRInt32 usage;
rv = gStorageDB->SetKey(this, aKey, aValue, aSecure, quota,
@ -2002,18 +1982,18 @@ nsDOMStorageItem::ToString(nsAString& aStr)
}
// Cycle collection implementation for nsDOMStorageEvent
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMStorageEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMStorageEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mStorageArea)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMStorageEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mStorageArea)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsDOMStorageEvent, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(nsDOMStorageEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMStorageEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMStorageEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mStorageArea)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMStorageEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mStorageArea)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsDOMStorageEvent, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(nsDOMStorageEvent, nsDOMEvent)
DOMCI_DATA(StorageEvent, nsDOMStorageEvent)

Просмотреть файл

@ -175,10 +175,6 @@ public:
return mSessionOnly;
}
// Some privileged internal pages can use a persistent storage even in
// session-only or private-browsing modes.
bool CanUseChromePersist();
// Check whether storage may be used by the caller, and whether it
// is session only. Returns true if storage may be used.
static PRBool
@ -270,8 +266,6 @@ protected:
nsPIDOMStorage* mSecurityChecker;
nsPIDOMStorage* mEventBroadcaster;
bool mCanUseChromePersist;
public:
// e.g. "moc.rab.oof.:" or "moc.rab.oof.:http:80" depending
// on association with a domain (globalStorage) or

Просмотреть файл

@ -74,10 +74,7 @@ nsDOMStorageDBWrapper::Init()
{
nsresult rv;
rv = mPersistentDB.Init(NS_LITERAL_STRING("webappsstore.sqlite"));
NS_ENSURE_SUCCESS(rv, rv);
rv = mChromePersistentDB.Init(NS_LITERAL_STRING("chromeappsstore.sqlite"));
rv = mPersistentDB.Init();
NS_ENSURE_SUCCESS(rv, rv);
rv = mSessionOnlyDB.Init(&mPersistentDB);
@ -93,8 +90,6 @@ nsresult
nsDOMStorageDBWrapper::GetAllKeys(nsDOMStorage* aStorage,
nsTHashtable<nsSessionStorageEntry>* aKeys)
{
if (aStorage->CanUseChromePersist())
return mChromePersistentDB.GetAllKeys(aStorage, aKeys);
if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
return mPrivateBrowsingDB.GetAllKeys(aStorage, aKeys);
if (aStorage->SessionOnly())
@ -109,8 +104,6 @@ nsDOMStorageDBWrapper::GetKeyValue(nsDOMStorage* aStorage,
nsAString& aValue,
PRBool* aSecure)
{
if (aStorage->CanUseChromePersist())
return mChromePersistentDB.GetKeyValue(aStorage, aKey, aValue, aSecure);
if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
return mPrivateBrowsingDB.GetKeyValue(aStorage, aKey, aValue, aSecure);
if (aStorage->SessionOnly())
@ -128,9 +121,6 @@ nsDOMStorageDBWrapper::SetKey(nsDOMStorage* aStorage,
PRBool aExcludeOfflineFromUsage,
PRInt32 *aNewUsage)
{
if (aStorage->CanUseChromePersist())
return mChromePersistentDB.SetKey(aStorage, aKey, aValue, aSecure,
aQuota, aExcludeOfflineFromUsage, aNewUsage);
if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
return mPrivateBrowsingDB.SetKey(aStorage, aKey, aValue, aSecure,
aQuota, aExcludeOfflineFromUsage, aNewUsage);
@ -147,8 +137,6 @@ nsDOMStorageDBWrapper::SetSecure(nsDOMStorage* aStorage,
const nsAString& aKey,
const PRBool aSecure)
{
if (aStorage->CanUseChromePersist())
return mChromePersistentDB.SetSecure(aStorage, aKey, aSecure);
if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
return mPrivateBrowsingDB.SetSecure(aStorage, aKey, aSecure);
if (aStorage->SessionOnly())
@ -163,8 +151,6 @@ nsDOMStorageDBWrapper::RemoveKey(nsDOMStorage* aStorage,
PRBool aExcludeOfflineFromUsage,
PRInt32 aKeyUsage)
{
if (aStorage->CanUseChromePersist())
return mChromePersistentDB.RemoveKey(aStorage, aKey, aExcludeOfflineFromUsage, aKeyUsage);
if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
return mPrivateBrowsingDB.RemoveKey(aStorage, aKey, aExcludeOfflineFromUsage, aKeyUsage);
if (aStorage->SessionOnly())
@ -176,8 +162,6 @@ nsDOMStorageDBWrapper::RemoveKey(nsDOMStorage* aStorage,
nsresult
nsDOMStorageDBWrapper::ClearStorage(nsDOMStorage* aStorage)
{
if (aStorage->CanUseChromePersist())
return mChromePersistentDB.ClearStorage(aStorage);
if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
return mPrivateBrowsingDB.ClearStorage(aStorage);
if (aStorage->SessionOnly())
@ -265,8 +249,6 @@ nsresult
nsDOMStorageDBWrapper::GetUsage(nsDOMStorage* aStorage,
PRBool aExcludeOfflineFromUsage, PRInt32 *aUsage)
{
if (aStorage->CanUseChromePersist())
return mChromePersistentDB.GetUsage(aStorage, aExcludeOfflineFromUsage, aUsage);
if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
return mPrivateBrowsingDB.GetUsage(aStorage, aExcludeOfflineFromUsage, aUsage);
if (aStorage->SessionOnly())

Просмотреть файл

@ -217,7 +217,6 @@ public:
nsACString& aDomain);
protected:
nsDOMStoragePersistentDB mChromePersistentDB;
nsDOMStoragePersistentDB mPersistentDB;
nsDOMStorageMemoryDB mSessionOnlyDB;
nsDOMStorageMemoryDB mPrivateBrowsingDB;

Просмотреть файл

@ -124,7 +124,7 @@ nsIsOfflineSQLFunction::OnFunctionCall(
}
nsresult
nsDOMStoragePersistentDB::Init(const nsString& aDatabaseName)
nsDOMStoragePersistentDB::Init()
{
nsresult rv;
@ -132,7 +132,7 @@ nsDOMStoragePersistentDB::Init(const nsString& aDatabaseName)
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(storageFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = storageFile->Append(aDatabaseName);
rv = storageFile->Append(NS_LITERAL_STRING("webappsstore.sqlite"));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStorageService> service;

Просмотреть файл

@ -54,7 +54,7 @@ public:
~nsDOMStoragePersistentDB() {}
nsresult
Init(const nsString& aDatabaseName);
Init();
/**
* Retrieve a list of all the keys associated with a particular domain.

Просмотреть файл

@ -13,99 +13,20 @@ function run_test()
testURI(Services.io.newURI("moz-safe-about:rights", null, null));
}
function testURI(aURI)
{
function testURI(aURI) {
print("Testing: " + aURI.spec);
let storage = getStorageForURI(aURI);
storage.setItem("test-item", "test-value");
print("Check that our value has been correctly stored.");
do_check_eq(storage.length, 1);
do_check_eq(storage.key(0), "test-item");
do_check_eq(storage.getItem("test-item"), "test-value");
print("Check that our value is correctly removed.");
storage.removeItem("test-item");
do_check_eq(storage.length, 0);
do_check_eq(storage.getItem("test-item"), null);
testURIWithPrivateBrowsing(aURI);
testURIWithClearCookies(aURI);
}
function testURIWithPrivateBrowsing(aURI) {
print("Testing with private browsing: " + aURI.spec);
// Skip test if PB mode is not supported.
if (!("@mozilla.org/privatebrowsing;1" in Components.classes)) {
print("Skipped.");
return;
}
let storage = getStorageForURI(aURI);
storage.setItem("test-item", "test-value");
print("Check that our value has been correctly stored.");
do_check_eq(storage.length, 1);
do_check_eq(storage.key(0), "test-item");
do_check_eq(storage.getItem("test-item"), "test-value");
togglePBMode(true);
do_check_eq(storage.length, 1);
do_check_eq(storage.key(0), "test-item");
do_check_eq(storage.getItem("test-item"), "test-value");
print("Check that our value is correctly removed.");
storage.removeItem("test-item");
do_check_eq(storage.length, 0);
do_check_eq(storage.getItem("test-item"), null);
togglePBMode(false);
do_check_eq(storage.length, 0);
do_check_eq(storage.getItem("test-item"), null);
}
function testURIWithClearCookies(aURI) {
let storage = getStorageForURI(aURI);
storage.setItem("test-item", "test-value");
print("Check that our value has been correctly stored.");
do_check_eq(storage.length, 1);
do_check_eq(storage.key(0), "test-item");
do_check_eq(storage.getItem("test-item"), "test-value");
let dsm = Components.classes["@mozilla.org/dom/storagemanager;1"].
getService(Components.interfaces.nsIObserver);
dsm.observe(null, "cookie-changed", "cleared");
print("Check that our value is still stored.");
do_check_eq(storage.length, 1);
do_check_eq(storage.key(0), "test-item");
do_check_eq(storage.getItem("test-item"), "test-value");
print("Check that we can explicitly clear value.");
storage.clear();
do_check_eq(storage.length, 0);
do_check_eq(storage.getItem("test-item"), null);
}
function getStorageForURI(aURI)
{
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);
return dsm.getLocalStorageForPrincipal(principal, "");
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);
}
function togglePBMode(aEnable)
{
let pb = Components.classes["@mozilla.org/privatebrowsing;1"].
getService(Components.interfaces.nsIPrivateBrowsingService);
if (aEnable) {
Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session",
true);
pb.privateBrowsingEnabled = true;
} else {
try {
prefBranch.clearUserPref("browser.privatebrowsing.keep_current_session");
} catch (ex) {}
pb.privateBrowsingEnabled = false;
}
}