| 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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 | 689 |
| 690 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 690 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 691 DialogSection section = static_cast<DialogSection>(i); | 691 DialogSection section = static_cast<DialogSection>(i); |
| 692 | 692 |
| 693 std::string country_code; | 693 std::string country_code; |
| 694 CountryComboboxModel* model = CountryComboboxModelForSection(section); | 694 CountryComboboxModel* model = CountryComboboxModelForSection(section); |
| 695 if (model) | 695 if (model) |
| 696 country_code = model->GetDefaultCountryCode(); | 696 country_code = model->GetDefaultCountryCode(); |
| 697 | 697 |
| 698 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 698 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 699 common::BuildInputsForSection(section, country_code, inputs); | 699 common::BuildInputsForSection( |
| 700 section, country_code, inputs, |
| 701 MutableAddressLanguageCodeForSection(section)); |
| 700 } | 702 } |
| 701 | 703 |
| 702 // Test whether we need to show the shipping section. If filling that section | 704 // Test whether we need to show the shipping section. If filling that section |
| 703 // would be a no-op, don't show it. | 705 // would be a no-op, don't show it. |
| 704 cares_about_shipping_ = form_structure_.FillFields( | 706 cares_about_shipping_ = form_structure_.FillFields( |
| 705 RequestedTypesForSection(SECTION_SHIPPING), | 707 RequestedTypesForSection(SECTION_SHIPPING), |
| 706 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), | 708 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), |
| 707 base::Bind(NullGetInfo), | 709 base::Bind(NullGetInfo), |
| 708 g_browser_process->GetApplicationLocale()); | 710 g_browser_process->GetApplicationLocale()); |
| 709 | 711 |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 if (inputs.empty()) | 1844 if (inputs.empty()) |
| 1843 return messages; | 1845 return messages; |
| 1844 | 1846 |
| 1845 AddressValidator::Status status = AddressValidator::SUCCESS; | 1847 AddressValidator::Status status = AddressValidator::SUCCESS; |
| 1846 if (section != SECTION_CC) { | 1848 if (section != SECTION_CC) { |
| 1847 AutofillProfile profile; | 1849 AutofillProfile profile; |
| 1848 FillFormGroupFromOutputs(inputs, &profile); | 1850 FillFormGroupFromOutputs(inputs, &profile); |
| 1849 AddressData address_data; | 1851 AddressData address_data; |
| 1850 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), | 1852 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), |
| 1851 &address_data); | 1853 &address_data); |
| 1854 address_data.language_code = AddressLanguageCodeForSection(section); |
| 1852 | 1855 |
| 1853 AddressProblems problems; | 1856 AddressProblems problems; |
| 1854 status = GetValidator()->ValidateAddress(address_data, | 1857 status = GetValidator()->ValidateAddress(address_data, |
| 1855 AddressProblemFilter(), | 1858 AddressProblemFilter(), |
| 1856 &problems); | 1859 &problems); |
| 1857 common::AddressType address_type = section == SECTION_SHIPPING ? | 1860 common::AddressType address_type = section == SECTION_SHIPPING ? |
| 1858 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 1861 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
| 1859 for (size_t i = 0; i < problems.size(); ++i) { | 1862 for (size_t i = 0; i < problems.size(); ++i) { |
| 1860 const AddressProblem& problem = problems[i]; | 1863 const AddressProblem& problem = problems[i]; |
| 1861 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; | 1864 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3039 } | 3042 } |
| 3040 | 3043 |
| 3041 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 3044 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| 3042 DialogSection section, | 3045 DialogSection section, |
| 3043 const FormStructure::InputFieldComparator& compare) { | 3046 const FormStructure::InputFieldComparator& compare) { |
| 3044 if (!SectionIsActive(section)) | 3047 if (!SectionIsActive(section)) |
| 3045 return; | 3048 return; |
| 3046 | 3049 |
| 3047 DetailInputs inputs; | 3050 DetailInputs inputs; |
| 3048 std::string country_code = CountryCodeForSection(section); | 3051 std::string country_code = CountryCodeForSection(section); |
| 3049 common::BuildInputsForSection(section, country_code, &inputs); | 3052 common::BuildInputsForSection(section, country_code, &inputs, |
| 3053 MutableAddressLanguageCodeForSection(section)); |
| 3050 std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); | 3054 std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); |
| 3051 | 3055 |
| 3052 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 3056 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 3053 if (wrapper) { | 3057 if (wrapper) { |
| 3054 // Only fill in data that is associated with this section. | 3058 // Only fill in data that is associated with this section. |
| 3055 wrapper->FillFormStructure(types, compare, &form_structure_); | 3059 wrapper->FillFormStructure(types, compare, &form_structure_); |
| 3056 | 3060 |
| 3057 // CVC needs special-casing because the CreditCard class doesn't store or | 3061 // CVC needs special-casing because the CreditCard class doesn't store or |
| 3058 // handle them. This isn't necessary when filling the combined CC and | 3062 // handle them. This isn't necessary when filling the combined CC and |
| 3059 // billing section as CVC comes from |full_wallet_| in this case. | 3063 // billing section as CVC comes from |full_wallet_| in this case. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3093 AutofillCreditCardWrapper card_wrapper(&card); | 3097 AutofillCreditCardWrapper card_wrapper(&card); |
| 3094 card_wrapper.FillFormStructure(types, compare, &form_structure_); | 3098 card_wrapper.FillFormStructure(types, compare, &form_structure_); |
| 3095 | 3099 |
| 3096 // Again, CVC needs special-casing. Fill it in directly from |output|. | 3100 // Again, CVC needs special-casing. Fill it in directly from |output|. |
| 3097 SetOutputForFieldsOfType( | 3101 SetOutputForFieldsOfType( |
| 3098 CREDIT_CARD_VERIFICATION_CODE, | 3102 CREDIT_CARD_VERIFICATION_CODE, |
| 3099 output[CREDIT_CARD_VERIFICATION_CODE]); | 3103 output[CREDIT_CARD_VERIFICATION_CODE]); |
| 3100 } else { | 3104 } else { |
| 3101 AutofillProfile profile; | 3105 AutofillProfile profile; |
| 3102 FillFormGroupFromOutputs(output, &profile); | 3106 FillFormGroupFromOutputs(output, &profile); |
| 3107 profile.set_language_code(AddressLanguageCodeForSection(section)); |
| 3103 | 3108 |
| 3104 if (ShouldSaveDetailsLocally()) { | 3109 if (ShouldSaveDetailsLocally()) { |
| 3105 profile.set_origin(RulesAreLoaded(section) ? | 3110 profile.set_origin(RulesAreLoaded(section) ? |
| 3106 kAutofillDialogOrigin : source_url_.GetOrigin().spec()); | 3111 kAutofillDialogOrigin : source_url_.GetOrigin().spec()); |
| 3107 | 3112 |
| 3108 std::string guid = GetManager()->SaveImportedProfile(profile); | 3113 std::string guid = GetManager()->SaveImportedProfile(profile); |
| 3109 newly_saved_data_model_guids_[section] = guid; | 3114 newly_saved_data_model_guids_[section] = guid; |
| 3110 } | 3115 } |
| 3111 | 3116 |
| 3112 AutofillProfileWrapper profile_wrapper(&profile); | 3117 AutofillProfileWrapper profile_wrapper(&profile); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3241 | 3246 |
| 3242 FieldValueMap inputs; | 3247 FieldValueMap inputs; |
| 3243 view_->GetUserInput(section, &inputs); | 3248 view_->GetUserInput(section, &inputs); |
| 3244 | 3249 |
| 3245 AutofillProfile profile; | 3250 AutofillProfile profile; |
| 3246 FillFormGroupFromOutputs(inputs, &profile); | 3251 FillFormGroupFromOutputs(inputs, &profile); |
| 3247 | 3252 |
| 3248 AddressData user_input; | 3253 AddressData user_input; |
| 3249 i18ninput::CreateAddressData( | 3254 i18ninput::CreateAddressData( |
| 3250 base::Bind(&GetInfoFromProfile, profile), &user_input); | 3255 base::Bind(&GetInfoFromProfile, profile), &user_input); |
| 3256 user_input.language_code = AddressLanguageCodeForSection(section); |
| 3251 | 3257 |
| 3252 static const size_t kSuggestionsLimit = 10; | 3258 static const size_t kSuggestionsLimit = 10; |
| 3253 AddressValidator::Status status = GetValidator()->GetSuggestions( | 3259 AddressValidator::Status status = GetValidator()->GetSuggestions( |
| 3254 user_input, focused_field, kSuggestionsLimit, | 3260 user_input, focused_field, kSuggestionsLimit, |
| 3255 &i18n_validator_suggestions_); | 3261 &i18n_validator_suggestions_); |
| 3256 | 3262 |
| 3257 if (status != AddressValidator::SUCCESS) | 3263 if (status != AddressValidator::SUCCESS) |
| 3258 return; | 3264 return; |
| 3259 | 3265 |
| 3260 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { | 3266 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3278 } | 3284 } |
| 3279 } | 3285 } |
| 3280 popup_icons->resize(popup_values->size()); | 3286 popup_icons->resize(popup_values->size()); |
| 3281 } | 3287 } |
| 3282 | 3288 |
| 3283 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 3289 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| 3284 DialogSection section) { | 3290 DialogSection section) { |
| 3285 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 3291 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 3286 } | 3292 } |
| 3287 | 3293 |
| 3294 std::string* AutofillDialogControllerImpl::MutableAddressLanguageCodeForSection( |
| 3295 DialogSection section) { |
| 3296 switch (section) { |
| 3297 case SECTION_BILLING: |
| 3298 case SECTION_CC_BILLING: |
| 3299 return &billing_address_language_code_; |
| 3300 case SECTION_SHIPPING: |
| 3301 return &shipping_address_language_code_; |
| 3302 case SECTION_CC: |
| 3303 return NULL; |
| 3304 } |
| 3305 NOTREACHED(); |
| 3306 return NULL; |
| 3307 } |
| 3308 |
| 3309 std::string AutofillDialogControllerImpl::AddressLanguageCodeForSection( |
| 3310 DialogSection section) { |
| 3311 std::string* language_code = MutableAddressLanguageCodeForSection(section); |
| 3312 return language_code != NULL ? *language_code : std::string(); |
| 3313 } |
| 3314 |
| 3288 std::vector<ServerFieldType> AutofillDialogControllerImpl:: | 3315 std::vector<ServerFieldType> AutofillDialogControllerImpl:: |
| 3289 RequestedTypesForSection(DialogSection section) const { | 3316 RequestedTypesForSection(DialogSection section) const { |
| 3290 return common::TypesFromInputs(RequestedFieldsForSection(section)); | 3317 return common::TypesFromInputs(RequestedFieldsForSection(section)); |
| 3291 } | 3318 } |
| 3292 | 3319 |
| 3293 std::string AutofillDialogControllerImpl::CountryCodeForSection( | 3320 std::string AutofillDialogControllerImpl::CountryCodeForSection( |
| 3294 DialogSection section) { | 3321 DialogSection section) { |
| 3295 base::string16 country; | 3322 base::string16 country; |
| 3296 | 3323 |
| 3297 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 3324 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3323 FieldValueMap outputs; | 3350 FieldValueMap outputs; |
| 3324 view_->GetUserInput(section, &outputs); | 3351 view_->GetUserInput(section, &outputs); |
| 3325 | 3352 |
| 3326 // If |country_name| is the same as the view, no-op and let the caller know. | 3353 // If |country_name| is the same as the view, no-op and let the caller know. |
| 3327 if (outputs[CountryTypeForSection(section)] == country_name) | 3354 if (outputs[CountryTypeForSection(section)] == country_name) |
| 3328 return false; | 3355 return false; |
| 3329 } | 3356 } |
| 3330 | 3357 |
| 3331 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 3358 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 3332 inputs->clear(); | 3359 inputs->clear(); |
| 3333 common::BuildInputsForSection(section, country_code, inputs); | 3360 common::BuildInputsForSection(section, country_code, inputs, |
| 3361 MutableAddressLanguageCodeForSection(section)); |
| 3334 return true; | 3362 return true; |
| 3335 } | 3363 } |
| 3336 | 3364 |
| 3337 void AutofillDialogControllerImpl::HidePopup() { | 3365 void AutofillDialogControllerImpl::HidePopup() { |
| 3338 if (popup_controller_) | 3366 if (popup_controller_) |
| 3339 popup_controller_->Hide(); | 3367 popup_controller_->Hide(); |
| 3340 popup_input_type_ = UNKNOWN_TYPE; | 3368 popup_input_type_ = UNKNOWN_TYPE; |
| 3341 } | 3369 } |
| 3342 | 3370 |
| 3343 void AutofillDialogControllerImpl::SetEditingExistingData( | 3371 void AutofillDialogControllerImpl::SetEditingExistingData( |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3581 } | 3609 } |
| 3582 | 3610 |
| 3583 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: | 3611 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: |
| 3584 CreateTransientAddress() { | 3612 CreateTransientAddress() { |
| 3585 // If not using billing for shipping, just scrape the view. | 3613 // If not using billing for shipping, just scrape the view. |
| 3586 FieldValueMap output; | 3614 FieldValueMap output; |
| 3587 view_->GetUserInput(SECTION_SHIPPING, &output); | 3615 view_->GetUserInput(SECTION_SHIPPING, &output); |
| 3588 | 3616 |
| 3589 AutofillProfile profile; | 3617 AutofillProfile profile; |
| 3590 FillFormGroupFromOutputs(output, &profile); | 3618 FillFormGroupFromOutputs(output, &profile); |
| 3619 profile.set_language_code(shipping_address_language_code_); |
| 3591 CanonicalizeState(validator_.get(), &profile); | 3620 CanonicalizeState(validator_.get(), &profile); |
| 3592 | 3621 |
| 3593 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); | 3622 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); |
| 3594 } | 3623 } |
| 3595 | 3624 |
| 3596 void AutofillDialogControllerImpl::GetFullWallet() { | 3625 void AutofillDialogControllerImpl::GetFullWallet() { |
| 3597 DCHECK(is_submitting_); | 3626 DCHECK(is_submitting_); |
| 3598 DCHECK(IsPayingWithWallet()); | 3627 DCHECK(IsPayingWithWallet()); |
| 3599 DCHECK(wallet_items_); | 3628 DCHECK(wallet_items_); |
| 3600 DCHECK(!active_instrument_id_.empty()); | 3629 DCHECK(!active_instrument_id_.empty()); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3901 return; | 3930 return; |
| 3902 | 3931 |
| 3903 if (newly_saved_card_) { | 3932 if (newly_saved_card_) { |
| 3904 scoped_ptr<AutofillProfile> billing_profile; | 3933 scoped_ptr<AutofillProfile> billing_profile; |
| 3905 if (IsManuallyEditingSection(SECTION_BILLING)) { | 3934 if (IsManuallyEditingSection(SECTION_BILLING)) { |
| 3906 // Scrape the view as the user's entering or updating information. | 3935 // Scrape the view as the user's entering or updating information. |
| 3907 FieldValueMap outputs; | 3936 FieldValueMap outputs; |
| 3908 view_->GetUserInput(SECTION_BILLING, &outputs); | 3937 view_->GetUserInput(SECTION_BILLING, &outputs); |
| 3909 billing_profile.reset(new AutofillProfile); | 3938 billing_profile.reset(new AutofillProfile); |
| 3910 FillFormGroupFromOutputs(outputs, billing_profile.get()); | 3939 FillFormGroupFromOutputs(outputs, billing_profile.get()); |
| 3940 billing_profile->set_language_code(billing_address_language_code_); |
| 3911 } else { | 3941 } else { |
| 3912 // Just snag the currently suggested profile. | 3942 // Just snag the currently suggested profile. |
| 3913 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> | 3943 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> |
| 3914 GetItemKeyForCheckedItem(); | 3944 GetItemKeyForCheckedItem(); |
| 3915 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | 3945 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
| 3916 billing_profile.reset(new AutofillProfile(*profile)); | 3946 billing_profile.reset(new AutofillProfile(*profile)); |
| 3917 } | 3947 } |
| 3918 | 3948 |
| 3919 ShowNewCreditCardBubble(newly_saved_card_.Pass(), | 3949 ShowNewCreditCardBubble(newly_saved_card_.Pass(), |
| 3920 billing_profile.Pass()); | 3950 billing_profile.Pass()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3937 view_->UpdateButtonStrip(); | 3967 view_->UpdateButtonStrip(); |
| 3938 } | 3968 } |
| 3939 | 3969 |
| 3940 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3970 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 3941 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3971 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3942 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3972 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3943 signin_helper_->StartWalletCookieValueFetch(); | 3973 signin_helper_->StartWalletCookieValueFetch(); |
| 3944 } | 3974 } |
| 3945 | 3975 |
| 3946 } // namespace autofill | 3976 } // namespace autofill |
| OLD | NEW |