Bug 1360374 - Identify FormAutofill fields when a field is focused on.; r?MattN draft
authorSean Lee <selee@mozilla.com>
Wed, 03 May 2017 07:52:35 +0800
changeset 573892 1fca5ebdf4640d3b7ef402c451ded713c63ddd90
parent 573891 c3e5497cff1c995821b1c9320fa71f1ef9a8c30e
child 573893 a2bde128895a7b8b2b7ad88c32bec9ef5ee4b9f3
push id57528
push userbmo:selee@mozilla.com
push dateMon, 08 May 2017 03:32:51 +0000
reviewersMattN
bugs1360374
milestone55.0a1
Bug 1360374 - Identify FormAutofill fields when a field is focused on.; r?MattN MozReview-Commit-ID: 3VtrwptASnr
browser/extensions/formautofill/FormAutofillContent.jsm
browser/extensions/formautofill/content/FormAutofillFrameScript.js
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -405,16 +405,23 @@ var FormAutofillContent = {
     // Collects root forms from inputs.
     for (let field of doc.getElementsByTagName("input")) {
       // We only consider text-like fields for now until we support radio and
       // checkbox buttons in the future.
       if (!field.mozIsTextField(true)) {
         continue;
       }
 
+      // For now skip consider fields in forms we've already seen before even
+      // if the specific field wasn't seen before. Ideally whether the field is
+      // already in the handler's form details would be considered.
+      if (this.getFormHandler(field)) {
+        continue;
+      }
+
       let formLike = FormLikeFactory.createFromField(field);
       if (!forms.some(form => form.rootElement === formLike.rootElement)) {
         forms.push(formLike);
       }
     }
 
     this.log.debug("Found", forms.length, "forms");
 
--- a/browser/extensions/formautofill/content/FormAutofillFrameScript.js
+++ b/browser/extensions/formautofill/content/FormAutofillFrameScript.js
@@ -18,37 +18,37 @@ Cu.import("resource://formautofill/FormA
 
 /**
  * Handles content's interactions for the frame.
  *
  * NOTE: Declares it by "var" to make it accessible in unit tests.
  */
 var FormAutofillFrameScript = {
   init() {
-    addEventListener("DOMContentLoaded", this);
+    addEventListener("focusin", this);
     addMessageListener("FormAutofill:PreviewProfile", this);
     addMessageListener("FormAutoComplete:PopupClosed", this);
   },
 
   handleEvent(evt) {
     if (!evt.isTrusted) {
       return;
     }
 
     if (!Services.prefs.getBoolPref("browser.formautofill.enabled")) {
       return;
     }
 
     switch (evt.type) {
-      case "DOMContentLoaded": {
-        let doc = evt.target;
-        if (!(doc instanceof Ci.nsIDOMHTMLDocument)) {
+      case "focusin": {
+        let element = evt.target;
+        if (!(element instanceof Ci.nsIDOMHTMLInputElement)) {
           return;
         }
-        FormAutofillContent.identifyAutofillFields(doc);
+        FormAutofillContent.identifyAutofillFields(element.ownerDocument);
         break;
       }
     }
   },
 
   receiveMessage(message) {
     if (!Services.prefs.getBoolPref("browser.formautofill.enabled")) {
       return;