moving cookies backend into necko: b=210561 r=dwitte sr=bryner

these files were moved from their old home in extensions/cookie.  the CVS
records cannot be simply moved because attic files exist in the new location,
and so i will unfortunately take cvs blame for all.  that's unfair to dwitte
who has made so many wonderful changes to the cookies backend code! ;-)

so, to find out the real cvs blame for these files, please look at the
following cvs remove'd files:

mozilla/extensions/cookie/nsCookieService.cpp
mozilla/extensions/cookie/nsCookieService.h
mozilla/extensions/cookie/nsCookie.cpp
mozilla/extensions/cookie/nsCookie.h
mozilla/extensions/cookie/nsICookie2.idl
mozilla/extensions/cookie/nsICookieConsent.idl
mozilla/extensions/cookie/nsICookie.idl
mozilla/extensions/cookie/nsICookieManager2.idl
mozilla/extensions/cookie/nsICookieManager.idl
mozilla/extensions/cookie/nsICookiePermission.idl
This commit is contained in:
darin%meer.net 2003-10-10 23:09:18 +00:00
Родитель fd825778c0
Коммит 948c1c9c08
4 изменённых файлов: 2870 добавлений и 0 удалений

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

@ -0,0 +1,147 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCookie.h"
/******************************************************************************
* nsCookie:
* string helper impl
******************************************************************************/
// 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 *toBegin = NS_STATIC_CAST(char*, nsMemory::Alloc(totalLength * sizeof(char)));
NS_ASSERTION(toBegin, "out of memory allocating for nsCookie!");
aDest1 = toBegin;
if (toBegin) {
nsACString::const_iterator fromBegin, fromEnd;
*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:
* 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)
{
// allocate a new (contiguous) string, and assign string members
StrBlockCopy(aName, aValue, aHost, aPath,
mName, mValue, mHost, mPath, mEnd);
}
nsCookie::~nsCookie()
{
if (mName)
nsMemory::Free(mName);
}
/******************************************************************************
* 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_IMPL_ISUPPORTS2(nsCookie, nsICookie, nsICookie2)

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

@ -0,0 +1,127 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* 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
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsCookie_h__
#define nsCookie_h__
#include "nsICookie.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.
*/
/******************************************************************************
* nsCookie:
* implementation
******************************************************************************/
class nsCookie : public nsICookie2
{
// this is required because we use a bitfield refcount member.
public:
NS_DECL_ISUPPORTS_INHERITED
protected:
NS_DECL_OWNINGTHREAD
public:
// nsISupports
NS_DECL_NSICOOKIE
NS_DECL_NSICOOKIE2
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;
};
#endif // nsCookie_h__

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,178 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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
* Netscape Communications Corporation.
* 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
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsCookieService_h__
#define nsCookieService_h__
#include "nsICookieService.h"
#include "nsICookieManager.h"
#include "nsICookieManager2.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsCookie.h"
#include "nsString.h"
#include "nsVoidArray.h"
struct nsCookieAttributes;
class nsICookieConsent;
class nsICookiePermission;
class nsIPrefBranch;
class nsIObserverService;
class nsIURI;
class nsIPrompt;
class nsIChannel;
class nsITimer;
class nsIFile;
class nsInt64;
/******************************************************************************
* nsCookieService:
* class declaration
******************************************************************************/
class nsCookieService : public nsICookieService
, public nsICookieManager2
, public nsIObserver
, public nsSupportsWeakReference
{
public:
// nsISupports
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSICOOKIESERVICE
NS_DECL_NSICOOKIEMANAGER
NS_DECL_NSICOOKIEMANAGER2
nsCookieService();
virtual ~nsCookieService();
static nsCookieService* GetSingleton();
protected:
void InitPrefObservers();
nsresult ReadPrefs();
nsresult Read();
nsresult Write();
PRBool SetCookieInternal(nsIURI *aHostURI, nsIChannel *aChannel, 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();
static void DoLazyWrite(nsITimer *aTimer, void *aClosure);
// Use LazyNotify to broadcast the "cookieChanged" notification at
// a reasonable frequency.
void LazyNotify();
static void DoLazyNotify(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;
nsCOMPtr<nsITimer> mNotifyTimer;
nsVoidArray mCookieList;
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.
// the following variables are Phoenix hacks to reduce ifdefs in the code.
PRPackedBool mCookiesEnabled_temp, // These two prefs are collapsed
mCookiesForDomainOnly_temp; // into mCookiesPermissions.
#endif
PRPackedBool mCookiesLifetimeEnabled, // Cookie lifetime limit enabled
mCookiesLifetimeCurrentSession, // Limit cookie lifetime to current session
mCookiesStrictDomains; // Optional pref to apply stricter domain checks
PRUint8 mCookiesPermissions; // BEHAVIOR_{ACCEPT, REJECTFOREIGN, REJECT, P3P}
PRInt32 mCookiesLifetimeSec; // Lifetime limit specified in seconds
/* 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;
};
#define NS_COOKIEMANAGER_CID {0xaaab6710,0xf2c,0x11d5,{0xa5,0x3b,0x0,0x10,0xa4,0x1,0xeb,0x10}}
#endif // nsCookieService_h__