Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1117)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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/component_strings.h" 81 #include "grit/component_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_storage_impl.h"
88 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h"
89 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_problem.h"
90 #include "ui/base/base_window.h" 87 #include "ui/base/base_window.h"
91 #include "ui/base/l10n/l10n_util.h" 88 #include "ui/base/l10n/l10n_util.h"
92 #include "ui/base/models/combobox_model.h" 89 #include "ui/base/models/combobox_model.h"
93 #include "ui/base/resource/resource_bundle.h" 90 #include "ui/base/resource/resource_bundle.h"
94 #include "ui/gfx/canvas.h" 91 #include "ui/gfx/canvas.h"
95 #include "ui/gfx/image/image_skia_operations.h" 92 #include "ui/gfx/image/image_skia_operations.h"
96 #include "ui/gfx/skia_util.h" 93 #include "ui/gfx/skia_util.h"
97 94
95 #define I18N_ADDRESSINPUT_UTIL_BASICTYPES_H_ // base/basictypes.h
96 #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h"
97 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h"
98 #include "third_party/libaddressinput/chromium/preload_address_validator.h"
99 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h"
100 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h"
101 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_pr oblem.h"
102 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_va lidator.h"
103 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h "
104
98 using ::i18n::addressinput::AddressData; 105 using ::i18n::addressinput::AddressData;
99 using ::i18n::addressinput::AddressField; 106 using ::i18n::addressinput::AddressField;
100 using ::i18n::addressinput::AddressProblem; 107 using ::i18n::addressinput::AddressProblem;
101 using ::i18n::addressinput::AddressProblemFilter; 108 using ::i18n::addressinput::FieldProblemMap;
102 using ::i18n::addressinput::AddressProblems;
103 using ::i18n::addressinput::AddressValidator;
104 109
105 namespace autofill { 110 namespace autofill {
106 111
107 namespace { 112 namespace {
108 113
109 const char kAddNewItemKey[] = "add-new-item"; 114 const char kAddNewItemKey[] = "add-new-item";
110 const char kManageItemsKey[] = "manage-items"; 115 const char kManageItemsKey[] = "manage-items";
111 const char kSameAsBillingKey[] = "same-as-billing"; 116 const char kSameAsBillingKey[] = "same-as-billing";
112 117
113 // URLs for Wallet error messages. 118 // URLs for Wallet error messages.
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); 512 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
508 } 513 }
509 514
510 ServerFieldType CountryTypeForSection(DialogSection section) { 515 ServerFieldType CountryTypeForSection(DialogSection section) {
511 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : 516 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY :
512 ADDRESS_BILLING_COUNTRY; 517 ADDRESS_BILLING_COUNTRY;
513 } 518 }
514 519
515 // Attempts to canonicalize the administrative area name in |profile| using the 520 // Attempts to canonicalize the administrative area name in |profile| using the
516 // rules in |validator|. 521 // rules in |validator|.
517 void CanonicalizeState(const AddressValidator* validator, 522 void CanonicalizeState(const PreloadAddressValidator* validator,
518 AutofillProfile* profile) { 523 AutofillProfile* profile) {
519 base::string16 administrative_area; 524 base::string16 administrative_area;
520 scoped_ptr<AddressData> address_data = 525 scoped_ptr<AddressData> address_data =
521 i18n::CreateAddressDataFromAutofillProfile( 526 i18n::CreateAddressDataFromAutofillProfile(
522 *profile, g_browser_process->GetApplicationLocale()); 527 *profile, g_browser_process->GetApplicationLocale());
523 528
524 validator->CanonicalizeAdministrativeArea(address_data.get()); 529 validator->CanonicalizeAdministrativeArea(address_data.get());
525 administrative_area = base::UTF8ToUTF16(address_data->administrative_area); 530 administrative_area = base::UTF8ToUTF16(address_data->administrative_area);
526 531
527 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), 532 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE),
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 822
818 acceptable_cc_types_ = form_structure_.PossibleValues(CREDIT_CARD_TYPE); 823 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 824 // Wallet generates MC virtual cards, so we have to disable it if MC is not
820 // allowed. 825 // allowed.
821 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard))) 826 if (ShouldDisallowCcType(CreditCard::TypeForDisplay(kMasterCard)))
822 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT); 827 DisableWallet(wallet::WalletClient::UNSUPPORTED_MERCHANT);
823 828
824 if (account_chooser_model_->WalletIsSelected()) 829 if (account_chooser_model_->WalletIsSelected())
825 FetchWalletCookie(); 830 FetchWalletCookie();
826 831
827 scoped_ptr< ::i18n::addressinput::Downloader> downloader( 832 validator_.reset(new PreloadAddressValidator(
828 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())); 833 scoped_ptr< ::i18n::addressinput::Downloader>(
829 validator_ = AddressValidator::Build( 834 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())),
830 downloader.Pass(),
831 ValidationRulesStorageFactory::CreateStorage(), 835 ValidationRulesStorageFactory::CreateStorage(),
832 this); 836 scoped_ptr< ::i18n::addressinput::Downloader>(
837 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())),
838 ValidationRulesStorageFactory::CreateStorage()));
833 839
834 SuggestionsUpdated(); 840 SuggestionsUpdated();
835 SubmitButtonDelayBegin(); 841 SubmitButtonDelayBegin();
836 view_.reset(CreateView()); 842 view_.reset(CreateView());
837 view_->Show(); 843 view_->Show();
838 GetManager()->AddObserver(this); 844 GetManager()->AddObserver(this);
839 845
840 if (!account_chooser_model_->WalletIsSelected()) 846 if (!account_chooser_model_->WalletIsSelected())
841 LogDialogLatencyToShow(); 847 LogDialogLatencyToShow();
842 } 848 }
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 } 1302 }
1297 1303
1298 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 1304 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
1299 for (DetailInputs::iterator it = inputs->begin(); 1305 for (DetailInputs::iterator it = inputs->begin();
1300 it != inputs->end(); ++it) { 1306 it != inputs->end(); ++it) {
1301 if (it->length != DetailInput::NONE) { 1307 if (it->length != DetailInput::NONE) {
1302 it->initial_value.clear(); 1308 it->initial_value.clear();
1303 } else if (!it->initial_value.empty() && 1309 } else if (!it->initial_value.empty() &&
1304 (it->type == ADDRESS_BILLING_COUNTRY || 1310 (it->type == ADDRESS_BILLING_COUNTRY ||
1305 it->type == ADDRESS_HOME_COUNTRY)) { 1311 it->type == ADDRESS_HOME_COUNTRY)) {
1306 GetValidator()->LoadRules(AutofillCountry::GetCountryCode( 1312 GetValidator()->LoadRules(
1307 it->initial_value, g_browser_process->GetApplicationLocale())); 1313 AutofillCountry::GetCountryCode(
1314 it->initial_value, g_browser_process->GetApplicationLocale()),
1315 *address_validation_rules_loaded_);
1308 } 1316 }
1309 } 1317 }
1310 } 1318 }
1311 1319
1312 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( 1320 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion(
1313 DialogSection section) { 1321 DialogSection section) {
1314 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so 1322 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so
1315 // get the wrapper before this potentially happens below. 1323 // get the wrapper before this potentially happens below.
1316 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 1324 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
1317 1325
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 base::string16 message = CreditCardNumberValidityMessage(value); 1902 base::string16 message = CreditCardNumberValidityMessage(value);
1895 if (!message.empty()) 1903 if (!message.empty())
1896 return message; 1904 return message;
1897 } 1905 }
1898 break; 1906 break;
1899 } 1907 }
1900 1908
1901 case CREDIT_CARD_EXP_MONTH: 1909 case CREDIT_CARD_EXP_MONTH:
1902 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) { 1910 if (!InputWasEdited(CREDIT_CARD_EXP_MONTH, value)) {
1903 return l10n_util::GetStringUTF16( 1911 return l10n_util::GetStringUTF16(
1904 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); 1912 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD);
1905 } 1913 }
1906 break; 1914 break;
1907 1915
1908 case CREDIT_CARD_EXP_4_DIGIT_YEAR: 1916 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
1909 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) { 1917 if (!InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, value)) {
1910 return l10n_util::GetStringUTF16( 1918 return l10n_util::GetStringUTF16(
1911 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); 1919 IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD);
1912 } 1920 }
1913 break; 1921 break;
1914 1922
1915 case CREDIT_CARD_VERIFICATION_CODE: 1923 case CREDIT_CARD_VERIFICATION_CODE:
1916 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) { 1924 if (!value.empty() && !autofill::IsValidCreditCardSecurityCode(value)) {
1917 return l10n_util::GetStringUTF16( 1925 return l10n_util::GetStringUTF16(
1918 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); 1926 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE);
1919 } 1927 }
1920 break; 1928 break;
1921 1929
(...skipping 10 matching lines...) Expand all
1932 break; 1940 break;
1933 1941
1934 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. 1942 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section.
1935 break; 1943 break;
1936 1944
1937 default: 1945 default:
1938 NOTREACHED(); // Trying to validate unknown field. 1946 NOTREACHED(); // Trying to validate unknown field.
1939 break; 1947 break;
1940 } 1948 }
1941 1949
1942 return value.empty() ? l10n_util::GetStringUTF16( 1950 return value.empty() ?
1943 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD) : 1951 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD) :
1944 base::string16(); 1952 base::string16();
1945 } 1953 }
1946 1954
1947 // TODO(groby): Also add tests. 1955 // TODO(groby): Also add tests.
1948 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( 1956 ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
1949 DialogSection section, 1957 DialogSection section,
1950 const FieldValueMap& inputs) { 1958 const FieldValueMap& inputs) {
1951 ValidityMessages messages; 1959 ValidityMessages messages;
1952 if (inputs.empty()) 1960 if (inputs.empty())
1953 return messages; 1961 return messages;
1954 1962
1955 AddressValidator::Status status = AddressValidator::SUCCESS; 1963 PreloadAddressValidator::Status status = PreloadAddressValidator::SUCCESS;
1956 if (section != SECTION_CC) { 1964 if (section != SECTION_CC) {
1957 AutofillProfile profile; 1965 AutofillProfile profile;
1958 FillFormGroupFromOutputs(inputs, &profile); 1966 FillFormGroupFromOutputs(inputs, &profile);
1959 scoped_ptr<AddressData> address_data = 1967 scoped_ptr<AddressData> address_data =
1960 i18n::CreateAddressDataFromAutofillProfile( 1968 i18n::CreateAddressDataFromAutofillProfile(
1961 profile, g_browser_process->GetApplicationLocale()); 1969 profile, g_browser_process->GetApplicationLocale());
1962 address_data->language_code = AddressLanguageCodeForSection(section); 1970 address_data->language_code = AddressLanguageCodeForSection(section);
1963 1971
1964 AddressProblems problems; 1972 FieldProblemMap problems;
1965 status = GetValidator()->ValidateAddress(*address_data, 1973 status = GetValidator()->Validate(*address_data, NULL, &problems);
1966 AddressProblemFilter(),
1967 &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 #if 0
1974 messages.Set(i18ninput::TypeForField(problem.field, address_type), 1980 base::string16 text = l10n_util::GetStringUTF16(
1981 IDS_LIBADDRESSINPUT_I18N_MISSING_REQUIRED_FIELD); // TODO!!!
1982 #else
1983 base::string16 text = base::ASCIIToUTF16("Placeholder Error. TODO.");
please use gerrit instead 2014/05/23 14:44:54 Need Keghani's error message strings.
1984 #endif
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
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
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
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
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
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698