| 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 "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| 18 #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" |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 namespace autofill { | 21 namespace autofill { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 bool ShouldShowCountry(const std::string& country_code) { | 25 bool ShouldShowCountry(const std::string& country_code, |
| 26 bool show_partially_supported_countries, |
| 27 const std::set<base::string16>& candidate_countries) { |
| 26 #if defined(ENABLE_AUTOFILL_DIALOG) | 28 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 27 return i18ninput::CountryIsFullySupported(country_code); | 29 if (!show_partially_supported_countries && |
| 28 #else | 30 !i18ninput::CountryIsFullySupported(country_code)) { |
| 31 return false; |
| 32 } |
| 33 #endif |
| 34 |
| 35 if (!candidate_countries.empty() && |
| 36 !candidate_countries.count(base::ASCIIToUTF16(country_code))) { |
| 37 return false; |
| 38 } |
| 39 |
| 29 return true; | 40 return true; |
| 30 #endif | |
| 31 } | 41 } |
| 32 | 42 |
| 33 } // namespace | 43 } // namespace |
| 34 | 44 |
| 35 CountryComboboxModel::CountryComboboxModel( | 45 CountryComboboxModel::CountryComboboxModel( |
| 36 const PersonalDataManager& manager, | 46 const PersonalDataManager& manager, |
| 47 const std::set<base::string16>& country_filter, |
| 37 bool show_partially_supported_countries) { | 48 bool show_partially_supported_countries) { |
| 38 // Insert the default country at the top as well as in the ordered list. | 49 // Insert the default country at the top as well as in the ordered list. |
| 39 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | |
| 40 std::string default_country_code = | 50 std::string default_country_code = |
| 41 manager.GetDefaultCountryCodeForNewAddress(); | 51 manager.GetDefaultCountryCodeForNewAddress(); |
| 42 DCHECK(!default_country_code.empty()); | 52 DCHECK(!default_country_code.empty()); |
| 43 | 53 |
| 44 if (show_partially_supported_countries || | 54 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 45 ShouldShowCountry(default_country_code)) { | 55 if (ShouldShowCountry(default_country_code, |
| 56 show_partially_supported_countries, |
| 57 country_filter)) { |
| 46 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); | 58 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); |
| 47 // The separator item. | 59 // The separator item. |
| 48 countries_.push_back(NULL); | 60 countries_.push_back(NULL); |
| 49 } | 61 } |
| 50 | 62 |
| 51 // The sorted list of countries. | 63 // The sorted list of countries. |
| 52 #if defined(ENABLE_AUTOFILL_DIALOG) | 64 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 53 const std::vector<std::string>& available_countries = | 65 const std::vector<std::string>& available_countries = |
| 54 ::i18n::addressinput::GetRegionCodes(); | 66 ::i18n::addressinput::GetRegionCodes(); |
| 55 #else | 67 #else |
| 56 std::vector<std::string> available_countries; | 68 std::vector<std::string> available_countries; |
| 57 AutofillCountry::GetAvailableCountries(&available_countries); | 69 AutofillCountry::GetAvailableCountries(&available_countries); |
| 58 #endif | 70 #endif |
| 59 | 71 |
| 60 std::vector<AutofillCountry*> sorted_countries; | 72 std::vector<AutofillCountry*> sorted_countries; |
| 61 for (std::vector<std::string>::const_iterator it = | 73 for (std::vector<std::string>::const_iterator it = |
| 62 available_countries.begin(); it != available_countries.end(); ++it) { | 74 available_countries.begin(); it != available_countries.end(); ++it) { |
| 63 if (show_partially_supported_countries || ShouldShowCountry(*it)) | 75 if (ShouldShowCountry(*it, |
| 76 show_partially_supported_countries, |
| 77 country_filter)) { |
| 64 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); | 78 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); |
| 79 } |
| 65 } | 80 } |
| 66 | 81 |
| 67 l10n_util::SortStringsUsingMethod(app_locale, | 82 l10n_util::SortStringsUsingMethod(app_locale, |
| 68 &sorted_countries, | 83 &sorted_countries, |
| 69 &AutofillCountry::name); | 84 &AutofillCountry::name); |
| 70 countries_.insert(countries_.end(), | 85 countries_.insert(countries_.end(), |
| 71 sorted_countries.begin(), | 86 sorted_countries.begin(), |
| 72 sorted_countries.end()); | 87 sorted_countries.end()); |
| 73 } | 88 } |
| 74 | 89 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 | 105 |
| 91 bool CountryComboboxModel::IsItemSeparatorAt(int index) { | 106 bool CountryComboboxModel::IsItemSeparatorAt(int index) { |
| 92 return !countries_[index]; | 107 return !countries_[index]; |
| 93 } | 108 } |
| 94 | 109 |
| 95 std::string CountryComboboxModel::GetDefaultCountryCode() const { | 110 std::string CountryComboboxModel::GetDefaultCountryCode() const { |
| 96 return countries_[GetDefaultIndex()]->country_code(); | 111 return countries_[GetDefaultIndex()]->country_code(); |
| 97 } | 112 } |
| 98 | 113 |
| 99 } // namespace autofill | 114 } // namespace autofill |
| OLD | NEW |