Mercurial > my-ubiquity-commands
comparison secure-data-storage/secure-data-storage.js @ 17:f3e03596fcf9
Added secure data storage command feed.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 08 Apr 2009 10:52:31 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:426e9c04c6f9 | 17:f3e03596fcf9 |
---|---|
1 Components.utils.import("resource://ubiquity/modules/ubiquity_protocol.js"); | |
2 | |
3 var loginManager = Cc["@mozilla.org/login-manager;1"] | |
4 .getService(Ci.nsILoginManager); | |
5 var path = 'secure-data-storage'; | |
6 var hostname = 'ubiquity://' + path; | |
7 var realm = 'Secure Data Storage'; | |
8 var formSubmitURL = null; | |
9 var username = ''; | |
10 var usernameField = ""; | |
11 var passwordField = ""; | |
12 | |
13 setPath(path, | |
14 ("data:text/html," + | |
15 "<html><head><title>Your Secure Data</title></head>" + | |
16 "<body></body></html>")); | |
17 | |
18 function pageLoad_path(doc) { | |
19 if (doc.location.href == hostname) { | |
20 var pass = getPass(); | |
21 if (!pass || pass == "\n") | |
22 pass = ("Click here to edit your secure data. " + | |
23 "It will automatically be saved when you close " + | |
24 "this page."); | |
25 var stuff = jQuery("<pre></pre>", doc).text(pass); | |
26 stuff.attr("contentEditable", "true"); | |
27 doc.defaultView.addEventListener( | |
28 "unload", | |
29 function() { | |
30 jQuery("br", stuff).replaceWith('\n'); | |
31 setPass(stuff.text()); | |
32 }, | |
33 true | |
34 ); | |
35 jQuery(doc.body).hide().append(stuff).fadeIn(); | |
36 } | |
37 } | |
38 | |
39 CmdUtils.CreateCommand( | |
40 {name: "my-secure-data", | |
41 previewUrl: "index.html", | |
42 preview: function(pblock) { | |
43 jQuery(pblock).addClass("ubiquity-preview-content"); | |
44 }, | |
45 execute: function() { | |
46 Utils.focusUrlInBrowser(hostname); | |
47 }} | |
48 ); | |
49 | |
50 function getPass() { | |
51 var result = loginManager.findLogins({}, hostname, formSubmitURL, realm); | |
52 if (result.length) | |
53 return result[0].password; | |
54 return ""; | |
55 } | |
56 | |
57 function setPass(password) { | |
58 var result = loginManager.findLogins({}, hostname, formSubmitURL, realm); | |
59 | |
60 var nsLoginInfo = new Components.Constructor( | |
61 "@mozilla.org/login-manager/loginInfo;1", | |
62 Ci.nsILoginInfo, | |
63 "init" | |
64 ); | |
65 | |
66 var extLoginInfo = new nsLoginInfo(hostname, | |
67 formSubmitURL, realm, | |
68 username, password, usernameField, | |
69 passwordField); | |
70 | |
71 if (result.length) { | |
72 if (result[0].password != password) | |
73 loginManager.modifyLogin(result[0], extLoginInfo); | |
74 } else { | |
75 loginManager.addLogin(extLoginInfo); | |
76 } | |
77 } |