| 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/autofill/country_combobox_model.h" | 5 #include "chrome/browser/ui/autofill/country_combobox_model.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "components/autofill/core/browser/autofill_country.h" | 10 #include "components/autofill/core/browser/autofill_country.h" |
| 11 #include "components/autofill/core/browser/personal_data_manager.h" | 11 #include "components/autofill/core/browser/personal_data_manager.h" |
| 12 #include "ui/base/l10n/l10n_util_collator.h" | 12 #include "ui/base/l10n/l10n_util_collator.h" |
| 13 #include "ui/base/models/combobox_model_observer.h" | 13 #include "ui/base/models/combobox_model_observer.h" |
| 14 | 14 |
| 15 // TODO(rouslan): Remove this check. http://crbug.com/337587 | 15 // TODO(rouslan): Remove this check. http://crbug.com/337587 |
| 16 #if defined(ENABLE_AUTOFILL_DIALOG) | 16 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 17 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| 17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" | 18 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace autofill { | 21 namespace autofill { |
| 21 | 22 |
| 22 CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) { | 23 namespace { |
| 24 |
| 25 bool ShouldShowCountry(const std::string& country_code) { |
| 26 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 27 return i18ninput::CountryIsFullySupported(country_code); |
| 28 #else |
| 29 return true; |
| 30 #endif |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
| 35 CountryComboboxModel::CountryComboboxModel( |
| 36 const PersonalDataManager& manager, |
| 37 bool show_partially_supported_countries) { |
| 23 // Insert the default country at the top as well as in the ordered list. | 38 // Insert the default country at the top as well as in the ordered list. |
| 24 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 39 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 25 std::string default_country_code = | 40 std::string default_country_code = |
| 26 manager.GetDefaultCountryCodeForNewAddress(); | 41 manager.GetDefaultCountryCodeForNewAddress(); |
| 27 DCHECK(!default_country_code.empty()); | 42 DCHECK(!default_country_code.empty()); |
| 28 | 43 |
| 29 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); | 44 if (show_partially_supported_countries || |
| 30 // The separator item. | 45 ShouldShowCountry(default_country_code)) { |
| 31 countries_.push_back(NULL); | 46 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); |
| 47 // The separator item. |
| 48 countries_.push_back(NULL); |
| 49 } |
| 32 | 50 |
| 33 // The sorted list of countries. | 51 // The sorted list of countries. |
| 34 #if defined(ENABLE_AUTOFILL_DIALOG) | 52 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 35 const std::vector<std::string>& available_countries = | 53 const std::vector<std::string>& available_countries = |
| 36 ::i18n::addressinput::GetRegionCodes(); | 54 ::i18n::addressinput::GetRegionCodes(); |
| 37 #else | 55 #else |
| 38 std::vector<std::string> available_countries; | 56 std::vector<std::string> available_countries; |
| 39 AutofillCountry::GetAvailableCountries(&available_countries); | 57 AutofillCountry::GetAvailableCountries(&available_countries); |
| 40 #endif | 58 #endif |
| 41 | 59 |
| 42 std::vector<AutofillCountry*> sorted_countries; | 60 std::vector<AutofillCountry*> sorted_countries; |
| 43 for (std::vector<std::string>::const_iterator it = | 61 for (std::vector<std::string>::const_iterator it = |
| 44 available_countries.begin(); it != available_countries.end(); ++it) { | 62 available_countries.begin(); it != available_countries.end(); ++it) { |
| 45 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); | 63 if (show_partially_supported_countries || ShouldShowCountry(*it)) |
| 64 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); |
| 46 } | 65 } |
| 47 | 66 |
| 48 l10n_util::SortStringsUsingMethod(app_locale, | 67 l10n_util::SortStringsUsingMethod(app_locale, |
| 49 &sorted_countries, | 68 &sorted_countries, |
| 50 &AutofillCountry::name); | 69 &AutofillCountry::name); |
| 51 countries_.insert(countries_.end(), | 70 countries_.insert(countries_.end(), |
| 52 sorted_countries.begin(), | 71 sorted_countries.begin(), |
| 53 sorted_countries.end()); | 72 sorted_countries.end()); |
| 54 } | 73 } |
| 55 | 74 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 71 | 90 |
| 72 bool CountryComboboxModel::IsItemSeparatorAt(int index) { | 91 bool CountryComboboxModel::IsItemSeparatorAt(int index) { |
| 73 return !countries_[index]; | 92 return !countries_[index]; |
| 74 } | 93 } |
| 75 | 94 |
| 76 std::string CountryComboboxModel::GetDefaultCountryCode() const { | 95 std::string CountryComboboxModel::GetDefaultCountryCode() const { |
| 77 return countries_[GetDefaultIndex()]->country_code(); | 96 return countries_[GetDefaultIndex()]->country_code(); |
| 78 } | 97 } |
| 79 | 98 |
| 80 } // namespace autofill | 99 } // namespace autofill |
| OLD | NEW |