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

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 // Load DownloadUtils module for convertByteUnits
michael@0 6 Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
michael@0 7 Components.utils.import("resource://gre/modules/LoadContextInfo.jsm");
michael@0 8 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 9
michael@0 10 var gAdvancedPane = {
michael@0 11 _inited: false,
michael@0 12
michael@0 13 /**
michael@0 14 * Brings the appropriate tab to the front and initializes various bits of UI.
michael@0 15 */
michael@0 16 init: function ()
michael@0 17 {
michael@0 18 this._inited = true;
michael@0 19 var advancedPrefs = document.getElementById("advancedPrefs");
michael@0 20
michael@0 21 var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
michael@0 22 if (preference.value !== null)
michael@0 23 advancedPrefs.selectedIndex = preference.value;
michael@0 24
michael@0 25 #ifdef HAVE_SHELL_SERVICE
michael@0 26 this.updateSetDefaultBrowser();
michael@0 27 #ifdef XP_WIN
michael@0 28 // In Windows 8 we launch the control panel since it's the only
michael@0 29 // way to get all file type association prefs. So we don't know
michael@0 30 // when the user will select the default. We refresh here periodically
michael@0 31 // in case the default changes. On other Windows OS's defaults can also
michael@0 32 // be set while the prefs are open.
michael@0 33 window.setInterval(this.updateSetDefaultBrowser, 1000);
michael@0 34
michael@0 35 #ifdef MOZ_METRO
michael@0 36 // Pre Windows 8, we should hide the update related settings
michael@0 37 // for the Metro browser
michael@0 38 let version = Components.classes["@mozilla.org/system-info;1"].
michael@0 39 getService(Components.interfaces.nsIPropertyBag2).
michael@0 40 getProperty("version");
michael@0 41 let preWin8 = parseFloat(version) < 6.2;
michael@0 42 this._showingWin8Prefs = !preWin8;
michael@0 43 if (preWin8) {
michael@0 44 ["autoMetro", "autoMetroIndent"].forEach(
michael@0 45 function(id) document.getElementById(id).collapsed = true
michael@0 46 );
michael@0 47 } else {
michael@0 48 let brandShortName =
michael@0 49 document.getElementById("bundleBrand").getString("brandShortName");
michael@0 50 let bundlePrefs = document.getElementById("bundlePreferences");
michael@0 51 let autoDesktop = document.getElementById("autoDesktop");
michael@0 52 autoDesktop.label =
michael@0 53 bundlePrefs.getFormattedString("updateAutoDesktop.label",
michael@0 54 [brandShortName]);
michael@0 55 autoDesktop.accessKey =
michael@0 56 bundlePrefs.getString("updateAutoDesktop.accessKey");
michael@0 57 }
michael@0 58 #endif
michael@0 59 #endif
michael@0 60 #endif
michael@0 61 #ifdef MOZ_UPDATER
michael@0 62 this.updateReadPrefs();
michael@0 63 #endif
michael@0 64 this.updateOfflineApps();
michael@0 65 #ifdef MOZ_CRASHREPORTER
michael@0 66 this.initSubmitCrashes();
michael@0 67 #endif
michael@0 68 this.initTelemetry();
michael@0 69 #ifdef MOZ_SERVICES_HEALTHREPORT
michael@0 70 this.initSubmitHealthReport();
michael@0 71 #endif
michael@0 72 this.updateActualCacheSize();
michael@0 73 this.updateActualAppCacheSize();
michael@0 74 },
michael@0 75
michael@0 76 /**
michael@0 77 * Stores the identity of the current tab in preferences so that the selected
michael@0 78 * tab can be persisted between openings of the preferences window.
michael@0 79 */
michael@0 80 tabSelectionChanged: function ()
michael@0 81 {
michael@0 82 if (!this._inited)
michael@0 83 return;
michael@0 84 var advancedPrefs = document.getElementById("advancedPrefs");
michael@0 85 var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
michael@0 86 preference.valueFromPreferences = advancedPrefs.selectedIndex;
michael@0 87 },
michael@0 88
michael@0 89 // GENERAL TAB
michael@0 90
michael@0 91 /*
michael@0 92 * Preferences:
michael@0 93 *
michael@0 94 * accessibility.browsewithcaret
michael@0 95 * - true enables keyboard navigation and selection within web pages using a
michael@0 96 * visible caret, false uses normal keyboard navigation with no caret
michael@0 97 * accessibility.typeaheadfind
michael@0 98 * - when set to true, typing outside text areas and input boxes will
michael@0 99 * automatically start searching for what's typed within the current
michael@0 100 * document; when set to false, no search action happens
michael@0 101 * general.autoScroll
michael@0 102 * - when set to true, clicking the scroll wheel on the mouse activates a
michael@0 103 * mouse mode where moving the mouse down scrolls the document downward with
michael@0 104 * speed correlated with the distance of the cursor from the original
michael@0 105 * position at which the click occurred (and likewise with movement upward);
michael@0 106 * if false, this behavior is disabled
michael@0 107 * general.smoothScroll
michael@0 108 * - set to true to enable finer page scrolling than line-by-line on page-up,
michael@0 109 * page-down, and other such page movements
michael@0 110 * layout.spellcheckDefault
michael@0 111 * - an integer:
michael@0 112 * 0 disables spellchecking
michael@0 113 * 1 enables spellchecking, but only for multiline text fields
michael@0 114 * 2 enables spellchecking for all text fields
michael@0 115 */
michael@0 116
michael@0 117 /**
michael@0 118 * Stores the original value of the spellchecking preference to enable proper
michael@0 119 * restoration if unchanged (since we're mapping a tristate onto a checkbox).
michael@0 120 */
michael@0 121 _storedSpellCheck: 0,
michael@0 122
michael@0 123 /**
michael@0 124 * Returns true if any spellchecking is enabled and false otherwise, caching
michael@0 125 * the current value to enable proper pref restoration if the checkbox is
michael@0 126 * never changed.
michael@0 127 */
michael@0 128 readCheckSpelling: function ()
michael@0 129 {
michael@0 130 var pref = document.getElementById("layout.spellcheckDefault");
michael@0 131 this._storedSpellCheck = pref.value;
michael@0 132
michael@0 133 return (pref.value != 0);
michael@0 134 },
michael@0 135
michael@0 136 /**
michael@0 137 * Returns the value of the spellchecking preference represented by UI,
michael@0 138 * preserving the preference's "hidden" value if the preference is
michael@0 139 * unchanged and represents a value not strictly allowed in UI.
michael@0 140 */
michael@0 141 writeCheckSpelling: function ()
michael@0 142 {
michael@0 143 var checkbox = document.getElementById("checkSpelling");
michael@0 144 return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0;
michael@0 145 },
michael@0 146
michael@0 147
michael@0 148 /**
michael@0 149 * When the user toggles the layers.acceleration.disabled pref,
michael@0 150 * sync its new value to the gfx.direct2d.disabled pref too.
michael@0 151 */
michael@0 152 updateHardwareAcceleration: function()
michael@0 153 {
michael@0 154 #ifdef XP_WIN
michael@0 155 var fromPref = document.getElementById("layers.acceleration.disabled");
michael@0 156 var toPref = document.getElementById("gfx.direct2d.disabled");
michael@0 157 toPref.value = fromPref.value;
michael@0 158 #endif
michael@0 159 },
michael@0 160
michael@0 161 // DATA CHOICES TAB
michael@0 162
michael@0 163 /**
michael@0 164 * Set up or hide the Learn More links for various data collection options
michael@0 165 */
michael@0 166 _setupLearnMoreLink: function (pref, element) {
michael@0 167 // set up the Learn More link with the correct URL
michael@0 168 let url = Services.prefs.getCharPref(pref);
michael@0 169 let el = document.getElementById(element);
michael@0 170
michael@0 171 if (url) {
michael@0 172 el.setAttribute("href", url);
michael@0 173 } else {
michael@0 174 el.setAttribute("hidden", "true");
michael@0 175 }
michael@0 176 },
michael@0 177
michael@0 178 /**
michael@0 179 *
michael@0 180 */
michael@0 181 initSubmitCrashes: function ()
michael@0 182 {
michael@0 183 this._setupLearnMoreLink("toolkit.crashreporter.infoURL",
michael@0 184 "crashReporterLearnMore");
michael@0 185
michael@0 186 var checkbox = document.getElementById("submitCrashesBox");
michael@0 187 try {
michael@0 188 var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
michael@0 189 getService(Components.interfaces.nsICrashReporter);
michael@0 190 checkbox.checked = cr.submitReports;
michael@0 191 } catch (e) {
michael@0 192 checkbox.style.display = "none";
michael@0 193 }
michael@0 194 },
michael@0 195
michael@0 196 /**
michael@0 197 *
michael@0 198 */
michael@0 199 updateSubmitCrashes: function ()
michael@0 200 {
michael@0 201 var checkbox = document.getElementById("submitCrashesBox");
michael@0 202 try {
michael@0 203 var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
michael@0 204 getService(Components.interfaces.nsICrashReporter);
michael@0 205 cr.submitReports = checkbox.checked;
michael@0 206 } catch (e) { }
michael@0 207 },
michael@0 208
michael@0 209 /**
michael@0 210 * The preference/checkbox is configured in XUL.
michael@0 211 *
michael@0 212 * In all cases, set up the Learn More link sanely.
michael@0 213 */
michael@0 214 initTelemetry: function ()
michael@0 215 {
michael@0 216 #ifdef MOZ_TELEMETRY_REPORTING
michael@0 217 this._setupLearnMoreLink("toolkit.telemetry.infoURL", "telemetryLearnMore");
michael@0 218 #endif
michael@0 219 },
michael@0 220
michael@0 221 #ifdef MOZ_SERVICES_HEALTHREPORT
michael@0 222 /**
michael@0 223 * Initialize the health report service reference and checkbox.
michael@0 224 */
michael@0 225 initSubmitHealthReport: function () {
michael@0 226 this._setupLearnMoreLink("datareporting.healthreport.infoURL", "FHRLearnMore");
michael@0 227
michael@0 228 let policy = Components.classes["@mozilla.org/datareporting/service;1"]
michael@0 229 .getService(Components.interfaces.nsISupports)
michael@0 230 .wrappedJSObject
michael@0 231 .policy;
michael@0 232
michael@0 233 let checkbox = document.getElementById("submitHealthReportBox");
michael@0 234
michael@0 235 if (!policy || policy.healthReportUploadLocked) {
michael@0 236 checkbox.setAttribute("disabled", "true");
michael@0 237 return;
michael@0 238 }
michael@0 239
michael@0 240 checkbox.checked = policy.healthReportUploadEnabled;
michael@0 241 },
michael@0 242
michael@0 243 /**
michael@0 244 * Update the health report policy acceptance with state from checkbox.
michael@0 245 */
michael@0 246 updateSubmitHealthReport: function () {
michael@0 247 let policy = Components.classes["@mozilla.org/datareporting/service;1"]
michael@0 248 .getService(Components.interfaces.nsISupports)
michael@0 249 .wrappedJSObject
michael@0 250 .policy;
michael@0 251
michael@0 252 if (!policy) {
michael@0 253 return;
michael@0 254 }
michael@0 255
michael@0 256 let checkbox = document.getElementById("submitHealthReportBox");
michael@0 257 policy.recordHealthReportUploadEnabled(checkbox.checked,
michael@0 258 "Checkbox from preferences pane");
michael@0 259 },
michael@0 260 #endif
michael@0 261
michael@0 262 // NETWORK TAB
michael@0 263
michael@0 264 /*
michael@0 265 * Preferences:
michael@0 266 *
michael@0 267 * browser.cache.disk.capacity
michael@0 268 * - the size of the browser cache in KB
michael@0 269 * - Only used if browser.cache.disk.smart_size.enabled is disabled
michael@0 270 */
michael@0 271
michael@0 272 /**
michael@0 273 * Displays a dialog in which proxy settings may be changed.
michael@0 274 */
michael@0 275 showConnections: function ()
michael@0 276 {
michael@0 277 openDialog("chrome://browser/content/preferences/connection.xul",
michael@0 278 "mozilla:connectionmanager",
michael@0 279 "modal=yes",
michael@0 280 null);
michael@0 281 },
michael@0 282
michael@0 283 // Retrieves the amount of space currently used by disk cache
michael@0 284 updateActualCacheSize: function ()
michael@0 285 {
michael@0 286 var actualSizeLabel = document.getElementById("actualDiskCacheSize");
michael@0 287 var prefStrBundle = document.getElementById("bundlePreferences");
michael@0 288
michael@0 289 // Needs to root the observer since cache service keeps only a weak reference.
michael@0 290 this.observer = {
michael@0 291 onNetworkCacheDiskConsumption: function(consumption) {
michael@0 292 var size = DownloadUtils.convertByteUnits(consumption);
michael@0 293 actualSizeLabel.value = prefStrBundle.getFormattedString("actualDiskCacheSize", size);
michael@0 294 },
michael@0 295
michael@0 296 QueryInterface: XPCOMUtils.generateQI([
michael@0 297 Components.interfaces.nsICacheStorageConsumptionObserver,
michael@0 298 Components.interfaces.nsISupportsWeakReference
michael@0 299 ])
michael@0 300 };
michael@0 301
michael@0 302 actualSizeLabel.value = prefStrBundle.getString("actualDiskCacheSizeCalculated");
michael@0 303
michael@0 304 var cacheService =
michael@0 305 Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
michael@0 306 .getService(Components.interfaces.nsICacheStorageService);
michael@0 307 cacheService.asyncGetDiskConsumption(this.observer);
michael@0 308 },
michael@0 309
michael@0 310 // Retrieves the amount of space currently used by offline cache
michael@0 311 updateActualAppCacheSize: function ()
michael@0 312 {
michael@0 313 var visitor = {
michael@0 314 visitDevice: function (deviceID, deviceInfo)
michael@0 315 {
michael@0 316 if (deviceID == "offline") {
michael@0 317 var actualSizeLabel = document.getElementById("actualAppCacheSize");
michael@0 318 var sizeStrings = DownloadUtils.convertByteUnits(deviceInfo.totalSize);
michael@0 319 var prefStrBundle = document.getElementById("bundlePreferences");
michael@0 320 var sizeStr = prefStrBundle.getFormattedString("actualAppCacheSize", sizeStrings);
michael@0 321 actualSizeLabel.value = sizeStr;
michael@0 322 }
michael@0 323 // Do not enumerate entries
michael@0 324 return false;
michael@0 325 },
michael@0 326
michael@0 327 visitEntry: function (deviceID, entryInfo)
michael@0 328 {
michael@0 329 // Do not enumerate entries.
michael@0 330 return false;
michael@0 331 }
michael@0 332 };
michael@0 333
michael@0 334 var cacheService =
michael@0 335 Components.classes["@mozilla.org/network/cache-service;1"]
michael@0 336 .getService(Components.interfaces.nsICacheService);
michael@0 337 cacheService.visitEntries(visitor);
michael@0 338 },
michael@0 339
michael@0 340 updateCacheSizeUI: function (smartSizeEnabled)
michael@0 341 {
michael@0 342 document.getElementById("useCacheBefore").disabled = smartSizeEnabled;
michael@0 343 document.getElementById("cacheSize").disabled = smartSizeEnabled;
michael@0 344 document.getElementById("useCacheAfter").disabled = smartSizeEnabled;
michael@0 345 },
michael@0 346
michael@0 347 readSmartSizeEnabled: function ()
michael@0 348 {
michael@0 349 // The smart_size.enabled preference element is inverted="true", so its
michael@0 350 // value is the opposite of the actual pref value
michael@0 351 var disabled = document.getElementById("browser.cache.disk.smart_size.enabled").value;
michael@0 352 this.updateCacheSizeUI(!disabled);
michael@0 353 },
michael@0 354
michael@0 355 /**
michael@0 356 * Converts the cache size from units of KB to units of MB and returns that
michael@0 357 * value.
michael@0 358 */
michael@0 359 readCacheSize: function ()
michael@0 360 {
michael@0 361 var preference = document.getElementById("browser.cache.disk.capacity");
michael@0 362 return preference.value / 1024;
michael@0 363 },
michael@0 364
michael@0 365 /**
michael@0 366 * Converts the cache size as specified in UI (in MB) to KB and returns that
michael@0 367 * value.
michael@0 368 */
michael@0 369 writeCacheSize: function ()
michael@0 370 {
michael@0 371 var cacheSize = document.getElementById("cacheSize");
michael@0 372 var intValue = parseInt(cacheSize.value, 10);
michael@0 373 return isNaN(intValue) ? 0 : intValue * 1024;
michael@0 374 },
michael@0 375
michael@0 376 /**
michael@0 377 * Clears the cache.
michael@0 378 */
michael@0 379 clearCache: function ()
michael@0 380 {
michael@0 381 var cache = Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
michael@0 382 .getService(Components.interfaces.nsICacheStorageService);
michael@0 383 try {
michael@0 384 cache.clear();
michael@0 385 } catch(ex) {}
michael@0 386 this.updateActualCacheSize();
michael@0 387 },
michael@0 388
michael@0 389 /**
michael@0 390 * Clears the application cache.
michael@0 391 */
michael@0 392 clearOfflineAppCache: function ()
michael@0 393 {
michael@0 394 Components.utils.import("resource:///modules/offlineAppCache.jsm");
michael@0 395 OfflineAppCacheHelper.clear();
michael@0 396
michael@0 397 this.updateActualAppCacheSize();
michael@0 398 this.updateOfflineApps();
michael@0 399 },
michael@0 400
michael@0 401 readOfflineNotify: function()
michael@0 402 {
michael@0 403 var pref = document.getElementById("browser.offline-apps.notify");
michael@0 404 var button = document.getElementById("offlineNotifyExceptions");
michael@0 405 button.disabled = !pref.value;
michael@0 406 return pref.value;
michael@0 407 },
michael@0 408
michael@0 409 showOfflineExceptions: function()
michael@0 410 {
michael@0 411 var bundlePreferences = document.getElementById("bundlePreferences");
michael@0 412 var params = { blockVisible : false,
michael@0 413 sessionVisible : false,
michael@0 414 allowVisible : false,
michael@0 415 prefilledHost : "",
michael@0 416 permissionType : "offline-app",
michael@0 417 manageCapability : Components.interfaces.nsIPermissionManager.DENY_ACTION,
michael@0 418 windowTitle : bundlePreferences.getString("offlinepermissionstitle"),
michael@0 419 introText : bundlePreferences.getString("offlinepermissionstext") };
michael@0 420 openDialog("chrome://browser/content/preferences/permissions.xul",
michael@0 421 "Browser:Permissions",
michael@0 422 "modal=yes",
michael@0 423 params);
michael@0 424 },
michael@0 425
michael@0 426 // XXX: duplicated in browser.js
michael@0 427 _getOfflineAppUsage: function (host, groups)
michael@0 428 {
michael@0 429 var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
michael@0 430 getService(Components.interfaces.nsIApplicationCacheService);
michael@0 431 if (!groups)
michael@0 432 groups = cacheService.getGroups();
michael@0 433
michael@0 434 var ios = Components.classes["@mozilla.org/network/io-service;1"].
michael@0 435 getService(Components.interfaces.nsIIOService);
michael@0 436
michael@0 437 var usage = 0;
michael@0 438 for (var i = 0; i < groups.length; i++) {
michael@0 439 var uri = ios.newURI(groups[i], null, null);
michael@0 440 if (uri.asciiHost == host) {
michael@0 441 var cache = cacheService.getActiveCache(groups[i]);
michael@0 442 usage += cache.usage;
michael@0 443 }
michael@0 444 }
michael@0 445
michael@0 446 return usage;
michael@0 447 },
michael@0 448
michael@0 449 /**
michael@0 450 * Updates the list of offline applications
michael@0 451 */
michael@0 452 updateOfflineApps: function ()
michael@0 453 {
michael@0 454 var pm = Components.classes["@mozilla.org/permissionmanager;1"]
michael@0 455 .getService(Components.interfaces.nsIPermissionManager);
michael@0 456
michael@0 457 var list = document.getElementById("offlineAppsList");
michael@0 458 while (list.firstChild) {
michael@0 459 list.removeChild(list.firstChild);
michael@0 460 }
michael@0 461
michael@0 462 var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
michael@0 463 getService(Components.interfaces.nsIApplicationCacheService);
michael@0 464 var groups = cacheService.getGroups();
michael@0 465
michael@0 466 var bundle = document.getElementById("bundlePreferences");
michael@0 467
michael@0 468 var enumerator = pm.enumerator;
michael@0 469 while (enumerator.hasMoreElements()) {
michael@0 470 var perm = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
michael@0 471 if (perm.type == "offline-app" &&
michael@0 472 perm.capability != Components.interfaces.nsIPermissionManager.DEFAULT_ACTION &&
michael@0 473 perm.capability != Components.interfaces.nsIPermissionManager.DENY_ACTION) {
michael@0 474 var row = document.createElement("listitem");
michael@0 475 row.id = "";
michael@0 476 row.className = "offlineapp";
michael@0 477 row.setAttribute("host", perm.host);
michael@0 478 var converted = DownloadUtils.
michael@0 479 convertByteUnits(this._getOfflineAppUsage(perm.host, groups));
michael@0 480 row.setAttribute("usage",
michael@0 481 bundle.getFormattedString("offlineAppUsage",
michael@0 482 converted));
michael@0 483 list.appendChild(row);
michael@0 484 }
michael@0 485 }
michael@0 486 },
michael@0 487
michael@0 488 offlineAppSelected: function()
michael@0 489 {
michael@0 490 var removeButton = document.getElementById("offlineAppsListRemove");
michael@0 491 var list = document.getElementById("offlineAppsList");
michael@0 492 if (list.selectedItem) {
michael@0 493 removeButton.setAttribute("disabled", "false");
michael@0 494 } else {
michael@0 495 removeButton.setAttribute("disabled", "true");
michael@0 496 }
michael@0 497 },
michael@0 498
michael@0 499 removeOfflineApp: function()
michael@0 500 {
michael@0 501 var list = document.getElementById("offlineAppsList");
michael@0 502 var item = list.selectedItem;
michael@0 503 var host = item.getAttribute("host");
michael@0 504
michael@0 505 var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
michael@0 506 .getService(Components.interfaces.nsIPromptService);
michael@0 507 var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 +
michael@0 508 prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1;
michael@0 509
michael@0 510 var bundle = document.getElementById("bundlePreferences");
michael@0 511 var title = bundle.getString("offlineAppRemoveTitle");
michael@0 512 var prompt = bundle.getFormattedString("offlineAppRemovePrompt", [host]);
michael@0 513 var confirm = bundle.getString("offlineAppRemoveConfirm");
michael@0 514 var result = prompts.confirmEx(window, title, prompt, flags, confirm,
michael@0 515 null, null, null, {});
michael@0 516 if (result != 0)
michael@0 517 return;
michael@0 518
michael@0 519 // clear offline cache entries
michael@0 520 var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"].
michael@0 521 getService(Components.interfaces.nsIApplicationCacheService);
michael@0 522 var ios = Components.classes["@mozilla.org/network/io-service;1"].
michael@0 523 getService(Components.interfaces.nsIIOService);
michael@0 524 var groups = cacheService.getGroups();
michael@0 525 for (var i = 0; i < groups.length; i++) {
michael@0 526 var uri = ios.newURI(groups[i], null, null);
michael@0 527 if (uri.asciiHost == host) {
michael@0 528 var cache = cacheService.getActiveCache(groups[i]);
michael@0 529 cache.discard();
michael@0 530 }
michael@0 531 }
michael@0 532
michael@0 533 // remove the permission
michael@0 534 var pm = Components.classes["@mozilla.org/permissionmanager;1"]
michael@0 535 .getService(Components.interfaces.nsIPermissionManager);
michael@0 536 pm.remove(host, "offline-app",
michael@0 537 Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
michael@0 538 pm.remove(host, "offline-app",
michael@0 539 Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
michael@0 540
michael@0 541 list.removeChild(item);
michael@0 542 gAdvancedPane.offlineAppSelected();
michael@0 543 this.updateActualAppCacheSize();
michael@0 544 },
michael@0 545
michael@0 546 // UPDATE TAB
michael@0 547
michael@0 548 /*
michael@0 549 * Preferences:
michael@0 550 *
michael@0 551 * app.update.enabled
michael@0 552 * - true if updates to the application are enabled, false otherwise
michael@0 553 * extensions.update.enabled
michael@0 554 * - true if updates to extensions and themes are enabled, false otherwise
michael@0 555 * browser.search.update
michael@0 556 * - true if updates to search engines are enabled, false otherwise
michael@0 557 * app.update.auto
michael@0 558 * - true if updates should be automatically downloaded and installed,
michael@0 559 * possibly with a warning if incompatible extensions are installed (see
michael@0 560 * app.update.mode); false if the user should be asked what he wants to do
michael@0 561 * when an update is available
michael@0 562 * app.update.mode
michael@0 563 * - an integer:
michael@0 564 * 0 do not warn if an update will disable extensions or themes
michael@0 565 * 1 warn if an update will disable extensions or themes
michael@0 566 * 2 warn if an update will disable extensions or themes *or* if the
michael@0 567 * update is a major update
michael@0 568 */
michael@0 569
michael@0 570 #ifdef MOZ_UPDATER
michael@0 571 /**
michael@0 572 * Selects the item of the radiogroup, and sets the warnIncompatible checkbox
michael@0 573 * based on the pref values and locked states.
michael@0 574 *
michael@0 575 * UI state matrix for update preference conditions
michael@0 576 *
michael@0 577 * UI Components: Preferences
michael@0 578 * Radiogroup i = app.update.enabled
michael@0 579 * Warn before disabling extensions checkbox ii = app.update.auto
michael@0 580 * iii = app.update.mode
michael@0 581 *
michael@0 582 * Disabled states:
michael@0 583 * Element pref value locked disabled
michael@0 584 * radiogroup i t/f f false
michael@0 585 * i t/f *t* *true*
michael@0 586 * ii t/f f false
michael@0 587 * ii t/f *t* *true*
michael@0 588 * iii 0/1/2 t/f false
michael@0 589 * warnIncompatible i t f false
michael@0 590 * i t *t* *true*
michael@0 591 * i *f* t/f *true*
michael@0 592 * ii t f false
michael@0 593 * ii t *t* *true*
michael@0 594 * ii *f* t/f *true*
michael@0 595 * iii 0/1/2 f false
michael@0 596 * iii 0/1/2 *t* *true*
michael@0 597 */
michael@0 598 updateReadPrefs: function ()
michael@0 599 {
michael@0 600 var enabledPref = document.getElementById("app.update.enabled");
michael@0 601 var autoPref = document.getElementById("app.update.auto");
michael@0 602 #ifdef XP_WIN
michael@0 603 #ifdef MOZ_METRO
michael@0 604 var metroEnabledPref = document.getElementById("app.update.metro.enabled");
michael@0 605 #endif
michael@0 606 #endif
michael@0 607 var radiogroup = document.getElementById("updateRadioGroup");
michael@0 608
michael@0 609 if (!enabledPref.value) // Don't care for autoPref.value in this case.
michael@0 610 radiogroup.value="manual"; // 3. Never check for updates.
michael@0 611 #ifdef XP_WIN
michael@0 612 #ifdef MOZ_METRO
michael@0 613 // enabledPref.value && autoPref.value && metroEnabledPref.value
michael@0 614 else if (metroEnabledPref.value && this._showingWin8Prefs)
michael@0 615 radiogroup.value="autoMetro"; // 0. Automatically install updates
michael@0 616 #endif
michael@0 617 #endif
michael@0 618 else if (autoPref.value) // enabledPref.value && autoPref.value
michael@0 619 radiogroup.value="auto"; // 1. Automatically install updates
michael@0 620 else // enabledPref.value && !autoPref.value
michael@0 621 radiogroup.value="checkOnly"; // 2. Check, but let me choose
michael@0 622
michael@0 623 var canCheck = Components.classes["@mozilla.org/updates/update-service;1"].
michael@0 624 getService(Components.interfaces.nsIApplicationUpdateService).
michael@0 625 canCheckForUpdates;
michael@0 626 // canCheck is false if the enabledPref is false and locked,
michael@0 627 // or the binary platform or OS version is not known.
michael@0 628 // A locked pref is sufficient to disable the radiogroup.
michael@0 629 radiogroup.disabled = !canCheck || enabledPref.locked || autoPref.locked;
michael@0 630
michael@0 631 var modePref = document.getElementById("app.update.mode");
michael@0 632 var warnIncompatible = document.getElementById("warnIncompatible");
michael@0 633 // the warnIncompatible checkbox value is set by readAddonWarn
michael@0 634 warnIncompatible.disabled = radiogroup.disabled || modePref.locked ||
michael@0 635 !enabledPref.value || !autoPref.value;
michael@0 636 #ifdef XP_WIN
michael@0 637 #ifdef MOZ_METRO
michael@0 638 if (this._showingWin8Prefs) {
michael@0 639 warnIncompatible.disabled |= metroEnabledPref.value;
michael@0 640 warnIncompatible.checked |= metroEnabledPref.value;
michael@0 641 }
michael@0 642 #endif
michael@0 643 #endif
michael@0 644
michael@0 645 #ifdef MOZ_MAINTENANCE_SERVICE
michael@0 646 // Check to see if the maintenance service is installed.
michael@0 647 // If it is don't show the preference at all.
michael@0 648 var installed;
michael@0 649 try {
michael@0 650 var wrk = Components.classes["@mozilla.org/windows-registry-key;1"]
michael@0 651 .createInstance(Components.interfaces.nsIWindowsRegKey);
michael@0 652 wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,
michael@0 653 "SOFTWARE\\Mozilla\\MaintenanceService",
michael@0 654 wrk.ACCESS_READ | wrk.WOW64_64);
michael@0 655 installed = wrk.readIntValue("Installed");
michael@0 656 wrk.close();
michael@0 657 } catch(e) {
michael@0 658 }
michael@0 659 if (installed != 1) {
michael@0 660 document.getElementById("useService").hidden = true;
michael@0 661 }
michael@0 662 #endif
michael@0 663 },
michael@0 664
michael@0 665 /**
michael@0 666 * Sets the pref values based on the selected item of the radiogroup,
michael@0 667 * and sets the disabled state of the warnIncompatible checkbox accordingly.
michael@0 668 */
michael@0 669 updateWritePrefs: function ()
michael@0 670 {
michael@0 671 var enabledPref = document.getElementById("app.update.enabled");
michael@0 672 var autoPref = document.getElementById("app.update.auto");
michael@0 673 var modePref = document.getElementById("app.update.mode");
michael@0 674 #ifdef XP_WIN
michael@0 675 #ifdef MOZ_METRO
michael@0 676 var metroEnabledPref = document.getElementById("app.update.metro.enabled");
michael@0 677 // Initialize the pref to false only if we're showing the option
michael@0 678 if (this._showingWin8Prefs) {
michael@0 679 metroEnabledPref.value = false;
michael@0 680 }
michael@0 681 #endif
michael@0 682 #endif
michael@0 683 var radiogroup = document.getElementById("updateRadioGroup");
michael@0 684 switch (radiogroup.value) {
michael@0 685 case "auto": // 1. Automatically install updates for Desktop only
michael@0 686 enabledPref.value = true;
michael@0 687 autoPref.value = true;
michael@0 688 break;
michael@0 689 #ifdef XP_WIN
michael@0 690 #ifdef MOZ_METRO
michael@0 691 case "autoMetro": // 0. Automatically install updates for both Metro and Desktop
michael@0 692 enabledPref.value = true;
michael@0 693 autoPref.value = true;
michael@0 694 metroEnabledPref.value = true;
michael@0 695 modePref.value = 1;
michael@0 696 break;
michael@0 697 #endif
michael@0 698 #endif
michael@0 699 case "checkOnly": // 2. Check, but let me choose
michael@0 700 enabledPref.value = true;
michael@0 701 autoPref.value = false;
michael@0 702 break;
michael@0 703 case "manual": // 3. Never check for updates.
michael@0 704 enabledPref.value = false;
michael@0 705 autoPref.value = false;
michael@0 706 }
michael@0 707
michael@0 708 var warnIncompatible = document.getElementById("warnIncompatible");
michael@0 709 warnIncompatible.disabled = enabledPref.locked || !enabledPref.value ||
michael@0 710 autoPref.locked || !autoPref.value ||
michael@0 711 modePref.locked;
michael@0 712 #ifdef XP_WIN
michael@0 713 #ifdef MOZ_METRO
michael@0 714 if (this._showingWin8Prefs) {
michael@0 715 warnIncompatible.disabled |= metroEnabledPref.value;
michael@0 716 warnIncompatible.checked |= metroEnabledPref.value;
michael@0 717 }
michael@0 718 #endif
michael@0 719 #endif
michael@0 720 },
michael@0 721
michael@0 722 /**
michael@0 723 * Stores the value of the app.update.mode preference, which is a tristate
michael@0 724 * integer preference. We store the value here so that we can properly
michael@0 725 * restore the preference value if the UI reflecting the preference value
michael@0 726 * is in a state which can represent either of two integer values (as
michael@0 727 * opposed to only one possible value in the other UI state).
michael@0 728 */
michael@0 729 _modePreference: -1,
michael@0 730
michael@0 731 /**
michael@0 732 * Reads the app.update.mode preference and converts its value into a
michael@0 733 * true/false value for use in determining whether the "Warn me if this will
michael@0 734 * disable extensions or themes" checkbox is checked. We also save the value
michael@0 735 * of the preference so that the preference value can be properly restored if
michael@0 736 * the user's preferences cannot adequately be expressed by a single checkbox.
michael@0 737 *
michael@0 738 * app.update.mode Checkbox State Meaning
michael@0 739 * 0 Unchecked Do not warn
michael@0 740 * 1 Checked Warn if there are incompatibilities
michael@0 741 * 2 Checked Warn if there are incompatibilities,
michael@0 742 * or the update is major.
michael@0 743 */
michael@0 744 readAddonWarn: function ()
michael@0 745 {
michael@0 746 var preference = document.getElementById("app.update.mode");
michael@0 747 var warn = preference.value != 0;
michael@0 748 gAdvancedPane._modePreference = warn ? preference.value : 1;
michael@0 749 return warn;
michael@0 750 },
michael@0 751
michael@0 752 /**
michael@0 753 * Converts the state of the "Warn me if this will disable extensions or
michael@0 754 * themes" checkbox into the integer preference which represents it,
michael@0 755 * returning that value.
michael@0 756 */
michael@0 757 writeAddonWarn: function ()
michael@0 758 {
michael@0 759 var warnIncompatible = document.getElementById("warnIncompatible");
michael@0 760 return !warnIncompatible.checked ? 0 : gAdvancedPane._modePreference;
michael@0 761 },
michael@0 762
michael@0 763 /**
michael@0 764 * Displays the history of installed updates.
michael@0 765 */
michael@0 766 showUpdates: function ()
michael@0 767 {
michael@0 768 var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"]
michael@0 769 .createInstance(Components.interfaces.nsIUpdatePrompt);
michael@0 770 prompter.showUpdateHistory(window);
michael@0 771 },
michael@0 772 #endif
michael@0 773
michael@0 774 // ENCRYPTION TAB
michael@0 775
michael@0 776 /*
michael@0 777 * Preferences:
michael@0 778 *
michael@0 779 * security.default_personal_cert
michael@0 780 * - a string:
michael@0 781 * "Select Automatically" select a certificate automatically when a site
michael@0 782 * requests one
michael@0 783 * "Ask Every Time" present a dialog to the user so he can select
michael@0 784 * the certificate to use on a site which
michael@0 785 * requests one
michael@0 786 */
michael@0 787
michael@0 788 /**
michael@0 789 * Displays the user's certificates and associated options.
michael@0 790 */
michael@0 791 showCertificates: function ()
michael@0 792 {
michael@0 793 openDialog("chrome://pippki/content/certManager.xul",
michael@0 794 "mozilla:certmanager",
michael@0 795 "modal=yes", null);
michael@0 796 },
michael@0 797
michael@0 798 /**
michael@0 799 * Displays a dialog in which OCSP preferences can be configured.
michael@0 800 */
michael@0 801 showOCSP: function ()
michael@0 802 {
michael@0 803 openDialog("chrome://mozapps/content/preferences/ocsp.xul",
michael@0 804 "mozilla:crlmanager",
michael@0 805 "modal=yes", null);
michael@0 806 },
michael@0 807
michael@0 808 /**
michael@0 809 * Displays a dialog from which the user can manage his security devices.
michael@0 810 */
michael@0 811 showSecurityDevices: function ()
michael@0 812 {
michael@0 813 openDialog("chrome://pippki/content/device_manager.xul",
michael@0 814 "mozilla:devicemanager",
michael@0 815 "modal=yes", null);
michael@0 816 }
michael@0 817 #ifdef HAVE_SHELL_SERVICE
michael@0 818 ,
michael@0 819
michael@0 820 // SYSTEM DEFAULTS
michael@0 821
michael@0 822 /*
michael@0 823 * Preferences:
michael@0 824 *
michael@0 825 * browser.shell.checkDefault
michael@0 826 * - true if a default-browser check (and prompt to make it so if necessary)
michael@0 827 * occurs at startup, false otherwise
michael@0 828 */
michael@0 829
michael@0 830 /**
michael@0 831 * Show button for setting browser as default browser or information that
michael@0 832 * browser is already the default browser.
michael@0 833 */
michael@0 834 updateSetDefaultBrowser: function()
michael@0 835 {
michael@0 836 let shellSvc = getShellService();
michael@0 837 let setDefaultPane = document.getElementById("setDefaultPane");
michael@0 838 if (!shellSvc) {
michael@0 839 setDefaultPane.hidden = true;
michael@0 840 document.getElementById("alwaysCheckDefault").disabled = true;
michael@0 841 return;
michael@0 842 }
michael@0 843 let selectedIndex =
michael@0 844 shellSvc.isDefaultBrowser(false, true) ? 1 : 0;
michael@0 845 setDefaultPane.selectedIndex = selectedIndex;
michael@0 846 },
michael@0 847
michael@0 848 /**
michael@0 849 * Set browser as the operating system default browser.
michael@0 850 */
michael@0 851 setDefaultBrowser: function()
michael@0 852 {
michael@0 853 let shellSvc = getShellService();
michael@0 854 if (!shellSvc)
michael@0 855 return;
michael@0 856 shellSvc.setDefaultBrowser(true, false);
michael@0 857 let selectedIndex =
michael@0 858 shellSvc.isDefaultBrowser(false, true) ? 1 : 0;
michael@0 859 document.getElementById("setDefaultPane").selectedIndex = selectedIndex;
michael@0 860 }
michael@0 861 #endif
michael@0 862 };

mercurial