1010#include " nsICookie2.h"
1111#include " nsIServiceManager.h"
1212#include " nsICookieManager.h"
13+ #include " nsICookieService.h"
1314#include " nsNetUtil.h"
1415#include " nsIInterfaceRequestorUtils.h"
1516#include " nsIProtocolHandler.h"
1617#include " nsIURI.h"
17- #include " nsIPrefService.h"
18- #include " nsIPrefBranch.h"
1918#include " nsIChannel.h"
2019#include " nsIHttpChannelInternal.h"
2120#include " nsIDOMWindow.h"
2726#include " nsNetCID.h"
2827#include " prtime.h"
2928#include " mozilla/StaticPtr.h"
29+ #include " nsContentUtils.h"
3030
3131/* ***************************************************************
3232 ************************ nsCookiePermission ********************
3333 ****************************************************************/
3434
35- // values for mCookiesLifetimePolicy
36- // 0 == accept normally
37- // 1 == ask before accepting, no more supported, treated like ACCEPT_NORMALLY
38- // (Bug 606655). 2 == downgrade to session 3 == limit lifetime to N days
39- static const uint32_t ACCEPT_NORMALLY = 0 ;
40- static const uint32_t ACCEPT_SESSION = 2 ;
41-
4235static const bool kDefaultPolicy = true ;
43- static const char kCookiesLifetimePolicy [] = " network.cookie.lifetimePolicy" ;
4436
4537static const nsLiteralCString kPermissionType (NS_LITERAL_CSTRING (" cookie" ));
4638
4739namespace {
4840mozilla::StaticRefPtr<nsCookiePermission> gSingleton ;
4941}
5042
51- NS_IMPL_ISUPPORTS (nsCookiePermission, nsICookiePermission, nsIObserver )
43+ NS_IMPL_ISUPPORTS (nsCookiePermission, nsICookiePermission)
5244
5345// static
5446already_AddRefed<nsICookiePermission> nsCookiePermission::GetOrCreate () {
@@ -71,31 +63,9 @@ bool nsCookiePermission::Init() {
7163 mThirdPartyUtil = do_GetService (THIRDPARTYUTIL_CONTRACTID , &rv);
7264 if (NS_FAILED (rv)) return false ;
7365
74- // failure to access the pref service is non-fatal...
75- nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService (NS_PREFSERVICE_CONTRACTID );
76- if (prefBranch) {
77- prefBranch->AddObserver (kCookiesLifetimePolicy , this , false );
78- PrefChanged (prefBranch, nullptr );
79- }
80-
8166 return true ;
8267}
8368
84- void nsCookiePermission::PrefChanged (nsIPrefBranch *aPrefBranch,
85- const char *aPref) {
86- int32_t val;
87-
88- #define PREF_CHANGED (_P ) (!aPref || !strcmp(aPref, _P))
89-
90- if (PREF_CHANGED (kCookiesLifetimePolicy ) &&
91- NS_SUCCEEDED (aPrefBranch->GetIntPref (kCookiesLifetimePolicy , &val))) {
92- if (val != static_cast <int32_t >(ACCEPT_SESSION )) {
93- val = ACCEPT_NORMALLY ;
94- }
95- mCookiesLifetimePolicy = val;
96- }
97- }
98-
9969NS_IMETHODIMP
10070nsCookiePermission::SetAccess (nsIURI *aURI, nsCookieAccess aAccess) {
10171 // Lazily initialize ourselves
@@ -159,7 +129,8 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI, nsIChannel *aChannel,
159129
160130 // now we need to figure out what type of accept policy we're dealing with
161131 // if we accept cookies normally, just bail and return
162- if (mCookiesLifetimePolicy == ACCEPT_NORMALLY ) {
132+ if (nsContentUtils::GetCookieLifetimePolicy () ==
133+ nsICookieService::ACCEPT_NORMALLY ) {
163134 *aResult = true ;
164135 return NS_OK ;
165136 }
@@ -171,7 +142,8 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI, nsIChannel *aChannel,
171142 // We are accepting the cookie, but,
172143 // if it's not a session cookie, we may have to limit its lifetime.
173144 if (!*aIsSession && delta > 0 ) {
174- if (mCookiesLifetimePolicy == ACCEPT_SESSION ) {
145+ if (nsContentUtils::GetCookieLifetimePolicy () ==
146+ nsICookieService::ACCEPT_SESSION ) {
175147 // limit lifetime to session
176148 *aIsSession = true ;
177149 }
@@ -180,15 +152,3 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI, nsIChannel *aChannel,
180152
181153 return NS_OK ;
182154}
183-
184- NS_IMETHODIMP
185- nsCookiePermission::Observe (nsISupports *aSubject, const char *aTopic,
186- const char16_t *aData) {
187- nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface (aSubject);
188- NS_ASSERTION (!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID , aTopic),
189- "unexpected topic - we only deal with pref changes!");
190-
191- if (prefBranch)
192- PrefChanged (prefBranch, NS_LossyConvertUTF16toASCII(aData).get ());
193- return NS_OK ;
194- }
0 commit comments