Bug 1476217 - Part 2 - Add a "Restore Defaults" button to Content Blocking preferences. r=jaws draft
authorJohann Hofmann <jhofmann@mozilla.com>
Mon, 23 Jul 2018 13:07:29 +0200
changeset 825734 f36084a86f7286999f92729e0a00e2d700f078de
parent 825733 04efae13fd02211bb1610b7693769a74a5ff6df5
child 825735 de9ea03089b3b2ed7984b6943a48cc3dd0c7f2c3
push id118155
push userjhofmann@mozilla.com
push dateThu, 02 Aug 2018 06:20:22 +0000
reviewersjaws
bugs1476217
milestone63.0a1
Bug 1476217 - Part 2 - Add a "Restore Defaults" button to Content Blocking preferences. r=jaws MozReview-Commit-ID: Dhiph7jmTbV
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/privacy.xul
browser/locales/en-US/browser/preferences/preferences.ftl
--- 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