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

Side by Side Diff: components/autofill/core/browser/autofill_field.cc

Issue 1811543002: [Autofill] Fill text state fields that have a max length of 2 with the state abbreviation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments and made code more robust Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_field_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/case_conversion.h"
10 #include "base/i18n/string_search.h" 11 #include "base/i18n/string_search.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
13 #include "base/sha1.h" 14 #include "base/sha1.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "components/autofill/core/browser/autofill_country.h" 19 #include "components/autofill/core/browser/autofill_country.h"
19 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 AddressData address_data; 408 AddressData address_data;
408 address_data.language_code = address_language_code; 409 address_data.language_code = address_language_code;
409 address_data.address_line = base::SplitString( 410 address_data.address_line = base::SplitString(
410 base::UTF16ToUTF8(value), "\n", 411 base::UTF16ToUTF8(value), "\n",
411 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 412 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
412 std::string line; 413 std::string line;
413 GetStreetAddressLinesAsSingleLine(address_data, &line); 414 GetStreetAddressLinesAsSingleLine(address_data, &line);
414 field->value = base::UTF8ToUTF16(line); 415 field->value = base::UTF8ToUTF16(line);
415 } 416 }
416 417
418 // Returns whether the |field| was filled with the state in |value| or its
419 // abbreviation. First looks if |value| fits directly in the field, then looks
420 // if the abbreviation of |value| fits. Does not fill if neither |value| or its
421 // abbreviation are too long for the field.
422 bool FillStateText(const base::string16& value, FormFieldData* field) {
423 if (field->max_length == 0 || field->max_length >= value.size()) {
424 // Fill the state value directly.
425 field->value = value;
426 return true;
427 } else {
428 // Fill with the state abbreviation.
429 base::string16 abbreviation;
430 state_names::GetNameAndAbbreviation(value, nullptr, &abbreviation);
431 if (abbreviation.size() != 0 && field->max_length >= abbreviation.size()) {
vabr (Chromium) 2016/03/17 09:03:37 optional nit: "!abbreviation.empty()" instead of "
sebsg 2016/03/17 14:46:08 Done.
432 field->value = base::i18n::ToUpper(abbreviation);
433 return true;
434 }
435 }
436 return false;
437 }
438
417 std::string Hash32Bit(const std::string& str) { 439 std::string Hash32Bit(const std::string& str) {
418 std::string hash_bin = base::SHA1HashString(str); 440 std::string hash_bin = base::SHA1HashString(str);
419 DCHECK_EQ(base::kSHA1Length, hash_bin.length()); 441 DCHECK_EQ(base::kSHA1Length, hash_bin.length());
420 442
421 uint32_t hash32 = ((hash_bin[0] & 0xFF) << 24) | 443 uint32_t hash32 = ((hash_bin[0] & 0xFF) << 24) |
422 ((hash_bin[1] & 0xFF) << 16) | ((hash_bin[2] & 0xFF) << 8) | 444 ((hash_bin[1] & 0xFF) << 16) | ((hash_bin[2] & 0xFF) << 8) |
423 (hash_bin[3] & 0xFF); 445 (hash_bin[3] & 0xFF);
424 446
425 return base::UintToString(hash32); 447 return base::UintToString(hash32);
426 } 448 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } else if (field_data->form_control_type == "select-one") { 581 } else if (field_data->form_control_type == "select-one") {
560 return FillSelectControl(type, value, app_locale, field_data); 582 return FillSelectControl(type, value, app_locale, field_data);
561 } else if (field_data->form_control_type == "month") { 583 } else if (field_data->form_control_type == "month") {
562 return FillMonthControl(value, field_data); 584 return FillMonthControl(value, field_data);
563 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { 585 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
564 FillStreetAddress(value, address_language_code, field_data); 586 FillStreetAddress(value, address_language_code, field_data);
565 return true; 587 return true;
566 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { 588 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
567 FillCreditCardNumberField(field, value, field_data); 589 FillCreditCardNumberField(field, value, field_data);
568 return true; 590 return true;
591 } else if (type.GetStorableType() == ADDRESS_HOME_STATE) {
592 return FillStateText(value, field_data);
569 } 593 }
570 594
571 field_data->value = value; 595 field_data->value = value;
572 return true; 596 return true;
573 } 597 }
574 598
575 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for 599 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for
576 // phone numbers with 10 or 11 digits. 600 // phone numbers with 10 or 11 digits.
577 base::string16 AutofillField::GetPhoneNumberValue( 601 base::string16 AutofillField::GetPhoneNumberValue(
578 const AutofillField& field, 602 const AutofillField& field,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 669 }
646 return best_match; 670 return best_match;
647 } 671 }
648 672
649 bool AutofillField::IsCreditCardPrediction() const { 673 bool AutofillField::IsCreditCardPrediction() const {
650 return AutofillType(server_type_).group() == CREDIT_CARD || 674 return AutofillType(server_type_).group() == CREDIT_CARD ||
651 AutofillType(heuristic_type_).group() == CREDIT_CARD; 675 AutofillType(heuristic_type_).group() == CREDIT_CARD;
652 } 676 }
653 677
654 } // namespace autofill 678 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698