From 2b07a1676549b433785d261b09c05cdf452ab0ac Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Tue, 13 Apr 2021 18:07:10 +0000 Subject: [PATCH] Bug 1698843 - Part 2: Make the private cookieBehavior getter to return the regular pref if there is a user value for the regular pref. r=johannh,dimi If the user has a non-default regular cookieBehavior, we will make the private cookieBehavior getter to return the regular pref to mirror the cookieBehavior in ETP custom mode. In addition, we don't need to do the pref migration because if the user has a non-default cookieBehavior, it will directly mirror to the private cookieBehavior pref so that the cookieBehavior is consistent for private mode. Differential Revision: https://phabricator.services.mozilla.com/D111002 --- netwerk/cookie/CookieService.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/netwerk/cookie/CookieService.cpp b/netwerk/cookie/CookieService.cpp index 5bb468463c4c..ef55f378d3e8 100644 --- a/netwerk/cookie/CookieService.cpp +++ b/netwerk/cookie/CookieService.cpp @@ -50,6 +50,26 @@ uint32_t MakeCookieBehavior(uint32_t aCookieBehavior) { // static uint32_t nsICookieManager::GetCookieBehavior(bool aIsPrivate) { if (aIsPrivate) { + // To sync the cookieBehavior pref between regular and private mode in ETP + // custom mode, we will return the regular cookieBehavior pref for private + // mode when + // 1. The regular cookieBehavior pref has a non-default value. + // 2. And the private cookieBehavior pref has a default value. + // Also, this can cover the migration case where the user has a non-default + // cookieBehavior before the private cookieBehavior was introduced. The + // getter here will directly return the regular cookieBehavior, so that the + // cookieBehavior for private mode is consistent. + if (mozilla::Preferences::HasUserValue( + "network.cookie.cookieBehavior.pbmode")) { + return MakeCookieBehavior( + mozilla::StaticPrefs::network_cookie_cookieBehavior_pbmode()); + } + + if (mozilla::Preferences::HasUserValue("network.cookie.cookieBehavior")) { + return MakeCookieBehavior( + mozilla::StaticPrefs::network_cookie_cookieBehavior()); + } + return MakeCookieBehavior( mozilla::StaticPrefs::network_cookie_cookieBehavior_pbmode()); }