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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 212873003: Store the language code for the address in autofill profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 8 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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
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
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 return &billing_address_language_code_;
3310 case SECTION_SHIPPING:
3311 return &shipping_address_language_code_;
3312 default:
Ilya Sherman 2014/03/29 01:24:42 please explicitly list all SECTION_'s rather than
please use gerrit instead 2014/04/02 21:54:52 Done.
3313 return NULL;
3314 }
3315 }
3316
3317 std::string AutofillDialogControllerImpl::AddressLanguageCodeForSection(
3318 DialogSection section) {
3319 std::string* language_code = MutableAddressLanguageCodeForSection(section);
3320 return language_code != NULL ? *language_code : std::string();
3321 }
3322
3299 std::vector<ServerFieldType> AutofillDialogControllerImpl:: 3323 std::vector<ServerFieldType> AutofillDialogControllerImpl::
3300 RequestedTypesForSection(DialogSection section) const { 3324 RequestedTypesForSection(DialogSection section) const {
3301 return common::TypesFromInputs(RequestedFieldsForSection(section)); 3325 return common::TypesFromInputs(RequestedFieldsForSection(section));
3302 } 3326 }
3303 3327
3304 std::string AutofillDialogControllerImpl::CountryCodeForSection( 3328 std::string AutofillDialogControllerImpl::CountryCodeForSection(
3305 DialogSection section) { 3329 DialogSection section) {
3306 base::string16 country; 3330 base::string16 country;
3307 3331
3308 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 3332 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
(...skipping 25 matching lines...) Expand all
3334 FieldValueMap outputs; 3358 FieldValueMap outputs;
3335 view_->GetUserInput(section, &outputs); 3359 view_->GetUserInput(section, &outputs);
3336 3360
3337 // If |country_name| is the same as the view, no-op and let the caller know. 3361 // If |country_name| is the same as the view, no-op and let the caller know.
3338 if (outputs[CountryTypeForSection(section)] == country_name) 3362 if (outputs[CountryTypeForSection(section)] == country_name)
3339 return false; 3363 return false;
3340 } 3364 }
3341 3365
3342 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 3366 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
3343 inputs->clear(); 3367 inputs->clear();
3344 common::BuildInputsForSection(section, country_code, inputs); 3368 common::BuildInputsForSection(section, country_code, inputs,
3369 MutableAddressLanguageCodeForSection(section));
3345 return true; 3370 return true;
3346 } 3371 }
3347 3372
3348 void AutofillDialogControllerImpl::HidePopup() { 3373 void AutofillDialogControllerImpl::HidePopup() {
3349 if (popup_controller_.get()) 3374 if (popup_controller_.get())
3350 popup_controller_->Hide(); 3375 popup_controller_->Hide();
3351 popup_input_type_ = UNKNOWN_TYPE; 3376 popup_input_type_ = UNKNOWN_TYPE;
3352 } 3377 }
3353 3378
3354 void AutofillDialogControllerImpl::SetEditingExistingData( 3379 void AutofillDialogControllerImpl::SetEditingExistingData(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3592 } 3617 }
3593 3618
3594 scoped_ptr<wallet::Address>AutofillDialogControllerImpl:: 3619 scoped_ptr<wallet::Address>AutofillDialogControllerImpl::
3595 CreateTransientAddress() { 3620 CreateTransientAddress() {
3596 // If not using billing for shipping, just scrape the view. 3621 // If not using billing for shipping, just scrape the view.
3597 FieldValueMap output; 3622 FieldValueMap output;
3598 view_->GetUserInput(SECTION_SHIPPING, &output); 3623 view_->GetUserInput(SECTION_SHIPPING, &output);
3599 3624
3600 AutofillProfile profile; 3625 AutofillProfile profile;
3601 FillFormGroupFromOutputs(output, &profile); 3626 FillFormGroupFromOutputs(output, &profile);
3627 profile.set_language_code(
3628 AddressLanguageCodeForSection(SECTION_SHIPPING));
3602 CanonicalizeState(validator_.get(), &profile); 3629 CanonicalizeState(validator_.get(), &profile);
3603 3630
3604 return scoped_ptr<wallet::Address>(new wallet::Address(profile)); 3631 return scoped_ptr<wallet::Address>(new wallet::Address(profile));
3605 } 3632 }
3606 3633
3607 void AutofillDialogControllerImpl::GetFullWallet() { 3634 void AutofillDialogControllerImpl::GetFullWallet() {
3608 DCHECK(is_submitting_); 3635 DCHECK(is_submitting_);
3609 DCHECK(IsPayingWithWallet()); 3636 DCHECK(IsPayingWithWallet());
3610 DCHECK(wallet_items_); 3637 DCHECK(wallet_items_);
3611 DCHECK(!active_instrument_id_.empty()); 3638 DCHECK(!active_instrument_id_.empty());
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
3912 return; 3939 return;
3913 3940
3914 if (newly_saved_card_) { 3941 if (newly_saved_card_) {
3915 scoped_ptr<AutofillProfile> billing_profile; 3942 scoped_ptr<AutofillProfile> billing_profile;
3916 if (IsManuallyEditingSection(SECTION_BILLING)) { 3943 if (IsManuallyEditingSection(SECTION_BILLING)) {
3917 // Scrape the view as the user's entering or updating information. 3944 // Scrape the view as the user's entering or updating information.
3918 FieldValueMap outputs; 3945 FieldValueMap outputs;
3919 view_->GetUserInput(SECTION_BILLING, &outputs); 3946 view_->GetUserInput(SECTION_BILLING, &outputs);
3920 billing_profile.reset(new AutofillProfile); 3947 billing_profile.reset(new AutofillProfile);
3921 FillFormGroupFromOutputs(outputs, billing_profile.get()); 3948 FillFormGroupFromOutputs(outputs, billing_profile.get());
3949 billing_profile->set_language_code(
3950 AddressLanguageCodeForSection(SECTION_BILLING));
3922 } else { 3951 } else {
3923 // Just snag the currently suggested profile. 3952 // Just snag the currently suggested profile.
3924 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)-> 3953 std::string item_key = SuggestionsMenuModelForSection(SECTION_BILLING)->
3925 GetItemKeyForCheckedItem(); 3954 GetItemKeyForCheckedItem();
3926 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); 3955 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key);
3927 billing_profile.reset(new AutofillProfile(*profile)); 3956 billing_profile.reset(new AutofillProfile(*profile));
3928 } 3957 }
3929 3958
3930 ShowNewCreditCardBubble(newly_saved_card_.Pass(), 3959 ShowNewCreditCardBubble(newly_saved_card_.Pass(),
3931 billing_profile.Pass()); 3960 billing_profile.Pass());
(...skipping 16 matching lines...) Expand all
3948 view_->UpdateButtonStrip(); 3977 view_->UpdateButtonStrip();
3949 } 3978 }
3950 3979
3951 void AutofillDialogControllerImpl::FetchWalletCookie() { 3980 void AutofillDialogControllerImpl::FetchWalletCookie() {
3952 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 3981 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
3953 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 3982 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
3954 signin_helper_->StartWalletCookieValueFetch(); 3983 signin_helper_->StartWalletCookieValueFetch();
3955 } 3984 }
3956 3985
3957 } // namespace autofill 3986 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698