browser/components/preferences/in-content/security.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 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
michael@0 6
michael@0 7 var gSecurityPane = {
michael@0 8 _pane: null,
michael@0 9
michael@0 10 /**
michael@0 11 * Initializes master password UI.
michael@0 12 */
michael@0 13 init: function ()
michael@0 14 {
michael@0 15 this._pane = document.getElementById("paneSecurity");
michael@0 16 this._initMasterPasswordUI();
michael@0 17 },
michael@0 18
michael@0 19 // ADD-ONS
michael@0 20
michael@0 21 /*
michael@0 22 * Preferences:
michael@0 23 *
michael@0 24 * xpinstall.whitelist.required
michael@0 25 * - true if a site must be added to a site whitelist before extensions
michael@0 26 * provided by the site may be installed from it, false if the extension
michael@0 27 * may be directly installed after a confirmation dialog
michael@0 28 */
michael@0 29
michael@0 30 /**
michael@0 31 * Enables/disables the add-ons Exceptions button depending on whether
michael@0 32 * or not add-on installation warnings are displayed.
michael@0 33 */
michael@0 34 readWarnAddonInstall: function ()
michael@0 35 {
michael@0 36 var warn = document.getElementById("xpinstall.whitelist.required");
michael@0 37 var exceptions = document.getElementById("addonExceptions");
michael@0 38
michael@0 39 exceptions.disabled = !warn.value;
michael@0 40
michael@0 41 // don't override the preference value
michael@0 42 return undefined;
michael@0 43 },
michael@0 44
michael@0 45 /**
michael@0 46 * Displays the exceptions lists for add-on installation warnings.
michael@0 47 */
michael@0 48 showAddonExceptions: function ()
michael@0 49 {
michael@0 50 var bundlePrefs = document.getElementById("bundlePreferences");
michael@0 51
michael@0 52 var params = this._addonParams;
michael@0 53 if (!params.windowTitle || !params.introText) {
michael@0 54 params.windowTitle = bundlePrefs.getString("addons_permissions_title");
michael@0 55 params.introText = bundlePrefs.getString("addonspermissionstext");
michael@0 56 }
michael@0 57
michael@0 58 openDialog("chrome://browser/content/preferences/permissions.xul",
michael@0 59 "Browser:Permissions",
michael@0 60 "modal=yes",
michael@0 61 params);
michael@0 62 },
michael@0 63
michael@0 64 /**
michael@0 65 * Parameters for the add-on install permissions dialog.
michael@0 66 */
michael@0 67 _addonParams:
michael@0 68 {
michael@0 69 blockVisible: false,
michael@0 70 sessionVisible: false,
michael@0 71 allowVisible: true,
michael@0 72 prefilledHost: "",
michael@0 73 permissionType: "install"
michael@0 74 },
michael@0 75
michael@0 76 // PASSWORDS
michael@0 77
michael@0 78 /*
michael@0 79 * Preferences:
michael@0 80 *
michael@0 81 * signon.rememberSignons
michael@0 82 * - true if passwords are remembered, false otherwise
michael@0 83 */
michael@0 84
michael@0 85 /**
michael@0 86 * Enables/disables the Exceptions button used to configure sites where
michael@0 87 * passwords are never saved. When browser is set to start in Private
michael@0 88 * Browsing mode, the "Remember passwords" UI is useless, so we disable it.
michael@0 89 */
michael@0 90 readSavePasswords: function ()
michael@0 91 {
michael@0 92 var pref = document.getElementById("signon.rememberSignons");
michael@0 93 var excepts = document.getElementById("passwordExceptions");
michael@0 94
michael@0 95 if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
michael@0 96 document.getElementById("savePasswords").disabled = true;
michael@0 97 excepts.disabled = true;
michael@0 98 return false;
michael@0 99 } else {
michael@0 100 excepts.disabled = !pref.value;
michael@0 101 // don't override pref value in UI
michael@0 102 return undefined;
michael@0 103 }
michael@0 104 },
michael@0 105
michael@0 106 /**
michael@0 107 * Displays a dialog in which the user can view and modify the list of sites
michael@0 108 * where passwords are never saved.
michael@0 109 */
michael@0 110 showPasswordExceptions: function ()
michael@0 111 {
michael@0 112 openDialog("chrome://passwordmgr/content/passwordManagerExceptions.xul",
michael@0 113 "Toolkit:PasswordManagerExceptions",
michael@0 114 "modal=yes",
michael@0 115 null);
michael@0 116 },
michael@0 117
michael@0 118 /**
michael@0 119 * Initializes master password UI: the "use master password" checkbox, selects
michael@0 120 * the master password button to show, and enables/disables it as necessary.
michael@0 121 * The master password is controlled by various bits of NSS functionality, so
michael@0 122 * the UI for it can't be controlled by the normal preference bindings.
michael@0 123 */
michael@0 124 _initMasterPasswordUI: function ()
michael@0 125 {
michael@0 126 var noMP = !this._masterPasswordSet();
michael@0 127
michael@0 128 var button = document.getElementById("changeMasterPassword");
michael@0 129 button.disabled = noMP;
michael@0 130
michael@0 131 var checkbox = document.getElementById("useMasterPassword");
michael@0 132 checkbox.checked = !noMP;
michael@0 133 },
michael@0 134
michael@0 135 /**
michael@0 136 * Returns true if the user has a master password set and false otherwise.
michael@0 137 */
michael@0 138 _masterPasswordSet: function ()
michael@0 139 {
michael@0 140 var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
michael@0 141 getService(Ci.nsIPKCS11ModuleDB);
michael@0 142 var slot = secmodDB.findSlotByName("");
michael@0 143 if (slot) {
michael@0 144 var status = slot.status;
michael@0 145 var hasMP = status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED &&
michael@0 146 status != Ci.nsIPKCS11Slot.SLOT_READY;
michael@0 147 return hasMP;
michael@0 148 } else {
michael@0 149 // XXX I have no bloody idea what this means
michael@0 150 return false;
michael@0 151 }
michael@0 152 },
michael@0 153
michael@0 154 /**
michael@0 155 * Enables/disables the master password button depending on the state of the
michael@0 156 * "use master password" checkbox, and prompts for master password removal if
michael@0 157 * one is set.
michael@0 158 */
michael@0 159 updateMasterPasswordButton: function ()
michael@0 160 {
michael@0 161 var checkbox = document.getElementById("useMasterPassword");
michael@0 162 var button = document.getElementById("changeMasterPassword");
michael@0 163 button.disabled = !checkbox.checked;
michael@0 164
michael@0 165 // unchecking the checkbox should try to immediately remove the master
michael@0 166 // password, because it's impossible to non-destructively remove the master
michael@0 167 // password used to encrypt all the passwords without providing it (by
michael@0 168 // design), and it would be extremely odd to pop up that dialog when the
michael@0 169 // user closes the prefwindow and saves his settings
michael@0 170 if (!checkbox.checked)
michael@0 171 this._removeMasterPassword();
michael@0 172 else
michael@0 173 this.changeMasterPassword();
michael@0 174
michael@0 175 this._initMasterPasswordUI();
michael@0 176 },
michael@0 177
michael@0 178 /**
michael@0 179 * Displays the "remove master password" dialog to allow the user to remove
michael@0 180 * the current master password. When the dialog is dismissed, master password
michael@0 181 * UI is automatically updated.
michael@0 182 */
michael@0 183 _removeMasterPassword: function ()
michael@0 184 {
michael@0 185 var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
michael@0 186 getService(Ci.nsIPKCS11ModuleDB);
michael@0 187 if (secmodDB.isFIPSEnabled) {
michael@0 188 var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
michael@0 189 getService(Ci.nsIPromptService);
michael@0 190 var bundle = document.getElementById("bundlePreferences");
michael@0 191 promptService.alert(window,
michael@0 192 bundle.getString("pw_change_failed_title"),
michael@0 193 bundle.getString("pw_change2empty_in_fips_mode"));
michael@0 194 }
michael@0 195 else {
michael@0 196 openDialog("chrome://mozapps/content/preferences/removemp.xul",
michael@0 197 "Toolkit:RemoveMasterPassword", "modal=yes", null);
michael@0 198 }
michael@0 199 this._initMasterPasswordUI();
michael@0 200 },
michael@0 201
michael@0 202 /**
michael@0 203 * Displays a dialog in which the master password may be changed.
michael@0 204 */
michael@0 205 changeMasterPassword: function ()
michael@0 206 {
michael@0 207 openDialog("chrome://mozapps/content/preferences/changemp.xul",
michael@0 208 "Toolkit:ChangeMasterPassword", "modal=yes", null);
michael@0 209 this._initMasterPasswordUI();
michael@0 210 },
michael@0 211
michael@0 212 /**
michael@0 213 * Shows the sites where the user has saved passwords and the associated login
michael@0 214 * information.
michael@0 215 */
michael@0 216 showPasswords: function ()
michael@0 217 {
michael@0 218 openDialog("chrome://passwordmgr/content/passwordManager.xul",
michael@0 219 "Toolkit:PasswordManager",
michael@0 220 "modal=yes", null);
michael@0 221 }
michael@0 222
michael@0 223 };

mercurial