Bug 1361237 - Part 2: Separate the filter criteria of Credit Card and Address fields.; r?MattN draft
authorSean Lee <selee@mozilla.com>
Mon, 22 May 2017 11:21:16 +0800
changeset 589321 ad3efa3f494329409b469dd0057123496bb29e72
parent 589320 20ee524f5c157369d6c008a9c444671c2fb4ef45
child 589322 61253d7ce53e0d306657fdb6cab17f2352f02457
push id62323
push userbmo:selee@mozilla.com
push dateTue, 06 Jun 2017 01:56:39 +0000
reviewersMattN
bugs1361237
milestone55.0a1
Bug 1361237 - Part 2: Separate the filter criteria of Credit Card and Address fields.; r?MattN MozReview-Commit-ID: Joii2WjQywm
browser/extensions/formautofill/FormAutofillContent.jsm
browser/extensions/formautofill/FormAutofillHandler.jsm
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -469,27 +469,33 @@ var FormAutofillContent = {
 
     this.log.debug("Found", forms.length, "forms");
 
     // Collects the fields that can be autofilled from each form and marks them
     // as autofill fields if the amount is above the threshold.
     forms.forEach(form => {
       let formHandler = new FormAutofillHandler(form);
       formHandler.collectFormFields();
-      if (formHandler.fieldDetails.length < AUTOFILL_FIELDS_THRESHOLD) {
-        this.log.debug("Ignoring form since it has only", formHandler.fieldDetails.length,
-                       "field(s)");
+      let validAddressForm = formHandler.numAddressesFields >= AUTOFILL_FIELDS_THRESHOLD;
+      let validCreditCardForm = formHandler.formDetails && formHandler.formDetails.find(i => i.fieldName == "cc-number");
+
+      if (!validAddressForm && !validCreditCardForm) {
+        this.log.debug("Ignoring form since it has only", formHandler.numAddressesFields,
+                       "address field(s)");
         return;
       }
 
       this._formsDetails.set(form.rootElement, formHandler);
       this.log.debug("Adding form handler to _formsDetails:", formHandler);
-      formHandler.fieldDetails.forEach(detail =>
-        this._markAsAutofillField(detail.elementWeakRef.get())
-      );
+      formHandler.fieldDetails.forEach(detail => {
+        if ((validAddressForm && FormAutofillUtils.isAddressField(detail.fieldName)) ||
+            (validCreditCardForm && FormAutofillUtils.isCreditCardField(detail.fieldName))) {
+          this._markAsAutofillField(detail.elementWeakRef.get());
+        }
+      });
     });
   },
 
   _markAsAutofillField(field) {
     // Since Form Autofill popup is only for input element, any non-Input
     // element should be excluded here.
     if (!field || !(field instanceof Ci.nsIDOMHTMLInputElement)) {
       return;
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -52,22 +52,29 @@ FormAutofillHandler.prototype = {
    */
   fieldDetails: null,
 
   /**
    * String of the filled profile's guid.
    */
   filledProfileGUID: null,
 
+  numAddressesFields: 0,
+
   /**
    * Set fieldDetails from the form about fields that can be autofilled.
    */
   collectFormFields() {
     let fieldDetails = FormAutofillHeuristics.getFormInfo(this.form);
     this.fieldDetails = fieldDetails ? fieldDetails : [];
+    for (let details of this.fieldDetails) {
+      if (FormAutofillUtils.isAddressField(details.fieldName)) {
+        this.numAddressesFields++;
+      }
+    }
     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