Bug 750554 - If service is not used for updates then do not show it in preferences. r=bbondy
authorPranav Ravichandran <prp.1111@gmail.com>
Thu, 31 May 2012 10:28:01 -0400
changeset 97735 68abc86fde1c736611ea09db5099d2363cc1c24e
parent 97734 f24ce56de72f08504fdd7ba7390ada0b398164d7
child 97745 5199196b65ec6bafc1fe877729f336c4db7d9abd
push id1439
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 20:19:22 +0000
treeherdermozilla-aurora@ea74834dccd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy
bugs750554
milestone15.0a1
Bug 750554 - If service is not used for updates then do not show it in preferences. r=bbondy
browser/components/preferences/advanced.js
toolkit/mozapps/update/nsIUpdateService.idl
toolkit/mozapps/update/nsUpdateService.js
--- a/browser/components/preferences/advanced.js
+++ b/browser/components/preferences/advanced.js
@@ -1,15 +1,16 @@
 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 // Load DownloadUtils module for convertByteUnits
 Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
+Components.utils.import("resource://gre/modules/ctypes.jsm");
 
 var gAdvancedPane = {
   _inited: false,
 
   /**
    * Brings the appropriate tab to the front and initializes various bits of UI.
    */
   init: function ()
@@ -47,17 +48,17 @@ var gAdvancedPane = {
   tabSelectionChanged: function ()
   {
     if (!this._inited)
       return;
     var advancedPrefs = document.getElementById("advancedPrefs");
     var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
     preference.valueFromPreferences = advancedPrefs.selectedIndex;
   },
-  
+
   // GENERAL TAB
 
   /*
    * Preferences:
    *
    * accessibility.browsewithcaret
    * - true enables keyboard navigation and selection within web pages using a
    *   visible caret, false uses normal keyboard navigation with no caret
@@ -165,17 +166,17 @@ var gAdvancedPane = {
   /**
    * Displays a dialog in which proxy settings may be changed.
    */
   showConnections: function ()
   {
     document.documentElement.openSubDialog("chrome://browser/content/preferences/connection.xul",
                                            "", null);
   },
- 
+
   // Retrieves the amount of space currently used by disk or offline cache
   updateActualCacheSize: function (device)
   {
     var visitor = {
       visitDevice: function (deviceID, deviceInfo)
       {
         if (deviceID == device) {
           var actualSizeLabel = document.getElementById(device == "disk" ?
@@ -215,17 +216,17 @@ var gAdvancedPane = {
 
   readSmartSizeEnabled: function ()
   {
     // The smart_size.enabled preference element is inverted="true", so its
     // value is the opposite of the actual pref value
     var disabled = document.getElementById("browser.cache.disk.smart_size.enabled").value;
     this.updateCacheSizeUI(!disabled);
   },
-  
+
   /**
    * Converts the cache size from units of KB to units of MB and returns that
    * value.
    */
   readCacheSize: function ()
   {
     var preference = document.getElementById("browser.cache.disk.capacity");
     return preference.value / 1024;
@@ -446,17 +447,17 @@ var gAdvancedPane = {
    */
 
 #ifdef MOZ_UPDATER
   /**
    * Selects the item of the radiogroup, and sets the warnIncompatible checkbox
    * based on the pref values and locked states.
    *
    * UI state matrix for update preference conditions
-   * 
+   *
    * UI Components:                              Preferences
    * Radiogroup                                  i   = app.update.enabled
    * Warn before disabling extensions checkbox   ii  = app.update.auto
    *                                             iii = app.update.mode
    *
    * Disabled states:
    * Element           pref  value  locked  disabled
    * radiogroup        i     t/f    f       false
@@ -512,16 +513,34 @@ var gAdvancedPane = {
                wrk.ACCESS_READ | wrk.WOW64_64);
       installed = wrk.readIntValue("Installed");
       wrk.close();
     } catch(e) {
     }
     if (installed != 1) {
       document.getElementById("useService").hidden = true;
     }
+    try {
+      const DRIVE_FIXED = 3;
+      const LPCWSTR = ctypes.jschar.ptr;
+      const UINT = ctypes.uint32_t;
+      let kernel32 = ctypes.open("kernel32");
+      let GetDriveType = kernel32.declare("GetDriveTypeW", ctypes.default_abi, UINT, LPCWSTR);
+      var UpdatesDir = Components.classes["@mozilla.org/updates/update-service;1"].
+                       getService(Components.interfaces.nsIApplicationUpdateService);
+      let rootPath = UpdatesDir.getUpdatesDirectory();
+      while (rootPath.parent != null) {
+        rootPath = rootPath.parent;
+      }
+      if (GetDriveType(rootPath.path) != DRIVE_FIXED) {
+        document.getElementById("useService").hidden = true;
+      }
+      kernel32.close();
+    } catch(e) {
+    }
 #endif
   },
 
   /**
    * Sets the pref values based on the selected item of the radiogroup,
    * and sets the disabled state of the warnIncompatible checkbox accordingly.
    */
   updateWritePrefs: function ()
@@ -630,17 +649,17 @@ var gAdvancedPane = {
                                         "", null);
   },
 
   /**
    * Displays a dialog which describes the user's CRLs.
    */
   showCRLs: function ()
   {
-    document.documentElement.openWindow("mozilla:crlmanager", 
+    document.documentElement.openWindow("mozilla:crlmanager",
                                         "chrome://pippki/content/crlManager.xul",
                                         "", null);
   },
 
   /**
    * Displays a dialog in which OCSP preferences can be configured.
    */
   showOCSP: function ()
--- a/toolkit/mozapps/update/nsIUpdateService.idl
+++ b/toolkit/mozapps/update/nsIUpdateService.idl
@@ -7,23 +7,24 @@
 
 interface nsIDOMDocument;
 interface nsIDOMElement;
 interface nsIDOMWindow;
 interface nsIRequest;
 interface nsIRequestObserver;
 interface nsISimpleEnumerator;
 interface nsIXMLHttpRequest;
+interface nsIFile;
 
 /**
  * An interface that describes an object representing a patch file that can
  * be downloaded and applied to a version of this application so that it
  * can be updated.
  */
-[scriptable, uuid(60523512-bb69-417c-9b2c-87a0664b0bbe)]
+[scriptable, uuid(1134957d-9449-481b-a515-4d88b9998278)]
 interface nsIUpdatePatch : nsISupports
 {
   /**
    * The type of this patch:
    * "partial"      A binary difference between two application versions
    * "complete"     A complete patch containing all of the replacement files
    *                to update to the new version
    */
@@ -395,16 +396,22 @@ interface nsIApplicationUpdateService : 
   AString downloadUpdate(in nsIUpdate update, in boolean background);
 
   /**
    * Apply an update in the background.
    */
   void applyUpdateInBackground(in nsIUpdate update);
 
   /**
+   * Get the Active Updates directory
+   * @returns The active updates directory.
+   */
+  nsIFile getUpdatesDirectory();
+
+  /**
    * Pauses the active update download process
    */
   void pauseDownload();
 
   /**
    * Whether or not there is an download happening at the moment.
    */
   readonly attribute boolean isDownloading;
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -6,17 +6,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/FileUtils.jsm");
 Components.utils.import("resource://gre/modules/AddonManager.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/ctypes.jsm")
+Components.utils.import("resource://gre/modules/ctypes.jsm");
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
 const UPDATESERVICE_CID = Components.ID("{B3C290A6-3943-4B89-8BBE-C01EB7B3B311}");
 const UPDATESERVICE_CONTRACTID = "@mozilla.org/updates/update-service;1";
 
@@ -2142,16 +2142,21 @@ UpdateService.prototype = {
   pauseDownload: function AUS_pauseDownload() {
     if (this.isDownloading)
       this._downloader.cancel();
   },
 
   /**
    * See nsIUpdateService.idl
    */
+  getUpdatesDirectory: getUpdatesDir,
+
+  /**
+   * See nsIUpdateService.idl
+   */
   get isDownloading() {
     return this._downloader && this._downloader.isBusy;
   },
 
   classID: UPDATESERVICE_CID,
   classInfo: XPCOMUtils.generateCI({classID: UPDATESERVICE_CID,
                                     contractID: UPDATESERVICE_CONTRACTID,
                                     interfaces: [Ci.nsIApplicationUpdateService,