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::FindValueInSelectControl(*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::FindValueInSelectControl(const FormFieldData& field, | |
530 const base::string16& value, | |
531 size_t* index) { | |
532 // Try stripping off spaces. | |
Evan Stade
2015/03/25 23:44:15
add link to bug
Lei Zhang
2015/03/26 02:12:36
Done.
| |
533 base::string16 value_stripped; | |
534 base::RemoveChars(base::StringToLowerASCII(value), base::kWhitespaceUTF16, | |
535 &value_stripped); | |
536 for (size_t i = 0; i < field.option_values.size(); ++i) { | |
537 base::string16 option_value_lowercase; | |
538 base::RemoveChars(base::StringToLowerASCII(field.option_values[i]), | |
539 base::kWhitespaceUTF16, &option_value_lowercase); | |
540 base::string16 option_contents_lowercase; | |
541 base::RemoveChars(base::StringToLowerASCII(field.option_contents[i]), | |
542 base::kWhitespaceUTF16, &option_contents_lowercase); | |
543 | |
544 // Perform a case-insensitive comparison. | |
545 if (value_stripped == option_value_lowercase || | |
546 value_stripped == option_contents_lowercase) { | |
547 if (index) | |
548 *index = i; | |
549 return true; | |
550 } | |
551 } | |
552 return false; | |
553 } | |
554 | |
544 } // namespace autofill | 555 } // namespace autofill |
OLD | NEW |