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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.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, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 57f639107d00b7d5fc4a9017beec2901c22a97f2..1bed919ef5a9cda6dd57c20af14d30d4fdee42bd 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -633,6 +633,15 @@ void AutofillDialogControllerImpl::Show() {
return;
}
+ billing_country_combobox_model_.reset(new CountryComboboxModel(
+ *GetManager(),
+ form_structure_.PossibleValues(ADDRESS_BILLING_COUNTRY),
+ false));
+ shipping_country_combobox_model_.reset(new CountryComboboxModel(
+ *GetManager(),
+ form_structure_.PossibleValues(ADDRESS_HOME_COUNTRY),
+ false));
+
// Log any relevant UI metrics and security exceptions.
GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN);
@@ -1375,10 +1384,10 @@ ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType(
return &cc_exp_year_combobox_model_;
case ADDRESS_BILLING_COUNTRY:
- return &billing_country_combobox_model_;
+ return billing_country_combobox_model_.get();
case ADDRESS_HOME_COUNTRY:
- return &shipping_country_combobox_model_;
+ return shipping_country_combobox_model_.get();
default:
return NULL;
@@ -1489,8 +1498,9 @@ bool AutofillDialogControllerImpl::SuggestionTextForSection(
return true;
}
- if (!IsASuggestionItemKey(item_key))
+ if (!IsASuggestionItemKey(item_key)) {
return false;
+ }
Dan Beam 2014/03/01 03:38:10 nit: revert
Evan Stade 2014/03/04 00:11:30 Done.
if (!IsPayingWithWallet() &&
(section == SECTION_BILLING || section == SECTION_SHIPPING)) {
@@ -2697,8 +2707,6 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl(
wallet_items_requested_(false),
handling_use_wallet_link_click_(false),
passive_failed_(false),
- billing_country_combobox_model_(*GetManager(), false),
- shipping_country_combobox_model_(*GetManager(), false),
suggested_cc_(this),
suggested_billing_(this),
suggested_cc_billing_(this),
@@ -2854,6 +2862,10 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
key,
addresses[i]->DisplayName(),
addresses[i]->DisplayNameDetail());
+ suggested_shipping_.SetEnabled(
+ key,
+ CanAcceptCountry(SECTION_SHIPPING,
+ addresses[i]->country_name_code()));
// TODO(scr): Move this assignment outside the loop or comment why it
// can't be there.
@@ -2874,7 +2886,9 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
std::string first_active_instrument_key;
std::string default_instrument_key;
for (size_t i = 0; i < instruments.size(); ++i) {
- bool allowed = IsInstrumentAllowed(*instruments[i]);
+ bool allowed = IsInstrumentAllowed(*instruments[i]) &&
+ CanAcceptCountry(SECTION_BILLING,
+ instruments[i]->address().country_name_code());
gfx::Image icon = instruments[i]->CardIcon();
if (!allowed && !icon.IsEmpty()) {
// Create a grayed disabled icon.
@@ -2945,8 +2959,6 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
for (size_t i = 0; i < profiles.size(); ++i) {
const AutofillProfile& profile = *profiles[i];
if (!i18ninput::AddressHasCompleteAndVerifiedData(profile) ||
- !i18ninput::CountryIsFullySupported(
- UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))) ||
(!i18ninput::Enabled() && HasInvalidAddress(*profiles[i]))) {
continue;
}
@@ -2954,9 +2966,19 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
// Don't add variants for addresses: name is part of credit card and
// we'll just ignore email and phone number variants.
suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]);
+ suggested_shipping_.SetEnabled(
+ profile.guid(),
+ CanAcceptCountry(
+ SECTION_SHIPPING,
+ UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))));
if (!profile.GetRawInfo(EMAIL_ADDRESS).empty() &&
!profile.IsPresentButInvalid(EMAIL_ADDRESS)) {
suggested_billing_.AddKeyedItem(profile.guid(), labels[i]);
+ suggested_billing_.SetEnabled(
+ profile.guid(),
+ CanAcceptCountry(
+ SECTION_BILLING,
+ UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))));
}
}
}
@@ -3163,6 +3185,19 @@ base::string16 AutofillDialogControllerImpl::GetValueFromSection(
return output[type];
}
+bool AutofillDialogControllerImpl::CanAcceptCountry(
+ DialogSection section,
+ const std::string& country_code) {
+ CountryComboboxModel* model = CountryComboboxModelForSection(section);
+ const std::vector<AutofillCountry*>& countries = model->countries();
+ for (size_t i = 0; i < countries.size(); ++i) {
+ if (countries[i] && countries[i]->country_code() == country_code)
+ return true;
+ }
+
+ return false;
+}
+
SuggestionsMenuModel* AutofillDialogControllerImpl::
SuggestionsMenuModelForSection(DialogSection section) {
switch (section) {
@@ -3204,10 +3239,10 @@ DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel(
CountryComboboxModel* AutofillDialogControllerImpl::
CountryComboboxModelForSection(DialogSection section) {
if (section == SECTION_BILLING)
- return &billing_country_combobox_model_;
+ return billing_country_combobox_model_.get();
if (section == SECTION_SHIPPING)
- return &shipping_country_combobox_model_;
+ return shipping_country_combobox_model_.get();
return NULL;
}
@@ -3705,9 +3740,13 @@ void AutofillDialogControllerImpl::GetDefaultAutofillChoice(
// item.
SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
for (int i = 0; i < model->GetItemCount(); ++i) {
- if (IsASuggestionItemKey(model->GetItemKeyAt(i))) {
+ // Try the first suggestion item that is enabled.
+ if (IsASuggestionItemKey(model->GetItemKeyAt(i)) && model->IsEnabledAt(i)) {
+ *guid = model->GetItemKeyAt(i);
+ return;
+ // Fall back to the first non-suggestion key.
Ilya Sherman 2014/03/03 23:55:54 I think this code chooses the last non-suggestion
Evan Stade 2014/03/04 00:11:30 that's what the guid->empty() check is for
Ilya Sherman 2014/03/04 00:53:57 Ah, true dat. Maybe DCHECK at the beginning of th
+ } else if (!IsASuggestionItemKey(model->GetItemKeyAt(i)) && guid->empty()) {
*guid = model->GetItemKeyAt(i);
- break;
}
}
}

Powered by Google App Engine
This is Rietveld 408576698