Chromium Code Reviews| Index: chrome/browser/ui/webui/options/autofill_options_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/autofill_options_handler.cc b/chrome/browser/ui/webui/options/autofill_options_handler.cc |
| index 4b512d5e5257215df44024e48df7789d4e48783d..fcab9b9e57d0ff8b045ebe938d1eba965c5b4eb8 100644 |
| --- a/chrome/browser/ui/webui/options/autofill_options_handler.cc |
| +++ b/chrome/browser/ui/webui/options/autofill_options_handler.cc |
| @@ -28,6 +28,7 @@ |
| #include "chrome/grit/generated_resources.h" |
| #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
| #include "components/autofill/core/browser/autofill_country.h" |
| +#include "components/autofill/core/browser/autofill_data_util.h" |
| #include "components/autofill/core/browser/autofill_profile.h" |
| #include "components/autofill/core/browser/credit_card.h" |
| #include "components/autofill/core/browser/personal_data_manager.h" |
| @@ -97,23 +98,19 @@ void GetAddressComponents(const std::string& country_code, |
| std::string not_used; |
| std::vector<AddressUiComponent> components = |
| i18n::addressinput::BuildComponents( |
| - country_code, |
| - localization, |
| - ui_language_code, |
| - components_language_code == NULL ? |
| - ¬_used : components_language_code); |
| + country_code, localization, ui_language_code, |
| + components_language_code == nullptr ? ¬_used |
| + : components_language_code); |
|
stevenjb
2016/04/18 20:42:35
components_language_code ? components_language_cod
tmartino
2016/04/19 17:46:38
Done.
|
| if (components.empty()) { |
| static const char kDefaultCountryCode[] = "US"; |
| components = i18n::addressinput::BuildComponents( |
| - kDefaultCountryCode, |
| - localization, |
| - ui_language_code, |
| - components_language_code == NULL ? |
| - ¬_used : components_language_code); |
| + kDefaultCountryCode, localization, ui_language_code, |
| + components_language_code == nullptr ? ¬_used |
| + : components_language_code); |
|
stevenjb
2016/04/18 20:42:35
ditto
tmartino
2016/04/19 17:46:38
Done.
|
| } |
| DCHECK(!components.empty()); |
| - base::ListValue* line = NULL; |
| + base::ListValue* line = nullptr; |
| static const char kField[] = "field"; |
| static const char kLength[] = "length"; |
| for (size_t i = 0; i < components.size(); ++i) { |
| @@ -208,7 +205,8 @@ void SetCountryData(const PersonalDataManager& manager, |
| namespace options { |
| -AutofillOptionsHandler::AutofillOptionsHandler() : personal_data_(NULL) {} |
| +AutofillOptionsHandler::AutofillOptionsHandler() |
| + : personal_data_(nullptr), prior_profile_(nullptr) {} |
| AutofillOptionsHandler::~AutofillOptionsHandler() { |
| if (personal_data_) |
| @@ -394,8 +392,8 @@ void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) { |
| return; |
| } |
| - AutofillProfile* profile = personal_data_->GetProfileByGUID(guid); |
| - if (!profile) { |
| + prior_profile_ = personal_data_->GetProfileByGUID(guid); |
| + if (!prior_profile_) { |
| // There is a race where a user can click once on the close button and |
| // quickly click again on the list item before the item is removed (since |
| // the list is not updated until the model tells the list an item has been |
| @@ -405,7 +403,7 @@ void AutofillOptionsHandler::LoadAddressEditor(const base::ListValue* args) { |
| } |
| base::DictionaryValue address; |
| - AutofillProfileToDictionary(*profile, &address); |
| + AutofillProfileToDictionary(*prior_profile_, &address); |
| web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); |
| } |
| @@ -480,12 +478,32 @@ void AutofillOptionsHandler::SetAddress(const base::ListValue* args) { |
| AutofillProfile profile(guid, kSettingsOrigin); |
| - base::string16 value; |
| - if (args->GetString(arg_counter++, &value)) { |
| - profile.SetInfo(AutofillType(autofill::NAME_FULL), value, |
| - g_browser_process->GetApplicationLocale()); |
| + base::string16 full_name; |
| + if (args->GetString(arg_counter++, &full_name)) { |
| + // Although First/Middle/Last are not displayed on the form, we transfer |
| + // this information when they match the full name given. This is because it |
| + // may not be possible later to correctly tokenize the concatenated full |
| + // name--e.g., when the last name contains a space, the first word would be |
|
stevenjb
2016/04/18 20:42:35
nit: s/--/, /
tmartino
2016/04/19 17:46:38
Done.
|
| + // treated as a middle name. |
| + if (prior_profile_ && autofill::data_util::ProfileMatchesFullName( |
| + full_name, *prior_profile_)) { |
| + profile.SetRawInfo(autofill::NAME_FULL, full_name); |
| + |
| + profile.SetRawInfo(autofill::NAME_FIRST, |
| + prior_profile_->GetRawInfo(autofill::NAME_FIRST)); |
| + profile.SetRawInfo(autofill::NAME_MIDDLE, |
| + prior_profile_->GetRawInfo(autofill::NAME_MIDDLE)); |
| + profile.SetRawInfo(autofill::NAME_LAST, |
| + prior_profile_->GetRawInfo(autofill::NAME_LAST)); |
| + } else { |
| + // In contrast to SetRawInfo, SetInfo will naively attempt to populate the |
| + // First/Middle/Last fields by tokenization. |
| + profile.SetInfo(AutofillType(autofill::NAME_FULL), full_name, |
| + g_browser_process->GetApplicationLocale()); |
| + } |
| } |
| + base::string16 value; |
| if (args->GetString(arg_counter++, &value)) |
| profile.SetRawInfo(autofill::COMPANY_NAME, value); |
| @@ -608,9 +626,7 @@ void AutofillOptionsHandler::AutofillProfileToDictionary( |
| scoped_ptr<base::ListValue> components(new base::ListValue); |
| GetAddressComponents( |
| base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
| - profile.language_code(), |
| - components.get(), |
| - NULL); |
| + profile.language_code(), components.get(), nullptr); |
| address->Set(kComponents, components.release()); |
| } |