Bug 667327 - Require Master Pasword before allowing password to be copied. r=kairo, sr=neil
authorEdmund Wong <ewong@pw-wspx.org>
Sat, 28 Apr 2012 10:44:01 -0400
changeset 11999 0338581fa753c09a30662c0029e7ebfcaa780dfa
parent 11998 2b4524d258f3dc56494cb2b50f41959d370a1d79
child 12000 00b3085697d35ddda3936b144aa321c30496a311
push id599
push usermconley@mozilla.com
push dateMon, 16 Jul 2012 20:33:12 +0000
treeherdercomm-beta@c3489d5b7b65 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskairo, neil
bugs667327
Bug 667327 - Require Master Pasword before allowing password to be copied. r=kairo, sr=neil
suite/common/dataman/dataman.js
--- a/suite/common/dataman/dataman.js
+++ b/suite/common/dataman/dataman.js
@@ -2028,23 +2028,41 @@ var gPasswords = {
     document.getElementById("pwd-context-remove").disabled =
       this.removeButton.disabled;
     document.getElementById("pwd-context-copypassword").disabled =
       this.tree.view.selection.count != 1;
     document.getElementById("pwd-context-selectall").disabled =
       this.tree.view.selection.count >= this.tree.view.rowCount;
   },
 
-  copyPassword: function passwords_copyPassword() {
+  copySelPassword: function passwords_copySelPassword() {
     // Copy selected signon's password to clipboard.
     let row = this.tree.currentIndex;
     let password = gPasswords.displayedSignons[row].password;
     gLocSvc.clipboard.copyString(password);
   },
 
+  copyPassword: function passwords_copyPassword() {
+    // Prompt for the master password upfront.
+    let token = Components.classes["@mozilla.org/security/pk11tokendb;1"]
+                          .getService(Components.interfaces.nsIPK11TokenDB)
+                          .getInternalKeyToken();
+
+    if (this.showPasswords || token.checkPassword(""))
+      this.copySelPassword();
+    else {
+      try {
+        token.login(true);
+        this.copySelPassword();
+      } catch (ex) {
+      // If user cancels an exception is expected.
+      }
+    }
+  },
+
   reactToChange: function passwords_reactToChange(aSubject, aData) {
     // aData: addLogin, modifyLogin, removeLogin, removeAllLogins
     if (aData == "removeAllLogins") {
       // Go for re-parsing the whole thing.
       if (this.displayedSignons.length) {
         this.tree.treeBoxObject.beginUpdateBatch();
         this.tree.view.selection.clearSelection();
         this.displayedSignons = [];