remove p3p hooks from cookies. b=383994, r=timeless, sr=biesi

This commit is contained in:
dwitte@stanford.edu 2007-06-20 22:17:08 -07:00
parent 6cc6875547
commit e55450dea9
8 changed files with 50 additions and 249 deletions

View File

@ -55,7 +55,6 @@ XPIDLSRCS = \
nsICookieService.idl \
nsICookieServiceInternal.idl \
nsICookie2.idl \
nsICookieConsent.idl \
nsICookieManager2.idl \
nsICookiePermission.idl \
$(NULL)

View File

@ -83,7 +83,7 @@ interface nsICookie : nsISupports {
readonly attribute boolean isSecure;
/**
* @DEPRECATED - use nsICookie2.expiry and nsICookie2.isSession instead.
* @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.
@ -92,31 +92,17 @@ interface nsICookie : nsISupports {
readonly attribute PRUint64 expires;
/**
* P3P status of cookie. Values are
*
* STATUS_UNKNOWN -- cookie collected in a previous session and this info no longer available
* STATUS_ACCEPTED -- cookie was accepted as it
* STATUS_DOWNGRADED -- cookie was accepted but downgraded to a session cookie
* STATUS_FLAGGED -- cookie was accepted with a warning being issued to the user
* STATUS_REJECTED -- cookie was not accepted
* @DEPRECATED status implementation will return STATUS_UNKNOWN in all cases.
*/
const nsCookieStatus STATUS_UNKNOWN=0;
const nsCookieStatus STATUS_ACCEPTED=1;
const nsCookieStatus STATUS_DOWNGRADED=2;
const nsCookieStatus STATUS_FLAGGED=3;
const nsCookieStatus STATUS_REJECTED=4;
readonly attribute nsCookieStatus status;
/**
* Site's compact policy. Values are
*
* POLICY_UNKNOWN -- cookie collected in a previous session and this info no longer available
* POLICY_NONE -- site did not send a compact policy along with the cookie
* POLICY_NO_CONSENT -- site collects identfiable information without user involvement
* POLICY_IMPLICIT_CONSENT -- site collects identifiable information unless user opts out
* POLICY_EXPLICIT_CONSENT -- site does not collect identifiable information unless user opts in
* POLICY_NO_II -- site does not collect identifiable information
* @DEPRECATED policy implementation will return POLICY_UNKNOWN in all cases.
*/
const nsCookiePolicy POLICY_UNKNOWN=0;
const nsCookiePolicy POLICY_NONE=1;

View File

@ -1,75 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsICookie.idl"
interface nsIURI;
interface nsIHttpChannel;
[scriptable,uuid(F5A34F50-1F39-11d6-A627-0010A401EB10)]
interface nsICookieConsent : nsISupports
{
/**
* getConsent
*
* gives a decision on what should be done with a cookie, based on a site's
* p3p policy and the user's preferences. the policy for the given URI and
* channel is also returned.
*
* @param uri
* the URI to find the policy for
* @param httpChannel
* the channel to extract the p3p headers from
* @param isForeign
* true if the cookie originates from a third-party site. this is used
* to decide the cookie status based on user preferences.
* @param policy
* the policy for the given URI, or nsICookie::POLICY_UNKNOWN if one
* cannot be found. valid values are defined in nsICookie.idl.
*
* @return nsCookieStatus value. valid values are defined in nsICookie.idl.
*/
nsCookieStatus getConsent(in nsIURI uri,
in nsIHttpChannel httpChannel,
in boolean isForeign,
out nsCookiePolicy policy);
};
%{C++
#define NS_COOKIECONSENT_CONTRACTID "@mozilla.org/cookie-consent;1"
%}

View File

@ -74,7 +74,7 @@ interface nsIChannel;
* to set the cookie.
* data : none.
*/
[scriptable, uuid(011C3190-1434-11d6-A618-0010A401EB10)]
[scriptable, uuid(2aaa897a-293c-4d2b-a657-8c9b7136996d)]
interface nsICookieService : nsISupports
{
/*
@ -154,11 +154,4 @@ interface nsICookieService : nsISupports
* ensure that the cookie privacy preferences are honored.
*/
void setCookieStringFromHttp(in nsIURI aURI, in nsIURI aFirstURI, in nsIPrompt aPrompt, in string aCookie, in string aServerTime, in nsIChannel aChannel);
/**
* This attribute really doesn't belong on this interface. CVS blame will
* tell you why it is here. It remains until we can find a better home for
* it. Read the source if you want to know what it does :-(
*/
readonly attribute boolean cookieIconIsVisible;
};

View File

@ -92,9 +92,7 @@ nsCookie::Create(const nsACString &aName,
PRInt64 aCreationID,
PRBool aIsSession,
PRBool aIsSecure,
PRBool aIsHttpOnly,
nsCookieStatus aStatus,
nsCookiePolicy aPolicy)
PRBool aIsHttpOnly)
{
// find the required string buffer size, adding 4 for the terminating nulls
const PRUint32 stringLength = aName.Length() + aValue.Length() +
@ -122,8 +120,7 @@ nsCookie::Create(const nsACString &aName,
// construct the cookie. placement new, oh yeah!
return new (place) nsCookie(name, value, host, path, end,
aExpiry, aCreationID,
aIsSession, aIsSecure, aIsHttpOnly,
aStatus, aPolicy);
aIsSession, aIsSecure, aIsHttpOnly);
}
/******************************************************************************
@ -141,9 +138,9 @@ NS_IMETHODIMP nsCookie::GetExpiry(PRInt64 *aExpiry) { *aExpiry = Expiry()
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; }
NS_IMETHODIMP nsCookie::GetIsHttpOnly(PRBool *aHttpOnly) { *aHttpOnly = IsHttpOnly(); return NS_OK; }
NS_IMETHODIMP nsCookie::GetStatus(nsCookieStatus *aStatus) { *aStatus = 0; return NS_OK; }
NS_IMETHODIMP nsCookie::GetPolicy(nsCookiePolicy *aPolicy) { *aPolicy = 0; return NS_OK; }
// compatibility method, for use with the legacy nsICookie interface.
// here, expires == 0 denotes a session cookie.

View File

@ -78,9 +78,7 @@ class nsCookie : public nsICookie2
PRInt64 aCreationID,
PRBool aIsSession,
PRBool aIsSecure,
PRBool aIsHttpOnly,
nsCookieStatus aStatus,
nsCookiePolicy aPolicy)
PRBool aIsHttpOnly)
: mNext(nsnull)
, mName(aName)
, mValue(aValue)
@ -93,8 +91,6 @@ class nsCookie : public nsICookie2
, mIsSession(aIsSession != PR_FALSE)
, mIsSecure(aIsSecure != PR_FALSE)
, mIsHttpOnly(aIsHttpOnly != PR_FALSE)
, mStatus(aStatus)
, mPolicy(aPolicy)
{
}
@ -109,9 +105,7 @@ class nsCookie : public nsICookie2
PRInt64 aCreationID,
PRBool aIsSession,
PRBool aIsSecure,
PRBool aIsHttpOnly,
nsCookieStatus aStatus,
nsCookiePolicy aPolicy);
PRBool aIsHttpOnly);
virtual ~nsCookie() {}
@ -129,8 +123,6 @@ class nsCookie : public nsICookie2
inline PRBool IsDomain() const { return *mHost == '.'; }
inline PRBool IsSecure() const { return mIsSecure; }
inline PRBool IsHttpOnly() const { return mIsHttpOnly; }
inline nsCookieStatus Status() const { return mStatus; }
inline nsCookiePolicy Policy() const { return mPolicy; }
// setters
inline void SetExpiry(PRInt64 aExpiry) { mExpiry = aExpiry; }
@ -163,8 +155,6 @@ class nsCookie : public nsICookie2
PRUint32 mIsSession : 1;
PRUint32 mIsSecure : 1;
PRUint32 mIsHttpOnly: 1;
PRUint32 mStatus : 3;
PRUint32 mPolicy : 3;
};
#endif // nsCookie_h__

View File

@ -45,7 +45,6 @@
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefService.h"
#include "nsICookieConsent.h"
#include "nsICookiePermission.h"
#include "nsIURI.h"
#include "nsIURL.h"
@ -98,18 +97,19 @@ static const PRUint32 kMaxCookiesPerHost = 50;
static const PRUint32 kMaxBytesPerCookie = 4096;
static const PRUint32 kMaxBytesPerPath = 1024;
// this constant augments those defined on nsICookie, and indicates
// the cookie should be rejected because of an error (rather than
// something the user can control). this is used for notifying about
// rejected cookies, since we only want to notify of rejections where
// these constants represent a decision about a cookie based on user prefs.
static const PRUint32 STATUS_ACCEPTED = 0;
static const PRUint32 STATUS_REJECTED = 1;
// STATUS_REJECTED_WITH_ERROR indicates the cookie should be rejected because
// of an error (rather than something the user can control). this is used for
// notification purposes, since we only want to notify of rejections where
// the user can do something about it (e.g. whitelist the site).
static const nsCookieStatus STATUS_REJECTED_WITH_ERROR = 5;
static const PRUint32 STATUS_REJECTED_WITH_ERROR = 2;
// behavior pref constants
static const PRUint32 BEHAVIOR_ACCEPT = 0;
static const PRUint32 BEHAVIOR_REJECTFOREIGN = 1;
static const PRUint32 BEHAVIOR_REJECT = 2;
static const PRUint32 BEHAVIOR_P3P = 3;
// pref string constants
static const char kPrefCookiesPermissions[] = "network.cookie.cookieBehavior";
@ -378,7 +378,6 @@ NS_IMPL_ISUPPORTS6(nsCookieService,
nsCookieService::nsCookieService()
: mCookieCount(0)
, mCookieIconVisible(PR_FALSE)
, mCookiesPermissions(BEHAVIOR_ACCEPT)
, mMaxNumberOfCookies(kMaxNumberOfCookies)
, mMaxCookiesPerHost(kMaxCookiesPerHost)
@ -409,7 +408,6 @@ nsCookieService::Init()
if (mObserverService) {
mObserverService->AddObserver(this, "profile-before-change", PR_TRUE);
mObserverService->AddObserver(this, "profile-do-change", PR_TRUE);
mObserverService->AddObserver(this, "cookieIcon", PR_TRUE);
}
mPermissionService = do_GetService(NS_COOKIEPERMISSION_CONTRACTID);
@ -585,11 +583,6 @@ nsCookieService::Observe(nsISupports *aSubject,
// the profile has already changed; init the db from the new location
InitDB();
} else if (!strcmp(aTopic, "cookieIcon")) {
// this is an evil trick to avoid the blatant inefficiency of
// (!nsCRT::strcmp(aData, NS_LITERAL_STRING("on").get()))
mCookieIconVisible = (aData[0] == 'o' && aData[1] == 'n' && aData[2] == '\0');
} else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
if (prefBranch)
@ -616,11 +609,10 @@ nsCookieService::GetCookieList(nsIURI *aHostURI,
}
// check default prefs
nsCookiePolicy cookiePolicy; // we don't use this here... just a placeholder
nsCookieStatus cookieStatus = CheckPrefs(aHostURI, aFirstURI, aChannel, nsnull, cookiePolicy);
PRUint32 cookieStatus = CheckPrefs(aHostURI, aFirstURI, aChannel, nsnull);
// for GetCookie(), we don't fire rejection notifications.
switch (cookieStatus) {
case nsICookie::STATUS_REJECTED:
case STATUS_REJECTED:
case STATUS_REJECTED_WITH_ERROR:
return;
}
@ -723,9 +715,9 @@ nsCookieService::GetCookieList(nsIURI *aHostURI,
NS_IMETHODIMP
nsCookieService::GetCookieValue(nsIURI *aHostURI,
nsIChannel *aChannel,
nsIChannel *aChannel,
const nsACString& aName,
nsACString& aResult)
nsACString& aResult)
{
aResult.Truncate();
@ -842,11 +834,10 @@ nsCookieService::SetCookieValue(nsIURI *aHostURI,
}
// check default prefs
nsCookiePolicy cookiePolicy = nsICookie::POLICY_UNKNOWN;
nsCookieStatus cookieStatus = CheckPrefs(aHostURI, firstURI, aChannel, "", cookiePolicy);
PRUint32 cookieStatus = CheckPrefs(aHostURI, firstURI, aChannel, "");
// fire a notification if cookie was rejected (but not if there was an error)
switch (cookieStatus) {
case nsICookie::STATUS_REJECTED:
case STATUS_REJECTED:
NotifyRejected(aHostURI);
case STATUS_REJECTED_WITH_ERROR:
return NS_OK;
@ -864,8 +855,7 @@ nsCookieService::SetCookieValue(nsIURI *aHostURI,
attributes.isSecure = PR_FALSE;
aHostURI->SchemeIs("https", &attributes.isSecure);
CheckAndAdd(aHostURI, aChannel, attributes,
cookieStatus, cookiePolicy, EmptyCString());
CheckAndAdd(aHostURI, aChannel, attributes, EmptyCString());
return NS_OK;
}
@ -901,11 +891,10 @@ nsCookieService::SetCookieStringFromHttp(nsIURI *aHostURI,
}
// check default prefs
nsCookiePolicy cookiePolicy = nsICookie::POLICY_UNKNOWN;
nsCookieStatus cookieStatus = CheckPrefs(aHostURI, aFirstURI, aChannel, aCookieHeader, cookiePolicy);
PRUint32 cookieStatus = CheckPrefs(aHostURI, aFirstURI, aChannel, aCookieHeader);
// fire a notification if cookie was rejected (but not if there was an error)
switch (cookieStatus) {
case nsICookie::STATUS_REJECTED:
case STATUS_REJECTED:
NotifyRejected(aHostURI);
case STATUS_REJECTED_WITH_ERROR:
return NS_OK;
@ -930,9 +919,7 @@ nsCookieService::SetCookieStringFromHttp(nsIURI *aHostURI,
// switch to a nice string type now, and process each cookie in the header
nsDependentCString cookieHeader(aCookieHeader);
while (SetCookieInternal(aHostURI, aChannel,
cookieHeader, serverTime,
cookieStatus, cookiePolicy));
while (SetCookieInternal(aHostURI, aChannel, cookieHeader, serverTime));
return NS_OK;
}
@ -957,31 +944,6 @@ nsCookieService::NotifyChanged(nsICookie2 *aCookie,
{
if (mObserverService)
mObserverService->NotifyObservers(aCookie, "cookie-changed", aData);
// fire a cookieIcon notification if the cookie was downgraded or flagged
// by p3p. the cookieIcon notification is now deprecated, but we still need
// this until consumers can be fixed. to see if cookies have been
// downgraded or flagged, listen to cookie-changed directly.
if (mCookiesPermissions == BEHAVIOR_P3P &&
(!nsCRT::strcmp(aData, NS_LITERAL_STRING("added").get()) ||
!nsCRT::strcmp(aData, NS_LITERAL_STRING("changed").get()))) {
nsCookieStatus status;
aCookie->GetStatus(&status);
if (status == nsICookie::STATUS_DOWNGRADED ||
status == nsICookie::STATUS_FLAGGED) {
mCookieIconVisible = PR_TRUE;
if (mObserverService)
mObserverService->NotifyObservers(nsnull, "cookieIcon", NS_LITERAL_STRING("on").get());
}
}
}
// this method is deprecated. listen to the cookie-changed notification instead.
NS_IMETHODIMP
nsCookieService::GetCookieIconIsVisible(PRBool *aIsVisible)
{
*aIsVisible = mCookieIconVisible;
return NS_OK;
}
/******************************************************************************
@ -994,7 +956,7 @@ nsCookieService::PrefChanged(nsIPrefBranch *aPrefBranch)
{
PRInt32 val;
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kPrefCookiesPermissions, &val)))
mCookiesPermissions = LIMIT(val, 0, 3, 0);
mCookiesPermissions = LIMIT(val, 0, 2, 0);
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kPrefMaxNumberOfCookies, &val)))
mMaxNumberOfCookies = LIMIT(val, 0, 0xFFFF, 0xFFFF);
@ -1063,9 +1025,7 @@ nsCookieService::Add(const nsACString &aDomain,
currentTimeInUsec,
aIsSession,
aIsSecure,
aIsHttpOnly,
nsICookie::STATUS_UNKNOWN,
nsICookie::POLICY_UNKNOWN);
aIsHttpOnly);
if (!cookie) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -1156,9 +1116,7 @@ nsCookieService::Read()
creationID,
PR_FALSE,
isSecure,
isHttpOnly,
nsICookie::STATUS_UNKNOWN,
nsICookie::POLICY_UNKNOWN);
isHttpOnly);
if (!newCookie)
return NS_ERROR_OUT_OF_MEMORY;
@ -1287,9 +1245,7 @@ nsCookieService::ImportCookies()
creationIDCounter,
PR_FALSE,
Substring(buffer, secureIndex, expiresIndex - secureIndex - 1).EqualsLiteral(kTrue),
isHttpOnly,
nsICookie::STATUS_UNKNOWN,
nsICookie::POLICY_UNKNOWN);
isHttpOnly);
if (!newCookie) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -1328,9 +1284,7 @@ PRBool
nsCookieService::SetCookieInternal(nsIURI *aHostURI,
nsIChannel *aChannel,
nsDependentCString &aCookieHeader,
PRInt64 aServerTime,
nsCookieStatus aStatus,
nsCookiePolicy aPolicy)
PRInt64 aServerTime)
{
// create a stack-based nsCookieAttributes, to store all the
// attributes parsed from the cookie
@ -1351,13 +1305,11 @@ nsCookieService::SetCookieInternal(nsIURI *aHostURI,
PRInt64 currentTimeInUsec = PR_Now();
cookieAttributes.creationID = currentTimeInUsec;
// calculate expiry time of cookie. we need to pass in cookieStatus, since
// the cookie may have been downgraded to a session cookie by p3p.
// calculate expiry time of cookie.
cookieAttributes.isSession = GetExpiry(cookieAttributes, aServerTime,
currentTimeInUsec / PR_USEC_PER_SEC, aStatus);
currentTimeInUsec / PR_USEC_PER_SEC);
CheckAndAdd(aHostURI, aChannel, cookieAttributes,
aStatus, aPolicy, savedCookieHeader);
CheckAndAdd(aHostURI, aChannel, cookieAttributes, savedCookieHeader);
return newCookie;
}
@ -1366,8 +1318,6 @@ void
nsCookieService::CheckAndAdd(nsIURI *aHostURI,
nsIChannel *aChannel,
nsCookieAttributes &aAttributes,
nsCookieStatus aStatus,
const nsCookiePolicy aPolicy,
const nsAFlatCString &aCookieHeader)
{
// reject cookie if it's over the size limit, per RFC2109
@ -1401,9 +1351,7 @@ nsCookieService::CheckAndAdd(nsIURI *aHostURI,
aAttributes.creationID,
aAttributes.isSession,
aAttributes.isSecure,
aAttributes.isHttpOnly,
aStatus,
aPolicy);
aAttributes.isHttpOnly);
if (!cookie) {
return;
}
@ -1877,12 +1825,11 @@ nsCookieService::IsForeign(nsIURI *aHostURI,
return !IsInDomain(NS_LITERAL_CSTRING(".") + firstHost, currentHost);
}
nsCookieStatus
PRUint32
nsCookieService::CheckPrefs(nsIURI *aHostURI,
nsIURI *aFirstURI,
nsIChannel *aChannel,
const char *aCookieHeader,
nsCookiePolicy &aPolicy)
const char *aCookieHeader)
{
// pref tree:
// 0) get the scheme strings from the two URI's
@ -1893,11 +1840,6 @@ nsCookieService::CheckPrefs(nsIURI *aHostURI,
// 4) go through enumerated permissions to see which one we have:
// -> cookies disabled: return
// -> dontacceptforeign: check if cookie is foreign
// -> p3p: check p3p cookie data
// we've extended the "nsCookieStatus" type to be used for all cases now
// (used to be only for p3p), so beware that its interpretation is not p3p-
// specific anymore.
// first, get the URI scheme for further use
// if GetScheme fails on aHostURI, reject; aFirstURI is optional, so failing is ok
@ -1929,10 +1871,10 @@ nsCookieService::CheckPrefs(nsIURI *aHostURI,
switch (access) {
case nsICookiePermission::ACCESS_DENY:
COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader, "cookies are blocked for this site");
return nsICookie::STATUS_REJECTED;
return STATUS_REJECTED;
case nsICookiePermission::ACCESS_ALLOW:
return nsICookie::STATUS_ACCEPTED;
return STATUS_ACCEPTED;
}
}
}
@ -1940,7 +1882,7 @@ nsCookieService::CheckPrefs(nsIURI *aHostURI,
// check default prefs - go thru enumerated permissions
if (mCookiesPermissions == BEHAVIOR_REJECT) {
COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader, "cookies are disabled");
return nsICookie::STATUS_REJECTED;
return STATUS_REJECTED;
} else if (mCookiesPermissions == BEHAVIOR_REJECTFOREIGN) {
// check if cookie is foreign.
@ -1951,35 +1893,12 @@ nsCookieService::CheckPrefs(nsIURI *aHostURI,
// passed to the redirected channels. (or isn't correctly set in the first place)
if (IsForeign(aHostURI, aFirstURI)) {
COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader, "originating server test failed");
return nsICookie::STATUS_REJECTED;
return STATUS_REJECTED;
}
} else if (mCookiesPermissions == BEHAVIOR_P3P) {
// check to see if P3P conditions are satisfied. see nsICookie.idl for
// P3P-related constants.
nsCookieStatus p3pStatus = nsICookie::STATUS_UNKNOWN;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
// lazily init the P3P service
if (!mP3PService)
mP3PService = do_GetService(NS_COOKIECONSENT_CONTRACTID);
if (mP3PService) {
// get the site policy and a status decision for the cookie
PRBool isForeign = IsForeign(aHostURI, aFirstURI);
mP3PService->GetConsent(aHostURI, httpChannel, isForeign, &aPolicy, &p3pStatus);
}
if (p3pStatus == nsICookie::STATUS_REJECTED) {
COOKIE_LOGFAILURE(aCookieHeader ? SET_COOKIE : GET_COOKIE, aHostURI, aCookieHeader, "P3P test failed");
}
return p3pStatus;
}
// if nothing has complained, accept cookie
return nsICookie::STATUS_ACCEPTED;
return STATUS_ACCEPTED;
}
// processes domain attribute, and returns PR_TRUE if host has permission to set for this domain.
@ -2100,8 +2019,7 @@ nsCookieService::CheckPath(nsCookieAttributes &aCookieAttributes,
PRBool
nsCookieService::GetExpiry(nsCookieAttributes &aCookieAttributes,
PRInt64 aServerTime,
PRInt64 aCurrentTime,
nsCookieStatus aStatus)
PRInt64 aCurrentTime)
{
/* Determine when the cookie should expire. This is done by taking the difference between
* the server time and the time the server wants the cookie to expire, and adding that
@ -2148,11 +2066,7 @@ nsCookieService::GetExpiry(nsCookieAttributes &aCookieAttributes,
// and the cookie will be expired - that's okay.
aCookieAttributes.expiryTime = aCurrentTime + delta;
// we need to return whether the cookie is a session cookie or not:
// the cookie may have been previously downgraded by p3p prefs,
// so we take that into account here. only applies to non-expired cookies.
return aStatus == nsICookie::STATUS_DOWNGRADED &&
aCookieAttributes.expiryTime > aCurrentTime;
return PR_FALSE;
}
/******************************************************************************

View File

@ -57,7 +57,6 @@ struct nsEnumerationData;
class nsAutoVoidArray;
class nsIPrefBranch;
class nsICookieConsent;
class nsICookiePermission;
class nsIPrefBranch;
class nsIObserverService;
@ -172,8 +171,8 @@ class nsCookieService : public nsICookieServiceInternal
nsresult Read();
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, PRInt64 aServerTime, nsCookieStatus aStatus, nsCookiePolicy aPolicy);
void CheckAndAdd(nsIURI *aHostURI, nsIChannel *aChannel, nsCookieAttributes &aAttributes, nsCookieStatus aStatus, nsCookiePolicy aPolicy, const nsAFlatCString &aCookieHeader);
PRBool SetCookieInternal(nsIURI *aHostURI, nsIChannel *aChannel, nsDependentCString &aCookieHeader, PRInt64 aServerTime);
void CheckAndAdd(nsIURI *aHostURI, nsIChannel *aChannel, nsCookieAttributes &aAttributes, const nsAFlatCString &aCookieHeader);
void AddInternal(nsCookie *aCookie, PRInt64 aCurrentTime, nsIURI *aHostURI, const char *aCookieHeader);
void RemoveCookieFromList(nsListIter &aIter);
PRBool AddCookieToList(nsCookie *aCookie, PRBool aWriteToDB = PR_TRUE);
@ -182,10 +181,10 @@ class nsCookieService : public nsICookieServiceInternal
static PRBool IsIPAddress(const nsAFlatCString &aHost);
static PRBool IsInDomain(const nsACString &aDomain, const nsACString &aHost, PRBool aIsDomain = PR_TRUE);
static PRBool IsForeign(nsIURI *aHostURI, nsIURI *aFirstURI);
nsCookieStatus CheckPrefs(nsIURI *aHostURI, nsIURI *aFirstURI, nsIChannel *aChannel, const char *aCookieHeader, nsCookiePolicy &aPolicy);
PRUint32 CheckPrefs(nsIURI *aHostURI, nsIURI *aFirstURI, nsIChannel *aChannel, const char *aCookieHeader);
static PRBool CheckDomain(nsCookieAttributes &aCookie, nsIURI *aHostURI);
static PRBool CheckPath(nsCookieAttributes &aCookie, nsIURI *aHostURI);
static PRBool GetExpiry(nsCookieAttributes &aCookie, PRInt64 aServerTime, PRInt64 aCurrentTime, nsCookieStatus aStatus);
static PRBool GetExpiry(nsCookieAttributes &aCookie, PRInt64 aServerTime, PRInt64 aCurrentTime);
void RemoveAllFromMemory();
void RemoveExpiredCookies(PRInt64 aCurrentTime);
PRBool FindCookie(const nsAFlatCString &aHost, const nsAFlatCString &aName, const nsAFlatCString &aPath, nsListIter &aIter);
@ -200,16 +199,14 @@ class nsCookieService : public nsICookieServiceInternal
nsCOMPtr<mozIStorageStatement> mStmtInsert;
nsCOMPtr<mozIStorageStatement> mStmtDelete;
nsCOMPtr<nsIObserverService> mObserverService;
nsCOMPtr<nsICookieConsent> mP3PService;
nsCOMPtr<nsICookiePermission> mPermissionService;
// impl members
nsTHashtable<nsCookieEntry> mHostTable;
PRUint32 mCookieCount;
PRPackedBool mCookieIconVisible;
// cached prefs
PRUint8 mCookiesPermissions; // BEHAVIOR_{ACCEPT, REJECTFOREIGN, REJECT, P3P}
PRUint8 mCookiesPermissions; // BEHAVIOR_{ACCEPT, REJECTFOREIGN, REJECT}
PRUint16 mMaxNumberOfCookies;
PRUint16 mMaxCookiesPerHost;