зеркало из https://github.com/mozilla/pjs.git
yet another cookie rewrite - up to part 3 this time.
- moves core cookie code into nsCookieService.{h,cpp}, and kills nsCookies & nsCookieManager - makes nsCookieService a singleton object that implements nsICookieManager also - improves mem efficiency of the nsCookie object, and removes unneeded conversions - adds an nsICookie2 interface to extend the sucky nsICookie. - fixes a few (unrelated) trivial things while I'm in there (use ->ASCII instead of ->UTF8, and remove some erroneous stuff in nsPermissionManager.h) cvs removal of nsCookies.{h,cpp} and nsCookieManager.{h,cpp} will follow; to find old blame info and logs for those files, look in attic. burn the witch! b=200632, r=alecf, sr=darin.
This commit is contained in:
Родитель
72e0408923
Коммит
d59e379438
|
@ -55,12 +55,10 @@ CPPSRCS = \
|
|||
nsModuleFactory.cpp \
|
||||
nsCookie.cpp \
|
||||
nsPermission.cpp \
|
||||
nsCookieManager.cpp \
|
||||
nsCookieService.cpp \
|
||||
nsImgManager.cpp \
|
||||
nsPermissionManager.cpp \
|
||||
nsPopupWindowManager.cpp \
|
||||
nsCookies.cpp \
|
||||
nsCookieHTTPNotify.cpp \
|
||||
nsCookiePromptService.cpp \
|
||||
nsCookiePermission.cpp \
|
||||
|
@ -72,6 +70,7 @@ SDK_XPIDLSRCS = \
|
|||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsICookie2.idl \
|
||||
nsICookieConsent.idl \
|
||||
nsIImgManager.idl \
|
||||
nsIPermissionManager.idl \
|
||||
|
@ -93,4 +92,3 @@ EXTRA_DSO_LDOPTS = \
|
|||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* Daniel Witte.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Daniel Witte (dwitte@stanford.edu)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -37,88 +37,110 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCookie.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// nsCookie Implementation
|
||||
/******************************************************************************
|
||||
* nsCookie:
|
||||
* string helper impl
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsCookie, nsICookie, nsISupportsWeakReference);
|
||||
|
||||
nsCookie::nsCookie()
|
||||
: cookieName(0),
|
||||
cookieValue(0),
|
||||
cookieIsDomain(PR_FALSE),
|
||||
cookieHost(0),
|
||||
cookiePath(0),
|
||||
cookieIsSecure(PR_FALSE)
|
||||
// allocate contiguous storage and copy aSource strings,
|
||||
// providing terminating nulls for each destination string.
|
||||
// XXX consider arena allocation here
|
||||
static inline void
|
||||
StrBlockCopy(const nsACString &aSource1,
|
||||
const nsACString &aSource2,
|
||||
const nsACString &aSource3,
|
||||
const nsACString &aSource4,
|
||||
char *&aDest1,
|
||||
char *&aDest2,
|
||||
char *&aDest3,
|
||||
char *&aDest4,
|
||||
char *&aDestEnd)
|
||||
{
|
||||
// find the required buffer size, adding 4 for the terminating nulls
|
||||
const PRUint32 totalLength = aSource1.Length() + aSource2.Length() + aSource3.Length() + aSource4.Length() + 4;
|
||||
|
||||
char *result = NS_STATIC_CAST(char*, nsMemory::Alloc(totalLength * sizeof(char)));
|
||||
NS_ASSERTION(result, "out of memory allocating for nsCookie!");
|
||||
|
||||
nsACString::const_iterator fromBegin, fromEnd;
|
||||
char *toBegin = result;
|
||||
|
||||
aDest1 = toBegin;
|
||||
*copy_string(aSource1.BeginReading(fromBegin), aSource1.EndReading(fromEnd), toBegin) = char(0);
|
||||
aDest2 = ++toBegin;
|
||||
*copy_string(aSource2.BeginReading(fromBegin), aSource2.EndReading(fromEnd), toBegin) = char(0);
|
||||
aDest3 = ++toBegin;
|
||||
*copy_string(aSource3.BeginReading(fromBegin), aSource3.EndReading(fromEnd), toBegin) = char(0);
|
||||
aDest4 = ++toBegin;
|
||||
*copy_string(aSource4.BeginReading(fromBegin), aSource4.EndReading(fromEnd), toBegin) = char(0);
|
||||
aDestEnd = toBegin;
|
||||
}
|
||||
|
||||
nsCookie::nsCookie
|
||||
(const nsACString &name,
|
||||
const nsACString &value,
|
||||
PRBool isDomain,
|
||||
const nsACString &host,
|
||||
const nsACString &path,
|
||||
PRBool isSecure,
|
||||
PRUint64 expires,
|
||||
nsCookieStatus status,
|
||||
nsCookiePolicy policy)
|
||||
: cookieName(name),
|
||||
cookieValue(value),
|
||||
cookieIsDomain(isDomain),
|
||||
cookieHost(host),
|
||||
cookiePath(path),
|
||||
cookieIsSecure(isSecure)
|
||||
/******************************************************************************
|
||||
* nsCookie:
|
||||
* ctor/dtor
|
||||
******************************************************************************/
|
||||
|
||||
nsCookie::nsCookie(const nsACString &aName,
|
||||
const nsACString &aValue,
|
||||
const nsACString &aHost,
|
||||
const nsACString &aPath,
|
||||
nsInt64 aExpiry,
|
||||
nsInt64 aLastAccessed,
|
||||
PRBool aIsSession,
|
||||
PRBool aIsDomain,
|
||||
PRBool aIsSecure,
|
||||
nsCookieStatus aStatus,
|
||||
nsCookiePolicy aPolicy)
|
||||
: mExpiry(aExpiry)
|
||||
, mLastAccessed(aLastAccessed)
|
||||
, mRefCnt(0)
|
||||
, mIsSession(aIsSession != PR_FALSE)
|
||||
, mIsDomain(aIsDomain != PR_FALSE)
|
||||
, mIsSecure(aIsSecure != PR_FALSE)
|
||||
, mStatus(aStatus)
|
||||
, mPolicy(aPolicy)
|
||||
{
|
||||
cookieExpires = expires;
|
||||
cookieStatus = status;
|
||||
cookiePolicy = policy;
|
||||
// allocate a new (contiguous) string, and assign string members
|
||||
StrBlockCopy(aName, aValue, aHost, aPath,
|
||||
mName, mValue, mHost, mPath, mEnd);
|
||||
}
|
||||
|
||||
nsCookie::~nsCookie(void) {
|
||||
nsCookie::~nsCookie()
|
||||
{
|
||||
if (mName)
|
||||
nsMemory::Free(mName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetName(nsACString& aName) {
|
||||
aName = cookieName;
|
||||
/******************************************************************************
|
||||
* nsCookie:
|
||||
* xpcom impl
|
||||
******************************************************************************/
|
||||
|
||||
// xpcom getters
|
||||
NS_IMETHODIMP nsCookie::GetName(nsACString &aName) { aName = Name(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetValue(nsACString &aValue) { aValue = Value(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetHost(nsACString &aHost) { aHost = Host(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetPath(nsACString &aPath) { aPath = Path(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetExpiry(PRInt64 *aExpiry) { *aExpiry = Expiry(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetIsSession(PRBool *aIsSession) { *aIsSession = IsSession(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetIsDomain(PRBool *aIsDomain) { *aIsDomain = IsDomain(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetIsSecure(PRBool *aIsSecure) { *aIsSecure = IsSecure(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetStatus(nsCookieStatus *aStatus) { *aStatus = Status(); return NS_OK; }
|
||||
NS_IMETHODIMP nsCookie::GetPolicy(nsCookiePolicy *aPolicy) { *aPolicy = Policy(); return NS_OK; }
|
||||
|
||||
// compatibility method, for use with the legacy nsICookie interface.
|
||||
// here, expires == 0 denotes a session cookie.
|
||||
NS_IMETHODIMP
|
||||
nsCookie::GetExpires(PRUint64 *aExpires)
|
||||
{
|
||||
if (IsSession()) {
|
||||
*aExpires = 0;
|
||||
} else {
|
||||
*aExpires = Expiry() > nsInt64(0) ? PRInt64(Expiry()) : 1;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetValue(nsACString& aValue) {
|
||||
aValue = cookieValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetIsDomain(PRBool *aIsDomain) {
|
||||
*aIsDomain = cookieIsDomain;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetHost(nsACString& aHost) {
|
||||
aHost = cookieHost;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetPath(nsACString& aPath) {
|
||||
aPath = cookiePath;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetIsSecure(PRBool *aIsSecure) {
|
||||
*aIsSecure = cookieIsSecure;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetExpires(PRUint64 *aExpires) {
|
||||
*aExpires = cookieExpires;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetStatus(nsCookieStatus *aStatus) {
|
||||
*aStatus = cookieStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCookie::GetPolicy(nsCookiePolicy *aPolicy) {
|
||||
*aPolicy = cookiePolicy;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMPL_ISUPPORTS2(nsCookie, nsICookie, nsICookie2)
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* Daniel Witte.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Daniel Witte (dwitte@stanford.edu)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -40,47 +40,100 @@
|
|||
#define nsCookie_h__
|
||||
|
||||
#include "nsICookie.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsICookie2.h"
|
||||
#include "nsString.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsInt64.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* The nsCookie class is the main cookie storage medium for use within cookie
|
||||
* code. It implements nsICookie2, which extends nsICookie, a frozen interface
|
||||
* for xpcom access of cookie objects.
|
||||
*/
|
||||
|
||||
class nsCookie : public nsICookie,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
/******************************************************************************
|
||||
* nsCookie:
|
||||
* implementation
|
||||
******************************************************************************/
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOOKIE
|
||||
class nsCookie : public nsICookie2
|
||||
{
|
||||
// this is required because we use a bitfield refcount member.
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
protected:
|
||||
NS_DECL_OWNINGTHREAD
|
||||
|
||||
nsCookie
|
||||
(const nsACString &name,
|
||||
const nsACString &value,
|
||||
PRBool isDomain,
|
||||
const nsACString &host,
|
||||
const nsACString &path,
|
||||
PRBool isSecure,
|
||||
PRUint64 expires,
|
||||
nsCookieStatus status,
|
||||
nsCookiePolicy policy
|
||||
);
|
||||
nsCookie();
|
||||
virtual ~nsCookie(void);
|
||||
|
||||
protected:
|
||||
nsCString cookieName;
|
||||
nsCString cookieValue;
|
||||
PRBool cookieIsDomain;
|
||||
nsCString cookieHost;
|
||||
nsCString cookiePath;
|
||||
PRBool cookieIsSecure;
|
||||
PRUint64 cookieExpires;
|
||||
nsCookieStatus cookieStatus;
|
||||
nsCookiePolicy cookiePolicy;
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_NSICOOKIE
|
||||
NS_DECL_NSICOOKIE2
|
||||
|
||||
// XXX the default ctor is required by nsModuleFactory.cpp,
|
||||
// because it registers nsCookie as a module with a constructor.
|
||||
// this probably shouldn't be happening. same for nsPermission.
|
||||
nsCookie()
|
||||
: mName(nsnull)
|
||||
, mRefCnt(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsCookie(const nsACString &aName,
|
||||
const nsACString &aValue,
|
||||
const nsACString &aHost,
|
||||
const nsACString &aPath,
|
||||
nsInt64 aExpiry,
|
||||
nsInt64 aLastAccessed,
|
||||
PRBool aIsSession,
|
||||
PRBool aIsDomain,
|
||||
PRBool aIsSecure,
|
||||
nsCookieStatus aStatus,
|
||||
nsCookiePolicy aPolicy);
|
||||
|
||||
virtual ~nsCookie();
|
||||
|
||||
// fast (inline, non-xpcom) getters
|
||||
inline const nsDependentCString Name() const { return nsDependentCString(mName, mValue - 1); }
|
||||
inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); }
|
||||
inline const nsDependentCString Host() const { return nsDependentCString(mHost, mPath - 1); }
|
||||
inline const nsDependentCString Path() const { return nsDependentCString(mPath, mEnd); }
|
||||
inline nsInt64 Expiry() const { NS_ASSERTION(!IsSession(), "can't get expiry time for a session cookie"); return mExpiry; }
|
||||
inline nsInt64 LastAccessed() const { return mLastAccessed; }
|
||||
inline PRBool IsSession() const { return mIsSession; }
|
||||
inline PRBool IsDomain() const { return mIsDomain; }
|
||||
inline PRBool IsSecure() const { return mIsSecure; }
|
||||
inline nsCookieStatus Status() const { return mStatus; }
|
||||
inline nsCookiePolicy Policy() const { return mPolicy; }
|
||||
|
||||
// setters on nsCookie only exist for SetLastAccessed().
|
||||
// except for this method, an nsCookie is immutable
|
||||
// and must be deleted & recreated if it needs to be changed.
|
||||
inline void SetLastAccessed(nsInt64 aLastAccessed) { mLastAccessed = aLastAccessed; }
|
||||
|
||||
protected:
|
||||
// member variables
|
||||
// we use char* ptrs to store the strings in a contiguous block,
|
||||
// so we save on the overhead of using nsCStrings. However, we
|
||||
// store a terminating null for each string, so we can hand them
|
||||
// out as nsAFlatCStrings.
|
||||
|
||||
// sizeof(nsCookie) = 44 bytes + Length(strings)
|
||||
char *mName;
|
||||
char *mValue;
|
||||
char *mHost;
|
||||
char *mPath;
|
||||
char *mEnd;
|
||||
nsInt64 mExpiry;
|
||||
nsInt64 mLastAccessed;
|
||||
PRUint32 mRefCnt : 16;
|
||||
PRUint32 mIsSession : 1;
|
||||
PRUint32 mIsDomain : 1;
|
||||
PRUint32 mIsSecure : 1;
|
||||
PRUint32 mStatus : 3;
|
||||
PRUint32 mPolicy : 3;
|
||||
};
|
||||
|
||||
// {E9FCB9A4-D376-458f-B720-E65E7DF593BC}
|
||||
#define NS_COOKIE_CID { 0xe9fcb9a4,0xd376,0x458f,{0xb7,0x20,0xe6,0x5e,0x7d,0xf5,0x93,0xbc}}
|
||||
#define NS_COOKIE_CID {0xe9fcb9a4,0xd376,0x458f,{0xb7,0x20,0xe6,0x5e,0x7d,0xf5,0x93,0xbc}}
|
||||
#define NS_COOKIE2_CID {0xd3493503,0x7854,0x46ed,{0x82,0x84,0x8a,0xf5,0x4a,0x84,0x7e,0xfb}}
|
||||
|
||||
#endif /* nsCookie_h__ */
|
||||
#endif // nsCookie_h__
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -16,11 +16,12 @@
|
|||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Daniel Witte (dwitte@stanford.edu)
|
||||
* Michiel van Leeuwen (mvl@exedo.nl)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -40,95 +41,141 @@
|
|||
#define nsCookieService_h__
|
||||
|
||||
#include "nsICookieService.h"
|
||||
#include "nsICookieManager.h"
|
||||
#include "nsICookieManager2.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCookiePrefObserver
|
||||
#include "nsCookie.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
// enumerated type, used to specify default cookie behavior
|
||||
typedef enum {
|
||||
PERMISSION_Accept,
|
||||
PERMISSION_DontAcceptForeign,
|
||||
PERMISSION_DontUse,
|
||||
PERMISSION_P3P
|
||||
} PERMISSION_BehaviorEnum;
|
||||
class nsCookieAttributes;
|
||||
class nsICookieConsent;
|
||||
class nsICookiePermission;
|
||||
class nsIPrefBranch;
|
||||
class nsIObserverService;
|
||||
class nsIURI;
|
||||
class nsIPrompt;
|
||||
class nsIChannel;
|
||||
class nsITimer;
|
||||
class nsIFile;
|
||||
class nsInt64;
|
||||
|
||||
class nsCookiePrefObserver : public nsIObserver
|
||||
, public nsSupportsWeakReference
|
||||
/******************************************************************************
|
||||
* nsCookieService:
|
||||
* class declaration
|
||||
******************************************************************************/
|
||||
|
||||
class nsCookieService : public nsICookieService
|
||||
, public nsICookieManager2
|
||||
, public nsIObserver
|
||||
, public nsIWebProgressListener
|
||||
, public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSICOOKIESERVICE
|
||||
NS_DECL_NSICOOKIEMANAGER
|
||||
NS_DECL_NSICOOKIEMANAGER2
|
||||
|
||||
nsCookiePrefObserver();
|
||||
virtual ~nsCookiePrefObserver();
|
||||
nsCookieService();
|
||||
virtual ~nsCookieService();
|
||||
nsresult Init();
|
||||
nsresult ReadPrefs();
|
||||
static nsCookieService* GetSingleton();
|
||||
static void FreeSingleton();
|
||||
|
||||
// member variables for caching prefs
|
||||
protected:
|
||||
void InitPrefObservers();
|
||||
nsresult ReadPrefs();
|
||||
nsresult Read();
|
||||
nsresult Write();
|
||||
PRBool SetCookieInternal(nsIURI *aHostURI, nsDependentCString &aCookieHeader, nsInt64 aServerTime, nsCookieStatus aStatus, nsCookiePolicy aPolicy);
|
||||
nsresult AddInternal(nsCookie *aCookie, nsInt64 aCurrentTime, nsIURI *aHostURI, const char *aCookieHeader);
|
||||
static PRBool GetTokenValue(nsASingleFragmentCString::const_char_iterator &aIter, nsASingleFragmentCString::const_char_iterator &aEndIter, nsDependentSingleFragmentCSubstring &aTokenString, nsDependentSingleFragmentCSubstring &aTokenValue, PRBool &aEqualsFound);
|
||||
static PRBool ParseAttributes(nsDependentCString &aCookieHeader, nsCookieAttributes &aCookie);
|
||||
static PRBool IsIPAddress(const nsAFlatCString &aHost);
|
||||
static PRBool IsFromMailNews(const nsAFlatCString &aScheme);
|
||||
static PRBool IsInDomain(const nsACString &aDomain, const nsACString &aHost, PRBool aIsDomain = PR_TRUE);
|
||||
static PRBool IsForeign(nsIURI *aHostURI, nsIURI *aFirstURI);
|
||||
static nsCookiePolicy GetP3PPolicy(PRInt32 aPolicy);
|
||||
PRInt32 SiteP3PPolicy(nsIURI *aCurrentURI, nsIChannel *aChannel);
|
||||
nsCookieStatus P3PDecision(nsIURI *aHostURI, nsIURI *aFirstURI, nsIChannel *aChannel);
|
||||
nsCookieStatus CheckPrefs(nsIURI *aHostURI, nsIURI *aFirstURI, nsIChannel *aChannel, const char *aCookieHeader);
|
||||
PRBool CheckDomain(nsCookieAttributes &aCookie, nsIURI *aHostURI);
|
||||
static PRBool CheckPath(nsCookieAttributes &aCookie, nsIURI *aHostURI);
|
||||
PRBool GetExpiry(nsCookieAttributes &aCookie, nsInt64 aServerTime, nsInt64 aCurrentTime, nsCookieStatus aStatus);
|
||||
void RemoveAllFromMemory();
|
||||
void RemoveExpiredCookies(nsInt64 aCurrentTime, PRInt32 &aOldestPosition);
|
||||
PRBool FindCookiesFromHost(nsCookie *aCookie, PRUint32 &aCountFromHost, nsInt64 aCurrentTime);
|
||||
PRBool FindPosition(nsCookie *aCookie, PRInt32 &aInsertPosition, PRInt32 &aDeletePosition, nsInt64 aCurrentTime);
|
||||
void UpdateCookieIcon();
|
||||
|
||||
// Use LazyWrite to save the cookies file on a timer. It will write
|
||||
// the file only once if repeatedly hammered quickly.
|
||||
void LazyWrite(PRBool aForce);
|
||||
static void DoLazyWrite(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
protected:
|
||||
// cached members
|
||||
nsCOMPtr<nsIPrefBranch> mPrefBranch;
|
||||
nsCOMPtr<nsIFile> mCookieFile;
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
nsCOMPtr<nsICookieConsent> mP3PService;
|
||||
nsCOMPtr<nsICookiePermission> mPermissionService;
|
||||
|
||||
// impl members
|
||||
nsCOMPtr<nsITimer> mWriteTimer;
|
||||
nsVoidArray mCookieList;
|
||||
PRUint32 mLoadCount;
|
||||
PRPackedBool mWritePending;
|
||||
PRPackedBool mCookieChanged;
|
||||
PRPackedBool mCookieIconVisible;
|
||||
|
||||
// cached prefs
|
||||
#ifdef MOZ_PHOENIX
|
||||
// unfortunately, we require this #ifdef for now, since Phoenix uses different
|
||||
// (more optimized) prefs to Mozilla. This will be fixed shortly.
|
||||
// (more optimized) prefs to Mozilla.
|
||||
// the following variables are Phoenix hacks to reduce ifdefs in the code.
|
||||
PRPackedBool mCookiesEnabled_temp, // These two prefs are collapsed
|
||||
mCookiesForDomainOnly_temp, // into mCookiesPermissions.
|
||||
mCookiesDisabledForMailNews; // Disable cookies in mailnews
|
||||
#else
|
||||
PRPackedBool mCookiesDisabledForMailNews; // Disable cookies in mailnews
|
||||
PRPackedBool mCookiesEnabled_temp, // These two prefs are collapsed
|
||||
mCookiesForDomainOnly_temp; // into mCookiesPermissions.
|
||||
#endif
|
||||
PRPackedBool mCookiesAskPermission, // Ask user permission before storing cookie
|
||||
mCookiesLifetimeEnabled, // Cookie lifetime limit enabled
|
||||
mCookiesLifetimeCurrentSession; // Limit cookie lifetime to current session
|
||||
PRInt32 mCookiesLifetimeSec; // Lifetime limit specified in seconds
|
||||
PRBool mCookiesStrictDomains; // Optional pref to apply stricter domain checks
|
||||
PERMISSION_BehaviorEnum mCookiesPermissions; // PERMISSION_{Accept, DontAcceptForeign, DontUse, P3P}
|
||||
nsXPIDLCString mCookiesP3PString; // P3P settings
|
||||
PRPackedBool mCookiesAskPermission, // Ask user permission before storing cookie
|
||||
mCookiesLifetimeEnabled, // Cookie lifetime limit enabled
|
||||
mCookiesLifetimeCurrentSession, // Limit cookie lifetime to current session
|
||||
mCookiesDisabledForMailNews, // Disable cookies in mailnews
|
||||
mCookiesStrictDomains; // Optional pref to apply stricter domain checks
|
||||
PRUint8 mCookiesPermissions; // BEHAVIOR_{ACCEPT, REJECTFOREIGN, REJECT, P3P}
|
||||
PRInt32 mCookiesLifetimeSec; // Lifetime limit specified in seconds
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIPrefBranch> mPrefBranch;
|
||||
/* mCookiesP3PString (below) consists of 8 characters having the following interpretation:
|
||||
* [0]: behavior for first-party cookies when site has no privacy policy
|
||||
* [1]: behavior for third-party cookies when site has no privacy policy
|
||||
* [2]: behavior for first-party cookies when site uses PII with no user consent
|
||||
* [3]: behavior for third-party cookies when site uses PII with no user consent
|
||||
* [4]: behavior for first-party cookies when site uses PII with implicit consent only
|
||||
* [5]: behavior for third-party cookies when site uses PII with implicit consent only
|
||||
* [6]: behavior for first-party cookies when site uses PII with explicit consent
|
||||
* [7]: behavior for third-party cookies when site uses PII with explicit consent
|
||||
*
|
||||
* (note: PII = personally identifiable information)
|
||||
*
|
||||
* each of the eight characters can be one of the following:
|
||||
* 'a': accept the cookie
|
||||
* 'd': accept the cookie but downgrade it to a session cookie
|
||||
* 'r': reject the cookie
|
||||
*/
|
||||
nsXPIDLCString mCookiesP3PString;
|
||||
|
||||
// private static member, used to cache a ptr to nsCookieService,
|
||||
// so we can make nsCookieService a singleton xpcom object.
|
||||
static nsCookieService *gCookieService;
|
||||
};
|
||||
|
||||
extern nsCookiePrefObserver *gCookiePrefObserver;
|
||||
#define NS_COOKIEMANAGER_CID {0xaaab6710,0xf2c,0x11d5,{0xa5,0x3b,0x0,0x10,0xa4,0x1,0xeb,0x10}}
|
||||
|
||||
// nsCookieService
|
||||
class nsCookieService : public nsICookieService,
|
||||
public nsIObserver,
|
||||
public nsIWebProgressListener,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSICOOKIESERVICE
|
||||
|
||||
nsCookieService();
|
||||
virtual ~nsCookieService();
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
// cached things
|
||||
nsCOMPtr<nsIFile> mCookieFile;
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
|
||||
// Use LazyWrite to save the cookies file on a timer. It will write
|
||||
// the file only once if repeatedly hammered quickly.
|
||||
void LazyWrite(PRBool aForce);
|
||||
static void DoLazyWrite(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
nsCOMPtr<nsITimer> mWriteTimer;
|
||||
PRUint32 mLoadCount;
|
||||
PRBool mWritePending;
|
||||
};
|
||||
|
||||
#endif /* nsCookieService_h__ */
|
||||
#endif // nsCookieService_h__
|
||||
|
|
|
@ -288,7 +288,7 @@ nsImgManager::Observe(nsISupports *aSubject,
|
|||
|
||||
if (!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) {
|
||||
// which pref changed?
|
||||
NS_ConvertUCS2toUTF8 pref(aData);
|
||||
NS_LossyConvertUCS2toASCII pref(aData);
|
||||
|
||||
if (pref.Equals(kImageBehaviorPrefName)) {
|
||||
rv = mPrefBranch->GetIntPref(kImageBehaviorPrefName, &mBehaviorPref);
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#include "nsCookie.h"
|
||||
#include "nsCCookie.h"
|
||||
#include "nsPermission.h"
|
||||
#include "nsCookieManager.h"
|
||||
#include "nsCCookieManager.h"
|
||||
#include "nsCookieService.h"
|
||||
#include "nsImgManager.h"
|
||||
|
@ -58,8 +57,7 @@
|
|||
// Define the constructor function for the objects
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookie)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPermission)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieService, Init)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsCookieService, nsCookieService::GetSingleton)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsImgManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPermissionManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPopupWindowManager, Init)
|
||||
|
@ -114,7 +112,7 @@ static const nsModuleComponentInfo components[] = {
|
|||
{ "CookieManager",
|
||||
NS_COOKIEMANAGER_CID,
|
||||
NS_COOKIEMANAGER_CONTRACTID,
|
||||
nsCookieManagerConstructor
|
||||
nsCookieServiceConstructor
|
||||
},
|
||||
{ "CookieService",
|
||||
NS_COOKIESERVICE_CID,
|
||||
|
@ -156,4 +154,11 @@ static const nsModuleComponentInfo components[] = {
|
|||
},
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(nsCookieModule, components)
|
||||
PR_STATIC_CALLBACK(void)
|
||||
cookieModuleDtor(nsIModule *aSelf)
|
||||
{
|
||||
// Release our singletons
|
||||
nsCookieService::FreeSingleton();
|
||||
}
|
||||
|
||||
NS_IMPL_NSGETMODULE_WITH_DTOR(nsCookieModule, components, cookieModuleDtor)
|
||||
|
|
|
@ -140,15 +140,14 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
inline nsresult AddInternal(const nsAFlatCString &aHost,
|
||||
PRUint32 aType,
|
||||
PRUint32 aPermission);
|
||||
nsresult AddInternal(const nsAFlatCString &aHost,
|
||||
PRUint32 aType,
|
||||
PRUint32 aPermission);
|
||||
|
||||
nsresult Read();
|
||||
nsresult Write();
|
||||
nsresult NotifyObservers(const nsACString &aHost);
|
||||
nsresult RemoveAllFromMemory();
|
||||
inline nsVoidArray* GetHostList();
|
||||
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
nsCOMPtr<nsIFile> mPermissionsFile;
|
||||
|
|
|
@ -153,7 +153,7 @@ nsPopupWindowManager::Observe(nsISupports *aSubject,
|
|||
const char *aTopic,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
NS_ConvertUCS2toUTF8 pref(aData);
|
||||
NS_LossyConvertUCS2toASCII pref(aData);
|
||||
if (pref.Equals(kPopupDisablePref)) {
|
||||
// refresh our local copy of the "disable popups" pref
|
||||
PRBool permission = PR_FALSE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче