зеркало из https://github.com/mozilla/gecko-dev.git
Bug 352704, clear DOM storage when clearing cookies, r=mconnor,jst, sr=dveditz
This commit is contained in:
Родитель
05b5cbef14
Коммит
e9212da0b0
|
@ -119,9 +119,7 @@ Sanitizer.prototype = {
|
|||
|
||||
get canClear()
|
||||
{
|
||||
var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Components.interfaces.nsICookieManager);
|
||||
return cookieMgr.enumerator.hasMoreElements();
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ var gCookiesWindow = {
|
|||
this._view._rowCount += rowCountImpact;
|
||||
this._tree.treeBoxObject.rowCountChanged(oldRowCount - 1, rowCountImpact);
|
||||
|
||||
document.getElementById("removeAllCookies").disabled = this._view._filtered || (this._view.rowCount == 0);
|
||||
document.getElementById("removeAllCookies").disabled = this._view._filtered;
|
||||
},
|
||||
|
||||
_view: {
|
||||
|
@ -575,7 +575,7 @@ var gCookiesWindow = {
|
|||
var stringKey = selectedCookieCount == 1 ? "removeCookie" : "removeCookies";
|
||||
document.getElementById("removeCookie").label = this._bundle.getString(stringKey);
|
||||
|
||||
document.getElementById("removeAllCookies").disabled = this._view._filtered || (this._view.rowCount == 0);
|
||||
document.getElementById("removeAllCookies").disabled = this._view._filtered;
|
||||
document.getElementById("removeCookie").disabled = !(seln.count > 0);
|
||||
},
|
||||
|
||||
|
|
|
@ -115,6 +115,73 @@ nsSessionStorageEntry::~nsSessionStorageEntry()
|
|||
{
|
||||
}
|
||||
|
||||
//
|
||||
// nsDOMStorageManager
|
||||
//
|
||||
|
||||
nsDOMStorageManager* nsDOMStorageManager::gStorageManager;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsDOMStorageManager, nsIObserver)
|
||||
|
||||
//static
|
||||
nsresult
|
||||
nsDOMStorageManager::Initialize()
|
||||
{
|
||||
gStorageManager = new nsDOMStorageManager();
|
||||
if (!gStorageManager)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (!gStorageManager->mStorages.Init())
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (os)
|
||||
os->AddObserver(gStorageManager, "cookie-changed", PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PLDHashOperator)
|
||||
ClearStorage(nsDOMStorageEntry* aEntry, void* userArg)
|
||||
{
|
||||
aEntry->mStorage->ClearAll();
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMStorageManager::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("cleared").get())) {
|
||||
mStorages.EnumerateEntries(ClearStorage, nsnull);
|
||||
|
||||
#ifdef MOZ_STORAGE
|
||||
nsresult rv = nsDOMStorage::InitDB();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return nsDOMStorage::gStorageDB->RemoveAll();
|
||||
#endif
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMStorageManager::AddToStoragesHash(nsDOMStorage* aStorage)
|
||||
{
|
||||
nsDOMStorageEntry* entry = mStorages.PutEntry(aStorage);
|
||||
if (entry)
|
||||
entry->mStorage = aStorage;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMStorageManager::RemoveFromStoragesHash(nsDOMStorage* aStorage)
|
||||
{
|
||||
nsDOMStorageEntry* entry = mStorages.GetEntry(aStorage);
|
||||
if (entry)
|
||||
mStorages.RemoveEntry(entry);
|
||||
}
|
||||
|
||||
//
|
||||
// nsDOMStorage
|
||||
//
|
||||
|
@ -123,6 +190,21 @@ nsSessionStorageEntry::~nsSessionStorageEntry()
|
|||
nsDOMStorageDB* nsDOMStorage::gStorageDB = nsnull;
|
||||
#endif
|
||||
|
||||
nsDOMStorageEntry::nsDOMStorageEntry(KeyTypePointer aStr)
|
||||
: nsVoidPtrHashKey(aStr), mStorage(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
nsDOMStorageEntry::nsDOMStorageEntry(const nsDOMStorageEntry& aToCopy)
|
||||
: nsVoidPtrHashKey(aToCopy), mStorage(nsnull)
|
||||
{
|
||||
NS_ERROR("DOMStorage horked.");
|
||||
}
|
||||
|
||||
nsDOMStorageEntry::~nsDOMStorageEntry()
|
||||
{
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMStorage)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStorage)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMStorage)
|
||||
|
@ -150,6 +232,8 @@ nsDOMStorage::nsDOMStorage()
|
|||
: mUseDB(PR_FALSE), mSessionOnly(PR_TRUE), mItemsCached(PR_FALSE)
|
||||
{
|
||||
mItems.Init(8);
|
||||
if (nsDOMStorageManager::gStorageManager)
|
||||
nsDOMStorageManager::gStorageManager->AddToStoragesHash(this);
|
||||
}
|
||||
|
||||
nsDOMStorage::nsDOMStorage(nsIURI* aURI, const nsAString& aDomain, PRBool aUseDB)
|
||||
|
@ -164,10 +248,14 @@ nsDOMStorage::nsDOMStorage(nsIURI* aURI, const nsAString& aDomain, PRBool aUseDB
|
|||
#endif
|
||||
|
||||
mItems.Init(8);
|
||||
if (nsDOMStorageManager::gStorageManager)
|
||||
nsDOMStorageManager::gStorageManager->AddToStoragesHash(this);
|
||||
}
|
||||
|
||||
nsDOMStorage::~nsDOMStorage()
|
||||
{
|
||||
if (nsDOMStorageManager::gStorageManager)
|
||||
nsDOMStorageManager::gStorageManager->RemoveFromStoragesHash(this);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -595,6 +683,19 @@ nsDOMStorage::SetSecure(const nsAString& aKey, PRBool aSecure)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PLDHashOperator)
|
||||
ClearStorageItem(nsSessionStorageEntry* aEntry, void* userArg)
|
||||
{
|
||||
aEntry->mItem->SetValueInternal(EmptyString());
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMStorage::ClearAll()
|
||||
{
|
||||
mItems.EnumerateEntries(ClearStorageItem, nsnull);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PLDHashOperator)
|
||||
CopyStorageItems(nsSessionStorageEntry* aEntry, void* userArg)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,17 @@
|
|||
|
||||
class nsDOMStorageItem;
|
||||
|
||||
class nsDOMStorageEntry : public nsVoidPtrHashKey
|
||||
{
|
||||
public:
|
||||
nsDOMStorageEntry(KeyTypePointer aStr);
|
||||
nsDOMStorageEntry(const nsDOMStorageEntry& aToCopy);
|
||||
~nsDOMStorageEntry();
|
||||
|
||||
// weak reference so that it can be deleted when no longer used
|
||||
nsDOMStorage* mStorage;
|
||||
};
|
||||
|
||||
class nsSessionStorageEntry : public nsStringHashKey
|
||||
{
|
||||
public:
|
||||
|
@ -68,6 +79,29 @@ public:
|
|||
nsRefPtr<nsDOMStorageItem> mItem;
|
||||
};
|
||||
|
||||
class nsDOMStorageManager : public nsIObserver
|
||||
{
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIObserver
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
void AddToStoragesHash(nsDOMStorage* aStorage);
|
||||
void RemoveFromStoragesHash(nsDOMStorage* aStorage);
|
||||
|
||||
nsresult ClearAllStorages();
|
||||
|
||||
static nsresult Initialize();
|
||||
|
||||
static nsDOMStorageManager* gStorageManager;
|
||||
|
||||
protected:
|
||||
|
||||
nsTHashtable<nsDOMStorageEntry> mStorages;
|
||||
};
|
||||
|
||||
class nsDOMStorage : public nsIDOMStorage,
|
||||
public nsPIDOMStorage
|
||||
{
|
||||
|
@ -117,9 +151,14 @@ public:
|
|||
nsresult
|
||||
SetSecure(const nsAString& aKey, PRBool aSecure);
|
||||
|
||||
// clear all values from the store
|
||||
void ClearAll();
|
||||
|
||||
protected:
|
||||
|
||||
nsresult InitDB();
|
||||
friend class nsDOMStorageManager;
|
||||
|
||||
static nsresult InitDB();
|
||||
|
||||
// cache the keys from the database for faster lookup
|
||||
nsresult CacheKeysFromDB();
|
||||
|
|
|
@ -130,6 +130,12 @@ nsDOMStorageDB::Init()
|
|||
"WHERE domain = ?1 "
|
||||
"AND key = ?2"),
|
||||
getter_AddRefs(mRemoveKeyStatement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// remove all keys
|
||||
rv = mConnection->CreateStatement(
|
||||
NS_LITERAL_CSTRING("DELETE FROM moz_webappsstore"),
|
||||
getter_AddRefs(mRemoveAllStatement));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -306,3 +312,10 @@ nsDOMStorageDB::RemoveKey(const nsAString& aDomain,
|
|||
|
||||
return mRemoveKeyStatement->Execute();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMStorageDB::RemoveAll()
|
||||
{
|
||||
mozStorageStatementScoper scope(mRemoveAllStatement);
|
||||
return mRemoveAllStatement->Execute();
|
||||
}
|
||||
|
|
|
@ -98,6 +98,12 @@ public:
|
|||
RemoveKey(const nsAString& aDomain,
|
||||
const nsAString& aKey);
|
||||
|
||||
/**
|
||||
* Removes all keys from storage. Used when clearing storage.
|
||||
*/
|
||||
nsresult
|
||||
RemoveAll();
|
||||
|
||||
protected:
|
||||
|
||||
nsCOMPtr<mozIStorageConnection> mConnection;
|
||||
|
@ -108,6 +114,7 @@ protected:
|
|||
nsCOMPtr<mozIStorageStatement> mUpdateKeyStatement;
|
||||
nsCOMPtr<mozIStorageStatement> mSetSecureStatement;
|
||||
nsCOMPtr<mozIStorageStatement> mRemoveKeyStatement;
|
||||
nsCOMPtr<mozIStorageStatement> mRemoveAllStatement;
|
||||
};
|
||||
|
||||
#endif /* nsDOMStorageDB_h___ */
|
||||
|
|
|
@ -77,6 +77,7 @@
|
|||
#include "nsXBLAtoms.h"
|
||||
#include "nsXBLWindowKeyHandler.h"
|
||||
#include "txXSLTProcessor.h"
|
||||
#include "nsDOMStorage.h"
|
||||
|
||||
#ifdef MOZ_XUL
|
||||
#include "nsXULContentUtils.h"
|
||||
|
@ -178,6 +179,12 @@ nsLayoutStatics::Initialize()
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
rv = nsDOMStorageManager::Initialize();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("Could not initialize nsDOMStorageManager");
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче