Chromium Code Reviews| 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 |
| 11 #include "apps/app_window.h" | 11 #include "apps/app_window.h" |
| 12 #include "apps/app_window_registry.h" | 12 #include "apps/app_window_registry.h" |
| 13 #include "apps/ui/native_app_window.h" | 13 #include "apps/ui/native_app_window.h" |
| 14 #include "base/base64.h" | 14 #include "base/base64.h" |
| 15 #include "base/basictypes.h" | |
| 15 #include "base/bind.h" | 16 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 17 #include "base/i18n/case_conversion.h" | 18 #include "base/i18n/case_conversion.h" |
| 18 #include "base/i18n/rtl.h" | 19 #include "base/i18n/rtl.h" |
| 19 #include "base/logging.h" | 20 #include "base/logging.h" |
| 20 #include "base/prefs/pref_registry_simple.h" | 21 #include "base/prefs/pref_registry_simple.h" |
| 21 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
| 22 #include "base/prefs/scoped_user_pref_update.h" | 23 #include "base/prefs/scoped_user_pref_update.h" |
| 23 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
| 24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 #include "content/public/browser/navigation_entry.h" | 73 #include "content/public/browser/navigation_entry.h" |
| 73 #include "content/public/browser/notification_service.h" | 74 #include "content/public/browser/notification_service.h" |
| 74 #include "content/public/browser/notification_types.h" | 75 #include "content/public/browser/notification_types.h" |
| 75 #include "content/public/browser/render_view_host.h" | 76 #include "content/public/browser/render_view_host.h" |
| 76 #include "content/public/browser/web_contents.h" | 77 #include "content/public/browser/web_contents.h" |
| 77 #include "content/public/common/url_constants.h" | 78 #include "content/public/common/url_constants.h" |
| 78 #include "grit/chromium_strings.h" | 79 #include "grit/chromium_strings.h" |
| 79 #include "grit/component_scaled_resources.h" | 80 #include "grit/component_scaled_resources.h" |
| 80 #include "grit/components_strings.h" | 81 #include "grit/components_strings.h" |
| 81 #include "grit/generated_resources.h" | 82 #include "grit/generated_resources.h" |
| 82 #include "grit/libaddressinput_strings.h" | 83 #include "grit/libaddressinput/messages.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/chromium/cpp/include/libaddressinput/addre ss_data.h" | 89 #include "third_party/libaddressinput/chromium/preload_address_validator.h" |
| 89 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_problem.h" | 90 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
| 91 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h" | |
| 92 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_pr oblem.h" | |
| 93 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h " | |
| 94 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati on.h" | |
| 90 #include "ui/base/base_window.h" | 95 #include "ui/base/base_window.h" |
| 91 #include "ui/base/l10n/l10n_util.h" | 96 #include "ui/base/l10n/l10n_util.h" |
| 92 #include "ui/base/models/combobox_model.h" | 97 #include "ui/base/models/combobox_model.h" |
| 93 #include "ui/base/resource/resource_bundle.h" | 98 #include "ui/base/resource/resource_bundle.h" |
| 94 #include "ui/gfx/canvas.h" | 99 #include "ui/gfx/canvas.h" |
| 95 #include "ui/gfx/image/image_skia_operations.h" | 100 #include "ui/gfx/image/image_skia_operations.h" |
| 96 #include "ui/gfx/skia_util.h" | 101 #include "ui/gfx/skia_util.h" |
| 97 | 102 |
| 98 using ::i18n::addressinput::AddressData; | 103 using ::i18n::addressinput::AddressData; |
| 99 using ::i18n::addressinput::AddressField; | 104 using ::i18n::addressinput::AddressField; |
| 100 using ::i18n::addressinput::AddressProblem; | 105 using ::i18n::addressinput::AddressProblem; |
| 101 using ::i18n::addressinput::AddressProblemFilter; | 106 using ::i18n::addressinput::FieldProblemMap; |
| 102 using ::i18n::addressinput::AddressProblems; | |
| 103 using ::i18n::addressinput::AddressValidator; | |
| 104 | 107 |
| 105 namespace autofill { | 108 namespace autofill { |
| 106 | 109 |
| 107 namespace { | 110 namespace { |
| 108 | 111 |
| 109 const char kAddNewItemKey[] = "add-new-item"; | 112 const char kAddNewItemKey[] = "add-new-item"; |
| 110 const char kManageItemsKey[] = "manage-items"; | 113 const char kManageItemsKey[] = "manage-items"; |
| 111 const char kSameAsBillingKey[] = "same-as-billing"; | 114 const char kSameAsBillingKey[] = "same-as-billing"; |
| 112 | 115 |
| 113 // URLs for Wallet error messages. | 116 // URLs for Wallet error messages. |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); | 510 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); |
| 508 } | 511 } |
| 509 | 512 |
| 510 ServerFieldType CountryTypeForSection(DialogSection section) { | 513 ServerFieldType CountryTypeForSection(DialogSection section) { |
| 511 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : | 514 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : |
| 512 ADDRESS_BILLING_COUNTRY; | 515 ADDRESS_BILLING_COUNTRY; |
| 513 } | 516 } |
| 514 | 517 |
| 515 // Attempts to canonicalize the administrative area name in |profile| using the | 518 // Attempts to canonicalize the administrative area name in |profile| using the |
| 516 // rules in |validator|. | 519 // rules in |validator|. |
| 517 void CanonicalizeState(const AddressValidator* validator, | 520 void CanonicalizeState(const PreloadAddressValidator* validator, |
| 518 AutofillProfile* profile) { | 521 AutofillProfile* profile) { |
| 519 base::string16 administrative_area; | 522 base::string16 administrative_area; |
| 520 scoped_ptr<AddressData> address_data = | 523 scoped_ptr<AddressData> address_data = |
| 521 i18n::CreateAddressDataFromAutofillProfile( | 524 i18n::CreateAddressDataFromAutofillProfile( |
| 522 *profile, g_browser_process->GetApplicationLocale()); | 525 *profile, g_browser_process->GetApplicationLocale()); |
| 523 | 526 |
| 524 validator->CanonicalizeAdministrativeArea(address_data.get()); | 527 validator->CanonicalizeAdministrativeArea(address_data.get()); |
| 525 administrative_area = base::UTF8ToUTF16(address_data->administrative_area); | 528 administrative_area = base::UTF8ToUTF16(address_data->administrative_area); |
| 526 | 529 |
| 527 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), | 530 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 | 820 |
| 818 acceptable_cc_types_ = form_structure_.PossibleValues(CREDIT_CARD_TYPE); | 821 acceptable_cc_types_ = form_structure_.PossibleValues(CREDIT_CARD_TYPE); |
| 819 // Wallet generates MC virtual cards, so we have to disable it if MC is not | 822 // Wallet generates MC virtual cards, so we have to disable it if MC is not |
| 820 // allowed. | 823 // allowed. |
| 821 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard))) | 824 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard))) |
| 822 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT); | 825 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT); |
| 823 | 826 |
| 824 if (account_chooser_model_->WalletIsSelected()) | 827 if (account_chooser_model_->WalletIsSelected()) |
| 825 FetchWalletCookie(); | 828 FetchWalletCookie(); |
| 826 | 829 |
| 827 scoped_ptr< ::i18n::addressinput::Downloader> downloader( | 830 validator_.reset(new PreloadAddressValidator( |
| 828 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())); | 831 I18N_ADDRESS_VALIDATION_DATA_URL, |
| 829 validator_ = AddressValidator::Build( | 832 scoped_ptr< ::i18n::addressinput::Downloader>( |
| 830 downloader.Pass(), | 833 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())), |
| 831 ValidationRulesStorageFactory::CreateStorage(), | 834 ValidationRulesStorageFactory::CreateStorage())); |
| 832 this); | |
| 833 | 835 |
| 834 SuggestionsUpdated(); | 836 SuggestionsUpdated(); |
| 835 SubmitButtonDelayBegin(); | 837 SubmitButtonDelayBegin(); |
| 836 view_.reset(CreateView()); | 838 view_.reset(CreateView()); |
| 837 view_->Show(); | 839 view_->Show(); |
| 838 GetManager()->AddObserver(this); | 840 GetManager()->AddObserver(this); |
| 839 | 841 |
| 840 if (!account_chooser_model_->WalletIsSelected()) | 842 if (!account_chooser_model_->WalletIsSelected()) |
| 841 LogDialogLatencyToShow(); | 843 LogDialogLatencyToShow(); |
| 842 } | 844 } |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1296 } | 1298 } |
| 1297 | 1299 |
| 1298 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1300 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1299 for (DetailInputs::iterator it = inputs->begin(); | 1301 for (DetailInputs::iterator it = inputs->begin(); |
| 1300 it != inputs->end(); ++it) { | 1302 it != inputs->end(); ++it) { |
| 1301 if (it->length != DetailInput::NONE) { | 1303 if (it->length != DetailInput::NONE) { |
| 1302 it->initial_value.clear(); | 1304 it->initial_value.clear(); |
| 1303 } else if (!it->initial_value.empty() && | 1305 } else if (!it->initial_value.empty() && |
| 1304 (it->type == ADDRESS_BILLING_COUNTRY || | 1306 (it->type == ADDRESS_BILLING_COUNTRY || |
| 1305 it->type == ADDRESS_HOME_COUNTRY)) { | 1307 it->type == ADDRESS_HOME_COUNTRY)) { |
| 1306 GetValidator()->LoadRules(AutofillCountry::GetCountryCode( | 1308 GetValidator()->LoadRules( |
| 1307 it->initial_value, g_browser_process->GetApplicationLocale())); | 1309 AutofillCountry::GetCountryCode( |
| 1310 it->initial_value, g_browser_process->GetApplicationLocale()), | |
| 1311 *address_validation_rules_loaded_); | |
| 1308 } | 1312 } |
| 1309 } | 1313 } |
| 1310 } | 1314 } |
| 1311 | 1315 |
| 1312 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( | 1316 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
| 1313 DialogSection section) { | 1317 DialogSection section) { |
| 1314 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so | 1318 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so |
| 1315 // get the wrapper before this potentially happens below. | 1319 // get the wrapper before this potentially happens below. |
| 1316 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1320 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 1317 | 1321 |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1894 base::string16 message = CreditCardNumberValidityMessage(value); | 1898 base::string16 message = CreditCardNumberValidityMessage(value); |
| 1895 if (!message.empty()) | 1899 if (!message.empty()) |
| 1896 return message; | 1900 return message; |
| 1897 } | 1901 } |
| 1898 break; | 1902 break; |
| 1899 } | 1903 } |
| 1900 | 1904 |
| 1901 case CREDIT_CARD_EXP_MONTH: | 1905 case CREDIT_CARD_EXP_MONTH: |
| 1902 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { | 1906 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { |
| 1903 return l10n_util::GetStringUTF16( | 1907 return l10n_util::GetStringUTF16( |
| 1904 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); | 1908 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); |
| 1905 } | 1909 } |
| 1906 break; | 1910 break; |
| 1907 | 1911 |
| 1908 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 1912 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 1909 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { | 1913 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { |
| 1910 return l10n_util::GetStringUTF16( | 1914 return l10n_util::GetStringUTF16( |
| 1911 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); | 1915 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD); |
| 1912 } | 1916 } |
| 1913 break; | 1917 break; |
| 1914 | 1918 |
| 1915 case CREDIT_CARD_VERIFICATION_CODE: | 1919 case CREDIT_CARD_VERIFICATION_CODE: |
| 1916 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { | 1920 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { |
| 1917 return l10n_util::GetStringUTF16( | 1921 return l10n_util::GetStringUTF16( |
| 1918 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); | 1922 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); |
| 1919 } | 1923 } |
| 1920 break; | 1924 break; |
| 1921 | 1925 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1932 break; | 1936 break; |
| 1933 | 1937 |
| 1934 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. | 1938 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. |
| 1935 break; | 1939 break; |
| 1936 | 1940 |
| 1937 default: | 1941 default: |
| 1938 NOTREACHED(); // Trying to validate unknown field. | 1942 NOTREACHED(); // Trying to validate unknown field. |
| 1939 break; | 1943 break; |
| 1940 } | 1944 } |
| 1941 | 1945 |
| 1942 return value.empty() ? l10n_util::GetStringUTF16( | 1946 return value.empty() ? |
| 1943 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD) : | 1947 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD) : |
| 1944 base::string16(); | 1948 base::string16(); |
| 1945 } | 1949 } |
| 1946 | 1950 |
| 1947 // TODO(groby): Also add tests. | 1951 // TODO(groby): Also add tests. |
| 1948 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( | 1952 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| 1949 DialogSection section, | 1953 DialogSection section, |
| 1950 const FieldValueMap& inputs) { | 1954 const FieldValueMap& inputs) { |
| 1951 ValidityMessages messages; | 1955 ValidityMessages messages; |
| 1952 if (inputs.empty()) | 1956 if (inputs.empty()) |
| 1953 return messages; | 1957 return messages; |
| 1954 | 1958 |
| 1955 AddressValidator::Status status = AddressValidator::SUCCESS; | 1959 PreloadAddressValidator::Status status = PreloadAddressValidator::SUCCESS; |
| 1956 if (section != SECTION_CC) { | 1960 if (section != SECTION_CC) { |
| 1957 AutofillProfile profile; | 1961 AutofillProfile profile; |
| 1958 FillFormGroupFromOutputs(inputs, &profile); | 1962 FillFormGroupFromOutputs(inputs, &profile); |
| 1959 scoped_ptr<AddressData> address_data = | 1963 scoped_ptr<AddressData> address_data = |
| 1960 i18n::CreateAddressDataFromAutofillProfile( | 1964 i18n::CreateAddressDataFromAutofillProfile( |
| 1961 profile, g_browser_process->GetApplicationLocale()); | 1965 profile, g_browser_process->GetApplicationLocale()); |
| 1962 address_data->language_code = AddressLanguageCodeForSection(section); | 1966 address_data->language_code = AddressLanguageCodeForSection(section); |
| 1963 | 1967 |
| 1964 AddressProblems problems; | 1968 ::i18n::addressinput::Localization localization; |
| 1965 status = GetValidator()->ValidateAddress(*address_data, | 1969 localization.SetGetter( |
| 1966 AddressProblemFilter(), | 1970 l10n_util::GetStringUTF8, g_browser_process->GetApplicationLocale()); |
| 1967 &problems); | 1971 |
| 1972 FieldProblemMap problems; | |
| 1973 status = GetValidator()->Validate(*address_data, NULL, &problems); | |
| 1968 common::AddressType address_type = section == SECTION_SHIPPING ? | 1974 common::AddressType address_type = section == SECTION_SHIPPING ? |
| 1969 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 1975 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
| 1970 for (size_t i = 0; i < problems.size(); ++i) { | 1976 for (FieldProblemMap::const_iterator iter = problems.begin(); |
| 1971 const AddressProblem& problem = problems[i]; | 1977 iter != problems.end(); ++iter) { |
| 1972 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; | 1978 bool sure = iter->second != ::i18n::addressinput::MISSING_REQUIRED_FIELD; |
| 1973 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); | 1979 base::string16 text = base::UTF8ToUTF16( |
| 1974 messages.Set(i18ninput::TypeForField(problem.field, address_type), | 1980 localization.GetErrorMessage(*address_data, |
| 1981 iter->first, | |
|
please use gerrit instead
2014/06/05 22:22:47
To reduce reviewer burden: add comment on what is
please use gerrit instead
2014/06/09 23:28:16
Done.
| |
| 1982 iter->second, | |
| 1983 /*enable_examples*/ true, | |
| 1984 /*enable_links*/ false)); | |
| 1985 messages.Set(i18ninput::TypeForField(iter->first, address_type), | |
| 1975 ValidityMessage(text, sure)); | 1986 ValidityMessage(text, sure)); |
| 1976 } | 1987 } |
| 1977 } | 1988 } |
| 1978 | 1989 |
| 1979 for (FieldValueMap::const_iterator iter = inputs.begin(); | 1990 for (FieldValueMap::const_iterator iter = inputs.begin(); |
| 1980 iter != inputs.end(); ++iter) { | 1991 iter != inputs.end(); ++iter) { |
| 1981 const ServerFieldType type = iter->first; | 1992 const ServerFieldType type = iter->first; |
| 1982 base::string16 text = InputValidityMessage(section, type, iter->second); | 1993 base::string16 text = InputValidityMessage(section, type, iter->second); |
| 1983 | 1994 |
| 1984 // Skip empty/unchanged fields in edit mode. If the individual field does | 1995 // Skip empty/unchanged fields in edit mode. If the individual field does |
| 1985 // not have validation errors, assume it to be valid unless later proven | 1996 // not have validation errors, assume it to be valid unless later proven |
| 1986 // otherwise. | 1997 // otherwise. |
| 1987 bool sure = InputWasEdited(type, iter->second); | 1998 bool sure = InputWasEdited(type, iter->second); |
| 1988 | 1999 |
| 1989 if (sure && status == AddressValidator::RULES_NOT_READY && | 2000 if (sure && status == PreloadAddressValidator::RULES_NOT_READY && |
| 1990 !ComboboxModelForAutofillType(type) && | 2001 !ComboboxModelForAutofillType(type) && |
| 1991 (AutofillType(type).group() == ADDRESS_HOME || | 2002 (AutofillType(type).group() == ADDRESS_HOME || |
| 1992 AutofillType(type).group() == ADDRESS_BILLING)) { | 2003 AutofillType(type).group() == ADDRESS_BILLING)) { |
| 1993 DCHECK(text.empty()); | 2004 DCHECK(text.empty()); |
| 1994 text = l10n_util::GetStringUTF16( | 2005 text = l10n_util::GetStringUTF16( |
| 1995 IDS_AUTOFILL_DIALOG_VALIDATION_WAITING_FOR_RULES); | 2006 IDS_AUTOFILL_DIALOG_VALIDATION_WAITING_FOR_RULES); |
| 1996 sure = false; | 2007 sure = false; |
| 1997 needs_validation_.insert(section); | 2008 needs_validation_.insert(section); |
| 1998 } | 2009 } |
| 1999 | 2010 |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2785 cares_about_shipping_(true), | 2796 cares_about_shipping_(true), |
| 2786 popup_input_type_(UNKNOWN_TYPE), | 2797 popup_input_type_(UNKNOWN_TYPE), |
| 2787 waiting_for_explicit_sign_in_response_(false), | 2798 waiting_for_explicit_sign_in_response_(false), |
| 2788 has_accepted_legal_documents_(false), | 2799 has_accepted_legal_documents_(false), |
| 2789 is_submitting_(false), | 2800 is_submitting_(false), |
| 2790 choose_another_instrument_or_address_(false), | 2801 choose_another_instrument_or_address_(false), |
| 2791 wallet_server_validation_recoverable_(true), | 2802 wallet_server_validation_recoverable_(true), |
| 2792 data_was_passed_back_(false), | 2803 data_was_passed_back_(false), |
| 2793 was_ui_latency_logged_(false), | 2804 was_ui_latency_logged_(false), |
| 2794 card_generated_animation_(2000, 60, this), | 2805 card_generated_animation_(2000, 60, this), |
| 2795 weak_ptr_factory_(this) { | 2806 weak_ptr_factory_(this), |
| 2807 address_validation_rules_loaded_( | |
| 2808 ::i18n::addressinput::BuildCallback( | |
| 2809 this, | |
| 2810 &AutofillDialogControllerImpl::AddressValidationRulesLoaded)) { | |
| 2796 DCHECK(!callback_.is_null()); | 2811 DCHECK(!callback_.is_null()); |
| 2797 } | 2812 } |
| 2798 | 2813 |
| 2799 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { | 2814 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
| 2800 return AutofillDialogView::Create(this); | 2815 return AutofillDialogView::Create(this); |
| 2801 } | 2816 } |
| 2802 | 2817 |
| 2803 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { | 2818 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { |
| 2804 return PersonalDataManagerFactory::GetForProfile(profile_); | 2819 return PersonalDataManagerFactory::GetForProfile(profile_); |
| 2805 } | 2820 } |
| 2806 | 2821 |
| 2807 AddressValidator* AutofillDialogControllerImpl::GetValidator() { | 2822 PreloadAddressValidator* AutofillDialogControllerImpl::GetValidator() { |
| 2808 return validator_.get(); | 2823 return validator_.get(); |
| 2809 } | 2824 } |
| 2810 | 2825 |
| 2811 const wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() | 2826 const wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() |
| 2812 const { | 2827 const { |
| 2813 return const_cast<AutofillDialogControllerImpl*>(this)->GetWalletClient(); | 2828 return const_cast<AutofillDialogControllerImpl*>(this)->GetWalletClient(); |
| 2814 } | 2829 } |
| 2815 | 2830 |
| 2816 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { | 2831 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { |
| 2817 return &wallet_client_; | 2832 return &wallet_client_; |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3352 | 3367 |
| 3353 AutofillProfile profile; | 3368 AutofillProfile profile; |
| 3354 FillFormGroupFromOutputs(inputs, &profile); | 3369 FillFormGroupFromOutputs(inputs, &profile); |
| 3355 | 3370 |
| 3356 scoped_ptr<AddressData> user_input = | 3371 scoped_ptr<AddressData> user_input = |
| 3357 i18n::CreateAddressDataFromAutofillProfile( | 3372 i18n::CreateAddressDataFromAutofillProfile( |
| 3358 profile, g_browser_process->GetApplicationLocale()); | 3373 profile, g_browser_process->GetApplicationLocale()); |
| 3359 user_input->language_code = AddressLanguageCodeForSection(section); | 3374 user_input->language_code = AddressLanguageCodeForSection(section); |
| 3360 | 3375 |
| 3361 static const size_t kSuggestionsLimit = 10; | 3376 static const size_t kSuggestionsLimit = 10; |
| 3362 AddressValidator::Status status = GetValidator()->GetSuggestions( | 3377 PreloadAddressValidator::Status status = GetValidator()->GetSuggestions( |
| 3363 *user_input, focused_field, kSuggestionsLimit, | 3378 *user_input, focused_field, kSuggestionsLimit, |
| 3364 &i18n_validator_suggestions_); | 3379 &i18n_validator_suggestions_); |
| 3365 | 3380 |
| 3366 if (status != AddressValidator::SUCCESS) | 3381 if (status != PreloadAddressValidator::SUCCESS) |
| 3367 return; | 3382 return; |
| 3368 | 3383 |
| 3369 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { | 3384 for (size_t i = 0; i < i18n_validator_suggestions_.size(); ++i) { |
| 3370 popup_values->push_back(base::UTF8ToUTF16( | 3385 popup_values->push_back(base::UTF8ToUTF16( |
| 3371 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); | 3386 i18n_validator_suggestions_[i].GetFieldValue(focused_field))); |
| 3372 | 3387 |
| 3373 // Disambiguate the suggestion by showing the smallest administrative | 3388 // Disambiguate the suggestion by showing the smallest administrative |
| 3374 // region of the suggested address: | 3389 // region of the suggested address: |
| 3375 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY | 3390 // ADMIN_AREA > LOCALITY > DEPENDENT_LOCALITY |
| 3376 popup_labels->push_back(base::string16()); | 3391 popup_labels->push_back(base::string16()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3457 if (outputs[CountryTypeForSection(section)] == country_name) | 3472 if (outputs[CountryTypeForSection(section)] == country_name) |
| 3458 return false; | 3473 return false; |
| 3459 } | 3474 } |
| 3460 | 3475 |
| 3461 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 3476 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 3462 inputs->clear(); | 3477 inputs->clear(); |
| 3463 BuildInputsForSection(section, country_code, inputs, | 3478 BuildInputsForSection(section, country_code, inputs, |
| 3464 MutableAddressLanguageCodeForSection(section)); | 3479 MutableAddressLanguageCodeForSection(section)); |
| 3465 | 3480 |
| 3466 if (!country_code.empty()) { | 3481 if (!country_code.empty()) { |
| 3467 GetValidator()->LoadRules(AutofillCountry::GetCountryCode( | 3482 GetValidator()->LoadRules( |
| 3468 country_name, g_browser_process->GetApplicationLocale())); | 3483 AutofillCountry::GetCountryCode( |
| 3484 country_name, g_browser_process->GetApplicationLocale()), | |
| 3485 *address_validation_rules_loaded_); | |
| 3469 } | 3486 } |
| 3470 | 3487 |
| 3471 return true; | 3488 return true; |
| 3472 } | 3489 } |
| 3473 | 3490 |
| 3474 void AutofillDialogControllerImpl::HidePopup() { | 3491 void AutofillDialogControllerImpl::HidePopup() { |
| 3475 if (popup_controller_) | 3492 if (popup_controller_) |
| 3476 popup_controller_->Hide(); | 3493 popup_controller_->Hide(); |
| 3477 popup_input_type_ = UNKNOWN_TYPE; | 3494 popup_input_type_ = UNKNOWN_TYPE; |
| 3478 } | 3495 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3540 if (!IsManuallyEditingSection(section)) | 3557 if (!IsManuallyEditingSection(section)) |
| 3541 return true; | 3558 return true; |
| 3542 | 3559 |
| 3543 FieldValueMap detail_outputs; | 3560 FieldValueMap detail_outputs; |
| 3544 view_->GetUserInput(section, &detail_outputs); | 3561 view_->GetUserInput(section, &detail_outputs); |
| 3545 return !InputsAreValid(section, detail_outputs).HasSureErrors(); | 3562 return !InputsAreValid(section, detail_outputs).HasSureErrors(); |
| 3546 } | 3563 } |
| 3547 | 3564 |
| 3548 bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { | 3565 bool AutofillDialogControllerImpl::RulesAreLoaded(DialogSection section) { |
| 3549 AddressData address_data; | 3566 AddressData address_data; |
| 3550 address_data.country_code = CountryCodeForSection(section); | 3567 address_data.region_code = CountryCodeForSection(section); |
| 3551 AddressValidator::Status status = GetValidator()->ValidateAddress( | 3568 FieldProblemMap dummy; |
| 3552 address_data, AddressProblemFilter(), NULL); | 3569 PreloadAddressValidator::Status status = GetValidator()->Validate( |
| 3553 return status == AddressValidator::SUCCESS; | 3570 address_data, NULL, &dummy); |
| 3571 return status == PreloadAddressValidator::SUCCESS; | |
| 3554 } | 3572 } |
| 3555 | 3573 |
| 3556 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( | 3574 bool AutofillDialogControllerImpl::IsCreditCardExpirationValid( |
| 3557 const base::string16& year, | 3575 const base::string16& year, |
| 3558 const base::string16& month) const { | 3576 const base::string16& month) const { |
| 3559 // If the expiration is in the past as per the local clock, it's invalid. | 3577 // If the expiration is in the past as per the local clock, it's invalid. |
| 3560 base::Time now = base::Time::Now(); | 3578 base::Time now = base::Time::Now(); |
| 3561 if (!autofill::IsValidCreditCardExpirationDate(year, month, now)) | 3579 if (!autofill::IsValidCreditCardExpirationDate(year, month, now)) |
| 3562 return false; | 3580 return false; |
| 3563 | 3581 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 3594 | 3612 |
| 3595 return false; | 3613 return false; |
| 3596 } | 3614 } |
| 3597 | 3615 |
| 3598 bool AutofillDialogControllerImpl::HasInvalidAddress( | 3616 bool AutofillDialogControllerImpl::HasInvalidAddress( |
| 3599 const AutofillProfile& profile) { | 3617 const AutofillProfile& profile) { |
| 3600 scoped_ptr<AddressData> address_data = | 3618 scoped_ptr<AddressData> address_data = |
| 3601 i18n::CreateAddressDataFromAutofillProfile( | 3619 i18n::CreateAddressDataFromAutofillProfile( |
| 3602 profile, g_browser_process->GetApplicationLocale()); | 3620 profile, g_browser_process->GetApplicationLocale()); |
| 3603 | 3621 |
| 3604 AddressProblems problems; | 3622 FieldProblemMap problems; |
| 3605 GetValidator()->ValidateAddress(*address_data, | 3623 GetValidator()->Validate(*address_data, NULL, &problems); |
| 3606 AddressProblemFilter(), | |
| 3607 &problems); | |
| 3608 return !problems.empty(); | 3624 return !problems.empty(); |
| 3609 } | 3625 } |
| 3610 | 3626 |
| 3611 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { | 3627 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
| 3612 return SectionIsActive(SECTION_SHIPPING) && | 3628 return SectionIsActive(SECTION_SHIPPING) && |
| 3613 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; | 3629 suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; |
| 3614 } | 3630 } |
| 3615 | 3631 |
| 3616 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { | 3632 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { |
| 3617 // It's possible that the user checked [X] Save details locally before | 3633 // It's possible that the user checked [X] Save details locally before |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3800 DCHECK_EQ(animation, &card_generated_animation_); | 3816 DCHECK_EQ(animation, &card_generated_animation_); |
| 3801 PushOverlayUpdate(); | 3817 PushOverlayUpdate(); |
| 3802 } | 3818 } |
| 3803 | 3819 |
| 3804 void AutofillDialogControllerImpl::AnimationEnded( | 3820 void AutofillDialogControllerImpl::AnimationEnded( |
| 3805 const gfx::Animation* animation) { | 3821 const gfx::Animation* animation) { |
| 3806 DCHECK_EQ(animation, &card_generated_animation_); | 3822 DCHECK_EQ(animation, &card_generated_animation_); |
| 3807 DoFinishSubmit(); | 3823 DoFinishSubmit(); |
| 3808 } | 3824 } |
| 3809 | 3825 |
| 3810 void AutofillDialogControllerImpl::OnAddressValidationRulesLoaded( | 3826 void AutofillDialogControllerImpl::AddressValidationRulesLoaded( |
| 3827 bool success, | |
| 3811 const std::string& country_code, | 3828 const std::string& country_code, |
| 3812 bool success) { | 3829 const int& /*rule_count*/) { |
| 3813 // Rules may load instantly (during initialization, before the view is | 3830 // Rules may load instantly (during initialization, before the view is |
| 3814 // even ready). We'll validate when the view is created. | 3831 // even ready). We'll validate when the view is created. |
| 3815 if (!view_) | 3832 if (!view_) |
| 3816 return; | 3833 return; |
| 3817 | 3834 |
| 3818 ScopedViewUpdates updates(view_.get()); | 3835 ScopedViewUpdates updates(view_.get()); |
| 3819 | 3836 |
| 3820 // TODO(dbeam): should we retry on failure? | 3837 // TODO(dbeam): should we retry on failure? |
| 3821 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 3838 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 3822 DialogSection section = static_cast<DialogSection>(i); | 3839 DialogSection section = static_cast<DialogSection>(i); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4096 view_->UpdateButtonStrip(); | 4113 view_->UpdateButtonStrip(); |
| 4097 } | 4114 } |
| 4098 | 4115 |
| 4099 void AutofillDialogControllerImpl::FetchWalletCookie() { | 4116 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 4100 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 4117 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 4101 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 4118 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 4102 signin_helper_->StartWalletCookieValueFetch(); | 4119 signin_helper_->StartWalletCookieValueFetch(); |
| 4103 } | 4120 } |
| 4104 | 4121 |
| 4105 } // namespace autofill | 4122 } // namespace autofill |
| OLD | NEW |