Bug 397416: Raise globalStorage quota for domains with the offline-app permission. r=enndeakin, sr=dveditz, blocking1.9=sicking

This commit is contained in:
dcamp%mozilla.com 2008-01-23 02:54:06 +00:00
Родитель c0f43440a7
Коммит 2200f581c7
6 изменённых файлов: 98 добавлений и 6 удалений

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

@ -60,6 +60,7 @@ REQUIRES = xpcom \
unicharutil \ unicharutil \
widget \ widget \
xpconnect \ xpconnect \
prefetch \
$(NULL) $(NULL)
ifdef MOZ_STORAGE ifdef MOZ_STORAGE

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

@ -54,18 +54,26 @@
#include "nsICookiePermission.h" #include "nsICookiePermission.h"
#include "nsIPermissionManager.h" #include "nsIPermissionManager.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsIJSContextStack.h"
static const PRUint32 ASK_BEFORE_ACCEPT = 1; static const PRUint32 ASK_BEFORE_ACCEPT = 1;
static const PRUint32 ACCEPT_SESSION = 2; static const PRUint32 ACCEPT_SESSION = 2;
static const PRUint32 BEHAVIOR_REJECT = 2; static const PRUint32 BEHAVIOR_REJECT = 2;
static const PRUint32 DEFAULT_QUOTA = 5 * 1024; static const PRUint32 DEFAULT_QUOTA = 5 * 1024;
// Be generous with offline apps by default...
static const PRUint32 DEFAULT_OFFLINE_APP_QUOTA = 200 * 1024;
// ... but warn if it goes over this amount
static const PRUint32 DEFAULT_OFFLINE_WARN_QUOTA = 50 * 1024;
static const char kPermissionType[] = "cookie"; static const char kPermissionType[] = "cookie";
static const char kStorageEnabled[] = "dom.storage.enabled"; static const char kStorageEnabled[] = "dom.storage.enabled";
static const char kDefaultQuota[] = "dom.storage.default_quota"; static const char kDefaultQuota[] = "dom.storage.default_quota";
static const char kCookiesBehavior[] = "network.cookie.cookieBehavior"; static const char kCookiesBehavior[] = "network.cookie.cookieBehavior";
static const char kCookiesLifetimePolicy[] = "network.cookie.lifetimePolicy"; static const char kCookiesLifetimePolicy[] = "network.cookie.lifetimePolicy";
static const char kOfflineAppWarnQuota[] = "offline-apps.quota.warn";
static const char kOfflineAppQuota[] = "offline-apps.quota.max";
// //
// Helper that tells us whether the caller is secure or not. // Helper that tells us whether the caller is secure or not.
@ -104,11 +112,44 @@ IsCallerSecure()
return NS_SUCCEEDED(rv) && isHttps; return NS_SUCCEEDED(rv) && isHttps;
} }
static PRInt32
GetQuota(const nsAString &domain) // 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.
static void
GetQuota(const nsAString &aDomain, PRInt32 *aQuota, PRInt32 *aWarnQuota)
{ {
// Fake a URI for the permission manager
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_STRING("http://") + aDomain);
if (uri) {
nsCOMPtr<nsIPermissionManager> permissionManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
PRUint32 perm;
if (permissionManager &&
NS_SUCCEEDED(permissionManager->TestExactPermission(uri, "offline-app", &perm)) &&
perm != nsIPermissionManager::UNKNOWN_ACTION &&
perm != nsIPermissionManager::DENY_ACTION) {
// This is an offline app, give more space by default.
*aQuota = ((PRInt32)nsContentUtils::GetIntPref(kOfflineAppQuota,
DEFAULT_OFFLINE_WARN_QUOTA * 1024));
if (perm == nsIOfflineCacheUpdateService::ALLOW_NO_WARN) {
*aWarnQuota = -1;
} else {
*aWarnQuota = ((PRInt32)nsContentUtils::GetIntPref(kOfflineAppWarnQuota,
DEFAULT_OFFLINE_WARN_QUOTA) * 1024);
}
return;
}
}
// FIXME: per-domain quotas? // FIXME: per-domain quotas?
return ((PRInt32)nsContentUtils::GetIntPref(kDefaultQuota, DEFAULT_QUOTA) * 1024); *aQuota = ((PRInt32)nsContentUtils::GetIntPref(kDefaultQuota,
DEFAULT_QUOTA) * 1024);
*aWarnQuota = -1;
} }
nsSessionStorageEntry::nsSessionStorageEntry(KeyTypePointer aStr) nsSessionStorageEntry::nsSessionStorageEntry(KeyTypePointer aStr)
@ -771,12 +812,37 @@ nsDOMStorage::SetDBValue(const nsAString& aKey,
currentDomain = mDomain; currentDomain = mDomain;
} }
PRInt32 quota;
PRInt32 warnQuota;
GetQuota(currentDomain, &quota, &warnQuota);
PRInt32 usage;
rv = gStorageDB->SetKey(mDomain, aKey, aValue, aSecure, rv = gStorageDB->SetKey(mDomain, aKey, aValue, aSecure,
currentDomain, GetQuota(currentDomain)); currentDomain, quota, &usage);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
mItemsCached = PR_FALSE; mItemsCached = PR_FALSE;
if (warnQuota >= 0 && usage > warnQuota) {
// try to include the window that exceeded the warn quota
nsCOMPtr<nsIDOMWindow> window;
JSContext *cx;
nsCOMPtr<nsIJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (stack && NS_SUCCEEDED(stack->Peek(&cx)) && cx) {
nsCOMPtr<nsIScriptContext> scriptContext;
scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext) {
window = do_QueryInterface(scriptContext->GetGlobalObject());
}
}
nsCOMPtr<nsIObserverService> os =
do_GetService("@mozilla.org/observer-service;1");
os->NotifyObservers(window, "dom-storage-warn-quota-exceeded",
currentDomain.get());
}
BroadcastChangeNotification(); BroadcastChangeNotification();
#endif #endif

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

@ -271,7 +271,8 @@ nsDOMStorageDB::SetKey(const nsAString& aDomain,
const nsAString& aValue, const nsAString& aValue,
PRBool aSecure, PRBool aSecure,
const nsAString& aOwner, const nsAString& aOwner,
PRInt32 aQuota) PRInt32 aQuota,
PRInt32 *aNewUsage)
{ {
mozStorageStatementScoper scope(mGetKeyValueStatement); mozStorageStatementScoper scope(mGetKeyValueStatement);
@ -362,6 +363,8 @@ nsDOMStorageDB::SetKey(const nsAString& aDomain,
mCachedUsage = usage; mCachedUsage = usage;
} }
*aNewUsage = usage;
return NS_OK; return NS_OK;
} }

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

@ -85,7 +85,8 @@ public:
const nsAString& aValue, const nsAString& aValue,
PRBool aSecure, PRBool aSecure,
const nsAString& aOwner, const nsAString& aOwner,
PRInt32 aQuota); PRInt32 aQuota,
PRInt32* aNewUsage);
/** /**
* Set the secure flag for a key in storage. Does nothing if the key was * Set the secure flag for a key in storage. Does nothing if the key was

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

@ -71,6 +71,14 @@ pref("browser.cache.offline.enable", true);
// offline cache capacity in kilobytes // offline cache capacity in kilobytes
pref("browser.cache.offline.capacity", 10240); pref("browser.cache.offline.capacity", 10240);
// offline apps should be limited to this much data in global storage
// (in kilobytes)
pref("offline-apps.quota.max", 204800);
// the user should be warned if offline app disk usage exceeds this amount
// (in kilobytes)
pref("offline-apps.quota.warn", 51200);
// Fastback caching - if this pref is negative, then we calculate the number // Fastback caching - if this pref is negative, then we calculate the number
// of content viewers to cache based on the amount of available memory. // of content viewers to cache based on the amount of available memory.
pref("browser.sessionhistory.max_total_viewers", -1); pref("browser.sessionhistory.max_total_viewers", -1);

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

@ -204,6 +204,19 @@ interface nsIOfflineCacheUpdate : nsISupports {
[scriptable, uuid(3abee04b-5bbb-4405-b659-35f780e38da0)] [scriptable, uuid(3abee04b-5bbb-4405-b659-35f780e38da0)]
interface nsIOfflineCacheUpdateService : nsISupports { interface nsIOfflineCacheUpdateService : nsISupports {
/**
* Constants for the offline-app permission.
*
* XXX: This isn't a great place for this, but it's really the only
* private offline-app-related interface
*/
/**
* Allow the domain to use offline APIs, and don't warn about excessive
* usage.
*/
const unsigned long ALLOW_NO_WARN = 3;
/** /**
* Access to the list of cache updates that have been scheduled. * Access to the list of cache updates that have been scheduled.
*/ */