From 2d62042b5cdf0a41df055805f77c9f295fccb6c9 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 24 Aug 2018 15:33:04 -0400 Subject: [PATCH] Bug 1486092 - Part 1: Move the browser.contentblocking.enabled pref to StaticPrefs; r=baku --- browser/app/profile/firefox.js | 1 - docshell/base/nsDocShell.cpp | 9 ++++----- modules/libpref/init/StaticPrefList.h | 7 +++++++ netwerk/protocol/http/nsHttpChannel.cpp | 5 ++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 3ddc8aeef556..6d9d1fd3dd01 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1487,7 +1487,6 @@ pref("browser.ping-centre.production.endpoint", "https://tiles.services.mozilla. // Enable GMP support in the addon manager. pref("media.gmp-provider.enabled", true); -pref("browser.contentblocking.enabled", true); pref("browser.contentblocking.cookies-site-data.ui.reject-trackers.recommended", true); pref("browser.contentblocking.fastblock.control-center.ui.enabled", true); pref("browser.contentblocking.trackingprotection.control-center.ui.enabled", true); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 70588b46f085..260729f8e505 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -29,6 +29,7 @@ #include "mozilla/Preferences.h" #include "mozilla/ResultExtensions.h" #include "mozilla/Services.h" +#include "mozilla/StaticPrefs.h" #include "mozilla/StartupTimeline.h" #include "mozilla/Telemetry.h" #include "mozilla/Unused.h" @@ -13115,23 +13116,21 @@ nsDocShell::GetUseTrackingProtection(bool* aUseTrackingProtection) { *aUseTrackingProtection = false; - static bool sCBEnabled = false; + bool cbEnabled = StaticPrefs::browser_contentblocking_enabled(); static bool sTPEnabled = false; static bool sTPInPBEnabled = false; static bool sPrefsInit = false; if (!sPrefsInit) { sPrefsInit = true; - Preferences::AddBoolVarCache(&sCBEnabled, - "browser.contentblocking.enabled", true); Preferences::AddBoolVarCache(&sTPEnabled, "privacy.trackingprotection.enabled", false); Preferences::AddBoolVarCache(&sTPInPBEnabled, "privacy.trackingprotection.pbmode.enabled", false); } - if (mUseTrackingProtection || (sCBEnabled && sTPEnabled) || - (sCBEnabled && UsePrivateBrowsing() && sTPInPBEnabled)) { + if (mUseTrackingProtection || (cbEnabled && sTPEnabled) || + (cbEnabled && UsePrivateBrowsing() && sTPInPBEnabled)) { *aUseTrackingProtection = true; return NS_OK; } diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index 9f3bc1d74a02..dbd499c1cac6 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -1246,6 +1246,13 @@ PREF("preferences.allow.omt-write", bool, true) // Privacy prefs //--------------------------------------------------------------------------- +// Whether Content Blocking has been enabled +VARCACHE_PREF( + "browser.contentblocking.enabled", + browser_contentblocking_enabled, + bool, true +) + VARCACHE_PREF( "privacy.restrict3rdpartystorage.ui.enabled", privacy_restrict3rdpartystorage_ui_enabled, diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 5cff8c365d66..f0b5c00d0a79 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -695,13 +695,11 @@ nsHttpChannel::CheckFastBlocked() LOG(("nsHttpChannel::CheckFastBlocked [this=%p]\n", this)); static bool sFastBlockInited = false; - static bool sIsContentBlockingEnabled = false; static bool sIsFastBlockEnabled = false; static uint32_t sFastBlockTimeout = 0; if (!sFastBlockInited) { sFastBlockInited = true; - Preferences::AddBoolVarCache(&sIsContentBlockingEnabled, "browser.contentblocking.enabled"); Preferences::AddBoolVarCache(&sIsFastBlockEnabled, "browser.fastblock.enabled"); Preferences::AddUintVarCache(&sFastBlockTimeout, "browser.fastblock.timeout"); } @@ -711,7 +709,8 @@ nsHttpChannel::CheckFastBlocked() return false; } - if (!sIsContentBlockingEnabled || !sIsFastBlockEnabled || + if (!StaticPrefs::browser_contentblocking_enabled() || + !sIsFastBlockEnabled || IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo) || !timestamp) { return false;