| OLD | NEW |
| 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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 616 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
| 617 &has_types, &has_sections); | 617 &has_types, &has_sections); |
| 618 | 618 |
| 619 // Fail if the author didn't specify autocomplete types. | 619 // Fail if the author didn't specify autocomplete types. |
| 620 if (!has_types) { | 620 if (!has_types) { |
| 621 callback_.Run(NULL); | 621 callback_.Run(NULL); |
| 622 delete this; | 622 delete this; |
| 623 return; | 623 return; |
| 624 } | 624 } |
| 625 | 625 |
| 626 billing_country_combobox_model_.reset(new CountryComboboxModel( |
| 627 *GetManager(), |
| 628 form_structure_.PossibleValues(ADDRESS_BILLING_COUNTRY), |
| 629 false)); |
| 630 shipping_country_combobox_model_.reset(new CountryComboboxModel( |
| 631 *GetManager(), |
| 632 form_structure_.PossibleValues(ADDRESS_HOME_COUNTRY), |
| 633 false)); |
| 634 |
| 626 // Log any relevant UI metrics and security exceptions. | 635 // Log any relevant UI metrics and security exceptions. |
| 627 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN); | 636 GetMetricLogger().LogDialogUiEvent(AutofillMetrics::DIALOG_UI_SHOWN); |
| 628 | 637 |
| 629 GetMetricLogger().LogDialogSecurityMetric( | 638 GetMetricLogger().LogDialogSecurityMetric( |
| 630 AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN); | 639 AutofillMetrics::SECURITY_METRIC_DIALOG_SHOWN); |
| 631 | 640 |
| 632 // The Autofill dialog is shown in response to a message from the renderer and | 641 // The Autofill dialog is shown in response to a message from the renderer and |
| 633 // as such, it can only be made in the context of the current document. A call | 642 // as such, it can only be made in the context of the current document. A call |
| 634 // to GetActiveEntry would return a pending entry, if there was one, which | 643 // to GetActiveEntry would return a pending entry, if there was one, which |
| 635 // would be a security bug. Therefore, we use the last committed URL for the | 644 // would be a security bug. Therefore, we use the last committed URL for the |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( | 1363 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( |
| 1355 ServerFieldType type) { | 1364 ServerFieldType type) { |
| 1356 switch (type) { | 1365 switch (type) { |
| 1357 case CREDIT_CARD_EXP_MONTH: | 1366 case CREDIT_CARD_EXP_MONTH: |
| 1358 return &cc_exp_month_combobox_model_; | 1367 return &cc_exp_month_combobox_model_; |
| 1359 | 1368 |
| 1360 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 1369 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 1361 return &cc_exp_year_combobox_model_; | 1370 return &cc_exp_year_combobox_model_; |
| 1362 | 1371 |
| 1363 case ADDRESS_BILLING_COUNTRY: | 1372 case ADDRESS_BILLING_COUNTRY: |
| 1364 return &billing_country_combobox_model_; | 1373 return billing_country_combobox_model_.get(); |
| 1365 | 1374 |
| 1366 case ADDRESS_HOME_COUNTRY: | 1375 case ADDRESS_HOME_COUNTRY: |
| 1367 return &shipping_country_combobox_model_; | 1376 return shipping_country_combobox_model_.get(); |
| 1368 | 1377 |
| 1369 default: | 1378 default: |
| 1370 return NULL; | 1379 return NULL; |
| 1371 } | 1380 } |
| 1372 } | 1381 } |
| 1373 | 1382 |
| 1374 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( | 1383 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
| 1375 DialogSection section) { | 1384 DialogSection section) { |
| 1376 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1385 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1377 // The shipping section menu is special. It will always show because there is | 1386 // The shipping section menu is special. It will always show because there is |
| (...skipping 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2639 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2648 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 2640 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2649 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 2641 form_structure_(form_structure), | 2650 form_structure_(form_structure), |
| 2642 invoked_from_same_origin_(true), | 2651 invoked_from_same_origin_(true), |
| 2643 source_url_(source_url), | 2652 source_url_(source_url), |
| 2644 callback_(callback), | 2653 callback_(callback), |
| 2645 wallet_client_(profile_->GetRequestContext(), this, source_url), | 2654 wallet_client_(profile_->GetRequestContext(), this, source_url), |
| 2646 wallet_items_requested_(false), | 2655 wallet_items_requested_(false), |
| 2647 handling_use_wallet_link_click_(false), | 2656 handling_use_wallet_link_click_(false), |
| 2648 passive_failed_(false), | 2657 passive_failed_(false), |
| 2649 billing_country_combobox_model_(*GetManager(), false), | |
| 2650 shipping_country_combobox_model_(*GetManager(), false), | |
| 2651 suggested_cc_(this), | 2658 suggested_cc_(this), |
| 2652 suggested_billing_(this), | 2659 suggested_billing_(this), |
| 2653 suggested_cc_billing_(this), | 2660 suggested_cc_billing_(this), |
| 2654 suggested_shipping_(this), | 2661 suggested_shipping_(this), |
| 2655 cares_about_shipping_(true), | 2662 cares_about_shipping_(true), |
| 2656 popup_input_type_(UNKNOWN_TYPE), | 2663 popup_input_type_(UNKNOWN_TYPE), |
| 2657 waiting_for_explicit_sign_in_response_(false), | 2664 waiting_for_explicit_sign_in_response_(false), |
| 2658 has_accepted_legal_documents_(false), | 2665 has_accepted_legal_documents_(false), |
| 2659 is_submitting_(false), | 2666 is_submitting_(false), |
| 2660 choose_another_instrument_or_address_(false), | 2667 choose_another_instrument_or_address_(false), |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2796 | 2803 |
| 2797 if (shipping_same_as_billing) | 2804 if (shipping_same_as_billing) |
| 2798 suggested_shipping_.SetCheckedItem(kSameAsBillingKey); | 2805 suggested_shipping_.SetCheckedItem(kSameAsBillingKey); |
| 2799 | 2806 |
| 2800 for (size_t i = 0; i < addresses.size(); ++i) { | 2807 for (size_t i = 0; i < addresses.size(); ++i) { |
| 2801 std::string key = base::IntToString(i); | 2808 std::string key = base::IntToString(i); |
| 2802 suggested_shipping_.AddKeyedItemWithMinorText( | 2809 suggested_shipping_.AddKeyedItemWithMinorText( |
| 2803 key, | 2810 key, |
| 2804 addresses[i]->DisplayName(), | 2811 addresses[i]->DisplayName(), |
| 2805 addresses[i]->DisplayNameDetail()); | 2812 addresses[i]->DisplayNameDetail()); |
| 2813 suggested_shipping_.SetEnabled( |
| 2814 key, |
| 2815 CanAcceptCountry(SECTION_SHIPPING, |
| 2816 addresses[i]->country_name_code())); |
| 2806 | 2817 |
| 2807 // TODO(scr): Move this assignment outside the loop or comment why it | 2818 // TODO(scr): Move this assignment outside the loop or comment why it |
| 2808 // can't be there. | 2819 // can't be there. |
| 2809 const std::string default_shipping_address_id = | 2820 const std::string default_shipping_address_id = |
| 2810 GetIdToSelect(wallet_items_->default_address_id(), | 2821 GetIdToSelect(wallet_items_->default_address_id(), |
| 2811 previous_default_shipping_address_id_, | 2822 previous_default_shipping_address_id_, |
| 2812 previously_selected_shipping_address_id_); | 2823 previously_selected_shipping_address_id_); |
| 2813 | 2824 |
| 2814 if (!shipping_same_as_billing && | 2825 if (!shipping_same_as_billing && |
| 2815 addresses[i]->object_id() == default_shipping_address_id) { | 2826 addresses[i]->object_id() == default_shipping_address_id) { |
| 2816 suggested_shipping_.SetCheckedItem(key); | 2827 suggested_shipping_.SetCheckedItem(key); |
| 2817 } | 2828 } |
| 2818 } | 2829 } |
| 2819 | 2830 |
| 2820 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 2831 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
| 2821 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = | 2832 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = |
| 2822 wallet_items_->instruments(); | 2833 wallet_items_->instruments(); |
| 2823 std::string first_active_instrument_key; | 2834 std::string first_active_instrument_key; |
| 2824 std::string default_instrument_key; | 2835 std::string default_instrument_key; |
| 2825 for (size_t i = 0; i < instruments.size(); ++i) { | 2836 for (size_t i = 0; i < instruments.size(); ++i) { |
| 2826 bool allowed = IsInstrumentAllowed(*instruments[i]); | 2837 bool allowed = IsInstrumentAllowed(*instruments[i]) && |
| 2838 CanAcceptCountry(SECTION_BILLING, |
| 2839 instruments[i]->address().country_name_code()); |
| 2827 gfx::Image icon = instruments[i]->CardIcon(); | 2840 gfx::Image icon = instruments[i]->CardIcon(); |
| 2828 if (!allowed && !icon.IsEmpty()) { | 2841 if (!allowed && !icon.IsEmpty()) { |
| 2829 // Create a grayed disabled icon. | 2842 // Create a grayed disabled icon. |
| 2830 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | 2843 SkBitmap disabled_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
| 2831 *icon.ToSkBitmap(), kGrayImageShift); | 2844 *icon.ToSkBitmap(), kGrayImageShift); |
| 2832 icon = gfx::Image( | 2845 icon = gfx::Image( |
| 2833 gfx::ImageSkia::CreateFrom1xBitmap(disabled_bitmap)); | 2846 gfx::ImageSkia::CreateFrom1xBitmap(disabled_bitmap)); |
| 2834 } | 2847 } |
| 2835 std::string key = base::IntToString(i); | 2848 std::string key = base::IntToString(i); |
| 2836 suggested_cc_billing_.AddKeyedItemWithMinorTextAndIcon( | 2849 suggested_cc_billing_.AddKeyedItemWithMinorTextAndIcon( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2895 const AutofillProfile& profile = *profiles[i]; | 2908 const AutofillProfile& profile = *profiles[i]; |
| 2896 if (!i18ninput::AddressHasCompleteAndVerifiedData(profile) || | 2909 if (!i18ninput::AddressHasCompleteAndVerifiedData(profile) || |
| 2897 !i18ninput::CountryIsFullySupported( | 2910 !i18ninput::CountryIsFullySupported( |
| 2898 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))) { | 2911 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))) { |
| 2899 continue; | 2912 continue; |
| 2900 } | 2913 } |
| 2901 | 2914 |
| 2902 // Don't add variants for addresses: name is part of credit card and | 2915 // Don't add variants for addresses: name is part of credit card and |
| 2903 // we'll just ignore email and phone number variants. | 2916 // we'll just ignore email and phone number variants. |
| 2904 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); | 2917 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); |
| 2918 suggested_shipping_.SetEnabled( |
| 2919 profile.guid(), |
| 2920 CanAcceptCountry( |
| 2921 SECTION_SHIPPING, |
| 2922 base::UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))); |
| 2905 if (!profile.GetRawInfo(EMAIL_ADDRESS).empty() && | 2923 if (!profile.GetRawInfo(EMAIL_ADDRESS).empty() && |
| 2906 !profile.IsPresentButInvalid(EMAIL_ADDRESS)) { | 2924 !profile.IsPresentButInvalid(EMAIL_ADDRESS)) { |
| 2907 suggested_billing_.AddKeyedItem(profile.guid(), labels[i]); | 2925 suggested_billing_.AddKeyedItem(profile.guid(), labels[i]); |
| 2926 suggested_billing_.SetEnabled( |
| 2927 profile.guid(), |
| 2928 CanAcceptCountry( |
| 2929 SECTION_BILLING, |
| 2930 base::UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))); |
| 2908 } | 2931 } |
| 2909 } | 2932 } |
| 2910 } | 2933 } |
| 2911 | 2934 |
| 2912 suggested_cc_.AddKeyedItem( | 2935 suggested_cc_.AddKeyedItem( |
| 2913 kAddNewItemKey, | 2936 kAddNewItemKey, |
| 2914 l10n_util::GetStringUTF16(IsAutofillEnabled() ? | 2937 l10n_util::GetStringUTF16(IsAutofillEnabled() ? |
| 2915 IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD : | 2938 IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD : |
| 2916 IDS_AUTOFILL_DIALOG_ENTER_CREDIT_CARD)); | 2939 IDS_AUTOFILL_DIALOG_ENTER_CREDIT_CARD)); |
| 2917 suggested_cc_.AddKeyedItem( | 2940 suggested_cc_.AddKeyedItem( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3104 | 3127 |
| 3105 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 3128 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 3106 if (wrapper) | 3129 if (wrapper) |
| 3107 return wrapper->GetInfo(AutofillType(type)); | 3130 return wrapper->GetInfo(AutofillType(type)); |
| 3108 | 3131 |
| 3109 FieldValueMap output; | 3132 FieldValueMap output; |
| 3110 view_->GetUserInput(section, &output); | 3133 view_->GetUserInput(section, &output); |
| 3111 return output[type]; | 3134 return output[type]; |
| 3112 } | 3135 } |
| 3113 | 3136 |
| 3137 bool AutofillDialogControllerImpl::CanAcceptCountry( |
| 3138 DialogSection section, |
| 3139 const std::string& country_code) { |
| 3140 CountryComboboxModel* model = CountryComboboxModelForSection(section); |
| 3141 const std::vector<AutofillCountry*>& countries = model->countries(); |
| 3142 for (size_t i = 0; i < countries.size(); ++i) { |
| 3143 if (countries[i] && countries[i]->country_code() == country_code) |
| 3144 return true; |
| 3145 } |
| 3146 |
| 3147 return false; |
| 3148 } |
| 3149 |
| 3114 SuggestionsMenuModel* AutofillDialogControllerImpl:: | 3150 SuggestionsMenuModel* AutofillDialogControllerImpl:: |
| 3115 SuggestionsMenuModelForSection(DialogSection section) { | 3151 SuggestionsMenuModelForSection(DialogSection section) { |
| 3116 switch (section) { | 3152 switch (section) { |
| 3117 case SECTION_CC: | 3153 case SECTION_CC: |
| 3118 return &suggested_cc_; | 3154 return &suggested_cc_; |
| 3119 case SECTION_BILLING: | 3155 case SECTION_BILLING: |
| 3120 return &suggested_billing_; | 3156 return &suggested_billing_; |
| 3121 case SECTION_SHIPPING: | 3157 case SECTION_SHIPPING: |
| 3122 return &suggested_shipping_; | 3158 return &suggested_shipping_; |
| 3123 case SECTION_CC_BILLING: | 3159 case SECTION_CC_BILLING: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3145 if (&model == &suggested_cc_billing_) | 3181 if (&model == &suggested_cc_billing_) |
| 3146 return SECTION_CC_BILLING; | 3182 return SECTION_CC_BILLING; |
| 3147 | 3183 |
| 3148 DCHECK_EQ(&model, &suggested_shipping_); | 3184 DCHECK_EQ(&model, &suggested_shipping_); |
| 3149 return SECTION_SHIPPING; | 3185 return SECTION_SHIPPING; |
| 3150 } | 3186 } |
| 3151 | 3187 |
| 3152 CountryComboboxModel* AutofillDialogControllerImpl:: | 3188 CountryComboboxModel* AutofillDialogControllerImpl:: |
| 3153 CountryComboboxModelForSection(DialogSection section) { | 3189 CountryComboboxModelForSection(DialogSection section) { |
| 3154 if (section == SECTION_BILLING) | 3190 if (section == SECTION_BILLING) |
| 3155 return &billing_country_combobox_model_; | 3191 return billing_country_combobox_model_.get(); |
| 3156 | 3192 |
| 3157 if (section == SECTION_SHIPPING) | 3193 if (section == SECTION_SHIPPING) |
| 3158 return &shipping_country_combobox_model_; | 3194 return shipping_country_combobox_model_.get(); |
| 3159 | 3195 |
| 3160 return NULL; | 3196 return NULL; |
| 3161 } | 3197 } |
| 3162 | 3198 |
| 3163 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 3199 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| 3164 DialogSection section) { | 3200 DialogSection section) { |
| 3165 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 3201 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 3166 } | 3202 } |
| 3167 | 3203 |
| 3168 std::vector<ServerFieldType> AutofillDialogControllerImpl:: | 3204 std::vector<ServerFieldType> AutofillDialogControllerImpl:: |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3637 } | 3673 } |
| 3638 | 3674 |
| 3639 void AutofillDialogControllerImpl::GetDefaultAutofillChoice( | 3675 void AutofillDialogControllerImpl::GetDefaultAutofillChoice( |
| 3640 DialogSection section, | 3676 DialogSection section, |
| 3641 std::string* guid) { | 3677 std::string* guid) { |
| 3642 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled()); | 3678 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled()); |
| 3643 // The default choice is the first thing in the menu that is a suggestion | 3679 // The default choice is the first thing in the menu that is a suggestion |
| 3644 // item. | 3680 // item. |
| 3645 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 3681 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 3646 for (int i = 0; i < model->GetItemCount(); ++i) { | 3682 for (int i = 0; i < model->GetItemCount(); ++i) { |
| 3647 if (IsASuggestionItemKey(model->GetItemKeyAt(i))) { | 3683 // Try the first suggestion item that is enabled. |
| 3684 if (IsASuggestionItemKey(model->GetItemKeyAt(i)) && model->IsEnabledAt(i)) { |
| 3648 *guid = model->GetItemKeyAt(i); | 3685 *guid = model->GetItemKeyAt(i); |
| 3649 break; | 3686 return; |
| 3687 // Fall back to the first non-suggestion key. |
| 3688 } else if (!IsASuggestionItemKey(model->GetItemKeyAt(i)) && guid->empty()) { |
| 3689 *guid = model->GetItemKeyAt(i); |
| 3650 } | 3690 } |
| 3651 } | 3691 } |
| 3652 } | 3692 } |
| 3653 | 3693 |
| 3654 bool AutofillDialogControllerImpl::GetAutofillChoice(DialogSection section, | 3694 bool AutofillDialogControllerImpl::GetAutofillChoice(DialogSection section, |
| 3655 std::string* guid) { | 3695 std::string* guid) { |
| 3656 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled()); | 3696 DCHECK(!IsPayingWithWallet() && IsAutofillEnabled()); |
| 3657 const base::DictionaryValue* choices = profile()->GetPrefs()->GetDictionary( | 3697 const base::DictionaryValue* choices = profile()->GetPrefs()->GetDictionary( |
| 3658 ::prefs::kAutofillDialogAutofillDefault); | 3698 ::prefs::kAutofillDialogAutofillDefault); |
| 3659 if (!choices) | 3699 if (!choices) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3807 view_->UpdateButtonStrip(); | 3847 view_->UpdateButtonStrip(); |
| 3808 } | 3848 } |
| 3809 | 3849 |
| 3810 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3850 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 3811 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3851 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3812 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3852 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3813 signin_helper_->StartWalletCookieValueFetch(); | 3853 signin_helper_->StartWalletCookieValueFetch(); |
| 3814 } | 3854 } |
| 3815 | 3855 |
| 3816 } // namespace autofill | 3856 } // namespace autofill |
| OLD | NEW |