Mercurial > my-ubiquity-commands
changeset 17:f3e03596fcf9
Added secure data storage command feed.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 08 Apr 2009 10:52:31 -0700 |
parents | 426e9c04c6f9 |
children | 08bddf757ed8 |
files | secure-data-storage/index.html secure-data-storage/secure-data-storage.js |
diffstat | 2 files changed, 105 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/secure-data-storage/index.html Wed Apr 08 10:52:31 2009 -0700 @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> + <link rel="commands" href="secure-data-storage.js"> + <title>Secure Data Storage</title> +</head> +<body> +<p> + The <tt>my-secure-data</tt> command allows you to access and edit a + plain text file that can contain whatever sensitive data you want. +</p> +<p> + If you have + Firefox's <a href="http://support.mozilla.com/en-US/kb/Protecting+stored+passwords+using+a+master+password">master + password feature</a> enabled, this data will be encrypted + on-disk. In addition, you'll be asked for your master password + before editing your data. +</p> +<p> + If you have <a href="https://services.mozilla.com/">Weave</a> + installed and configured to sync passwords, this data will + automatically be synced between your computers and devices that + have Weave installed. +</p> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/secure-data-storage/secure-data-storage.js Wed Apr 08 10:52:31 2009 -0700 @@ -0,0 +1,77 @@ +Components.utils.import("resource://ubiquity/modules/ubiquity_protocol.js"); + +var loginManager = Cc["@mozilla.org/login-manager;1"] + .getService(Ci.nsILoginManager); +var path = 'secure-data-storage'; +var hostname = 'ubiquity://' + path; +var realm = 'Secure Data Storage'; +var formSubmitURL = null; +var username = ''; +var usernameField = ""; +var passwordField = ""; + +setPath(path, + ("data:text/html," + + "<html><head><title>Your Secure Data</title></head>" + + "<body></body></html>")); + +function pageLoad_path(doc) { + if (doc.location.href == hostname) { + var pass = getPass(); + if (!pass || pass == "\n") + pass = ("Click here to edit your secure data. " + + "It will automatically be saved when you close " + + "this page."); + var stuff = jQuery("<pre></pre>", doc).text(pass); + stuff.attr("contentEditable", "true"); + doc.defaultView.addEventListener( + "unload", + function() { + jQuery("br", stuff).replaceWith('\n'); + setPass(stuff.text()); + }, + true + ); + jQuery(doc.body).hide().append(stuff).fadeIn(); + } +} + +CmdUtils.CreateCommand( + {name: "my-secure-data", + previewUrl: "index.html", + preview: function(pblock) { + jQuery(pblock).addClass("ubiquity-preview-content"); + }, + execute: function() { + Utils.focusUrlInBrowser(hostname); + }} +); + +function getPass() { + var result = loginManager.findLogins({}, hostname, formSubmitURL, realm); + if (result.length) + return result[0].password; + return ""; +} + +function setPass(password) { + var result = loginManager.findLogins({}, hostname, formSubmitURL, realm); + + var nsLoginInfo = new Components.Constructor( + "@mozilla.org/login-manager/loginInfo;1", + Ci.nsILoginInfo, + "init" + ); + + var extLoginInfo = new nsLoginInfo(hostname, + formSubmitURL, realm, + username, password, usernameField, + passwordField); + + if (result.length) { + if (result[0].password != password) + loginManager.modifyLogin(result[0], extLoginInfo); + } else { + loginManager.addLogin(extLoginInfo); + } +}