Bug 1724136 - P2. Restructure onFormSubmit function r=sfoster,tgiles
authorDimi Lee <dlee@mozilla.com>
Mon, 13 Sep 2021 12:24:49 +0000
changeset 591738 3a0f70175d72b95cd15f26207a7f0f3e6fe456a6
parent 591737 a8ca5104f6f8579b3d007ddd65391a7c2cfa9036
child 591739 0bf41da9f46737d2c351a609e0ccbf4f3d7bcc21
push id38786
push usermlaza@mozilla.com
push dateMon, 13 Sep 2021 21:32:24 +0000
treeherdermozilla-central@b50ef8e31c4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster, tgiles
bugs1724136
milestone94.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 1724136 - P2. Restructure onFormSubmit function r=sfoster,tgiles Since _getFormFields calls getUsernameFieldFromUsernameOnlyForm, we don't have to call getUsernameFieldFromUsernameOnlyForm in onFormSubmit. Instead, We can just use the result of _getFormFields to know whether an username-only form is submitted. This also makes sure we use the site recipe while check if the form is a username-only form during form submission. Depends on D124339 Differential Revision: https://phabricator.services.mozilla.com/D124340
toolkit/components/passwordmgr/LoginManagerChild.jsm
--- a/toolkit/components/passwordmgr/LoginManagerChild.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerChild.jsm
@@ -1912,33 +1912,16 @@ this.LoginManagerChild = class LoginMana
    * Looks for a password change in the submitted form, so we can update
    * our stored password.
    *
    * @param {LoginForm} form
    */
   _onFormSubmit(form, reason) {
     log("_onFormSubmit", form);
 
-    // If the form is in a username-only form, record the username field before
-    // it is removed.
-    let usernameField = this.getUsernameFieldFromUsernameOnlyForm(
-      form.rootElement
-    );
-    if (usernameField) {
-      log(
-        "_onFormSubmit: username-only form. Record the username field but not sending prompt"
-      );
-      let docState = this.stateForDocument(form.ownerDocument);
-      docState.mockUsernameOnlyField = {
-        name: usernameField.name,
-        value: usernameField.value,
-      };
-      return;
-    }
-
     this._maybeSendFormInteractionMessage(
       form,
       "PasswordManager:onFormSubmit",
       {
         targetField: null,
         isSubmission: true,
         // When this is trigger by inferring from form removal, the form is not
         // connected anymore, skip checking isConnected in this case.
@@ -2016,30 +1999,40 @@ this.LoginManagerChild = class LoginMana
         passwordField &&
         passwordField != newPasswordField &&
         passwordField != oldPasswordField &&
         passwordField != confirmPasswordField
       ) {
         newPasswordField = passwordField;
       }
 
+      let docState = this.stateForDocument(doc);
+
       // Need at least 1 valid password field to do anything.
       if (newPasswordField == null) {
+        if (isSubmission && usernameField) {
+          log(
+            "_onFormSubmit: username-only form. Record the username field but not sending prompt"
+          );
+          docState.mockUsernameOnlyField = {
+            name: usernameField.name,
+            value: usernameField.value,
+          };
+        }
         return;
       }
 
       let fullyMungedPattern = /^\*+$|^•+$|^\.+$/;
       // Check `isSubmission` to allow munged passwords in dismissed by default doorhangers (since
       // they are initiated by the user) in case this matches their actual password.
       if (isSubmission && newPasswordField?.value.match(fullyMungedPattern)) {
         log("new password looks munged. Not sending prompt");
         return;
       }
 
-      let docState = this.stateForDocument(doc);
       // When the username field is empty, check whether we have found it previously from
       // a username-only form, if yes, fill in its value.
       // XXX This is not ideal, we only use the previous saved username field when the current
       // form doesn't have one. This means if there is a username field found in the current
       // form, we don't compare it to the saved one, which might be a better choice in some cases.
       // The reason we are not doing it now is because we haven't found a real world example.
       if (!usernameField) {
         if (docState.mockUsernameOnlyField) {