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