зеркало из https://github.com/mozilla/gecko-dev.git
switch cookies over to mozStorage. b=230933, r=sdwilsh, sr=mconnor.
remove nsInt64 usage from cookies, b=384225, r+sr=biesi.
This commit is contained in:
Родитель
b631a0ec0d
Коммит
5493e24575
|
@ -87,11 +87,6 @@ static const char kCookiesAskPermission[] = "network.cookie.warnAboutCookies";
|
|||
|
||||
static const char kPermissionType[] = "cookie";
|
||||
|
||||
// XXX these casts and constructs are horrible, but our nsInt64/nsTime
|
||||
// classes are lacking so we need them for now. see bug 198694.
|
||||
#define USEC_PER_SEC (nsInt64(1000000))
|
||||
#define NOW_IN_SECONDS (nsInt64(PR_Now()) / USEC_PER_SEC)
|
||||
|
||||
#ifdef MOZ_MAIL_NEWS
|
||||
// returns PR_TRUE if URI appears to be the URI of a mailnews protocol
|
||||
static PRBool
|
||||
|
@ -166,7 +161,7 @@ void
|
|||
nsCookiePermission::PrefChanged(nsIPrefBranch *aPrefBranch,
|
||||
const char *aPref)
|
||||
{
|
||||
PRBool val;
|
||||
PRInt32 val;
|
||||
|
||||
#define PREF_CHANGED(_P) (!aPref || !strcmp(aPref, _P))
|
||||
|
||||
|
@ -312,8 +307,8 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
|
|||
}
|
||||
|
||||
// declare this here since it'll be used in all of the remaining cases
|
||||
nsInt64 currentTime = NOW_IN_SECONDS;
|
||||
nsInt64 delta = nsInt64(*aExpiry) - currentTime;
|
||||
PRInt64 currentTime = PR_Now() / PR_USEC_PER_SEC;
|
||||
PRInt64 delta = *aExpiry - currentTime;
|
||||
|
||||
// check whether the user wants to be prompted
|
||||
if (mCookiesLifetimePolicy == ASK_BEFORE_ACCEPT) {
|
||||
|
@ -377,7 +372,7 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
|
|||
// check if the cookie we're trying to set is already expired, and return;
|
||||
// but only if there's no previous cookie, because then we need to delete the previous
|
||||
// cookie. we need this check to avoid prompting the user for already-expired cookies.
|
||||
if (!foundCookie && !*aIsSession && delta <= nsInt64(0)) {
|
||||
if (!foundCookie && !*aIsSession && delta <= 0) {
|
||||
// the cookie has already expired. accept it, and let the backend figure
|
||||
// out it's expired, so that we get correct logging & notifications.
|
||||
*aResult = PR_TRUE;
|
||||
|
@ -411,7 +406,7 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
|
|||
} else {
|
||||
// we're not prompting, so we must be limiting the lifetime somehow
|
||||
// if it's a session cookie, we do nothing
|
||||
if (!*aIsSession && delta > nsInt64(0)) {
|
||||
if (!*aIsSession && delta > 0) {
|
||||
if (mCookiesLifetimePolicy == ACCEPT_SESSION) {
|
||||
// limit lifetime to session
|
||||
*aIsSession = PR_TRUE;
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include "nsIPermissionManager.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsInt64.h"
|
||||
#include "prlong.h"
|
||||
|
||||
class nsIPrefBranch;
|
||||
|
@ -71,7 +70,7 @@ public:
|
|||
private:
|
||||
nsCOMPtr<nsIPermissionManager> mPermMgr;
|
||||
|
||||
nsInt64 mCookiesLifetimeSec; // lifetime limit specified in seconds
|
||||
PRInt64 mCookiesLifetimeSec; // lifetime limit specified in seconds
|
||||
PRUint8 mCookiesLifetimePolicy; // pref for how long cookies are stored
|
||||
PRPackedBool mCookiesAlwaysAcceptSession; // don't prompt for session cookies
|
||||
#ifdef MOZ_MAIL_NEWS
|
||||
|
|
|
@ -83,7 +83,11 @@ interface nsICookie : nsISupports {
|
|||
readonly attribute boolean isSecure;
|
||||
|
||||
/**
|
||||
* expiration time (local timezone) expressed as number of seconds since Jan 1, 1970
|
||||
* @DEPRECATED - use nsICookie2.expiry and nsICookie2.isSession instead.
|
||||
*
|
||||
* expiration time in seconds since midnight (00:00:00), January 1, 1970 UTC.
|
||||
* expires = 0 represents a session cookie.
|
||||
* expires = 1 represents an expiration time earlier than Jan 1, 1970.
|
||||
*/
|
||||
readonly attribute PRUint64 expires;
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ REQUIRES = \
|
|||
xpcom \
|
||||
string \
|
||||
pref \
|
||||
storage \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
|
|
@ -75,18 +75,21 @@ StrBlockCopy(const nsACString &aSource1,
|
|||
* creation helper
|
||||
******************************************************************************/
|
||||
|
||||
// This is a counter that is incremented each time we allocate a new nsCookie.
|
||||
// The value of the counter is stored with each nsCookie so that we can sort
|
||||
// cookies by creation time (within the current browser session).
|
||||
static PRUint32 gLastCreationTime;
|
||||
// This is a counter that keeps track of the last used creation id, each time we
|
||||
// create a new nsCookie. The creation id is nominally the time (in microseconds)
|
||||
// the cookie was created. This id also corresponds to the row id used in the
|
||||
// sqlite database, which must be unique. However, since it's possible two cookies
|
||||
// may be created at the same time, or the system clock isn't monotonic, we must
|
||||
// check each id to enforce monotonicity.
|
||||
static PRInt64 gLastCreationID;
|
||||
|
||||
nsCookie *
|
||||
nsCookie::Create(const nsACString &aName,
|
||||
const nsACString &aValue,
|
||||
const nsACString &aHost,
|
||||
const nsACString &aPath,
|
||||
nsInt64 aExpiry,
|
||||
nsInt64 aLastAccessed,
|
||||
PRInt64 aExpiry,
|
||||
PRInt64 aCreationID,
|
||||
PRBool aIsSession,
|
||||
PRBool aIsSecure,
|
||||
PRBool aIsHttpOnly,
|
||||
|
@ -109,9 +112,16 @@ nsCookie::Create(const nsACString &aName,
|
|||
StrBlockCopy(aName, aValue, aHost, aPath,
|
||||
name, value, host, path, end);
|
||||
|
||||
// check if the creation id given to us is greater than the running maximum
|
||||
// (it should always be monotonically increasing). if it's not, make up our own.
|
||||
if (aCreationID > gLastCreationID)
|
||||
gLastCreationID = aCreationID;
|
||||
else
|
||||
aCreationID = ++gLastCreationID;
|
||||
|
||||
// construct the cookie. placement new, oh yeah!
|
||||
return new (place) nsCookie(name, value, host, path, end,
|
||||
aExpiry, aLastAccessed, ++gLastCreationTime,
|
||||
aExpiry, aCreationID,
|
||||
aIsSession, aIsSecure, aIsHttpOnly,
|
||||
aStatus, aPolicy);
|
||||
}
|
||||
|
@ -143,7 +153,7 @@ nsCookie::GetExpires(PRUint64 *aExpires)
|
|||
if (IsSession()) {
|
||||
*aExpires = 0;
|
||||
} else {
|
||||
*aExpires = Expiry() > nsInt64(0) ? PRInt64(Expiry()) : 1;
|
||||
*aExpires = Expiry() > 0 ? Expiry() : 1;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include "nsICookie.h"
|
||||
#include "nsICookie2.h"
|
||||
#include "nsString.h"
|
||||
#include "nsInt64.h"
|
||||
|
||||
/**
|
||||
* The nsCookie class is the main cookie storage medium for use within cookie
|
||||
|
@ -75,9 +74,8 @@ class nsCookie : public nsICookie2
|
|||
const char *aHost,
|
||||
const char *aPath,
|
||||
const char *aEnd,
|
||||
nsInt64 aExpiry,
|
||||
nsInt64 aLastAccessed,
|
||||
PRUint32 aCreationTime,
|
||||
PRInt64 aExpiry,
|
||||
PRInt64 aCreationID,
|
||||
PRBool aIsSession,
|
||||
PRBool aIsSecure,
|
||||
PRBool aIsHttpOnly,
|
||||
|
@ -90,8 +88,7 @@ class nsCookie : public nsICookie2
|
|||
, mPath(aPath)
|
||||
, mEnd(aEnd)
|
||||
, mExpiry(aExpiry)
|
||||
, mLastAccessed(aLastAccessed)
|
||||
, mCreationTime(aCreationTime)
|
||||
, mCreationID(aCreationID)
|
||||
, mRefCnt(0)
|
||||
, mIsSession(aIsSession != PR_FALSE)
|
||||
, mIsSecure(aIsSecure != PR_FALSE)
|
||||
|
@ -108,8 +105,8 @@ class nsCookie : public nsICookie2
|
|||
const nsACString &aValue,
|
||||
const nsACString &aHost,
|
||||
const nsACString &aPath,
|
||||
nsInt64 aExpiry,
|
||||
nsInt64 aLastAccessed,
|
||||
PRInt64 aExpiry,
|
||||
PRInt64 aCreationID,
|
||||
PRBool aIsSession,
|
||||
PRBool aIsSecure,
|
||||
PRBool aIsHttpOnly,
|
||||
|
@ -124,9 +121,10 @@ class nsCookie : public nsICookie2
|
|||
inline const nsDependentCString Host() const { return nsDependentCString(mHost, mPath - 1); }
|
||||
inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mPath - 1); }
|
||||
inline const nsDependentCString Path() const { return nsDependentCString(mPath, mEnd); }
|
||||
inline nsInt64 Expiry() const { return mExpiry; }
|
||||
inline nsInt64 LastAccessed() const { return mLastAccessed; }
|
||||
inline PRUint32 CreationTime() const { return mCreationTime; }
|
||||
inline PRInt64 Expiry() const { return mExpiry; }
|
||||
inline PRInt64 CreationID() const { return mCreationID; }
|
||||
// cookie creation time, in seconds
|
||||
inline PRInt64 CreationTime() const { return mCreationID / PR_USEC_PER_SEC; }
|
||||
inline PRBool IsSession() const { return mIsSession; }
|
||||
inline PRBool IsDomain() const { return *mHost == '.'; }
|
||||
inline PRBool IsSecure() const { return mIsSecure; }
|
||||
|
@ -135,10 +133,11 @@ class nsCookie : public nsICookie2
|
|||
inline nsCookiePolicy Policy() const { return mPolicy; }
|
||||
|
||||
// setters
|
||||
inline void SetLastAccessed(nsInt64 aLastAccessed) { mLastAccessed = aLastAccessed; }
|
||||
inline void SetExpiry(PRInt64 aExpiry) { mExpiry = aExpiry; }
|
||||
inline void SetIsSession(PRBool aIsSession) { mIsSession = aIsSession; }
|
||||
inline void SetCreationTime(PRUint32 aCT) { mCreationTime = aCT; }
|
||||
inline void SetExpiry(PRInt64 aExpiry) { mExpiry = aExpiry; }
|
||||
inline void SetIsSession(PRBool aIsSession) { mIsSession = aIsSession; }
|
||||
// set the creation id manually, overriding the monotonicity checks in Create().
|
||||
// use with caution!
|
||||
inline void SetCreationID(PRInt64 aID) { mCreationID = aID; }
|
||||
|
||||
// linked list management helper
|
||||
inline nsCookie*& Next() { return mNext; }
|
||||
|
@ -156,9 +155,10 @@ class nsCookie : public nsICookie2
|
|||
const char *mHost;
|
||||
const char *mPath;
|
||||
const char *mEnd;
|
||||
nsInt64 mExpiry;
|
||||
nsInt64 mLastAccessed;
|
||||
PRUint32 mCreationTime;
|
||||
PRInt64 mExpiry;
|
||||
// creation id is unique for each cookie and approximately represents the cookie
|
||||
// creation time, in microseconds.
|
||||
PRInt64 mCreationID;
|
||||
PRUint32 mRefCnt : 16;
|
||||
PRUint32 mIsSession : 1;
|
||||
PRUint32 mIsSecure : 1;
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -50,8 +50,6 @@
|
|||
#include "nsString.h"
|
||||
#include "nsTHashtable.h"
|
||||
|
||||
#include "nsInt64.h"
|
||||
|
||||
struct nsCookieAttributes;
|
||||
struct nsListIter;
|
||||
struct nsEnumerationData;
|
||||
|
@ -65,8 +63,8 @@ class nsIPrefBranch;
|
|||
class nsIObserverService;
|
||||
class nsIURI;
|
||||
class nsIChannel;
|
||||
class nsITimer;
|
||||
class nsIFile;
|
||||
class mozIStorageConnection;
|
||||
class mozIStorageStatement;
|
||||
|
||||
// hash entry class
|
||||
class nsCookieEntry : public PLDHashEntryHdr
|
||||
|
@ -168,15 +166,17 @@ class nsCookieService : public nsICookieServiceInternal
|
|||
|
||||
protected:
|
||||
void PrefChanged(nsIPrefBranch *aPrefBranch);
|
||||
nsresult InitDB();
|
||||
nsresult CreateTable();
|
||||
nsresult ImportCookies();
|
||||
nsresult Read();
|
||||
nsresult Write();
|
||||
void GetCookieList(nsIURI *aHostURI, nsIURI *aFirstURI, nsIChannel *aChannel, const nsACString *aName, PRBool isHttpBound, nsAutoVoidArray &aResult);
|
||||
char* CookieStringFromArray(const nsAutoVoidArray& aCookieList, nsIURI *aHostURI);
|
||||
PRBool SetCookieInternal(nsIURI *aHostURI, nsIChannel *aChannel, nsDependentCString &aCookieHeader, nsInt64 aServerTime, nsCookieStatus aStatus, nsCookiePolicy aPolicy);
|
||||
PRBool SetCookieInternal(nsIURI *aHostURI, nsIChannel *aChannel, nsDependentCString &aCookieHeader, PRInt64 aServerTime, nsCookieStatus aStatus, nsCookiePolicy aPolicy);
|
||||
void CheckAndAdd(nsIURI *aHostURI, nsIChannel *aChannel, nsCookieAttributes &aAttributes, nsCookieStatus aStatus, nsCookiePolicy aPolicy, const nsAFlatCString &aCookieHeader);
|
||||
void AddInternal(nsCookie *aCookie, nsInt64 aCurrentTime, nsIURI *aHostURI, const char *aCookieHeader);
|
||||
void AddInternal(nsCookie *aCookie, PRInt64 aCurrentTime, nsIURI *aHostURI, const char *aCookieHeader);
|
||||
void RemoveCookieFromList(nsListIter &aIter);
|
||||
PRBool AddCookieToList(nsCookie *aCookie);
|
||||
PRBool AddCookieToList(nsCookie *aCookie, PRBool aWriteToDB = PR_TRUE);
|
||||
static PRBool GetTokenValue(nsASingleFragmentCString::const_char_iterator &aIter, nsASingleFragmentCString::const_char_iterator &aEndIter, nsDependentCSubstring &aTokenString, nsDependentCSubstring &aTokenValue, PRBool &aEqualsFound);
|
||||
static PRBool ParseAttributes(nsDependentCString &aCookieHeader, nsCookieAttributes &aCookie);
|
||||
static PRBool IsIPAddress(const nsAFlatCString &aHost);
|
||||
|
@ -185,32 +185,27 @@ class nsCookieService : public nsICookieServiceInternal
|
|||
nsCookieStatus CheckPrefs(nsIURI *aHostURI, nsIURI *aFirstURI, nsIChannel *aChannel, const char *aCookieHeader, nsCookiePolicy &aPolicy);
|
||||
static PRBool CheckDomain(nsCookieAttributes &aCookie, nsIURI *aHostURI);
|
||||
static PRBool CheckPath(nsCookieAttributes &aCookie, nsIURI *aHostURI);
|
||||
static PRBool GetExpiry(nsCookieAttributes &aCookie, nsInt64 aServerTime, nsInt64 aCurrentTime, nsCookieStatus aStatus);
|
||||
static PRBool GetExpiry(nsCookieAttributes &aCookie, PRInt64 aServerTime, PRInt64 aCurrentTime, nsCookieStatus aStatus);
|
||||
void RemoveAllFromMemory();
|
||||
void RemoveExpiredCookies(nsInt64 aCurrentTime);
|
||||
void RemoveExpiredCookies(PRInt64 aCurrentTime);
|
||||
PRBool FindCookie(const nsAFlatCString &aHost, const nsAFlatCString &aName, const nsAFlatCString &aPath, nsListIter &aIter);
|
||||
void FindOldestCookie(nsEnumerationData &aData);
|
||||
PRUint32 CountCookiesFromHostInternal(const nsACString &aHost, nsEnumerationData &aData);
|
||||
void NotifyRejected(nsIURI *aHostURI);
|
||||
void NotifyChanged(nsICookie2 *aCookie, const PRUnichar *aData);
|
||||
|
||||
// Use LazyWrite to save the cookies file on a timer. It will write
|
||||
// the file only once if repeatedly hammered quickly.
|
||||
void LazyWrite();
|
||||
static void DoLazyWrite(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
protected:
|
||||
// cached members
|
||||
nsCOMPtr<nsIFile> mCookieFile;
|
||||
nsCOMPtr<mozIStorageConnection> mDBConn;
|
||||
nsCOMPtr<mozIStorageStatement> mStmtInsert;
|
||||
nsCOMPtr<mozIStorageStatement> mStmtDelete;
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
nsCOMPtr<nsICookieConsent> mP3PService;
|
||||
nsCOMPtr<nsICookiePermission> mPermissionService;
|
||||
|
||||
// impl members
|
||||
nsCOMPtr<nsITimer> mWriteTimer;
|
||||
nsTHashtable<nsCookieEntry> mHostTable;
|
||||
PRUint32 mCookieCount;
|
||||
PRPackedBool mCookieChanged;
|
||||
PRPackedBool mCookieIconVisible;
|
||||
|
||||
// cached prefs
|
||||
|
|
Загрузка…
Ссылка в новой задаче