!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 43 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/passwordmgr/content/passwordManager.js"
2
3 /*** =================== SAVED SIGNONS CODE =================== ***/
4
5 var kSignonBundle;
6
SignonsStartup
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
7 function SignonsStartup() {
8 kSignonBundle = document.getElementById("signonBundle");
9 document.getElementById("togglePasswords").label = kSignonBundle.getString("showPasswords");
10 document.getElementById("togglePasswords").accessKey = kSignonBundle.getString("showPasswordsAccessKey");
11 document.getElementById("signonsIntro").value = kSignonBundle.getString("loginsSpielAll");
12 LoadSignons();
13
14 // filter the table if requested by caller
15 if (window.arguments && window.arguments[0] &&
16 window.arguments[0].filterString)
17 setFilter(window.arguments[0].filterString);
18
19 FocusFilterBox();
20 }
21
22 var signonsTreeView = {
23 _filterSet : [],
24 _lastSelectedRanges : [],
25 selection: null,
26
27 rowCount : 0,
setTree
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
28 setTree : function(tree) {},
getImageSrc
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
29 getImageSrc : function(row,column) {},
getProgressMode
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
30 getProgressMode : function(row,column) {},
getCellValue
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
31 getCellValue : function(row,column) {},
getCellText
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
32 getCellText : function(row,column) {
33 var signon = this._filterSet.length ? this._filterSet[row] : signons[row];
34 switch (column.id) {
35 case "siteCol":
36 return signon.httpRealm ?
37 (signon.hostname + " (" + signon.httpRealm + ")"):
38 signon.hostname;
39 case "userCol":
40 return signon.username || "";
41 case "passwordCol":
42 return signon.password || "";
43 default:
44 return "";
45 }
46 },
isSeparator
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
47 isSeparator : function(index) { return false; },
isSorted
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
48 isSorted : function() { return false; },
isContainer
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
49 isContainer : function(index) { return false; },
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
50 cycleHeader : function(column) {},
getRowProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
51 getRowProperties : function(row,prop) {},
getColumnProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
52 getColumnProperties : function(column,prop) {},
getCellProperties
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
53 getCellProperties : function(row,column,prop) {}
54 };
55
56
LoadSignons
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 function LoadSignons() {
58 // loads signons into table
59 signons = passwordmanager.getAllLogins({});
60 signonsTreeView.rowCount = signons.length;
61
62 // sort and display the table
63 signonsTree.treeBoxObject.view = signonsTreeView;
64 SignonColumnSort('hostname');
65
66 // disable "remove all signons" button if there are no signons
67 var element = document.getElementById("removeAllSignons");
68 var toggle = document.getElementById("togglePasswords");
69 if (signons.length == 0 || gSelectUserInUse) {
70 element.setAttribute("disabled","true");
71 toggle.setAttribute("disabled","true");
72 } else {
73 element.removeAttribute("disabled");
74 toggle.removeAttribute("disabled");
75 }
76
77 return true;
78 }
79
SignonSelected
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
80 function SignonSelected() {
81 var selections = GetTreeSelections(signonsTree);
82 if (selections.length && !gSelectUserInUse) {
83 document.getElementById("removeSignon").removeAttribute("disabled");
84 }
85 }
86
DeleteSignon
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
87 function DeleteSignon() {
88 var syncNeeded = (signonsTreeView._filterSet.length != 0);
89 DeleteSelectedItemFromTree(signonsTree, signonsTreeView,
90 signonsTreeView._filterSet.length ? signonsTreeView._filterSet : signons,
91 deletedSignons, "removeSignon", "removeAllSignons");
92 FinalizeSignonDeletions(syncNeeded);
93 }
94
DeleteAllSignons
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
95 function DeleteAllSignons() {
96 var prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
97 .getService(Components.interfaces.nsIPromptService);
98
99 // Confirm the user wants to remove all passwords
100 var dummy = { value: false };
101 if (prompter.confirmEx(window,
102 kSignonBundle.getString("removeAllPasswordsTitle"),
103 kSignonBundle.getString("removeAllPasswordsPrompt"),
104 prompter.STD_YES_NO_BUTTONS + prompter.BUTTON_POS_1_DEFAULT,
105 null, null, null, null, dummy) == 1) // 1 == "No" button
106 return;
107
108 var syncNeeded = (signonsTreeView._filterSet.length != 0);
109 DeleteAllFromTree(signonsTree, signonsTreeView,
110 signonsTreeView._filterSet.length ? signonsTreeView._filterSet : signons,
111 deletedSignons, "removeSignon", "removeAllSignons");
112 FinalizeSignonDeletions(syncNeeded);
113 }
114
TogglePasswordVisible
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
115 function TogglePasswordVisible() {
116 if (!showingPasswords && !ConfirmShowPasswords())
117 return;
118
119 showingPasswords = !showingPasswords;
120 document.getElementById("togglePasswords").label = kSignonBundle.getString(showingPasswords ? "hidePasswords" : "showPasswords");
121 document.getElementById("togglePasswords").accessKey = kSignonBundle.getString(showingPasswords ? "hidePasswordsAccessKey" : "showPasswordsAccessKey");
122 document.getElementById("passwordCol").hidden = !showingPasswords;
123 _filterPasswords();
124 }
125
AskUserShowPasswords
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
126 function AskUserShowPasswords() {
127 var prompter = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
128 var dummy = { value: false };
129
130 // Confirm the user wants to display passwords
131 return prompter.confirmEx(window,
132 null,
133 kSignonBundle.getString("noMasterPasswordPrompt"), prompter.STD_YES_NO_BUTTONS,
134 null, null, null, null, dummy) == 0; // 0=="Yes" button
135 }
136
ConfirmShowPasswords
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
137 function ConfirmShowPasswords() {
138 // This doesn't harm if passwords are not encrypted
139 var tokendb = Components.classes["@mozilla.org/security/pk11tokendb;1"]
140 .createInstance(Components.interfaces.nsIPK11TokenDB);
141 var token = tokendb.getInternalKeyToken();
142
143 // If there is no master password, still give the user a chance to opt-out of displaying passwords
144 if (token.checkPassword(""))
145 return AskUserShowPasswords();
146
147 // So there's a master password. But since checkPassword didn't succeed, we're logged out (per nsIPK11Token.idl).
148 try {
149 // Relogin and ask for the master password.
150 token.login(true); // 'true' means always prompt for token password. User will be prompted until
151 // clicking 'Cancel' or entering the correct password.
152 } catch (e) {
153 // An exception will be thrown if the user cancels the login prompt dialog.
154 // User is also logged out of Software Security Device.
155 }
156
157 return token.isLoggedIn();
158 }
159
FinalizeSignonDeletions
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
160 function FinalizeSignonDeletions(syncNeeded) {
161 for (var s=0; s<deletedSignons.length; s++) {
162 passwordmanager.removeLogin(deletedSignons[s]);
163 }
164 // If the deletion has been performed in a filtered view, reflect the deletion in the unfiltered table.
165 // See bug 405389.
166 if (syncNeeded)
167 signons = passwordmanager.getAllLogins({});
168 deletedSignons.length = 0;
169 }
170
HandleSignonKeyPress
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
171 function HandleSignonKeyPress(e) {
172 if (e.keyCode == 46) {
173 DeleteSignon();
174 }
175 }
176
177 var lastSignonSortColumn = "";
178 var lastSignonSortAscending = false;
179
SignonColumnSort
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
180 function SignonColumnSort(column) {
181 lastSignonSortAscending =
182 SortTree(signonsTree, signonsTreeView,
183 signonsTreeView._filterSet.length ? signonsTreeView._filterSet : signons,
184 column, lastSignonSortColumn, lastSignonSortAscending);
185 lastSignonSortColumn = column;
186 }
187
SignonClearFilter
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
188 function SignonClearFilter() {
189 var singleSelection = (signonsTreeView.selection.count == 1);
190
191 // Clear the Filter and the Tree Display
192 document.getElementById("filter").value = "";
193 signonsTreeView.rowCount = 0;
194 signonsTree.treeBoxObject.rowCountChanged(0, -signonsTreeView._filterSet.length);
195 signonsTreeView._filterSet = [];
196
197 // Just reload the list to make sure deletions are respected
198 lastSignonSortColumn = "";
199 lastSignonSortAscending = false;
200 LoadSignons();
201
202 // Restore selection
203 if (singleSelection) {
204 signonsTreeView.selection.clearSelection();
205 for (i = 0; i < signonsTreeView._lastSelectedRanges.length; ++i) {
206 var range = signonsTreeView._lastSelectedRanges[i];
207 signonsTreeView.selection.rangedSelect(range.min, range.max, true);
208 }
209 } else {
210 signonsTreeView.selection.select(0);
211 }
212 signonsTreeView._lastSelectedRanges = [];
213
214 document.getElementById("signonsIntro").value = kSignonBundle.getString("loginsSpielAll");
215 document.getElementById("clearFilter").disabled = true;
216 FocusFilterBox();
217 }
218
FocusFilterBox
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
219 function FocusFilterBox()
220 {
221 if (document.getElementById("filter").getAttribute("focused") != "true")
222 document.getElementById("filter").focus();
223 }
224
SignonMatchesFilter
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
225 function SignonMatchesFilter(aSignon, aFilterValue) {
226 if (aSignon.hostname.toLowerCase().indexOf(aFilterValue) != -1)
227 return true;
228 if (aSignon.username &&
229 aSignon.username.toLowerCase().indexOf(aFilterValue) != -1)
230 return true;
231 if (aSignon.httpRealm &&
232 aSignon.httpRealm.toLowerCase().indexOf(aFilterValue) != -1)
233 return true;
234 if (showingPasswords && aSignon.password &&
235 aSignon.password.toLowerCase().indexOf(aFilterValue) != -1)
236 return true;
237
238 return false;
239 }
240
FilterPasswords
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
241 function FilterPasswords(aFilterValue, view) {
242 aFilterValue = aFilterValue.toLowerCase();
anon:243:24
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
243 return signons.filter(function (s) SignonMatchesFilter(s, aFilterValue));
244 }
245
SignonSaveState
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
246 function SignonSaveState() {
247 // Save selection
248 var seln = signonsTreeView.selection;
249 signonsTreeView._lastSelectedRanges = [];
250 var rangeCount = seln.getRangeCount();
251 for (var i = 0; i < rangeCount; ++i) {
252 var min = {}; var max = {};
253 seln.getRangeAt(i, min, max);
254 signonsTreeView._lastSelectedRanges.push({ min: min.value, max: max.value });
255 }
256 }
257
_filterPasswords
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
258 function _filterPasswords()
259 {
260 var filter = document.getElementById("filter").value;
261 if (filter == "") {
262 SignonClearFilter();
263 return;
264 }
265
266 var newFilterSet = FilterPasswords(filter, signonsTreeView);
267 if (!signonsTreeView._filterSet.length) {
268 // Save Display Info for the Non-Filtered mode when we first
269 // enter Filtered mode.
270 SignonSaveState();
271 }
272 signonsTreeView._filterSet = newFilterSet;
273
274 // Clear the display
275 signonsTree.treeBoxObject.rowCountChanged(0, -signonsTreeView.rowCount);
276 // Set up the filtered display
277 signonsTreeView.rowCount = signonsTreeView._filterSet.length;
278 signonsTree.treeBoxObject.rowCountChanged(0, signonsTreeView.rowCount);
279
280 // if the view is not empty then select the first item
281 if (signonsTreeView.rowCount > 0)
282 signonsTreeView.selection.select(0);
283
284 document.getElementById("signonsIntro").value = kSignonBundle.getString("loginsSpielFiltered");
285 document.getElementById("clearFilter").disabled = false;
286 }
287
HandleSignonFilterKeyPress
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
288 function HandleSignonFilterKeyPress(aEvent) {
289 if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE &&
290 document.getElementById("filter").value != "")
291 SignonClearFilter();
292 }
293
setFilter
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
294 function setFilter(aFilterString) {
295 if (document.getElementById("filter").value != "")
296 SignonClearFilter();
297 document.getElementById("filter").value = aFilterString;
298 _filterPasswords();
299 }