Chromium Code Reviews| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 if (view_) | 134 if (view_) |
| 135 view_->UpdatesFinished(); | 135 view_->UpdatesFinished(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 AutofillDialogView* view_; | 139 AutofillDialogView* view_; |
| 140 | 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(ScopedViewUpdates); | 141 DISALLOW_COPY_AND_ASSIGN(ScopedViewUpdates); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 base::string16 NullGetInfo(const AutofillType& type) { | |
| 145 return base::string16(); | |
| 146 } | |
| 147 | |
| 144 // Returns true if |input| should be used to fill a site-requested |field| which | 148 // Returns true if |input| should be used to fill a site-requested |field| which |
| 145 // is notated with a "shipping" tag, for use when the user has decided to use | 149 // is notated with a "shipping" tag, for use when the user has decided to use |
| 146 // the billing address as the shipping address. | 150 // the billing address as the shipping address. |
| 147 bool ServerTypeMatchesShippingField(ServerFieldType type, | 151 bool ServerTypeMatchesShippingField(ServerFieldType type, |
| 148 const AutofillField& field) { | 152 const AutofillField& field) { |
| 149 // Equivalent billing field type is used to support UseBillingAsShipping | 153 // Equivalent billing field type is used to support UseBillingAsShipping |
| 150 // usecase. | 154 // usecase. |
| 151 return common::ServerTypeMatchesFieldType( | 155 return common::ServerTypeMatchesFieldType( |
| 152 type, | 156 type, |
| 153 AutofillType(AutofillType::GetEquivalentBillingFieldType( | 157 AutofillType(AutofillType::GetEquivalentBillingFieldType( |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 CountryComboboxModel* model = CountryComboboxModelForSection(section); | 596 CountryComboboxModel* model = CountryComboboxModelForSection(section); |
| 593 if (model) | 597 if (model) |
| 594 country_code = model->GetDefaultCountryCode(); | 598 country_code = model->GetDefaultCountryCode(); |
| 595 | 599 |
| 596 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 600 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 597 common::BuildInputsForSection(section, country_code, inputs); | 601 common::BuildInputsForSection(section, country_code, inputs); |
| 598 } | 602 } |
| 599 | 603 |
| 600 // Test whether we need to show the shipping section. If filling that section | 604 // Test whether we need to show the shipping section. If filling that section |
| 601 // would be a no-op, don't show it. | 605 // would be a no-op, don't show it. |
| 602 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); | 606 cares_about_shipping_ = form_structure_.FillFields( |
| 603 cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure( | 607 RequestedTypesForSection(SECTION_SHIPPING), |
| 604 inputs, | |
| 605 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), | 608 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), |
| 606 &form_structure_); | 609 base::Bind(NullGetInfo), |
| 610 g_browser_process->GetApplicationLocale()); | |
| 607 | 611 |
| 608 account_chooser_model_.reset( | 612 account_chooser_model_.reset( |
| 609 new AccountChooserModel(this, | 613 new AccountChooserModel(this, |
| 610 profile_, | 614 profile_, |
| 611 !ShouldShowAccountChooser(), | 615 !ShouldShowAccountChooser(), |
| 612 metric_logger_)); | 616 metric_logger_)); |
| 613 | 617 |
| 614 if (account_chooser_model_->WalletIsSelected()) | 618 if (account_chooser_model_->WalletIsSelected()) |
| 615 FetchWalletCookie(); | 619 FetchWalletCookie(); |
| 616 | 620 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 | 784 |
| 781 const SkColor start_top_color = SkColorSetRGB(0xD6, 0xD6, 0xD6); | 785 const SkColor start_top_color = SkColorSetRGB(0xD6, 0xD6, 0xD6); |
| 782 const SkColor start_bottom_color = SkColorSetRGB(0x98, 0x98, 0x98); | 786 const SkColor start_bottom_color = SkColorSetRGB(0x98, 0x98, 0x98); |
| 783 const SkColor final_top_color = SkColorSetRGB(0x52, 0x9F, 0xF8); | 787 const SkColor final_top_color = SkColorSetRGB(0x52, 0x9F, 0xF8); |
| 784 const SkColor final_bottom_color = SkColorSetRGB(0x22, 0x75, 0xE5); | 788 const SkColor final_bottom_color = SkColorSetRGB(0x22, 0x75, 0xE5); |
| 785 | 789 |
| 786 if (full_wallet_ && full_wallet_->required_actions().empty()) { | 790 if (full_wallet_ && full_wallet_->required_actions().empty()) { |
| 787 card_scrambling_delay_.Stop(); | 791 card_scrambling_delay_.Stop(); |
| 788 card_scrambling_refresher_.Stop(); | 792 card_scrambling_refresher_.Stop(); |
| 789 | 793 |
| 790 base::string16 cc_number = | 794 base::string16 cc_number = base::ASCIIToUTF16(full_wallet_->GetPan()); |
|
Dan Beam
2014/01/27 20:51:40
if you need this as a string16 anyways i'd just le
| |
| 791 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); | |
| 792 DCHECK_GE(cc_number.size(), 4U); | 795 DCHECK_GE(cc_number.size(), 4U); |
| 793 state.image = GetGeneratedCardImage( | 796 state.image = GetGeneratedCardImage( |
| 794 base::ASCIIToUTF16("XXXX XXXX XXXX ") + | 797 base::ASCIIToUTF16("XXXX XXXX XXXX ") + |
| 795 cc_number.substr(cc_number.size() - 4), | 798 cc_number.substr(cc_number.size() - 4), |
| 796 full_wallet_->billing_address()->recipient_name(), | 799 full_wallet_->billing_address()->recipient_name(), |
| 797 color_utils::AlphaBlend( | 800 color_utils::AlphaBlend( |
| 798 final_top_color, | 801 final_top_color, |
| 799 start_top_color, | 802 start_top_color, |
| 800 255 * card_generated_animation_.GetCurrentValue()), | 803 255 * card_generated_animation_.GetCurrentValue()), |
| 801 color_utils::AlphaBlend( | 804 color_utils::AlphaBlend( |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1881 | 1884 |
| 1882 std::vector<base::string16> popup_values, popup_labels, popup_icons; | 1885 std::vector<base::string16> popup_values, popup_labels, popup_icons; |
| 1883 if (common::IsCreditCardType(type)) { | 1886 if (common::IsCreditCardType(type)) { |
| 1884 GetManager()->GetCreditCardSuggestions(AutofillType(type), | 1887 GetManager()->GetCreditCardSuggestions(AutofillType(type), |
| 1885 field_contents, | 1888 field_contents, |
| 1886 &popup_values, | 1889 &popup_values, |
| 1887 &popup_labels, | 1890 &popup_labels, |
| 1888 &popup_icons, | 1891 &popup_icons, |
| 1889 &popup_guids_); | 1892 &popup_guids_); |
| 1890 } else { | 1893 } else { |
| 1891 std::vector<ServerFieldType> field_types; | 1894 std::vector<ServerFieldType> field_types = |
| 1892 const DetailInputs& inputs = RequestedFieldsForSection(section); | 1895 RequestedTypesForSection(section); |
| 1893 for (DetailInputs::const_iterator iter = inputs.begin(); | |
| 1894 iter != inputs.end(); ++iter) { | |
| 1895 field_types.push_back(iter->type); | |
| 1896 } | |
| 1897 GetManager()->GetProfileSuggestions(AutofillType(type), | 1896 GetManager()->GetProfileSuggestions(AutofillType(type), |
| 1898 field_contents, | 1897 field_contents, |
| 1899 false, | 1898 false, |
| 1900 field_types, | 1899 field_types, |
| 1901 &popup_values, | 1900 &popup_values, |
| 1902 &popup_labels, | 1901 &popup_labels, |
| 1903 &popup_icons, | 1902 &popup_icons, |
| 1904 &popup_guids_); | 1903 &popup_guids_); |
| 1905 } | 1904 } |
| 1906 | 1905 |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2899 | 2898 |
| 2900 ShowEditUiIfBadSuggestion(section); | 2899 ShowEditUiIfBadSuggestion(section); |
| 2901 UpdateSection(section); | 2900 UpdateSection(section); |
| 2902 } | 2901 } |
| 2903 | 2902 |
| 2904 UpdateForErrors(); | 2903 UpdateForErrors(); |
| 2905 } | 2904 } |
| 2906 | 2905 |
| 2907 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 2906 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| 2908 DialogSection section, | 2907 DialogSection section, |
| 2909 const InputFieldComparator& compare) { | 2908 const FormStructure::InputFieldComparator& compare) { |
| 2910 if (!SectionIsActive(section)) | 2909 if (!SectionIsActive(section)) |
| 2911 return; | 2910 return; |
| 2912 | 2911 |
| 2913 DetailInputs inputs; | 2912 DetailInputs inputs; |
| 2914 std::string country_code = CountryCodeForSection(section); | 2913 std::string country_code = CountryCodeForSection(section); |
| 2915 common::BuildInputsForSection(section, country_code, &inputs); | 2914 common::BuildInputsForSection(section, country_code, &inputs); |
| 2915 std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); | |
| 2916 | 2916 |
| 2917 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 2917 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 2918 if (wrapper) { | 2918 if (wrapper) { |
| 2919 // Only fill in data that is associated with this section. | 2919 // Only fill in data that is associated with this section. |
| 2920 wrapper->FillFormStructure(inputs, compare, &form_structure_); | 2920 wrapper->FillFormStructure(types, compare, &form_structure_); |
| 2921 | 2921 |
| 2922 // CVC needs special-casing because the CreditCard class doesn't store or | 2922 // CVC needs special-casing because the CreditCard class doesn't store or |
| 2923 // handle them. This isn't necessary when filling the combined CC and | 2923 // handle them. This isn't necessary when filling the combined CC and |
| 2924 // billing section as CVC comes from |full_wallet_| in this case. | 2924 // billing section as CVC comes from |full_wallet_| in this case. |
| 2925 if (section == SECTION_CC) | 2925 if (section == SECTION_CC) |
| 2926 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); | 2926 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); |
| 2927 | 2927 |
| 2928 // When filling from Wallet data, use the email address associated with the | 2928 // When filling from Wallet data, use the email address associated with the |
| 2929 // account. There is no other email address stored as part of a Wallet | 2929 // account. There is no other email address stored as part of a Wallet |
| 2930 // address. | 2930 // address. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2948 GetValueFromSection(SECTION_BILLING, NAME_BILLING_FULL)); | 2948 GetValueFromSection(SECTION_BILLING, NAME_BILLING_FULL)); |
| 2949 | 2949 |
| 2950 if (ShouldSaveDetailsLocally()) { | 2950 if (ShouldSaveDetailsLocally()) { |
| 2951 std::string guid = GetManager()->SaveImportedCreditCard(card); | 2951 std::string guid = GetManager()->SaveImportedCreditCard(card); |
| 2952 newly_saved_data_model_guids_[section] = guid; | 2952 newly_saved_data_model_guids_[section] = guid; |
| 2953 DCHECK(!profile()->IsOffTheRecord()); | 2953 DCHECK(!profile()->IsOffTheRecord()); |
| 2954 newly_saved_card_.reset(new CreditCard(card)); | 2954 newly_saved_card_.reset(new CreditCard(card)); |
| 2955 } | 2955 } |
| 2956 | 2956 |
| 2957 AutofillCreditCardWrapper card_wrapper(&card); | 2957 AutofillCreditCardWrapper card_wrapper(&card); |
| 2958 card_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2958 card_wrapper.FillFormStructure(types, compare, &form_structure_); |
| 2959 | 2959 |
| 2960 // Again, CVC needs special-casing. Fill it in directly from |output|. | 2960 // Again, CVC needs special-casing. Fill it in directly from |output|. |
| 2961 SetOutputForFieldsOfType( | 2961 SetOutputForFieldsOfType( |
| 2962 CREDIT_CARD_VERIFICATION_CODE, | 2962 CREDIT_CARD_VERIFICATION_CODE, |
| 2963 output[CREDIT_CARD_VERIFICATION_CODE]); | 2963 output[CREDIT_CARD_VERIFICATION_CODE]); |
| 2964 } else { | 2964 } else { |
| 2965 AutofillProfile profile; | 2965 AutofillProfile profile; |
| 2966 profile.set_origin(kAutofillDialogOrigin); | 2966 profile.set_origin(kAutofillDialogOrigin); |
| 2967 FillFormGroupFromOutputs(output, &profile); | 2967 FillFormGroupFromOutputs(output, &profile); |
| 2968 | 2968 |
| 2969 if (ShouldSaveDetailsLocally()) { | 2969 if (ShouldSaveDetailsLocally()) { |
| 2970 std::string guid = GetManager()->SaveImportedProfile(profile); | 2970 std::string guid = GetManager()->SaveImportedProfile(profile); |
| 2971 newly_saved_data_model_guids_[section] = guid; | 2971 newly_saved_data_model_guids_[section] = guid; |
| 2972 } | 2972 } |
| 2973 | 2973 |
| 2974 AutofillProfileWrapper profile_wrapper(&profile); | 2974 AutofillProfileWrapper profile_wrapper(&profile); |
| 2975 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2975 profile_wrapper.FillFormStructure(types, compare, &form_structure_); |
| 2976 } | 2976 } |
| 2977 } | 2977 } |
| 2978 } | 2978 } |
| 2979 | 2979 |
| 2980 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2980 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
| 2981 FillOutputForSectionWithComparator( | 2981 FillOutputForSectionWithComparator( |
| 2982 section, base::Bind(common::ServerTypeMatchesField, section)); | 2982 section, base::Bind(common::ServerTypeMatchesField, section)); |
| 2983 } | 2983 } |
| 2984 | 2984 |
| 2985 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( | 2985 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3063 return &shipping_country_combobox_model_; | 3063 return &shipping_country_combobox_model_; |
| 3064 | 3064 |
| 3065 return NULL; | 3065 return NULL; |
| 3066 } | 3066 } |
| 3067 | 3067 |
| 3068 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 3068 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| 3069 DialogSection section) { | 3069 DialogSection section) { |
| 3070 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 3070 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 3071 } | 3071 } |
| 3072 | 3072 |
| 3073 std::vector<ServerFieldType> AutofillDialogControllerImpl:: | |
| 3074 RequestedTypesForSection(DialogSection section) const { | |
| 3075 return common::TypesFromInputs(RequestedFieldsForSection(section)); | |
| 3076 } | |
| 3077 | |
| 3073 std::string AutofillDialogControllerImpl::CountryCodeForSection( | 3078 std::string AutofillDialogControllerImpl::CountryCodeForSection( |
| 3074 DialogSection section) { | 3079 DialogSection section) { |
| 3075 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 3080 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 3076 if (wrapper) { | 3081 if (wrapper) { |
| 3077 return AutofillCountry::GetCountryCode( | 3082 return AutofillCountry::GetCountryCode( |
| 3078 wrapper->GetInfo(AutofillType(CountryTypeForSection(section))), | 3083 wrapper->GetInfo(AutofillType(CountryTypeForSection(section))), |
| 3079 g_browser_process->GetApplicationLocale()); | 3084 g_browser_process->GetApplicationLocale()); |
| 3080 } | 3085 } |
| 3081 | 3086 |
| 3082 CountryComboboxModel* model = CountryComboboxModelForSection(section); | 3087 CountryComboboxModel* model = CountryComboboxModelForSection(section); |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3647 view_->UpdateButtonStrip(); | 3652 view_->UpdateButtonStrip(); |
| 3648 } | 3653 } |
| 3649 | 3654 |
| 3650 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3655 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 3651 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3656 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3652 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3657 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3653 signin_helper_->StartWalletCookieValueFetch(); | 3658 signin_helper_->StartWalletCookieValueFetch(); |
| 3654 } | 3659 } |
| 3655 | 3660 |
| 3656 } // namespace autofill | 3661 } // namespace autofill |
| OLD | NEW |