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