Bug 1548253 - Port pref cache variables of nsContentUtils to StaticPrefs - privacy.donottrackheader.enabled, r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 01 May 2019 21:09:44 +0000
changeset 530993 10c31efa0b104462441fb807fb1de5bc056f444b
parent 530992 c64a91442fa0bb7547b1095970a53005ddb5aba1
child 530994 c1f3b933fcf9618533528c8460022040625c566f
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)
reviewersEhsan
bugs1548253
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 1548253 - Port pref cache variables of nsContentUtils to StaticPrefs - privacy.donottrackheader.enabled, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D29514
dom/base/Navigator.cpp
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -573,17 +573,17 @@ void Navigator::GetBuildID(nsAString& aB
     return;
   }
 
   aBuildID.Truncate();
   AppendASCIItoUTF16(buildID, aBuildID);
 }
 
 void Navigator::GetDoNotTrack(nsAString& aResult) {
-  bool doNotTrack = nsContentUtils::DoNotTrackEnabled();
+  bool doNotTrack = StaticPrefs::privacy_donottrackheader_enabled();
   if (!doNotTrack) {
     nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(mWindow);
     doNotTrack = loadContext && loadContext->UseTrackingProtection();
   }
 
   if (doNotTrack) {
     aResult.AssignLiteral("1");
   } else {
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -329,18 +329,16 @@ nsCString* nsContentUtils::sJSBytecodeMi
 nsContentUtils::UserInteractionObserver*
     nsContentUtils::sUserInteractionObserver = nullptr;
 
 nsHtml5StringParser* nsContentUtils::sHTMLFragmentParser = nullptr;
 nsIParser* nsContentUtils::sXMLFragmentParser = nullptr;
 nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr;
 bool nsContentUtils::sFragmentParsingActive = false;
 
-bool nsContentUtils::sDoNotTrackEnabled = false;
-
 bool nsContentUtils::sAntiTrackingControlCenterUIEnabled = false;
 
 mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump");
 
 int32_t nsContentUtils::sInnerOrOuterWindowCount = 0;
 uint32_t nsContentUtils::sInnerOrOuterWindowSerialCounter = 0;
 
 // Subset of
@@ -613,19 +611,16 @@ nsresult nsContentUtils::Init() {
     RegisterStrongMemoryReporter(new DOMEventListenerManagersHashReporter());
   }
 
   sBlockedScriptRunners = new AutoTArray<nsCOMPtr<nsIRunnable>, 8>;
 
   Preferences::AddBoolVarCache(&sAllowXULXBL_for_file,
                                "dom.allow_XUL_XBL_for_file");
 
-  Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
-                               "privacy.donottrackheader.enabled", false);
-
   Preferences::AddBoolVarCache(&sUseActivityCursor, "ui.use_activity_cursor",
                                false);
 
   Preferences::AddBoolVarCache(&sAnimationsAPICoreEnabled,
                                "dom.animations-api.core.enabled", false);
 
   Preferences::AddBoolVarCache(&sGetBoxQuadsEnabled,
                                "layout.css.getBoxQuads.enabled", false);
@@ -6968,20 +6963,16 @@ bool nsContentUtils::IsCORSSafelistedReq
          (aName.LowerCaseEqualsLiteral("accept-language") &&
           nsContentUtils::IsAllowedNonCorsLanguage(aValue)) ||
          (aName.LowerCaseEqualsLiteral("content-language") &&
           nsContentUtils::IsAllowedNonCorsLanguage(aValue)) ||
          (aName.LowerCaseEqualsLiteral("content-type") &&
           nsContentUtils::IsAllowedNonCorsContentType(aValue));
 }
 
-bool nsContentUtils::DoNotTrackEnabled() {
-  return nsContentUtils::sDoNotTrackEnabled;
-}
-
 mozilla::LogModule* nsContentUtils::DOMDumpLog() { return sDOMDumpLog; }
 
 bool nsContentUtils::GetNodeTextContent(nsINode* aNode, bool aDeep,
                                         nsAString& aResult,
                                         const fallible_t& aFallible) {
   aResult.Truncate();
   return AppendNodeTextContent(aNode, aDeep, aResult, aFallible);
 }
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2666,21 +2666,16 @@ class nsContentUtils {
    * Returns pointer to HTML editor instance for the aPresContext when there is.
    * The HTML editor is shared by contenteditable elements or used in
    * designMode.  When there are no contenteditable elements and the document
    * is not in designMode, this returns nullptr.
    */
   static mozilla::HTMLEditor* GetHTMLEditor(nsPresContext* aPresContext);
 
   /**
-   * Returns true if the privacy.donottrackheader.enabled pref is set.
-   */
-  static bool DoNotTrackEnabled();
-
-  /**
    * Returns a LogModule that dump calls from content script are logged to.
    * This can be enabled with the 'Dump' module, and is useful for synchronizing
    * content JS to other logging modules.
    */
   static mozilla::LogModule* DOMDumpLog();
 
   /**
    * Returns whether a given header is forbidden for an XHR or fetch
@@ -3486,17 +3481,16 @@ class nsContentUtils {
   static nsString* sOSText;
   static nsString* sAltText;
   static nsString* sModifierSeparator;
 
   // Alternate data mime type, used by the ScriptLoader to register and read the
   // bytecode out of the nsCacheInfoChannel.
   static nsCString* sJSBytecodeMimeType;
 
-  static bool sDoNotTrackEnabled;
   static mozilla::LazyLogModule sDOMDumpLog;
 
   static int32_t sInnerOrOuterWindowCount;
   static uint32_t sInnerOrOuterWindowSerialCounter;
 };
 
 /* static */ inline nsContentPolicyType
 nsContentUtils::InternalContentPolicyTypeToExternal(nsContentPolicyType aType) {
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -2351,16 +2351,23 @@ VARCACHE_PREF(
 
 // Spoof user locale to English
 VARCACHE_PREF(
   "privacy.spoof_english",
    privacy_spoof_english,
   RelaxedAtomicUint32, 0
 )
 
+// send "do not track" HTTP header, disabled by default
+VARCACHE_PREF(
+  "privacy.donottrackheader.enabled",
+   privacy_donottrackheader_enabled,
+  bool, false
+)
+
 // Lower the priority of network loads for resources on the tracking protection
 // list.  Note that this requires the
 // privacy.trackingprotection.annotate_channels pref to be on in order to have
 // any effect.
 #ifdef NIGHTLY_BUILD
 # define PREF_VALUE true
 #else
 # define PREF_VALUE false
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1412,18 +1412,16 @@ pref("privacy.restrict3rdpartystorage.us
 // Excessive reporting of blocked popups can be a DOS vector,
 // by overloading the main process as popups get blocked and when
 // users try to restore all popups, which is the most visible
 // option in our UI at the time of writing.
 // We will invisibly drop any popups from a page that has already
 // opened more than this number of popups.
 pref("privacy.popups.maxReported", 100);
 
-// send "do not track" HTTP header, disabled by default
-pref("privacy.donottrackheader.enabled",    false);
 // Enforce tracking protection in all modes
 // In Firefox Desktop this pref is set by browser.contentblocking.features.[standard, strict] see firefox.js for details.
 pref("privacy.trackingprotection.enabled",  false);
 // Enforce tracking protection in Private Browsing mode
 // In Firefox Desktop this pref is set by browser.contentblocking.features.[standard, strict] see firefox.js for details.
 pref("privacy.trackingprotection.pbmode.enabled",  true);
 // First Party Isolation (double keying), disabled by default
 pref("privacy.firstparty.isolate",                        false);
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -9641,17 +9641,17 @@ void nsHttpChannel::SetDoNotTrack() {
   /**
    * 'DoNotTrack' header should be added if 'privacy.donottrackheader.enabled'
    * is true or tracking protection is enabled. See bug 1258033.
    */
   nsCOMPtr<nsILoadContext> loadContext;
   NS_QueryNotificationCallbacks(this, loadContext);
 
   if ((loadContext && loadContext->UseTrackingProtection()) ||
-      nsContentUtils::DoNotTrackEnabled()) {
+      StaticPrefs::privacy_donottrackheader_enabled()) {
     DebugOnly<nsresult> rv = mRequestHead.SetHeader(
         nsHttp::DoNotTrack, NS_LITERAL_CSTRING("1"), false);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
   }
 }
 
 void nsHttpChannel::ReportRcwnStats(bool isFromNet) {
   if (!sRCWNEnabled) {
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -99,17 +99,16 @@
 #define UA_PREF_PREFIX "general.useragent."
 #ifdef XP_WIN
 #  define UA_SPARE_PLATFORM
 #endif
 
 #define HTTP_PREF_PREFIX "network.http."
 #define INTL_ACCEPT_LANGUAGES "intl.accept_languages"
 #define BROWSER_PREF_PREFIX "browser.cache."
-#define DONOTTRACK_HEADER_ENABLED "privacy.donottrackheader.enabled"
 #define H2MANDATORY_SUITE "security.ssl3.ecdhe_rsa_aes_128_gcm_sha256"
 #define SAFE_HINT_HEADER_VALUE "safeHint.enabled"
 #define SECURITY_PREFIX "security."
 
 #define TCP_FAST_OPEN_ENABLE "network.tcp.tcp_fastopen_enable"
 #define TCP_FAST_OPEN_FAILURE_LIMIT \
   "network.tcp.tcp_fastopen_consecutive_failure_limit"
 #define TCP_FAST_OPEN_STALLS_LIMIT "network.tcp.tcp_fastopen_http_stalls_limit"
@@ -248,17 +247,16 @@ nsHttpHandler::nsHttpHandler()
       mLegacyAppName("Mozilla"),
       mLegacyAppVersion("5.0"),
       mProduct("Gecko"),
       mCompatFirefoxEnabled(false),
       mUserAgentIsDirty(true),
       mAcceptLanguagesIsDirty(true),
       mPromptTempRedirect(true),
       mEnablePersistentHttpsCaching(false),
-      mDoNotTrackEnabled(false),
       mSafeHintEnabled(false),
       mParentalControlEnabled(false),
       mHandlerActive(false),
       mDebugObservations(false),
       mEnableSpdy(false),
       mHttp2Enabled(true),
       mUseH2Deps(true),
       mEnforceHttp2TlsProfile(true),
@@ -435,17 +433,16 @@ nsHttpHandler::~nsHttpHandler() {
   nsHttp::DestroyAtomTable();
 }
 
 static const char* gCallbackPrefs[] = {
     HTTP_PREF_PREFIX,
     UA_PREF_PREFIX,
     INTL_ACCEPT_LANGUAGES,
     BROWSER_PREF("disk_cache_ssl"),
-    DONOTTRACK_HEADER_ENABLED,
     H2MANDATORY_SUITE,
     HTTP_PREF("tcp_keepalive.short_lived_connections"),
     HTTP_PREF("tcp_keepalive.long_lived_connections"),
     SAFE_HINT_HEADER_VALUE,
     SECURITY_PREFIX,
     TCP_FAST_OPEN_ENABLE,
     TCP_FAST_OPEN_FAILURE_LIMIT,
     TCP_FAST_OPEN_STALLS_LIMIT,
@@ -1757,23 +1754,16 @@ void nsHttpHandler::PrefsChanged(const c
     // string resources.
     mAcceptLanguagesIsDirty = true;
   }
 
   //
   // Tracking options
   //
 
-  if (PREF_CHANGED(DONOTTRACK_HEADER_ENABLED)) {
-    cVar = false;
-    rv = Preferences::GetBool(DONOTTRACK_HEADER_ENABLED, &cVar);
-    if (NS_SUCCEEDED(rv)) {
-      mDoNotTrackEnabled = cVar;
-    }
-  }
   // Hint option
   if (PREF_CHANGED(SAFE_HINT_HEADER_VALUE)) {
     cVar = false;
     rv = Preferences::GetBool(SAFE_HINT_HEADER_VALUE, &cVar);
     if (NS_SUCCEEDED(rv)) {
       mSafeHintEnabled = cVar;
     }
   }
@@ -2205,17 +2195,17 @@ nsHttpHandler::Observe(nsISupports* subj
     gIOService->SetHttpHandlerAlreadyShutingDown();
 
     ShutdownConnectionManager();
 
     // need to reset the session start time since cache validation may
     // depend on this value.
     mSessionStartTime = NowInSeconds();
 
-    if (!mDoNotTrackEnabled) {
+    if (!StaticPrefs::privacy_donottrackheader_enabled()) {
       Telemetry::Accumulate(Telemetry::DNT_USAGE, 2);
     } else {
       Telemetry::Accumulate(Telemetry::DNT_USAGE, 1);
     }
 
     if (UseFastOpen()) {
       Telemetry::Accumulate(Telemetry::TCP_FAST_OPEN_STATUS, 0);
     } else if (!mFastOpenSupported) {
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -568,19 +568,16 @@ class nsHttpHandler final : public nsIHt
   bool mUserAgentIsDirty;  // true if mUserAgent should be rebuilt
   bool mAcceptLanguagesIsDirty;
 
   bool mPromptTempRedirect;
 
   // Persistent HTTPS caching flag
   bool mEnablePersistentHttpsCaching;
 
-  // For broadcasting tracking preference
-  bool mDoNotTrackEnabled;
-
   // for broadcasting safe hint;
   bool mSafeHintEnabled;
   bool mParentalControlEnabled;
 
   // true in between init and shutdown states
   Atomic<bool, Relaxed> mHandlerActive;
 
   // The value of 'hidden' network.http.debug-observations : 1;