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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX); | 505 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX); |
505 | 506 |
506 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); | 507 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); |
507 } | 508 } |
508 | 509 |
509 ServerFieldType CountryTypeForSection(DialogSection section) { | 510 ServerFieldType CountryTypeForSection(DialogSection section) { |
510 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : | 511 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : |
511 ADDRESS_BILLING_COUNTRY; | 512 ADDRESS_BILLING_COUNTRY; |
512 } | 513 } |
513 | 514 |
514 // profile.GetInfo() thunk. | |
515 base::string16 GetInfoFromProfile(const AutofillProfile& profile, | |
516 const AutofillType& type) { | |
517 return profile.GetInfo(type, g_browser_process->GetApplicationLocale()); | |
518 } | |
519 | |
520 // Attempts to canonicalize the administrative area name in |profile| using the | 515 // Attempts to canonicalize the administrative area name in |profile| using the |
521 // rules in |validator|. | 516 // rules in |validator|. |
522 void CanonicalizeState(const AddressValidator* validator, | 517 void CanonicalizeState(const AddressValidator* validator, |
523 AutofillProfile* profile) { | 518 AutofillProfile* profile) { |
524 base::string16 administrative_area; | 519 base::string16 administrative_area; |
525 AddressData address_data; | 520 scoped_ptr<AddressData> address_data = |
526 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, *profile), | 521 i18n::CreateAddressDataFromAutofillProfile( |
527 &address_data); | 522 *profile, g_browser_process->GetApplicationLocale()); |
528 | 523 |
529 validator->CanonicalizeAdministrativeArea(&address_data); | 524 validator->CanonicalizeAdministrativeArea(address_data.get()); |
530 administrative_area = base::UTF8ToUTF16(address_data.administrative_area); | 525 administrative_area = base::UTF8ToUTF16(address_data->administrative_area); |
531 | 526 |
532 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), | 527 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), |
533 administrative_area, | 528 administrative_area, |
534 g_browser_process->GetApplicationLocale()); | 529 g_browser_process->GetApplicationLocale()); |
535 } | 530 } |
536 | 531 |
537 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name, | 532 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name, |
538 const base::string16& number) { | 533 const base::string16& number) { |
539 std::string region = AutofillCountry::GetCountryCode( | 534 std::string region = AutofillCountry::GetCountryCode( |
540 country_name, | 535 country_name, |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 DialogSection section, | 1943 DialogSection section, |
1949 const FieldValueMap& inputs) { | 1944 const FieldValueMap& inputs) { |
1950 ValidityMessages messages; | 1945 ValidityMessages messages; |
1951 if (inputs.empty()) | 1946 if (inputs.empty()) |
1952 return messages; | 1947 return messages; |
1953 | 1948 |
1954 AddressValidator::Status status = AddressValidator::SUCCESS; | 1949 AddressValidator::Status status = AddressValidator::SUCCESS; |
1955 if (section != SECTION_CC) { | 1950 if (section != SECTION_CC) { |
1956 AutofillProfile profile; | 1951 AutofillProfile profile; |
1957 FillFormGroupFromOutputs(inputs, &profile); | 1952 FillFormGroupFromOutputs(inputs, &profile); |
1958 AddressData address_data; | 1953 scoped_ptr<AddressData> address_data = |
1959 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), | 1954 i18n::CreateAddressDataFromAutofillProfile( |
1960 &address_data); | 1955 profile, g_browser_process->GetApplicationLocale()); |
1961 address_data.language_code = AddressLanguageCodeForSection(section); | 1956 address_data->language_code = AddressLanguageCodeForSection(section); |
1962 | 1957 |
1963 AddressProblems problems; | 1958 AddressProblems problems; |
1964 status = GetValidator()->ValidateAddress(address_data, | 1959 status = GetValidator()->ValidateAddress(*address_data, |
1965 AddressProblemFilter(), | 1960 AddressProblemFilter(), |
1966 &problems); | 1961 &problems); |
1967 common::AddressType address_type = section == SECTION_SHIPPING ? | 1962 common::AddressType address_type = section == SECTION_SHIPPING ? |
1968 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 1963 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
1969 for (size_t i = 0; i < problems.size(); ++i) { | 1964 for (size_t i = 0; i < problems.size(); ++i) { |
1970 const AddressProblem& problem = problems[i]; | 1965 const AddressProblem& problem = problems[i]; |
1971 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; | 1966 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
1972 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); | 1967 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); |
1973 messages.Set(i18ninput::TypeForField(problem.field, address_type), | 1968 messages.Set(i18ninput::TypeForField(problem.field, address_type), |
1974 ValidityMessage(text, sure)); | 1969 ValidityMessage(text, sure)); |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3020 cards[i]->Label(), | 3015 cards[i]->Label(), |
3021 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); | 3016 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); |
3022 } | 3017 } |
3023 | 3018 |
3024 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 3019 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
3025 std::vector<base::string16> labels; | 3020 std::vector<base::string16> labels; |
3026 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); | 3021 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); |
3027 DCHECK_EQ(labels.size(), profiles.size()); | 3022 DCHECK_EQ(labels.size(), profiles.size()); |
3028 for (size_t i = 0; i < profiles.size(); ++i) { | 3023 for (size_t i = 0; i < profiles.size(); ++i) { |
3029 const AutofillProfile& profile = *profiles[i]; | 3024 const AutofillProfile& profile = *profiles[i]; |
3030 if (!i18ninput::AddressHasCompleteAndVerifiedData(profile) || | 3025 if (!i18ninput::AddressHasCompleteAndVerifiedData( |
| 3026 profile, g_browser_process->GetApplicationLocale()) || |
3031 !i18ninput::CountryIsFullySupported( | 3027 !i18ninput::CountryIsFullySupported( |
3032 base::UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))) { | 3028 base::UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))) { |
3033 continue; | 3029 continue; |
3034 } | 3030 } |
3035 | 3031 |
3036 // Don't add variants for addresses: name is part of credit card and | 3032 // Don't add variants for addresses: name is part of credit card and |
3037 // we'll just ignore email and phone number variants. | 3033 // we'll just ignore email and phone number variants. |
3038 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); | 3034 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); |
3039 suggested_shipping_.SetEnabled( | 3035 suggested_shipping_.SetEnabled( |
3040 profile.guid(), | 3036 profile.guid(), |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3341 AddressField focused_field; | 3337 AddressField focused_field; |
3342 if (!i18ninput::FieldForType(type, &focused_field)) | 3338 if (!i18ninput::FieldForType(type, &focused_field)) |
3343 return; | 3339 return; |
3344 | 3340 |
3345 FieldValueMap inputs; | 3341 FieldValueMap inputs; |
3346 view_->GetUserInput(section, &inputs); | 3342 view_->GetUserInput(section, &inputs); |
3347 | 3343 |
3348 AutofillProfile profile; | 3344 AutofillProfile profile; |
3349 FillFormGroupFromOutputs(inputs, &profile); | 3345 FillFormGroupFromOutputs(inputs, &profile); |
3350 | 3346 |
3351 AddressData user_input; | 3347 scoped_ptr<AddressData> user_input = |
3352 i18ninput::CreateAddressData( | 3348 i18n::CreateAddressDataFromAutofillProfile( |
3353 base::Bind(&GetInfoFromProfile, profile), &user_input); | 3349 profile, g_browser_process->GetApplicationLocale()); |
3354 user_input.language_code = AddressLanguageCodeForSection(section); | 3350 user_input->language_code = AddressLanguageCodeForSection(section); |
3355 | 3351 |
3356 static const size_t kSuggestionsLimit = 10; | 3352 static const size_t kSuggestionsLimit = 10; |
3357 AddressValidator::Status status = GetValidator()->GetSuggestions( | 3353 AddressValidator::Status status = GetValidator()->GetSuggestions( |
3358 user_input, focused_field, kSuggestionsLimit, | 3354 *user_input, focused_field, kSuggestionsLimit, |
3359 &i18n_validator_suggestions_); | 3355 &i18n_validator_suggestions_); |
3360 | 3356 |
3361 if (status != AddressValidator::SUCCESS) | 3357 if (status != AddressValidator::SUCCESS) |
3362 return; | 3358 return; |
3363 | 3359 |
3364 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { | 3360 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
3365 popup_values->push_back(base::UTF8ToUTF16( | 3361 popup_values->push_back(base::UTF8ToUTF16( |
3366 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); | 3362 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); |
3367 | 3363 |
3368 // Disambiguate the suggestion by showing the smallest administrative | 3364 // Disambiguate the suggestion by showing the smallest administrative |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3565 // by the Online Wallet server, mark it invalid on selection. | 3561 // by the Online Wallet server, mark it invalid on selection. |
3566 return false; | 3562 return false; |
3567 } | 3563 } |
3568 } | 3564 } |
3569 | 3565 |
3570 return true; | 3566 return true; |
3571 } | 3567 } |
3572 | 3568 |
3573 bool AutofillDialogControllerImpl::HasInvalidAddress( | 3569 bool AutofillDialogControllerImpl::HasInvalidAddress( |
3574 const AutofillProfile& profile) { | 3570 const AutofillProfile& profile) { |
3575 AddressData address_data; | 3571 scoped_ptr<AddressData> address_data = |
3576 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), | 3572 i18n::CreateAddressDataFromAutofillProfile( |
3577 &address_data); | 3573 profile, g_browser_process->GetApplicationLocale()); |
3578 | 3574 |
3579 AddressProblems problems; | 3575 AddressProblems problems; |
3580 GetValidator()->ValidateAddress(address_data, | 3576 GetValidator()->ValidateAddress(*address_data, |
3581 AddressProblemFilter(), | 3577 AddressProblemFilter(), |
3582 &problems); | 3578 &problems); |
3583 return !problems.empty(); | 3579 return !problems.empty(); |
3584 } | 3580 } |
3585 | 3581 |
3586 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { | 3582 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
3587 return SectionIsActive(SECTION_SHIPPING) && | 3583 return SectionIsActive(SECTION_SHIPPING) && |
3588 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; | 3584 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; |
3589 } | 3585 } |
3590 | 3586 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4071 view_->UpdateButtonStrip(); | 4067 view_->UpdateButtonStrip(); |
4072 } | 4068 } |
4073 | 4069 |
4074 void AutofillDialogControllerImpl::FetchWalletCookie() { | 4070 void AutofillDialogControllerImpl::FetchWalletCookie() { |
4075 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 4071 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
4076 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 4072 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
4077 signin_helper_->StartWalletCookieValueFetch(); | 4073 signin_helper_->StartWalletCookieValueFetch(); |
4078 } | 4074 } |
4079 | 4075 |
4080 } // namespace autofill | 4076 } // namespace autofill |
OLD | NEW |