1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/preferences/in-content/security.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,223 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); 1.9 + 1.10 +var gSecurityPane = { 1.11 + _pane: null, 1.12 + 1.13 + /** 1.14 + * Initializes master password UI. 1.15 + */ 1.16 + init: function () 1.17 + { 1.18 + this._pane = document.getElementById("paneSecurity"); 1.19 + this._initMasterPasswordUI(); 1.20 + }, 1.21 + 1.22 + // ADD-ONS 1.23 + 1.24 + /* 1.25 + * Preferences: 1.26 + * 1.27 + * xpinstall.whitelist.required 1.28 + * - true if a site must be added to a site whitelist before extensions 1.29 + * provided by the site may be installed from it, false if the extension 1.30 + * may be directly installed after a confirmation dialog 1.31 + */ 1.32 + 1.33 + /** 1.34 + * Enables/disables the add-ons Exceptions button depending on whether 1.35 + * or not add-on installation warnings are displayed. 1.36 + */ 1.37 + readWarnAddonInstall: function () 1.38 + { 1.39 + var warn = document.getElementById("xpinstall.whitelist.required"); 1.40 + var exceptions = document.getElementById("addonExceptions"); 1.41 + 1.42 + exceptions.disabled = !warn.value; 1.43 + 1.44 + // don't override the preference value 1.45 + return undefined; 1.46 + }, 1.47 + 1.48 + /** 1.49 + * Displays the exceptions lists for add-on installation warnings. 1.50 + */ 1.51 + showAddonExceptions: function () 1.52 + { 1.53 + var bundlePrefs = document.getElementById("bundlePreferences"); 1.54 + 1.55 + var params = this._addonParams; 1.56 + if (!params.windowTitle || !params.introText) { 1.57 + params.windowTitle = bundlePrefs.getString("addons_permissions_title"); 1.58 + params.introText = bundlePrefs.getString("addonspermissionstext"); 1.59 + } 1.60 + 1.61 + openDialog("chrome://browser/content/preferences/permissions.xul", 1.62 + "Browser:Permissions", 1.63 + "modal=yes", 1.64 + params); 1.65 + }, 1.66 + 1.67 + /** 1.68 + * Parameters for the add-on install permissions dialog. 1.69 + */ 1.70 + _addonParams: 1.71 + { 1.72 + blockVisible: false, 1.73 + sessionVisible: false, 1.74 + allowVisible: true, 1.75 + prefilledHost: "", 1.76 + permissionType: "install" 1.77 + }, 1.78 + 1.79 + // PASSWORDS 1.80 + 1.81 + /* 1.82 + * Preferences: 1.83 + * 1.84 + * signon.rememberSignons 1.85 + * - true if passwords are remembered, false otherwise 1.86 + */ 1.87 + 1.88 + /** 1.89 + * Enables/disables the Exceptions button used to configure sites where 1.90 + * passwords are never saved. When browser is set to start in Private 1.91 + * Browsing mode, the "Remember passwords" UI is useless, so we disable it. 1.92 + */ 1.93 + readSavePasswords: function () 1.94 + { 1.95 + var pref = document.getElementById("signon.rememberSignons"); 1.96 + var excepts = document.getElementById("passwordExceptions"); 1.97 + 1.98 + if (PrivateBrowsingUtils.permanentPrivateBrowsing) { 1.99 + document.getElementById("savePasswords").disabled = true; 1.100 + excepts.disabled = true; 1.101 + return false; 1.102 + } else { 1.103 + excepts.disabled = !pref.value; 1.104 + // don't override pref value in UI 1.105 + return undefined; 1.106 + } 1.107 + }, 1.108 + 1.109 + /** 1.110 + * Displays a dialog in which the user can view and modify the list of sites 1.111 + * where passwords are never saved. 1.112 + */ 1.113 + showPasswordExceptions: function () 1.114 + { 1.115 + openDialog("chrome://passwordmgr/content/passwordManagerExceptions.xul", 1.116 + "Toolkit:PasswordManagerExceptions", 1.117 + "modal=yes", 1.118 + null); 1.119 + }, 1.120 + 1.121 + /** 1.122 + * Initializes master password UI: the "use master password" checkbox, selects 1.123 + * the master password button to show, and enables/disables it as necessary. 1.124 + * The master password is controlled by various bits of NSS functionality, so 1.125 + * the UI for it can't be controlled by the normal preference bindings. 1.126 + */ 1.127 + _initMasterPasswordUI: function () 1.128 + { 1.129 + var noMP = !this._masterPasswordSet(); 1.130 + 1.131 + var button = document.getElementById("changeMasterPassword"); 1.132 + button.disabled = noMP; 1.133 + 1.134 + var checkbox = document.getElementById("useMasterPassword"); 1.135 + checkbox.checked = !noMP; 1.136 + }, 1.137 + 1.138 + /** 1.139 + * Returns true if the user has a master password set and false otherwise. 1.140 + */ 1.141 + _masterPasswordSet: function () 1.142 + { 1.143 + var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"]. 1.144 + getService(Ci.nsIPKCS11ModuleDB); 1.145 + var slot = secmodDB.findSlotByName(""); 1.146 + if (slot) { 1.147 + var status = slot.status; 1.148 + var hasMP = status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED && 1.149 + status != Ci.nsIPKCS11Slot.SLOT_READY; 1.150 + return hasMP; 1.151 + } else { 1.152 + // XXX I have no bloody idea what this means 1.153 + return false; 1.154 + } 1.155 + }, 1.156 + 1.157 + /** 1.158 + * Enables/disables the master password button depending on the state of the 1.159 + * "use master password" checkbox, and prompts for master password removal if 1.160 + * one is set. 1.161 + */ 1.162 + updateMasterPasswordButton: function () 1.163 + { 1.164 + var checkbox = document.getElementById("useMasterPassword"); 1.165 + var button = document.getElementById("changeMasterPassword"); 1.166 + button.disabled = !checkbox.checked; 1.167 + 1.168 + // unchecking the checkbox should try to immediately remove the master 1.169 + // password, because it's impossible to non-destructively remove the master 1.170 + // password used to encrypt all the passwords without providing it (by 1.171 + // design), and it would be extremely odd to pop up that dialog when the 1.172 + // user closes the prefwindow and saves his settings 1.173 + if (!checkbox.checked) 1.174 + this._removeMasterPassword(); 1.175 + else 1.176 + this.changeMasterPassword(); 1.177 + 1.178 + this._initMasterPasswordUI(); 1.179 + }, 1.180 + 1.181 + /** 1.182 + * Displays the "remove master password" dialog to allow the user to remove 1.183 + * the current master password. When the dialog is dismissed, master password 1.184 + * UI is automatically updated. 1.185 + */ 1.186 + _removeMasterPassword: function () 1.187 + { 1.188 + var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"]. 1.189 + getService(Ci.nsIPKCS11ModuleDB); 1.190 + if (secmodDB.isFIPSEnabled) { 1.191 + var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"]. 1.192 + getService(Ci.nsIPromptService); 1.193 + var bundle = document.getElementById("bundlePreferences"); 1.194 + promptService.alert(window, 1.195 + bundle.getString("pw_change_failed_title"), 1.196 + bundle.getString("pw_change2empty_in_fips_mode")); 1.197 + } 1.198 + else { 1.199 + openDialog("chrome://mozapps/content/preferences/removemp.xul", 1.200 + "Toolkit:RemoveMasterPassword", "modal=yes", null); 1.201 + } 1.202 + this._initMasterPasswordUI(); 1.203 + }, 1.204 + 1.205 + /** 1.206 + * Displays a dialog in which the master password may be changed. 1.207 + */ 1.208 + changeMasterPassword: function () 1.209 + { 1.210 + openDialog("chrome://mozapps/content/preferences/changemp.xul", 1.211 + "Toolkit:ChangeMasterPassword", "modal=yes", null); 1.212 + this._initMasterPasswordUI(); 1.213 + }, 1.214 + 1.215 + /** 1.216 + * Shows the sites where the user has saved passwords and the associated login 1.217 + * information. 1.218 + */ 1.219 + showPasswords: function () 1.220 + { 1.221 + openDialog("chrome://passwordmgr/content/passwordManager.xul", 1.222 + "Toolkit:PasswordManager", 1.223 + "modal=yes", null); 1.224 + } 1.225 + 1.226 +};