| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #include "content/public/browser/navigation_entry.h" | 73 #include "content/public/browser/navigation_entry.h" |
| 74 #include "content/public/browser/notification_service.h" | 74 #include "content/public/browser/notification_service.h" |
| 75 #include "content/public/browser/notification_types.h" | 75 #include "content/public/browser/notification_types.h" |
| 76 #include "content/public/browser/render_view_host.h" | 76 #include "content/public/browser/render_view_host.h" |
| 77 #include "content/public/browser/web_contents.h" | 77 #include "content/public/browser/web_contents.h" |
| 78 #include "content/public/common/url_constants.h" | 78 #include "content/public/common/url_constants.h" |
| 79 #include "grit/chromium_strings.h" | 79 #include "grit/chromium_strings.h" |
| 80 #include "grit/component_scaled_resources.h" | 80 #include "grit/component_scaled_resources.h" |
| 81 #include "grit/components_strings.h" | 81 #include "grit/components_strings.h" |
| 82 #include "grit/generated_resources.h" | 82 #include "grit/generated_resources.h" |
| 83 #include "grit/libaddressinput_strings.h" |
| 83 #include "grit/platform_locale_settings.h" | 84 #include "grit/platform_locale_settings.h" |
| 84 #include "grit/theme_resources.h" | 85 #include "grit/theme_resources.h" |
| 85 #include "net/cert/cert_status_flags.h" | 86 #include "net/cert/cert_status_flags.h" |
| 86 #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h" | 87 #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h" |
| 87 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" | 88 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" |
| 88 #include "third_party/libaddressinput/messages.h" | 89 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" |
| 89 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da
ta.h" | 90 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_problem.h" |
| 90 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi
eld.h" | |
| 91 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_pr
oblem.h" | |
| 92 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" | |
| 93 #include "ui/base/base_window.h" | 91 #include "ui/base/base_window.h" |
| 94 #include "ui/base/l10n/l10n_util.h" | 92 #include "ui/base/l10n/l10n_util.h" |
| 95 #include "ui/base/models/combobox_model.h" | 93 #include "ui/base/models/combobox_model.h" |
| 96 #include "ui/base/resource/resource_bundle.h" | 94 #include "ui/base/resource/resource_bundle.h" |
| 97 #include "ui/gfx/canvas.h" | 95 #include "ui/gfx/canvas.h" |
| 98 #include "ui/gfx/image/image_skia_operations.h" | 96 #include "ui/gfx/image/image_skia_operations.h" |
| 99 #include "ui/gfx/skia_util.h" | 97 #include "ui/gfx/skia_util.h" |
| 100 | 98 |
| 101 using ::i18n::addressinput::AddressData; | 99 using ::i18n::addressinput::AddressData; |
| 102 using ::i18n::addressinput::AddressField; | 100 using ::i18n::addressinput::AddressField; |
| 103 using ::i18n::addressinput::AddressProblem; | 101 using ::i18n::addressinput::AddressProblem; |
| 104 using ::i18n::addressinput::ADMIN_AREA; | 102 using ::i18n::addressinput::AddressProblemFilter; |
| 105 using ::i18n::addressinput::DEPENDENT_LOCALITY; | 103 using ::i18n::addressinput::AddressProblems; |
| 106 using ::i18n::addressinput::Downloader; | 104 using ::i18n::addressinput::AddressValidator; |
| 107 using ::i18n::addressinput::FieldProblemMap; | |
| 108 using ::i18n::addressinput::Localization; | |
| 109 using ::i18n::addressinput::MISSING_REQUIRED_FIELD; | |
| 110 | 105 |
| 111 namespace autofill { | 106 namespace autofill { |
| 112 | 107 |
| 113 namespace { | 108 namespace { |
| 114 | 109 |
| 115 const char kAddNewItemKey[] = "add-new-item"; | 110 const char kAddNewItemKey[] = "add-new-item"; |
| 116 const char kManageItemsKey[] = "manage-items"; | 111 const char kManageItemsKey[] = "manage-items"; |
| 117 const char kSameAsBillingKey[] = "same-as-billing"; | 112 const char kSameAsBillingKey[] = "same-as-billing"; |
| 118 | 113 |
| 119 // URLs for Wallet error messages. | 114 // URLs for Wallet error messages. |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 | 849 |
| 855 acceptable_cc_types_ = form_structure_.PossibleValues(CREDIT_CARD_TYPE); | 850 acceptable_cc_types_ = form_structure_.PossibleValues(CREDIT_CARD_TYPE); |
| 856 // Wallet generates MC virtual cards, so we have to disable it if MC is not | 851 // Wallet generates MC virtual cards, so we have to disable it if MC is not |
| 857 // allowed. | 852 // allowed. |
| 858 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard))) | 853 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard))) |
| 859 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT); | 854 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT); |
| 860 | 855 |
| 861 if (account_chooser_model_->WalletIsSelected()) | 856 if (account_chooser_model_->WalletIsSelected()) |
| 862 FetchWalletCookie(); | 857 FetchWalletCookie(); |
| 863 | 858 |
| 864 validator_.reset(new AddressValidator( | 859 scoped_ptr< ::i18n::addressinput::Downloader> downloader( |
| 865 I18N_ADDRESS_VALIDATION_DATA_URL, | 860 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())); |
| 866 scoped_ptr<Downloader>( | 861 validator_ = AddressValidator::Build( |
| 867 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())), | 862 downloader.Pass(), |
| 868 ValidationRulesStorageFactory::CreateStorage(), | 863 ValidationRulesStorageFactory::CreateStorage(), |
| 869 this)); | 864 this); |
| 870 | 865 |
| 871 SuggestionsUpdated(); | 866 SuggestionsUpdated(); |
| 872 SubmitButtonDelayBegin(); | 867 SubmitButtonDelayBegin(); |
| 873 view_.reset(CreateView()); | 868 view_.reset(CreateView()); |
| 874 view_->Show(); | 869 view_->Show(); |
| 875 GetManager()->AddObserver(this); | 870 GetManager()->AddObserver(this); |
| 876 | 871 |
| 877 if (!account_chooser_model_->WalletIsSelected()) | 872 if (!account_chooser_model_->WalletIsSelected()) |
| 878 LogDialogLatencyToShow(); | 873 LogDialogLatencyToShow(); |
| 879 } | 874 } |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 base::string16 message = CreditCardNumberValidityMessage(value); | 1926 base::string16 message = CreditCardNumberValidityMessage(value); |
| 1932 if (!message.empty()) | 1927 if (!message.empty()) |
| 1933 return message; | 1928 return message; |
| 1934 } | 1929 } |
| 1935 break; | 1930 break; |
| 1936 } | 1931 } |
| 1937 | 1932 |
| 1938 case CREDIT_CARD_EXP_MONTH: | 1933 case CREDIT_CARD_EXP_MONTH: |
| 1939 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { | 1934 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { |
| 1940 return l10n_util::GetStringUTF16( | 1935 return l10n_util::GetStringUTF16( |
| 1941 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); | 1936 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); |
| 1942 } | 1937 } |
| 1943 break; | 1938 break; |
| 1944 | 1939 |
| 1945 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 1940 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 1946 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { | 1941 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { |
| 1947 return l10n_util::GetStringUTF16( | 1942 return l10n_util::GetStringUTF16( |
| 1948 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); | 1943 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); |
| 1949 } | 1944 } |
| 1950 break; | 1945 break; |
| 1951 | 1946 |
| 1952 case CREDIT_CARD_VERIFICATION_CODE: | 1947 case CREDIT_CARD_VERIFICATION_CODE: |
| 1953 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { | 1948 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { |
| 1954 return l10n_util::GetStringUTF16( | 1949 return l10n_util::GetStringUTF16( |
| 1955 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); | 1950 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); |
| 1956 } | 1951 } |
| 1957 break; | 1952 break; |
| 1958 | 1953 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1970 | 1965 |
| 1971 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. | 1966 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. |
| 1972 break; | 1967 break; |
| 1973 | 1968 |
| 1974 default: | 1969 default: |
| 1975 NOTREACHED(); // Trying to validate unknown field. | 1970 NOTREACHED(); // Trying to validate unknown field. |
| 1976 break; | 1971 break; |
| 1977 } | 1972 } |
| 1978 | 1973 |
| 1979 return value.empty() ? l10n_util::GetStringUTF16( | 1974 return value.empty() ? l10n_util::GetStringUTF16( |
| 1980 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD) : | 1975 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD) : |
| 1981 base::string16(); | 1976 base::string16(); |
| 1982 } | 1977 } |
| 1983 | 1978 |
| 1984 // TODO(groby): Also add tests. | 1979 // TODO(groby): Also add tests. |
| 1985 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( | 1980 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| 1986 DialogSection section, | 1981 DialogSection section, |
| 1987 const FieldValueMap& inputs) { | 1982 const FieldValueMap& inputs) { |
| 1988 ValidityMessages messages; | 1983 ValidityMessages messages; |
| 1989 if (inputs.empty()) | 1984 if (inputs.empty()) |
| 1990 return messages; | 1985 return messages; |
| 1991 | 1986 |
| 1992 AddressValidator::Status status = AddressValidator::SUCCESS; | 1987 AddressValidator::Status status = AddressValidator::SUCCESS; |
| 1993 if (section != SECTION_CC) { | 1988 if (section != SECTION_CC) { |
| 1994 AutofillProfile profile; | 1989 AutofillProfile profile; |
| 1995 FillFormGroupFromOutputs(inputs, &profile); | 1990 FillFormGroupFromOutputs(inputs, &profile); |
| 1996 scoped_ptr<AddressData> address_data = | 1991 scoped_ptr<AddressData> address_data = |
| 1997 i18n::CreateAddressDataFromAutofillProfile( | 1992 i18n::CreateAddressDataFromAutofillProfile( |
| 1998 profile, g_browser_process->GetApplicationLocale()); | 1993 profile, g_browser_process->GetApplicationLocale()); |
| 1999 address_data->language_code = AddressLanguageCodeForSection(section); | 1994 address_data->language_code = AddressLanguageCodeForSection(section); |
| 2000 | 1995 |
| 2001 Localization localization; | 1996 AddressProblems problems; |
| 2002 localization.SetGetter(l10n_util::GetStringUTF8); | 1997 status = GetValidator()->ValidateAddress(*address_data, |
| 2003 FieldProblemMap problems; | 1998 AddressProblemFilter(), |
| 2004 status = GetValidator()->ValidateAddress(*address_data, NULL, &problems); | 1999 &problems); |
| 2005 common::AddressType address_type = section == SECTION_SHIPPING ? | 2000 common::AddressType address_type = section == SECTION_SHIPPING ? |
| 2006 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 2001 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
| 2007 | 2002 for (size_t i = 0; i < problems.size(); ++i) { |
| 2008 for (FieldProblemMap::const_iterator iter = problems.begin(); | 2003 const AddressProblem& problem = problems[i]; |
| 2009 iter != problems.end(); ++iter) { | 2004 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
| 2010 bool sure = iter->second != MISSING_REQUIRED_FIELD; | 2005 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); |
| 2011 base::string16 text = base::UTF8ToUTF16(localization.GetErrorMessage( | 2006 messages.Set(i18ninput::TypeForField(problem.field, address_type), |
| 2012 *address_data, iter->first, iter->second, true, false)); | |
| 2013 messages.Set(i18ninput::TypeForField(iter->first, address_type), | |
| 2014 ValidityMessage(text, sure)); | 2007 ValidityMessage(text, sure)); |
| 2015 } | 2008 } |
| 2016 } | 2009 } |
| 2017 | 2010 |
| 2018 for (FieldValueMap::const_iterator iter = inputs.begin(); | 2011 for (FieldValueMap::const_iterator iter = inputs.begin(); |
| 2019 iter != inputs.end(); ++iter) { | 2012 iter != inputs.end(); ++iter) { |
| 2020 const ServerFieldType type = iter->first; | 2013 const ServerFieldType type = iter->first; |
| 2021 base::string16 text = InputValidityMessage(section, type, iter->second); | 2014 base::string16 text = InputValidityMessage(section, type, iter->second); |
| 2022 | 2015 |
| 2023 // Skip empty/unchanged fields in edit mode. If the individual field does | 2016 // Skip empty/unchanged fields in edit mode. If the individual field does |
| (...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3423 return; | 3416 return; |
| 3424 | 3417 |
| 3425 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { | 3418 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
| 3426 popup_values->push_back(base::UTF8ToUTF16( | 3419 popup_values->push_back(base::UTF8ToUTF16( |
| 3427 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); | 3420 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); |
| 3428 | 3421 |
| 3429 // Disambiguate the suggestion by showing the smallest administrative | 3422 // Disambiguate the suggestion by showing the smallest administrative |
| 3430 // region of the suggested address: | 3423 // region of the suggested address: |
| 3431 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY | 3424 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY |
| 3432 popup_labels->push_back(base::string16()); | 3425 popup_labels->push_back(base::string16()); |
| 3433 for (int field = DEPENDENT_LOCALITY; field >= ADMIN_AREA; --field) { | 3426 for (int field = ::i18n::addressinput::DEPENDENT_LOCALITY; |
| 3427 field >= ::i18n::addressinput::ADMIN_AREA; |
| 3428 --field) { |
| 3434 const std::string& field_value = | 3429 const std::string& field_value = |
| 3435 i18n_validator_suggestions_[i].GetFieldValue( | 3430 i18n_validator_suggestions_[i].GetFieldValue( |
| 3436 static_cast<AddressField>(field)); | 3431 static_cast<AddressField>(field)); |
| 3437 if (focused_field != field && !field_value.empty()) { | 3432 if (focused_field != field && !field_value.empty()) { |
| 3438 popup_labels->back().assign(base::UTF8ToUTF16(field_value)); | 3433 popup_labels->back().assign(base::UTF8ToUTF16(field_value)); |
| 3439 break; | 3434 break; |
| 3440 } | 3435 } |
| 3441 } | 3436 } |
| 3442 } | 3437 } |
| 3443 popup_icons->resize(popup_values->size()); | 3438 popup_icons->resize(popup_values->size()); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3606 | 3601 |
| 3607 FieldValueMap detail_outputs; | 3602 FieldValueMap detail_outputs; |
| 3608 view_->GetUserInput(section, &detail_outputs); | 3603 view_->GetUserInput(section, &detail_outputs); |
| 3609 return !InputsAreValid(section, detail_outputs).HasSureErrors(); | 3604 return !InputsAreValid(section, detail_outputs).HasSureErrors(); |
| 3610 } | 3605 } |
| 3611 | 3606 |
| 3612 bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { | 3607 bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { |
| 3613 AddressData address_data; | 3608 AddressData address_data; |
| 3614 address_data.region_code = CountryCodeForSection(section); | 3609 address_data.region_code = CountryCodeForSection(section); |
| 3615 AddressValidator::Status status = GetValidator()->ValidateAddress( | 3610 AddressValidator::Status status = GetValidator()->ValidateAddress( |
| 3616 address_data, NULL, NULL); | 3611 address_data, AddressProblemFilter(), NULL); |
| 3617 return status == AddressValidator::SUCCESS; | 3612 return status == AddressValidator::SUCCESS; |
| 3618 } | 3613 } |
| 3619 | 3614 |
| 3620 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( | 3615 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( |
| 3621 const base::string16& year, | 3616 const base::string16& year, |
| 3622 const base::string16& month) const { | 3617 const base::string16& month) const { |
| 3623 // If the expiration is in the past as per the local clock, it's invalid. | 3618 // If the expiration is in the past as per the local clock, it's invalid. |
| 3624 base::Time now = base::Time::Now(); | 3619 base::Time now = base::Time::Now(); |
| 3625 if (!autofill::IsValidCreditCardExpirationDate(year, month, now)) | 3620 if (!autofill::IsValidCreditCardExpirationDate(year, month, now)) |
| 3626 return false; | 3621 return false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3658 | 3653 |
| 3659 return false; | 3654 return false; |
| 3660 } | 3655 } |
| 3661 | 3656 |
| 3662 bool AutofillDialogControllerImpl::HasInvalidAddress( | 3657 bool AutofillDialogControllerImpl::HasInvalidAddress( |
| 3663 const AutofillProfile& profile) { | 3658 const AutofillProfile& profile) { |
| 3664 scoped_ptr<AddressData> address_data = | 3659 scoped_ptr<AddressData> address_data = |
| 3665 i18n::CreateAddressDataFromAutofillProfile( | 3660 i18n::CreateAddressDataFromAutofillProfile( |
| 3666 profile, g_browser_process->GetApplicationLocale()); | 3661 profile, g_browser_process->GetApplicationLocale()); |
| 3667 | 3662 |
| 3668 FieldProblemMap problems; | 3663 AddressProblems problems; |
| 3669 GetValidator()->ValidateAddress(*address_data, NULL, &problems); | 3664 GetValidator()->ValidateAddress(*address_data, |
| 3665 AddressProblemFilter(), |
| 3666 &problems); |
| 3670 return !problems.empty(); | 3667 return !problems.empty(); |
| 3671 } | 3668 } |
| 3672 | 3669 |
| 3673 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { | 3670 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
| 3674 return SectionIsActive(SECTION_SHIPPING) && | 3671 return SectionIsActive(SECTION_SHIPPING) && |
| 3675 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; | 3672 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; |
| 3676 } | 3673 } |
| 3677 | 3674 |
| 3678 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { | 3675 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { |
| 3679 // It's possible that the user checked [X] Save details locally before | 3676 // It's possible that the user checked [X] Save details locally before |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4158 view_->UpdateButtonStrip(); | 4155 view_->UpdateButtonStrip(); |
| 4159 } | 4156 } |
| 4160 | 4157 |
| 4161 void AutofillDialogControllerImpl::FetchWalletCookie() { | 4158 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 4162 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 4159 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 4163 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 4160 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 4164 signin_helper_->StartWalletCookieValueFetch(); | 4161 signin_helper_->StartWalletCookieValueFetch(); |
| 4165 } | 4162 } |
| 4166 | 4163 |
| 4167 } // namespace autofill | 4164 } // namespace autofill |
| OLD | NEW |