Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Unified Diff: components/autofill/core/browser/autofill_manager.cc

Issue 1029233002: Autofill - don't prompt to unmask a credit card if the number isn't needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolve histograms conflict Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autofill_manager.cc
diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc
index 099cc6361ecabca5085d76efe5bcbf3491db47b1..a316f6ef891e33c21ef1cccabe6c9ea383cefdbd 100644
--- a/components/autofill/core/browser/autofill_manager.cc
+++ b/components/autofill/core/browser/autofill_manager.cc
@@ -554,6 +554,34 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id,
}
}
+bool AutofillManager::WillFillCreditCardNumber(const FormData& form,
+ const FormFieldData& field) {
+ FormStructure* form_structure = nullptr;
+ AutofillField* autofill_field = nullptr;
+ if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field))
+ return false;
+
+ if (autofill_field->Type().GetStorableType() == CREDIT_CARD_NUMBER)
+ return true;
+
+ // If the relevant section is already autofilled, the new fill operation will
+ // only fill |autofill_field|.
+ if (SectionIsAutofilled(*form_structure, form, autofill_field->section()))
+ return false;
+
+ DCHECK_EQ(form_structure->field_count(), form.fields.size());
+ for (size_t i = 0; i < form_structure->field_count(); ++i) {
+ if (form_structure->field(i)->section() == autofill_field->section() &&
+ form_structure->field(i)->Type().GetStorableType() ==
+ CREDIT_CARD_NUMBER &&
+ form.fields[i].value.empty()) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
void AutofillManager::FillOrPreviewCreditCardForm(
AutofillDriver::RendererFormDataAction action,
int query_id,
@@ -562,7 +590,8 @@ void AutofillManager::FillOrPreviewCreditCardForm(
const CreditCard& credit_card,
size_t variant) {
if (action == AutofillDriver::FORM_DATA_ACTION_FILL) {
- if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) {
+ if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD &&
+ WillFillCreditCardNumber(form, field)) {
unmasking_card_ = credit_card;
unmasking_query_id_ = query_id;
unmasking_form_ = form;
« no previous file with comments | « components/autofill/core/browser/autofill_manager.h ('k') | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698