|
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/. */ |
|
5 |
|
6 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); |
|
7 |
|
8 var gSecurityPane = { |
|
9 _pane: null, |
|
10 |
|
11 /** |
|
12 * Initializes master password UI. |
|
13 */ |
|
14 init: function () |
|
15 { |
|
16 this._pane = document.getElementById("paneSecurity"); |
|
17 this._initMasterPasswordUI(); |
|
18 }, |
|
19 |
|
20 // ADD-ONS |
|
21 |
|
22 /* |
|
23 * Preferences: |
|
24 * |
|
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 |
|
29 */ |
|
30 |
|
31 /** |
|
32 * Enables/disables the add-ons Exceptions button depending on whether |
|
33 * or not add-on installation warnings are displayed. |
|
34 */ |
|
35 readWarnAddonInstall: function () |
|
36 { |
|
37 var warn = document.getElementById("xpinstall.whitelist.required"); |
|
38 var exceptions = document.getElementById("addonExceptions"); |
|
39 |
|
40 exceptions.disabled = !warn.value; |
|
41 |
|
42 // don't override the preference value |
|
43 return undefined; |
|
44 }, |
|
45 |
|
46 /** |
|
47 * Displays the exceptions lists for add-on installation warnings. |
|
48 */ |
|
49 showAddonExceptions: function () |
|
50 { |
|
51 var bundlePrefs = document.getElementById("bundlePreferences"); |
|
52 |
|
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"); |
|
57 } |
|
58 |
|
59 document.documentElement.openWindow("Browser:Permissions", |
|
60 "chrome://browser/content/preferences/permissions.xul", |
|
61 "", params); |
|
62 }, |
|
63 |
|
64 /** |
|
65 * Parameters for the add-on install permissions dialog. |
|
66 */ |
|
67 _addonParams: |
|
68 { |
|
69 blockVisible: false, |
|
70 sessionVisible: false, |
|
71 allowVisible: true, |
|
72 prefilledHost: "", |
|
73 permissionType: "install" |
|
74 }, |
|
75 |
|
76 // PASSWORDS |
|
77 |
|
78 /* |
|
79 * Preferences: |
|
80 * |
|
81 * signon.rememberSignons |
|
82 * - true if passwords are remembered, false otherwise |
|
83 */ |
|
84 |
|
85 /** |
|
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. |
|
89 */ |
|
90 readSavePasswords: function () |
|
91 { |
|
92 var pref = document.getElementById("signon.rememberSignons"); |
|
93 var excepts = document.getElementById("passwordExceptions"); |
|
94 |
|
95 if (PrivateBrowsingUtils.permanentPrivateBrowsing) { |
|
96 document.getElementById("savePasswords").disabled = true; |
|
97 excepts.disabled = true; |
|
98 return false; |
|
99 } else { |
|
100 excepts.disabled = !pref.value; |
|
101 // don't override pref value in UI |
|
102 return undefined; |
|
103 } |
|
104 }, |
|
105 |
|
106 /** |
|
107 * Displays a dialog in which the user can view and modify the list of sites |
|
108 * where passwords are never saved. |
|
109 */ |
|
110 showPasswordExceptions: function () |
|
111 { |
|
112 document.documentElement.openWindow("Toolkit:PasswordManagerExceptions", |
|
113 "chrome://passwordmgr/content/passwordManagerExceptions.xul", |
|
114 "", null); |
|
115 }, |
|
116 |
|
117 /** |
|
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. |
|
122 */ |
|
123 _initMasterPasswordUI: function () |
|
124 { |
|
125 var noMP = !this._masterPasswordSet(); |
|
126 |
|
127 var button = document.getElementById("changeMasterPassword"); |
|
128 button.disabled = noMP; |
|
129 |
|
130 var checkbox = document.getElementById("useMasterPassword"); |
|
131 checkbox.checked = !noMP; |
|
132 }, |
|
133 |
|
134 /** |
|
135 * Returns true if the user has a master password set and false otherwise. |
|
136 */ |
|
137 _masterPasswordSet: function () |
|
138 { |
|
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(""); |
|
143 if (slot) { |
|
144 var status = slot.status; |
|
145 var hasMP = status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED && |
|
146 status != Ci.nsIPKCS11Slot.SLOT_READY; |
|
147 return hasMP; |
|
148 } else { |
|
149 // XXX I have no bloody idea what this means |
|
150 return false; |
|
151 } |
|
152 }, |
|
153 |
|
154 /** |
|
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 |
|
157 * one is set. |
|
158 */ |
|
159 updateMasterPasswordButton: function () |
|
160 { |
|
161 var checkbox = document.getElementById("useMasterPassword"); |
|
162 var button = document.getElementById("changeMasterPassword"); |
|
163 button.disabled = !checkbox.checked; |
|
164 |
|
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(); |
|
172 else |
|
173 this.changeMasterPassword(); |
|
174 |
|
175 this._initMasterPasswordUI(); |
|
176 |
|
177 // We might want to hide sync's password engine. |
|
178 gSyncPane.updateWeavePrefs(); |
|
179 }, |
|
180 |
|
181 /** |
|
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. |
|
185 */ |
|
186 _removeMasterPassword: function () |
|
187 { |
|
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")); |
|
198 } |
|
199 else { |
|
200 document.documentElement.openSubDialog("chrome://mozapps/content/preferences/removemp.xul", |
|
201 "", null); |
|
202 } |
|
203 this._initMasterPasswordUI(); |
|
204 }, |
|
205 |
|
206 /** |
|
207 * Displays a dialog in which the master password may be changed. |
|
208 */ |
|
209 changeMasterPassword: function () |
|
210 { |
|
211 document.documentElement.openSubDialog("chrome://mozapps/content/preferences/changemp.xul", |
|
212 "", null); |
|
213 this._initMasterPasswordUI(); |
|
214 }, |
|
215 |
|
216 /** |
|
217 * Shows the sites where the user has saved passwords and the associated login |
|
218 * information. |
|
219 */ |
|
220 showPasswords: function () |
|
221 { |
|
222 document.documentElement.openWindow("Toolkit:PasswordManager", |
|
223 "chrome://passwordmgr/content/passwordManager.xul", |
|
224 "", null); |
|
225 } |
|
226 |
|
227 }; |