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/shell_window.h" | 11 #include "apps/shell_window.h" |
12 #include "apps/shell_window_registry.h" | 12 #include "apps/shell_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/bind.h" | 15 #include "base/bind.h" |
16 #include "base/bind_helpers.h" | |
16 #include "base/i18n/case_conversion.h" | 17 #include "base/i18n/case_conversion.h" |
17 #include "base/i18n/rtl.h" | 18 #include "base/i18n/rtl.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/prefs/pref_registry_simple.h" | 20 #include "base/prefs/pref_registry_simple.h" |
20 #include "base/prefs/pref_service.h" | 21 #include "base/prefs/pref_service.h" |
21 #include "base/prefs/scoped_user_pref_update.h" | 22 #include "base/prefs/scoped_user_pref_update.h" |
22 #include "base/rand_util.h" | 23 #include "base/rand_util.h" |
23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_split.h" | 25 #include "base/strings/string_split.h" |
25 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
28 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 29 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
30 #include "chrome/browser/autofill/validation_rules_storage_factory.h" | |
29 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" | 33 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
32 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 34 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
33 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 35 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
34 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 36 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
35 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" | 37 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" |
36 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" | 38 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" |
37 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
38 #include "chrome/browser/ui/browser_finder.h" | 40 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 #include "content/public/browser/web_contents.h" | 74 #include "content/public/browser/web_contents.h" |
73 #include "content/public/browser/web_contents_view.h" | 75 #include "content/public/browser/web_contents_view.h" |
74 #include "content/public/common/url_constants.h" | 76 #include "content/public/common/url_constants.h" |
75 #include "grit/chromium_strings.h" | 77 #include "grit/chromium_strings.h" |
76 #include "grit/component_strings.h" | 78 #include "grit/component_strings.h" |
77 #include "grit/generated_resources.h" | 79 #include "grit/generated_resources.h" |
78 #include "grit/platform_locale_settings.h" | 80 #include "grit/platform_locale_settings.h" |
79 #include "grit/theme_resources.h" | 81 #include "grit/theme_resources.h" |
80 #include "grit/webkit_resources.h" | 82 #include "grit/webkit_resources.h" |
81 #include "net/cert/cert_status_flags.h" | 83 #include "net/cert/cert_status_flags.h" |
84 #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h" | |
85 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" | |
86 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" | |
87 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_problem.h" | |
82 #include "ui/base/base_window.h" | 88 #include "ui/base/base_window.h" |
83 #include "ui/base/l10n/l10n_util.h" | 89 #include "ui/base/l10n/l10n_util.h" |
84 #include "ui/base/models/combobox_model.h" | 90 #include "ui/base/models/combobox_model.h" |
85 #include "ui/base/resource/resource_bundle.h" | 91 #include "ui/base/resource/resource_bundle.h" |
86 #include "ui/events/event.h" | 92 #include "ui/events/event.h" |
87 #include "ui/gfx/canvas.h" | 93 #include "ui/gfx/canvas.h" |
88 #include "ui/gfx/image/image_skia_operations.h" | 94 #include "ui/gfx/image/image_skia_operations.h" |
89 #include "ui/gfx/skia_util.h" | 95 #include "ui/gfx/skia_util.h" |
90 | 96 |
97 using ::i18n::addressinput::AddressData; | |
98 using ::i18n::addressinput::AddressField; | |
99 using ::i18n::addressinput::AddressProblem; | |
100 using ::i18n::addressinput::AddressProblemFilter; | |
101 using ::i18n::addressinput::AddressProblems; | |
102 using ::i18n::addressinput::AddressValidator; | |
103 | |
91 namespace autofill { | 104 namespace autofill { |
92 | 105 |
93 namespace { | 106 namespace { |
94 | 107 |
95 const char kAddNewItemKey[] = "add-new-item"; | 108 const char kAddNewItemKey[] = "add-new-item"; |
96 const char kManageItemsKey[] = "manage-items"; | 109 const char kManageItemsKey[] = "manage-items"; |
97 const char kSameAsBillingKey[] = "same-as-billing"; | 110 const char kSameAsBillingKey[] = "same-as-billing"; |
98 | 111 |
99 // URLs for Wallet error messages. | 112 // URLs for Wallet error messages. |
100 const char kBuyerLegalAddressStatusUrl[] = | 113 const char kBuyerLegalAddressStatusUrl[] = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 private: | 151 private: |
139 AutofillDialogView* view_; | 152 AutofillDialogView* view_; |
140 | 153 |
141 DISALLOW_COPY_AND_ASSIGN(ScopedViewUpdates); | 154 DISALLOW_COPY_AND_ASSIGN(ScopedViewUpdates); |
142 }; | 155 }; |
143 | 156 |
144 base::string16 NullGetInfo(const AutofillType& type) { | 157 base::string16 NullGetInfo(const AutofillType& type) { |
145 return base::string16(); | 158 return base::string16(); |
146 } | 159 } |
147 | 160 |
161 // Extract |type| from |inputs| using |section| to determine whether the info | |
162 // should be billing or shipping specific (for sections with address info). | |
163 base::string16 GetInfoFromInputs(const FieldValueMap& inputs, | |
164 DialogSection section, | |
165 const AutofillType& type) { | |
166 ServerFieldType field_type = type.GetStorableType(); | |
167 if (section != SECTION_SHIPPING) | |
168 field_type = AutofillType::GetEquivalentBillingFieldType(field_type); | |
169 | |
170 base::string16 info; | |
171 FieldValueMap::const_iterator it = inputs.find(field_type); | |
172 if (it != inputs.end()) | |
173 info = it->second; | |
174 | |
175 if (!info.empty() && type.html_type() == HTML_TYPE_COUNTRY_CODE) { | |
176 info = base::ASCIIToUTF16(AutofillCountry::GetCountryCode( | |
177 info, g_browser_process->GetApplicationLocale())); | |
178 } | |
179 | |
180 return info; | |
181 } | |
182 | |
148 // Returns true if |input| should be used to fill a site-requested |field| which | 183 // Returns true if |input| should be used to fill a site-requested |field| which |
149 // is notated with a "shipping" tag, for use when the user has decided to use | 184 // is notated with a "shipping" tag, for use when the user has decided to use |
150 // the billing address as the shipping address. | 185 // the billing address as the shipping address. |
151 bool ServerTypeMatchesShippingField(ServerFieldType type, | 186 bool ServerTypeMatchesShippingField(ServerFieldType type, |
152 const AutofillField& field) { | 187 const AutofillField& field) { |
153 // Equivalent billing field type is used to support UseBillingAsShipping | 188 // Equivalent billing field type is used to support UseBillingAsShipping |
154 // usecase. | 189 // usecase. |
155 return common::ServerTypeMatchesFieldType( | 190 return common::ServerTypeMatchesFieldType( |
156 type, | 191 type, |
157 AutofillType(AutofillType::GetEquivalentBillingFieldType( | 192 AutofillType(AutofillType::GetEquivalentBillingFieldType( |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 | 646 |
612 account_chooser_model_.reset( | 647 account_chooser_model_.reset( |
613 new AccountChooserModel(this, | 648 new AccountChooserModel(this, |
614 profile_, | 649 profile_, |
615 !ShouldShowAccountChooser(), | 650 !ShouldShowAccountChooser(), |
616 metric_logger_)); | 651 metric_logger_)); |
617 | 652 |
618 if (account_chooser_model_->WalletIsSelected()) | 653 if (account_chooser_model_->WalletIsSelected()) |
619 FetchWalletCookie(); | 654 FetchWalletCookie(); |
620 | 655 |
656 if (i18ninput::Enabled()) { | |
657 scoped_ptr< ::i18n::addressinput::Downloader> downloader( | |
658 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext())); | |
659 validator_ = AddressValidator::Build( | |
660 downloader.Pass(), | |
661 ValidationRulesStorageFactory::CreateStorage(), | |
662 this); | |
663 GetValidator()->LoadRules( | |
664 GetManager()->GetDefaultCountryCodeForNewAddress()); | |
665 } | |
666 | |
621 // TODO(estade): don't show the dialog if the site didn't specify the right | 667 // TODO(estade): don't show the dialog if the site didn't specify the right |
622 // fields. First we must figure out what the "right" fields are. | 668 // fields. First we must figure out what the "right" fields are. |
623 SuggestionsUpdated(); | 669 SuggestionsUpdated(); |
624 SubmitButtonDelayBegin(); | 670 SubmitButtonDelayBegin(); |
625 view_.reset(CreateView()); | 671 view_.reset(CreateView()); |
626 view_->Show(); | 672 view_->Show(); |
627 GetManager()->AddObserver(this); | 673 GetManager()->AddObserver(this); |
628 | 674 |
629 if (!account_chooser_model_->WalletIsSelected()) | 675 if (!account_chooser_model_->WalletIsSelected()) |
630 LogDialogLatencyToShow(); | 676 LogDialogLatencyToShow(); |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 } | 1201 } |
1156 | 1202 |
1157 return snapshot; | 1203 return snapshot; |
1158 } | 1204 } |
1159 | 1205 |
1160 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( | 1206 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( |
1161 const FieldValueMap& snapshot) { | 1207 const FieldValueMap& snapshot) { |
1162 if (snapshot.empty()) | 1208 if (snapshot.empty()) |
1163 return; | 1209 return; |
1164 | 1210 |
1165 FieldMapWrapper wrapper(snapshot); | |
1166 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 1211 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
1167 DialogSection section = static_cast<DialogSection>(i); | 1212 DialogSection section = static_cast<DialogSection>(i); |
1168 if (!SectionIsActive(section)) | 1213 if (!SectionIsActive(section)) |
1169 continue; | 1214 continue; |
1170 | 1215 |
1171 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1216 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
1172 wrapper.FillInputs(inputs); | |
1173 | |
1174 for (size_t i = 0; i < inputs->size(); ++i) { | 1217 for (size_t i = 0; i < inputs->size(); ++i) { |
1175 if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { | 1218 DetailInput* input = &(*inputs)[i]; |
1219 input->initial_value = | |
1220 GetInfoFromInputs(snapshot, section, AutofillType(input->type)); | |
1221 if (InputWasEdited(input->type, input->initial_value)) | |
1176 SuggestionsMenuModelForSection(section)->SetCheckedItem(kAddNewItemKey); | 1222 SuggestionsMenuModelForSection(section)->SetCheckedItem(kAddNewItemKey); |
1177 break; | |
1178 } | |
1179 } | 1223 } |
1180 } | 1224 } |
1181 } | 1225 } |
1182 | 1226 |
1183 void AutofillDialogControllerImpl::UpdateSection(DialogSection section) { | 1227 void AutofillDialogControllerImpl::UpdateSection(DialogSection section) { |
1184 if (view_) | 1228 if (view_) |
1185 view_->UpdateSection(section); | 1229 view_->UpdateSection(section); |
1186 } | 1230 } |
1187 | 1231 |
1188 void AutofillDialogControllerImpl::UpdateForErrors() { | 1232 void AutofillDialogControllerImpl::UpdateForErrors() { |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1641 if (it != wallet_errors_.end()) { | 1685 if (it != wallet_errors_.end()) { |
1642 TypeErrorInputMap::const_iterator iter = it->second.find(type); | 1686 TypeErrorInputMap::const_iterator iter = it->second.find(type); |
1643 if (iter != it->second.end()) { | 1687 if (iter != it->second.end()) { |
1644 if (iter->second.second == value) | 1688 if (iter->second.second == value) |
1645 return iter->second.first; | 1689 return iter->second.first; |
1646 it->second.erase(type); | 1690 it->second.erase(type); |
1647 } | 1691 } |
1648 } | 1692 } |
1649 } | 1693 } |
1650 | 1694 |
1651 switch (AutofillType(type).GetStorableType()) { | 1695 AutofillType autofill_type(type); |
1696 if (i18ninput::Enabled() && | |
1697 (autofill_type.group() == ADDRESS_HOME || | |
1698 autofill_type.group() == ADDRESS_BILLING)) { | |
1699 // TODO(dbeam): delete all US-specific address validation when | |
1700 // --enable-autofill-address-i18n is removed. | |
1701 return base::string16(); | |
1702 } | |
1703 | |
1704 switch (autofill_type.GetStorableType()) { | |
1652 case EMAIL_ADDRESS: | 1705 case EMAIL_ADDRESS: |
1653 if (!value.empty() && !IsValidEmailAddress(value)) { | 1706 if (!value.empty() && !IsValidEmailAddress(value)) { |
1654 return l10n_util::GetStringUTF16( | 1707 return l10n_util::GetStringUTF16( |
1655 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_EMAIL_ADDRESS); | 1708 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_EMAIL_ADDRESS); |
1656 } | 1709 } |
1657 break; | 1710 break; |
1658 | 1711 |
1659 case CREDIT_CARD_NUMBER: { | 1712 case CREDIT_CARD_NUMBER: { |
1660 if (!value.empty()) { | 1713 if (!value.empty()) { |
1661 base::string16 message = CreditCardNumberValidityMessage(value); | 1714 base::string16 message = CreditCardNumberValidityMessage(value); |
(...skipping 30 matching lines...) Expand all Loading... | |
1692 case ADDRESS_HOME_LINE2: | 1745 case ADDRESS_HOME_LINE2: |
1693 case ADDRESS_HOME_DEPENDENT_LOCALITY: | 1746 case ADDRESS_HOME_DEPENDENT_LOCALITY: |
1694 case ADDRESS_HOME_SORTING_CODE: | 1747 case ADDRESS_HOME_SORTING_CODE: |
1695 return base::string16(); // Optional until we have better validation. | 1748 return base::string16(); // Optional until we have better validation. |
1696 | 1749 |
1697 case ADDRESS_HOME_CITY: | 1750 case ADDRESS_HOME_CITY: |
1698 case ADDRESS_HOME_COUNTRY: | 1751 case ADDRESS_HOME_COUNTRY: |
1699 break; | 1752 break; |
1700 | 1753 |
1701 case ADDRESS_HOME_STATE: | 1754 case ADDRESS_HOME_STATE: |
1702 if (!value.empty() && !autofill::IsValidState(value) && | 1755 if (!value.empty() &&!autofill::IsValidState(value) && |
1703 CountryCodeForSection(section) == "US") { | 1756 CountryCodeForSection(section) == "US") { |
1757 DCHECK(!i18ninput::Enabled()); | |
1704 return l10n_util::GetStringUTF16( | 1758 return l10n_util::GetStringUTF16( |
1705 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); | 1759 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); |
1706 } | 1760 } |
1707 break; | 1761 break; |
1708 | 1762 |
1709 case ADDRESS_HOME_ZIP: | 1763 case ADDRESS_HOME_ZIP: |
1710 if (!value.empty() && !autofill::IsValidZip(value) && | 1764 if (!value.empty() && !autofill::IsValidZip(value) && |
1711 CountryCodeForSection(section) == "US") { | 1765 CountryCodeForSection(section) == "US") { |
1766 DCHECK(!i18ninput::Enabled()); | |
1712 return l10n_util::GetStringUTF16( | 1767 return l10n_util::GetStringUTF16( |
1713 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); | 1768 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); |
1714 } | 1769 } |
1715 break; | 1770 break; |
1716 | 1771 |
1717 case NAME_FULL: | 1772 case NAME_FULL: |
1718 // Wallet requires a first and last billing name. | 1773 // Wallet requires a first and last billing name. |
1719 if (section == SECTION_CC_BILLING && !value.empty() && | 1774 if (section == SECTION_CC_BILLING && !value.empty() && |
1720 !IsCardHolderNameValidForWallet(value)) { | 1775 !IsCardHolderNameValidForWallet(value)) { |
1721 DCHECK(IsPayingWithWallet()); | 1776 DCHECK(IsPayingWithWallet()); |
(...skipping 16 matching lines...) Expand all Loading... | |
1738 return value.empty() ? | 1793 return value.empty() ? |
1739 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : | 1794 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : |
1740 base::string16(); | 1795 base::string16(); |
1741 } | 1796 } |
1742 | 1797 |
1743 // TODO(groby): Also add tests. | 1798 // TODO(groby): Also add tests. |
1744 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( | 1799 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
1745 DialogSection section, | 1800 DialogSection section, |
1746 const FieldValueMap& inputs) { | 1801 const FieldValueMap& inputs) { |
1747 ValidityMessages messages; | 1802 ValidityMessages messages; |
1803 if (inputs.empty()) | |
1804 return messages; | |
1805 | |
1748 FieldValueMap field_values; | 1806 FieldValueMap field_values; |
1807 | |
1808 if (i18ninput::Enabled() && section != SECTION_CC) { | |
1809 AddressData address_data; | |
1810 i18ninput::CreateAddressData( | |
1811 base::Bind(&GetInfoFromInputs, base::ConstRef(inputs), section), | |
1812 &address_data); | |
1813 | |
1814 AddressProblems problems; | |
1815 if (GetValidator()->ValidateAddress( | |
1816 address_data, | |
1817 AddressProblemFilter(), | |
1818 &problems) == AddressValidator::SUCCESS) { | |
1819 common::AddressType address_type = section == SECTION_SHIPPING ? | |
1820 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | |
1821 for (size_t i = 0; i < problems.size(); ++i) { | |
1822 const AddressProblem& problem = problems[i]; | |
1823 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; | |
1824 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); | |
1825 messages.Set(i18ninput::TypeForField(problem.field, address_type), | |
1826 ValidityMessage(text, sure)); | |
1827 } | |
1828 } else { | |
1829 // TODO(dbeam): disable submit button until able to successfully validate. | |
1830 } | |
1831 } | |
1832 | |
1749 for (FieldValueMap::const_iterator iter = inputs.begin(); | 1833 for (FieldValueMap::const_iterator iter = inputs.begin(); |
1750 iter != inputs.end(); ++iter) { | 1834 iter != inputs.end(); ++iter) { |
1751 const ServerFieldType type = iter->first; | 1835 const ServerFieldType type = iter->first; |
1836 if (!messages.GetMessageOrDefault(type).text.empty()) | |
1837 continue; | |
1752 | 1838 |
1753 base::string16 text = InputValidityMessage(section, type, iter->second); | 1839 base::string16 text = InputValidityMessage(section, type, iter->second); |
1754 | 1840 |
1755 // Skip empty/unchanged fields in edit mode. Ignore country as it always has | 1841 // Skip empty/unchanged fields in edit mode. Ignore country as it always has |
1756 // a value. If the individual field does not have validation errors, assume | 1842 // a value. If the individual field does not have validation errors, assume |
1757 // it to be valid unless later proven otherwise. | 1843 // it to be valid unless later proven otherwise. |
1758 bool sure = InputWasEdited(type, iter->second) || | 1844 bool sure = InputWasEdited(type, iter->second) || |
1759 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY; | 1845 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY; |
1760 | 1846 |
1761 // Consider only individually valid fields for inter-field validation. | 1847 // Consider only individually valid fields for inter-field validation. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1847 void AutofillDialogControllerImpl::UserEditedOrActivatedInput( | 1933 void AutofillDialogControllerImpl::UserEditedOrActivatedInput( |
1848 DialogSection section, | 1934 DialogSection section, |
1849 ServerFieldType type, | 1935 ServerFieldType type, |
1850 gfx::NativeView parent_view, | 1936 gfx::NativeView parent_view, |
1851 const gfx::Rect& content_bounds, | 1937 const gfx::Rect& content_bounds, |
1852 const base::string16& field_contents, | 1938 const base::string16& field_contents, |
1853 bool was_edit) { | 1939 bool was_edit) { |
1854 ScopedViewUpdates updates(view_.get()); | 1940 ScopedViewUpdates updates(view_.get()); |
1855 | 1941 |
1856 if (type == ADDRESS_BILLING_COUNTRY || type == ADDRESS_HOME_COUNTRY) { | 1942 if (type == ADDRESS_BILLING_COUNTRY || type == ADDRESS_HOME_COUNTRY) { |
1943 DCHECK(i18ninput::Enabled()); | |
1944 | |
1857 const FieldValueMap snapshot = TakeUserInputSnapshot(); | 1945 const FieldValueMap snapshot = TakeUserInputSnapshot(); |
1946 | |
1858 // Clobber the inputs because the view's already been updated. | 1947 // Clobber the inputs because the view's already been updated. |
1859 RebuildInputsForCountry(section, field_contents, true); | 1948 RebuildInputsForCountry(section, field_contents, true); |
1860 RestoreUserInputFromSnapshot(snapshot); | 1949 RestoreUserInputFromSnapshot(snapshot); |
1861 UpdateSection(section); | 1950 UpdateSection(section); |
1951 | |
1952 GetValidator()->LoadRules(AutofillCountry::GetCountryCode( | |
1953 field_contents, g_browser_process->GetApplicationLocale())); | |
1862 } | 1954 } |
1863 | 1955 |
1864 // The rest of this method applies only to textfields. If a combobox, bail. | 1956 // The rest of this method applies only to textfields. If a combobox, bail. |
1865 if (ComboboxModelForAutofillType(type)) | 1957 if (ComboboxModelForAutofillType(type)) |
1866 return; | 1958 return; |
1867 | 1959 |
1868 // If the field is edited down to empty, don't show a popup. | 1960 // If the field is edited down to empty, don't show a popup. |
1869 if (was_edit && field_contents.empty()) { | 1961 if (was_edit && field_contents.empty()) { |
1870 HidePopup(); | 1962 HidePopup(); |
1871 return; | 1963 return; |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2568 handling_use_wallet_link_click_(false), | 2660 handling_use_wallet_link_click_(false), |
2569 passive_failed_(false), | 2661 passive_failed_(false), |
2570 billing_country_combobox_model_(*GetManager()), | 2662 billing_country_combobox_model_(*GetManager()), |
2571 shipping_country_combobox_model_(*GetManager()), | 2663 shipping_country_combobox_model_(*GetManager()), |
2572 suggested_cc_(this), | 2664 suggested_cc_(this), |
2573 suggested_billing_(this), | 2665 suggested_billing_(this), |
2574 suggested_cc_billing_(this), | 2666 suggested_cc_billing_(this), |
2575 suggested_shipping_(this), | 2667 suggested_shipping_(this), |
2576 cares_about_shipping_(true), | 2668 cares_about_shipping_(true), |
2577 popup_input_type_(UNKNOWN_TYPE), | 2669 popup_input_type_(UNKNOWN_TYPE), |
2578 weak_ptr_factory_(this), | |
2579 waiting_for_explicit_sign_in_response_(false), | 2670 waiting_for_explicit_sign_in_response_(false), |
2580 has_accepted_legal_documents_(false), | 2671 has_accepted_legal_documents_(false), |
2581 is_submitting_(false), | 2672 is_submitting_(false), |
2582 choose_another_instrument_or_address_(false), | 2673 choose_another_instrument_or_address_(false), |
2583 wallet_server_validation_recoverable_(true), | 2674 wallet_server_validation_recoverable_(true), |
2584 data_was_passed_back_(false), | 2675 data_was_passed_back_(false), |
2585 was_ui_latency_logged_(false), | 2676 was_ui_latency_logged_(false), |
2586 card_generated_animation_(2000, 60, this) { | 2677 card_generated_animation_(2000, 60, this), |
2678 weak_ptr_factory_(this) { | |
2587 // TODO(estade): remove duplicates from |form_structure|? | 2679 // TODO(estade): remove duplicates from |form_structure|? |
2588 DCHECK(!callback_.is_null()); | 2680 DCHECK(!callback_.is_null()); |
2589 } | 2681 } |
2590 | 2682 |
2591 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { | 2683 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
2592 return AutofillDialogView::Create(this); | 2684 return AutofillDialogView::Create(this); |
2593 } | 2685 } |
2594 | 2686 |
2595 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { | 2687 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { |
2596 return PersonalDataManagerFactory::GetForProfile(profile_); | 2688 return PersonalDataManagerFactory::GetForProfile(profile_); |
2597 } | 2689 } |
2598 | 2690 |
2599 const wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() | 2691 const wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() |
2600 const { | 2692 const { |
2601 return const_cast<AutofillDialogControllerImpl*>(this)->GetWalletClient(); | 2693 return const_cast<AutofillDialogControllerImpl*>(this)->GetWalletClient(); |
2602 } | 2694 } |
2603 | 2695 |
2604 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { | 2696 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { |
2605 return &wallet_client_; | 2697 return &wallet_client_; |
2606 } | 2698 } |
2607 | 2699 |
2700 AddressValidator* AutofillDialogControllerImpl::GetValidator() { | |
2701 return validator_.get(); | |
2702 } | |
2703 | |
2608 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { | 2704 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { |
2609 return account_chooser_model_->WalletIsSelected() && | 2705 return account_chooser_model_->WalletIsSelected() && |
2610 SignedInState() == SIGNED_IN; | 2706 SignedInState() == SIGNED_IN; |
2611 } | 2707 } |
2612 | 2708 |
2613 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { | 2709 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { |
2614 risk_data_.clear(); | 2710 risk_data_.clear(); |
2615 | 2711 |
2616 uint64 obfuscated_gaia_id = 0; | 2712 uint64 obfuscated_gaia_id = 0; |
2617 bool success = base::StringToUint64(wallet_items_->ObfuscatedGaiaId(), | 2713 bool success = base::StringToUint64(wallet_items_->ObfuscatedGaiaId(), |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3066 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 3162 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
3067 } | 3163 } |
3068 | 3164 |
3069 std::vector<ServerFieldType> AutofillDialogControllerImpl:: | 3165 std::vector<ServerFieldType> AutofillDialogControllerImpl:: |
3070 RequestedTypesForSection(DialogSection section) const { | 3166 RequestedTypesForSection(DialogSection section) const { |
3071 return common::TypesFromInputs(RequestedFieldsForSection(section)); | 3167 return common::TypesFromInputs(RequestedFieldsForSection(section)); |
3072 } | 3168 } |
3073 | 3169 |
3074 std::string AutofillDialogControllerImpl::CountryCodeForSection( | 3170 std::string AutofillDialogControllerImpl::CountryCodeForSection( |
3075 DialogSection section) { | 3171 DialogSection section) { |
3172 base::string16 country; | |
3173 | |
3076 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 3174 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
3077 if (wrapper) { | 3175 if (wrapper) { |
3078 return AutofillCountry::GetCountryCode( | 3176 country = wrapper->GetInfo(AutofillType(CountryTypeForSection(section))); |
3079 wrapper->GetInfo(AutofillType(CountryTypeForSection(section))), | 3177 } else { |
3080 g_browser_process->GetApplicationLocale()); | 3178 FieldValueMap outputs; |
3179 view_->GetUserInput(section, &outputs); | |
3180 country = outputs[CountryTypeForSection(section)]; | |
3081 } | 3181 } |
3082 | 3182 |
3083 CountryComboboxModel* model = CountryComboboxModelForSection(section); | 3183 return AutofillCountry::GetCountryCode( |
3084 return model ? model->GetDefaultCountryCode() : std::string(); | 3184 country, g_browser_process->GetApplicationLocale()); |
3085 } | 3185 } |
3086 | 3186 |
3087 bool AutofillDialogControllerImpl::RebuildInputsForCountry( | 3187 bool AutofillDialogControllerImpl::RebuildInputsForCountry( |
3088 DialogSection section, | 3188 DialogSection section, |
3089 const base::string16& country_name, | 3189 const base::string16& country_name, |
3090 bool should_clobber) { | 3190 bool should_clobber) { |
3091 DCHECK_NE(SECTION_CC, section); | 3191 DCHECK_NE(SECTION_CC, section); |
3092 | 3192 |
3093 if (view_ && !should_clobber) { | 3193 if (view_ && !should_clobber) { |
3094 FieldValueMap outputs; | 3194 FieldValueMap outputs; |
3095 view_->GetUserInput(section, &outputs); | 3195 view_->GetUserInput(section, &outputs); |
3096 | 3196 |
3097 // If |country_name| is the same as the view, no-op and let the caller know. | 3197 // If |country_name| is the same as the view, no-op and let the caller know. |
3098 if (outputs[CountryTypeForSection(section)] == country_name) | 3198 if (outputs[CountryTypeForSection(section)] == country_name) |
3099 return false; | 3199 return false; |
3100 } | 3200 } |
3101 | 3201 |
3102 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 3202 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
3103 inputs->clear(); | 3203 inputs->clear(); |
3104 | 3204 |
3105 std::string country_code = AutofillCountry::GetCountryCode( | 3205 std::string country_code = AutofillCountry::GetCountryCode( |
3106 country_name, g_browser_process->GetApplicationLocale()); | 3206 country_name, g_browser_process->GetApplicationLocale()); |
3107 common::BuildInputsForSection(section, country_code, inputs); | 3207 common::BuildInputsForSection(section, country_code, inputs); |
3208 | |
Evan Stade
2014/02/01 00:56:31
^H
Dan Beam
2014/02/01 01:14:54
Done.
| |
3108 return true; | 3209 return true; |
3109 } | 3210 } |
3110 | 3211 |
3111 void AutofillDialogControllerImpl::HidePopup() { | 3212 void AutofillDialogControllerImpl::HidePopup() { |
3112 if (popup_controller_.get()) | 3213 if (popup_controller_.get()) |
3113 popup_controller_->Hide(); | 3214 popup_controller_->Hide(); |
3114 popup_input_type_ = UNKNOWN_TYPE; | 3215 popup_input_type_ = UNKNOWN_TYPE; |
3115 } | 3216 } |
3116 | 3217 |
3117 void AutofillDialogControllerImpl::SetEditingExistingData( | 3218 void AutofillDialogControllerImpl::SetEditingExistingData( |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3391 DCHECK_EQ(animation, &card_generated_animation_); | 3492 DCHECK_EQ(animation, &card_generated_animation_); |
3392 PushOverlayUpdate(); | 3493 PushOverlayUpdate(); |
3393 } | 3494 } |
3394 | 3495 |
3395 void AutofillDialogControllerImpl::AnimationEnded( | 3496 void AutofillDialogControllerImpl::AnimationEnded( |
3396 const gfx::Animation* animation) { | 3497 const gfx::Animation* animation) { |
3397 DCHECK_EQ(animation, &card_generated_animation_); | 3498 DCHECK_EQ(animation, &card_generated_animation_); |
3398 DoFinishSubmit(); | 3499 DoFinishSubmit(); |
3399 } | 3500 } |
3400 | 3501 |
3502 void AutofillDialogControllerImpl::OnAddressValidationRulesLoaded( | |
3503 const std::string& country_code, | |
3504 bool success) { | |
3505 // TODO(dbeam): should we retry on failure? | |
3506 // TODO(dbeam): disable the submit button until rules are successfully loaded. | |
3507 // TODO(dbeam): ask |view_| to re-validate its contents if necessary. | |
3508 } | |
3509 | |
3401 void AutofillDialogControllerImpl::DoFinishSubmit() { | 3510 void AutofillDialogControllerImpl::DoFinishSubmit() { |
3402 FillOutputForSection(SECTION_CC); | 3511 FillOutputForSection(SECTION_CC); |
3403 FillOutputForSection(SECTION_BILLING); | 3512 FillOutputForSection(SECTION_BILLING); |
3404 FillOutputForSection(SECTION_CC_BILLING); | 3513 FillOutputForSection(SECTION_CC_BILLING); |
3405 | 3514 |
3406 if (ShouldUseBillingForShipping()) { | 3515 if (ShouldUseBillingForShipping()) { |
3407 FillOutputForSectionWithComparator( | 3516 FillOutputForSectionWithComparator( |
3408 SECTION_BILLING, | 3517 SECTION_BILLING, |
3409 base::Bind(ServerTypeMatchesShippingField)); | 3518 base::Bind(ServerTypeMatchesShippingField)); |
3410 FillOutputForSectionWithComparator( | 3519 FillOutputForSectionWithComparator( |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3648 view_->UpdateButtonStrip(); | 3757 view_->UpdateButtonStrip(); |
3649 } | 3758 } |
3650 | 3759 |
3651 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3760 void AutofillDialogControllerImpl::FetchWalletCookie() { |
3652 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3761 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
3653 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3762 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
3654 signin_helper_->StartWalletCookieValueFetch(); | 3763 signin_helper_->StartWalletCookieValueFetch(); |
3655 } | 3764 } |
3656 | 3765 |
3657 } // namespace autofill | 3766 } // namespace autofill |
OLD | NEW |