diff --git a/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc b/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc index 5db1d3d289f54..90db85407ddeb 100644 --- a/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc +++ b/chrome/browser/ui/android/autofill/autofill_dialog_controller_android.cc @@ -115,14 +115,10 @@ void FillOutputForSectionWithComparator( g_browser_process->GetApplicationLocale()); std::vector types = common::TypesFromInputs(inputs); - form_structure.FillFields( - types, - compare, - get_info, - section == SECTION_CC_BILLING - ? full_wallet->billing_address()->language_code() - : full_wallet->shipping_address()->language_code(), - g_browser_process->GetApplicationLocale()); + form_structure.FillFields(types, + compare, + get_info, + g_browser_process->GetApplicationLocale()); } void FillOutputForSection( @@ -349,7 +345,6 @@ void AutofillDialogControllerAndroid::Show() { common::TypesFromInputs(inputs), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(NullGetInfo), - std::string(), g_browser_process->GetApplicationLocale()); } diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index 86570836f18b2..f235881990ab9 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -839,7 +839,6 @@ void AutofillDialogControllerImpl::Show() { RequestedTypesForSection(SECTION_SHIPPING), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(NullGetInfo), - std::string(), g_browser_process->GetApplicationLocale()); transaction_amount_ = form_structure_.GetUniqueValue( diff --git a/chrome/browser/ui/autofill/data_model_wrapper.cc b/chrome/browser/ui/autofill/data_model_wrapper.cc index ebb79a2a6f066..00cbbfa09093e 100644 --- a/chrome/browser/ui/autofill/data_model_wrapper.cc +++ b/chrome/browser/ui/autofill/data_model_wrapper.cc @@ -91,7 +91,6 @@ bool DataModelWrapper::FillFormStructure( types, compare, base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), - GetLanguageCode(), g_browser_process->GetApplicationLocale()); } diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc index c2a744203af23..3fec668f3c76a 100644 --- a/components/autofill/core/browser/autofill_field.cc +++ b/components/autofill/core/browser/autofill_field.cc @@ -15,12 +15,8 @@ #include "components/autofill/core/browser/phone_number.h" #include "components/autofill/core/browser/state_names.h" #include "grit/components_strings.h" -#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h" -#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h" #include "ui/base/l10n/l10n_util.h" -using ::i18n::addressinput::AddressData; -using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; using base::ASCIIToUTF16; using base::StringToInt; @@ -358,23 +354,18 @@ bool FillMonthControl(const base::string16& value, FormFieldData* field) { return true; } -// Fills |field| with the street address in |value|. Translates newlines into +// Fills |field| with the street address in |value|. Translates newlines into // equivalent separators when necessary, i.e. when filling a single-line field. -// The separators depend on |address_language_code|. void FillStreetAddress(const base::string16& value, - const std::string& address_language_code, FormFieldData* field) { if (field->form_control_type == "textarea") { field->value = value; return; } - AddressData address_data; - address_data.language_code = address_language_code; - base::SplitString(base::UTF16ToUTF8(value), '\n', &address_data.address_line); - std::string line; - GetStreetAddressLinesAsSingleLine(address_data, &line); - field->value = base::UTF8ToUTF16(line); + const base::string16& separator = + l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_SEPARATOR); + base::ReplaceChars(value, base::ASCIIToUTF16("\n"), separator, &field->value); } std::string Hash32Bit(const std::string& str) { @@ -471,7 +462,6 @@ bool AutofillField::IsFieldFillable() const { // static bool AutofillField::FillFormField(const AutofillField& field, const base::string16& value, - const std::string& address_language_code, const std::string& app_locale, FormFieldData* field_data) { AutofillType type = field.Type(); @@ -484,7 +474,7 @@ bool AutofillField::FillFormField(const AutofillField& field, } else if (field_data->form_control_type == "month") { return FillMonthControl(value, field_data); } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { - FillStreetAddress(value, address_language_code, field_data); + FillStreetAddress(value, field_data); return true; } diff --git a/components/autofill/core/browser/autofill_field.h b/components/autofill/core/browser/autofill_field.h index b810e76010cef..f0b1e7ef2b35e 100644 --- a/components/autofill/core/browser/autofill_field.h +++ b/components/autofill/core/browser/autofill_field.h @@ -65,13 +65,11 @@ class AutofillField : public FormFieldData { void set_default_value(const std::string& value) { default_value_ = value; } const std::string& default_value() const { return default_value_; } - // Set |field_data|'s value to |value|. Uses |field|, |address_language_code|, - // and |app_locale| as hints when filling exceptional cases like phone number - // values and + // fields. Returns |true| if the field has been filled, |false| otherwise. static bool FillFormField(const AutofillField& field, const base::string16& value, - const std::string& address_language_code, const std::string& app_locale, FormFieldData* field_data); diff --git a/components/autofill/core/browser/autofill_field_unittest.cc b/components/autofill/core/browser/autofill_field_unittest.cc index 9d0f3ac3ae77f..b7451d23f1bac 100644 --- a/components/autofill/core/browser/autofill_field_unittest.cc +++ b/components/autofill/core/browser/autofill_field_unittest.cc @@ -2,18 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/autofill/core/browser/autofill_field.h" - #include "base/format_macros.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" +#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/field_types.h" #include "testing/gtest/include/gtest/gtest.h" using base::ASCIIToUTF16; -using base::UTF8ToUTF16; namespace autofill { namespace { @@ -126,13 +124,11 @@ TEST(AutofillFieldTest, FillPhoneNumber) { field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); // Fill with a non-phone number; should fill normally. - AutofillField::FillFormField( - field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Oh hai"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value); // Fill with a phone number; should fill just the prefix. - AutofillField::FillFormField( - field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("5551234"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("555"), field.value); // Now reset the type, and set a max-length instead. @@ -141,8 +137,7 @@ TEST(AutofillFieldTest, FillPhoneNumber) { field.max_length = 4; // Fill with a phone-number; should fill just the suffix. - AutofillField::FillFormField( - field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("5551234"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("1234"), field.value); } @@ -160,8 +155,8 @@ TEST(AutofillFieldTest, FillSelectControlByValue) { field.option_contents[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i)); } - AutofillField::FillFormField( - field, ASCIIToUTF16("Meenie"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Meenie"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("Meenie"), field.value); } @@ -179,8 +174,8 @@ TEST(AutofillFieldTest, FillSelectControlByContents) { field.option_values[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i)); } - AutofillField::FillFormField( - field, ASCIIToUTF16("Miney"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Miney"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("2"), field.value); // Corresponds to "Miney". } @@ -193,8 +188,7 @@ TEST(AutofillFieldTest, FillSelectControlWithFullCountryNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_COUNTRY); - AutofillField::FillFormField( - field, ASCIIToUTF16("CA"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); } @@ -207,8 +201,7 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedCountryNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_COUNTRY); - AutofillField::FillFormField( - field, ASCIIToUTF16("Canada"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Canada"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("CA"), field.value); } @@ -221,8 +214,7 @@ TEST(AutofillFieldTest, FillSelectControlWithFullStateNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("CA"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("California"), field.value); } @@ -235,8 +227,8 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviateStateNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("California"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("CA"), field.value); } @@ -250,8 +242,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("California"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value); } @@ -265,8 +257,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Virginia"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("VA - Virginia"), field.value); } @@ -282,8 +274,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Virginia"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("WV - West Virginia"), field.value); } @@ -299,8 +291,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("North Carolina"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("North Carolina"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("North Carolina."), field.value); } } @@ -315,8 +307,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("CA"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value); } @@ -329,8 +321,8 @@ TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) { base::string16()); field.set_heuristic_type(ADDRESS_HOME_STATE); - AutofillField::FillFormField( - field, ASCIIToUTF16("NC"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("NC"), "en-US", + &field); EXPECT_EQ(base::string16(), field.value); } } @@ -345,18 +337,15 @@ TEST(AutofillFieldTest, FillSelectControlWithNumericMonth) { field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); // Try with a leading zero. - AutofillField::FillFormField( - field, ASCIIToUTF16("03"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("03"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("03"), field.value); // Try without a leading zero. - AutofillField::FillFormField( - field, ASCIIToUTF16("4"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("4"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("04"), field.value); // Try a two-digit month. - AutofillField::FillFormField( - field, ASCIIToUTF16("11"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("11"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("11"), field.value); } @@ -371,14 +360,13 @@ TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedMonthName) { base::string16()); field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); - AutofillField::FillFormField( - field, ASCIIToUTF16("04"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("04"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("Apr"), field.value); } TEST(AutofillFieldTest, FillSelectControlWithFullMonthName) { const char* const kMonthsFull[] = { - "January","February", "March", "April", "May", "June", + "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", }; AutofillField field( @@ -386,8 +374,7 @@ TEST(AutofillFieldTest, FillSelectControlWithFullMonthName) { base::string16()); field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); - AutofillField::FillFormField( - field, ASCIIToUTF16("04"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("04"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("April"), field.value); } @@ -400,8 +387,7 @@ TEST(AutofillFieldTest, FillSelectControlWithNumericMonthSansLeadingZero) { base::string16()); field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); - AutofillField::FillFormField( - field, ASCIIToUTF16("04"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("04"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("4"), field.value); } @@ -413,8 +399,7 @@ TEST(AutofillFieldTest, FillSelectControlWithTwoDigitCreditCardYear) { base::string16()); field.set_heuristic_type(CREDIT_CARD_EXP_2_DIGIT_YEAR); - AutofillField::FillFormField( - field, ASCIIToUTF16("2017"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("2017"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("17"), field.value); } @@ -429,23 +414,22 @@ TEST(AutofillFieldTest, FillSelectControlWithCreditCardType) { field.set_heuristic_type(CREDIT_CARD_TYPE); // Normal case: - AutofillField::FillFormField( - field, ASCIIToUTF16("Visa"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Visa"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("Visa"), field.value); // Filling should be able to handle intervening whitespace: - AutofillField::FillFormField( - field, ASCIIToUTF16("MasterCard"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("MasterCard"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("Master Card"), field.value); // American Express is sometimes abbreviated as AmEx: - AutofillField::FillFormField( - field, ASCIIToUTF16("American Express"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("American Express"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("AmEx"), field.value); // Case insensitivity: - AutofillField::FillFormField( - field, ASCIIToUTF16("Discover"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("Discover"), "en-US", + &field); EXPECT_EQ(ASCIIToUTF16("discover"), field.value); } @@ -454,18 +438,15 @@ TEST(AutofillFieldTest, FillMonthControl) { field.form_control_type = "month"; // Try a month with two digits. - AutofillField::FillFormField( - field, ASCIIToUTF16("12/2017"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("12/2017"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("2017-12"), field.value); // Try a month with a leading zero. - AutofillField::FillFormField( - field, ASCIIToUTF16("03/2019"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("03/2019"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("2019-03"), field.value); // Try a month without a leading zero. - AutofillField::FillFormField( - field, ASCIIToUTF16("4/2018"), "en-US", "en-US", &field); + AutofillField::FillFormField(field, ASCIIToUTF16("4/2018"), "en-US", &field); EXPECT_EQ(ASCIIToUTF16("2018-04"), field.value); } @@ -475,13 +456,8 @@ TEST(AutofillFieldTest, FillStreetAddressTextArea) { base::string16 value = ASCIIToUTF16("123 Fake St.\n" "Apt. 42"); - AutofillField::FillFormField(field, value, "en-US", "en-US", &field); + AutofillField::FillFormField(field, value, "en-US", &field); EXPECT_EQ(value, field.value); - - base::string16 ja_value = UTF8ToUTF16("桜丘町26-1\n" - "セルリアンタワー6階"); - AutofillField::FillFormField(field, ja_value, "ja-JP", "en-US", &field); - EXPECT_EQ(ja_value, field.value); } TEST(AutofillFieldTest, FillStreetAddressTextField) { @@ -491,16 +467,8 @@ TEST(AutofillFieldTest, FillStreetAddressTextField) { base::string16 value = ASCIIToUTF16("123 Fake St.\n" "Apt. 42"); - AutofillField::FillFormField(field, value, "en-US", "en-US", &field); + AutofillField::FillFormField(field, value, "en-US", &field); EXPECT_EQ(ASCIIToUTF16("123 Fake St., Apt. 42"), field.value); - - AutofillField::FillFormField(field, - UTF8ToUTF16("桜丘町26-1\n" - "セルリアンタワー6階"), - "ja-JP", - "en-US", - &field); - EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value); } } // namespace diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc index 77fc9463a03c6..cb4be9320a3c4 100644 --- a/components/autofill/core/browser/autofill_manager.cc +++ b/components/autofill/core/browser/autofill_manager.cc @@ -550,12 +550,9 @@ void AutofillManager::FillOrPreviewForm( FormData result = form; base::string16 profile_full_name; - std::string profile_language_code; if (!is_credit_card) { profile_full_name = data_model->GetInfo( AutofillType(NAME_FULL), app_locale_); - profile_language_code = - static_cast(data_model)->language_code(); } // If the relevant section is auto-filled, we should fill |field| but not the @@ -566,11 +563,8 @@ void AutofillManager::FillOrPreviewForm( if ((*iter) == field) { base::string16 value = data_model->GetInfoForVariant( autofill_field->Type(), variant, app_locale_); - if (AutofillField::FillFormField(*autofill_field, - value, - profile_language_code, - app_locale_, - &(*iter))) { + if (AutofillField::FillFormField( + *autofill_field, value, app_locale_, &(*iter))) { // Mark the cached field as autofilled, so that we can detect when a // user edits an autofilled field (for metrics). autofill_field->is_autofilled = true; @@ -626,11 +620,8 @@ void AutofillManager::FillOrPreviewForm( (result.fields[i] == field || result.fields[i].form_control_type == "select-one" || result.fields[i].value.empty()); - if (AutofillField::FillFormField(*cached_field, - value, - profile_language_code, - app_locale_, - &result.fields[i])) { + if (AutofillField::FillFormField( + *cached_field, value, app_locale_, &result.fields[i])) { // Mark the cached field as autofilled, so that we can detect when a // user edits an autofilled field (for metrics). form_structure->field(i)->is_autofilled = true; diff --git a/components/autofill/core/browser/form_structure.cc b/components/autofill/core/browser/form_structure.cc index f31fbc6874d7d..a01d91547bcf8 100644 --- a/components/autofill/core/browser/form_structure.cc +++ b/components/autofill/core/browser/form_structure.cc @@ -1107,7 +1107,6 @@ bool FormStructure::FillFields( const std::vector& types, const InputFieldComparator& matches, const base::Callback& get_info, - const std::string& address_language_code, const std::string& app_locale) { bool filled_something = false; for (size_t i = 0; i < field_count(); ++i) { @@ -1115,7 +1114,6 @@ bool FormStructure::FillFields( if (matches.Run(types[j], *field(i))) { AutofillField::FillFormField(*field(i), get_info.Run(field(i)->Type()), - address_language_code, app_locale, field(i)); filled_something = true; diff --git a/components/autofill/core/browser/form_structure.h b/components/autofill/core/browser/form_structure.h index cead91f3b6153..7a9d915782a98 100644 --- a/components/autofill/core/browser/form_structure.h +++ b/components/autofill/core/browser/form_structure.h @@ -137,13 +137,11 @@ class FormStructure { InputFieldComparator; // Fills in |fields_| that match |types| (via |matches|) with info from - // |get_info|. Uses |address_language_code| to determine line separators when - // collapsing street address lines into a single-line input text field. + // |get_info|. bool FillFields( const std::vector& types, const InputFieldComparator& matches, const base::Callback& get_info, - const std::string& address_language_code, const std::string& app_locale); // Returns the values that can be filled into the form structure for the