browser/components/preferences/security.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 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
michael@0 7
michael@0 8 var gSecurityPane = {
michael@0 9 _pane: null,
michael@0 10
michael@0 11 /**
michael@0 12 * Initializes master password UI.
michael@0 13 */
michael@0 14 init: function ()
michael@0 15 {
michael@0 16 this._pane = document.getElementById("paneSecurity");
michael@0 17 this._initMasterPasswordUI();
michael@0 18 },
michael@0 19
michael@0 20 // ADD-ONS
michael@0 21
michael@0 22 /*
michael@0 23 * Preferences:
michael@0 24 *
michael@0 25 * xpinstall.whitelist.required
michael@0 26 * - true if a site must be added to a site whitelist before extensions
michael@0 27 * provided by the site may be installed from it, false if the extension
michael@0 28 * may be directly installed after a confirmation dialog
michael@0 29 */
michael@0 30
michael@0 31 /**
michael@0 32 * Enables/disables the add-ons Exceptions button depending on whether
michael@0 33 * or not add-on installation warnings are displayed.
michael@0 34 */
michael@0 35 readWarnAddonInstall: function ()
michael@0 36 {
michael@0 37 var warn = document.getElementById("xpinstall.whitelist.required");
michael@0 38 var exceptions = document.getElementById("addonExceptions");
michael@0 39
michael@0 40 exceptions.disabled = !warn.value;
michael@0 41
michael@0 42 // don't override the preference value
michael@0 43 return undefined;
michael@0 44 },
michael@0 45
michael@0 46 /**
michael@0 47 * Displays the exceptions lists for add-on installation warnings.
michael@0 48 */
michael@0 49 showAddonExceptions: function ()
michael@0 50 {
michael@0 51 var bundlePrefs = document.getElementById("bundlePreferences");
michael@0 52
michael@0 53 var params = this._addonParams;
michael@0 54 if (!params.windowTitle || !params.introText) {
michael@0 55 params.windowTitle = bundlePrefs.getString("addons_permissions_title");
michael@0 56 params.introText = bundlePrefs.getString("addonspermissionstext");
michael@0 57 }
michael@0 58
michael@0 59 document.documentElement.openWindow("Browser:Permissions",
michael@0 60 "chrome://browser/content/preferences/permissions.xul",
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 document.documentElement.openWindow("Toolkit:PasswordManagerExceptions",
michael@0 113 "chrome://passwordmgr/content/passwordManagerExceptions.xul",
michael@0 114 "", null);
michael@0 115 },
michael@0 116
michael@0 117 /**
michael@0 118 * Initializes master password UI: the "use master password" checkbox, selects
michael@0 119 * the master password button to show, and enables/disables it as necessary.
michael@0 120 * The master password is controlled by various bits of NSS functionality, so
michael@0 121 * the UI for it can't be controlled by the normal preference bindings.
michael@0 122 */
michael@0 123 _initMasterPasswordUI: function ()
michael@0 124 {
michael@0 125 var noMP = !this._masterPasswordSet();
michael@0 126
michael@0 127 var button = document.getElementById("changeMasterPassword");
michael@0 128 button.disabled = noMP;
michael@0 129
michael@0 130 var checkbox = document.getElementById("useMasterPassword");
michael@0 131 checkbox.checked = !noMP;
michael@0 132 },
michael@0 133
michael@0 134 /**
michael@0 135 * Returns true if the user has a master password set and false otherwise.
michael@0 136 */
michael@0 137 _masterPasswordSet: function ()
michael@0 138 {
michael@0 139 const Cc = Components.classes, Ci = Components.interfaces;
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 // We might want to hide sync's password engine.
michael@0 178 gSyncPane.updateWeavePrefs();
michael@0 179 },
michael@0 180
michael@0 181 /**
michael@0 182 * Displays the "remove master password" dialog to allow the user to remove
michael@0 183 * the current master password. When the dialog is dismissed, master password
michael@0 184 * UI is automatically updated.
michael@0 185 */
michael@0 186 _removeMasterPassword: function ()
michael@0 187 {
michael@0 188 const Cc = Components.classes, Ci = Components.interfaces;
michael@0 189 var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
michael@0 190 getService(Ci.nsIPKCS11ModuleDB);
michael@0 191 if (secmodDB.isFIPSEnabled) {
michael@0 192 var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
michael@0 193 getService(Ci.nsIPromptService);
michael@0 194 var bundle = document.getElementById("bundlePreferences");
michael@0 195 promptService.alert(window,
michael@0 196 bundle.getString("pw_change_failed_title"),
michael@0 197 bundle.getString("pw_change2empty_in_fips_mode"));
michael@0 198 }
michael@0 199 else {
michael@0 200 document.documentElement.openSubDialog("chrome://mozapps/content/preferences/removemp.xul",
michael@0 201 "", null);
michael@0 202 }
michael@0 203 this._initMasterPasswordUI();
michael@0 204 },
michael@0 205
michael@0 206 /**
michael@0 207 * Displays a dialog in which the master password may be changed.
michael@0 208 */
michael@0 209 changeMasterPassword: function ()
michael@0 210 {
michael@0 211 document.documentElement.openSubDialog("chrome://mozapps/content/preferences/changemp.xul",
michael@0 212 "", null);
michael@0 213 this._initMasterPasswordUI();
michael@0 214 },
michael@0 215
michael@0 216 /**
michael@0 217 * Shows the sites where the user has saved passwords and the associated login
michael@0 218 * information.
michael@0 219 */
michael@0 220 showPasswords: function ()
michael@0 221 {
michael@0 222 document.documentElement.openWindow("Toolkit:PasswordManager",
michael@0 223 "chrome://passwordmgr/content/passwordManager.xul",
michael@0 224 "", null);
michael@0 225 }
michael@0 226
michael@0 227 };

mercurial