Bug 1371113 - Part 2: Show doorhanger and save/disable credit card. r=lchang
MozReview-Commit-ID: EcAL3ANrrGb
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -560,16 +560,17 @@ FormAutofillHandler.prototype = {
if (data.address &&
Object.keys(data.address.record).length < FormAutofillUtils.AUTOFILL_FIELDS_THRESHOLD) {
log.debug("No address record saving since there are only",
Object.keys(data.address.record).length,
"usable fields");
delete data.address;
}
- if (data.creditCard && !data.creditCard.record["cc-number"]) {
- log.debug("No credit card record saving since card number is empty");
+ if (data.creditCard && (!data.creditCard.record["cc-number"] ||
+ !FormAutofillUtils.isCCNumber(data.creditCard.record["cc-number"]))) {
+ log.debug("No credit card record saving since card number is invalid");
delete data.creditCard;
}
return data;
},
};
--- a/browser/extensions/formautofill/FormAutofillParent.jsm
+++ b/browser/extensions/formautofill/FormAutofillParent.jsm
@@ -321,19 +321,17 @@ FormAutofillParent.prototype = {
Services.ppmm.initialProcessData.autofillSavedFieldNames.delete(fieldName);
});
Services.ppmm.broadcastAsyncMessage("FormAutofill:savedFieldNames",
Services.ppmm.initialProcessData.autofillSavedFieldNames);
this._updateStatus();
},
- _onFormSubmit(data, target) {
- let {address} = data;
-
+ _onAddressSubmit(address, target) {
if (address.guid) {
// Avoid updating the fields that users don't modify.
let originalAddress = this.profileStorage.addresses.get(address.guid);
for (let field in address.record) {
if (address.untouchedFields.includes(field) && originalAddress[field]) {
address.record[field] = originalAddress[field];
}
}
@@ -384,9 +382,43 @@ FormAutofillParent.prototype = {
{origin: "autofillDoorhanger"});
});
} else {
// We want to exclude the first time form filling.
Services.telemetry.scalarAdd("formautofill.addresses.fill_type_manual", 1);
}
}
},
+
+ async _onCreditCardSubmit(creditCard, target) {
+ // We'll show the credit card doorhanger if:
+ // - User applys autofill and changed
+ // - User fills form manually
+ if (creditCard.guid &&
+ Object.keys(creditCard.record).every(key => creditCard.untouchedFields.includes(key))) {
+ return;
+ }
+
+ let state = await FormAutofillDoorhanger.show(target, "creditCard");
+ if (state == "cancel") {
+ return;
+ }
+
+ if (state == "disable") {
+ Services.prefs.setBoolPref("extensions.formautofill.creditCards.enabled", false);
+ return;
+ }
+
+ await this.profileStorage.creditCards.normalizeCCNumberFields(creditCard.record);
+ this.profileStorage.creditCards.add(creditCard.record);
+ },
+
+ _onFormSubmit(data, target) {
+ let {address, creditCard} = data;
+
+ if (address) {
+ this._onAddressSubmit(address, target);
+ }
+ if (creditCard) {
+ this._onCreditCardSubmit(creditCard, target);
+ }
+ },
};