Bug 1476217 - Part 2 - Add a "Restore Defaults" button to Content Blocking preferences. r=jaws
MozReview-Commit-ID: Dhiph7jmTbV
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -424,25 +424,49 @@ var gPrivacyPane = {
/**
* Initializes the content blocking section.
*/
initContentBlocking() {
let contentBlockingCheckbox = document.getElementById("contentBlockingCheckbox");
setEventListener("contentBlockingToggle", "command",
() => contentBlockingCheckbox.click());
setEventListener("changeBlockListLink", "click", this.showBlockLists);
+ setEventListener("contentBlockingRestoreDefaults", "command",
+ this.restoreContentBlockingPrefs);
setEventListener("trackingProtectionMenu", "command",
this.trackingProtectionWritePrefs);
let link = document.getElementById("contentBlockingLearnMore");
let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "tracking-protection";
link.setAttribute("href", url);
},
/**
+ * Resets all user-exposed content blocking preferences to their default values.
+ */
+ async restoreContentBlockingPrefs() {
+ function clearIfNotLocked(pref) {
+ if (!Services.prefs.prefIsLocked(pref)) {
+ Services.prefs.clearUserPref(pref);
+ }
+ }
+
+ clearIfNotLocked("browser.contentblocking.enabled");
+ clearIfNotLocked("urlclassifier.trackingTable");
+
+ let controllingExtension = await getControllingExtension(
+ PREF_SETTING_TYPE, TRACKING_PROTECTION_KEY);
+ if (!controllingExtension) {
+ for (let preference of TRACKING_PROTECTION_PREFS) {
+ clearIfNotLocked(preference);
+ }
+ }
+ },
+
+ /**
* Changes the visibility of elements in the TP/CB section depending on the
* content blocking UI pref.
*/
updateContentBlockingVisibility() {
let visibleState = {
"contentBlockingHeader": true,
"contentBlockingDescription": true,
"contentBlockingLearnMore": true,
--- a/browser/components/preferences/in-content/privacy.xul
+++ b/browser/components/preferences/in-content/privacy.xul
@@ -293,16 +293,23 @@
<html:a id="trackingProtectionLearnMore" data-l10n-name="learn-more" target="_blank" class="learnMore text-link"/>
</description>
<description id="contentBlockingDescription" class="description-with-side-element" data-l10n-id="content-blocking-desc"></description>
<label id="contentBlockingLearnMore" data-l10n-id="content-blocking-learn-more" class="learnMore text-link"/>
</vbox>
<vbox>
<!-- Please don't remove the wrapping hbox/vbox/box for these elements. It's used to properly compute the search tooltip position. -->
<hbox>
+ <button id="contentBlockingRestoreDefaults"
+ class="accessory-button"
+ flex="1"
+ data-l10n-id="content-blocking-restore-defaults"/>
+ </hbox>
+ <!-- Please don't remove the wrapping hbox/vbox/box for these elements. It's used to properly compute the search tooltip position. -->
+ <hbox>
<button id="trackingProtectionExceptions"
class="accessory-button"
flex="1"
data-l10n-id="tracking-exceptions"
preference="pref.privacy.disable_button.tracking_protection_exceptions"
search-l10n-ids="
permissions-remove.label,
permissions-remove-all.label,
--- a/browser/locales/en-US/browser/preferences/preferences.ftl
+++ b/browser/locales/en-US/browser/preferences/preferences.ftl
@@ -791,16 +791,19 @@ addressbar-suggestions-settings = Change
## Privacy Section - Content Blocking
content-blocking-header = Content Blocking
content-blocking-desc = Block third-party content, like ads or code, that can slow your browsing and track you around the web. Customize your settings for the best balance of protection and performance.
content-blocking-learn-more = Learn More
+content-blocking-restore-defaults =
+ .label = Restore Defaults
+ .accesskey = R
content-blocking-toggle-on =
.tooltiptext = Turn Off Content Blocking
content-blocking-toggle-off =
.tooltiptext = Turn On Content Blocking
content-blocking-toggle-label-on = ON
.accesskey = O