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

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: 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
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 // Fills |field| with the state in |value|. Checks for potential field that
419 // expect the state abbreviation by looking at the maxlength attribute of the
420 // |field|.
421 void FillStateText(const base::string16& value, FormFieldData* field) {
422 if (field->max_length != 2) {
vabr (Chromium) 2016/03/16 16:38:45 The "2" here is related to the data used in GetAbb
sebsg 2016/03/16 23:41:01 Good idea, I also added a check to 0 (default valu
vabr (Chromium) 2016/03/17 09:03:37 Acknowledged, both your improvements SGTM.
423 // Fill the state value directly.
424 field->value = value;
425 } else {
426 // Fill with the state abbreviation.
427 base::string16 full, abbreviation;
428 state_names::GetNameAndAbbreviation(value, &full, &abbreviation);
vabr (Chromium) 2016/03/16 16:38:45 &full -> nullptr
sebsg 2016/03/16 23:41:01 Didn't think of that, thanks!
429 field->value = base::i18n::ToUpper(abbreviation);
430 }
431 }
432
417 std::string Hash32Bit(const std::string& str) { 433 std::string Hash32Bit(const std::string& str) {
418 std::string hash_bin = base::SHA1HashString(str); 434 std::string hash_bin = base::SHA1HashString(str);
419 DCHECK_EQ(base::kSHA1Length, hash_bin.length()); 435 DCHECK_EQ(base::kSHA1Length, hash_bin.length());
420 436
421 uint32_t hash32 = ((hash_bin[0] & 0xFF) << 24) | 437 uint32_t hash32 = ((hash_bin[0] & 0xFF) << 24) |
422 ((hash_bin[1] & 0xFF) << 16) | ((hash_bin[2] & 0xFF) << 8) | 438 ((hash_bin[1] & 0xFF) << 16) | ((hash_bin[2] & 0xFF) << 8) |
423 (hash_bin[3] & 0xFF); 439 (hash_bin[3] & 0xFF);
424 440
425 return base::UintToString(hash32); 441 return base::UintToString(hash32);
426 } 442 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } else if (field_data->form_control_type == "select-one") { 575 } else if (field_data->form_control_type == "select-one") {
560 return FillSelectControl(type, value, app_locale, field_data); 576 return FillSelectControl(type, value, app_locale, field_data);
561 } else if (field_data->form_control_type == "month") { 577 } else if (field_data->form_control_type == "month") {
562 return FillMonthControl(value, field_data); 578 return FillMonthControl(value, field_data);
563 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { 579 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
564 FillStreetAddress(value, address_language_code, field_data); 580 FillStreetAddress(value, address_language_code, field_data);
565 return true; 581 return true;
566 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { 582 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
567 FillCreditCardNumberField(field, value, field_data); 583 FillCreditCardNumberField(field, value, field_data);
568 return true; 584 return true;
585 } else if (type.GetStorableType() == ADDRESS_HOME_STATE) {
586 FillStateText(value, field_data);
587 return true;
569 } 588 }
570 589
571 field_data->value = value; 590 field_data->value = value;
572 return true; 591 return true;
573 } 592 }
574 593
575 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for 594 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for
576 // phone numbers with 10 or 11 digits. 595 // phone numbers with 10 or 11 digits.
577 base::string16 AutofillField::GetPhoneNumberValue( 596 base::string16 AutofillField::GetPhoneNumberValue(
578 const AutofillField& field, 597 const AutofillField& field,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 664 }
646 return best_match; 665 return best_match;
647 } 666 }
648 667
649 bool AutofillField::IsCreditCardPrediction() const { 668 bool AutofillField::IsCreditCardPrediction() const {
650 return AutofillType(server_type_).group() == CREDIT_CARD || 669 return AutofillType(server_type_).group() == CREDIT_CARD ||
651 AutofillType(heuristic_type_).group() == CREDIT_CARD; 670 AutofillType(heuristic_type_).group() == CREDIT_CARD;
652 } 671 }
653 672
654 } // namespace autofill 673 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698