| 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 <utility> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/guid.h" | 15 #include "base/guid.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 153 |
| 153 switch (components[i].length_hint) { | 154 switch (components[i].length_hint) { |
| 154 case AddressUiComponent::HINT_LONG: | 155 case AddressUiComponent::HINT_LONG: |
| 155 component->SetString(kLength, "long"); | 156 component->SetString(kLength, "long"); |
| 156 break; | 157 break; |
| 157 case AddressUiComponent::HINT_SHORT: | 158 case AddressUiComponent::HINT_SHORT: |
| 158 component->SetString(kLength, "short"); | 159 component->SetString(kLength, "short"); |
| 159 break; | 160 break; |
| 160 } | 161 } |
| 161 | 162 |
| 162 line->Append(component.release()); | 163 line->Append(std::move(component)); |
| 163 } | 164 } |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Sets data related to the country <select>. | 167 // Sets data related to the country <select>. |
| 167 void SetCountryData(const PersonalDataManager& manager, | 168 void SetCountryData(const PersonalDataManager& manager, |
| 168 base::DictionaryValue* localized_strings) { | 169 base::DictionaryValue* localized_strings) { |
| 169 autofill::CountryComboboxModel model; | 170 autofill::CountryComboboxModel model; |
| 170 model.SetCountries(manager, base::Callback<bool(const std::string&)>()); | 171 model.SetCountries(manager, base::Callback<bool(const std::string&)>()); |
| 171 const std::vector<AutofillCountry*>& countries = model.countries(); | 172 const std::vector<AutofillCountry*>& countries = model.countries(); |
| 172 localized_strings->SetString("defaultCountryCode", | 173 localized_strings->SetString("defaultCountryCode", |
| 173 countries.front()->country_code()); | 174 countries.front()->country_code()); |
| 174 | 175 |
| 175 // An ordered list of options to show in the <select>. | 176 // An ordered list of options to show in the <select>. |
| 176 std::unique_ptr<base::ListValue> country_list(new base::ListValue()); | 177 std::unique_ptr<base::ListValue> country_list(new base::ListValue()); |
| 177 for (size_t i = 0; i < countries.size(); ++i) { | 178 for (size_t i = 0; i < countries.size(); ++i) { |
| 178 std::unique_ptr<base::DictionaryValue> option_details( | 179 std::unique_ptr<base::DictionaryValue> option_details( |
| 179 new base::DictionaryValue()); | 180 new base::DictionaryValue()); |
| 180 option_details->SetString("name", model.GetItemAt(i)); | 181 option_details->SetString("name", model.GetItemAt(i)); |
| 181 option_details->SetString( | 182 option_details->SetString( |
| 182 "value", | 183 "value", |
| 183 countries[i] ? countries[i]->country_code() : "separator"); | 184 countries[i] ? countries[i]->country_code() : "separator"); |
| 184 country_list->Append(option_details.release()); | 185 country_list->Append(std::move(option_details)); |
| 185 } | 186 } |
| 186 localized_strings->Set("autofillCountrySelectList", country_list.release()); | 187 localized_strings->Set("autofillCountrySelectList", country_list.release()); |
| 187 | 188 |
| 188 std::unique_ptr<base::ListValue> default_country_components( | 189 std::unique_ptr<base::ListValue> default_country_components( |
| 189 new base::ListValue); | 190 new base::ListValue); |
| 190 std::string default_country_language_code; | 191 std::string default_country_language_code; |
| 191 GetAddressComponents(countries.front()->country_code(), | 192 GetAddressComponents(countries.front()->country_code(), |
| 192 g_browser_process->GetApplicationLocale(), | 193 g_browser_process->GetApplicationLocale(), |
| 193 default_country_components.get(), | 194 default_country_components.get(), |
| 194 &default_country_language_code); | 195 &default_country_language_code); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); | 346 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); |
| 346 std::vector<base::string16> label_parts; | 347 std::vector<base::string16> label_parts; |
| 347 base::SplitStringUsingSubstr(labels[i], separator, &label_parts); | 348 base::SplitStringUsingSubstr(labels[i], separator, &label_parts); |
| 348 | 349 |
| 349 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 350 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 350 value->SetString("guid", profiles[i]->guid()); | 351 value->SetString("guid", profiles[i]->guid()); |
| 351 value->SetString("label", label_parts[0]); | 352 value->SetString("label", label_parts[0]); |
| 352 value->SetString("sublabel", labels[i].substr(label_parts[0].size())); | 353 value->SetString("sublabel", labels[i].substr(label_parts[0].size())); |
| 353 value->SetBoolean("isLocal", profiles[i]->record_type() == | 354 value->SetBoolean("isLocal", profiles[i]->record_type() == |
| 354 AutofillProfile::LOCAL_PROFILE); | 355 AutofillProfile::LOCAL_PROFILE); |
| 355 addresses.Append(value.release()); | 356 addresses.Append(std::move(value)); |
| 356 } | 357 } |
| 357 | 358 |
| 358 web_ui()->CallJavascriptFunctionUnsafe("AutofillOptions.setAddressList", | 359 web_ui()->CallJavascriptFunctionUnsafe("AutofillOptions.setAddressList", |
| 359 addresses); | 360 addresses); |
| 360 | 361 |
| 361 base::ListValue credit_cards; | 362 base::ListValue credit_cards; |
| 362 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); | 363 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); |
| 363 for (const CreditCard* card : cards) { | 364 for (const CreditCard* card : cards) { |
| 364 credit_cards.Append(CreditCardToDictionary(*card).release()); | 365 credit_cards.Append(CreditCardToDictionary(*card)); |
| 365 } | 366 } |
| 366 | 367 |
| 367 web_ui()->CallJavascriptFunctionUnsafe("AutofillOptions.setCreditCardList", | 368 web_ui()->CallJavascriptFunctionUnsafe("AutofillOptions.setCreditCardList", |
| 368 credit_cards); | 369 credit_cards); |
| 369 } | 370 } |
| 370 | 371 |
| 371 void AutofillOptionsHandler::RemoveData(const base::ListValue* args) { | 372 void AutofillOptionsHandler::RemoveData(const base::ListValue* args) { |
| 372 DCHECK(IsPersonalDataLoaded()); | 373 DCHECK(IsPersonalDataLoaded()); |
| 373 | 374 |
| 374 std::string guid; | 375 std::string guid; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 address->SetString(kLanguageCode, profile.language_code()); | 628 address->SetString(kLanguageCode, profile.language_code()); |
| 628 | 629 |
| 629 std::unique_ptr<base::ListValue> components(new base::ListValue); | 630 std::unique_ptr<base::ListValue> components(new base::ListValue); |
| 630 GetAddressComponents( | 631 GetAddressComponents( |
| 631 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 632 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
| 632 profile.language_code(), components.get(), nullptr); | 633 profile.language_code(), components.get(), nullptr); |
| 633 address->Set(kComponents, components.release()); | 634 address->Set(kComponents, components.release()); |
| 634 } | 635 } |
| 635 | 636 |
| 636 } // namespace options | 637 } // namespace options |
| OLD | NEW |