Bug 1554377 - Cleanup nsCookie implementation - network_cookie_thirdparty_nonsecureSessionOnly to StaticPrefs, r=Ehsan

Differential Revision: https://phabricator.services.mozilla.com/D32615

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-05-31 09:32:33 +00:00
parent 1040f3de6a
commit fd927a96aa
6 changed files with 30 additions and 46 deletions

View File

@ -5725,6 +5725,13 @@ VARCACHE_PREF(
bool, false
)
VARCACHE_PREF(
Live,
"network.cookie.thirdparty.nonsecureSessionOnly",
network_cookie_thirdparty_nonsecureSessionOnly,
bool, false
)
// Enables the predictive service.
VARCACHE_PREF(
Live,

View File

@ -2327,7 +2327,6 @@ pref("network.proxy.no_proxies_on", "");
pref("network.proxy.allow_hijacking_localhost", false);
pref("network.proxy.failover_timeout", 1800); // 30 minutes
pref("network.online", true); //online/offline
pref("network.cookie.thirdparty.nonsecureSessionOnly", false);
// The interval in seconds to move the cookies in the child process.
// Set to 0 to disable moving the cookies.

View File

@ -37,8 +37,6 @@ namespace mozilla {
namespace net {
// Pref string constants
static const char kPrefThirdPartyNonsecureSession[] =
"network.cookie.thirdparty.nonsecureSessionOnly";
static const char kCookieMoveIntervalSecs[] =
"network.cookie.move.interval_sec";
@ -57,8 +55,7 @@ already_AddRefed<CookieServiceChild> CookieServiceChild::GetSingleton() {
NS_IMPL_ISUPPORTS(CookieServiceChild, nsICookieService, nsIObserver,
nsITimerCallback, nsISupportsWeakReference)
CookieServiceChild::CookieServiceChild()
: mThirdPartyNonsecureSession(false), mIPCOpen(false) {
CookieServiceChild::CookieServiceChild() : mIPCOpen(false) {
NS_ASSERTION(IsNeckoChild(), "not a child process");
mozilla::dom::ContentChild* cc =
@ -87,7 +84,6 @@ CookieServiceChild::CookieServiceChild()
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
NS_WARNING_ASSERTION(prefBranch, "no prefservice");
if (prefBranch) {
prefBranch->AddObserver(kPrefThirdPartyNonsecureSession, this, true);
prefBranch->AddObserver(kCookieMoveIntervalSecs, this, true);
PrefChanged(prefBranch);
}
@ -250,11 +246,6 @@ mozilla::ipc::IPCResult CookieServiceChild::RecvTrackCookiesLoad(
}
void CookieServiceChild::PrefChanged(nsIPrefBranch* aPrefBranch) {
bool boolval;
if (NS_SUCCEEDED(
aPrefBranch->GetBoolPref(kPrefThirdPartyNonsecureSession, &boolval)))
mThirdPartyNonsecureSession = boolval;
int32_t val;
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookieMoveIntervalSecs, &val))) {
gMoveCookiesIntervalSeconds = clamped<uint32_t>(val, 0, 3600);
@ -314,8 +305,8 @@ void CookieServiceChild::GetCookieStringFromCookieHashTable(
nsCookieService::GetCookieSettings(aChannel);
CookieStatus cookieStatus = nsCookieService::CheckPrefs(
cookieSettings, mThirdPartyNonsecureSession, aHostURI, aIsForeign,
aIsTrackingResource, aFirstPartyStorageAccessGranted, nullptr,
cookieSettings, aHostURI, aIsForeign, aIsTrackingResource,
aFirstPartyStorageAccessGranted, nullptr,
CountCookiesFromHashTable(baseDomain, attrs), attrs, &aRejectedReason);
if (cookieStatus != STATUS_ACCEPTED &&
@ -419,7 +410,7 @@ bool CookieServiceChild::RequireThirdPartyCheck(nsILoadInfo* aLoadInfo) {
cookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ||
StaticPrefs::network_cookie_thirdparty_sessionOnly() ||
mThirdPartyNonsecureSession;
StaticPrefs::network_cookie_thirdparty_nonsecureSessionOnly();
}
void CookieServiceChild::RecordDocumentCookie(nsCookie* aCookie,
@ -588,8 +579,8 @@ nsresult CookieServiceChild::SetCookieStringInternal(nsIURI* aHostURI,
nsCookieService::GetCookieSettings(aChannel);
CookieStatus cookieStatus = nsCookieService::CheckPrefs(
cookieSettings, mThirdPartyNonsecureSession, aHostURI, isForeign,
isTrackingResource, firstPartyStorageAccessGranted, aCookieString,
cookieSettings, aHostURI, isForeign, isTrackingResource,
firstPartyStorageAccessGranted, aCookieString,
CountCookiesFromHashTable(baseDomain, attrs), attrs, &rejectedReason);
if (cookieStatus != STATUS_ACCEPTED &&

View File

@ -104,7 +104,6 @@ class CookieServiceChild : public PCookieServiceChild,
nsCOMPtr<nsITimer> mCookieTimer;
nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil;
nsCOMPtr<nsIEffectiveTLDService> mTLDService;
bool mThirdPartyNonsecureSession;
bool mIPCOpen;
};

View File

@ -130,8 +130,6 @@ static const char kPrefMaxNumberOfCookies[] = "network.cookie.maxNumber";
static const char kPrefMaxCookiesPerHost[] = "network.cookie.maxPerHost";
static const char kPrefCookieQuotaPerHost[] = "network.cookie.quotaPerHost";
static const char kPrefCookiePurgeAge[] = "network.cookie.purgeAge";
static const char kPrefThirdPartyNonsecureSession[] =
"network.cookie.thirdparty.nonsecureSessionOnly";
static void bindCookieParameters(mozIStorageBindingParamsArray* aParamsArray,
const nsCookieKey& aKey,
@ -584,7 +582,6 @@ NS_IMPL_ISUPPORTS(nsCookieService, nsICookieService, nsICookieManager,
nsCookieService::nsCookieService()
: mDBState(nullptr),
mThirdPartyNonsecureSession(false),
mMaxNumberOfCookies(kMaxNumberOfCookies),
mMaxCookiesPerHost(kMaxCookiesPerHost),
mCookieQuotaPerHost(kCookieQuotaPerHost),
@ -611,7 +608,6 @@ nsresult nsCookieService::Init() {
prefBranch->AddObserver(kPrefMaxNumberOfCookies, this, true);
prefBranch->AddObserver(kPrefMaxCookiesPerHost, this, true);
prefBranch->AddObserver(kPrefCookiePurgeAge, this, true);
prefBranch->AddObserver(kPrefThirdPartyNonsecureSession, this, true);
PrefChanged(prefBranch);
}
@ -2172,10 +2168,10 @@ void nsCookieService::SetCookieStringInternal(
nsAutoCString hostFromURI;
aHostURI->GetHost(hostFromURI);
CountCookiesFromHost(hostFromURI, &priorCookieCount);
CookieStatus cookieStatus = CheckPrefs(
cookieSettings, mThirdPartyNonsecureSession, aHostURI, aIsForeign,
aIsTrackingResource, aFirstPartyStorageAccessGranted, aCookieHeader.get(),
priorCookieCount, aOriginAttrs, &rejectedReason);
CookieStatus cookieStatus =
CheckPrefs(cookieSettings, aHostURI, aIsForeign, aIsTrackingResource,
aFirstPartyStorageAccessGranted, aCookieHeader.get(),
priorCookieCount, aOriginAttrs, &rejectedReason);
MOZ_ASSERT_IF(rejectedReason, cookieStatus == STATUS_REJECTED);
@ -2344,11 +2340,6 @@ void nsCookieService::PrefChanged(nsIPrefBranch* aPrefBranch) {
mCookiePurgeAge =
int64_t(LIMIT(val, 0, INT32_MAX, INT32_MAX)) * PR_USEC_PER_SEC;
}
bool boolval;
if (NS_SUCCEEDED(
aPrefBranch->GetBoolPref(kPrefThirdPartyNonsecureSession, &boolval)))
mThirdPartyNonsecureSession = boolval;
}
/******************************************************************************
@ -2996,10 +2987,10 @@ void nsCookieService::GetCookiesForURI(
uint32_t rejectedReason = aRejectedReason;
uint32_t priorCookieCount = 0;
CountCookiesFromHost(hostFromURI, &priorCookieCount);
CookieStatus cookieStatus = CheckPrefs(
cookieSettings, mThirdPartyNonsecureSession, aHostURI, aIsForeign,
aIsTrackingResource, aFirstPartyStorageAccessGranted, nullptr,
priorCookieCount, aOriginAttrs, &rejectedReason);
CookieStatus cookieStatus =
CheckPrefs(cookieSettings, aHostURI, aIsForeign, aIsTrackingResource,
aFirstPartyStorageAccessGranted, nullptr, priorCookieCount,
aOriginAttrs, &rejectedReason);
MOZ_ASSERT_IF(rejectedReason, cookieStatus == STATUS_REJECTED);
@ -3931,11 +3922,10 @@ static inline bool IsSubdomainOf(const nsCString& a, const nsCString& b) {
}
CookieStatus nsCookieService::CheckPrefs(
nsICookieSettings* aCookieSettings, bool aThirdPartyNonsecureSession,
nsIURI* aHostURI, bool aIsForeign, bool aIsTrackingResource,
bool aFirstPartyStorageAccessGranted, const char* aCookieHeader,
const int aNumOfCookies, const OriginAttributes& aOriginAttrs,
uint32_t* aRejectedReason) {
nsICookieSettings* aCookieSettings, nsIURI* aHostURI, bool aIsForeign,
bool aIsTrackingResource, bool aFirstPartyStorageAccessGranted,
const char* aCookieHeader, const int aNumOfCookies,
const OriginAttributes& aOriginAttrs, uint32_t* aRejectedReason) {
nsresult rv;
MOZ_ASSERT(aRejectedReason);
@ -4034,7 +4024,7 @@ CookieStatus nsCookieService::CheckPrefs(
return STATUS_ACCEPT_SESSION;
}
if (aThirdPartyNonsecureSession) {
if (StaticPrefs::network_cookie_thirdparty_nonsecureSessionOnly()) {
bool isHTTPS = false;
aHostURI->SchemeIs("https", &isHTTPS);
if (!isHTTPS) return STATUS_ACCEPT_SESSION;

View File

@ -213,11 +213,10 @@ class nsCookieService final : public nsICookieService,
nsIChannel* aChannel, bool& aSetCookie,
mozIThirdPartyUtil* aThirdPartyUtil);
static CookieStatus CheckPrefs(
nsICookieSettings* aCookieSettings, bool aThirdPartyNonsecureSession,
nsIURI* aHostURI, bool aIsForeign, bool aIsTrackingResource,
bool aIsFirstPartyStorageAccessGranted, const char* aCookieHeader,
const int aNumOfCookies, const OriginAttributes& aOriginAttrs,
uint32_t* aRejectedReason);
nsICookieSettings* aCookieSettings, nsIURI* aHostURI, bool aIsForeign,
bool aIsTrackingResource, bool aIsFirstPartyStorageAccessGranted,
const char* aCookieHeader, const int aNumOfCookies,
const OriginAttributes& aOriginAttrs, uint32_t* aRejectedReason);
static int64_t ParseServerTime(const nsCString& aServerTime);
static already_AddRefed<nsICookieSettings> GetCookieSettings(
@ -368,7 +367,6 @@ class nsCookieService final : public nsICookieService,
RefPtr<DBState> mDefaultDBState;
RefPtr<DBState> mPrivateDBState;
bool mThirdPartyNonsecureSession;
uint16_t mMaxNumberOfCookies;
uint16_t mMaxCookiesPerHost;
uint16_t mCookieQuotaPerHost;