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

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

Issue 1639563002: [Autofill] Fill from the last digits when filling a phone number with a maximum length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 11 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 e9eaa73638de8f9ab1a94c4e655dcb9ffe32bfa2..754ec0175be74bfcf416f6c51d84048fdc0f2eaf 100644
--- a/components/autofill/core/browser/autofill_field.cc
+++ b/components/autofill/core/browser/autofill_field.cc
@@ -544,7 +544,7 @@ bool AutofillField::FillFormField(const AutofillField& field,
return false;
}
- if (type.GetStorableType() == PHONE_HOME_NUMBER) {
+ if (type.group() == PHONE_HOME) {
FillPhoneNumberField(field, value, field_data);
return true;
} else if (field_data->form_control_type == "select-one") {
@@ -563,27 +563,42 @@ bool AutofillField::FillFormField(const AutofillField& field,
return true;
}
+// TODO(crbug.com/581514): Add support for filling only the prefix/suffix for
+// phone numbers with 10 or 11 digits.
base::string16 AutofillField::GetPhoneNumberValue(
const AutofillField& field,
const base::string16& number,
const FormFieldData& field_data) {
- // Check to see if the size field matches the "prefix" or "suffix" size.
- // If so, return the appropriate substring.
- if (number.length() !=
- PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) {
- return number;
- }
+ // TODO(crbug.com/581485): Investigate the use of libphonenumber here.
+ // Check to see if the |field| size matches the "prefix" or "suffix" size or
+ // if
+ // the field was labeled as such. If so, return the appropriate substring.
+ if (number.length() ==
+ PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) {
+ if (field.phone_part() == AutofillField::PHONE_PREFIX ||
+ field_data.max_length == PhoneNumber::kPrefixLength) {
+ return number.substr(PhoneNumber::kPrefixOffset,
+ PhoneNumber::kPrefixLength);
+ }
- if (field.phone_part() == AutofillField::PHONE_PREFIX ||
- field_data.max_length == PhoneNumber::kPrefixLength) {
- return
- number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength);
+ if (field.phone_part() == AutofillField::PHONE_SUFFIX ||
+ field_data.max_length == PhoneNumber::kSuffixLength) {
+ return number.substr(PhoneNumber::kSuffixOffset,
+ PhoneNumber::kSuffixLength);
+ }
}
- if (field.phone_part() == AutofillField::PHONE_SUFFIX ||
- field_data.max_length == PhoneNumber::kSuffixLength) {
- return
- number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength);
+ // If no max length was specified, return the complete number.
+ if (field_data.max_length == 0)
+ return number;
+
+ // If |number| exceeds the maximum size of the field, cut the first part to
+ // provide a valid number for the field. For example, the number 15142365264
+ // with a field with a max length of 10 would return 5142365264, thus removing
+ // the country code and remaining valid.
+ if (number.length() > field_data.max_length) {
+ return number.substr(number.length() - field_data.max_length,
+ field_data.max_length);
}
return number;
« no previous file with comments | « components/autofill/core/browser/autofill_field.h ('k') | components/autofill/core/browser/autofill_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698