| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/options/autofill_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 static const char kDependentLocalityField[] = "dependentLocality"; | 61 static const char kDependentLocalityField[] = "dependentLocality"; |
| 62 static const char kCityField[] = "city"; | 62 static const char kCityField[] = "city"; |
| 63 static const char kStateField[] = "state"; | 63 static const char kStateField[] = "state"; |
| 64 static const char kPostalCodeField[] = "postalCode"; | 64 static const char kPostalCodeField[] = "postalCode"; |
| 65 static const char kSortingCodeField[] = "sortingCode"; | 65 static const char kSortingCodeField[] = "sortingCode"; |
| 66 static const char kCountryField[] = "country"; | 66 static const char kCountryField[] = "country"; |
| 67 | 67 |
| 68 static const char kComponents[] = "components"; | 68 static const char kComponents[] = "components"; |
| 69 static const char kLanguageCode[] = "languageCode"; | 69 static const char kLanguageCode[] = "languageCode"; |
| 70 | 70 |
| 71 scoped_ptr<base::DictionaryValue> CreditCardToDictionary( | 71 std::unique_ptr<base::DictionaryValue> CreditCardToDictionary( |
| 72 const CreditCard& card) { | 72 const CreditCard& card) { |
| 73 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 73 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 74 value->SetString("guid", card.guid()); | 74 value->SetString("guid", card.guid()); |
| 75 std::pair<base::string16, base::string16> label_pieces = card.LabelPieces(); | 75 std::pair<base::string16, base::string16> label_pieces = card.LabelPieces(); |
| 76 value->SetString("label", label_pieces.first); | 76 value->SetString("label", label_pieces.first); |
| 77 value->SetString("sublabel", label_pieces.second); | 77 value->SetString("sublabel", label_pieces.second); |
| 78 value->SetBoolean("isLocal", card.record_type() == CreditCard::LOCAL_CARD); | 78 value->SetBoolean("isLocal", card.record_type() == CreditCard::LOCAL_CARD); |
| 79 value->SetBoolean("isCached", | 79 value->SetBoolean("isCached", |
| 80 card.record_type() == CreditCard::FULL_SERVER_CARD); | 80 card.record_type() == CreditCard::FULL_SERVER_CARD); |
| 81 return value; | 81 return value; |
| 82 } | 82 } |
| 83 | 83 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 static const char kField[] = "field"; | 117 static const char kField[] = "field"; |
| 118 static const char kLength[] = "length"; | 118 static const char kLength[] = "length"; |
| 119 for (size_t i = 0; i < components.size(); ++i) { | 119 for (size_t i = 0; i < components.size(); ++i) { |
| 120 if (i == 0 || | 120 if (i == 0 || |
| 121 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || | 121 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || |
| 122 components[i].length_hint == AddressUiComponent::HINT_LONG) { | 122 components[i].length_hint == AddressUiComponent::HINT_LONG) { |
| 123 line = new base::ListValue; | 123 line = new base::ListValue; |
| 124 address_components->Append(line); | 124 address_components->Append(line); |
| 125 } | 125 } |
| 126 | 126 |
| 127 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); | 127 std::unique_ptr<base::DictionaryValue> component(new base::DictionaryValue); |
| 128 component->SetString("name", components[i].name); | 128 component->SetString("name", components[i].name); |
| 129 | 129 |
| 130 switch (components[i].field) { | 130 switch (components[i].field) { |
| 131 case i18n::addressinput::COUNTRY: | 131 case i18n::addressinput::COUNTRY: |
| 132 component->SetString(kField, kCountryField); | 132 component->SetString(kField, kCountryField); |
| 133 break; | 133 break; |
| 134 case i18n::addressinput::ADMIN_AREA: | 134 case i18n::addressinput::ADMIN_AREA: |
| 135 component->SetString(kField, kStateField); | 135 component->SetString(kField, kStateField); |
| 136 break; | 136 break; |
| 137 case i18n::addressinput::LOCALITY: | 137 case i18n::addressinput::LOCALITY: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // Sets data related to the country <select>. | 173 // Sets data related to the country <select>. |
| 174 void SetCountryData(const PersonalDataManager& manager, | 174 void SetCountryData(const PersonalDataManager& manager, |
| 175 base::DictionaryValue* localized_strings) { | 175 base::DictionaryValue* localized_strings) { |
| 176 autofill::CountryComboboxModel model; | 176 autofill::CountryComboboxModel model; |
| 177 model.SetCountries(manager, base::Callback<bool(const std::string&)>()); | 177 model.SetCountries(manager, base::Callback<bool(const std::string&)>()); |
| 178 const std::vector<AutofillCountry*>& countries = model.countries(); | 178 const std::vector<AutofillCountry*>& countries = model.countries(); |
| 179 localized_strings->SetString("defaultCountryCode", | 179 localized_strings->SetString("defaultCountryCode", |
| 180 countries.front()->country_code()); | 180 countries.front()->country_code()); |
| 181 | 181 |
| 182 // An ordered list of options to show in the <select>. | 182 // An ordered list of options to show in the <select>. |
| 183 scoped_ptr<base::ListValue> country_list(new base::ListValue()); | 183 std::unique_ptr<base::ListValue> country_list(new base::ListValue()); |
| 184 for (size_t i = 0; i < countries.size(); ++i) { | 184 for (size_t i = 0; i < countries.size(); ++i) { |
| 185 scoped_ptr<base::DictionaryValue> option_details( | 185 std::unique_ptr<base::DictionaryValue> option_details( |
| 186 new base::DictionaryValue()); | 186 new base::DictionaryValue()); |
| 187 option_details->SetString("name", model.GetItemAt(i)); | 187 option_details->SetString("name", model.GetItemAt(i)); |
| 188 option_details->SetString( | 188 option_details->SetString( |
| 189 "value", | 189 "value", |
| 190 countries[i] ? countries[i]->country_code() : "separator"); | 190 countries[i] ? countries[i]->country_code() : "separator"); |
| 191 country_list->Append(option_details.release()); | 191 country_list->Append(option_details.release()); |
| 192 } | 192 } |
| 193 localized_strings->Set("autofillCountrySelectList", country_list.release()); | 193 localized_strings->Set("autofillCountrySelectList", country_list.release()); |
| 194 | 194 |
| 195 scoped_ptr<base::ListValue> default_country_components(new base::ListValue); | 195 std::unique_ptr<base::ListValue> default_country_components( |
| 196 new base::ListValue); |
| 196 std::string default_country_language_code; | 197 std::string default_country_language_code; |
| 197 GetAddressComponents(countries.front()->country_code(), | 198 GetAddressComponents(countries.front()->country_code(), |
| 198 g_browser_process->GetApplicationLocale(), | 199 g_browser_process->GetApplicationLocale(), |
| 199 default_country_components.get(), | 200 default_country_components.get(), |
| 200 &default_country_language_code); | 201 &default_country_language_code); |
| 201 localized_strings->Set("autofillDefaultCountryComponents", | 202 localized_strings->Set("autofillDefaultCountryComponents", |
| 202 default_country_components.release()); | 203 default_country_components.release()); |
| 203 localized_strings->SetString("autofillDefaultCountryLanguageCode", | 204 localized_strings->SetString("autofillDefaultCountryLanguageCode", |
| 204 default_country_language_code); | 205 default_country_language_code); |
| 205 } | 206 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 for (size_t i = 0; i < profiles.size(); ++i) { | 346 for (size_t i = 0; i < profiles.size(); ++i) { |
| 346 // Skip showing auxiliary profiles (e.g. Mac Contacts) for now. | 347 // Skip showing auxiliary profiles (e.g. Mac Contacts) for now. |
| 347 if (profiles[i]->record_type() == AutofillProfile::AUXILIARY_PROFILE) | 348 if (profiles[i]->record_type() == AutofillProfile::AUXILIARY_PROFILE) |
| 348 continue; | 349 continue; |
| 349 | 350 |
| 350 base::string16 separator = | 351 base::string16 separator = |
| 351 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); | 352 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); |
| 352 std::vector<base::string16> label_parts; | 353 std::vector<base::string16> label_parts; |
| 353 base::SplitStringUsingSubstr(labels[i], separator, &label_parts); | 354 base::SplitStringUsingSubstr(labels[i], separator, &label_parts); |
| 354 | 355 |
| 355 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 356 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 356 value->SetString("guid", profiles[i]->guid()); | 357 value->SetString("guid", profiles[i]->guid()); |
| 357 value->SetString("label", label_parts[0]); | 358 value->SetString("label", label_parts[0]); |
| 358 value->SetString("sublabel", labels[i].substr(label_parts[0].size())); | 359 value->SetString("sublabel", labels[i].substr(label_parts[0].size())); |
| 359 value->SetBoolean("isLocal", profiles[i]->record_type() == | 360 value->SetBoolean("isLocal", profiles[i]->record_type() == |
| 360 AutofillProfile::LOCAL_PROFILE); | 361 AutofillProfile::LOCAL_PROFILE); |
| 361 addresses.Append(value.release()); | 362 addresses.Append(value.release()); |
| 362 } | 363 } |
| 363 | 364 |
| 364 web_ui()->CallJavascriptFunction("AutofillOptions.setAddressList", addresses); | 365 web_ui()->CallJavascriptFunction("AutofillOptions.setAddressList", addresses); |
| 365 | 366 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 413 |
| 413 void AutofillOptionsHandler::LoadAddressEditorComponents( | 414 void AutofillOptionsHandler::LoadAddressEditorComponents( |
| 414 const base::ListValue* args) { | 415 const base::ListValue* args) { |
| 415 std::string country_code; | 416 std::string country_code; |
| 416 if (!args->GetString(0, &country_code)) { | 417 if (!args->GetString(0, &country_code)) { |
| 417 NOTREACHED(); | 418 NOTREACHED(); |
| 418 return; | 419 return; |
| 419 } | 420 } |
| 420 | 421 |
| 421 base::DictionaryValue input; | 422 base::DictionaryValue input; |
| 422 scoped_ptr<base::ListValue> components(new base::ListValue); | 423 std::unique_ptr<base::ListValue> components(new base::ListValue); |
| 423 std::string language_code; | 424 std::string language_code; |
| 424 GetAddressComponents(country_code, g_browser_process->GetApplicationLocale(), | 425 GetAddressComponents(country_code, g_browser_process->GetApplicationLocale(), |
| 425 components.get(), &language_code); | 426 components.get(), &language_code); |
| 426 input.Set(kComponents, components.release()); | 427 input.Set(kComponents, components.release()); |
| 427 input.SetString(kLanguageCode, language_code); | 428 input.SetString(kLanguageCode, language_code); |
| 428 | 429 |
| 429 web_ui()->CallJavascriptFunction( | 430 web_ui()->CallJavascriptFunction( |
| 430 "AutofillEditAddressOverlay.loadAddressComponents", input); | 431 "AutofillEditAddressOverlay.loadAddressComponents", input); |
| 431 } | 432 } |
| 432 | 433 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE)); | 599 profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE)); |
| 599 address->SetString(kPostalCodeField, | 600 address->SetString(kPostalCodeField, |
| 600 profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP)); | 601 profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP)); |
| 601 address->SetString(kCountryField, | 602 address->SetString(kCountryField, |
| 602 profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 603 profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
| 603 address->SetString("phone", | 604 address->SetString("phone", |
| 604 profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); | 605 profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); |
| 605 address->SetString("email", profile.GetRawInfo(autofill::EMAIL_ADDRESS)); | 606 address->SetString("email", profile.GetRawInfo(autofill::EMAIL_ADDRESS)); |
| 606 address->SetString(kLanguageCode, profile.language_code()); | 607 address->SetString(kLanguageCode, profile.language_code()); |
| 607 | 608 |
| 608 scoped_ptr<base::ListValue> components(new base::ListValue); | 609 std::unique_ptr<base::ListValue> components(new base::ListValue); |
| 609 GetAddressComponents( | 610 GetAddressComponents( |
| 610 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 611 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
| 611 profile.language_code(), | 612 profile.language_code(), |
| 612 components.get(), | 613 components.get(), |
| 613 NULL); | 614 NULL); |
| 614 address->Set(kComponents, components.release()); | 615 address->Set(kComponents, components.release()); |
| 615 } | 616 } |
| 616 | 617 |
| 617 } // namespace options | 618 } // namespace options |
| OLD | NEW |