Bug 1547114 - Part 6: Convert network.cookie.lifetimePolicy into a static pref; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 26 Apr 2019 15:42:01 +0000
changeset 530371 246b613845d3879b528ddd789ce10a6fd67e4772
parent 530370 e28229a014fa7884169dfc22dfc949bef16540a1
child 530372 fb9c7644874e516e5db3298c25b5b7d17aff2886
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1547114
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1547114 - Part 6: Convert network.cookie.lifetimePolicy into a static pref; r=baku Differential Revision: https://phabricator.services.mozilla.com/D28997
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
extensions/cookie/nsCookiePermission.cpp
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -339,19 +339,16 @@ nsCString* nsContentUtils::sJSBytecodeMi
 int32_t nsContentUtils::sPrivacyMaxInnerWidth = 1000;
 int32_t nsContentUtils::sPrivacyMaxInnerHeight = 1000;
 
 nsContentUtils::UserInteractionObserver*
     nsContentUtils::sUserInteractionObserver = nullptr;
 
 uint32_t nsContentUtils::sHandlingInputTimeout = 1000;
 
-uint32_t nsContentUtils::sCookiesLifetimePolicy =
-    nsICookieService::ACCEPT_NORMALLY;
-
 nsHtml5StringParser* nsContentUtils::sHTMLFragmentParser = nullptr;
 nsIParser* nsContentUtils::sXMLFragmentParser = nullptr;
 nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr;
 bool nsContentUtils::sFragmentParsingActive = false;
 
 bool nsContentUtils::sDoNotTrackEnabled = false;
 
 bool nsContentUtils::sAntiTrackingControlCenterUIEnabled = false;
@@ -674,20 +671,16 @@ nsresult nsContentUtils::Init() {
 
   Preferences::AddUintVarCache(
       &sHandlingInputTimeout, "dom.event.handling-user-input-time-limit", 1000);
 
   Preferences::AddBoolVarCache(
       &sSendPerformanceTimingNotifications,
       "dom.performance.enable_notify_performance_timing", false);
 
-  Preferences::AddUintVarCache(&sCookiesLifetimePolicy,
-                               "network.cookie.lifetimePolicy",
-                               nsICookieService::ACCEPT_NORMALLY);
-
   Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
                                "privacy.donottrackheader.enabled", false);
 
   Preferences::AddBoolVarCache(&sUseActivityCursor, "ui.use_activity_cursor",
                                false);
 
   Preferences::AddBoolVarCache(&sAnimationsAPICoreEnabled,
                                "dom.animations-api.core.enabled", false);
@@ -8279,17 +8272,17 @@ nsContentUtils::StorageAccess nsContentU
   return InternalStorageAllowedCheck(aPrincipal, nullptr, nullptr, nullptr,
                                      rejectedReason);
 }
 
 // static, private
 void nsContentUtils::GetCookieLifetimePolicyFromCookieSettings(
     nsICookieSettings* aCookieSettings, nsIPrincipal* aPrincipal,
     uint32_t* aLifetimePolicy) {
-  *aLifetimePolicy = sCookiesLifetimePolicy;
+  *aLifetimePolicy = StaticPrefs::network_cookie_lifetimePolicy();
 
   if (aCookieSettings) {
     uint32_t cookiePermission = 0;
     nsresult rv =
         aCookieSettings->CookiePermission(aPrincipal, &cookiePermission);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return;
     }
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -3355,21 +3355,16 @@ class nsContentUtils {
   /**
    * Returns true if the top level ancestor content document of aDocument hasn't
    * yet had the first contentful paint and there is a high priority event
    * pending in the main thread.
    */
   static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
       Document* aDocument);
 
-  /**
-   * Gets the global cookie lifetime policy.
-   */
-  static uint32_t GetCookieLifetimePolicy() { return sCookiesLifetimePolicy; }
-
  private:
   static bool InitializeEventTable();
 
   static nsresult EnsureStringBundle(PropertiesFile aFile);
 
   static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
                               nsIPrincipal* aPrincipal);
 
@@ -3508,17 +3503,16 @@ class nsContentUtils {
   static bool sTailingEnabled;
   static bool sShowInputPlaceholderOnFocus;
   static bool sAutoFocusEnabled;
 #ifndef RELEASE_OR_BETA
   static bool sBypassCSSOMOriginCheck;
 #endif
   static bool sIsBytecodeCacheEnabled;
   static int32_t sBytecodeCacheStrategy;
-  static uint32_t sCookiesLifetimePolicy;
   static bool sAntiTrackingControlCenterUIEnabled;
 
   static int32_t sPrivacyMaxInnerWidth;
   static int32_t sPrivacyMaxInnerHeight;
 
   class UserInteractionObserver;
   static UserInteractionObserver* sUserInteractionObserver;
 
--- a/extensions/cookie/nsCookiePermission.cpp
+++ b/extensions/cookie/nsCookiePermission.cpp
@@ -26,16 +26,18 @@
 #include "prtime.h"
 #include "mozilla/StaticPtr.h"
 #include "nsContentUtils.h"
 
 /****************************************************************
  ************************ nsCookiePermission ********************
  ****************************************************************/
 
+using namespace mozilla;
+
 static const bool kDefaultPolicy = true;
 
 static const nsLiteralCString kPermissionType(NS_LITERAL_CSTRING("cookie"));
 
 namespace {
 mozilla::StaticRefPtr<nsCookiePermission> gSingleton;
 }
 
@@ -103,30 +105,30 @@ nsCookiePermission::CanSetCookie(nsIURI 
       *aResult = false;
       break;
 
     default:
       // Here we can have any legacy permission value.
 
       // now we need to figure out what type of accept policy we're dealing with
       // if we accept cookies normally, just bail and return
-      if (nsContentUtils::GetCookieLifetimePolicy() ==
+      if (StaticPrefs::network_cookie_lifetimePolicy() ==
           nsICookieService::ACCEPT_NORMALLY) {
         *aResult = true;
         return NS_OK;
       }
 
       // declare this here since it'll be used in all of the remaining cases
       int64_t currentTime = PR_Now() / PR_USEC_PER_SEC;
       int64_t delta = *aExpiry - currentTime;
 
       // We are accepting the cookie, but,
       // if it's not a session cookie, we may have to limit its lifetime.
       if (!*aIsSession && delta > 0) {
-        if (nsContentUtils::GetCookieLifetimePolicy() ==
+        if (StaticPrefs::network_cookie_lifetimePolicy() ==
             nsICookieService::ACCEPT_SESSION) {
           // limit lifetime to session
           *aIsSession = true;
         }
       }
   }
 
   return NS_OK;
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -1959,16 +1959,27 @@ VARCACHE_PREF(
 // Keep the old default of accepting all cookies
 // In Firefox Desktop this pref is set by browser.contentblocking.features.[standard, strict] see firefox.js for details.
 VARCACHE_PREF(
   "network.cookie.cookieBehavior",
   network_cookie_cookieBehavior,
   RelaxedAtomicInt32, 0
 )
 
+// Cookie lifetime policy. Possible values:
+// 0 - accept all cookies
+// 1 - deprecated. don't use it.
+// 2 - accept as session cookies
+// 3 - deprecated. don't use it.
+VARCACHE_PREF(
+  "network.cookie.lifetimePolicy",
+  network_cookie_lifetimePolicy,
+  RelaxedAtomicInt32, 0
+)
+
 // Enables the predictive service.
 VARCACHE_PREF(
   "network.predictor.enabled",
    network_predictor_enabled,
   bool, true
 )
 
 // Allow CookieSettings to be unblocked for channels without a document.
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2404,23 +2404,16 @@ pref("network.proxy.no_proxies_on",     
 // Set true to allow resolving proxy for localhost
 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.sessionOnly", false);
 pref("network.cookie.thirdparty.nonsecureSessionOnly", false);
 pref("network.cookie.same-site.enabled",    true); // Honor the SameSite cookie attribute
 
-// Cookie lifetime policy. Possible values:
-// 0 - accept all cookies
-// 1 - deprecated. don't use it.
-// 2 - accept as session cookies
-// 3 - deprecated. don't use it.
-pref("network.cookie.lifetimePolicy",       0);
-
 // The interval in seconds to move the cookies in the child process.
 // Set to 0 to disable moving the cookies.
 pref("network.cookie.move.interval_sec",    10);
 
 pref("network.cookie.maxNumber", 3000);
 pref("network.cookie.maxPerHost", 180);
 // Cookies quota for each host. If cookies exceed the limit maxPerHost,
 // (maxPerHost - quotaPerHost) cookies will be evicted.