Bug 722850 - Part 3: Check the private browsing status of channels when checking cookie permissions. r=mconnor

This commit is contained in:
Josh Matthews 2012-02-01 05:20:01 -05:00
parent a7cb2b3434
commit b4fc8f6d3a
5 changed files with 13 additions and 37 deletions

View File

@ -238,7 +238,7 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
// without asking, or if we are in private browsing mode, just
// accept the cookie and return
if ((*aIsSession && mCookiesAlwaysAcceptSession) ||
InPrivateBrowsing()) {
(aChannel && NS_UsePrivateBrowsing(aChannel))) {
*aResult = true;
return NS_OK;
}
@ -272,16 +272,6 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
do_GetService(NS_COOKIEPROMPTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
// try to get a nsIDOMWindow from the channel...
nsCOMPtr<nsIDOMWindow> parent;
if (aChannel) {
nsCOMPtr<nsILoadContext> ctx;
NS_QueryNotificationCallbacks(aChannel, ctx);
if (ctx) {
ctx->GetAssociatedWindow(getter_AddRefs(parent));
}
}
// get some useful information to present to the user:
// whether a previous cookie already exists, and how many cookies this host
// has set
@ -310,7 +300,7 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
bool rememberDecision = false;
int32_t dialogRes = nsICookiePromptService::DENY_COOKIE;
rv = cookiePromptService->CookieDialog(parent, aCookie, hostPort,
rv = cookiePromptService->CookieDialog(nullptr, aCookie, hostPort,
countFromHost, foundCookie,
&rememberDecision, &dialogRes);
if (NS_FAILED(rv)) return rv;
@ -368,14 +358,3 @@ nsCookiePermission::Observe(nsISupports *aSubject,
PrefChanged(prefBranch, NS_LossyConvertUTF16toASCII(aData).get());
return NS_OK;
}
bool
nsCookiePermission::InPrivateBrowsing()
{
bool inPrivateBrowsingMode = false;
if (!mPBService)
mPBService = do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
if (mPBService)
mPBService->GetPrivateBrowsingEnabled(&inPrivateBrowsingMode);
return inPrivateBrowsingMode;
}

View File

@ -10,7 +10,6 @@
#include "nsIObserver.h"
#include "nsCOMPtr.h"
#include "prlong.h"
#include "nsIPrivateBrowsingService.h"
#include "mozIThirdPartyUtil.h"
class nsIPrefBranch;
@ -35,10 +34,8 @@ public:
private:
bool EnsureInitialized() { return (mPermMgr != NULL && mThirdPartyUtil != NULL) || Init(); };
bool InPrivateBrowsing();
nsCOMPtr<nsIPermissionManager> mPermMgr;
nsCOMPtr<nsIPrivateBrowsingService> mPBService;
nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil;
int64_t mCookiesLifetimeSec; // lifetime limit specified in seconds

View File

@ -100,9 +100,10 @@ CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
GetAppInfoFromLoadContext(aLoadContext, appId, isInBrowserElement, isPrivate);
nsDependentCString cookieString(aCookieString, 0);
//TODO: bug 812475, pass a real channel object
mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
aServerTime, aFromHttp, appId,
isInBrowserElement, isPrivate);
isInBrowserElement, isPrivate, nullptr);
return true;
}

View File

@ -1571,7 +1571,7 @@ nsCookieService::SetCookieStringCommon(nsIURI *aHostURI,
nsDependentCString serverTime(aServerTime ? aServerTime : "");
SetCookieStringInternal(aHostURI, isForeign, cookieString,
serverTime, aFromHttp, appId, inBrowserElement,
isPrivate);
isPrivate, aChannel);
return NS_OK;
}
@ -1583,7 +1583,8 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI,
bool aFromHttp,
uint32_t aAppId,
bool aInBrowserElement,
bool aIsPrivate)
bool aIsPrivate,
nsIChannel *aChannel)
{
NS_ASSERTION(aHostURI, "null host!");
@ -1642,7 +1643,7 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI,
// process each cookie in the header
while (SetCookieInternal(aHostURI, key, requireHostMatch, cookieStatus,
aCookieHeader, serverTime, aFromHttp)) {
aCookieHeader, serverTime, aFromHttp, aChannel)) {
// document.cookie can only set one cookie at a time
if (!aFromHttp)
break;
@ -2644,7 +2645,8 @@ nsCookieService::SetCookieInternal(nsIURI *aHostURI,
CookieStatus aStatus,
nsDependentCString &aCookieHeader,
int64_t aServerTime,
bool aFromHttp)
bool aFromHttp,
nsIChannel *aChannel)
{
NS_ASSERTION(aHostURI, "null host!");
@ -2714,11 +2716,8 @@ nsCookieService::SetCookieInternal(nsIURI *aHostURI,
// to determine if we can set the cookie
if (mPermissionService) {
bool permission;
// Not passing an nsIChannel here means CanSetCookie will use the currently
// active window to display the prompt. This isn't exactly ideal, but this
// code is going away. See bug 546746.
mPermissionService->CanSetCookie(aHostURI,
nullptr,
aChannel,
static_cast<nsICookie2*>(static_cast<nsCookie*>(cookie)),
&cookieAttributes.isSession,
&cookieAttributes.expiryTime,

View File

@ -269,8 +269,8 @@ class nsCookieService : public nsICookieService
nsresult GetCookieStringCommon(nsIURI *aHostURI, nsIChannel *aChannel, bool aHttpBound, char** aCookie);
void GetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, bool aHttpBound, uint32_t aAppId, bool aInBrowserElement, bool aIsPrivate, nsCString &aCookie);
nsresult SetCookieStringCommon(nsIURI *aHostURI, const char *aCookieHeader, const char *aServerTime, nsIChannel *aChannel, bool aFromHttp);
void SetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, nsDependentCString &aCookieHeader, const nsCString &aServerTime, bool aFromHttp, uint32_t aAppId, bool aInBrowserElement, bool aIsPrivate);
bool SetCookieInternal(nsIURI *aHostURI, const nsCookieKey& aKey, bool aRequireHostMatch, CookieStatus aStatus, nsDependentCString &aCookieHeader, int64_t aServerTime, bool aFromHttp);
void SetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, nsDependentCString &aCookieHeader, const nsCString &aServerTime, bool aFromHttp, uint32_t aAppId, bool aInBrowserElement, bool aIsPrivate, nsIChannel* aChannel);
bool SetCookieInternal(nsIURI *aHostURI, const nsCookieKey& aKey, bool aRequireHostMatch, CookieStatus aStatus, nsDependentCString &aCookieHeader, int64_t aServerTime, bool aFromHttp, nsIChannel* aChannel);
void AddInternal(const nsCookieKey& aKey, nsCookie *aCookie, int64_t aCurrentTimeInUsec, nsIURI *aHostURI, const char *aCookieHeader, bool aFromHttp);
void RemoveCookieFromList(const nsListIter &aIter, mozIStorageBindingParamsArray *aParamsArray = NULL);
void AddCookieToList(const nsCookieKey& aKey, nsCookie *aCookie, DBState *aDBState, mozIStorageBindingParamsArray *aParamsArray, bool aWriteToDB = true);