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 0ccf7d90feb92c60ca7d0ad4e271d7536f116b81..677dfde4b9344280d2787f04a402d989486a43cd 100644 |
--- a/components/autofill/core/browser/autofill_manager.cc |
+++ b/components/autofill/core/browser/autofill_manager.cc |
@@ -551,6 +551,33 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
} |
} |
+bool AutofillManager::WillFillCreditCardNumber(const FormData& form, |
+ const FormFieldData& field) { |
+ FormStructure* form_structure = NULL; |
brettw
2015/03/24 22:30:47
I thought we were preferring nullptr for new code.
Evan Stade
2015/03/24 22:34:01
old habits die hard
|
+ AutofillField* autofill_field = NULL; |
+ 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 autofilled, we'll only fill |autofill_field|. |
brettw
2015/03/24 22:30:47
Everything here makes sense to me except these thr
Evan Stade
2015/03/24 22:34:01
your understanding is correct, I'll apply your new
|
+ 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, |
@@ -559,7 +586,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; |