Bug 1186123 - Ensure the password field is masked by default in the capture doorhanger. r=rittme
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 29 Jul 2015 23:04:26 -0700
changeset 287061 b0ea220ccfb3893f2d2f979c10b82dbd8b008feb
parent 286970 50eefd290385d410e17b28a00b00ff79a4e24841
child 287062 7e94e4795386f80aa71451798363c22d5fe5b77d
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrittme
bugs1186123
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1186123 - Ensure the password field is masked by default in the capture doorhanger. r=rittme * The `type` setter won't work if the <xul:textbox> lost its binding before the blur occurs so switch to setAttribute. * For good measure, set the type attribute to "password" before setting the value.
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -842,24 +842,27 @@ LoginManagerPrompter.prototype = {
       if (element) {
         element.setAttribute("buttonlabel", label);
         element.setAttribute("buttonaccesskey", accessKey);
         updateButtonStatus(element);
       }
     };
 
     let writeDataToUI = () => {
+      // setAttribute is used since the <textbox> binding may not be attached yet.
       chromeDoc.getElementById("password-notification-username")
                .setAttribute("placeholder", usernamePlaceholder);
       chromeDoc.getElementById("password-notification-username")
                .setAttribute("value", login.username);
-      chromeDoc.getElementById("password-notification-password")
-               .setAttribute("value", login.password);
-      chromeDoc.getElementById("password-notification-password")
-               .setAttribute("show-content", showPasswordPlaceholder);
+
+      let passwordField = chromeDoc.getElementById("password-notification-password");
+      // Ensure the type is reset so the field is masked.
+      passwordField.setAttribute("type", "password");
+      passwordField.setAttribute("value", login.password);
+      passwordField.setAttribute("show-content", showPasswordPlaceholder);
       updateButtonLabel();
     };
 
     let readDataFromUI = () => {
       login.username =
         chromeDoc.getElementById("password-notification-username").value;
       login.password =
         chromeDoc.getElementById("password-notification-password").value;
@@ -875,23 +878,24 @@ LoginManagerPrompter.prototype = {
       // Gets the caret position before changing the type of the textbox
       let selectionStart = passwordField.selectionStart;
       let selectionEnd = passwordField.selectionEnd;
       if (focusEvent.rangeParent != null) {
         // Check for a click over the SHOW placeholder
         selectionStart = passwordField.value.length;
         selectionEnd = passwordField.value.length;
       }
-      passwordField.type = "";
+      passwordField.setAttribute("type", "");
       passwordField.selectionStart = selectionStart;
       passwordField.selectionEnd = selectionEnd;
     };
 
     let onPasswordBlur = () => {
-      chromeDoc.getElementById("password-notification-password").type = "password";
+      // Use setAttribute in case the <textbox> binding isn't applied.
+      chromeDoc.getElementById("password-notification-password").setAttribute("type", "password");
     };
 
     let onNotificationClick = (clickEvent) => {
       // Removes focus from textboxes when we click elsewhere on the doorhanger.
       let focusedElement = Services.focus.focusedElement;
       if (!focusedElement || focusedElement.nodeName != "html:input") {
         // No input is focused so we don't need to blur
         return;