OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/autofill_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/autofill/core/browser/autofill_country.h" | 15 #include "components/autofill/core/browser/autofill_country.h" |
| 16 #include "components/autofill/core/browser/autofill_regexes.h" |
16 #include "components/autofill/core/browser/autofill_type.h" | 17 #include "components/autofill/core/browser/autofill_type.h" |
17 #include "components/autofill/core/browser/phone_number.h" | 18 #include "components/autofill/core/browser/phone_number.h" |
18 #include "components/autofill/core/browser/state_names.h" | 19 #include "components/autofill/core/browser/state_names.h" |
19 #include "components/autofill/core/common/autofill_switches.h" | 20 #include "components/autofill/core/common/autofill_switches.h" |
20 #include "grit/components_strings.h" | 21 #include "grit/components_strings.h" |
21 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da
ta.h" | 22 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da
ta.h" |
22 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo
rmatter.h" | 23 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo
rmatter.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
24 | 25 |
25 using ::i18n::addressinput::AddressData; | 26 using ::i18n::addressinput::AddressData; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 242 } |
242 } | 243 } |
243 | 244 |
244 return false; | 245 return false; |
245 } | 246 } |
246 | 247 |
247 // Try to fill a credit card type |value| (Visa, MasterCard, etc.) into the | 248 // Try to fill a credit card type |value| (Visa, MasterCard, etc.) into the |
248 // given |field|. | 249 // given |field|. |
249 bool FillCreditCardTypeSelectControl(const base::string16& value, | 250 bool FillCreditCardTypeSelectControl(const base::string16& value, |
250 FormFieldData* field) { | 251 FormFieldData* field) { |
251 // Try stripping off spaces. | 252 size_t idx; |
252 base::string16 value_stripped; | 253 if (AutofillField::FindValueInCreditTypeSelectControl(*field, value, &idx)) { |
253 base::RemoveChars(base::StringToLowerASCII(value), base::kWhitespaceUTF16, | 254 field->value = field->option_values[idx]; |
254 &value_stripped); | 255 return true; |
255 | |
256 for (size_t i = 0; i < field->option_values.size(); ++i) { | |
257 base::string16 option_value_lowercase; | |
258 base::RemoveChars(base::StringToLowerASCII(field->option_values[i]), | |
259 base::kWhitespaceUTF16, &option_value_lowercase); | |
260 base::string16 option_contents_lowercase; | |
261 base::RemoveChars(base::StringToLowerASCII(field->option_contents[i]), | |
262 base::kWhitespaceUTF16, &option_contents_lowercase); | |
263 | |
264 // Perform a case-insensitive comparison; but fill the form with the | |
265 // original text, not the lowercased version. | |
266 if (value_stripped == option_value_lowercase || | |
267 value_stripped == option_contents_lowercase) { | |
268 field->value = field->option_values[i]; | |
269 return true; | |
270 } | |
271 } | 256 } |
272 | 257 |
273 // For American Express, also try filling as "AmEx". | 258 // For American Express, also try filling as "AmEx". |
274 if (value == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX)) | 259 if (value == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX)) |
275 return FillCreditCardTypeSelectControl(ASCIIToUTF16("AmEx"), field); | 260 return FillCreditCardTypeSelectControl(ASCIIToUTF16("AmEx"), field); |
276 | 261 |
277 return false; | 262 return false; |
278 } | 263 } |
279 | 264 |
280 // Set |field_data|'s value to |number|, or possibly an appropriate substring of | 265 // Set |field_data|'s value to |number|, or possibly an appropriate substring of |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 519 |
535 if (field.phone_part() == AutofillField::PHONE_SUFFIX || | 520 if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
536 field_data.max_length == PhoneNumber::kSuffixLength) { | 521 field_data.max_length == PhoneNumber::kSuffixLength) { |
537 return | 522 return |
538 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); | 523 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); |
539 } | 524 } |
540 | 525 |
541 return number; | 526 return number; |
542 } | 527 } |
543 | 528 |
| 529 // static |
| 530 bool AutofillField::FindValueInCreditTypeSelectControl( |
| 531 const FormFieldData& field, |
| 532 const base::string16& regex, |
| 533 size_t* index) { |
| 534 for (size_t i = 0; i < field.option_values.size(); ++i) { |
| 535 if (MatchesPattern(field.option_values[i], regex) || |
| 536 MatchesPattern(field.option_contents[i], regex)) { |
| 537 if (index) |
| 538 *index = i; |
| 539 return true; |
| 540 } |
| 541 } |
| 542 return false; |
| 543 } |
| 544 |
544 } // namespace autofill | 545 } // namespace autofill |
OLD | NEW |