Bug 1349489 - Part 1: Move the codes from FormAutofillHandler.collectFormFields to FormAutofillHeuristics.getFormInfo.; r=MattN
☠☠ backed out by cc35b73d4f98 ☠ ☠
authorSean Lee <selee@mozilla.com>
Fri, 21 Apr 2017 15:15:35 +0800
changeset 569311 4ff3acec9515433fc2692826c9ca3ab9b3e354b0
parent 569310 0b8bf5cb743f4b6da71aa03b456aa551d6b96d4f
child 569312 6208b116de638c1466bc5fd381f20117e6fce77b
push id56143
push userbmo:jeremychen@mozilla.com
push dateThu, 27 Apr 2017 10:17:21 +0000
reviewersMattN
bugs1349489
milestone55.0a1
Bug 1349489 - Part 1: Move the codes from FormAutofillHandler.collectFormFields to FormAutofillHeuristics.getFormInfo.; r=MattN MozReview-Commit-ID: BQTpopSyBUe
browser/extensions/formautofill/FormAutofillHandler.jsm
browser/extensions/formautofill/FormAutofillHeuristics.jsm
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -56,46 +56,18 @@ FormAutofillHandler.prototype = {
    * String of the filled profile's guid.
    */
   filledProfileGUID: null,
 
   /**
    * Set fieldDetails from the form about fields that can be autofilled.
    */
   collectFormFields() {
-    this.fieldDetails = [];
-
-    for (let element of this.form.elements) {
-      // Exclude elements to which no autocomplete field has been assigned.
-      let info = FormAutofillHeuristics.getInfo(element);
-      if (!info) {
-        continue;
-      }
-
-      // Store the association between the field metadata and the element.
-      if (this.fieldDetails.some(f => f.section == info.section &&
-                                      f.addressType == info.addressType &&
-                                      f.contactType == info.contactType &&
-                                      f.fieldName == info.fieldName)) {
-        // A field with the same identifier already exists.
-        log.debug("Not collecting a field matching another with the same info:", info);
-        continue;
-      }
-
-      let formatWithElement = {
-        section: info.section,
-        addressType: info.addressType,
-        contactType: info.contactType,
-        fieldName: info.fieldName,
-        elementWeakRef: Cu.getWeakReference(element),
-      };
-
-      this.fieldDetails.push(formatWithElement);
-    }
-
+    let fieldDetails = FormAutofillHeuristics.getFormInfo(this.form);
+    this.fieldDetails = fieldDetails ? fieldDetails : [];
     log.debug("Collected details on", this.fieldDetails.length, "fields");
   },
 
   /**
    * Processes form fields that can be autofilled, and populates them with the
    * profile provided by backend.
    *
    * @param {Object} profile
--- a/browser/extensions/formautofill/FormAutofillHeuristics.jsm
+++ b/browser/extensions/formautofill/FormAutofillHeuristics.jsm
@@ -25,16 +25,49 @@ this.FormAutofillHeuristics = {
     "address-level2",
     "address-level1",
     "postal-code",
     "country",
     "tel",
     "email",
   ],
 
+  getFormInfo(form) {
+    let fieldDetails = [];
+    for (let element of form.elements) {
+      // Exclude elements to which no autocomplete field has been assigned.
+      let info = this.getInfo(element);
+      if (!info) {
+        continue;
+      }
+
+      // Store the association between the field metadata and the element.
+      if (fieldDetails.some(f => f.section == info.section &&
+                                 f.addressType == info.addressType &&
+                                 f.contactType == info.contactType &&
+                                 f.fieldName == info.fieldName)) {
+        // A field with the same identifier already exists.
+        log.debug("Not collecting a field matching another with the same info:", info);
+        continue;
+      }
+
+      let formatWithElement = {
+        section: info.section,
+        addressType: info.addressType,
+        contactType: info.contactType,
+        fieldName: info.fieldName,
+        elementWeakRef: Cu.getWeakReference(element),
+      };
+
+      fieldDetails.push(formatWithElement);
+    }
+
+    return fieldDetails;
+  },
+
   getInfo(element) {
     if (!(element instanceof Ci.nsIDOMHTMLInputElement)) {
       return null;
     }
 
     let info = element.getAutocompleteInfo();
     if (!info || !info.fieldName ||
         !this.VALID_FIELDS.includes(info.fieldName)) {