[epiphany/mcatanzaro/#1018] Make password manager user account selector actually work



commit d41289ee1f63223e1dab72a4b4a23020425b4a65
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Feb 5 15:02:10 2020 -0600

    Make password manager user account selector actually work
    
    I broke this in 4e1f237f by changing FormManager.preFill() to require a
    formAuth parameter, but not updating every callsite.
    
    I think it was probably broken even before that, though, because there
    was no code to update the formAuth when changing the selected username.
    We have to do that too before calling preFill(). Also, blank out the
    password field beforehand just in case we fail to fill in the password,
    to avoid any possibility of using the old password for the new username.
    
    Fixes #1018

 embed/web-process-extension/resources/js/ephy.js | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/embed/web-process-extension/resources/js/ephy.js 
b/embed/web-process-extension/resources/js/ephy.js
index a106a6073..f099b0ebb 100644
--- a/embed/web-process-extension/resources/js/ephy.js
+++ b/embed/web-process-extension/resources/js/ephy.js
@@ -103,12 +103,13 @@ Ephy.getWebAppIcon = function(baseURL)
 
 Ephy.PreFillUserMenu = class PreFillUserMenu
 {
-    constructor(manager, userElement, users, passwordElement)
+    constructor(manager, formAuth, users)
     {
         this._manager = manager;
-        this._userElement = userElement;
+        this._formAuth = formAuth;
+        this._userElement = formAuth.usernameNode;
         this._users = users;
-        this._passwordElement = passwordElement;
+        this._passwordElement = formAuth.passwordNode;
         this._selected = null;
         this._wasEdited = false;
 
@@ -165,7 +166,7 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
         if (newSelect) {
             this._selected = newSelect;
             this._userElement.value = this._selected.firstElementChild.textContent;
-            this._manager.preFill();
+            this._usernameSelected();
         } else {
             this._passwordElement.value = '';
         }
@@ -233,7 +234,7 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
                 this._userElement.value = user;
                 this._selected = li;
                 this._removeMenu();
-                this._manager.preFill();
+                this._usernameSelected();
             }, true);
         }
 
@@ -249,6 +250,13 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
         if (menu)
             menu.parentNode.removeChild(menu);
     }
+
+    _usernameSelected()
+    {
+        this._formAuth.username = this._userElement.value;
+        this._passwordElement.value = '';
+        this._manager.preFill(this._formAuth);
+    }
 }
 
 Ephy.formControlsAssociated = function(pageID, frameID, forms, serializer)
@@ -443,7 +451,7 @@ Ephy.FormManager = class FormManager
             Ephy.passwordManager.queryUsernames(formAuth.origin).then(users => {
                 if (users.length > 1) {
                     Ephy.log('More than one saved username, hooking menu for choosing which one to select');
-                    this._preFillUserMenu = new Ephy.PreFillUserMenu(this, formAuth.usernameNode, users, 
formAuth.passwordNode);
+                    this._preFillUserMenu = new Ephy.PreFillUserMenu(this, formAuth, users);
                 }
                 this.preFill(formAuth);
             });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]