Bug 1515078 - Add opt out UX in about:preferences for Pocket Newtab r=Mardak
authorAndrei Oprea <andrei.br92@gmail.com>
Fri, 18 Jan 2019 14:51:17 +0000
changeset 511556 3e975e4b35581bf59856f275d8fe56c7667d8b84
parent 511555 0e161fee4d4483d1deaad69db6cf5a5ea59287e9
child 511557 10d517464fb1ba1ea73ddcaea039e32f4f4116f6
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1515078
milestone66.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 1515078 - Add opt out UX in about:preferences for Pocket Newtab r=Mardak Differential Revision: https://phabricator.services.mozilla.com/D16539
browser/components/preferences/in-content/home.js
--- a/browser/components/preferences/in-content/home.js
+++ b/browser/components/preferences/in-content/home.js
@@ -38,16 +38,29 @@ var gHomePane = {
   HOME_MODE_CUSTOM: "2",
   NEWTAB_ENABLED_PREF: "browser.newtabpage.enabled",
   ACTIVITY_STREAM_PREF_BRANCH: "browser.newtabpage.activity-stream.",
 
   get homePanePrefs() {
     return Preferences.getAll().filter(pref => pref.id.includes(this.ACTIVITY_STREAM_PREF_BRANCH));
   },
 
+  get isPocketNewtabEnabled() {
+    const value = Services.prefs.getStringPref("browser.newtabpage.activity-stream.discoverystream.config", "");
+    if (value) {
+      try {
+        return JSON.parse(value).enabled;
+      } catch (e) {
+        console.error("Failed to parse Discovery Stream pref.");
+      }
+    }
+
+    return false;
+  },
+
   /**
    * _handleNewTabOverrides: disables new tab settings UI. Called by
    * an observer in ._watchNewTab that watches for new tab url changes
    */
   async _handleNewTabOverrides() {
     const isControlled = await handleControllingExtension(
       URL_OVERRIDES_TYPE, NEW_TAB_KEY);
     const el = document.getElementById("newTabMode");
@@ -376,17 +389,18 @@ var gHomePane = {
     const value = event.target.value || homePref.defaultValue;
     homePref.value = value;
   },
 
   /**
    * Check all Home Tab preferences for user set values.
    */
   _changedHomeTabDefaultPrefs() {
-    const homeContentChanged = this.homePanePrefs.some(pref => pref.hasUserValue);
+    // If Discovery Stream is enabled Firefox Home Content preference options are hidden
+    const homeContentChanged = !this.isPocketNewtabEnabled && this.homePanePrefs.some(pref => pref.hasUserValue);
     const homePref = Preferences.get("browser.startup.homepage");
     const newtabPref = Preferences.get(this.NEWTAB_ENABLED_PREF);
 
     return homeContentChanged || homePref.hasUserValue || newtabPref.hasUserValue;
   },
 
   /**
    * Show the Restore Defaults button if any preference on the Home tab was
@@ -398,17 +412,20 @@ var gHomePane = {
     btn.style.visibility = prefChanged ? "visible" : "hidden";
   },
 
   /**
    * Set all prefs on the Home tab back to their default values.
    */
   restoreDefaultPrefsForHome() {
     this.restoreDefaultHomePage();
-    this.homePanePrefs.forEach(pref => Services.prefs.clearUserPref(pref.id));
+    // If Discovery Stream is enabled Firefox Home Content preference options are hidden
+    if (!this.isPocketNewtabEnabled) {
+      this.homePanePrefs.forEach(pref => Services.prefs.clearUserPref(pref.id));
+    }
   },
 
   init() {
     // Event Listeners
     document.getElementById("homeMode").addEventListener("command", this.onMenuChange.bind(this));
     document.getElementById("homePageUrl").addEventListener("change", this.onCustomHomePageChange.bind(this));
     document.getElementById("homePageUrl").addEventListener("input", this.onCustomHomePageInput.bind(this));
     document.getElementById("useCurrentBtn").addEventListener("command", this.setHomePageToCurrent.bind(this));