| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "components/autofill/content/browser/risk/fingerprint.h" | 47 #include "components/autofill/content/browser/risk/fingerprint.h" |
| 48 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 48 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
| 49 #include "components/autofill/content/browser/wallet/form_field_error.h" | 49 #include "components/autofill/content/browser/wallet/form_field_error.h" |
| 50 #include "components/autofill/content/browser/wallet/full_wallet.h" | 50 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 51 #include "components/autofill/content/browser/wallet/gaia_account.h" | 51 #include "components/autofill/content/browser/wallet/gaia_account.h" |
| 52 #include "components/autofill/content/browser/wallet/instrument.h" | 52 #include "components/autofill/content/browser/wallet/instrument.h" |
| 53 #include "components/autofill/content/browser/wallet/wallet_address.h" | 53 #include "components/autofill/content/browser/wallet/wallet_address.h" |
| 54 #include "components/autofill/content/browser/wallet/wallet_items.h" | 54 #include "components/autofill/content/browser/wallet/wallet_items.h" |
| 55 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 55 #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
| 56 #include "components/autofill/content/browser/wallet/wallet_signin_helper.h" | 56 #include "components/autofill/content/browser/wallet/wallet_signin_helper.h" |
| 57 #include "components/autofill/core/browser/address_i18n.h" |
| 57 #include "components/autofill/core/browser/autofill_country.h" | 58 #include "components/autofill/core/browser/autofill_country.h" |
| 58 #include "components/autofill/core/browser/autofill_data_model.h" | 59 #include "components/autofill/core/browser/autofill_data_model.h" |
| 59 #include "components/autofill/core/browser/autofill_manager.h" | 60 #include "components/autofill/core/browser/autofill_manager.h" |
| 60 #include "components/autofill/core/browser/autofill_type.h" | 61 #include "components/autofill/core/browser/autofill_type.h" |
| 61 #include "components/autofill/core/browser/personal_data_manager.h" | 62 #include "components/autofill/core/browser/personal_data_manager.h" |
| 62 #include "components/autofill/core/browser/phone_number_i18n.h" | 63 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 63 #include "components/autofill/core/browser/validation.h" | 64 #include "components/autofill/core/browser/validation.h" |
| 64 #include "components/autofill/core/common/autofill_pref_names.h" | 65 #include "components/autofill/core/common/autofill_pref_names.h" |
| 65 #include "components/autofill/core/common/form_data.h" | 66 #include "components/autofill/core/common/form_data.h" |
| 66 #include "components/user_prefs/pref_registry_syncable.h" | 67 #include "components/user_prefs/pref_registry_syncable.h" |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 base::string16 GetInfoFromProfile(const AutofillProfile& profile, | 524 base::string16 GetInfoFromProfile(const AutofillProfile& profile, |
| 524 const AutofillType& type) { | 525 const AutofillType& type) { |
| 525 return profile.GetInfo(type, g_browser_process->GetApplicationLocale()); | 526 return profile.GetInfo(type, g_browser_process->GetApplicationLocale()); |
| 526 } | 527 } |
| 527 | 528 |
| 528 // Attempts to canonicalize the administrative area name in |profile| using the | 529 // Attempts to canonicalize the administrative area name in |profile| using the |
| 529 // rules in |validator|. | 530 // rules in |validator|. |
| 530 void CanonicalizeState(const AddressValidator* validator, | 531 void CanonicalizeState(const AddressValidator* validator, |
| 531 AutofillProfile* profile) { | 532 AutofillProfile* profile) { |
| 532 base::string16 administrative_area; | 533 base::string16 administrative_area; |
| 533 AddressData address_data; | 534 scoped_ptr<AddressData> address_data = |
| 534 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, *profile), | 535 i18n::CreateAddressData(base::Bind(&GetInfoFromProfile, *profile)); |
| 535 &address_data); | |
| 536 | 536 |
| 537 validator->CanonicalizeAdministrativeArea(&address_data); | 537 validator->CanonicalizeAdministrativeArea(address_data.get()); |
| 538 administrative_area = base::UTF8ToUTF16(address_data.administrative_area); | 538 administrative_area = base::UTF8ToUTF16(address_data->administrative_area); |
| 539 | 539 |
| 540 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), | 540 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), |
| 541 administrative_area, | 541 administrative_area, |
| 542 g_browser_process->GetApplicationLocale()); | 542 g_browser_process->GetApplicationLocale()); |
| 543 } | 543 } |
| 544 | 544 |
| 545 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name, | 545 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name, |
| 546 const base::string16& number) { | 546 const base::string16& number) { |
| 547 std::string region = AutofillCountry::GetCountryCode( | 547 std::string region = AutofillCountry::GetCountryCode( |
| 548 country_name, | 548 country_name, |
| (...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 DialogSection section, | 1956 DialogSection section, |
| 1957 const FieldValueMap& inputs) { | 1957 const FieldValueMap& inputs) { |
| 1958 ValidityMessages messages; | 1958 ValidityMessages messages; |
| 1959 if (inputs.empty()) | 1959 if (inputs.empty()) |
| 1960 return messages; | 1960 return messages; |
| 1961 | 1961 |
| 1962 AddressValidator::Status status = AddressValidator::SUCCESS; | 1962 AddressValidator::Status status = AddressValidator::SUCCESS; |
| 1963 if (section != SECTION_CC) { | 1963 if (section != SECTION_CC) { |
| 1964 AutofillProfile profile; | 1964 AutofillProfile profile; |
| 1965 FillFormGroupFromOutputs(inputs, &profile); | 1965 FillFormGroupFromOutputs(inputs, &profile); |
| 1966 AddressData address_data; | 1966 scoped_ptr<AddressData> address_data = |
| 1967 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), | 1967 i18n::CreateAddressData(base::Bind(&GetInfoFromProfile, profile)); |
| 1968 &address_data); | 1968 address_data->language_code = AddressLanguageCodeForSection(section); |
| 1969 address_data.language_code = AddressLanguageCodeForSection(section); | |
| 1970 | 1969 |
| 1971 AddressProblems problems; | 1970 AddressProblems problems; |
| 1972 status = GetValidator()->ValidateAddress(address_data, | 1971 status = GetValidator()->ValidateAddress(*address_data, |
| 1973 AddressProblemFilter(), | 1972 AddressProblemFilter(), |
| 1974 &problems); | 1973 &problems); |
| 1975 common::AddressType address_type = section == SECTION_SHIPPING ? | 1974 common::AddressType address_type = section == SECTION_SHIPPING ? |
| 1976 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 1975 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
| 1977 for (size_t i = 0; i < problems.size(); ++i) { | 1976 for (size_t i = 0; i < problems.size(); ++i) { |
| 1978 const AddressProblem& problem = problems[i]; | 1977 const AddressProblem& problem = problems[i]; |
| 1979 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; | 1978 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
| 1980 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); | 1979 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); |
| 1981 messages.Set(i18ninput::TypeForField(problem.field, address_type), | 1980 messages.Set(i18ninput::TypeForField(problem.field, address_type), |
| 1982 ValidityMessage(text, sure)); | 1981 ValidityMessage(text, sure)); |
| (...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3349 AddressField focused_field; | 3348 AddressField focused_field; |
| 3350 if (!i18ninput::FieldForType(type, &focused_field)) | 3349 if (!i18ninput::FieldForType(type, &focused_field)) |
| 3351 return; | 3350 return; |
| 3352 | 3351 |
| 3353 FieldValueMap inputs; | 3352 FieldValueMap inputs; |
| 3354 view_->GetUserInput(section, &inputs); | 3353 view_->GetUserInput(section, &inputs); |
| 3355 | 3354 |
| 3356 AutofillProfile profile; | 3355 AutofillProfile profile; |
| 3357 FillFormGroupFromOutputs(inputs, &profile); | 3356 FillFormGroupFromOutputs(inputs, &profile); |
| 3358 | 3357 |
| 3359 AddressData user_input; | 3358 scoped_ptr<AddressData> user_input = |
| 3360 i18ninput::CreateAddressData( | 3359 i18n::CreateAddressData(base::Bind(&GetInfoFromProfile, profile)); |
| 3361 base::Bind(&GetInfoFromProfile, profile), &user_input); | 3360 user_input->language_code = AddressLanguageCodeForSection(section); |
| 3362 user_input.language_code = AddressLanguageCodeForSection(section); | |
| 3363 | 3361 |
| 3364 static const size_t kSuggestionsLimit = 10; | 3362 static const size_t kSuggestionsLimit = 10; |
| 3365 AddressValidator::Status status = GetValidator()->GetSuggestions( | 3363 AddressValidator::Status status = GetValidator()->GetSuggestions( |
| 3366 user_input, focused_field, kSuggestionsLimit, | 3364 *user_input, focused_field, kSuggestionsLimit, |
| 3367 &i18n_validator_suggestions_); | 3365 &i18n_validator_suggestions_); |
| 3368 | 3366 |
| 3369 if (status != AddressValidator::SUCCESS) | 3367 if (status != AddressValidator::SUCCESS) |
| 3370 return; | 3368 return; |
| 3371 | 3369 |
| 3372 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { | 3370 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
| 3373 popup_values->push_back(base::UTF8ToUTF16( | 3371 popup_values->push_back(base::UTF8ToUTF16( |
| 3374 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); | 3372 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); |
| 3375 | 3373 |
| 3376 // Disambiguate the suggestion by showing the smallest administrative | 3374 // Disambiguate the suggestion by showing the smallest administrative |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3573 // by the Online Wallet server, mark it invalid on selection. | 3571 // by the Online Wallet server, mark it invalid on selection. |
| 3574 return false; | 3572 return false; |
| 3575 } | 3573 } |
| 3576 } | 3574 } |
| 3577 | 3575 |
| 3578 return true; | 3576 return true; |
| 3579 } | 3577 } |
| 3580 | 3578 |
| 3581 bool AutofillDialogControllerImpl::HasInvalidAddress( | 3579 bool AutofillDialogControllerImpl::HasInvalidAddress( |
| 3582 const AutofillProfile& profile) { | 3580 const AutofillProfile& profile) { |
| 3583 AddressData address_data; | 3581 scoped_ptr<AddressData> address_data = |
| 3584 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), | 3582 i18n::CreateAddressData(base::Bind(&GetInfoFromProfile, profile)); |
| 3585 &address_data); | |
| 3586 | 3583 |
| 3587 AddressProblems problems; | 3584 AddressProblems problems; |
| 3588 GetValidator()->ValidateAddress(address_data, | 3585 GetValidator()->ValidateAddress(*address_data, |
| 3589 AddressProblemFilter(), | 3586 AddressProblemFilter(), |
| 3590 &problems); | 3587 &problems); |
| 3591 return !problems.empty(); | 3588 return !problems.empty(); |
| 3592 } | 3589 } |
| 3593 | 3590 |
| 3594 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { | 3591 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
| 3595 return SectionIsActive(SECTION_SHIPPING) && | 3592 return SectionIsActive(SECTION_SHIPPING) && |
| 3596 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; | 3593 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; |
| 3597 } | 3594 } |
| 3598 | 3595 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4081 view_->UpdateButtonStrip(); | 4078 view_->UpdateButtonStrip(); |
| 4082 } | 4079 } |
| 4083 | 4080 |
| 4084 void AutofillDialogControllerImpl::FetchWalletCookie() { | 4081 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 4085 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 4082 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 4086 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 4083 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 4087 signin_helper_->StartWalletCookieValueFetch(); | 4084 signin_helper_->StartWalletCookieValueFetch(); |
| 4088 } | 4085 } |
| 4089 | 4086 |
| 4090 } // namespace autofill | 4087 } // namespace autofill |
| OLD | NEW |