browser/components/preferences/advanced.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial