Bug 1325648 - Remove token choosing functionality from changepassword.(js|xul). r=keeler draft
authorCykesiopka <cykesiopka.bmo@gmail.com>
Fri, 06 Jan 2017 23:11:26 +0800
changeset 456995 e0e6eb89735125a9b85491356c9d367eab0c2a3b
parent 456956 44319b48939468ccee22cc03a4cae5e506c2847d
child 541371 9174fb79291b5bcf5243021924c248e7c5ddeafb
push id40657
push usercykesiopka.bmo@gmail.com
push dateFri, 06 Jan 2017 15:49:46 +0000
reviewerskeeler
bugs1325648
milestone53.0a1
Bug 1325648 - Remove token choosing functionality from changepassword.(js|xul). r=keeler The functionality is unnecessary duplication of what the Device Manager already does, and nsITokenDialogs.ChooseToken() exists as a dedicated UI for choosing tokens anyways. Since we're already breaking addon compat, the changes here also update nsITokenPasswordDialogs.setPassword() to not unnecessarily return the `canceled` value through an outparam. MozReview-Commit-ID: C2KVXzrpDR3
security/manager/pki/resources/content/changepassword.js
security/manager/pki/resources/content/changepassword.xul
security/manager/ssl/nsITokenPasswordDialogs.idl
security/manager/ssl/tests/unit/test_sdr.js
--- a/security/manager/pki/resources/content/changepassword.js
+++ b/security/manager/pki/resources/content/changepassword.js
@@ -1,18 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
-const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
 const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
-const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
 const nsPKCS11ModuleDB = "@mozilla.org/security/pkcs11moduledb;1";
 const nsIPKCS11ModuleDB = Components.interfaces.nsIPKCS11ModuleDB;
 const nsIPKCS11Slot = Components.interfaces.nsIPKCS11Slot;
 const nsIPK11Token = Components.interfaces.nsIPK11Token;
 
 var params;
 var tokenName = "";
 var pw1;
@@ -24,68 +22,24 @@ function doPrompt(msg)
   prompts.alert(window, null, msg);
 }
 
 function onLoad()
 {
   document.documentElement.getButton("accept").disabled = true;
 
   pw1 = document.getElementById("pw1");
-  try {
-     params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
-     tokenName = params.GetString(1);
-  } catch (e) {
-      // this should not happen.
-      // previously we had self.name, but self.name was a bad idea
-      // as window name must be a subset of ascii, and the code was
-      // previously trying to assign unicode to the window's name.
-      // I checked all the places where we get a password prompt and
-      // all of them pass an argument as part of this patch.
-      tokenName = "";
-  }
+  params = window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
+  tokenName = params.GetString(1);
 
-  if (tokenName == "") {
-    let tokenDB = Components.classes[nsPK11TokenDB].getService(nsIPK11TokenDB);
-    let tokenList = tokenDB.listTokens();
-    let i = 0;
-    let menu = document.getElementById("tokenMenu");
-    while (tokenList.hasMoreElements()) {
-      let token = tokenList.getNext().QueryInterface(nsIPK11Token);
-      if (token.needsLogin() || !(token.needsUserInit)) {
-        let menuItemNode = document.createElement("menuitem");
-        menuItemNode.setAttribute("value", token.tokenName);
-        menuItemNode.setAttribute("label", token.tokenName);
-        menu.firstChild.appendChild(menuItemNode);
-        if (i == 0) {
-          menu.selectedItem = menuItemNode;
-          tokenName = token.tokenName;
-        }
-        i++;
-      }
-    }
-  } else {
-    var sel = document.getElementById("tokenMenu");
-    sel.setAttribute("hidden", "true");
-    var tag = document.getElementById("tokenName");
-    tag.setAttribute("value", tokenName);
-  }
+  document.getElementById("tokenName").setAttribute("value", tokenName);
 
   process();
 }
 
-function onMenuChange()
-{
-   //get the selected token
-   var list = document.getElementById("tokenMenu");
-   tokenName = list.value;
-
-   process();
-}
-
-
 function process()
 {
   let bundle = document.getElementById("pippki_bundle");
 
   // If the token is unitialized, don't use the old password box.
   // Otherwise, do.
 
   let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"]
--- a/security/manager/pki/resources/content/changepassword.xul
+++ b/security/manager/pki/resources/content/changepassword.xul
@@ -16,30 +16,18 @@
 <stringbundle id="pippki_bundle" src="chrome://pippki/locale/pippki.properties"/>
 
 <script type="application/javascript"
         src="chrome://pippki/content/changepassword.js"/>
 
 <hbox align="center">
   <label value="&setPassword.tokenName.label;: "/>
   <label id="tokenName" />
-  <menulist id="tokenMenu" oncommand="onMenuChange()">
-     <menupopup/>
-  </menulist>
 </hbox>
 
-
-<!--
-    <menulist id="signerList" disabled="true">
-      <menupopup>
-        <menuitem id="token-menu" label="Built-in private key database"/>
-        <menuitem label="Bob Lord's iButton"/>
-      </menupopup>
-    </menulist>
--->
 <separator/>
 
 <groupbox>
 <grid>
  <columns>
    <column/>
    <column/> 
  </columns>
--- a/security/manager/ssl/nsITokenPasswordDialogs.idl
+++ b/security/manager/ssl/nsITokenPasswordDialogs.idl
@@ -1,29 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 interface nsIInterfaceRequestor;
 
-
 /**
- * nsITokenPasswordDialogs
  *  This is the interface for setting and changing password
  *  on a PKCS11 token.
  */
 [scriptable, uuid(87dbd64a-4466-474e-95f5-1ad1cee5702c)]
 interface nsITokenPasswordDialogs : nsISupports
 {
   /**
-   * setPassword - sets the password/PIN on the named token.
-   *   The canceled output value should be set to TRUE when
-   *   the user (or implementation) cancels the operation.
+   * Brings up a dialog to set the password on a token.
+   *
+   * @param ctx A user interface context.
+   * @param tokenName Name of the token.
+   * @return true if the user canceled the dialog, false otherwise.
    */
-  void setPassword(in nsIInterfaceRequestor ctx, in wstring tokenName,
-                   out boolean canceled);
+  boolean setPassword(in nsIInterfaceRequestor ctx, in wstring tokenName);
 };
 
 %{C++
 #define NS_TOKENPASSWORDSDIALOG_CONTRACTID "@mozilla.org/nsTokenPasswordDialogs;1"
 %}
--- a/security/manager/ssl/tests/unit/test_sdr.js
+++ b/security/manager/ssl/tests/unit/test_sdr.js
@@ -6,21 +6,21 @@
 // Tests various aspects of the nsISecretDecoderRing implementation.
 
 do_get_profile();
 
 let gSetPasswordShownCount = 0;
 
 // Mock implementation of nsITokenPasswordDialogs.
 const gTokenPasswordDialogs = {
-  setPassword: (ctx, tokenName, canceled) => {
+  setPassword(ctx, tokenName) {
     gSetPasswordShownCount++;
     do_print(`setPassword() called; shown ${gSetPasswordShownCount} times`);
     do_print(`tokenName: ${tokenName}`);
-    canceled.value = false;
+    return false; // Returning false means "the user didn't cancel".
   },
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsITokenPasswordDialogs])
 };
 
 function run_test() {
   // We have to set a password and login before we attempt to encrypt anything.
   // In particular, failing to do so will cause the Encrypt() implementation to