browser/components/preferences/in-content/advanced.js

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

mercurial