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