Chromium Code Reviews| 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/i18n/string_search.h" | 8 #include "base/i18n/string_search.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // Like SetSelectControlValue, but searches within the field values and options | 95 // Like SetSelectControlValue, but searches within the field values and options |
| 96 // for |value|. First it tokenizes the options, then tries to match against | 96 // for |value|. First it tokenizes the options, then tries to match against |
| 97 // tokens. For example, "NC - North Carolina" would match "nc" but not "ca". | 97 // tokens. For example, "NC - North Carolina" would match "nc" but not "ca". |
| 98 bool SetSelectControlValueTokenMatch(const base::string16& value, | 98 bool SetSelectControlValueTokenMatch(const base::string16& value, |
| 99 FormFieldData* field) { | 99 FormFieldData* field) { |
| 100 std::vector<base::string16> tokenized; | 100 std::vector<base::string16> tokenized; |
| 101 DCHECK_EQ(field->option_values.size(), field->option_contents.size()); | 101 DCHECK_EQ(field->option_values.size(), field->option_contents.size()); |
| 102 l10n::CaseInsensitiveCompare compare; | 102 l10n::CaseInsensitiveCompare compare; |
| 103 | 103 |
| 104 for (size_t i = 0; i < field->option_values.size(); ++i) { | 104 for (size_t i = 0; i < field->option_values.size(); ++i) { |
| 105 base::SplitStringAlongWhitespace(field->option_values[i], &tokenized); | 105 tokenized = base::SplitString( |
| 106 field->option_values[i], base::kWhitespaceASCIIAs16, | |
| 107 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
| 106 if (std::find_if(tokenized.begin(), tokenized.end(), | 108 if (std::find_if(tokenized.begin(), tokenized.end(), |
| 107 [&compare, value](base::string16& rhs) { | 109 [&compare, value](base::string16& rhs) { |
| 108 return compare.StringsEqual(value, rhs); | 110 return compare.StringsEqual(value, rhs); |
| 109 }) != tokenized.end()) { | 111 }) != tokenized.end()) { |
| 110 field->value = field->option_values[i]; | 112 field->value = field->option_values[i]; |
| 111 return true; | 113 return true; |
| 112 } | 114 } |
| 113 | 115 |
| 114 base::SplitStringAlongWhitespace(field->option_contents[i], &tokenized); | 116 tokenized = base::SplitString( |
| 117 field->option_contents[i], base::kWhitespaceASCIIAs16, | |
| 118 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
| 115 if (std::find_if(tokenized.begin(), tokenized.end(), | 119 if (std::find_if(tokenized.begin(), tokenized.end(), |
| 116 [&compare, value](base::string16& rhs) { | 120 [&compare, value](base::string16& rhs) { |
| 117 return compare.StringsEqual(value, rhs); | 121 return compare.StringsEqual(value, rhs); |
| 118 }) != tokenized.end()) { | 122 }) != tokenized.end()) { |
| 119 field->value = field->option_values[i]; | 123 field->value = field->option_values[i]; |
| 120 return true; | 124 return true; |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 | 127 |
| 124 return false; | 128 return false; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 return FillCreditCardTypeSelectControl(value, field); | 330 return FillCreditCardTypeSelectControl(value, field); |
| 327 } | 331 } |
| 328 | 332 |
| 329 return false; | 333 return false; |
| 330 } | 334 } |
| 331 | 335 |
| 332 // Fills in the month control |field| with |value|. |value| should be a date | 336 // Fills in the month control |field| with |value|. |value| should be a date |
| 333 // formatted as MM/YYYY. If it isn't, filling will fail. | 337 // formatted as MM/YYYY. If it isn't, filling will fail. |
| 334 bool FillMonthControl(const base::string16& value, FormFieldData* field) { | 338 bool FillMonthControl(const base::string16& value, FormFieldData* field) { |
| 335 // Autofill formats a combined date as month/year. | 339 // Autofill formats a combined date as month/year. |
| 336 std::vector<base::string16> pieces; | 340 std::vector<base::string16> pieces = base::SplitString( |
| 337 base::SplitString(value, base::char16('/'), &pieces); | 341 value, base::ASCIIToUTF16("/"), |
| 342 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
|
yzshen1
2015/07/22 22:38:23
TRIM_WHITESPACE
| |
| 338 if (pieces.size() != 2) | 343 if (pieces.size() != 2) |
| 339 return false; | 344 return false; |
| 340 | 345 |
| 341 // HTML5 input="month" is formatted as year-month. | 346 // HTML5 input="month" is formatted as year-month. |
| 342 base::string16 month = pieces[0]; | 347 base::string16 month = pieces[0]; |
| 343 base::string16 year = pieces[1]; | 348 base::string16 year = pieces[1]; |
| 344 if ((month.size() != 1 && month.size() != 2) || year.size() != 4) | 349 if ((month.size() != 1 && month.size() != 2) || year.size() != 4) |
| 345 return false; | 350 return false; |
| 346 | 351 |
| 347 // HTML5 input="month" expects zero-padded months. | 352 // HTML5 input="month" expects zero-padded months. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 358 void FillStreetAddress(const base::string16& value, | 363 void FillStreetAddress(const base::string16& value, |
| 359 const std::string& address_language_code, | 364 const std::string& address_language_code, |
| 360 FormFieldData* field) { | 365 FormFieldData* field) { |
| 361 if (field->form_control_type == "textarea") { | 366 if (field->form_control_type == "textarea") { |
| 362 field->value = value; | 367 field->value = value; |
| 363 return; | 368 return; |
| 364 } | 369 } |
| 365 | 370 |
| 366 AddressData address_data; | 371 AddressData address_data; |
| 367 address_data.language_code = address_language_code; | 372 address_data.language_code = address_language_code; |
| 368 base::SplitString(base::UTF16ToUTF8(value), '\n', &address_data.address_line); | 373 address_data.address_line = base::SplitString( |
| 374 base::UTF16ToUTF8(value), "\n", | |
| 375 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
|
yzshen1
2015/07/22 22:38:23
TRIM_WHITESPACE
| |
| 369 std::string line; | 376 std::string line; |
| 370 GetStreetAddressLinesAsSingleLine(address_data, &line); | 377 GetStreetAddressLinesAsSingleLine(address_data, &line); |
| 371 field->value = base::UTF8ToUTF16(line); | 378 field->value = base::UTF8ToUTF16(line); |
| 372 } | 379 } |
| 373 | 380 |
| 374 std::string Hash32Bit(const std::string& str) { | 381 std::string Hash32Bit(const std::string& str) { |
| 375 std::string hash_bin = base::SHA1HashString(str); | 382 std::string hash_bin = base::SHA1HashString(str); |
| 376 DCHECK_EQ(base::kSHA1Length, hash_bin.length()); | 383 DCHECK_EQ(base::kSHA1Length, hash_bin.length()); |
| 377 | 384 |
| 378 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | | 385 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 if (compare.StringsEqual(value_stripped, option_contents)) { | 563 if (compare.StringsEqual(value_stripped, option_contents)) { |
| 557 if (index) | 564 if (index) |
| 558 *index = i; | 565 *index = i; |
| 559 return true; | 566 return true; |
| 560 } | 567 } |
| 561 } | 568 } |
| 562 return false; | 569 return false; |
| 563 } | 570 } |
| 564 | 571 |
| 565 } // namespace autofill | 572 } // namespace autofill |
| OLD | NEW |