Bug 1361237 - Part 2: Separate the filter criteria of Credit Card and Address fields.; r?MattN
MozReview-Commit-ID: Joii2WjQywm
--- 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