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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 | 690 |
691 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 691 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
692 DialogSection section = static_cast<DialogSection>(i); | 692 DialogSection section = static_cast<DialogSection>(i); |
693 | 693 |
694 std::string country_code; | 694 std::string country_code; |
695 CountryComboboxModel* model = CountryComboboxModelForSection(section); | 695 CountryComboboxModel* model = CountryComboboxModelForSection(section); |
696 if (model) | 696 if (model) |
697 country_code = model->GetDefaultCountryCode(); | 697 country_code = model->GetDefaultCountryCode(); |
698 | 698 |
699 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 699 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
700 common::BuildInputsForSection(section, country_code, inputs); | 700 common::BuildInputsForSection( |
701 section, country_code, inputs, | |
702 MutableAddressLanguageCodeForSection(section)); | |
701 } | 703 } |
702 | 704 |
703 // Test whether we need to show the shipping section. If filling that section | 705 // Test whether we need to show the shipping section. If filling that section |
704 // would be a no-op, don't show it. | 706 // would be a no-op, don't show it. |
705 cares_about_shipping_ = form_structure_.FillFields( | 707 cares_about_shipping_ = form_structure_.FillFields( |
706 RequestedTypesForSection(SECTION_SHIPPING), | 708 RequestedTypesForSection(SECTION_SHIPPING), |
707 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), | 709 base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), |
708 base::Bind(NullGetInfo), | 710 base::Bind(NullGetInfo), |
709 g_browser_process->GetApplicationLocale()); | 711 g_browser_process->GetApplicationLocale()); |
710 | 712 |
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1844 if (inputs.empty()) | 1846 if (inputs.empty()) |
1845 return messages; | 1847 return messages; |
1846 | 1848 |
1847 AddressValidator::Status status = AddressValidator::SUCCESS; | 1849 AddressValidator::Status status = AddressValidator::SUCCESS; |
1848 if (section != SECTION_CC) { | 1850 if (section != SECTION_CC) { |
1849 AutofillProfile profile; | 1851 AutofillProfile profile; |
1850 FillFormGroupFromOutputs(inputs, &profile); | 1852 FillFormGroupFromOutputs(inputs, &profile); |
1851 AddressData address_data; | 1853 AddressData address_data; |
1852 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), | 1854 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), |
1853 &address_data); | 1855 &address_data); |
1856 address_data.language_code = AddressLanguageCodeForSection(section); | |
1854 | 1857 |
1855 AddressProblems problems; | 1858 AddressProblems problems; |
1856 status = GetValidator()->ValidateAddress(address_data, | 1859 status = GetValidator()->ValidateAddress(address_data, |
1857 AddressProblemFilter(), | 1860 AddressProblemFilter(), |
1858 &problems); | 1861 &problems); |
1859 common::AddressType address_type = section == SECTION_SHIPPING ? | 1862 common::AddressType address_type = section == SECTION_SHIPPING ? |
1860 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 1863 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
1861 for (size_t i = 0; i < problems.size(); ++i) { | 1864 for (size_t i = 0; i < problems.size(); ++i) { |
1862 const AddressProblem& problem = problems[i]; | 1865 const AddressProblem& problem = problems[i]; |
1863 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; | 1866 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3050 } | 3053 } |
3051 | 3054 |
3052 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 3055 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
3053 DialogSection section, | 3056 DialogSection section, |
3054 const FormStructure::InputFieldComparator& compare) { | 3057 const FormStructure::InputFieldComparator& compare) { |
3055 if (!SectionIsActive(section)) | 3058 if (!SectionIsActive(section)) |
3056 return; | 3059 return; |
3057 | 3060 |
3058 DetailInputs inputs; | 3061 DetailInputs inputs; |
3059 std::string country_code = CountryCodeForSection(section); | 3062 std::string country_code = CountryCodeForSection(section); |
3060 common::BuildInputsForSection(section, country_code, &inputs); | 3063 common::BuildInputsForSection(section, country_code, &inputs, |
3064 MutableAddressLanguageCodeForSection(section)); | |
3061 std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); | 3065 std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); |
3062 | 3066 |
3063 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 3067 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
3064 if (wrapper) { | 3068 if (wrapper) { |
3065 // Only fill in data that is associated with this section. | 3069 // Only fill in data that is associated with this section. |
3066 wrapper->FillFormStructure(types, compare, &form_structure_); | 3070 wrapper->FillFormStructure(types, compare, &form_structure_); |
3067 | 3071 |
3068 // CVC needs special-casing because the CreditCard class doesn't store or | 3072 // CVC needs special-casing because the CreditCard class doesn't store or |
3069 // handle them. This isn't necessary when filling the combined CC and | 3073 // handle them. This isn't necessary when filling the combined CC and |
3070 // billing section as CVC comes from |full_wallet_| in this case. | 3074 // billing section as CVC comes from |full_wallet_| in this case. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3104 AutofillCreditCardWrapper card_wrapper(&card); | 3108 AutofillCreditCardWrapper card_wrapper(&card); |
3105 card_wrapper.FillFormStructure(types, compare, &form_structure_); | 3109 card_wrapper.FillFormStructure(types, compare, &form_structure_); |
3106 | 3110 |
3107 // Again, CVC needs special-casing. Fill it in directly from |output|. | 3111 // Again, CVC needs special-casing. Fill it in directly from |output|. |
3108 SetOutputForFieldsOfType( | 3112 SetOutputForFieldsOfType( |
3109 CREDIT_CARD_VERIFICATION_CODE, | 3113 CREDIT_CARD_VERIFICATION_CODE, |
3110 output[CREDIT_CARD_VERIFICATION_CODE]); | 3114 output[CREDIT_CARD_VERIFICATION_CODE]); |
3111 } else { | 3115 } else { |
3112 AutofillProfile profile; | 3116 AutofillProfile profile; |
3113 FillFormGroupFromOutputs(output, &profile); | 3117 FillFormGroupFromOutputs(output, &profile); |
3118 profile.set_language_code(AddressLanguageCodeForSection(section)); | |
3114 | 3119 |
3115 if (ShouldSaveDetailsLocally()) { | 3120 if (ShouldSaveDetailsLocally()) { |
3116 profile.set_origin(RulesAreLoaded(section) ? | 3121 profile.set_origin(RulesAreLoaded(section) ? |
3117 kAutofillDialogOrigin : source_url_.GetOrigin().spec()); | 3122 kAutofillDialogOrigin : source_url_.GetOrigin().spec()); |
3118 | 3123 |
3119 std::string guid = GetManager()->SaveImportedProfile(profile); | 3124 std::string guid = GetManager()->SaveImportedProfile(profile); |
3120 newly_saved_data_model_guids_[section] = guid; | 3125 newly_saved_data_model_guids_[section] = guid; |
3121 } | 3126 } |
3122 | 3127 |
3123 AutofillProfileWrapper profile_wrapper(&profile); | 3128 AutofillProfileWrapper profile_wrapper(&profile); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3252 | 3257 |
3253 FieldValueMap inputs; | 3258 FieldValueMap inputs; |
3254 view_->GetUserInput(section, &inputs); | 3259 view_->GetUserInput(section, &inputs); |
3255 | 3260 |
3256 AutofillProfile profile; | 3261 AutofillProfile profile; |
3257 FillFormGroupFromOutputs(inputs, &profile); | 3262 FillFormGroupFromOutputs(inputs, &profile); |
3258 | 3263 |
3259 AddressData user_input; | 3264 AddressData user_input; |
3260 i18ninput::CreateAddressData( | 3265 i18ninput::CreateAddressData( |
3261 base::Bind(&GetInfoFromProfile, profile), &user_input); | 3266 base::Bind(&GetInfoFromProfile, profile), &user_input); |
3267 user_input.language_code = AddressLanguageCodeForSection(section); | |
3262 | 3268 |
3263 static const size_t kSuggestionsLimit = 10; | 3269 static const size_t kSuggestionsLimit = 10; |
3264 AddressValidator::Status status = GetValidator()->GetSuggestions( | 3270 AddressValidator::Status status = GetValidator()->GetSuggestions( |
3265 user_input, focused_field, kSuggestionsLimit, | 3271 user_input, focused_field, kSuggestionsLimit, |
3266 &i18n_validator_suggestions_); | 3272 &i18n_validator_suggestions_); |
3267 | 3273 |
3268 if (status != AddressValidator::SUCCESS) | 3274 if (status != AddressValidator::SUCCESS) |
3269 return; | 3275 return; |
3270 | 3276 |
3271 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { | 3277 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
(...skipping 17 matching lines...) Expand all Loading... | |
3289 } | 3295 } |
3290 } | 3296 } |
3291 popup_icons->resize(popup_values->size()); | 3297 popup_icons->resize(popup_values->size()); |
3292 } | 3298 } |
3293 | 3299 |
3294 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 3300 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
3295 DialogSection section) { | 3301 DialogSection section) { |
3296 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 3302 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
3297 } | 3303 } |
3298 | 3304 |
3305 std::string* AutofillDialogControllerImpl::MutableAddressLanguageCodeForSection( | |
3306 DialogSection section) { | |
3307 switch (section) { | |
3308 case SECTION_BILLING: | |
3309 case SECTION_CC_BILLING: | |
3310 return &billing_address_language_code_; | |
3311 case SECTION_SHIPPING: | |
3312 return &shipping_address_language_code_; | |
3313 case SECTION_CC: | |
3314 return NULL; | |
3315 } | |
3316 NOTREACHED(); | |
3317 return NULL; | |
3318 } | |
3319 | |
3320 std::string AutofillDialogControllerImpl::AddressLanguageCodeForSection( | |
3321 DialogSection section) { | |
3322 std::string* language_code = MutableAddressLanguageCodeForSection(section); | |
3323 return language_code != NULL ? *language_code : std::string(); | |
3324 } | |
3325 | |
3299 std::vector<ServerFieldType> AutofillDialogControllerImpl:: | 3326 std::vector<ServerFieldType> AutofillDialogControllerImpl:: |
3300 RequestedTypesForSection(DialogSection section) const { | 3327 RequestedTypesForSection(DialogSection section) const { |
3301 return common::TypesFromInputs(RequestedFieldsForSection(section)); | 3328 return common::TypesFromInputs(RequestedFieldsForSection(section)); |
3302 } | 3329 } |
3303 | 3330 |
3304 std::string AutofillDialogControllerImpl::CountryCodeForSection( | 3331 std::string AutofillDialogControllerImpl::CountryCodeForSection( |
3305 DialogSection section) { | 3332 DialogSection section) { |
3306 base::string16 country; | 3333 base::string16 country; |
3307 | 3334 |
3308 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 3335 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
(...skipping 25 matching lines...) Expand all Loading... | |
3334 FieldValueMap outputs; | 3361 FieldValueMap outputs; |
3335 view_->GetUserInput(section, &outputs); | 3362 view_->GetUserInput(section, &outputs); |
3336 | 3363 |
3337 // If |country_name| is the same as the view, no-op and let the caller know. | 3364 // If |country_name| is the same as the view, no-op and let the caller know. |
3338 if (outputs[CountryTypeForSection(section)] == country_name) | 3365 if (outputs[CountryTypeForSection(section)] == country_name) |
3339 return false; | 3366 return false; |
3340 } | 3367 } |
3341 | 3368 |
3342 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 3369 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
3343 inputs->clear(); | 3370 inputs->clear(); |
3344 common::BuildInputsForSection(section, country_code, inputs); | 3371 common::BuildInputsForSection(section, country_code, inputs, |
3372 MutableAddressLanguageCodeForSection(section)); | |
3345 return true; | 3373 return true; |
3346 } | 3374 } |
3347 | 3375 |
3348 void AutofillDialogControllerImpl::HidePopup() { | 3376 void AutofillDialogControllerImpl::HidePopup() { |
3349 if (popup_controller_.get()) | 3377 if (popup_controller_.get()) |
3350 popup_controller_->Hide(); | 3378 popup_controller_->Hide(); |
3351 popup_input_type_ = UNKNOWN_TYPE; | 3379 popup_input_type_ = UNKNOWN_TYPE; |
3352 } | 3380 } |
3353 | 3381 |
3354 void AutofillDialogControllerImpl::SetEditingExistingData( | 3382 void AutofillDialogControllerImpl::SetEditingExistingData( |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3592 } | 3620 } |
3593 | 3621 |
3594 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: | 3622 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: |
3595 CreateTransientAddress() { | 3623 CreateTransientAddress() { |
3596 // If not using billing for shipping, just scrape the view. | 3624 // If not using billing for shipping, just scrape the view. |
3597 FieldValueMap output; | 3625 FieldValueMap output; |
3598 view_->GetUserInput(SECTION_SHIPPING, &output); | 3626 view_->GetUserInput(SECTION_SHIPPING, &output); |
3599 | 3627 |
3600 AutofillProfile profile; | 3628 AutofillProfile profile; |
3601 FillFormGroupFromOutputs(output, &profile); | 3629 FillFormGroupFromOutputs(output, &profile); |
3630 profile.set_language_code( | |
3631 AddressLanguageCodeForSection(SECTION_SHIPPING)); | |
Evan Stade
2014/04/10 00:58:49
use shipping_langauge_code_ directly
please use gerrit instead
2014/04/10 20:39:45
Good point.
| |
3602 CanonicalizeState(validator_.get(), &profile); | 3632 CanonicalizeState(validator_.get(), &profile); |
3603 | 3633 |
3604 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); | 3634 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); |
3605 } | 3635 } |
3606 | 3636 |
3607 void AutofillDialogControllerImpl::GetFullWallet() { | 3637 void AutofillDialogControllerImpl::GetFullWallet() { |
3608 DCHECK(is_submitting_); | 3638 DCHECK(is_submitting_); |
3609 DCHECK(IsPayingWithWallet()); | 3639 DCHECK(IsPayingWithWallet()); |
3610 DCHECK(wallet_items_); | 3640 DCHECK(wallet_items_); |
3611 DCHECK(!active_instrument_id_.empty()); | 3641 DCHECK(!active_instrument_id_.empty()); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3912 return; | 3942 return; |
3913 | 3943 |
3914 if (newly_saved_card_) { | 3944 if (newly_saved_card_) { |
3915 scoped_ptr<AutofillProfile> billing_profile; | 3945 scoped_ptr<AutofillProfile> billing_profile; |
3916 if (IsManuallyEditingSection(SECTION_BILLING)) { | 3946 if (IsManuallyEditingSection(SECTION_BILLING)) { |
3917 // Scrape the view as the user's entering or updating information. | 3947 // Scrape the view as the user's entering or updating information. |
3918 FieldValueMap outputs; | 3948 FieldValueMap outputs; |
3919 view_->GetUserInput(SECTION_BILLING, &outputs); | 3949 view_->GetUserInput(SECTION_BILLING, &outputs); |
3920 billing_profile.reset(new AutofillProfile); | 3950 billing_profile.reset(new AutofillProfile); |
3921 FillFormGroupFromOutputs(outputs, billing_profile.get()); | 3951 FillFormGroupFromOutputs(outputs, billing_profile.get()); |
3952 billing_profile->set_language_code( | |
3953 AddressLanguageCodeForSection(SECTION_BILLING)); | |
Evan Stade
2014/04/10 00:58:49
ditto
please use gerrit instead
2014/04/10 20:39:45
Done.
| |
3922 } else { | 3954 } else { |
3923 // Just snag the currently suggested profile. | 3955 // Just snag the currently suggested profile. |
3924 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> | 3956 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> |
3925 GetItemKeyForCheckedItem(); | 3957 GetItemKeyForCheckedItem(); |
3926 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | 3958 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
3927 billing_profile.reset(new AutofillProfile(*profile)); | 3959 billing_profile.reset(new AutofillProfile(*profile)); |
3928 } | 3960 } |
3929 | 3961 |
3930 ShowNewCreditCardBubble(newly_saved_card_.Pass(), | 3962 ShowNewCreditCardBubble(newly_saved_card_.Pass(), |
3931 billing_profile.Pass()); | 3963 billing_profile.Pass()); |
(...skipping 16 matching lines...) Expand all Loading... | |
3948 view_->UpdateButtonStrip(); | 3980 view_->UpdateButtonStrip(); |
3949 } | 3981 } |
3950 | 3982 |
3951 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3983 void AutofillDialogControllerImpl::FetchWalletCookie() { |
3952 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3984 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
3953 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3985 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
3954 signin_helper_->StartWalletCookieValueFetch(); | 3986 signin_helper_->StartWalletCookieValueFetch(); |
3955 } | 3987 } |
3956 | 3988 |
3957 } // namespace autofill | 3989 } // namespace autofill |
OLD | NEW |