!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 4; c-basic-offset: 2; -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is mozilla.org Code.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
initPanel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
39 function initPanel() {
40 var tag = document.getElementById("panelFrame").getAttribute("tag");
41 if (hWalletViewer) {
42 hWalletViewer.onpageload(tag)
43 } else {
44 window.queuedTag = tag;
45 window.queuedTagPending = true;
46 }
47 }
48
49 var hWalletViewer = null;
50 var walletViewerInterface = null;
51 var walletServiceInterface = null;
52 var bundle = null; // string bundle
53 var JS_STRINGS_FILE = "chrome://communicator/locale/wallet/WalletEditor.properties";
54 var schemaToValue = [];
55 var BREAK = "|";
56
onLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 function onLoad()
58 {
59 hWalletViewer = new nsWalletViewer('panelFrame');
60
61 if (!hWalletViewer)
62 throw "failed to create walletviewer";
63 else
64 hWalletViewer.init();
65 }
66
nsWalletViewer
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
67 function nsWalletViewer(frame_id)
68 {
69 if (!frame_id) {
70 throw "Error: frame_id not supplied!";
71 }
72 this.contentFrame = frame_id
73 this.cancelHandlers = [];
74 this.okHandlers = [];
75
76 // set up window
77 this.onload();
78 }
79
80 nsWalletViewer.prototype =
81 {
onload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
82 onload:
83 function() {
84 walletViewerInterface = Components.classes["@mozilla.org/walleteditor/walleteditor-world;1"].createInstance();
85 walletViewerInterface = walletViewerInterface.QueryInterface(Components.interfaces.nsIWalletEditor);
86
87 walletServiceInterface = Components.classes['@mozilla.org/wallet/wallet-service;1'];
88 walletServiceInterface = walletServiceInterface.getService();
89 walletServiceInterface = walletServiceInterface.QueryInterface(Components.interfaces.nsIWalletService);
90
91 bundle = srGetStrBundle(JS_STRINGS_FILE); /* initialize string bundle */
92
93 if (!EncryptionTest()) {
94 dump("*** user failed to unlock the database\n");
95 return;
96 }
97 if (!FetchInput()) {
98 dump("*** user failed to unlock the database\n");
99 return;
100 }
101
102 // allow l10n to hide certain panels
103 var pref = Components.classes["@mozilla.org/preferences-service;1"]
104 .getService(Components.interfaces.nsIPrefBranch);
105 var panel;
106 try {
107 if (pref.getBoolPref("wallet.namePanel.hide")) {
108 panel = document.getElementById("pnameID");
109 panel.setAttribute("hidden", "true");
110 panel = document.getElementById("snameID");
111 panel.setAttribute("hidden", "true");
112 panel = document.getElementById("bnameID");
113 panel.setAttribute("hidden", "true");
114 }
115 if (pref.getBoolPref("wallet.addressPanel.hide")) {
116 panel = document.getElementById("paddressID");
117 panel.setAttribute("hidden", "true");
118 panel = document.getElementById("saddressID");
119 panel.setAttribute("hidden", "true");
120 panel = document.getElementById("baddressID");
121 panel.setAttribute("hidden", "true");
122 }
123 if (pref.getBoolPref("wallet.phonePanel.hide")) {
124 panel = document.getElementById("pphoneID");
125 panel.setAttribute("hidden", "true");
126 panel = document.getElementById("sphoneID");
127 panel.setAttribute("hidden", "true");
128 panel = document.getElementById("bphoneID");
129 panel.setAttribute("hidden", "true");
130 }
131 if (pref.getBoolPref("wallet.creditPanel.hide")) {
132 panel = document.getElementById("pcreditID");
133 panel.setAttribute("hidden", "true");
134 }
135 if (pref.getBoolPref("wallet.employPanel.hide")) {
136 panel = document.getElementById("pemployID");
137 panel.setAttribute("hidden", "true");
138 }
139 if (pref.getBoolPref("wallet.miscPanel.hide")) {
140 panel = document.getElementById("pmiscID");
141 panel.setAttribute("hidden", "true");
142 }
143 } catch(e) {
144 // error -- stop hiding if prefs are missing
145 }
146 },
147
init
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
148 init:
149 function() {
150 if (window.queuedTagPending) {
151 this.onpageload(window.queuedTag);
152 }
153 this.closeBranches("pnameID");
154 },
155
onAccept
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
156 onAccept:
157 function() {
158 for(var i = 0; i < hWalletViewer.okHandlers.length; i++) {
159 hWalletViewer.okHandlers[i]();
160 }
161
162 var tag = document.getElementById(hWalletViewer.contentFrame).getAttribute("tag");
163 hWalletViewer.savePageData(tag);
164 hWalletViewer.saveAllData();
165
166 return true;
167 },
168
onCancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
169 onCancel:
170 function() {
171 for(var i = 0; i < hWalletViewer.cancelHandlers.length; i++) {
172 hWalletViewer.cancelHandlers[i]();
173 }
174
175 return true;
176 },
177
registerOKCallbackFunc
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
178 registerOKCallbackFunc:
179 function(aFunctionReference) {
180 this.okHandlers[this.okHandlers.length] = aFunctionReference;
181 },
182
registerCancelCallbackFunc
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
183 registerCancelCallbackFunc:
184 function(aFunctionReference) {
185 this.cancelHandlers[this.cancelHandlers.length] = aFunctionReference;
186 },
187
saveAllData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
188 saveAllData:
189 function() {
190 ReturnOutput();
191 },
192
savePageData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
193 savePageData:
194 function(tag) {
195 /* collect the list of menuItem labels */
196 var elementIDs;
197 var contentFrame = window.frames[this.contentFrame];
198 if ("_elementIDs" in contentFrame) { // make sure page finished loading
199 elementIDs = contentFrame._elementIDs;
200 }
201 for(var i = 0; i < elementIDs.length; i++) {
202 var values = "";
203 var menuList = contentFrame.document.getElementById(elementIDs[i]);
204 if (menuList.parentNode.getAttribute("hidden") == "true") {
205 continue; /* needed for concatenations only */
206 }
207 Append(menuList); /* in case current editing has not been stored away */
208 var menuPopup = menuList.firstChild;
209
210 /* visit each menuItem */
211 for (var menuItem = menuPopup.firstChild;
212 menuItem != menuPopup.lastChild; /* skip empty item at end of list */
213 menuItem = menuItem.nextSibling) {
214 values += (menuItem.getAttribute("label") + BREAK);
215 }
216 schemaToValue[tag+elementIDs[i]] = values;
217 }
218 },
219
switchPage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
220 switchPage:
221 function() {
222 var PanelTree = document.getElementById("panelTree");
223 if (PanelTree.view.selection.count == 0) return;
224 var selectedItem = PanelTree.contentView.getItemAtIndex(PanelTree.currentIndex);
225
226 var oldURL = document.getElementById(this.contentFrame).getAttribute("src");
227 var oldTag = document.getElementById(this.contentFrame).getAttribute("tag");
228
229 this.savePageData(oldTag); // save data from the current page.
230
231 var newURL = selectedItem.firstChild.firstChild.getAttribute("url");
232 var newTag = selectedItem.firstChild.firstChild.getAttribute("tag");
233 if (newURL != oldURL || newTag != oldTag) {
234 document.getElementById(this.contentFrame).setAttribute("src", newURL);
235 document.getElementById(this.contentFrame).setAttribute("tag", newTag);
236 }
237 },
238
onpageload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
239 onpageload:
240 function(aPageTag) {
241 if ('Startup' in window.frames[ this.contentFrame ]) {
242 window.frames[ this.contentFrame ].Startup(schemaToValue);
243 }
244
245 /* restore the list of menuItem labels */
246 var elementIDs = window.frames[this.contentFrame]._elementIDs;
247 for(var i = 0; i < elementIDs.length; i++) {
248 var menuList = window.frames[this.contentFrame].document.getElementById(elementIDs[i]);
249 if (!menuList) {
250 dump("*** FIX ME: '_elementIDs' in '" + aPageTag +
251 "' contains a reference to a non-existent element ID '" +
252 elementIDs[i] + "'.\n");
253 return;
254 }
255 var menuPopup = menuList.firstChild;
256 if ((aPageTag+elementIDs[i]) in schemaToValue) {
257
258 /* following unhiding is needed for concatenations only */
259 var row = menuList.parentNode;
260 var rows = row.parentNode;
261 var grid = rows.parentNode;
262 var groupBox = grid.parentNode;
263 groupBox.setAttribute("hidden", "false");
264 row.setAttribute("hidden", "false");
265
266 var strings = schemaToValue[aPageTag+elementIDs[i]].split(BREAK);
267 for (var j = 0; j<strings.length-1; j++) {
268 var menuItem = window.frames[this.contentFrame].document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
269 if (menuItem) {
270 menuItem.setAttribute("label", strings[j]);
271 menuItem.setAttribute("len", strings[j].length);
272 menuPopup.insertBefore(menuItem, menuPopup.lastChild);
273 }
274 }
275 };
276 menuList.selectedItem = menuPopup.firstChild; // ????? is this temporary ?????
277 }
278 },
279
closeBranches
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
280 closeBranches:
281 function(aComponentName) {
282 var panelChildren = document.getElementById("panelChildren");
283 var panelTree = document.getElementById("panelTree");
284 for(var i = 0; i < panelChildren.childNodes.length; i++) {
285 var currentItem = panelChildren.childNodes[i];
286 if (currentItem.id != aComponentName && currentItem.id != "primary") {
287 currentItem.removeAttribute("open");
288 }
289 }
290 var openItem = document.getElementById(aComponentName);
291 var index = panelTree.contentView.getIndexOfItem(openItem);
292 panelTree.view.selection.select(index);
293 }
294
295 };
296
Append
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
297 function Append(thisMenuList) {
298
299 /* Note: we always want a zero-length textbox so the user
300 * can start typing in a new value. So we need to determine
301 * if user has started typing into the zero-length textbox
302 * in which case it's time to create yet another zero-length
303 * one. We also need to determine if user has removed all
304 * text in a textbox in which case that textbox needs to
305 * be removed
306 */
307
308 /* transfer value from menu list to the selected menu item */
309 var thisMenuItem = thisMenuList.selectedItem;
310 if (!thisMenuItem) {
311 return;
312 }
313 thisMenuItem.setAttribute('label', thisMenuList.value);
314
315 /* determine previous size of textbox */
316 var len = Number(thisMenuItem.getAttribute("len"));
317
318 /* update previous size */
319 var newLen = thisMenuItem.getAttribute("label").length;
320 thisMenuItem.setAttribute("len", newLen);
321
322 /* obtain parent element */
323 var thisMenuPopup = thisMenuItem.parentNode;
324 if (!thisMenuPopup) {
325 return;
326 }
327
328 /* determine if it's time to remove menuItem */
329 if (newLen == 0) {
330 /* no characters left in text field */
331 if (len) {
332 /* previously there were some characters, time to remove */
333 thisMenuPopup.parentNode.selectedItem = thisMenuPopup.lastChild;
334 thisMenuPopup.removeChild(thisMenuItem);
335 }
336 return;
337 }
338
339 /* currently modified entry is not null so put it at head of list */
340 if (thisMenuPopup.childNodes.length > 1) {
341 thisMenuPopup.removeChild(thisMenuItem);
342 thisMenuPopup.insertBefore(thisMenuItem, thisMenuPopup.firstChild);
343 }
344
345 /* determine if it's time to add menuItem */
346 if (len) {
347 /* previously there were some characters and there still are so it's not time to add */
348 return;
349 }
350
351 /* add menu item */
352 var menuItem = thisMenuPopup.ownerDocument.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
353 if (!menuItem) {
354 return;
355 }
356 menuItem.setAttribute("label", "");
357 menuItem.setAttribute("len", "0");
358 thisMenuPopup.appendChild(menuItem);
359
360 return;
361 }
362
363 /* return the wallet output data */
ReturnOutput
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
364 function ReturnOutput() {
365 var schema;
366 var output = "OK" + BREAK;
367 var value;
368 for (schema in schemaToValue) {
369 if (schemaToValue[schema] != "") {
370 value = schemaToValue[schema].split(BREAK);
371 for (var i=0; i<value.length-1; i++) { /* skip empty value at end */
372 output += (schema + BREAK + Encrypt(value[i]) + BREAK + BREAK);
373 }
374 }
375 }
376 walletViewerInterface.SetValue(output, window);
377 }
378
379 /* clear all data */
ClearAll
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
380 function ClearAll() {
381
382 // clear out all values from database
383 schemaToValue = [];
384
385 // clear out values on current page
386 var elementIDs = window.frames[hWalletViewer.contentFrame]._elementIDs;
387 for(var i = 0; i < elementIDs.length; i++) {
388 var menuList = window.frames[hWalletViewer.contentFrame].document.getElementById(elementIDs[i]);
389 var menuPopup = menuList.firstChild;
390
391 // remove all menuItems except for last one
392 while (menuPopup.childNodes.length > 1) {
393 menuPopup.removeChild(menuPopup.firstChild);
394 }
395 menuList.removeAttribute("label");
396 menuList.selectedItem = menuPopup.firstChild;
397 }
398 }
399
400 /* get the wallet input data */
FetchInput
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
401 function FetchInput() {
402 /* get wallet data into a list */
403 var list = walletViewerInterface.GetValue();
404
405 /* format of this list is as follows:
406 *
407 * BREAK-CHARACTER
408 * schema-name BREAK-CHARACTER
409 * value BREAK-CHARACTER
410 * synonymous-value-1 BREAK-CHARACTER
411 * ...
412 * synonymous-value-n BREAK-CHARACTER
413 *
414 * and repeat above pattern for each schema name. Note that if there are more than
415 * one distinct values for a particular schema name, the above pattern is repeated
416 * for each such distinct value
417 */
418
419 /* check for database being unlocked */
420 if (list.length == 0) {
421 /* user supplied invalid database key */
422 window.close(); // ?????
423 return false;
424 }
425
426 /* parse the list into the schemas and their corresponding values */
427 BREAK = list[0];
428 var strings = list.split(BREAK);
429 var stringsLength = strings.length;
430 var schema, value;
431 for (var i=1; i<stringsLength; i++) {
432 if (strings[i] != "" && strings[i-1] == "") {
433 schema = strings[i++];
434 value = Decrypt(strings[i]);
435 if (!(schema in schemaToValue)) {
436 schemaToValue[schema] = [];
437 }
438 schemaToValue[schema] += (value + BREAK);
439 }
440 }
441
442 return true;
443 }
444
445 /* decrypt a value */
Decrypt
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
446 function Decrypt(crypt) {
447 try {
448 return walletServiceInterface.WALLET_Decrypt(crypt);
449 } catch (ex) {
450 return bundle.GetStringFromName("EncryptionFailure");
451 }
452 }
453
454 /* encrypt a value */
Encrypt
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
455 function Encrypt(text) {
456 try {
457 return walletServiceInterface.WALLET_Encrypt(text);
458 } catch (ex) {
459 alert(bundle.GetStringFromName("UnableToUnlockDatabase"));
460 return "";
461 }
462 }
463
464 /* see if user was able to unlock the database */
EncryptionTest
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
465 function EncryptionTest() {
466 try {
467 walletServiceInterface.WALLET_Encrypt("dummy");
468 } catch (ex) {
469 alert(bundle.GetStringFromName("UnableToUnlockDatabase"));
470 window.close(); // ?????
471 return false;
472 }
473 return true;
474 }
475
476 // called by the help button overlaid from platformDialogOverlay
doHelpButton
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
477 function doHelpButton() {
478 openHelp("forms_data");
479 }