browser/components/preferences/advanced.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/preferences/advanced.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,897 @@
     1.4 +# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +// Load DownloadUtils module for convertByteUnits
    1.10 +Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
    1.11 +Components.utils.import("resource://gre/modules/ctypes.jsm");
    1.12 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.13 +Components.utils.import("resource://gre/modules/LoadContextInfo.jsm");
    1.14 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    1.15 +
    1.16 +var gAdvancedPane = {
    1.17 +  _inited: false,
    1.18 +
    1.19 +  /**
    1.20 +   * Brings the appropriate tab to the front and initializes various bits of UI.
    1.21 +   */
    1.22 +  init: function ()
    1.23 +  {
    1.24 +    this._inited = true;
    1.25 +    var advancedPrefs = document.getElementById("advancedPrefs");
    1.26 +
    1.27 +    var extraArgs = window.arguments[1];
    1.28 +    if (extraArgs && extraArgs["advancedTab"]){
    1.29 +      advancedPrefs.selectedTab = document.getElementById(extraArgs["advancedTab"]);
    1.30 +    } else {
    1.31 +      var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
    1.32 +      if (preference.value !== null)
    1.33 +        advancedPrefs.selectedIndex = preference.value;
    1.34 +    }
    1.35 +
    1.36 +#ifdef HAVE_SHELL_SERVICE
    1.37 +    this.updateSetDefaultBrowser();
    1.38 +#ifdef XP_WIN
    1.39 +    // In Windows 8 we launch the control panel since it's the only
    1.40 +    // way to get all file type association prefs. So we don't know
    1.41 +    // when the user will select the default.  We refresh here periodically
    1.42 +    // in case the default changes.  On other Windows OS's defaults can also
    1.43 +    // be set while the prefs are open.
    1.44 +    window.setInterval(this.updateSetDefaultBrowser, 1000);
    1.45 +
    1.46 +#ifdef MOZ_METRO
    1.47 +    // Pre Windows 8, we should hide the update related settings
    1.48 +    // for the Metro browser
    1.49 +    let version = Components.classes["@mozilla.org/system-info;1"].
    1.50 +                  getService(Components.interfaces.nsIPropertyBag2).
    1.51 +                  getProperty("version");
    1.52 +    let preWin8 = parseFloat(version) < 6.2;
    1.53 +    this._showingWin8Prefs = !preWin8;
    1.54 +    if (preWin8) {
    1.55 +      ["autoMetro", "autoMetroIndent"].forEach(
    1.56 +        function(id) document.getElementById(id).collapsed = true
    1.57 +      );
    1.58 +    } else {
    1.59 +      let brandShortName =
    1.60 +        document.getElementById("bundleBrand").getString("brandShortName");
    1.61 +      let bundlePrefs = document.getElementById("bundlePreferences");
    1.62 +      let autoDesktop = document.getElementById("autoDesktop");
    1.63 +      autoDesktop.label =
    1.64 +        bundlePrefs.getFormattedString("updateAutoDesktop.label",
    1.65 +                                       [brandShortName]);
    1.66 +      autoDesktop.accessKey =
    1.67 +        bundlePrefs.getString("updateAutoDesktop.accessKey");
    1.68 +    }
    1.69 +#endif
    1.70 +#endif
    1.71 +#endif
    1.72 +
    1.73 +#ifdef MOZ_UPDATER
    1.74 +    this.updateReadPrefs();
    1.75 +#endif
    1.76 +    this.updateOfflineApps();
    1.77 +#ifdef MOZ_CRASHREPORTER
    1.78 +    this.initSubmitCrashes();
    1.79 +#endif
    1.80 +    this.initTelemetry();
    1.81 +#ifdef MOZ_SERVICES_HEALTHREPORT
    1.82 +    this.initSubmitHealthReport();
    1.83 +#endif
    1.84 +
    1.85 +    this.updateActualCacheSize();
    1.86 +    this.updateActualAppCacheSize();
    1.87 +
    1.88 +    // Notify observers that the UI is now ready
    1.89 +    Services.obs.notifyObservers(window, "advanced-pane-loaded", null);
    1.90 +  },
    1.91 +
    1.92 +  /**
    1.93 +   * Stores the identity of the current tab in preferences so that the selected
    1.94 +   * tab can be persisted between openings of the preferences window.
    1.95 +   */
    1.96 +  tabSelectionChanged: function ()
    1.97 +  {
    1.98 +    if (!this._inited)
    1.99 +      return;
   1.100 +    var advancedPrefs = document.getElementById("advancedPrefs");
   1.101 +    var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
   1.102 +    preference.valueFromPreferences = advancedPrefs.selectedIndex;
   1.103 +  },
   1.104 +
   1.105 +  // GENERAL TAB
   1.106 +
   1.107 +  /*
   1.108 +   * Preferences:
   1.109 +   *
   1.110 +   * accessibility.browsewithcaret
   1.111 +   * - true enables keyboard navigation and selection within web pages using a
   1.112 +   *   visible caret, false uses normal keyboard navigation with no caret
   1.113 +   * accessibility.typeaheadfind
   1.114 +   * - when set to true, typing outside text areas and input boxes will
   1.115 +   *   automatically start searching for what's typed within the current
   1.116 +   *   document; when set to false, no search action happens
   1.117 +   * general.autoScroll
   1.118 +   * - when set to true, clicking the scroll wheel on the mouse activates a
   1.119 +   *   mouse mode where moving the mouse down scrolls the document downward with
   1.120 +   *   speed correlated with the distance of the cursor from the original
   1.121 +   *   position at which the click occurred (and likewise with movement upward);
   1.122 +   *   if false, this behavior is disabled
   1.123 +   * general.smoothScroll
   1.124 +   * - set to true to enable finer page scrolling than line-by-line on page-up,
   1.125 +   *   page-down, and other such page movements
   1.126 +   * layout.spellcheckDefault
   1.127 +   * - an integer:
   1.128 +   *     0  disables spellchecking
   1.129 +   *     1  enables spellchecking, but only for multiline text fields
   1.130 +   *     2  enables spellchecking for all text fields
   1.131 +   */
   1.132 +
   1.133 +  /**
   1.134 +   * Stores the original value of the spellchecking preference to enable proper
   1.135 +   * restoration if unchanged (since we're mapping a tristate onto a checkbox).
   1.136 +   */
   1.137 +  _storedSpellCheck: 0,
   1.138 +
   1.139 +  /**
   1.140 +   * Returns true if any spellchecking is enabled and false otherwise, caching
   1.141 +   * the current value to enable proper pref restoration if the checkbox is
   1.142 +   * never changed.
   1.143 +   */
   1.144 +  readCheckSpelling: function ()
   1.145 +  {
   1.146 +    var pref = document.getElementById("layout.spellcheckDefault");
   1.147 +    this._storedSpellCheck = pref.value;
   1.148 +
   1.149 +    return (pref.value != 0);
   1.150 +  },
   1.151 +
   1.152 +  /**
   1.153 +   * Returns the value of the spellchecking preference represented by UI,
   1.154 +   * preserving the preference's "hidden" value if the preference is
   1.155 +   * unchanged and represents a value not strictly allowed in UI.
   1.156 +   */
   1.157 +  writeCheckSpelling: function ()
   1.158 +  {
   1.159 +    var checkbox = document.getElementById("checkSpelling");
   1.160 +    return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0;
   1.161 +  },
   1.162 +
   1.163 +  /**
   1.164 +   * When the user toggles the layers.acceleration.disabled pref,
   1.165 +   * sync its new value to the gfx.direct2d.disabled pref too.
   1.166 +   */
   1.167 +  updateHardwareAcceleration: function()
   1.168 +  {
   1.169 +#ifdef XP_WIN
   1.170 +    var fromPref = document.getElementById("layers.acceleration.disabled");
   1.171 +    var toPref = document.getElementById("gfx.direct2d.disabled");
   1.172 +    toPref.value = fromPref.value;
   1.173 +#endif
   1.174 +  },
   1.175 +
   1.176 +  // DATA CHOICES TAB
   1.177 +
   1.178 +  /**
   1.179 +   * opening links behind a modal dialog is poor form. Work around flawed text-link handling here.
   1.180 +   */
   1.181 +  openTextLink: function (evt) {
   1.182 +    let where = Services.prefs.getBoolPref("browser.preferences.instantApply") ? "tab" : "window";
   1.183 +    openUILinkIn(evt.target.getAttribute("href"), where);
   1.184 +    evt.preventDefault();
   1.185 +  },
   1.186 +
   1.187 +  /**
   1.188 +   * Set up or hide the Learn More links for various data collection options
   1.189 +   */
   1.190 +  _setupLearnMoreLink: function (pref, element) {
   1.191 +    // set up the Learn More link with the correct URL
   1.192 +    let url = Services.prefs.getCharPref(pref);
   1.193 +    let el = document.getElementById(element);
   1.194 +
   1.195 +    if (url) {
   1.196 +      el.setAttribute("href", url);
   1.197 +    } else {
   1.198 +      el.setAttribute("hidden", "true");
   1.199 +    }
   1.200 +  },
   1.201 +
   1.202 +  /**
   1.203 +   *
   1.204 +   */
   1.205 +  initSubmitCrashes: function ()
   1.206 +  {
   1.207 +    var checkbox = document.getElementById("submitCrashesBox");
   1.208 +    try {
   1.209 +      var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
   1.210 +               getService(Components.interfaces.nsICrashReporter);
   1.211 +      checkbox.checked = cr.submitReports;
   1.212 +    } catch (e) {
   1.213 +      checkbox.style.display = "none";
   1.214 +    }
   1.215 +    this._setupLearnMoreLink("toolkit.crashreporter.infoURL", "crashReporterLearnMore");
   1.216 +  },
   1.217 +
   1.218 +  /**
   1.219 +   *
   1.220 +   */
   1.221 +  updateSubmitCrashes: function ()
   1.222 +  {
   1.223 +    var checkbox = document.getElementById("submitCrashesBox");
   1.224 +    try {
   1.225 +      var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
   1.226 +               getService(Components.interfaces.nsICrashReporter);
   1.227 +      cr.submitReports = checkbox.checked;
   1.228 +    } catch (e) { }
   1.229 +  },
   1.230 +
   1.231 +
   1.232 +  /**
   1.233 +   * The preference/checkbox is configured in XUL.
   1.234 +   *
   1.235 +   * In all cases, set up the Learn More link sanely
   1.236 +   */
   1.237 +  initTelemetry: function ()
   1.238 +  {
   1.239 +#ifdef MOZ_TELEMETRY_REPORTING
   1.240 +    this._setupLearnMoreLink("toolkit.telemetry.infoURL", "telemetryLearnMore");
   1.241 +#endif
   1.242 +  },
   1.243 +
   1.244 +#ifdef MOZ_SERVICES_HEALTHREPORT
   1.245 +  /**
   1.246 +   * Initialize the health report service reference and checkbox.
   1.247 +   */
   1.248 +  initSubmitHealthReport: function () {
   1.249 +    this._setupLearnMoreLink("datareporting.healthreport.infoURL", "FHRLearnMore");
   1.250 +
   1.251 +    let policy = Components.classes["@mozilla.org/datareporting/service;1"]
   1.252 +                                   .getService(Components.interfaces.nsISupports)
   1.253 +                                   .wrappedJSObject
   1.254 +                                   .policy;
   1.255 +
   1.256 +    let checkbox = document.getElementById("submitHealthReportBox");
   1.257 +
   1.258 +    if (!policy || policy.healthReportUploadLocked) {
   1.259 +      checkbox.setAttribute("disabled", "true");
   1.260 +      return;
   1.261 +    }
   1.262 +
   1.263 +    checkbox.checked = policy.healthReportUploadEnabled;
   1.264 +  },
   1.265 +
   1.266 +  /**
   1.267 +   * Update the health report policy acceptance with state from checkbox.
   1.268 +   */
   1.269 +  updateSubmitHealthReport: function () {
   1.270 +    let policy = Components.classes["@mozilla.org/datareporting/service;1"]
   1.271 +                                   .getService(Components.interfaces.nsISupports)
   1.272 +                                   .wrappedJSObject
   1.273 +                                   .policy;
   1.274 +
   1.275 +    if (!policy) {
   1.276 +      return;
   1.277 +    }
   1.278 +
   1.279 +    let checkbox = document.getElementById("submitHealthReportBox");
   1.280 +    policy.recordHealthReportUploadEnabled(checkbox.checked,
   1.281 +                                           "Checkbox from preferences pane");
   1.282 +  },
   1.283 +#endif
   1.284 +
   1.285 +  // NETWORK TAB
   1.286 +
   1.287 +  /*
   1.288 +   * Preferences:
   1.289 +   *
   1.290 +   * browser.cache.disk.capacity
   1.291 +   * - the size of the browser cache in KB
   1.292 +   * - Only used if browser.cache.disk.smart_size.enabled is disabled
   1.293 +   */
   1.294 +
   1.295 +  /**
   1.296 +   * Displays a dialog in which proxy settings may be changed.
   1.297 +   */
   1.298 +  showConnections: function ()
   1.299 +  {
   1.300 +    document.documentElement.openSubDialog("chrome://browser/content/preferences/connection.xul",
   1.301 +                                           "", null);
   1.302 +  },
   1.303 +
   1.304 +  // Retrieves the amount of space currently used by disk cache
   1.305 +  updateActualCacheSize: function ()
   1.306 +  {
   1.307 +    var actualSizeLabel = document.getElementById("actualDiskCacheSize");
   1.308 +    var prefStrBundle = document.getElementById("bundlePreferences");
   1.309 +
   1.310 +    // Needs to root the observer since cache service keeps only a weak reference.
   1.311 +    this.observer = {
   1.312 +      onNetworkCacheDiskConsumption: function(consumption) {
   1.313 +        var size = DownloadUtils.convertByteUnits(consumption);
   1.314 +        actualSizeLabel.value = prefStrBundle.getFormattedString("actualDiskCacheSize", size);
   1.315 +      },
   1.316 +
   1.317 +      QueryInterface: XPCOMUtils.generateQI([
   1.318 +        Components.interfaces.nsICacheStorageConsumptionObserver,
   1.319 +        Components.interfaces.nsISupportsWeakReference
   1.320 +      ])
   1.321 +    };
   1.322 +
   1.323 +    actualSizeLabel.value = prefStrBundle.getString("actualDiskCacheSizeCalculated");
   1.324 +
   1.325 +    var cacheService =
   1.326 +      Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
   1.327 +                .getService(Components.interfaces.nsICacheStorageService);
   1.328 +    cacheService.asyncGetDiskConsumption(this.observer);
   1.329 +  },
   1.330 +
   1.331 +  // Retrieves the amount of space currently used by offline cache
   1.332 +  updateActualAppCacheSize: function ()
   1.333 +  {
   1.334 +    var visitor = {
   1.335 +      visitDevice: function (deviceID, deviceInfo)
   1.336 +      {
   1.337 +        if (deviceID == "offline") {
   1.338 +          var actualSizeLabel = document.getElementById("actualAppCacheSize");
   1.339 +          var sizeStrings = DownloadUtils.convertByteUnits(deviceInfo.totalSize);
   1.340 +          var prefStrBundle = document.getElementById("bundlePreferences");
   1.341 +          var sizeStr = prefStrBundle.getFormattedString("actualAppCacheSize", sizeStrings);
   1.342 +          actualSizeLabel.value = sizeStr;
   1.343 +        }
   1.344 +        // Do not enumerate entries
   1.345 +        return false;
   1.346 +      },
   1.347 +
   1.348 +      visitEntry: function (deviceID, entryInfo)
   1.349 +      {
   1.350 +        // Do not enumerate entries.
   1.351 +        return false;
   1.352 +      }
   1.353 +    };
   1.354 +
   1.355 +    var cacheService =
   1.356 +      Components.classes["@mozilla.org/network/cache-service;1"]
   1.357 +                .getService(Components.interfaces.nsICacheService);
   1.358 +    cacheService.visitEntries(visitor);
   1.359 +  },
   1.360 +
   1.361 +  updateCacheSizeUI: function (smartSizeEnabled)
   1.362 +  {
   1.363 +    document.getElementById("useCacheBefore").disabled = smartSizeEnabled;
   1.364 +    document.getElementById("cacheSize").disabled = smartSizeEnabled;
   1.365 +    document.getElementById("useCacheAfter").disabled = smartSizeEnabled;
   1.366 +  },
   1.367 +
   1.368 +  readSmartSizeEnabled: function ()
   1.369 +  {
   1.370 +    // The smart_size.enabled preference element is inverted="true", so its
   1.371 +    // value is the opposite of the actual pref value
   1.372 +    var disabled = document.getElementById("browser.cache.disk.smart_size.enabled").value;
   1.373 +    this.updateCacheSizeUI(!disabled);
   1.374 +  },
   1.375 +
   1.376 +  /**
   1.377 +   * Converts the cache size from units of KB to units of MB and returns that
   1.378 +   * value.
   1.379 +   */
   1.380 +  readCacheSize: function ()
   1.381 +  {
   1.382 +    var preference = document.getElementById("browser.cache.disk.capacity");
   1.383 +    return preference.value / 1024;
   1.384 +  },
   1.385 +
   1.386 +  /**
   1.387 +   * Converts the cache size as specified in UI (in MB) to KB and returns that
   1.388 +   * value.
   1.389 +   */
   1.390 +  writeCacheSize: function ()
   1.391 +  {
   1.392 +    var cacheSize = document.getElementById("cacheSize");
   1.393 +    var intValue = parseInt(cacheSize.value, 10);
   1.394 +    return isNaN(intValue) ? 0 : intValue * 1024;
   1.395 +  },
   1.396 +
   1.397 +  /**
   1.398 +   * Clears the cache.
   1.399 +   */
   1.400 +  clearCache: function ()
   1.401 +  {
   1.402 +    var cache = Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
   1.403 +                                 .getService(Components.interfaces.nsICacheStorageService);
   1.404 +    try {
   1.405 +      cache.clear();
   1.406 +    } catch(ex) {}
   1.407 +    this.updateActualCacheSize();
   1.408 +  },
   1.409 +
   1.410 +  /**
   1.411 +   * Clears the application cache.
   1.412 +   */
   1.413 +  clearOfflineAppCache: function ()
   1.414 +  {
   1.415 +    Components.utils.import("resource:///modules/offlineAppCache.jsm");
   1.416 +    OfflineAppCacheHelper.clear();
   1.417 +
   1.418 +    this.updateActualAppCacheSize();
   1.419 +    this.updateOfflineApps();
   1.420 +  },
   1.421 +
   1.422 +  readOfflineNotify: function()
   1.423 +  {
   1.424 +    var pref = document.getElementById("browser.offline-apps.notify");
   1.425 +    var button = document.getElementById("offlineNotifyExceptions");
   1.426 +    button.disabled = !pref.value;
   1.427 +    return pref.value;
   1.428 +  },
   1.429 +
   1.430 +  showOfflineExceptions: function()
   1.431 +  {
   1.432 +    var bundlePreferences = document.getElementById("bundlePreferences");
   1.433 +    var params = { blockVisible     : false,
   1.434 +                   sessionVisible   : false,
   1.435 +                   allowVisible     : false,
   1.436 +                   prefilledHost    : "",
   1.437 +                   permissionType   : "offline-app",
   1.438 +                   manageCapability : Components.interfaces.nsIPermissionManager.DENY_ACTION,
   1.439 +                   windowTitle      : bundlePreferences.getString("offlinepermissionstitle"),
   1.440 +                   introText        : bundlePreferences.getString("offlinepermissionstext") };
   1.441 +    document.documentElement.openWindow("Browser:Permissions",
   1.442 +                                        "chrome://browser/content/preferences/permissions.xul",
   1.443 +                                        "", params);
   1.444 +  },
   1.445 +
   1.446 +  // XXX: duplicated in browser.js
   1.447 +  _getOfflineAppUsage: function (host, groups)
   1.448 +  {
   1.449 +    var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
   1.450 +                       getService(Components.interfaces.nsIApplicationCacheService);
   1.451 +    if (!groups)
   1.452 +      groups = cacheService.getGroups();
   1.453 +
   1.454 +    var ios = Components.classes["@mozilla.org/network/io-service;1"].
   1.455 +              getService(Components.interfaces.nsIIOService);
   1.456 +
   1.457 +    var usage = 0;
   1.458 +    for (var i = 0; i < groups.length; i++) {
   1.459 +      var uri = ios.newURI(groups[i], null, null);
   1.460 +      if (uri.asciiHost == host) {
   1.461 +        var cache = cacheService.getActiveCache(groups[i]);
   1.462 +        usage += cache.usage;
   1.463 +      }
   1.464 +    }
   1.465 +
   1.466 +    return usage;
   1.467 +  },
   1.468 +
   1.469 +  /**
   1.470 +   * Updates the list of offline applications
   1.471 +   */
   1.472 +  updateOfflineApps: function ()
   1.473 +  {
   1.474 +    var pm = Components.classes["@mozilla.org/permissionmanager;1"]
   1.475 +                       .getService(Components.interfaces.nsIPermissionManager);
   1.476 +
   1.477 +    var list = document.getElementById("offlineAppsList");
   1.478 +    while (list.firstChild) {
   1.479 +      list.removeChild(list.firstChild);
   1.480 +    }
   1.481 +
   1.482 +    var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
   1.483 +                       getService(Components.interfaces.nsIApplicationCacheService);
   1.484 +    var groups = cacheService.getGroups();
   1.485 +
   1.486 +    var bundle = document.getElementById("bundlePreferences");
   1.487 +
   1.488 +    var enumerator = pm.enumerator;
   1.489 +    while (enumerator.hasMoreElements()) {
   1.490 +      var perm = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
   1.491 +      if (perm.type == "offline-app" &&
   1.492 +          perm.capability != Components.interfaces.nsIPermissionManager.DEFAULT_ACTION &&
   1.493 +          perm.capability != Components.interfaces.nsIPermissionManager.DENY_ACTION) {
   1.494 +        var row = document.createElement("listitem");
   1.495 +        row.id = "";
   1.496 +        row.className = "offlineapp";
   1.497 +        row.setAttribute("host", perm.host);
   1.498 +        var converted = DownloadUtils.
   1.499 +                        convertByteUnits(this._getOfflineAppUsage(perm.host, groups));
   1.500 +        row.setAttribute("usage",
   1.501 +                         bundle.getFormattedString("offlineAppUsage",
   1.502 +                                                   converted));
   1.503 +        list.appendChild(row);
   1.504 +      }
   1.505 +    }
   1.506 +  },
   1.507 +
   1.508 +  offlineAppSelected: function()
   1.509 +  {
   1.510 +    var removeButton = document.getElementById("offlineAppsListRemove");
   1.511 +    var list = document.getElementById("offlineAppsList");
   1.512 +    if (list.selectedItem) {
   1.513 +      removeButton.setAttribute("disabled", "false");
   1.514 +    } else {
   1.515 +      removeButton.setAttribute("disabled", "true");
   1.516 +    }
   1.517 +  },
   1.518 +
   1.519 +  removeOfflineApp: function()
   1.520 +  {
   1.521 +    var list = document.getElementById("offlineAppsList");
   1.522 +    var item = list.selectedItem;
   1.523 +    var host = item.getAttribute("host");
   1.524 +
   1.525 +    var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
   1.526 +                            .getService(Components.interfaces.nsIPromptService);
   1.527 +    var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 +
   1.528 +                prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1;
   1.529 +
   1.530 +    var bundle = document.getElementById("bundlePreferences");
   1.531 +    var title = bundle.getString("offlineAppRemoveTitle");
   1.532 +    var prompt = bundle.getFormattedString("offlineAppRemovePrompt", [host]);
   1.533 +    var confirm = bundle.getString("offlineAppRemoveConfirm");
   1.534 +    var result = prompts.confirmEx(window, title, prompt, flags, confirm,
   1.535 +                                   null, null, null, {});
   1.536 +    if (result != 0)
   1.537 +      return;
   1.538 +
   1.539 +    // clear offline cache entries
   1.540 +    var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
   1.541 +                       getService(Components.interfaces.nsIApplicationCacheService);
   1.542 +    var ios = Components.classes["@mozilla.org/network/io-service;1"].
   1.543 +              getService(Components.interfaces.nsIIOService);
   1.544 +    var groups = cacheService.getGroups();
   1.545 +    for (var i = 0; i < groups.length; i++) {
   1.546 +        var uri = ios.newURI(groups[i], null, null);
   1.547 +        if (uri.asciiHost == host) {
   1.548 +            var cache = cacheService.getActiveCache(groups[i]);
   1.549 +            cache.discard();
   1.550 +        }
   1.551 +    }
   1.552 +
   1.553 +    // remove the permission
   1.554 +    var pm = Components.classes["@mozilla.org/permissionmanager;1"]
   1.555 +                       .getService(Components.interfaces.nsIPermissionManager);
   1.556 +    pm.remove(host, "offline-app",
   1.557 +              Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
   1.558 +    pm.remove(host, "offline-app",
   1.559 +              Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
   1.560 +
   1.561 +    list.removeChild(item);
   1.562 +    gAdvancedPane.offlineAppSelected();
   1.563 +    this.updateActualAppCacheSize();
   1.564 +  },
   1.565 +
   1.566 +  // UPDATE TAB
   1.567 +
   1.568 +  /*
   1.569 +   * Preferences:
   1.570 +   *
   1.571 +   * app.update.enabled
   1.572 +   * - true if updates to the application are enabled, false otherwise
   1.573 +   * extensions.update.enabled
   1.574 +   * - true if updates to extensions and themes are enabled, false otherwise
   1.575 +   * browser.search.update
   1.576 +   * - true if updates to search engines are enabled, false otherwise
   1.577 +   * app.update.auto
   1.578 +   * - true if updates should be automatically downloaded and installed,
   1.579 +   *   possibly with a warning if incompatible extensions are installed (see
   1.580 +   *   app.update.mode); false if the user should be asked what he wants to do
   1.581 +   *   when an update is available
   1.582 +   * app.update.mode
   1.583 +   * - an integer:
   1.584 +   *     0    do not warn if an update will disable extensions or themes
   1.585 +   *     1    warn if an update will disable extensions or themes
   1.586 +   *     2    warn if an update will disable extensions or themes *or* if the
   1.587 +   *          update is a major update
   1.588 +   */
   1.589 +
   1.590 +#ifdef MOZ_UPDATER
   1.591 +  /**
   1.592 +   * Selects the item of the radiogroup, and sets the warnIncompatible checkbox
   1.593 +   * based on the pref values and locked states.
   1.594 +   *
   1.595 +   * UI state matrix for update preference conditions
   1.596 +   *
   1.597 +   * UI Components:                              Preferences
   1.598 +   * Radiogroup                                  i   = app.update.enabled
   1.599 +   * Warn before disabling extensions checkbox   ii  = app.update.auto
   1.600 +   *                                             iii = app.update.mode
   1.601 +   *
   1.602 +   * Disabled states:
   1.603 +   * Element           pref  value  locked  disabled
   1.604 +   * radiogroup        i     t/f    f       false
   1.605 +   *                   i     t/f    *t*     *true*
   1.606 +   *                   ii    t/f    f       false
   1.607 +   *                   ii    t/f    *t*     *true*
   1.608 +   *                   iii   0/1/2  t/f     false
   1.609 +   * warnIncompatible  i     t      f       false
   1.610 +   *                   i     t      *t*     *true*
   1.611 +   *                   i     *f*    t/f     *true*
   1.612 +   *                   ii    t      f       false
   1.613 +   *                   ii    t      *t*     *true*
   1.614 +   *                   ii    *f*    t/f     *true*
   1.615 +   *                   iii   0/1/2  f       false
   1.616 +   *                   iii   0/1/2  *t*     *true*
   1.617 +   */
   1.618 +  updateReadPrefs: function ()
   1.619 +  {
   1.620 +    var enabledPref = document.getElementById("app.update.enabled");
   1.621 +    var autoPref = document.getElementById("app.update.auto");
   1.622 +#ifdef XP_WIN
   1.623 +#ifdef MOZ_METRO
   1.624 +    var metroEnabledPref = document.getElementById("app.update.metro.enabled");
   1.625 +#endif
   1.626 +#endif
   1.627 +    var radiogroup = document.getElementById("updateRadioGroup");
   1.628 +
   1.629 +    if (!enabledPref.value)   // Don't care for autoPref.value in this case.
   1.630 +      radiogroup.value="manual";    // 3. Never check for updates.
   1.631 +#ifdef XP_WIN
   1.632 +#ifdef MOZ_METRO
   1.633 +    // enabledPref.value && autoPref.value && metroEnabledPref.value
   1.634 +    else if (metroEnabledPref.value && this._showingWin8Prefs)
   1.635 +      radiogroup.value="autoMetro"; // 0. Automatically install updates for both Metro and Desktop
   1.636 +#endif
   1.637 +#endif
   1.638 +    else if (autoPref.value)  // enabledPref.value && autoPref.value
   1.639 +      radiogroup.value="auto";      // 1. Automatically install updates for Desktop only
   1.640 +    else                      // enabledPref.value && !autoPref.value
   1.641 +      radiogroup.value="checkOnly"; // 2. Check, but let me choose
   1.642 +
   1.643 +    var canCheck = Components.classes["@mozilla.org/updates/update-service;1"].
   1.644 +                     getService(Components.interfaces.nsIApplicationUpdateService).
   1.645 +                     canCheckForUpdates;
   1.646 +    // canCheck is false if the enabledPref is false and locked,
   1.647 +    // or the binary platform or OS version is not known.
   1.648 +    // A locked pref is sufficient to disable the radiogroup.
   1.649 +    radiogroup.disabled = !canCheck || enabledPref.locked || autoPref.locked;
   1.650 +
   1.651 +    var modePref = document.getElementById("app.update.mode");
   1.652 +    var warnIncompatible = document.getElementById("warnIncompatible");
   1.653 +    // the warnIncompatible checkbox value is set by readAddonWarn
   1.654 +    warnIncompatible.disabled = radiogroup.disabled || modePref.locked ||
   1.655 +                                !enabledPref.value || !autoPref.value;
   1.656 +#ifdef XP_WIN
   1.657 +#ifdef MOZ_METRO
   1.658 +    if (this._showingWin8Prefs) {
   1.659 +      warnIncompatible.disabled |= metroEnabledPref.value;
   1.660 +      warnIncompatible.checked |= metroEnabledPref.value;
   1.661 +    }
   1.662 +#endif
   1.663 +#endif
   1.664 +
   1.665 +#ifdef MOZ_MAINTENANCE_SERVICE
   1.666 +    // Check to see if the maintenance service is installed.
   1.667 +    // If it is don't show the preference at all.
   1.668 +    var installed;
   1.669 +    try {
   1.670 +      var wrk = Components.classes["@mozilla.org/windows-registry-key;1"]
   1.671 +                .createInstance(Components.interfaces.nsIWindowsRegKey);
   1.672 +      wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,
   1.673 +               "SOFTWARE\\Mozilla\\MaintenanceService",
   1.674 +               wrk.ACCESS_READ | wrk.WOW64_64);
   1.675 +      installed = wrk.readIntValue("Installed");
   1.676 +      wrk.close();
   1.677 +    } catch(e) {
   1.678 +    }
   1.679 +    if (installed != 1) {
   1.680 +      document.getElementById("useService").hidden = true;
   1.681 +    }
   1.682 +    try {
   1.683 +      const DRIVE_FIXED = 3;
   1.684 +      const LPCWSTR = ctypes.jschar.ptr;
   1.685 +      const UINT = ctypes.uint32_t;
   1.686 +      let kernel32 = ctypes.open("kernel32");
   1.687 +      let GetDriveType = kernel32.declare("GetDriveTypeW", ctypes.default_abi, UINT, LPCWSTR);
   1.688 +      var UpdatesDir = Components.classes["@mozilla.org/updates/update-service;1"].
   1.689 +                       getService(Components.interfaces.nsIApplicationUpdateService);
   1.690 +      let rootPath = UpdatesDir.getUpdatesDirectory();
   1.691 +      while (rootPath.parent != null) {
   1.692 +        rootPath = rootPath.parent;
   1.693 +      }
   1.694 +      if (GetDriveType(rootPath.path) != DRIVE_FIXED) {
   1.695 +        document.getElementById("useService").hidden = true;
   1.696 +      }
   1.697 +      kernel32.close();
   1.698 +    } catch(e) {
   1.699 +    }
   1.700 +#endif
   1.701 +  },
   1.702 +
   1.703 +  /**
   1.704 +   * Sets the pref values based on the selected item of the radiogroup,
   1.705 +   * and sets the disabled state of the warnIncompatible checkbox accordingly.
   1.706 +   */
   1.707 +  updateWritePrefs: function ()
   1.708 +  {
   1.709 +    var enabledPref = document.getElementById("app.update.enabled");
   1.710 +    var autoPref = document.getElementById("app.update.auto");
   1.711 +    var modePref = document.getElementById("app.update.mode");
   1.712 +#ifdef XP_WIN
   1.713 +#ifdef MOZ_METRO
   1.714 +    var metroEnabledPref = document.getElementById("app.update.metro.enabled");
   1.715 +    // Initialize the pref to false only if we're showing the option
   1.716 +    if (this._showingWin8Prefs) {
   1.717 +      metroEnabledPref.value = false;
   1.718 +    }
   1.719 +#endif
   1.720 +#endif
   1.721 +    var radiogroup = document.getElementById("updateRadioGroup");
   1.722 +    switch (radiogroup.value) {
   1.723 +      case "auto":      // 1. Automatically install updates for Desktop only
   1.724 +        enabledPref.value = true;
   1.725 +        autoPref.value = true;
   1.726 +        break;
   1.727 +#ifdef XP_WIN
   1.728 +#ifdef MOZ_METRO
   1.729 +      case "autoMetro": // 0. Automatically install updates for both Metro and Desktop
   1.730 +        enabledPref.value = true;
   1.731 +        autoPref.value = true;
   1.732 +        metroEnabledPref.value = true;
   1.733 +        modePref.value = 1;
   1.734 +        break;
   1.735 +#endif
   1.736 +#endif
   1.737 +      case "checkOnly": // 2. Check, but let me choose
   1.738 +        enabledPref.value = true;
   1.739 +        autoPref.value = false;
   1.740 +        break;
   1.741 +      case "manual":    // 3. Never check for updates.
   1.742 +        enabledPref.value = false;
   1.743 +        autoPref.value = false;
   1.744 +    }
   1.745 +
   1.746 +    var warnIncompatible = document.getElementById("warnIncompatible");
   1.747 +    warnIncompatible.disabled = enabledPref.locked || !enabledPref.value ||
   1.748 +                                autoPref.locked || !autoPref.value ||
   1.749 +                                modePref.locked;
   1.750 +
   1.751 +#ifdef XP_WIN
   1.752 +#ifdef MOZ_METRO
   1.753 +    if (this._showingWin8Prefs) {
   1.754 +      warnIncompatible.disabled |= metroEnabledPref.value;
   1.755 +      warnIncompatible.checked |= metroEnabledPref.value;
   1.756 +    }
   1.757 +#endif
   1.758 +#endif
   1.759 +  },
   1.760 +
   1.761 +  /**
   1.762 +   * Stores the value of the app.update.mode preference, which is a tristate
   1.763 +   * integer preference.  We store the value here so that we can properly
   1.764 +   * restore the preference value if the UI reflecting the preference value
   1.765 +   * is in a state which can represent either of two integer values (as
   1.766 +   * opposed to only one possible value in the other UI state).
   1.767 +   */
   1.768 +  _modePreference: -1,
   1.769 +
   1.770 +  /**
   1.771 +   * Reads the app.update.mode preference and converts its value into a
   1.772 +   * true/false value for use in determining whether the "Warn me if this will
   1.773 +   * disable extensions or themes" checkbox is checked.  We also save the value
   1.774 +   * of the preference so that the preference value can be properly restored if
   1.775 +   * the user's preferences cannot adequately be expressed by a single checkbox.
   1.776 +   *
   1.777 +   * app.update.mode          Checkbox State    Meaning
   1.778 +   * 0                        Unchecked         Do not warn
   1.779 +   * 1                        Checked           Warn if there are incompatibilities
   1.780 +   * 2                        Checked           Warn if there are incompatibilities,
   1.781 +   *                                            or the update is major.
   1.782 +   */
   1.783 +  readAddonWarn: function ()
   1.784 +  {
   1.785 +    var preference = document.getElementById("app.update.mode");
   1.786 +    var warn = preference.value != 0;
   1.787 +    gAdvancedPane._modePreference = warn ? preference.value : 1;
   1.788 +    return warn;
   1.789 +  },
   1.790 +
   1.791 +  /**
   1.792 +   * Converts the state of the "Warn me if this will disable extensions or
   1.793 +   * themes" checkbox into the integer preference which represents it,
   1.794 +   * returning that value.
   1.795 +   */
   1.796 +  writeAddonWarn: function ()
   1.797 +  {
   1.798 +    var warnIncompatible = document.getElementById("warnIncompatible");
   1.799 +    return !warnIncompatible.checked ? 0 : gAdvancedPane._modePreference;
   1.800 +  },
   1.801 +
   1.802 +  /**
   1.803 +   * Displays the history of installed updates.
   1.804 +   */
   1.805 +  showUpdates: function ()
   1.806 +  {
   1.807 +    var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"]
   1.808 +                             .createInstance(Components.interfaces.nsIUpdatePrompt);
   1.809 +    prompter.showUpdateHistory(window);
   1.810 +  },
   1.811 +#endif
   1.812 +
   1.813 +  // ENCRYPTION TAB
   1.814 +
   1.815 +  /*
   1.816 +   * Preferences:
   1.817 +   *
   1.818 +   * security.default_personal_cert
   1.819 +   * - a string:
   1.820 +   *     "Select Automatically"   select a certificate automatically when a site
   1.821 +   *                              requests one
   1.822 +   *     "Ask Every Time"         present a dialog to the user so he can select
   1.823 +   *                              the certificate to use on a site which
   1.824 +   *                              requests one
   1.825 +   */
   1.826 +
   1.827 +  /**
   1.828 +   * Displays the user's certificates and associated options.
   1.829 +   */
   1.830 +  showCertificates: function ()
   1.831 +  {
   1.832 +    document.documentElement.openWindow("mozilla:certmanager",
   1.833 +                                        "chrome://pippki/content/certManager.xul",
   1.834 +                                        "", null);
   1.835 +  },
   1.836 +
   1.837 +  /**
   1.838 +   * Displays a dialog in which OCSP preferences can be configured.
   1.839 +   */
   1.840 +  showOCSP: function ()
   1.841 +  {
   1.842 +    document.documentElement.openSubDialog("chrome://mozapps/content/preferences/ocsp.xul",
   1.843 +                                           "", null);
   1.844 +  },
   1.845 +
   1.846 +  /**
   1.847 +   * Displays a dialog from which the user can manage his security devices.
   1.848 +   */
   1.849 +  showSecurityDevices: function ()
   1.850 +  {
   1.851 +    document.documentElement.openWindow("mozilla:devicemanager",
   1.852 +                                        "chrome://pippki/content/device_manager.xul",
   1.853 +                                        "", null);
   1.854 +  }
   1.855 +#ifdef HAVE_SHELL_SERVICE
   1.856 +  ,
   1.857 +
   1.858 +  // SYSTEM DEFAULTS
   1.859 +
   1.860 +  /*
   1.861 +   * Preferences:
   1.862 +   *
   1.863 +   * browser.shell.checkDefault
   1.864 +   * - true if a default-browser check (and prompt to make it so if necessary)
   1.865 +   *   occurs at startup, false otherwise
   1.866 +   */
   1.867 +
   1.868 +  /**
   1.869 +   * Show button for setting browser as default browser or information that
   1.870 +   * browser is already the default browser.
   1.871 +   */
   1.872 +  updateSetDefaultBrowser: function()
   1.873 +  {
   1.874 +    let shellSvc = getShellService();
   1.875 +    let setDefaultPane = document.getElementById("setDefaultPane");
   1.876 +    if (!shellSvc) {
   1.877 +      setDefaultPane.hidden = true;
   1.878 +      document.getElementById("alwaysCheckDefault").disabled = true;
   1.879 +      return;
   1.880 +    }
   1.881 +    let selectedIndex =
   1.882 +      shellSvc.isDefaultBrowser(false, true) ? 1 : 0;
   1.883 +    setDefaultPane.selectedIndex = selectedIndex;
   1.884 +  },
   1.885 +
   1.886 +  /**
   1.887 +   * Set browser as the operating system default browser.
   1.888 +   */
   1.889 +  setDefaultBrowser: function()
   1.890 +  {
   1.891 +    let shellSvc = getShellService();
   1.892 +    if (!shellSvc)
   1.893 +      return;
   1.894 +    shellSvc.setDefaultBrowser(true, false);
   1.895 +    let selectedIndex =
   1.896 +      shellSvc.isDefaultBrowser(false, true) ? 1 : 0;
   1.897 +    document.getElementById("setDefaultPane").selectedIndex = selectedIndex;
   1.898 +  }
   1.899 +#endif
   1.900 +};

mercurial