Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: chrome/browser/ui/autofill/country_combobox_model.cc

Issue 178263004: rAc - Only show countries we're able to fill in. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 500s begone Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 return true;
37
38 AutofillCountry country(country_code,
39 g_browser_process->GetApplicationLocale());
40 if (!candidate_countries.count(base::ASCIIToUTF16(country_code)) &&
41 !candidate_countries.count(country.name())) {
42 return false;
43 }
44
29 return true; 45 return true;
30 #endif
31 } 46 }
32 47
33 } // namespace 48 } // namespace
34 49
35 CountryComboboxModel::CountryComboboxModel( 50 CountryComboboxModel::CountryComboboxModel(
36 const PersonalDataManager& manager, 51 const PersonalDataManager& manager,
52 const std::set<base::string16>& country_filter,
37 bool show_partially_supported_countries) { 53 bool show_partially_supported_countries) {
38 // Insert the default country at the top as well as in the ordered list. 54 // 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 = 55 std::string default_country_code =
41 manager.GetDefaultCountryCodeForNewAddress(); 56 manager.GetDefaultCountryCodeForNewAddress();
42 DCHECK(!default_country_code.empty()); 57 DCHECK(!default_country_code.empty());
43 58
44 if (show_partially_supported_countries || 59 const std::string& app_locale = g_browser_process->GetApplicationLocale();
45 ShouldShowCountry(default_country_code)) { 60 if (ShouldShowCountry(default_country_code,
61 show_partially_supported_countries,
62 country_filter)) {
46 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); 63 countries_.push_back(new AutofillCountry(default_country_code, app_locale));
47 // The separator item. 64 // The separator item.
48 countries_.push_back(NULL); 65 countries_.push_back(NULL);
49 } 66 }
50 67
51 // The sorted list of countries. 68 // The sorted list of countries.
52 #if defined(ENABLE_AUTOFILL_DIALOG) 69 #if defined(ENABLE_AUTOFILL_DIALOG)
53 const std::vector<std::string>& available_countries = 70 const std::vector<std::string>& available_countries =
54 ::i18n::addressinput::GetRegionCodes(); 71 ::i18n::addressinput::GetRegionCodes();
55 #else 72 #else
56 std::vector<std::string> available_countries; 73 std::vector<std::string> available_countries;
57 AutofillCountry::GetAvailableCountries(&available_countries); 74 AutofillCountry::GetAvailableCountries(&available_countries);
58 #endif 75 #endif
59 76
60 std::vector<AutofillCountry*> sorted_countries; 77 std::vector<AutofillCountry*> sorted_countries;
61 for (std::vector<std::string>::const_iterator it = 78 for (std::vector<std::string>::const_iterator it =
62 available_countries.begin(); it != available_countries.end(); ++it) { 79 available_countries.begin(); it != available_countries.end(); ++it) {
63 if (show_partially_supported_countries || ShouldShowCountry(*it)) 80 if (ShouldShowCountry(*it,
81 show_partially_supported_countries,
82 country_filter)) {
64 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); 83 sorted_countries.push_back(new AutofillCountry(*it, app_locale));
84 }
65 } 85 }
66 86
67 l10n_util::SortStringsUsingMethod(app_locale, 87 l10n_util::SortStringsUsingMethod(app_locale,
68 &sorted_countries, 88 &sorted_countries,
69 &AutofillCountry::name); 89 &AutofillCountry::name);
70 countries_.insert(countries_.end(), 90 countries_.insert(countries_.end(),
71 sorted_countries.begin(), 91 sorted_countries.begin(),
72 sorted_countries.end()); 92 sorted_countries.end());
73 } 93 }
74 94
(...skipping 15 matching lines...) Expand all
90 110
91 bool CountryComboboxModel::IsItemSeparatorAt(int index) { 111 bool CountryComboboxModel::IsItemSeparatorAt(int index) {
92 return !countries_[index]; 112 return !countries_[index];
93 } 113 }
94 114
95 std::string CountryComboboxModel::GetDefaultCountryCode() const { 115 std::string CountryComboboxModel::GetDefaultCountryCode() const {
96 return countries_[GetDefaultIndex()]->country_code(); 116 return countries_[GetDefaultIndex()]->country_code();
97 } 117 }
98 118
99 } // namespace autofill 119 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698