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: Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); michael@0: michael@0: var gSecurityPane = { michael@0: _pane: null, michael@0: michael@0: /** michael@0: * Initializes master password UI. michael@0: */ michael@0: init: function () michael@0: { michael@0: this._pane = document.getElementById("paneSecurity"); michael@0: this._initMasterPasswordUI(); michael@0: }, michael@0: michael@0: // ADD-ONS michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * xpinstall.whitelist.required michael@0: * - true if a site must be added to a site whitelist before extensions michael@0: * provided by the site may be installed from it, false if the extension michael@0: * may be directly installed after a confirmation dialog michael@0: */ michael@0: michael@0: /** michael@0: * Enables/disables the add-ons Exceptions button depending on whether michael@0: * or not add-on installation warnings are displayed. michael@0: */ michael@0: readWarnAddonInstall: function () michael@0: { michael@0: var warn = document.getElementById("xpinstall.whitelist.required"); michael@0: var exceptions = document.getElementById("addonExceptions"); michael@0: michael@0: exceptions.disabled = !warn.value; michael@0: michael@0: // don't override the preference value michael@0: return undefined; michael@0: }, michael@0: michael@0: /** michael@0: * Displays the exceptions lists for add-on installation warnings. michael@0: */ michael@0: showAddonExceptions: function () michael@0: { michael@0: var bundlePrefs = document.getElementById("bundlePreferences"); michael@0: michael@0: var params = this._addonParams; michael@0: if (!params.windowTitle || !params.introText) { michael@0: params.windowTitle = bundlePrefs.getString("addons_permissions_title"); michael@0: params.introText = bundlePrefs.getString("addonspermissionstext"); michael@0: } michael@0: 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: /** michael@0: * Parameters for the add-on install permissions dialog. michael@0: */ michael@0: _addonParams: michael@0: { michael@0: blockVisible: false, michael@0: sessionVisible: false, michael@0: allowVisible: true, michael@0: prefilledHost: "", michael@0: permissionType: "install" michael@0: }, michael@0: michael@0: // PASSWORDS michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * signon.rememberSignons michael@0: * - true if passwords are remembered, false otherwise michael@0: */ michael@0: michael@0: /** michael@0: * Enables/disables the Exceptions button used to configure sites where michael@0: * passwords are never saved. When browser is set to start in Private michael@0: * Browsing mode, the "Remember passwords" UI is useless, so we disable it. michael@0: */ michael@0: readSavePasswords: function () michael@0: { michael@0: var pref = document.getElementById("signon.rememberSignons"); michael@0: var excepts = document.getElementById("passwordExceptions"); michael@0: michael@0: if (PrivateBrowsingUtils.permanentPrivateBrowsing) { michael@0: document.getElementById("savePasswords").disabled = true; michael@0: excepts.disabled = true; michael@0: return false; michael@0: } else { michael@0: excepts.disabled = !pref.value; michael@0: // don't override pref value in UI michael@0: return undefined; michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * Displays a dialog in which the user can view and modify the list of sites michael@0: * where passwords are never saved. michael@0: */ michael@0: showPasswordExceptions: function () michael@0: { michael@0: openDialog("chrome://passwordmgr/content/passwordManagerExceptions.xul", michael@0: "Toolkit:PasswordManagerExceptions", michael@0: "modal=yes", michael@0: null); michael@0: }, michael@0: michael@0: /** michael@0: * Initializes master password UI: the "use master password" checkbox, selects michael@0: * the master password button to show, and enables/disables it as necessary. michael@0: * The master password is controlled by various bits of NSS functionality, so michael@0: * the UI for it can't be controlled by the normal preference bindings. michael@0: */ michael@0: _initMasterPasswordUI: function () michael@0: { michael@0: var noMP = !this._masterPasswordSet(); michael@0: michael@0: var button = document.getElementById("changeMasterPassword"); michael@0: button.disabled = noMP; michael@0: michael@0: var checkbox = document.getElementById("useMasterPassword"); michael@0: checkbox.checked = !noMP; michael@0: }, michael@0: michael@0: /** michael@0: * Returns true if the user has a master password set and false otherwise. michael@0: */ michael@0: _masterPasswordSet: function () michael@0: { michael@0: var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"]. michael@0: getService(Ci.nsIPKCS11ModuleDB); michael@0: var slot = secmodDB.findSlotByName(""); michael@0: if (slot) { michael@0: var status = slot.status; michael@0: var hasMP = status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED && michael@0: status != Ci.nsIPKCS11Slot.SLOT_READY; michael@0: return hasMP; michael@0: } else { michael@0: // XXX I have no bloody idea what this means michael@0: return false; michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * Enables/disables the master password button depending on the state of the michael@0: * "use master password" checkbox, and prompts for master password removal if michael@0: * one is set. michael@0: */ michael@0: updateMasterPasswordButton: function () michael@0: { michael@0: var checkbox = document.getElementById("useMasterPassword"); michael@0: var button = document.getElementById("changeMasterPassword"); michael@0: button.disabled = !checkbox.checked; michael@0: michael@0: // unchecking the checkbox should try to immediately remove the master michael@0: // password, because it's impossible to non-destructively remove the master michael@0: // password used to encrypt all the passwords without providing it (by michael@0: // design), and it would be extremely odd to pop up that dialog when the michael@0: // user closes the prefwindow and saves his settings michael@0: if (!checkbox.checked) michael@0: this._removeMasterPassword(); michael@0: else michael@0: this.changeMasterPassword(); michael@0: michael@0: this._initMasterPasswordUI(); michael@0: }, michael@0: michael@0: /** michael@0: * Displays the "remove master password" dialog to allow the user to remove michael@0: * the current master password. When the dialog is dismissed, master password michael@0: * UI is automatically updated. michael@0: */ michael@0: _removeMasterPassword: function () michael@0: { michael@0: var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"]. michael@0: getService(Ci.nsIPKCS11ModuleDB); michael@0: if (secmodDB.isFIPSEnabled) { michael@0: var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"]. michael@0: getService(Ci.nsIPromptService); michael@0: var bundle = document.getElementById("bundlePreferences"); michael@0: promptService.alert(window, michael@0: bundle.getString("pw_change_failed_title"), michael@0: bundle.getString("pw_change2empty_in_fips_mode")); michael@0: } michael@0: else { michael@0: openDialog("chrome://mozapps/content/preferences/removemp.xul", michael@0: "Toolkit:RemoveMasterPassword", "modal=yes", null); michael@0: } michael@0: this._initMasterPasswordUI(); michael@0: }, michael@0: michael@0: /** michael@0: * Displays a dialog in which the master password may be changed. michael@0: */ michael@0: changeMasterPassword: function () michael@0: { michael@0: openDialog("chrome://mozapps/content/preferences/changemp.xul", michael@0: "Toolkit:ChangeMasterPassword", "modal=yes", null); michael@0: this._initMasterPasswordUI(); michael@0: }, michael@0: michael@0: /** michael@0: * Shows the sites where the user has saved passwords and the associated login michael@0: * information. michael@0: */ michael@0: showPasswords: function () michael@0: { michael@0: openDialog("chrome://passwordmgr/content/passwordManager.xul", michael@0: "Toolkit:PasswordManager", michael@0: "modal=yes", null); michael@0: } michael@0: michael@0: };