Bug 1164469 - LoginManagerContent._fillForm should take an options argument; r?MattN draft
authorJim Porter <jporter@mozilla.com>
Mon, 20 Mar 2017 19:13:13 -0500
changeset 554857 edf00064d75c
parent 554803 38894655c89e
child 622454 0580c7440c6a
push id52071
push userbmo:squibblyflabbetydoo@gmail.com
push dateMon, 03 Apr 2017 02:07:15 +0000
reviewersMattN
bugs1164469
milestone55.0a1
Bug 1164469 - LoginManagerContent._fillForm should take an options argument; r?MattN MozReview-Commit-ID: A38fIWbGCaa
toolkit/components/passwordmgr/LoginManagerContent.jsm
--- a/toolkit/components/passwordmgr/LoginManagerContent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContent.jsm
@@ -536,32 +536,35 @@ var LoginManagerContent = {
             "document. This may mean we navigated to a document from a different",
             "site before we had a chance to indicate this change in the user",
             "interface.");
         return;
       }
     }
 
     let clobberUsername = true;
-    let options = {
-      inputElement,
-    };
-
     let form = LoginFormFactory.createFromField(inputElement);
     if (inputElement.type == "password") {
       clobberUsername = false;
     }
-    this._fillForm(form, true, clobberUsername, true, true, loginsFound, recipes, options);
+
+    this._fillForm(form, loginsFound, recipes, {
+      inputElement,
+      autofillForm: true,
+      clobberUsername,
+      clobberPassword: true,
+      userTriggered: true,
+    });
   },
 
   loginsFound({ form, loginsFound, recipes }) {
     let doc = form.ownerDocument;
     let autofillForm = gAutofillForms && !PrivateBrowsingUtils.isContentWindowPrivate(doc.defaultView);
 
-    this._fillForm(form, autofillForm, false, false, false, loginsFound, recipes);
+    this._fillForm(form, loginsFound, recipes, {autofillForm});
   },
 
   /**
    * Focus event handler for username fields to decide whether to show autocomplete.
    * @param {FocusEvent} event
    */
   _onUsernameFocus(event) {
     let focusedField = event.target;
@@ -643,17 +646,21 @@ var LoginManagerContent = {
 
     // Make sure the username field fillForm will use is the
     // same field as the autocomplete was activated on.
     var [usernameField, passwordField, ignored] =
         this._getFormFields(acForm, false, recipes);
     if (usernameField == acInputField && passwordField) {
       this._getLoginDataFromParent(acForm, { showMasterPassword: false })
           .then(({ form, loginsFound, recipes }) => {
-            this._fillForm(form, true, false, true, true, loginsFound, recipes);
+            this._fillForm(form, loginsFound, recipes, {
+              autofillForm: true,
+              clobberPassword: true,
+              userTriggered: true,
+            });
           })
           .then(null, Cu.reportError);
     } else {
       // Ignore the event, it's for some input we don't care about.
     }
   },
 
   /**
@@ -978,33 +985,43 @@ var LoginManagerContent = {
                                     { openerTopWindow });
   },
 
   /**
    * Attempt to find the username and password fields in a form, and fill them
    * in using the provided logins and recipes.
    *
    * @param {LoginForm} form
-   * @param {bool} autofillForm denotes if we should fill the form in automatically
-   * @param {bool} clobberUsername controls if an existing username can be overwritten.
-   *                               If this is false and an inputElement of type password
-   *                               is also passed, the username field will be ignored.
-   *                               If this is false and no inputElement is passed, if the username
-   *                               field value is not found in foundLogins, it will not fill the password.
-   * @param {bool} clobberPassword controls if an existing password value can be
-   *                               overwritten
-   * @param {bool} userTriggered is an indication of whether this filling was triggered by
-   *                             the user
-   * @param {nsILoginInfo[]} foundLogins is an array of nsILoginInfo that could be used for the form
-   * @param {Set} recipes that could be used to affect how the form is filled
-   * @param {Object} [options = {}] is a list of options for this method.
-            - [inputElement] is an optional target input element we want to fill
+   * @param {nsILoginInfo[]} foundLogins an array of nsILoginInfo that could be
+            used for the form
+   * @param {Set} recipes a set of recipes that could be used to affect how the
+            form is filled
+   * @param {Object} [options = {}] a list of options for this method
+   * @param {HTMLInputElement} [options.inputElement = null] an optional target
+   *        input element we want to fill
+   * @param {bool} [options.autofillForm = false] denotes if we should fill the
+   *        form in automatically
+   * @param {bool} [options.clobberUsername = false] controls if an existing
+   *        username can be overwritten. If this is false and an inputElement
+   *        of type password is also passed, the username field will be ignored.
+   *        If this is false and no inputElement is passed, if the username
+   *        field value is not found in foundLogins, it will not fill the
+   *        password.
+   * @param {bool} [options.clobberPassword = false] controls if an existing
+   *        password value can be overwritten
+   * @param {bool} [options.userTriggered = false] an indication of whether
+   *        this filling was triggered by the user
    */
-  _fillForm(form, autofillForm, clobberUsername, clobberPassword,
-            userTriggered, foundLogins, recipes, {inputElement} = {}) {
+  _fillForm(form, foundLogins, recipes, {
+    inputElement = null,
+    autofillForm = false,
+    clobberUsername = false,
+    clobberPassword = false,
+    userTriggered = false,
+  } = {}) {
     if (form instanceof Ci.nsIDOMHTMLFormElement) {
       throw new Error("_fillForm should only be called with FormLike objects");
     }
 
     log("_fillForm", form.elements);
     let ignoreAutocomplete = true;
     // Will be set to one of AUTOFILL_RESULT in the `try` block.
     let autofillResult = -1;