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

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

Issue 261013010: autocomplete: add ability to get full address (hidden behind a flag). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX); 513 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX);
513 514
514 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); 515 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
515 } 516 }
516 517
517 ServerFieldType CountryTypeForSection(DialogSection section) { 518 ServerFieldType CountryTypeForSection(DialogSection section) {
518 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : 519 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY :
519 ADDRESS_BILLING_COUNTRY; 520 ADDRESS_BILLING_COUNTRY;
520 } 521 }
521 522
522 // profile.GetInfo() thunk.
523 base::string16 GetInfoFromProfile(const AutofillProfile& profile,
524 const AutofillType& type) {
525 return profile.GetInfo(type, g_browser_process->GetApplicationLocale());
526 }
527
528 // Attempts to canonicalize the administrative area name in |profile| using the 523 // Attempts to canonicalize the administrative area name in |profile| using the
529 // rules in |validator|. 524 // rules in |validator|.
530 void CanonicalizeState(const AddressValidator* validator, 525 void CanonicalizeState(const AddressValidator* validator,
531 AutofillProfile* profile) { 526 AutofillProfile* profile) {
532 base::string16 administrative_area; 527 base::string16 administrative_area;
533 AddressData address_data; 528 scoped_ptr<AddressData> address_data =
534 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, *profile), 529 i18n::CreateAddressDataFromAutofillProfile(
535 &address_data); 530 *profile, g_browser_process->GetApplicationLocale());
536 531
537 validator->CanonicalizeAdministrativeArea(&address_data); 532 validator->CanonicalizeAdministrativeArea(address_data.get());
538 administrative_area = base::UTF8ToUTF16(address_data.administrative_area); 533 administrative_area = base::UTF8ToUTF16(address_data->administrative_area);
539 534
540 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), 535 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE),
541 administrative_area, 536 administrative_area,
542 g_browser_process->GetApplicationLocale()); 537 g_browser_process->GetApplicationLocale());
543 } 538 }
544 539
545 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name, 540 ValidityMessage GetPhoneValidityMessage(const base::string16& country_name,
546 const base::string16& number) { 541 const base::string16& number) {
547 std::string region = AutofillCountry::GetCountryCode( 542 std::string region = AutofillCountry::GetCountryCode(
548 country_name, 543 country_name,
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 DialogSection section, 1951 DialogSection section,
1957 const FieldValueMap& inputs) { 1952 const FieldValueMap& inputs) {
1958 ValidityMessages messages; 1953 ValidityMessages messages;
1959 if (inputs.empty()) 1954 if (inputs.empty())
1960 return messages; 1955 return messages;
1961 1956
1962 AddressValidator::Status status = AddressValidator::SUCCESS; 1957 AddressValidator::Status status = AddressValidator::SUCCESS;
1963 if (section != SECTION_CC) { 1958 if (section != SECTION_CC) {
1964 AutofillProfile profile; 1959 AutofillProfile profile;
1965 FillFormGroupFromOutputs(inputs, &profile); 1960 FillFormGroupFromOutputs(inputs, &profile);
1966 AddressData address_data; 1961 scoped_ptr<AddressData> address_data =
1967 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), 1962 i18n::CreateAddressDataFromAutofillProfile(
1968 &address_data); 1963 profile, g_browser_process->GetApplicationLocale());
1969 address_data.language_code = AddressLanguageCodeForSection(section); 1964 address_data->language_code = AddressLanguageCodeForSection(section);
1970 1965
1971 AddressProblems problems; 1966 AddressProblems problems;
1972 status = GetValidator()->ValidateAddress(address_data, 1967 status = GetValidator()->ValidateAddress(*address_data,
1973 AddressProblemFilter(), 1968 AddressProblemFilter(),
1974 &problems); 1969 &problems);
1975 common::AddressType address_type = section == SECTION_SHIPPING ? 1970 common::AddressType address_type = section == SECTION_SHIPPING ?
1976 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; 1971 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING;
1977 for (size_t i = 0; i < problems.size(); ++i) { 1972 for (size_t i = 0; i < problems.size(); ++i) {
1978 const AddressProblem& problem = problems[i]; 1973 const AddressProblem& problem = problems[i];
1979 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; 1974 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD;
1980 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); 1975 base::string16 text = l10n_util::GetStringUTF16(problem.description_id);
1981 messages.Set(i18ninput::TypeForField(problem.field, address_type), 1976 messages.Set(i18ninput::TypeForField(problem.field, address_type),
1982 ValidityMessage(text, sure)); 1977 ValidityMessage(text, sure));
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
3028 cards[i]->Label(), 3023 cards[i]->Label(),
3029 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); 3024 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type())));
3030 } 3025 }
3031 3026
3032 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); 3027 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles();
3033 std::vector<base::string16> labels; 3028 std::vector<base::string16> labels;
3034 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); 3029 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels);
3035 DCHECK_EQ(labels.size(), profiles.size()); 3030 DCHECK_EQ(labels.size(), profiles.size());
3036 for (size_t i = 0; i < profiles.size(); ++i) { 3031 for (size_t i = 0; i < profiles.size(); ++i) {
3037 const AutofillProfile& profile = *profiles[i]; 3032 const AutofillProfile& profile = *profiles[i];
3038 if (!i18ninput::AddressHasCompleteAndVerifiedData(profile) || 3033 if (!i18ninput::AddressHasCompleteAndVerifiedData(
3034 profile, g_browser_process->GetApplicationLocale()) ||
3039 !i18ninput::CountryIsFullySupported( 3035 !i18ninput::CountryIsFullySupported(
3040 base::UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))) { 3036 base::UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))) {
3041 continue; 3037 continue;
3042 } 3038 }
3043 3039
3044 // Don't add variants for addresses: name is part of credit card and 3040 // Don't add variants for addresses: name is part of credit card and
3045 // we'll just ignore email and phone number variants. 3041 // we'll just ignore email and phone number variants.
3046 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); 3042 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]);
3047 suggested_shipping_.SetEnabled( 3043 suggested_shipping_.SetEnabled(
3048 profile.guid(), 3044 profile.guid(),
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
3349 AddressField focused_field; 3345 AddressField focused_field;
3350 if (!i18ninput::FieldForType(type, &focused_field)) 3346 if (!i18ninput::FieldForType(type, &focused_field))
3351 return; 3347 return;
3352 3348
3353 FieldValueMap inputs; 3349 FieldValueMap inputs;
3354 view_->GetUserInput(section, &inputs); 3350 view_->GetUserInput(section, &inputs);
3355 3351
3356 AutofillProfile profile; 3352 AutofillProfile profile;
3357 FillFormGroupFromOutputs(inputs, &profile); 3353 FillFormGroupFromOutputs(inputs, &profile);
3358 3354
3359 AddressData user_input; 3355 scoped_ptr<AddressData> user_input =
3360 i18ninput::CreateAddressData( 3356 i18n::CreateAddressDataFromAutofillProfile(
3361 base::Bind(&GetInfoFromProfile, profile), &user_input); 3357 profile, g_browser_process->GetApplicationLocale());
3362 user_input.language_code = AddressLanguageCodeForSection(section); 3358 user_input->language_code = AddressLanguageCodeForSection(section);
3363 3359
3364 static const size_t kSuggestionsLimit = 10; 3360 static const size_t kSuggestionsLimit = 10;
3365 AddressValidator::Status status = GetValidator()->GetSuggestions( 3361 AddressValidator::Status status = GetValidator()->GetSuggestions(
3366 user_input, focused_field, kSuggestionsLimit, 3362 *user_input, focused_field, kSuggestionsLimit,
3367 &i18n_validator_suggestions_); 3363 &i18n_validator_suggestions_);
3368 3364
3369 if (status != AddressValidator::SUCCESS) 3365 if (status != AddressValidator::SUCCESS)
3370 return; 3366 return;
3371 3367
3372 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { 3368 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) {
3373 popup_values->push_back(base::UTF8ToUTF16( 3369 popup_values->push_back(base::UTF8ToUTF16(
3374 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); 3370 i18n_validator_suggestions_[i].GetFieldValue(focused_field)));
3375 3371
3376 // Disambiguate the suggestion by showing the smallest administrative 3372 // Disambiguate the suggestion by showing the smallest administrative
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
3573 // by the Online Wallet server, mark it invalid on selection. 3569 // by the Online Wallet server, mark it invalid on selection.
3574 return false; 3570 return false;
3575 } 3571 }
3576 } 3572 }
3577 3573
3578 return true; 3574 return true;
3579 } 3575 }
3580 3576
3581 bool AutofillDialogControllerImpl::HasInvalidAddress( 3577 bool AutofillDialogControllerImpl::HasInvalidAddress(
3582 const AutofillProfile& profile) { 3578 const AutofillProfile& profile) {
3583 AddressData address_data; 3579 scoped_ptr<AddressData> address_data =
3584 i18ninput::CreateAddressData(base::Bind(&GetInfoFromProfile, profile), 3580 i18n::CreateAddressDataFromAutofillProfile(
3585 &address_data); 3581 profile, g_browser_process->GetApplicationLocale());
3586 3582
3587 AddressProblems problems; 3583 AddressProblems problems;
3588 GetValidator()->ValidateAddress(address_data, 3584 GetValidator()->ValidateAddress(*address_data,
3589 AddressProblemFilter(), 3585 AddressProblemFilter(),
3590 &problems); 3586 &problems);
3591 return !problems.empty(); 3587 return !problems.empty();
3592 } 3588 }
3593 3589
3594 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { 3590 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
3595 return SectionIsActive(SECTION_SHIPPING) && 3591 return SectionIsActive(SECTION_SHIPPING) &&
3596 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; 3592 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
3597 } 3593 }
3598 3594
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
4081 view_->UpdateButtonStrip(); 4077 view_->UpdateButtonStrip();
4082 } 4078 }
4083 4079
4084 void AutofillDialogControllerImpl::FetchWalletCookie() { 4080 void AutofillDialogControllerImpl::FetchWalletCookie() {
4085 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 4081 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
4086 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 4082 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
4087 signin_helper_->StartWalletCookieValueFetch(); 4083 signin_helper_->StartWalletCookieValueFetch();
4088 } 4084 }
4089 4085
4090 } // namespace autofill 4086 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698