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" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 return false; | 244 return false; |
245 } | 245 } |
246 | 246 |
247 // Try to fill a credit card type |value| (Visa, MasterCard, etc.) into the | 247 // Try to fill a credit card type |value| (Visa, MasterCard, etc.) into the |
248 // given |field|. | 248 // given |field|. |
249 bool FillCreditCardTypeSelectControl(const base::string16& value, | 249 bool FillCreditCardTypeSelectControl(const base::string16& value, |
250 FormFieldData* field) { | 250 FormFieldData* field) { |
251 // Try stripping off spaces. | 251 size_t idx; |
252 base::string16 value_stripped; | 252 if (AutofillField::FindValueInCreditTypeSelectControl(*field, value, &idx)) { |
253 base::RemoveChars(base::StringToLowerASCII(value), base::kWhitespaceUTF16, | 253 field->value = field->option_values[idx]; |
254 &value_stripped); | 254 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 } | 255 } |
272 | 256 |
273 // For American Express, also try filling as "AmEx". | 257 // For American Express, also try filling as "AmEx". |
274 if (value == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX)) | 258 if (value == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX)) |
275 return FillCreditCardTypeSelectControl(ASCIIToUTF16("AmEx"), field); | 259 return FillCreditCardTypeSelectControl(ASCIIToUTF16("AmEx"), field); |
276 | 260 |
277 return false; | 261 return false; |
278 } | 262 } |
279 | 263 |
280 // Set |field_data|'s value to |number|, or possibly an appropriate substring of | 264 // 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 | 518 |
535 if (field.phone_part() == AutofillField::PHONE_SUFFIX || | 519 if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
536 field_data.max_length == PhoneNumber::kSuffixLength) { | 520 field_data.max_length == PhoneNumber::kSuffixLength) { |
537 return | 521 return |
538 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); | 522 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); |
539 } | 523 } |
540 | 524 |
541 return number; | 525 return number; |
542 } | 526 } |
543 | 527 |
528 // static | |
529 bool AutofillField::FindValueInCreditTypeSelectControl( | |
Evan Stade
2015/03/25 21:25:51
nothing about this looks credit card specific (?)
Lei Zhang
2015/03/25 22:18:48
Done.
| |
530 const FormFieldData& field, | |
531 const base::string16& value, | |
532 size_t* index) { | |
533 // Try stripping off spaces. | |
534 base::string16 value_stripped; | |
535 base::RemoveChars(base::StringToLowerASCII(value), base::kWhitespaceUTF16, | |
536 &value_stripped); | |
537 for (size_t i = 0; i < field.option_values.size(); ++i) { | |
538 base::string16 option_value_lowercase; | |
539 base::RemoveChars(base::StringToLowerASCII(field.option_values[i]), | |
540 base::kWhitespaceUTF16, &option_value_lowercase); | |
541 base::string16 option_contents_lowercase; | |
542 base::RemoveChars(base::StringToLowerASCII(field.option_contents[i]), | |
Evan Stade
2015/03/25 21:25:51
I don't think assuming this is ASCII and failing o
Lei Zhang
2015/03/25 22:18:48
base::StringToLowerASCII() doesn't fail if it enco
Evan Stade
2015/03/25 22:23:08
my point is that upper case accented character won
Lei Zhang
2015/03/25 22:39:03
Sure, that's a valid point, but I just want to mov
Evan Stade
2015/03/25 22:39:53
seems like it would only take about 5 minutes of e
| |
543 base::kWhitespaceUTF16, &option_contents_lowercase); | |
544 | |
545 // Perform a case-insensitive comparison. | |
546 if (value_stripped == option_value_lowercase || | |
547 value_stripped == option_contents_lowercase) { | |
548 if (index) | |
549 *index = i; | |
550 return true; | |
551 } | |
552 } | |
553 return false; | |
554 } | |
555 | |
544 } // namespace autofill | 556 } // namespace autofill |
OLD | NEW |