michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Load DownloadUtils module for convertByteUnits michael@0: Components.utils.import("resource://gre/modules/DownloadUtils.jsm"); michael@0: Components.utils.import("resource://gre/modules/LoadContextInfo.jsm"); michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: var gAdvancedPane = { michael@0: _inited: false, michael@0: michael@0: /** michael@0: * Brings the appropriate tab to the front and initializes various bits of UI. michael@0: */ michael@0: init: function () michael@0: { michael@0: this._inited = true; michael@0: var advancedPrefs = document.getElementById("advancedPrefs"); michael@0: michael@0: var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex"); michael@0: if (preference.value !== null) michael@0: advancedPrefs.selectedIndex = preference.value; michael@0: michael@0: #ifdef HAVE_SHELL_SERVICE michael@0: this.updateSetDefaultBrowser(); michael@0: #ifdef XP_WIN michael@0: // In Windows 8 we launch the control panel since it's the only michael@0: // way to get all file type association prefs. So we don't know michael@0: // when the user will select the default. We refresh here periodically michael@0: // in case the default changes. On other Windows OS's defaults can also michael@0: // be set while the prefs are open. michael@0: window.setInterval(this.updateSetDefaultBrowser, 1000); michael@0: michael@0: #ifdef MOZ_METRO michael@0: // Pre Windows 8, we should hide the update related settings michael@0: // for the Metro browser michael@0: let version = Components.classes["@mozilla.org/system-info;1"]. michael@0: getService(Components.interfaces.nsIPropertyBag2). michael@0: getProperty("version"); michael@0: let preWin8 = parseFloat(version) < 6.2; michael@0: this._showingWin8Prefs = !preWin8; michael@0: if (preWin8) { michael@0: ["autoMetro", "autoMetroIndent"].forEach( michael@0: function(id) document.getElementById(id).collapsed = true michael@0: ); michael@0: } else { michael@0: let brandShortName = michael@0: document.getElementById("bundleBrand").getString("brandShortName"); michael@0: let bundlePrefs = document.getElementById("bundlePreferences"); michael@0: let autoDesktop = document.getElementById("autoDesktop"); michael@0: autoDesktop.label = michael@0: bundlePrefs.getFormattedString("updateAutoDesktop.label", michael@0: [brandShortName]); michael@0: autoDesktop.accessKey = michael@0: bundlePrefs.getString("updateAutoDesktop.accessKey"); michael@0: } michael@0: #endif michael@0: #endif michael@0: #endif michael@0: #ifdef MOZ_UPDATER michael@0: this.updateReadPrefs(); michael@0: #endif michael@0: this.updateOfflineApps(); michael@0: #ifdef MOZ_CRASHREPORTER michael@0: this.initSubmitCrashes(); michael@0: #endif michael@0: this.initTelemetry(); michael@0: #ifdef MOZ_SERVICES_HEALTHREPORT michael@0: this.initSubmitHealthReport(); michael@0: #endif michael@0: this.updateActualCacheSize(); michael@0: this.updateActualAppCacheSize(); michael@0: }, michael@0: michael@0: /** michael@0: * Stores the identity of the current tab in preferences so that the selected michael@0: * tab can be persisted between openings of the preferences window. michael@0: */ michael@0: tabSelectionChanged: function () michael@0: { michael@0: if (!this._inited) michael@0: return; michael@0: var advancedPrefs = document.getElementById("advancedPrefs"); michael@0: var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex"); michael@0: preference.valueFromPreferences = advancedPrefs.selectedIndex; michael@0: }, michael@0: michael@0: // GENERAL TAB michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * accessibility.browsewithcaret michael@0: * - true enables keyboard navigation and selection within web pages using a michael@0: * visible caret, false uses normal keyboard navigation with no caret michael@0: * accessibility.typeaheadfind michael@0: * - when set to true, typing outside text areas and input boxes will michael@0: * automatically start searching for what's typed within the current michael@0: * document; when set to false, no search action happens michael@0: * general.autoScroll michael@0: * - when set to true, clicking the scroll wheel on the mouse activates a michael@0: * mouse mode where moving the mouse down scrolls the document downward with michael@0: * speed correlated with the distance of the cursor from the original michael@0: * position at which the click occurred (and likewise with movement upward); michael@0: * if false, this behavior is disabled michael@0: * general.smoothScroll michael@0: * - set to true to enable finer page scrolling than line-by-line on page-up, michael@0: * page-down, and other such page movements michael@0: * layout.spellcheckDefault michael@0: * - an integer: michael@0: * 0 disables spellchecking michael@0: * 1 enables spellchecking, but only for multiline text fields michael@0: * 2 enables spellchecking for all text fields michael@0: */ michael@0: michael@0: /** michael@0: * Stores the original value of the spellchecking preference to enable proper michael@0: * restoration if unchanged (since we're mapping a tristate onto a checkbox). michael@0: */ michael@0: _storedSpellCheck: 0, michael@0: michael@0: /** michael@0: * Returns true if any spellchecking is enabled and false otherwise, caching michael@0: * the current value to enable proper pref restoration if the checkbox is michael@0: * never changed. michael@0: */ michael@0: readCheckSpelling: function () michael@0: { michael@0: var pref = document.getElementById("layout.spellcheckDefault"); michael@0: this._storedSpellCheck = pref.value; michael@0: michael@0: return (pref.value != 0); michael@0: }, michael@0: michael@0: /** michael@0: * Returns the value of the spellchecking preference represented by UI, michael@0: * preserving the preference's "hidden" value if the preference is michael@0: * unchanged and represents a value not strictly allowed in UI. michael@0: */ michael@0: writeCheckSpelling: function () michael@0: { michael@0: var checkbox = document.getElementById("checkSpelling"); michael@0: return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0; michael@0: }, michael@0: michael@0: michael@0: /** michael@0: * When the user toggles the layers.acceleration.disabled pref, michael@0: * sync its new value to the gfx.direct2d.disabled pref too. michael@0: */ michael@0: updateHardwareAcceleration: function() michael@0: { michael@0: #ifdef XP_WIN michael@0: var fromPref = document.getElementById("layers.acceleration.disabled"); michael@0: var toPref = document.getElementById("gfx.direct2d.disabled"); michael@0: toPref.value = fromPref.value; michael@0: #endif michael@0: }, michael@0: michael@0: // DATA CHOICES TAB michael@0: michael@0: /** michael@0: * Set up or hide the Learn More links for various data collection options michael@0: */ michael@0: _setupLearnMoreLink: function (pref, element) { michael@0: // set up the Learn More link with the correct URL michael@0: let url = Services.prefs.getCharPref(pref); michael@0: let el = document.getElementById(element); michael@0: michael@0: if (url) { michael@0: el.setAttribute("href", url); michael@0: } else { michael@0: el.setAttribute("hidden", "true"); michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * michael@0: */ michael@0: initSubmitCrashes: function () michael@0: { michael@0: this._setupLearnMoreLink("toolkit.crashreporter.infoURL", michael@0: "crashReporterLearnMore"); michael@0: michael@0: var checkbox = document.getElementById("submitCrashesBox"); michael@0: try { michael@0: var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"]. michael@0: getService(Components.interfaces.nsICrashReporter); michael@0: checkbox.checked = cr.submitReports; michael@0: } catch (e) { michael@0: checkbox.style.display = "none"; michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * michael@0: */ michael@0: updateSubmitCrashes: function () michael@0: { michael@0: var checkbox = document.getElementById("submitCrashesBox"); michael@0: try { michael@0: var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"]. michael@0: getService(Components.interfaces.nsICrashReporter); michael@0: cr.submitReports = checkbox.checked; michael@0: } catch (e) { } michael@0: }, michael@0: michael@0: /** michael@0: * The preference/checkbox is configured in XUL. michael@0: * michael@0: * In all cases, set up the Learn More link sanely. michael@0: */ michael@0: initTelemetry: function () michael@0: { michael@0: #ifdef MOZ_TELEMETRY_REPORTING michael@0: this._setupLearnMoreLink("toolkit.telemetry.infoURL", "telemetryLearnMore"); michael@0: #endif michael@0: }, michael@0: michael@0: #ifdef MOZ_SERVICES_HEALTHREPORT michael@0: /** michael@0: * Initialize the health report service reference and checkbox. michael@0: */ michael@0: initSubmitHealthReport: function () { michael@0: this._setupLearnMoreLink("datareporting.healthreport.infoURL", "FHRLearnMore"); michael@0: michael@0: let policy = Components.classes["@mozilla.org/datareporting/service;1"] michael@0: .getService(Components.interfaces.nsISupports) michael@0: .wrappedJSObject michael@0: .policy; michael@0: michael@0: let checkbox = document.getElementById("submitHealthReportBox"); michael@0: michael@0: if (!policy || policy.healthReportUploadLocked) { michael@0: checkbox.setAttribute("disabled", "true"); michael@0: return; michael@0: } michael@0: michael@0: checkbox.checked = policy.healthReportUploadEnabled; michael@0: }, michael@0: michael@0: /** michael@0: * Update the health report policy acceptance with state from checkbox. michael@0: */ michael@0: updateSubmitHealthReport: function () { michael@0: let policy = Components.classes["@mozilla.org/datareporting/service;1"] michael@0: .getService(Components.interfaces.nsISupports) michael@0: .wrappedJSObject michael@0: .policy; michael@0: michael@0: if (!policy) { michael@0: return; michael@0: } michael@0: michael@0: let checkbox = document.getElementById("submitHealthReportBox"); michael@0: policy.recordHealthReportUploadEnabled(checkbox.checked, michael@0: "Checkbox from preferences pane"); michael@0: }, michael@0: #endif michael@0: michael@0: // NETWORK TAB michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * browser.cache.disk.capacity michael@0: * - the size of the browser cache in KB michael@0: * - Only used if browser.cache.disk.smart_size.enabled is disabled michael@0: */ michael@0: michael@0: /** michael@0: * Displays a dialog in which proxy settings may be changed. michael@0: */ michael@0: showConnections: function () michael@0: { michael@0: openDialog("chrome://browser/content/preferences/connection.xul", michael@0: "mozilla:connectionmanager", michael@0: "modal=yes", michael@0: null); michael@0: }, michael@0: michael@0: // Retrieves the amount of space currently used by disk cache michael@0: updateActualCacheSize: function () michael@0: { michael@0: var actualSizeLabel = document.getElementById("actualDiskCacheSize"); michael@0: var prefStrBundle = document.getElementById("bundlePreferences"); michael@0: michael@0: // Needs to root the observer since cache service keeps only a weak reference. michael@0: this.observer = { michael@0: onNetworkCacheDiskConsumption: function(consumption) { michael@0: var size = DownloadUtils.convertByteUnits(consumption); michael@0: actualSizeLabel.value = prefStrBundle.getFormattedString("actualDiskCacheSize", size); michael@0: }, michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([ michael@0: Components.interfaces.nsICacheStorageConsumptionObserver, michael@0: Components.interfaces.nsISupportsWeakReference michael@0: ]) michael@0: }; michael@0: michael@0: actualSizeLabel.value = prefStrBundle.getString("actualDiskCacheSizeCalculated"); michael@0: michael@0: var cacheService = michael@0: Components.classes["@mozilla.org/netwerk/cache-storage-service;1"] michael@0: .getService(Components.interfaces.nsICacheStorageService); michael@0: cacheService.asyncGetDiskConsumption(this.observer); michael@0: }, michael@0: michael@0: // Retrieves the amount of space currently used by offline cache michael@0: updateActualAppCacheSize: function () michael@0: { michael@0: var visitor = { michael@0: visitDevice: function (deviceID, deviceInfo) michael@0: { michael@0: if (deviceID == "offline") { michael@0: var actualSizeLabel = document.getElementById("actualAppCacheSize"); michael@0: var sizeStrings = DownloadUtils.convertByteUnits(deviceInfo.totalSize); michael@0: var prefStrBundle = document.getElementById("bundlePreferences"); michael@0: var sizeStr = prefStrBundle.getFormattedString("actualAppCacheSize", sizeStrings); michael@0: actualSizeLabel.value = sizeStr; michael@0: } michael@0: // Do not enumerate entries michael@0: return false; michael@0: }, michael@0: michael@0: visitEntry: function (deviceID, entryInfo) michael@0: { michael@0: // Do not enumerate entries. michael@0: return false; michael@0: } michael@0: }; michael@0: michael@0: var cacheService = michael@0: Components.classes["@mozilla.org/network/cache-service;1"] michael@0: .getService(Components.interfaces.nsICacheService); michael@0: cacheService.visitEntries(visitor); michael@0: }, michael@0: michael@0: updateCacheSizeUI: function (smartSizeEnabled) michael@0: { michael@0: document.getElementById("useCacheBefore").disabled = smartSizeEnabled; michael@0: document.getElementById("cacheSize").disabled = smartSizeEnabled; michael@0: document.getElementById("useCacheAfter").disabled = smartSizeEnabled; michael@0: }, michael@0: michael@0: readSmartSizeEnabled: function () michael@0: { michael@0: // The smart_size.enabled preference element is inverted="true", so its michael@0: // value is the opposite of the actual pref value michael@0: var disabled = document.getElementById("browser.cache.disk.smart_size.enabled").value; michael@0: this.updateCacheSizeUI(!disabled); michael@0: }, michael@0: michael@0: /** michael@0: * Converts the cache size from units of KB to units of MB and returns that michael@0: * value. michael@0: */ michael@0: readCacheSize: function () michael@0: { michael@0: var preference = document.getElementById("browser.cache.disk.capacity"); michael@0: return preference.value / 1024; michael@0: }, michael@0: michael@0: /** michael@0: * Converts the cache size as specified in UI (in MB) to KB and returns that michael@0: * value. michael@0: */ michael@0: writeCacheSize: function () michael@0: { michael@0: var cacheSize = document.getElementById("cacheSize"); michael@0: var intValue = parseInt(cacheSize.value, 10); michael@0: return isNaN(intValue) ? 0 : intValue * 1024; michael@0: }, michael@0: michael@0: /** michael@0: * Clears the cache. michael@0: */ michael@0: clearCache: function () michael@0: { michael@0: var cache = Components.classes["@mozilla.org/netwerk/cache-storage-service;1"] michael@0: .getService(Components.interfaces.nsICacheStorageService); michael@0: try { michael@0: cache.clear(); michael@0: } catch(ex) {} michael@0: this.updateActualCacheSize(); michael@0: }, michael@0: michael@0: /** michael@0: * Clears the application cache. michael@0: */ michael@0: clearOfflineAppCache: function () michael@0: { michael@0: Components.utils.import("resource:///modules/offlineAppCache.jsm"); michael@0: OfflineAppCacheHelper.clear(); michael@0: michael@0: this.updateActualAppCacheSize(); michael@0: this.updateOfflineApps(); michael@0: }, michael@0: michael@0: readOfflineNotify: function() michael@0: { michael@0: var pref = document.getElementById("browser.offline-apps.notify"); michael@0: var button = document.getElementById("offlineNotifyExceptions"); michael@0: button.disabled = !pref.value; michael@0: return pref.value; michael@0: }, michael@0: michael@0: showOfflineExceptions: function() michael@0: { michael@0: var bundlePreferences = document.getElementById("bundlePreferences"); michael@0: var params = { blockVisible : false, michael@0: sessionVisible : false, michael@0: allowVisible : false, michael@0: prefilledHost : "", michael@0: permissionType : "offline-app", michael@0: manageCapability : Components.interfaces.nsIPermissionManager.DENY_ACTION, michael@0: windowTitle : bundlePreferences.getString("offlinepermissionstitle"), michael@0: introText : bundlePreferences.getString("offlinepermissionstext") }; michael@0: openDialog("chrome://browser/content/preferences/permissions.xul", michael@0: "Browser:Permissions", michael@0: "modal=yes", michael@0: params); michael@0: }, michael@0: michael@0: // XXX: duplicated in browser.js michael@0: _getOfflineAppUsage: function (host, groups) michael@0: { michael@0: var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"]. michael@0: getService(Components.interfaces.nsIApplicationCacheService); michael@0: if (!groups) michael@0: groups = cacheService.getGroups(); michael@0: michael@0: var ios = Components.classes["@mozilla.org/network/io-service;1"]. michael@0: getService(Components.interfaces.nsIIOService); michael@0: michael@0: var usage = 0; michael@0: for (var i = 0; i < groups.length; i++) { michael@0: var uri = ios.newURI(groups[i], null, null); michael@0: if (uri.asciiHost == host) { michael@0: var cache = cacheService.getActiveCache(groups[i]); michael@0: usage += cache.usage; michael@0: } michael@0: } michael@0: michael@0: return usage; michael@0: }, michael@0: michael@0: /** michael@0: * Updates the list of offline applications michael@0: */ michael@0: updateOfflineApps: function () michael@0: { michael@0: var pm = Components.classes["@mozilla.org/permissionmanager;1"] michael@0: .getService(Components.interfaces.nsIPermissionManager); michael@0: michael@0: var list = document.getElementById("offlineAppsList"); michael@0: while (list.firstChild) { michael@0: list.removeChild(list.firstChild); michael@0: } michael@0: michael@0: var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"]. michael@0: getService(Components.interfaces.nsIApplicationCacheService); michael@0: var groups = cacheService.getGroups(); michael@0: michael@0: var bundle = document.getElementById("bundlePreferences"); michael@0: michael@0: var enumerator = pm.enumerator; michael@0: while (enumerator.hasMoreElements()) { michael@0: var perm = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission); michael@0: if (perm.type == "offline-app" && michael@0: perm.capability != Components.interfaces.nsIPermissionManager.DEFAULT_ACTION && michael@0: perm.capability != Components.interfaces.nsIPermissionManager.DENY_ACTION) { michael@0: var row = document.createElement("listitem"); michael@0: row.id = ""; michael@0: row.className = "offlineapp"; michael@0: row.setAttribute("host", perm.host); michael@0: var converted = DownloadUtils. michael@0: convertByteUnits(this._getOfflineAppUsage(perm.host, groups)); michael@0: row.setAttribute("usage", michael@0: bundle.getFormattedString("offlineAppUsage", michael@0: converted)); michael@0: list.appendChild(row); michael@0: } michael@0: } michael@0: }, michael@0: michael@0: offlineAppSelected: function() michael@0: { michael@0: var removeButton = document.getElementById("offlineAppsListRemove"); michael@0: var list = document.getElementById("offlineAppsList"); michael@0: if (list.selectedItem) { michael@0: removeButton.setAttribute("disabled", "false"); michael@0: } else { michael@0: removeButton.setAttribute("disabled", "true"); michael@0: } michael@0: }, michael@0: michael@0: removeOfflineApp: function() michael@0: { michael@0: var list = document.getElementById("offlineAppsList"); michael@0: var item = list.selectedItem; michael@0: var host = item.getAttribute("host"); michael@0: michael@0: var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] michael@0: .getService(Components.interfaces.nsIPromptService); michael@0: var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 + michael@0: prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1; michael@0: michael@0: var bundle = document.getElementById("bundlePreferences"); michael@0: var title = bundle.getString("offlineAppRemoveTitle"); michael@0: var prompt = bundle.getFormattedString("offlineAppRemovePrompt", [host]); michael@0: var confirm = bundle.getString("offlineAppRemoveConfirm"); michael@0: var result = prompts.confirmEx(window, title, prompt, flags, confirm, michael@0: null, null, null, {}); michael@0: if (result != 0) michael@0: return; michael@0: michael@0: // clear offline cache entries michael@0: var cacheService = Components.classes["@mozilla.org/network/application-cache-service;1"]. michael@0: getService(Components.interfaces.nsIApplicationCacheService); michael@0: var ios = Components.classes["@mozilla.org/network/io-service;1"]. michael@0: getService(Components.interfaces.nsIIOService); michael@0: var groups = cacheService.getGroups(); michael@0: for (var i = 0; i < groups.length; i++) { michael@0: var uri = ios.newURI(groups[i], null, null); michael@0: if (uri.asciiHost == host) { michael@0: var cache = cacheService.getActiveCache(groups[i]); michael@0: cache.discard(); michael@0: } michael@0: } michael@0: michael@0: // remove the permission michael@0: var pm = Components.classes["@mozilla.org/permissionmanager;1"] michael@0: .getService(Components.interfaces.nsIPermissionManager); michael@0: pm.remove(host, "offline-app", michael@0: Components.interfaces.nsIPermissionManager.ALLOW_ACTION); michael@0: pm.remove(host, "offline-app", michael@0: Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN); michael@0: michael@0: list.removeChild(item); michael@0: gAdvancedPane.offlineAppSelected(); michael@0: this.updateActualAppCacheSize(); michael@0: }, michael@0: michael@0: // UPDATE TAB michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * app.update.enabled michael@0: * - true if updates to the application are enabled, false otherwise michael@0: * extensions.update.enabled michael@0: * - true if updates to extensions and themes are enabled, false otherwise michael@0: * browser.search.update michael@0: * - true if updates to search engines are enabled, false otherwise michael@0: * app.update.auto michael@0: * - true if updates should be automatically downloaded and installed, michael@0: * possibly with a warning if incompatible extensions are installed (see michael@0: * app.update.mode); false if the user should be asked what he wants to do michael@0: * when an update is available michael@0: * app.update.mode michael@0: * - an integer: michael@0: * 0 do not warn if an update will disable extensions or themes michael@0: * 1 warn if an update will disable extensions or themes michael@0: * 2 warn if an update will disable extensions or themes *or* if the michael@0: * update is a major update michael@0: */ michael@0: michael@0: #ifdef MOZ_UPDATER michael@0: /** michael@0: * Selects the item of the radiogroup, and sets the warnIncompatible checkbox michael@0: * based on the pref values and locked states. michael@0: * michael@0: * UI state matrix for update preference conditions michael@0: * michael@0: * UI Components: Preferences michael@0: * Radiogroup i = app.update.enabled michael@0: * Warn before disabling extensions checkbox ii = app.update.auto michael@0: * iii = app.update.mode michael@0: * michael@0: * Disabled states: michael@0: * Element pref value locked disabled michael@0: * radiogroup i t/f f false michael@0: * i t/f *t* *true* michael@0: * ii t/f f false michael@0: * ii t/f *t* *true* michael@0: * iii 0/1/2 t/f false michael@0: * warnIncompatible i t f false michael@0: * i t *t* *true* michael@0: * i *f* t/f *true* michael@0: * ii t f false michael@0: * ii t *t* *true* michael@0: * ii *f* t/f *true* michael@0: * iii 0/1/2 f false michael@0: * iii 0/1/2 *t* *true* michael@0: */ michael@0: updateReadPrefs: function () michael@0: { michael@0: var enabledPref = document.getElementById("app.update.enabled"); michael@0: var autoPref = document.getElementById("app.update.auto"); michael@0: #ifdef XP_WIN michael@0: #ifdef MOZ_METRO michael@0: var metroEnabledPref = document.getElementById("app.update.metro.enabled"); michael@0: #endif michael@0: #endif michael@0: var radiogroup = document.getElementById("updateRadioGroup"); michael@0: michael@0: if (!enabledPref.value) // Don't care for autoPref.value in this case. michael@0: radiogroup.value="manual"; // 3. Never check for updates. michael@0: #ifdef XP_WIN michael@0: #ifdef MOZ_METRO michael@0: // enabledPref.value && autoPref.value && metroEnabledPref.value michael@0: else if (metroEnabledPref.value && this._showingWin8Prefs) michael@0: radiogroup.value="autoMetro"; // 0. Automatically install updates michael@0: #endif michael@0: #endif michael@0: else if (autoPref.value) // enabledPref.value && autoPref.value michael@0: radiogroup.value="auto"; // 1. Automatically install updates michael@0: else // enabledPref.value && !autoPref.value michael@0: radiogroup.value="checkOnly"; // 2. Check, but let me choose michael@0: michael@0: var canCheck = Components.classes["@mozilla.org/updates/update-service;1"]. michael@0: getService(Components.interfaces.nsIApplicationUpdateService). michael@0: canCheckForUpdates; michael@0: // canCheck is false if the enabledPref is false and locked, michael@0: // or the binary platform or OS version is not known. michael@0: // A locked pref is sufficient to disable the radiogroup. michael@0: radiogroup.disabled = !canCheck || enabledPref.locked || autoPref.locked; michael@0: michael@0: var modePref = document.getElementById("app.update.mode"); michael@0: var warnIncompatible = document.getElementById("warnIncompatible"); michael@0: // the warnIncompatible checkbox value is set by readAddonWarn michael@0: warnIncompatible.disabled = radiogroup.disabled || modePref.locked || michael@0: !enabledPref.value || !autoPref.value; michael@0: #ifdef XP_WIN michael@0: #ifdef MOZ_METRO michael@0: if (this._showingWin8Prefs) { michael@0: warnIncompatible.disabled |= metroEnabledPref.value; michael@0: warnIncompatible.checked |= metroEnabledPref.value; michael@0: } michael@0: #endif michael@0: #endif michael@0: michael@0: #ifdef MOZ_MAINTENANCE_SERVICE michael@0: // Check to see if the maintenance service is installed. michael@0: // If it is don't show the preference at all. michael@0: var installed; michael@0: try { michael@0: var wrk = Components.classes["@mozilla.org/windows-registry-key;1"] michael@0: .createInstance(Components.interfaces.nsIWindowsRegKey); michael@0: wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE, michael@0: "SOFTWARE\\Mozilla\\MaintenanceService", michael@0: wrk.ACCESS_READ | wrk.WOW64_64); michael@0: installed = wrk.readIntValue("Installed"); michael@0: wrk.close(); michael@0: } catch(e) { michael@0: } michael@0: if (installed != 1) { michael@0: document.getElementById("useService").hidden = true; michael@0: } michael@0: #endif michael@0: }, michael@0: michael@0: /** michael@0: * Sets the pref values based on the selected item of the radiogroup, michael@0: * and sets the disabled state of the warnIncompatible checkbox accordingly. michael@0: */ michael@0: updateWritePrefs: function () michael@0: { michael@0: var enabledPref = document.getElementById("app.update.enabled"); michael@0: var autoPref = document.getElementById("app.update.auto"); michael@0: var modePref = document.getElementById("app.update.mode"); michael@0: #ifdef XP_WIN michael@0: #ifdef MOZ_METRO michael@0: var metroEnabledPref = document.getElementById("app.update.metro.enabled"); michael@0: // Initialize the pref to false only if we're showing the option michael@0: if (this._showingWin8Prefs) { michael@0: metroEnabledPref.value = false; michael@0: } michael@0: #endif michael@0: #endif michael@0: var radiogroup = document.getElementById("updateRadioGroup"); michael@0: switch (radiogroup.value) { michael@0: case "auto": // 1. Automatically install updates for Desktop only michael@0: enabledPref.value = true; michael@0: autoPref.value = true; michael@0: break; michael@0: #ifdef XP_WIN michael@0: #ifdef MOZ_METRO michael@0: case "autoMetro": // 0. Automatically install updates for both Metro and Desktop michael@0: enabledPref.value = true; michael@0: autoPref.value = true; michael@0: metroEnabledPref.value = true; michael@0: modePref.value = 1; michael@0: break; michael@0: #endif michael@0: #endif michael@0: case "checkOnly": // 2. Check, but let me choose michael@0: enabledPref.value = true; michael@0: autoPref.value = false; michael@0: break; michael@0: case "manual": // 3. Never check for updates. michael@0: enabledPref.value = false; michael@0: autoPref.value = false; michael@0: } michael@0: michael@0: var warnIncompatible = document.getElementById("warnIncompatible"); michael@0: warnIncompatible.disabled = enabledPref.locked || !enabledPref.value || michael@0: autoPref.locked || !autoPref.value || michael@0: modePref.locked; michael@0: #ifdef XP_WIN michael@0: #ifdef MOZ_METRO michael@0: if (this._showingWin8Prefs) { michael@0: warnIncompatible.disabled |= metroEnabledPref.value; michael@0: warnIncompatible.checked |= metroEnabledPref.value; michael@0: } michael@0: #endif michael@0: #endif michael@0: }, michael@0: michael@0: /** michael@0: * Stores the value of the app.update.mode preference, which is a tristate michael@0: * integer preference. We store the value here so that we can properly michael@0: * restore the preference value if the UI reflecting the preference value michael@0: * is in a state which can represent either of two integer values (as michael@0: * opposed to only one possible value in the other UI state). michael@0: */ michael@0: _modePreference: -1, michael@0: michael@0: /** michael@0: * Reads the app.update.mode preference and converts its value into a michael@0: * true/false value for use in determining whether the "Warn me if this will michael@0: * disable extensions or themes" checkbox is checked. We also save the value michael@0: * of the preference so that the preference value can be properly restored if michael@0: * the user's preferences cannot adequately be expressed by a single checkbox. michael@0: * michael@0: * app.update.mode Checkbox State Meaning michael@0: * 0 Unchecked Do not warn michael@0: * 1 Checked Warn if there are incompatibilities michael@0: * 2 Checked Warn if there are incompatibilities, michael@0: * or the update is major. michael@0: */ michael@0: readAddonWarn: function () michael@0: { michael@0: var preference = document.getElementById("app.update.mode"); michael@0: var warn = preference.value != 0; michael@0: gAdvancedPane._modePreference = warn ? preference.value : 1; michael@0: return warn; michael@0: }, michael@0: michael@0: /** michael@0: * Converts the state of the "Warn me if this will disable extensions or michael@0: * themes" checkbox into the integer preference which represents it, michael@0: * returning that value. michael@0: */ michael@0: writeAddonWarn: function () michael@0: { michael@0: var warnIncompatible = document.getElementById("warnIncompatible"); michael@0: return !warnIncompatible.checked ? 0 : gAdvancedPane._modePreference; michael@0: }, michael@0: michael@0: /** michael@0: * Displays the history of installed updates. michael@0: */ michael@0: showUpdates: function () michael@0: { michael@0: var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"] michael@0: .createInstance(Components.interfaces.nsIUpdatePrompt); michael@0: prompter.showUpdateHistory(window); michael@0: }, michael@0: #endif michael@0: michael@0: // ENCRYPTION TAB michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * security.default_personal_cert michael@0: * - a string: michael@0: * "Select Automatically" select a certificate automatically when a site michael@0: * requests one michael@0: * "Ask Every Time" present a dialog to the user so he can select michael@0: * the certificate to use on a site which michael@0: * requests one michael@0: */ michael@0: michael@0: /** michael@0: * Displays the user's certificates and associated options. michael@0: */ michael@0: showCertificates: function () michael@0: { michael@0: openDialog("chrome://pippki/content/certManager.xul", michael@0: "mozilla:certmanager", michael@0: "modal=yes", null); michael@0: }, michael@0: michael@0: /** michael@0: * Displays a dialog in which OCSP preferences can be configured. michael@0: */ michael@0: showOCSP: function () michael@0: { michael@0: openDialog("chrome://mozapps/content/preferences/ocsp.xul", michael@0: "mozilla:crlmanager", michael@0: "modal=yes", null); michael@0: }, michael@0: michael@0: /** michael@0: * Displays a dialog from which the user can manage his security devices. michael@0: */ michael@0: showSecurityDevices: function () michael@0: { michael@0: openDialog("chrome://pippki/content/device_manager.xul", michael@0: "mozilla:devicemanager", michael@0: "modal=yes", null); michael@0: } michael@0: #ifdef HAVE_SHELL_SERVICE michael@0: , michael@0: michael@0: // SYSTEM DEFAULTS michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * browser.shell.checkDefault michael@0: * - true if a default-browser check (and prompt to make it so if necessary) michael@0: * occurs at startup, false otherwise michael@0: */ michael@0: michael@0: /** michael@0: * Show button for setting browser as default browser or information that michael@0: * browser is already the default browser. michael@0: */ michael@0: updateSetDefaultBrowser: function() michael@0: { michael@0: let shellSvc = getShellService(); michael@0: let setDefaultPane = document.getElementById("setDefaultPane"); michael@0: if (!shellSvc) { michael@0: setDefaultPane.hidden = true; michael@0: document.getElementById("alwaysCheckDefault").disabled = true; michael@0: return; michael@0: } michael@0: let selectedIndex = michael@0: shellSvc.isDefaultBrowser(false, true) ? 1 : 0; michael@0: setDefaultPane.selectedIndex = selectedIndex; michael@0: }, michael@0: michael@0: /** michael@0: * Set browser as the operating system default browser. michael@0: */ michael@0: setDefaultBrowser: function() michael@0: { michael@0: let shellSvc = getShellService(); michael@0: if (!shellSvc) michael@0: return; michael@0: shellSvc.setDefaultBrowser(true, false); michael@0: let selectedIndex = michael@0: shellSvc.isDefaultBrowser(false, true) ? 1 : 0; michael@0: document.getElementById("setDefaultPane").selectedIndex = selectedIndex; michael@0: } michael@0: #endif michael@0: };