Commit 167fb404 authored by rouslan@chromium.org's avatar rouslan@chromium.org

Reland "Use language-specific street address line separators."

This patch fixes a past-the-end iterator and relands
https://crrev.com/284335, which was reverted in
https://crrev.com/284340.

TBR=estade@chromium.org,aruslan@chromium.org
BUG=270261

Review URL: https://codereview.chromium.org/403923003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284354 0039d316-1c4b-4281-b951-d872f2087c98
parent f278a931
......@@ -40,7 +40,7 @@ vars = {
# to update other nacl_*_revision's.
"nacl_tools_revision": "13077", # native_client/DEPS: tools_rev
"google_toolbox_for_mac_revision": "662",
"libaddressinput_revision": "305",
"libaddressinput_revision": "310",
"libphonenumber_revision": "621",
"libvpx_revision": "282874",
"lss_revision": "26",
......
......@@ -115,9 +115,13 @@ void FillOutputForSectionWithComparator(
g_browser_process->GetApplicationLocale());
std::vector<ServerFieldType> types = common::TypesFromInputs(inputs);
form_structure.FillFields(types,
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());
}
......@@ -345,6 +349,7 @@ void AutofillDialogControllerAndroid::Show() {
common::TypesFromInputs(inputs),
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
base::Bind(NullGetInfo),
std::string(),
g_browser_process->GetApplicationLocale());
}
......
......@@ -839,6 +839,7 @@ 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(
......
......@@ -91,6 +91,7 @@ bool DataModelWrapper::FillFormStructure(
types,
compare,
base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
GetLanguageCode(),
g_browser_process->GetApplicationLocale());
}
......
......@@ -15,8 +15,12 @@
#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;
......@@ -356,16 +360,21 @@ bool FillMonthControl(const base::string16& value, FormFieldData* field) {
// 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;
}
const base::string16& separator =
l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_SEPARATOR);
base::ReplaceChars(value, base::ASCIIToUTF16("\n"), separator, &field->value);
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);
}
std::string Hash32Bit(const std::string& str) {
......@@ -462,6 +471,7 @@ 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();
......@@ -474,7 +484,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, field_data);
FillStreetAddress(value, address_language_code, field_data);
return true;
}
......
......@@ -65,11 +65,13 @@ 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| and |app_locale| as
// hints when filling exceptional cases like phone number values and <select>
// fields. Returns |true| if the field has been filled, |false| otherwise.
// 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 <select> 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);
......
......@@ -550,9 +550,12 @@ 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<const AutofillProfile*>(data_model)->language_code();
}
// If the relevant section is auto-filled, we should fill |field| but not the
......@@ -563,8 +566,11 @@ void AutofillManager::FillOrPreviewForm(
if ((*iter) == field) {
base::string16 value = data_model->GetInfoForVariant(
autofill_field->Type(), variant, app_locale_);
if (AutofillField::FillFormField(
*autofill_field, value, app_locale_, &(*iter))) {
if (AutofillField::FillFormField(*autofill_field,
value,
profile_language_code,
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;
......@@ -620,8 +626,11 @@ 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, app_locale_, &result.fields[i])) {
if (AutofillField::FillFormField(*cached_field,
value,
profile_language_code,
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;
......
......@@ -1107,6 +1107,7 @@ bool FormStructure::FillFields(
const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& 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) {
......@@ -1114,6 +1115,7 @@ 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;
......
......@@ -137,11 +137,13 @@ class FormStructure {
InputFieldComparator;
// Fills in |fields_| that match |types| (via |matches|) with info from
// |get_info|.
// |get_info|. Uses |address_language_code| to determine line separators when
// collapsing street address lines into a single-line input text field.
bool FillFields(
const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& 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
......
......@@ -2,8 +2,8 @@ Name: The library to input, validate, and display addresses.
Short Name: libaddressinput
URL: https://code.google.com/p/libaddressinput/
Version: 0
Date: 11 July 2014
Revision: 305
Date: 19 July 2014
Revision: 310
License: Apache 2.0
License File: LICENSE
Security Critical: no
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment