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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 | 860 |
866 acceptable_cc_types_ = form_structure_.PossibleValues(CREDIT_CARD_TYPE); | 861 acceptable_cc_types_ = form_structure_.PossibleValues(CREDIT_CARD_TYPE); |
867 // Wallet generates MC virtual cards, so we have to disable it if MC is not | 862 // Wallet generates MC virtual cards, so we have to disable it if MC is not |
868 // allowed. | 863 // allowed. |
869 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard))) | 864 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard))) |
870 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT); | 865 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT); |
871 | 866 |
872 if (account_chooser_model_->WalletIsSelected()) | 867 if (account_chooser_model_->WalletIsSelected()) |
873 FetchWalletCookie(); | 868 FetchWalletCookie(); |
874 | 869 |
875 validator_.reset(new AddressValidator( | 870 scoped_ptr< ::i18n::addressinput::Downloader> downloader( |
876 I18N_ADDRESS_VALIDATION_DATA_URL, | 871 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())); |
877 scoped_ptr<Downloader>( | 872 validator_ = AddressValidator::Build( |
878 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())), | 873 downloader.Pass(), |
879 ValidationRulesStorageFactory::CreateStorage(), | 874 ValidationRulesStorageFactory::CreateStorage(), |
880 this)); | 875 this); |
881 | 876 |
882 SuggestionsUpdated(); | 877 SuggestionsUpdated(); |
883 SubmitButtonDelayBegin(); | 878 SubmitButtonDelayBegin(); |
884 view_.reset(CreateView()); | 879 view_.reset(CreateView()); |
885 view_->Show(); | 880 view_->Show(); |
886 GetManager()->AddObserver(this); | 881 GetManager()->AddObserver(this); |
887 | 882 |
888 if (!account_chooser_model_->WalletIsSelected()) | 883 if (!account_chooser_model_->WalletIsSelected()) |
889 LogDialogLatencyToShow(); | 884 LogDialogLatencyToShow(); |
890 } | 885 } |
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 base::string16 message = CreditCardNumberValidityMessage(value); | 1937 base::string16 message = CreditCardNumberValidityMessage(value); |
1943 if (!message.empty()) | 1938 if (!message.empty()) |
1944 return message; | 1939 return message; |
1945 } | 1940 } |
1946 break; | 1941 break; |
1947 } | 1942 } |
1948 | 1943 |
1949 case CREDIT_CARD_EXP_MONTH: | 1944 case CREDIT_CARD_EXP_MONTH: |
1950 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { | 1945 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { |
1951 return l10n_util::GetStringUTF16( | 1946 return l10n_util::GetStringUTF16( |
1952 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); | 1947 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); |
1953 } | 1948 } |
1954 break; | 1949 break; |
1955 | 1950 |
1956 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 1951 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
1957 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { | 1952 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { |
1958 return l10n_util::GetStringUTF16( | 1953 return l10n_util::GetStringUTF16( |
1959 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); | 1954 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); |
1960 } | 1955 } |
1961 break; | 1956 break; |
1962 | 1957 |
1963 case CREDIT_CARD_VERIFICATION_CODE: | 1958 case CREDIT_CARD_VERIFICATION_CODE: |
1964 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { | 1959 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { |
1965 return l10n_util::GetStringUTF16( | 1960 return l10n_util::GetStringUTF16( |
1966 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); | 1961 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); |
1967 } | 1962 } |
1968 break; | 1963 break; |
1969 | 1964 |
(...skipping 11 matching lines...) Expand all Loading... |
1981 | 1976 |
1982 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. | 1977 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. |
1983 break; | 1978 break; |
1984 | 1979 |
1985 default: | 1980 default: |
1986 NOTREACHED(); // Trying to validate unknown field. | 1981 NOTREACHED(); // Trying to validate unknown field. |
1987 break; | 1982 break; |
1988 } | 1983 } |
1989 | 1984 |
1990 return value.empty() ? l10n_util::GetStringUTF16( | 1985 return value.empty() ? l10n_util::GetStringUTF16( |
1991 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD) : | 1986 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD) : |
1992 base::string16(); | 1987 base::string16(); |
1993 } | 1988 } |
1994 | 1989 |
1995 // TODO(groby): Also add tests. | 1990 // TODO(groby): Also add tests. |
1996 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( | 1991 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
1997 DialogSection section, | 1992 DialogSection section, |
1998 const FieldValueMap& inputs) { | 1993 const FieldValueMap& inputs) { |
1999 ValidityMessages messages; | 1994 ValidityMessages messages; |
2000 if (inputs.empty()) | 1995 if (inputs.empty()) |
2001 return messages; | 1996 return messages; |
2002 | 1997 |
2003 AddressValidator::Status status = AddressValidator::SUCCESS; | 1998 AddressValidator::Status status = AddressValidator::SUCCESS; |
2004 if (section != SECTION_CC) { | 1999 if (section != SECTION_CC) { |
2005 AutofillProfile profile; | 2000 AutofillProfile profile; |
2006 FillFormGroupFromOutputs(inputs, &profile); | 2001 FillFormGroupFromOutputs(inputs, &profile); |
2007 scoped_ptr<AddressData> address_data = | 2002 scoped_ptr<AddressData> address_data = |
2008 i18n::CreateAddressDataFromAutofillProfile( | 2003 i18n::CreateAddressDataFromAutofillProfile( |
2009 profile, g_browser_process->GetApplicationLocale()); | 2004 profile, g_browser_process->GetApplicationLocale()); |
2010 address_data->language_code = AddressLanguageCodeForSection(section); | 2005 address_data->language_code = AddressLanguageCodeForSection(section); |
2011 | 2006 |
2012 Localization localization; | 2007 AddressProblems problems; |
2013 localization.SetGetter(l10n_util::GetStringUTF8); | 2008 status = GetValidator()->ValidateAddress(*address_data, |
2014 FieldProblemMap problems; | 2009 AddressProblemFilter(), |
2015 status = GetValidator()->ValidateAddress(*address_data, NULL, &problems); | 2010 &problems); |
2016 common::AddressType address_type = section == SECTION_SHIPPING ? | 2011 common::AddressType address_type = section == SECTION_SHIPPING ? |
2017 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 2012 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
2018 | 2013 for (size_t i = 0; i < problems.size(); ++i) { |
2019 for (FieldProblemMap::const_iterator iter = problems.begin(); | 2014 const AddressProblem& problem = problems[i]; |
2020 iter != problems.end(); ++iter) { | 2015 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
2021 bool sure = iter->second != MISSING_REQUIRED_FIELD; | 2016 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); |
2022 base::string16 text = base::UTF8ToUTF16(localization.GetErrorMessage( | 2017 messages.Set(i18ninput::TypeForField(problem.field, address_type), |
2023 *address_data, iter->first, iter->second, true, false)); | |
2024 messages.Set(i18ninput::TypeForField(iter->first, address_type), | |
2025 ValidityMessage(text, sure)); | 2018 ValidityMessage(text, sure)); |
2026 } | 2019 } |
2027 } | 2020 } |
2028 | 2021 |
2029 for (FieldValueMap::const_iterator iter = inputs.begin(); | 2022 for (FieldValueMap::const_iterator iter = inputs.begin(); |
2030 iter != inputs.end(); ++iter) { | 2023 iter != inputs.end(); ++iter) { |
2031 const ServerFieldType type = iter->first; | 2024 const ServerFieldType type = iter->first; |
2032 base::string16 text = InputValidityMessage(section, type, iter->second); | 2025 base::string16 text = InputValidityMessage(section, type, iter->second); |
2033 | 2026 |
2034 // Skip empty/unchanged fields in edit mode. If the individual field does | 2027 // Skip empty/unchanged fields in edit mode. If the individual field does |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3431 return; | 3424 return; |
3432 | 3425 |
3433 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { | 3426 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
3434 popup_values->push_back(base::UTF8ToUTF16( | 3427 popup_values->push_back(base::UTF8ToUTF16( |
3435 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); | 3428 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); |
3436 | 3429 |
3437 // Disambiguate the suggestion by showing the smallest administrative | 3430 // Disambiguate the suggestion by showing the smallest administrative |
3438 // region of the suggested address: | 3431 // region of the suggested address: |
3439 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY | 3432 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY |
3440 popup_labels->push_back(base::string16()); | 3433 popup_labels->push_back(base::string16()); |
3441 for (int field = DEPENDENT_LOCALITY; field >= ADMIN_AREA; --field) { | 3434 for (int field = ::i18n::addressinput::DEPENDENT_LOCALITY; |
| 3435 field >= ::i18n::addressinput::ADMIN_AREA; |
| 3436 --field) { |
3442 const std::string& field_value = | 3437 const std::string& field_value = |
3443 i18n_validator_suggestions_[i].GetFieldValue( | 3438 i18n_validator_suggestions_[i].GetFieldValue( |
3444 static_cast<AddressField>(field)); | 3439 static_cast<AddressField>(field)); |
3445 if (focused_field != field && !field_value.empty()) { | 3440 if (focused_field != field && !field_value.empty()) { |
3446 popup_labels->back().assign(base::UTF8ToUTF16(field_value)); | 3441 popup_labels->back().assign(base::UTF8ToUTF16(field_value)); |
3447 break; | 3442 break; |
3448 } | 3443 } |
3449 } | 3444 } |
3450 } | 3445 } |
3451 popup_icons->resize(popup_values->size()); | 3446 popup_icons->resize(popup_values->size()); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3614 | 3609 |
3615 FieldValueMap detail_outputs; | 3610 FieldValueMap detail_outputs; |
3616 view_->GetUserInput(section, &detail_outputs); | 3611 view_->GetUserInput(section, &detail_outputs); |
3617 return !InputsAreValid(section, detail_outputs).HasSureErrors(); | 3612 return !InputsAreValid(section, detail_outputs).HasSureErrors(); |
3618 } | 3613 } |
3619 | 3614 |
3620 bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { | 3615 bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { |
3621 AddressData address_data; | 3616 AddressData address_data; |
3622 address_data.region_code = CountryCodeForSection(section); | 3617 address_data.region_code = CountryCodeForSection(section); |
3623 AddressValidator::Status status = GetValidator()->ValidateAddress( | 3618 AddressValidator::Status status = GetValidator()->ValidateAddress( |
3624 address_data, NULL, NULL); | 3619 address_data, AddressProblemFilter(), NULL); |
3625 return status == AddressValidator::SUCCESS; | 3620 return status == AddressValidator::SUCCESS; |
3626 } | 3621 } |
3627 | 3622 |
3628 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( | 3623 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( |
3629 const base::string16& year, | 3624 const base::string16& year, |
3630 const base::string16& month) const { | 3625 const base::string16& month) const { |
3631 // If the expiration is in the past as per the local clock, it's invalid. | 3626 // If the expiration is in the past as per the local clock, it's invalid. |
3632 base::Time now = base::Time::Now(); | 3627 base::Time now = base::Time::Now(); |
3633 if (!autofill::IsValidCreditCardExpirationDate(year, month, now)) | 3628 if (!autofill::IsValidCreditCardExpirationDate(year, month, now)) |
3634 return false; | 3629 return false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3666 | 3661 |
3667 return false; | 3662 return false; |
3668 } | 3663 } |
3669 | 3664 |
3670 bool AutofillDialogControllerImpl::HasInvalidAddress( | 3665 bool AutofillDialogControllerImpl::HasInvalidAddress( |
3671 const AutofillProfile& profile) { | 3666 const AutofillProfile& profile) { |
3672 scoped_ptr<AddressData> address_data = | 3667 scoped_ptr<AddressData> address_data = |
3673 i18n::CreateAddressDataFromAutofillProfile( | 3668 i18n::CreateAddressDataFromAutofillProfile( |
3674 profile, g_browser_process->GetApplicationLocale()); | 3669 profile, g_browser_process->GetApplicationLocale()); |
3675 | 3670 |
3676 FieldProblemMap problems; | 3671 AddressProblems problems; |
3677 GetValidator()->ValidateAddress(*address_data, NULL, &problems); | 3672 GetValidator()->ValidateAddress(*address_data, |
| 3673 AddressProblemFilter(), |
| 3674 &problems); |
3678 return !problems.empty(); | 3675 return !problems.empty(); |
3679 } | 3676 } |
3680 | 3677 |
3681 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { | 3678 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
3682 return SectionIsActive(SECTION_SHIPPING) && | 3679 return SectionIsActive(SECTION_SHIPPING) && |
3683 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; | 3680 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; |
3684 } | 3681 } |
3685 | 3682 |
3686 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { | 3683 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { |
3687 // It's possible that the user checked [X] Save details locally before | 3684 // 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... |
4166 view_->UpdateButtonStrip(); | 4163 view_->UpdateButtonStrip(); |
4167 } | 4164 } |
4168 | 4165 |
4169 void AutofillDialogControllerImpl::FetchWalletCookie() { | 4166 void AutofillDialogControllerImpl::FetchWalletCookie() { |
4170 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 4167 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
4171 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 4168 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
4172 signin_helper_->StartWalletCookieValueFetch(); | 4169 signin_helper_->StartWalletCookieValueFetch(); |
4173 } | 4170 } |
4174 | 4171 |
4175 } // namespace autofill | 4172 } // namespace autofill |
OLD | NEW |