1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
12 * Initializes master password UI.
16 this._pane = document.getElementById("paneSecurity");
17 this._initMasterPasswordUI();
25 * xpinstall.whitelist.required
26 * - true if a site must be added to a site whitelist before extensions
27 * provided by the site may be installed from it, false if the extension
28 * may be directly installed after a confirmation dialog
32 * Enables/disables the add-ons Exceptions button depending on whether
33 * or not add-on installation warnings are displayed.
35 readWarnAddonInstall: function ()
37 var warn = document.getElementById("xpinstall.whitelist.required");
38 var exceptions = document.getElementById("addonExceptions");
40 exceptions.disabled = !warn.value;
42 // don't override the preference value
47 * Displays the exceptions lists for add-on installation warnings.
49 showAddonExceptions: function ()
51 var bundlePrefs = document.getElementById("bundlePreferences");
53 var params = this._addonParams;
54 if (!params.windowTitle || !params.introText) {
55 params.windowTitle = bundlePrefs.getString("addons_permissions_title");
56 params.introText = bundlePrefs.getString("addonspermissionstext");
59 document.documentElement.openWindow("Browser:Permissions",
60 "chrome://browser/content/preferences/permissions.xul",
65 * Parameters for the add-on install permissions dialog.
70 sessionVisible: false,
73 permissionType: "install"
81 * signon.rememberSignons
82 * - true if passwords are remembered, false otherwise
86 * Enables/disables the Exceptions button used to configure sites where
87 * passwords are never saved. When browser is set to start in Private
88 * Browsing mode, the "Remember passwords" UI is useless, so we disable it.
90 readSavePasswords: function ()
92 var pref = document.getElementById("signon.rememberSignons");
93 var excepts = document.getElementById("passwordExceptions");
95 if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
96 document.getElementById("savePasswords").disabled = true;
97 excepts.disabled = true;
100 excepts.disabled = !pref.value;
101 // don't override pref value in UI
107 * Displays a dialog in which the user can view and modify the list of sites
108 * where passwords are never saved.
110 showPasswordExceptions: function ()
112 document.documentElement.openWindow("Toolkit:PasswordManagerExceptions",
113 "chrome://passwordmgr/content/passwordManagerExceptions.xul",
118 * Initializes master password UI: the "use master password" checkbox, selects
119 * the master password button to show, and enables/disables it as necessary.
120 * The master password is controlled by various bits of NSS functionality, so
121 * the UI for it can't be controlled by the normal preference bindings.
123 _initMasterPasswordUI: function ()
125 var noMP = !this._masterPasswordSet();
127 var button = document.getElementById("changeMasterPassword");
128 button.disabled = noMP;
130 var checkbox = document.getElementById("useMasterPassword");
131 checkbox.checked = !noMP;
135 * Returns true if the user has a master password set and false otherwise.
137 _masterPasswordSet: function ()
139 const Cc = Components.classes, Ci = Components.interfaces;
140 var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
141 getService(Ci.nsIPKCS11ModuleDB);
142 var slot = secmodDB.findSlotByName("");
144 var status = slot.status;
145 var hasMP = status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED &&
146 status != Ci.nsIPKCS11Slot.SLOT_READY;
149 // XXX I have no bloody idea what this means
155 * Enables/disables the master password button depending on the state of the
156 * "use master password" checkbox, and prompts for master password removal if
159 updateMasterPasswordButton: function ()
161 var checkbox = document.getElementById("useMasterPassword");
162 var button = document.getElementById("changeMasterPassword");
163 button.disabled = !checkbox.checked;
165 // unchecking the checkbox should try to immediately remove the master
166 // password, because it's impossible to non-destructively remove the master
167 // password used to encrypt all the passwords without providing it (by
168 // design), and it would be extremely odd to pop up that dialog when the
169 // user closes the prefwindow and saves his settings
170 if (!checkbox.checked)
171 this._removeMasterPassword();
173 this.changeMasterPassword();
175 this._initMasterPasswordUI();
177 // We might want to hide sync's password engine.
178 gSyncPane.updateWeavePrefs();
182 * Displays the "remove master password" dialog to allow the user to remove
183 * the current master password. When the dialog is dismissed, master password
184 * UI is automatically updated.
186 _removeMasterPassword: function ()
188 const Cc = Components.classes, Ci = Components.interfaces;
189 var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
190 getService(Ci.nsIPKCS11ModuleDB);
191 if (secmodDB.isFIPSEnabled) {
192 var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
193 getService(Ci.nsIPromptService);
194 var bundle = document.getElementById("bundlePreferences");
195 promptService.alert(window,
196 bundle.getString("pw_change_failed_title"),
197 bundle.getString("pw_change2empty_in_fips_mode"));
200 document.documentElement.openSubDialog("chrome://mozapps/content/preferences/removemp.xul",
203 this._initMasterPasswordUI();
207 * Displays a dialog in which the master password may be changed.
209 changeMasterPassword: function ()
211 document.documentElement.openSubDialog("chrome://mozapps/content/preferences/changemp.xul",
213 this._initMasterPasswordUI();
217 * Shows the sites where the user has saved passwords and the associated login
220 showPasswords: function ()
222 document.documentElement.openWindow("Toolkit:PasswordManager",
223 "chrome://passwordmgr/content/passwordManager.xul",