let chrome check globalStorage usage for a domain. b=396249, r=enndeakin, sr=jst, a=jst

This commit is contained in:
dcamp@mozilla.com 2007-10-03 23:05:32 -07:00
Родитель 5d50624fde
Коммит 87b02e0c5b
8 изменённых файлов: 112 добавлений и 11 удалений

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

@ -52,6 +52,7 @@ EXPORTS = \
XPIDLSRCS = \
nsIDOMToString.idl \
nsIDOMStorageManager.idl \
$(NULL)
SDK_XPIDLSRCS = \

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

@ -0,0 +1,52 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
[scriptable, uuid(74dc93d1-8cdf-43b1-a52c-776dcb873475)]
interface nsIDOMStorageManager : nsISupports
{
/**
* Return the amount of disk space used by a domain. Usage is checked
* against the domain of the page that set the key (the owner domain), not
* the domain of the storage object.
*
* @param aOwnerDomain The domain to check.
* @returns the space usage of the domain, in bytes.
*/
long getUsage(in AString aOwnerDomain);
};

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

@ -131,7 +131,9 @@ nsSessionStorageEntry::~nsSessionStorageEntry()
nsDOMStorageManager* nsDOMStorageManager::gStorageManager;
NS_IMPL_ISUPPORTS1(nsDOMStorageManager, nsIObserver)
NS_IMPL_ISUPPORTS2(nsDOMStorageManager,
nsIDOMStorageManager,
nsIObserver)
//static
nsresult
@ -156,6 +158,16 @@ nsDOMStorageManager::Initialize()
return NS_OK;
}
//static
nsDOMStorageManager*
nsDOMStorageManager::GetInstance()
{
NS_ASSERTION(gStorageManager,
"nsDOMStorageManager::GetInstance() called before Initialize()");
NS_IF_ADDREF(gStorageManager);
return gStorageManager;
}
//static
void
nsDOMStorageManager::Shutdown()
@ -194,6 +206,16 @@ nsDOMStorageManager::Observe(nsISupports *aSubject,
return NS_OK;
}
NS_IMETHODIMP
nsDOMStorageManager::GetUsage(const nsAString& aDomain,
PRInt32 *aUsage)
{
nsresult rv = nsDOMStorage::InitDB();
NS_ENSURE_SUCCESS(rv, rv);
return nsDOMStorage::gStorageDB->GetUsage(aDomain, aUsage);
}
void
nsDOMStorageManager::AddToStoragesHash(nsDOMStorage* aStorage)
{

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

@ -51,6 +51,7 @@
#include "nsIDOMToString.h"
#include "nsDOMEvent.h"
#include "nsIDOMStorageEvent.h"
#include "nsIDOMStorageManager.h"
#ifdef MOZ_STORAGE
#include "nsDOMStorageDB.h"
@ -80,12 +81,16 @@ public:
nsRefPtr<nsDOMStorageItem> mItem;
};
class nsDOMStorageManager : public nsIObserver
class nsDOMStorageManager : public nsIDOMStorageManager
, public nsIObserver
{
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMStorageManager
NS_DECL_NSIDOMSTORAGEMANAGER
// nsIObserver
NS_DECL_NSIOBSERVER
@ -95,6 +100,7 @@ public:
nsresult ClearAllStorages();
static nsresult Initialize();
static nsDOMStorageManager* GetInstance();
static void Shutdown();
static nsDOMStorageManager* gStorageManager;

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

@ -271,12 +271,8 @@ nsDOMStorageDB::SetKey(const nsAString& aDomain,
PRInt32 usage = 0;
nsresult rv;
if (!aOwner.IsEmpty()) {
if (aOwner == mCachedOwner) {
usage = mCachedUsage;
} else {
rv = GetUsage(aOwner, &usage);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = GetUsage(aOwner, &usage);
NS_ENSURE_SUCCESS(rv, rv);
}
usage += aKey.Length() + aValue.Length();
@ -426,6 +422,11 @@ nsDOMStorageDB::RemoveAll()
nsresult
nsDOMStorageDB::GetUsage(const nsAString &aOwner, PRInt32 *aUsage)
{
if (aOwner == mCachedOwner) {
*aUsage = mCachedUsage;
return NS_OK;
}
mozStorageStatementScoper scope(mGetUsageStatement);
nsresult rv = mGetUsageStatement->BindStringParameter(0, aOwner);
@ -440,5 +441,13 @@ nsDOMStorageDB::GetUsage(const nsAString &aOwner, PRInt32 *aUsage)
return NS_OK;
}
return mGetUsageStatement->GetInt32(0, aUsage);
rv = mGetUsageStatement->GetInt32(0, aUsage);
NS_ENSURE_SUCCESS(rv, rv);
if (!aOwner.IsEmpty()) {
mCachedOwner = aOwner;
mCachedUsage = *aUsage;
}
return NS_OK;
}

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

@ -111,10 +111,10 @@ public:
nsresult
RemoveAll();
protected:
nsresult GetUsage(const nsAString &aOwner, PRInt32 *aUsage);
protected:
nsCOMPtr<mozIStorageConnection> mConnection;
nsCOMPtr<mozIStorageStatement> mGetAllKeysStatement;

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

@ -214,4 +214,8 @@
#define NS_DOMSTORAGE_CID \
{ 0x8b449142, 0x1eab, 0x4bfa, { 0x98, 0x30, 0xfa, 0xb6, 0xeb, 0xb0, 0x97, 0x74 } }
// {b88a4712-eb52-4c10-9b85-bf5894b510f0}
#define NS_DOMSTORAGEMANAGER_CID \
{ 0xb88a4712, 0xeb52, 0x4c10, { 0x9b, 0x85, 0xbf, 0x58, 0x94, 0xb5, 0x10, 0xf0 } }
#endif /* nsLayoutCID_h__ */

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

@ -283,6 +283,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(txNodeSetAdaptor, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXMLHttpRequest)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMParser)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDOMStorageManager,
nsDOMStorageManager::GetInstance)
//-----------------------------------------------------------------------------
@ -1307,6 +1309,11 @@ static const nsModuleComponentInfo gComponents[] = {
"@mozilla.org/dom/storage;1",
NS_NewDOMStorage },
{ "DOM Storage Manager",
NS_DOMSTORAGEMANAGER_CID,
"@mozilla.org/dom/storagemanager;1",
nsDOMStorageManagerConstructor },
{ "Text Editor",
NS_TEXTEDITOR_CID,
"@mozilla.org/editor/texteditor;1",