# HG changeset patch # User Atul Varma # Date 1239213151 25200 # Node ID f3e03596fcf945b31680bc32cf34e74f427184f2 # Parent 426e9c04c6f99bf97ea787eb1aceb6055f27c59a Added secure data storage command feed. diff -r 426e9c04c6f9 -r f3e03596fcf9 secure-data-storage/index.html --- /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 @@ + + + + + + Secure Data Storage + + +

+ The my-secure-data command allows you to access and edit a + plain text file that can contain whatever sensitive data you want. +

+

+ If you have + Firefox's master + password feature enabled, this data will be encrypted + on-disk. In addition, you'll be asked for your master password + before editing your data. +

+

+ If you have Weave + installed and configured to sync passwords, this data will + automatically be synced between your computers and devices that + have Weave installed. +

+ + diff -r 426e9c04c6f9 -r f3e03596fcf9 secure-data-storage/secure-data-storage.js --- /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," + + "Your Secure Data" + + "")); + +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("
", 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);
+  }
+}