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

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

Issue 381613005: [Autofill] Autofill fails to fill credit card number when split across fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments. Created 6 years, 4 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_field.cc
diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc
index c2a744203af2321856cbc617e84fece0c7a1c114..d61d66f2db3c98398dd24d3908a25c22227050e0 100644
--- a/components/autofill/core/browser/autofill_field.cc
+++ b/components/autofill/core/browser/autofill_field.cc
@@ -298,6 +298,26 @@ void FillPhoneNumberField(const AutofillField& field,
field_data->value = value;
}
+// Set |field_data|'s value to |cc_number|, or possibly an appropriate substring
+// of |cc_number| for cases where credit card number splits across multiple HTML
+// form input fields.
+// The |field| specifies the |credit_card_number_start_index_| to the substring
+// within credit card number.
+void FillCreditCardNumberField(const AutofillField& field,
+ const base::string16& cc_number,
Ilya Sherman 2014/08/12 04:23:41 nit: Please don't use the abbreviation "cc". Inst
Pritam Nikam 2014/08/12 14:00:37 Done.
+ FormFieldData* field_data) {
+ base::string16 value = cc_number;
+
+ // |filed|'s max_length truncates credit card number to fit within.
Ilya Sherman 2014/08/12 04:23:41 nit: "filed" -> "field"
Pritam Nikam 2014/08/12 14:00:37 Done.
+ if (field.credit_card_number_start_index() &&
Ilya Sherman 2014/08/12 04:23:41 There's no need to check whether the start index i
Pritam Nikam 2014/08/12 14:00:37 Done.
+ field.credit_card_number_start_index() < value.length())
+ value =
+ value.substr(field.credit_card_number_start_index(),
+ value.length() - field.credit_card_number_start_index());
Ilya Sherman 2014/08/12 04:23:41 You can shorten this by dropping the second argume
Pritam Nikam 2014/08/12 14:00:37 Done.
+
+ field_data->value = value;
+}
+
// Fills in the select control |field| with |value|. If an exact match is not
// found, falls back to alternate filling strategies based on the |type|.
bool FillSelectControl(const AutofillType& type,
@@ -396,7 +416,8 @@ AutofillField::AutofillField()
heuristic_type_(UNKNOWN_TYPE),
html_type_(HTML_TYPE_UNKNOWN),
html_mode_(HTML_MODE_NONE),
- phone_part_(IGNORED) {
+ phone_part_(IGNORED),
+ credit_card_number_start_index_(0) {
}
AutofillField::AutofillField(const FormFieldData& field,
@@ -407,10 +428,12 @@ AutofillField::AutofillField(const FormFieldData& field,
heuristic_type_(UNKNOWN_TYPE),
html_type_(HTML_TYPE_UNKNOWN),
html_mode_(HTML_MODE_NONE),
- phone_part_(IGNORED) {
+ phone_part_(IGNORED),
+ credit_card_number_start_index_(0) {
}
-AutofillField::~AutofillField() {}
+AutofillField::~AutofillField() {
+}
void AutofillField::set_heuristic_type(ServerFieldType type) {
if (type >= 0 && type < MAX_VALID_FIELD_TYPE &&
@@ -486,6 +509,9 @@ bool AutofillField::FillFormField(const AutofillField& field,
} else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
FillStreetAddress(value, address_language_code, field_data);
return true;
+ } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
+ FillCreditCardNumberField(field, value, field_data);
+ return true;
}
field_data->value = value;

Powered by Google App Engine
This is Rietveld 408576698