increase the allowable number of total cookies and number of cookies per host, and add prefs so embeddors can tune these values.

b=213963, r=mconnor, sr=darin
This commit is contained in:
dwitte%stanford.edu 2004-04-24 04:17:31 +00:00
Родитель 5e66901da1
Коммит 3d9f621775
2 изменённых файлов: 30 добавлений и 12 удалений

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

@ -80,9 +80,14 @@ static const char kCookieFileName[] = "cookies.txt";
static const PRUint32 kLazyWriteTimeout = 5000; //msec
static const PRUint32 kMaxNumberOfCookies = 300;
static const PRUint32 kMaxCookiesPerHost = 20;
static const PRUint32 kMaxBytesPerCookie = 4096;
#undef LIMIT
#define LIMIT(x, low, high, default) ((x) >= (low) && (x) <= (high) ? (x) : (default))
// default limits for the cookie list. these can be tuned by the
// network.cookie.maxNumber and network.cookie.maxPerHost prefs respectively.
static const PRUint32 kMaxNumberOfCookies = 1000;
static const PRUint32 kMaxCookiesPerHost = 50;
static const PRUint32 kMaxBytesPerCookie = 4096;
// this constant augments those defined on nsICookie, and indicates
// the cookie should be rejected because of an error (rather than
@ -103,7 +108,9 @@ static const PRUint32 BEHAVIOR_REJECT = 2;
static const PRUint32 BEHAVIOR_P3P = 3;
// pref string constants
static const char kCookiesPermissions[] = "network.cookie.cookieBehavior";
static const char kPrefCookiesPermissions[] = "network.cookie.cookieBehavior";
static const char kPrefMaxNumberOfCookies[] = "network.cookie.maxNumber";
static const char kPrefMaxCookiesPerHost[] = "network.cookie.maxPerHost";
// struct for temporarily storing cookie attributes during header parsing
struct nsCookieAttributes
@ -368,6 +375,8 @@ nsCookieService::nsCookieService()
, mCookieChanged(PR_FALSE)
, mCookieIconVisible(PR_FALSE)
, mCookiesPermissions(BEHAVIOR_ACCEPT)
, mMaxNumberOfCookies(kMaxNumberOfCookies)
, mMaxCookiesPerHost(kMaxCookiesPerHost)
{
}
@ -381,7 +390,9 @@ nsCookieService::Init()
// init our pref and observer
nsCOMPtr<nsIPrefBranchInternal> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefBranch) {
prefBranch->AddObserver(kCookiesPermissions, this, PR_TRUE);
prefBranch->AddObserver(kPrefCookiesPermissions, this, PR_TRUE);
prefBranch->AddObserver(kPrefMaxNumberOfCookies, this, PR_TRUE);
prefBranch->AddObserver(kPrefMaxCookiesPerHost, this, PR_TRUE);
PrefChanged(prefBranch);
}
@ -572,7 +583,7 @@ nsCookieService::GetCookieStringFromHttp(nsIURI *aHostURI,
continue;
}
// check if the cookie has expired
// check if the cookie has expired
if (!cookie->IsSession() && cookie->Expiry() <= currentTime) {
continue;
}
@ -778,9 +789,14 @@ void
nsCookieService::PrefChanged(nsIPrefBranch *aPrefBranch)
{
PRInt32 val;
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookiesPermissions, &val)) &&
val >= 0 && val <= 3)
mCookiesPermissions = val;
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kPrefCookiesPermissions, &val)))
mCookiesPermissions = LIMIT(val, 0, 3, 0);
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kPrefMaxNumberOfCookies, &val)))
mMaxNumberOfCookies = LIMIT(val, 0, 0xFFFF, 0xFFFF);
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kPrefMaxCookiesPerHost, &val)))
mMaxCookiesPerHost = LIMIT(val, 0, 0xFFFF, 0xFFFF);
}
/******************************************************************************
@ -1224,17 +1240,17 @@ nsCookieService::AddInternal(nsCookie *aCookie,
// check if we have to delete an old cookie.
nsEnumerationData data(aCurrentTime, LL_MAXINT);
if (CountCookiesFromHost(aCookie, data) >= kMaxCookiesPerHost) {
if (CountCookiesFromHost(aCookie, data) >= mMaxCookiesPerHost) {
// remove the oldest cookie from host
oldCookie = data.iter.current;
RemoveCookieFromList(data.iter);
} else if (mCookieCount >= kMaxNumberOfCookies) {
} else if (mCookieCount >= mMaxNumberOfCookies) {
// try to make room, by removing expired cookies
RemoveExpiredCookies(aCurrentTime);
// check if we still have to get rid of something
if (mCookieCount >= kMaxNumberOfCookies) {
if (mCookieCount >= mMaxNumberOfCookies) {
// find the position of the oldest cookie, and remove it
data.oldestTime = LL_MAXINT;
FindOldestCookie(data);

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

@ -212,6 +212,8 @@ class nsCookieService : public nsICookieService
// cached prefs
PRUint8 mCookiesPermissions; // BEHAVIOR_{ACCEPT, REJECTFOREIGN, REJECT, P3P}
PRUint16 mMaxNumberOfCookies;
PRUint16 mMaxCookiesPerHost;
// private static member, used to cache a ptr to nsCookieService,
// so we can make nsCookieService a singleton xpcom object.