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

Side by Side 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: 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill_dialog_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 form_structure_.ParseFieldTypesFromAutocompleteAttributes( 626 form_structure_.ParseFieldTypesFromAutocompleteAttributes(
627 &has_types, &has_sections); 627 &has_types, &has_sections);
628 628
629 // Fail if the author didn't specify autocomplete types. 629 // Fail if the author didn't specify autocomplete types.
630 if (!has_types) { 630 if (!has_types) {
631 callback_.Run(NULL); 631 callback_.Run(NULL);
632 delete this; 632 delete this;
633 return; 633 return;
634 } 634 }
635 635
636 billing_country_combobox_model_.reset(new CountryComboboxModel(
637 *GetManager(),
638 form_structure_.PossibleValues(ADDRESS_BILLING_COUNTRY),
639 false));
640 shipping_country_combobox_model_.reset(new CountryComboboxModel(
641 *GetManager(),
642 form_structure_.PossibleValues(ADDRESS_HOME_COUNTRY),
643 false));
644
636 // Log any relevant UI metrics and security exceptions. 645 // Log any relevant UI metrics and security exceptions.
637 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN); 646 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN);
638 647
639 GetMetricLogger().LogDialogSecurityMetric( 648 GetMetricLogger().LogDialogSecurityMetric(
640 AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN); 649 AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN);
641 650
642 // The Autofill dialog is shown in response to a message from the renderer and 651 // The Autofill dialog is shown in response to a message from the renderer and
643 // as such, it can only be made in the context of the current document. A call 652 // as such, it can only be made in the context of the current document. A call
644 // to GetActiveEntry would return a pending entry, if there was one, which 653 // to GetActiveEntry would return a pending entry, if there was one, which
645 // would be a security bug. Therefore, we use the last committed URL for the 654 // would be a security bug. Therefore, we use the last committed URL for the
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( 1377 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType(
1369 ServerFieldType type) { 1378 ServerFieldType type) {
1370 switch (type) { 1379 switch (type) {
1371 case CREDIT_CARD_EXP_MONTH: 1380 case CREDIT_CARD_EXP_MONTH:
1372 return &cc_exp_month_combobox_model_; 1381 return &cc_exp_month_combobox_model_;
1373 1382
1374 case CREDIT_CARD_EXP_4_DIGIT_YEAR: 1383 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
1375 return &cc_exp_year_combobox_model_; 1384 return &cc_exp_year_combobox_model_;
1376 1385
1377 case ADDRESS_BILLING_COUNTRY: 1386 case ADDRESS_BILLING_COUNTRY:
1378 return &billing_country_combobox_model_; 1387 return billing_country_combobox_model_.get();
1379 1388
1380 case ADDRESS_HOME_COUNTRY: 1389 case ADDRESS_HOME_COUNTRY:
1381 return &shipping_country_combobox_model_; 1390 return shipping_country_combobox_model_.get();
1382 1391
1383 default: 1392 default:
1384 return NULL; 1393 return NULL;
1385 } 1394 }
1386 } 1395 }
1387 1396
1388 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( 1397 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection(
1389 DialogSection section) { 1398 DialogSection section) {
1390 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 1399 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
1391 // The shipping section menu is special. It will always show because there is 1400 // The shipping section menu is special. It will always show because there is
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), 2699 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())),
2691 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), 2700 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN),
2692 form_structure_(form_structure), 2701 form_structure_(form_structure),
2693 invoked_from_same_origin_(true), 2702 invoked_from_same_origin_(true),
2694 source_url_(source_url), 2703 source_url_(source_url),
2695 callback_(callback), 2704 callback_(callback),
2696 wallet_client_(profile_->GetRequestContext(), this, source_url), 2705 wallet_client_(profile_->GetRequestContext(), this, source_url),
2697 wallet_items_requested_(false), 2706 wallet_items_requested_(false),
2698 handling_use_wallet_link_click_(false), 2707 handling_use_wallet_link_click_(false),
2699 passive_failed_(false), 2708 passive_failed_(false),
2700 billing_country_combobox_model_(*GetManager(), false),
2701 shipping_country_combobox_model_(*GetManager(), false),
2702 suggested_cc_(this), 2709 suggested_cc_(this),
2703 suggested_billing_(this), 2710 suggested_billing_(this),
2704 suggested_cc_billing_(this), 2711 suggested_cc_billing_(this),
2705 suggested_shipping_(this), 2712 suggested_shipping_(this),
2706 cares_about_shipping_(true), 2713 cares_about_shipping_(true),
2707 popup_input_type_(UNKNOWN_TYPE), 2714 popup_input_type_(UNKNOWN_TYPE),
2708 waiting_for_explicit_sign_in_response_(false), 2715 waiting_for_explicit_sign_in_response_(false),
2709 has_accepted_legal_documents_(false), 2716 has_accepted_legal_documents_(false),
2710 is_submitting_(false), 2717 is_submitting_(false),
2711 choose_another_instrument_or_address_(false), 2718 choose_another_instrument_or_address_(false),
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 2854
2848 if (shipping_same_as_billing) 2855 if (shipping_same_as_billing)
2849 suggested_shipping_.SetCheckedItem(kSameAsBillingKey); 2856 suggested_shipping_.SetCheckedItem(kSameAsBillingKey);
2850 2857
2851 for (size_t i = 0; i < addresses.size(); ++i) { 2858 for (size_t i = 0; i < addresses.size(); ++i) {
2852 std::string key = base::IntToString(i); 2859 std::string key = base::IntToString(i);
2853 suggested_shipping_.AddKeyedItemWithMinorText( 2860 suggested_shipping_.AddKeyedItemWithMinorText(
2854 key, 2861 key,
2855 addresses[i]->DisplayName(), 2862 addresses[i]->DisplayName(),
2856 addresses[i]->DisplayNameDetail()); 2863 addresses[i]->DisplayNameDetail());
2864 suggested_shipping_.SetEnabled(
2865 key,
2866 CanAcceptCountry(SECTION_SHIPPING,
2867 addresses[i]->country_name_code()));
2857 2868
2858 // TODO(scr): Move this assignment outside the loop or comment why it 2869 // TODO(scr): Move this assignment outside the loop or comment why it
2859 // can't be there. 2870 // can't be there.
2860 const std::string default_shipping_address_id = 2871 const std::string default_shipping_address_id =
2861 GetIdToSelect(wallet_items_->default_address_id(), 2872 GetIdToSelect(wallet_items_->default_address_id(),
2862 previous_default_shipping_address_id_, 2873 previous_default_shipping_address_id_,
2863 previously_selected_shipping_address_id_); 2874 previously_selected_shipping_address_id_);
2864 2875
2865 if (!shipping_same_as_billing && 2876 if (!shipping_same_as_billing &&
2866 addresses[i]->object_id() == default_shipping_address_id) { 2877 addresses[i]->object_id() == default_shipping_address_id) {
2867 suggested_shipping_.SetCheckedItem(key); 2878 suggested_shipping_.SetCheckedItem(key);
2868 } 2879 }
2869 } 2880 }
2870 2881
2871 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { 2882 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
2872 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = 2883 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments =
2873 wallet_items_->instruments(); 2884 wallet_items_->instruments();
2874 std::string first_active_instrument_key; 2885 std::string first_active_instrument_key;
2875 std::string default_instrument_key; 2886 std::string default_instrument_key;
2876 for (size_t i = 0; i < instruments.size(); ++i) { 2887 for (size_t i = 0; i < instruments.size(); ++i) {
2877 bool allowed = IsInstrumentAllowed(*instruments[i]); 2888 bool allowed = IsInstrumentAllowed(*instruments[i]) &&
2889 CanAcceptCountry(SECTION_BILLING,
2890 instruments[i]->address().country_name_code());
2878 gfx::Image icon = instruments[i]->CardIcon(); 2891 gfx::Image icon = instruments[i]->CardIcon();
2879 if (!allowed && !icon.IsEmpty()) { 2892 if (!allowed && !icon.IsEmpty()) {
2880 // Create a grayed disabled icon. 2893 // Create a grayed disabled icon.
2881 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( 2894 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap(
2882 *icon.ToSkBitmap(), kGrayImageShift); 2895 *icon.ToSkBitmap(), kGrayImageShift);
2883 icon = gfx::Image( 2896 icon = gfx::Image(
2884 gfx::ImageSkia::CreateFrom1xBitmap(disabled_bitmap)); 2897 gfx::ImageSkia::CreateFrom1xBitmap(disabled_bitmap));
2885 } 2898 }
2886 std::string key = base::IntToString(i); 2899 std::string key = base::IntToString(i);
2887 suggested_cc_billing_.AddKeyedItemWithMinorTextAndIcon( 2900 suggested_cc_billing_.AddKeyedItemWithMinorTextAndIcon(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2938 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); 2951 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type())));
2939 } 2952 }
2940 2953
2941 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); 2954 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
2942 std::vector<base::string16> labels; 2955 std::vector<base::string16> labels;
2943 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); 2956 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels);
2944 DCHECK_EQ(labels.size(), profiles.size()); 2957 DCHECK_EQ(labels.size(), profiles.size());
2945 for (size_t i = 0; i < profiles.size(); ++i) { 2958 for (size_t i = 0; i < profiles.size(); ++i) {
2946 const AutofillProfile& profile = *profiles[i]; 2959 const AutofillProfile& profile = *profiles[i];
2947 if (!i18ninput::AddressHasCompleteAndVerifiedData(profile) || 2960 if (!i18ninput::AddressHasCompleteAndVerifiedData(profile) ||
2948 !i18ninput::CountryIsFullySupported(
2949 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))) ||
2950 (!i18ninput::Enabled() && HasInvalidAddress(*profiles[i]))) { 2961 (!i18ninput::Enabled() && HasInvalidAddress(*profiles[i]))) {
2951 continue; 2962 continue;
2952 } 2963 }
2953 2964
2954 // Don't add variants for addresses: name is part of credit card and 2965 // Don't add variants for addresses: name is part of credit card and
2955 // we'll just ignore email and phone number variants. 2966 // we'll just ignore email and phone number variants.
2956 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); 2967 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]);
2968 suggested_shipping_.SetEnabled(
2969 profile.guid(),
2970 CanAcceptCountry(
2971 SECTION_SHIPPING,
2972 UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))));
2957 if (!profile.GetRawInfo(EMAIL_ADDRESS).empty() && 2973 if (!profile.GetRawInfo(EMAIL_ADDRESS).empty() &&
2958 !profile.IsPresentButInvalid(EMAIL_ADDRESS)) { 2974 !profile.IsPresentButInvalid(EMAIL_ADDRESS)) {
2959 suggested_billing_.AddKeyedItem(profile.guid(), labels[i]); 2975 suggested_billing_.AddKeyedItem(profile.guid(), labels[i]);
2976 suggested_billing_.SetEnabled(
2977 profile.guid(),
2978 CanAcceptCountry(
2979 SECTION_BILLING,
2980 UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))));
2960 } 2981 }
2961 } 2982 }
2962 } 2983 }
2963 2984
2964 suggested_cc_.AddKeyedItem( 2985 suggested_cc_.AddKeyedItem(
2965 kAddNewItemKey, 2986 kAddNewItemKey,
2966 l10n_util::GetStringUTF16(IsAutofillEnabled() ? 2987 l10n_util::GetStringUTF16(IsAutofillEnabled() ?
2967 IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD : 2988 IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD :
2968 IDS_AUTOFILL_DIALOG_ENTER_CREDIT_CARD)); 2989 IDS_AUTOFILL_DIALOG_ENTER_CREDIT_CARD));
2969 suggested_cc_.AddKeyedItem( 2990 suggested_cc_.AddKeyedItem(
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3156 3177
3157 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 3178 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
3158 if (wrapper) 3179 if (wrapper)
3159 return wrapper->GetInfo(AutofillType(type)); 3180 return wrapper->GetInfo(AutofillType(type));
3160 3181
3161 FieldValueMap output; 3182 FieldValueMap output;
3162 view_->GetUserInput(section, &output); 3183 view_->GetUserInput(section, &output);
3163 return output[type]; 3184 return output[type];
3164 } 3185 }
3165 3186
3187 bool AutofillDialogControllerImpl::CanAcceptCountry(
3188 DialogSection section,
3189 const std::string& country_code) {
3190 CountryComboboxModel* model = CountryComboboxModelForSection(section);
3191 const std::vector<AutofillCountry*>& countries = model->countries();
3192 for (size_t i = 0; i < countries.size(); ++i) {
3193 if (countries[i] && countries[i]->country_code() == country_code)
3194 return true;
3195 }
3196
3197 return false;
3198 }
3199
3166 SuggestionsMenuModel* AutofillDialogControllerImpl:: 3200 SuggestionsMenuModel* AutofillDialogControllerImpl::
3167 SuggestionsMenuModelForSection(DialogSection section) { 3201 SuggestionsMenuModelForSection(DialogSection section) {
3168 switch (section) { 3202 switch (section) {
3169 case SECTION_CC: 3203 case SECTION_CC:
3170 return &suggested_cc_; 3204 return &suggested_cc_;
3171 case SECTION_BILLING: 3205 case SECTION_BILLING:
3172 return &suggested_billing_; 3206 return &suggested_billing_;
3173 case SECTION_SHIPPING: 3207 case SECTION_SHIPPING:
3174 return &suggested_shipping_; 3208 return &suggested_shipping_;
3175 case SECTION_CC_BILLING: 3209 case SECTION_CC_BILLING:
(...skipping 21 matching lines...) Expand all
3197 if (&model == &suggested_cc_billing_) 3231 if (&model == &suggested_cc_billing_)
3198 return SECTION_CC_BILLING; 3232 return SECTION_CC_BILLING;
3199 3233
3200 DCHECK_EQ(&model, &suggested_shipping_); 3234 DCHECK_EQ(&model, &suggested_shipping_);
3201 return SECTION_SHIPPING; 3235 return SECTION_SHIPPING;
3202 } 3236 }
3203 3237
3204 CountryComboboxModel* AutofillDialogControllerImpl:: 3238 CountryComboboxModel* AutofillDialogControllerImpl::
3205 CountryComboboxModelForSection(DialogSection section) { 3239 CountryComboboxModelForSection(DialogSection section) {
3206 if (section == SECTION_BILLING) 3240 if (section == SECTION_BILLING)
3207 return &billing_country_combobox_model_; 3241 return billing_country_combobox_model_.get();
3208 3242
3209 if (section == SECTION_SHIPPING) 3243 if (section == SECTION_SHIPPING)
3210 return &shipping_country_combobox_model_; 3244 return shipping_country_combobox_model_.get();
3211 3245
3212 return NULL; 3246 return NULL;
3213 } 3247 }
3214 3248
3215 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( 3249 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
3216 DialogSection section) { 3250 DialogSection section) {
3217 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); 3251 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
3218 } 3252 }
3219 3253
3220 std::vector<ServerFieldType> AutofillDialogControllerImpl:: 3254 std::vector<ServerFieldType> AutofillDialogControllerImpl::
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 } 3732 }
3699 3733
3700 void AutofillDialogControllerImpl::GetDefaultAutofillChoice( 3734 void AutofillDialogControllerImpl::GetDefaultAutofillChoice(
3701 DialogSection section, 3735 DialogSection section,
3702 std::string* guid) { 3736 std::string* guid) {
3703 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled()); 3737 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled());
3704 // The default choice is the first thing in the menu that is a suggestion 3738 // The default choice is the first thing in the menu that is a suggestion
3705 // item. 3739 // item.
3706 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 3740 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
3707 for (int i = 0; i < model->GetItemCount(); ++i) { 3741 for (int i = 0; i < model->GetItemCount(); ++i) {
3708 if (IsASuggestionItemKey(model->GetItemKeyAt(i))) { 3742 // Try the first suggestion item that is enabled.
3743 if (IsASuggestionItemKey(model->GetItemKeyAt(i)) && model->IsEnabledAt(i)) {
3709 *guid = model->GetItemKeyAt(i); 3744 *guid = model->GetItemKeyAt(i);
3710 break; 3745 return;
3746 // Fall back to the first non-suggestion key.
3747 } else if (!IsASuggestionItemKey(model->GetItemKeyAt(i)) && guid->empty()) {
3748 *guid = model->GetItemKeyAt(i);
3711 } 3749 }
3712 } 3750 }
3713 } 3751 }
3714 3752
3715 bool AutofillDialogControllerImpl::GetAutofillChoice(DialogSection section, 3753 bool AutofillDialogControllerImpl::GetAutofillChoice(DialogSection section,
3716 std::string* guid) { 3754 std::string* guid) {
3717 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled()); 3755 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled());
3718 const base::DictionaryValue* choices = profile()->GetPrefs()->GetDictionary( 3756 const base::DictionaryValue* choices = profile()->GetPrefs()->GetDictionary(
3719 ::prefs::kAutofillDialogAutofillDefault); 3757 ::prefs::kAutofillDialogAutofillDefault);
3720 if (!choices) 3758 if (!choices)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
3868 view_->UpdateButtonStrip(); 3906 view_->UpdateButtonStrip();
3869 } 3907 }
3870 3908
3871 void AutofillDialogControllerImpl::FetchWalletCookie() { 3909 void AutofillDialogControllerImpl::FetchWalletCookie() {
3872 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 3910 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
3873 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 3911 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
3874 signin_helper_->StartWalletCookieValueFetch(); 3912 signin_helper_->StartWalletCookieValueFetch();
3875 } 3913 }
3876 3914
3877 } // namespace autofill 3915 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698