Bug 1458308 - Change about:preferences to use the new auto update pref mechanism r=flod,jaws
☠☠ backed out by f8c4d4c647ae ☠ ☠
authorKirk Steuber <ksteuber@mozilla.com>
Mon, 29 Oct 2018 21:30:36 +0000
changeset 499962 99317c8cd24700297ba75c0c450fb1fe9b852884
parent 499961 7370877bd9e1c0276e486dfe16ff23eac202a833
child 499963 51e675ce6c5626ee1feb5e125c7aa16867e5f213
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflod, jaws
bugs1458308
milestone65.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 1458308 - Change about:preferences to use the new auto update pref mechanism r=flod,jaws Depends on D4590 Differential Revision: https://phabricator.services.mozilla.com/D4591
browser/components/preferences/in-content/main.js
browser/components/preferences/in-content/main.xul
browser/locales/en-US/browser/preferences/preferences.ftl
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -15,16 +15,17 @@ ChromeUtils.import("resource:///modules/
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm");
 ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
 ChromeUtils.import("resource://gre/modules/Localization.jsm");
 ChromeUtils.defineModuleGetter(this, "CloudStorage",
   "resource://gre/modules/CloudStorage.jsm");
 
 XPCOMUtils.defineLazyServiceGetters(this, {
+  gAUS: ["@mozilla.org/updates/update-service;1", "nsIApplicationUpdateService"],
   gHandlerService: ["@mozilla.org/uriloader/handler-service;1", "nsIHandlerService"],
   gMIMEService: ["@mozilla.org/mime;1", "nsIMIMEService"],
 });
 
 // Constants & Enumeration Values
 const TYPE_PDF = "application/pdf";
 
 const PREF_PDFJS_DISABLED = "pdfjs.disabled";
@@ -38,16 +39,18 @@ const PREF_CONTAINERS_EXTENSION = "priva
 // Preferences that affect which entries to show in the list.
 const PREF_SHOW_PLUGINS_IN_LIST = "browser.download.show_plugins_in_list";
 const PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS =
   "browser.download.hide_plugins_without_extensions";
 
 // Strings to identify ExtensionSettingsStore overrides
 const CONTAINERS_KEY = "privacy.containers";
 
+const AUTO_UPDATE_CHANGED_TOPIC = "auto-update-config-change";
+
 // The nsHandlerInfoAction enumeration values in nsIHandlerInfo identify
 // the actions the application can take with content of various types.
 // But since nsIHandlerInfo doesn't support plugins, there's no value
 // identifying the "use plugin" action, so we use this constant instead.
 const kActionUsePlugin = 5;
 
 const ICON_URL_APP = AppConstants.platform == "linux" ?
   "moz-icon://dummy.exe?size=16" :
@@ -170,17 +173,16 @@ if (AppConstants.platform === "win") {
   Preferences.addAll([
     { id: "browser.taskbar.previews.enable", type: "bool" },
     { id: "ui.osk.enabled", type: "bool" },
   ]);
 }
 
 if (AppConstants.MOZ_UPDATER) {
   Preferences.addAll([
-    { id: "app.update.auto", type: "bool" },
     { id: "app.update.disable_button.showUpdateHistory", type: "bool" },
   ]);
 
   if (AppConstants.MOZ_MAINTENANCE_SERVICE) {
     Preferences.addAll([
       { id: "app.update.service.enabled", type: "bool" },
     ]);
   }
@@ -476,16 +478,24 @@ var gMainPane = {
         gMainPane.showUpdates);
 
       if (Services.policies && !Services.policies.isAllowed("appUpdate")) {
         document.getElementById("updateAllowDescription").hidden = true;
         document.getElementById("updateRadioGroup").hidden = true;
         if (AppConstants.MOZ_MAINTENANCE_SERVICE) {
           document.getElementById("useService").hidden = true;
         }
+      } else {
+        // Start with no option selected since we are still reading the value
+        document.getElementById("autoDesktop").removeAttribute("selected");
+        document.getElementById("manualDesktop").removeAttribute("selected");
+        // Start reading the correct value from the disk
+        this.updateReadPrefs();
+        setEventListener("updateRadioGroup", "command",
+                         gMainPane.updateWritePrefs);
       }
 
       if (AppConstants.MOZ_MAINTENANCE_SERVICE) {
         // Check to see if the maintenance service is installed.
         // If it isn't installed, don't show the preference at all.
         let installed;
         try {
           let wrk = Cc["@mozilla.org/windows-registry-key;1"]
@@ -504,16 +514,17 @@ var gMainPane = {
     }
 
     // Initilize Application section.
 
     // Observe preferences that influence what we display so we can rebuild
     // the view when they change.
     Services.prefs.addObserver(PREF_SHOW_PLUGINS_IN_LIST, this);
     Services.prefs.addObserver(PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS, this);
+    Services.obs.addObserver(this, AUTO_UPDATE_CHANGED_TOPIC);
 
     setEventListener("filter", "command", gMainPane.filter);
     setEventListener("typeColumn", "click", gMainPane.sort);
     setEventListener("actionColumn", "click", gMainPane.sort);
     setEventListener("chooseFolder", "command", gMainPane.chooseFolder);
     setEventListener("saveWhere", "command", gMainPane.handleSaveToCommand);
     Preferences.get("browser.download.folderList").on("change",
       gMainPane.displayDownloadDirPref.bind(gMainPane));
@@ -1270,28 +1281,81 @@ var gMainPane = {
       document.getElementById("limitContentProcess").disabled = true;
       document.getElementById("contentProcessCount").disabled = true;
       document.getElementById("contentProcessCountEnabledDescription").hidden = true;
       document.getElementById("contentProcessCountDisabledDescription").hidden = false;
     }
   },
 
   /**
+   * Selects the correct item in the update radio group
+   */
+  async updateReadPrefs() {
+    if (AppConstants.MOZ_UPDATER &&
+        (!Services.policies || Services.policies.isAllowed("appUpdate"))) {
+      let radiogroup = document.getElementById("updateRadioGroup");
+      radiogroup.disabled = true;
+      try {
+        let enabled = await gAUS.getAutoUpdateIsEnabled();
+        radiogroup.value = enabled;
+        radiogroup.disabled = false;
+      } catch (error) {
+        Cu.reportError(error);
+      }
+    }
+  },
+
+  /**
+   * Writes the value of the update radio group to the disk
+   */
+  async updateWritePrefs() {
+    if (AppConstants.MOZ_UPDATER &&
+        (!Services.policies || Services.policies.isAllowed("appUpdate"))) {
+      let radiogroup = document.getElementById("updateRadioGroup");
+      let updateAutoValue = (radiogroup.value == "true");
+      radiogroup.disabled = true;
+      try {
+        await gAUS.setAutoUpdateIsEnabled(updateAutoValue);
+        radiogroup.disabled = false;
+      } catch (error) {
+        Cu.reportError(error);
+        await this.updateReadPrefs();
+        await this.reportUpdatePrefWriteError(error);
+      }
+    }
+  },
+
+  async reportUpdatePrefWriteError(error) {
+    let [title, message] = await document.l10n.formatValues([
+      {id: "update-pref-write-failure-title"},
+      {id: "update-pref-write-failure-message", args: {path: error.path}},
+    ]);
+
+    // Set up the Ok Button
+    let buttonFlags = (Services.prompt.BUTTON_POS_0 *
+                       Services.prompt.BUTTON_TITLE_OK);
+    Services.prompt.confirmEx(window, title, message, buttonFlags,
+                              null, null, null, null, {});
+  },
+
+  /**
    * Displays the history of installed updates.
    */
   showUpdates() {
     gSubDialog.open("chrome://mozapps/content/update/history.xul");
   },
 
   destroy() {
     window.removeEventListener("unload", this);
     Services.prefs.removeObserver(PREF_SHOW_PLUGINS_IN_LIST, this);
     Services.prefs.removeObserver(PREF_HIDE_PLUGINS_WITHOUT_EXTENSIONS, this);
 
     Services.prefs.removeObserver(PREF_CONTAINERS_EXTENSION, this);
+
+    Services.obs.removeObserver(this, AUTO_UPDATE_CHANGED_TOPIC);
   },
 
 
   // nsISupports
 
   QueryInterface: ChromeUtils.generateQI([Ci.nsIObserver]),
 
   // nsIObserver
@@ -1312,16 +1376,21 @@ var gMainPane = {
           await this._rebuildVisibleTypes();
           this._sortVisibleTypes();
         }
 
         // All the prefs we observe can affect what we display, so we rebuild
         // the view when any of them changes.
         this._rebuildView();
       }
+    } else if (aTopic == AUTO_UPDATE_CHANGED_TOPIC) {
+      if (aData != "true" && aData != "false") {
+        throw new Error("Invalid preference value for app.update.auto");
+      }
+      document.getElementById("updateRadioGroup").value = aData;
     }
   },
 
 
   // EventListener
 
   handleEvent(aEvent) {
     if (aEvent.type == "unload") {
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -555,21 +555,22 @@
                 disabled="true"/>
       </hbox>
     </deck>
   </vbox>
 #endif
 
 #ifdef MOZ_UPDATER
   <description id="updateAllowDescription" data-l10n-id="update-application-allow-description"></description>
-  <radiogroup id="updateRadioGroup" preference="app.update.auto">
+  <radiogroup id="updateRadioGroup">
     <radio id="autoDesktop"
            value="true"
            data-l10n-id="update-application-auto"/>
-    <radio value="false"
+    <radio id="manualDesktop"
+           value="false"
            data-l10n-id="update-application-check-choose"/>
   </radiogroup>
 #ifdef MOZ_MAINTENANCE_SERVICE
   <checkbox id="useService"
             data-l10n-id="update-application-use-service"
             preference="app.update.service.enabled"/>
 #endif
 #endif
--- a/browser/locales/en-US/browser/preferences/preferences.ftl
+++ b/browser/locales/en-US/browser/preferences/preferences.ftl
@@ -355,16 +355,22 @@ update-application-manual =
 update-application-use-service =
     .label = Use a background service to install updates
     .accesskey = b
 
 update-enable-search-update =
     .label = Automatically update search engines
     .accesskey = e
 
+update-pref-write-failure-title = Write Failure
+
+# Variables:
+#   $path (String) - Path to the configuration file
+update-pref-write-failure-message = Unable to save preference. Could not write to file: { $path }
+
 ## General Section - Performance
 
 performance-title = Performance
 
 performance-use-recommended-settings-checkbox =
     .label = Use recommended performance settings
     .accesskey = U