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

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: . 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) {
Dan Beam 2014/03/01 03:38:10 nit: const-ref
Evan Stade 2014/03/04 00:11:30 good catch, done.
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
Dan Beam 2014/03/01 03:38:10 if (candidate_countries.empty()) return true; /
Evan Stade 2014/03/04 00:11:30 not really an improvement, but done
Dan Beam 2014/03/04 00:19:50 doesn't construct an AutofillCountry needlessly...
35 AutofillCountry country(country_code,
36 g_browser_process->GetApplicationLocale());
37 if (!candidate_countries.empty() &&
38 !candidate_countries.count(base::ASCIIToUTF16(country_code)) &&
39 !candidate_countries.count(country.name())) {
40 return false;
41 }
Ilya Sherman 2014/03/03 23:55:54 What happens if the <select> dropdown includes loc
Evan Stade 2014/03/04 00:11:30 what happens is that requestAutocomplete won't wor
Dan Beam 2014/03/04 00:19:50 in general i think this was a cool idea, but +1 to
Ilya Sherman 2014/03/04 00:53:57 IMO we should either only support country codes, o
42
29 return true; 43 return true;
30 #endif
31 } 44 }
32 45
33 } // namespace 46 } // namespace
34 47
35 CountryComboboxModel::CountryComboboxModel( 48 CountryComboboxModel::CountryComboboxModel(
36 const PersonalDataManager& manager, 49 const PersonalDataManager& manager,
50 const std::set<base::string16>& country_filter,
37 bool show_partially_supported_countries) { 51 bool show_partially_supported_countries) {
38 // Insert the default country at the top as well as in the ordered list. 52 // 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 = 53 std::string default_country_code =
41 manager.GetDefaultCountryCodeForNewAddress(); 54 manager.GetDefaultCountryCodeForNewAddress();
42 DCHECK(!default_country_code.empty()); 55 DCHECK(!default_country_code.empty());
43 56
44 if (show_partially_supported_countries || 57 const std::string& app_locale = g_browser_process->GetApplicationLocale();
45 ShouldShowCountry(default_country_code)) { 58 if (ShouldShowCountry(default_country_code,
59 show_partially_supported_countries,
60 country_filter)) {
46 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); 61 countries_.push_back(new AutofillCountry(default_country_code, app_locale));
47 // The separator item. 62 // The separator item.
48 countries_.push_back(NULL); 63 countries_.push_back(NULL);
49 } 64 }
50 65
51 // The sorted list of countries. 66 // The sorted list of countries.
52 #if defined(ENABLE_AUTOFILL_DIALOG) 67 #if defined(ENABLE_AUTOFILL_DIALOG)
53 const std::vector<std::string>& available_countries = 68 const std::vector<std::string>& available_countries =
54 ::i18n::addressinput::GetRegionCodes(); 69 ::i18n::addressinput::GetRegionCodes();
55 #else 70 #else
56 std::vector<std::string> available_countries; 71 std::vector<std::string> available_countries;
57 AutofillCountry::GetAvailableCountries(&available_countries); 72 AutofillCountry::GetAvailableCountries(&available_countries);
58 #endif 73 #endif
59 74
60 std::vector<AutofillCountry*> sorted_countries; 75 std::vector<AutofillCountry*> sorted_countries;
61 for (std::vector<std::string>::const_iterator it = 76 for (std::vector<std::string>::const_iterator it =
62 available_countries.begin(); it != available_countries.end(); ++it) { 77 available_countries.begin(); it != available_countries.end(); ++it) {
63 if (show_partially_supported_countries || ShouldShowCountry(*it)) 78 if (ShouldShowCountry(*it,
79 show_partially_supported_countries,
80 country_filter)) {
64 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); 81 sorted_countries.push_back(new AutofillCountry(*it, app_locale));
82 }
65 } 83 }
66 84
67 l10n_util::SortStringsUsingMethod(app_locale, 85 l10n_util::SortStringsUsingMethod(app_locale,
68 &sorted_countries, 86 &sorted_countries,
69 &AutofillCountry::name); 87 &AutofillCountry::name);
70 countries_.insert(countries_.end(), 88 countries_.insert(countries_.end(),
71 sorted_countries.begin(), 89 sorted_countries.begin(),
72 sorted_countries.end()); 90 sorted_countries.end());
73 } 91 }
74 92
(...skipping 15 matching lines...) Expand all
90 108
91 bool CountryComboboxModel::IsItemSeparatorAt(int index) { 109 bool CountryComboboxModel::IsItemSeparatorAt(int index) {
92 return !countries_[index]; 110 return !countries_[index];
93 } 111 }
94 112
95 std::string CountryComboboxModel::GetDefaultCountryCode() const { 113 std::string CountryComboboxModel::GetDefaultCountryCode() const {
96 return countries_[GetDefaultIndex()]->country_code(); 114 return countries_[GetDefaultIndex()]->country_code();
97 } 115 }
98 116
99 } // namespace autofill 117 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698