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

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

Issue 124533003: Add country combobox to change country and rebuild address inputs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 11 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
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // access checks. 597 // access checks.
598 const GURL& current_url = web_contents()->GetLastCommittedURL(); 598 const GURL& current_url = web_contents()->GetLastCommittedURL();
599 invoked_from_same_origin_ = 599 invoked_from_same_origin_ =
600 current_url.GetOrigin() == source_url_.GetOrigin(); 600 current_url.GetOrigin() == source_url_.GetOrigin();
601 601
602 if (!invoked_from_same_origin_) { 602 if (!invoked_from_same_origin_) {
603 GetMetricLogger().LogDialogSecurityMetric( 603 GetMetricLogger().LogDialogSecurityMetric(
604 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); 604 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME);
605 } 605 }
606 606
607 // TODO(dbeam): use GetManager()->GetDefaultCountryCodeForNewAddress() 607 // TODO(dbeam): does SECTION_CC need to be internationalized?
Evan Stade 2014/01/15 23:12:29 I don't think so. I think you can leave out this T
Dan Beam 2014/01/16 01:39:13 Done.
608 // instead when the country combobox is visible. http://crbug.com/331544 608 common::BuildInputsForSection(SECTION_CC, "US", &requested_cc_fields_);
Evan Stade 2014/01/15 23:12:29 pass an empty country code to make it clear it's n
Dan Beam 2014/01/16 01:39:13 Done.
609 std::string country_code = "US"; 609 OnComboboxModelChanged(&billing_country_combobox_model_);
610 common::BuildInputsForSection(SECTION_CC, 610 OnComboboxModelChanged(&shipping_country_combobox_model_);
611 country_code,
612 &requested_cc_fields_);
613 common::BuildInputsForSection(SECTION_BILLING,
614 country_code,
615 &requested_billing_fields_);
616 common::BuildInputsForSection(SECTION_CC_BILLING,
617 country_code,
618 &requested_cc_billing_fields_);
619 common::BuildInputsForSection(SECTION_SHIPPING,
620 country_code,
621 &requested_shipping_fields_);
622 611
623 // Test whether we need to show the shipping section. If filling that section 612 // Test whether we need to show the shipping section. If filling that section
624 // would be a no-op, don't show it. 613 // would be a no-op, don't show it.
625 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); 614 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING);
626 cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure( 615 cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure(
627 inputs, 616 inputs,
628 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), 617 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING),
629 &form_structure_); 618 &form_structure_);
630 619
631 account_chooser_model_.reset( 620 account_chooser_model_.reset(
632 new AccountChooserModel(this, 621 new AccountChooserModel(this,
633 profile_, 622 profile_,
634 !ShouldShowAccountChooser(), 623 !ShouldShowAccountChooser(),
635 metric_logger_)); 624 metric_logger_));
636 625
637 if (account_chooser_model_->WalletIsSelected()) 626 if (account_chooser_model_->WalletIsSelected())
638 FetchWalletCookie(); 627 FetchWalletCookie();
639 628
640 // TODO(estade): don't show the dialog if the site didn't specify the right 629 // TODO(estade): don't show the dialog if the site didn't specify the right
641 // fields. First we must figure out what the "right" fields are. 630 // fields. First we must figure out what the "right" fields are.
642 SuggestionsUpdated(); 631 SuggestionsUpdated();
643 SubmitButtonDelayBegin(); 632 SubmitButtonDelayBegin();
644 view_.reset(CreateView()); 633 view_.reset(CreateView());
645 view_->Show(); 634 view_->Show();
635
646 GetManager()->AddObserver(this); 636 GetManager()->AddObserver(this);
637 billing_country_combobox_model_.AddObserver(this);
638 shipping_country_combobox_model_.AddObserver(this);
647 639
648 if (!account_chooser_model_->WalletIsSelected()) 640 if (!account_chooser_model_->WalletIsSelected())
649 LogDialogLatencyToShow(); 641 LogDialogLatencyToShow();
650 } 642 }
651 643
652 void AutofillDialogControllerImpl::Hide() { 644 void AutofillDialogControllerImpl::Hide() {
653 if (view_) 645 if (view_)
654 view_->Hide(); 646 view_->Hide();
655 } 647 }
656 648
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 1083
1092 for (size_t i = 0; i < documents.size(); ++i) { 1084 for (size_t i = 0; i < documents.size(); ++i) {
1093 size_t link_start = offsets[i] + base_offset; 1085 size_t link_start = offsets[i] + base_offset;
1094 legal_document_link_ranges_.push_back(gfx::Range( 1086 legal_document_link_ranges_.push_back(gfx::Range(
1095 link_start, link_start + documents[i]->display_name().size())); 1087 link_start, link_start + documents[i]->display_name().size()));
1096 } 1088 }
1097 legal_documents_text_ = text; 1089 legal_documents_text_ = text;
1098 } 1090 }
1099 1091
1100 void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { 1092 void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) {
1101 SetEditingExistingData(section, false);
1102
1103 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 1093 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
1104 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { 1094 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) {
1105 it->initial_value = common::GetHardcodedValueForType(it->type); 1095 it->initial_value = common::GetHardcodedValueForType(it->type);
1106 } 1096 }
1107 } 1097 }
1108 1098
1109 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( 1099 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion(
1110 DialogSection section) { 1100 DialogSection section) {
1111 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so 1101 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so
1112 // get the wrapper before this potentially happens below. 1102 // get the wrapper before this potentially happens below.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 } 1153 }
1164 1154
1165 return snapshot; 1155 return snapshot;
1166 } 1156 }
1167 1157
1168 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( 1158 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot(
1169 const FieldValueMap& snapshot) { 1159 const FieldValueMap& snapshot) {
1170 if (snapshot.empty()) 1160 if (snapshot.empty())
1171 return; 1161 return;
1172 1162
1163 FieldValueMap::const_iterator it = snapshot.find(ADDRESS_BILLING_COUNTRY);
1164 if (it != snapshot.end()) {
1165 billing_country_combobox_model_.SetDefaultCountry(
1166 AutofillCountry::GetCountryCode(
1167 it->second, g_browser_process->GetApplicationLocale()));
1168 }
1169
1170 FieldValueMap::const_iterator ship_it = snapshot.find(ADDRESS_HOME_COUNTRY);
1171 if (ship_it != snapshot.end()) {
1172 shipping_country_combobox_model_.SetDefaultCountry(
1173 AutofillCountry::GetCountryCode(
1174 ship_it->second, g_browser_process->GetApplicationLocale()));
1175 }
1176
1173 FieldMapWrapper wrapper(snapshot); 1177 FieldMapWrapper wrapper(snapshot);
1174 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 1178 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
1175 DialogSection section = static_cast<DialogSection>(i); 1179 DialogSection section = static_cast<DialogSection>(i);
1176 if (!SectionIsActive(section)) 1180 if (!SectionIsActive(section))
1177 continue; 1181 continue;
1178 1182
1179 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 1183 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
1180 wrapper.FillInputs(inputs); 1184 wrapper.FillInputs(inputs);
1181 1185
1182 for (size_t i = 0; i < inputs->size(); ++i) { 1186 for (size_t i = 0; i < inputs->size(); ++i) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1300
1297 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( 1301 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType(
1298 ServerFieldType type) { 1302 ServerFieldType type) {
1299 switch (type) { 1303 switch (type) {
1300 case CREDIT_CARD_EXP_MONTH: 1304 case CREDIT_CARD_EXP_MONTH:
1301 return &cc_exp_month_combobox_model_; 1305 return &cc_exp_month_combobox_model_;
1302 1306
1303 case CREDIT_CARD_EXP_4_DIGIT_YEAR: 1307 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
1304 return &cc_exp_year_combobox_model_; 1308 return &cc_exp_year_combobox_model_;
1305 1309
1310 case ADDRESS_BILLING_COUNTRY:
1311 return &billing_country_combobox_model_;
1312
1306 case ADDRESS_HOME_COUNTRY: 1313 case ADDRESS_HOME_COUNTRY:
1307 case ADDRESS_BILLING_COUNTRY: 1314 return &shipping_country_combobox_model_;
1308 return &country_combobox_model_;
1309 1315
1310 default: 1316 default:
1311 return NULL; 1317 return NULL;
1312 } 1318 }
1313 } 1319 }
1314 1320
1315 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( 1321 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection(
1316 DialogSection section) { 1322 DialogSection section) {
1317 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 1323 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
1318 // The shipping section menu is special. It will always show because there is 1324 // The shipping section menu is special. It will always show because there is
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 } 1698 }
1693 break; 1699 break;
1694 1700
1695 case ADDRESS_HOME_LINE1: 1701 case ADDRESS_HOME_LINE1:
1696 break; 1702 break;
1697 1703
1698 case ADDRESS_HOME_LINE2: 1704 case ADDRESS_HOME_LINE2:
1699 return base::string16(); // Line 2 is optional - always valid. 1705 return base::string16(); // Line 2 is optional - always valid.
1700 1706
1701 case ADDRESS_HOME_CITY: 1707 case ADDRESS_HOME_CITY:
1708 case ADDRESS_HOME_DEPENDENT_LOCALITY:
1702 case ADDRESS_HOME_COUNTRY: 1709 case ADDRESS_HOME_COUNTRY:
1703 break; 1710 break;
1704 1711
1705 case ADDRESS_HOME_STATE: 1712 case ADDRESS_HOME_STATE:
1706 if (!value.empty() && !autofill::IsValidState(value)) { 1713 if (!value.empty() && !autofill::IsValidState(value) &&
1714 CountryCodeForSection(section) == "US") {
1707 return l10n_util::GetStringUTF16( 1715 return l10n_util::GetStringUTF16(
1708 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); 1716 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION);
1709 } 1717 }
1710 break; 1718 break;
1711 1719
1712 case ADDRESS_HOME_ZIP: 1720 case ADDRESS_HOME_ZIP:
1713 if (!value.empty() && !autofill::IsValidZip(value)) { 1721 if (!value.empty() && !autofill::IsValidZip(value) &&
1722 CountryCodeForSection(section) == "US") {
1714 return l10n_util::GetStringUTF16( 1723 return l10n_util::GetStringUTF16(
1715 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); 1724 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE);
1716 } 1725 }
1717 break; 1726 break;
1718 1727
1728 case ADDRESS_HOME_SORTING_CODE:
1729 break;
1730
1719 case NAME_FULL: 1731 case NAME_FULL:
1720 // Wallet requires a first and last billing name. 1732 // Wallet requires a first and last billing name.
1721 if (section == SECTION_CC_BILLING && !value.empty() && 1733 if (section == SECTION_CC_BILLING && !value.empty() &&
1722 !IsCardHolderNameValidForWallet(value)) { 1734 !IsCardHolderNameValidForWallet(value)) {
1723 DCHECK(IsPayingWithWallet()); 1735 DCHECK(IsPayingWithWallet());
1724 return l10n_util::GetStringUTF16( 1736 return l10n_util::GetStringUTF16(
1725 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES); 1737 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES);
1726 } 1738 }
1727 break; 1739 break;
1728 1740
(...skipping 11 matching lines...) Expand all
1740 return value.empty() ? 1752 return value.empty() ?
1741 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : 1753 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) :
1742 base::string16(); 1754 base::string16();
1743 } 1755 }
1744 1756
1745 // TODO(groby): Also add tests. 1757 // TODO(groby): Also add tests.
1746 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( 1758 ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
1747 DialogSection section, 1759 DialogSection section,
1748 const FieldValueMap& inputs) { 1760 const FieldValueMap& inputs) {
1749 ValidityMessages messages; 1761 ValidityMessages messages;
1750 std::map<ServerFieldType, base::string16> field_values; 1762 FieldValueMap field_values;
1751 for (FieldValueMap::const_iterator iter = inputs.begin(); 1763 for (FieldValueMap::const_iterator iter = inputs.begin();
1752 iter != inputs.end(); ++iter) { 1764 iter != inputs.end(); ++iter) {
1753 const ServerFieldType type = iter->first; 1765 const ServerFieldType type = iter->first;
1754 1766
1755 base::string16 text = InputValidityMessage(section, type, iter->second); 1767 base::string16 text = InputValidityMessage(section, type, iter->second);
1756 1768
1757 // Skip empty/unchanged fields in edit mode. Ignore country code as it 1769 // Skip empty/unchanged fields in edit mode. Ignore country as it always has
1758 // always has a value. If the individual field does not have validation 1770 // a value. If the individual field does not have validation errors, assume
1759 // errors, assume it to be valid unless later proven otherwise. 1771 // it to be valid unless later proven otherwise.
1760 bool sure = InputWasEdited(type, iter->second) || 1772 bool sure = InputWasEdited(type, iter->second) ||
1761 ComboboxModelForAutofillType(type) == &country_combobox_model_; 1773 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY;
1762 1774
1763 // Consider only individually valid fields for inter-field validation. 1775 // Consider only individually valid fields for inter-field validation.
1764 if (text.empty()) { 1776 if (text.empty()) {
1765 field_values[type] = iter->second; 1777 field_values[type] = iter->second;
1766 // If the field is valid but can be invalidated by inter-field validation, 1778 // If the field is valid but can be invalidated by inter-field validation,
1767 // assume it to be unsure. 1779 // assume it to be unsure.
1768 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR || 1780 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
1769 type == CREDIT_CARD_EXP_MONTH || 1781 type == CREDIT_CARD_EXP_MONTH ||
1770 type == CREDIT_CARD_VERIFICATION_CODE || 1782 type == CREDIT_CARD_VERIFICATION_CODE ||
1771 type == PHONE_HOME_WHOLE_NUMBER || 1783 type == PHONE_HOME_WHOLE_NUMBER ||
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 return messages; 1858 return messages;
1847 } 1859 }
1848 1860
1849 void AutofillDialogControllerImpl::UserEditedOrActivatedInput( 1861 void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
1850 DialogSection section, 1862 DialogSection section,
1851 ServerFieldType type, 1863 ServerFieldType type,
1852 gfx::NativeView parent_view, 1864 gfx::NativeView parent_view,
1853 const gfx::Rect& content_bounds, 1865 const gfx::Rect& content_bounds,
1854 const base::string16& field_contents, 1866 const base::string16& field_contents,
1855 bool was_edit) { 1867 bool was_edit) {
1868 ScopedViewUpdates updates(view_.get());
1869
1870 if (type == ADDRESS_BILLING_COUNTRY || type == ADDRESS_HOME_COUNTRY) {
1871 FieldValueMap snapshot = TakeUserInputSnapshot();
1872 snapshot[type] = field_contents;
1873 RestoreUserInputFromSnapshot(snapshot);
1874 const bool is_billing = type == ADDRESS_BILLING_COUNTRY;
1875 UpdateSection(is_billing ? ActiveBillingSection() : SECTION_SHIPPING);
1876 }
1877
1878 // The rest of this method applies only to textfields. If a combobox, bail.
1879 if (ComboboxModelForAutofillType(type))
1880 return;
1881
1856 // If the field is edited down to empty, don't show a popup. 1882 // If the field is edited down to empty, don't show a popup.
1857 if (was_edit && field_contents.empty()) { 1883 if (was_edit && field_contents.empty()) {
1858 HidePopup(); 1884 HidePopup();
1859 return; 1885 return;
1860 } 1886 }
1861 1887
1862 // If the user clicks while the popup is already showing, be sure to hide 1888 // If the user clicks while the popup is already showing, be sure to hide
1863 // it. 1889 // it.
1864 if (!was_edit && popup_controller_.get()) { 1890 if (!was_edit && popup_controller_.get()) {
1865 HidePopup(); 1891 HidePopup();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 1949
1924 void AutofillDialogControllerImpl::FocusMoved() { 1950 void AutofillDialogControllerImpl::FocusMoved() {
1925 HidePopup(); 1951 HidePopup();
1926 } 1952 }
1927 1953
1928 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const { 1954 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const {
1929 return popup_input_type_ == UNKNOWN_TYPE; 1955 return popup_input_type_ == UNKNOWN_TYPE;
1930 } 1956 }
1931 1957
1932 void AutofillDialogControllerImpl::ViewClosed() { 1958 void AutofillDialogControllerImpl::ViewClosed() {
1933 GetManager()->RemoveObserver(this); 1959 GetManager()->RemoveObserver(this);
Evan Stade 2014/01/15 23:12:29 why is this here and not in the destructor? why a
Dan Beam 2014/01/16 01:39:13 Done.
1960 billing_country_combobox_model_.RemoveObserver(this);
1961 shipping_country_combobox_model_.RemoveObserver(this);
1934 1962
1935 // Called from here rather than in ~AutofillDialogControllerImpl as this 1963 // Called from here rather than in ~AutofillDialogControllerImpl as this
1936 // relies on virtual methods that change to their base class in the dtor. 1964 // relies on virtual methods that change to their base class in the dtor.
1937 MaybeShowCreditCardBubble(); 1965 MaybeShowCreditCardBubble();
1938 1966
1939 delete this; 1967 delete this;
1940 } 1968 }
1941 1969
1942 std::vector<DialogNotification> AutofillDialogControllerImpl:: 1970 std::vector<DialogNotification> AutofillDialogControllerImpl::
1943 CurrentNotifications() { 1971 CurrentNotifications() {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 if (common::IsCreditCardType(popup_input_type_)) { 2179 if (common::IsCreditCardType(popup_input_type_)) {
2152 wrapper.reset(new AutofillCreditCardWrapper( 2180 wrapper.reset(new AutofillCreditCardWrapper(
2153 GetManager()->GetCreditCardByGUID(pair.first))); 2181 GetManager()->GetCreditCardByGUID(pair.first)));
2154 } else { 2182 } else {
2155 wrapper.reset(new AutofillProfileWrapper( 2183 wrapper.reset(new AutofillProfileWrapper(
2156 GetManager()->GetProfileByGUID(pair.first), 2184 GetManager()->GetProfileByGUID(pair.first),
2157 AutofillType(popup_input_type_), 2185 AutofillType(popup_input_type_),
2158 pair.second)); 2186 pair.second));
2159 } 2187 }
2160 2188
2189 if (i18ninput::Enabled()) {
2190 // If country will change while filling, rebuild inputs now.
Evan Stade 2014/01/15 23:12:29 I can't make sense of this sentence.
Dan Beam 2014/01/16 01:39:13 Removed.
2191 base::string16 billing_country;
2192 if (!billing_country_combobox_model_.GetDefaultIndex())
2193 billing_country = wrapper->GetInfo(AutofillType(ADDRESS_BILLING_COUNTRY));
2194
2195 base::string16 shipping_country;
2196 if (!shipping_country_combobox_model_.GetDefaultIndex())
2197 shipping_country = wrapper->GetInfo(AutofillType(ADDRESS_HOME_COUNTRY));
2198
2199 if (!billing_country.empty() || !shipping_country.empty()) {
2200 FieldValueMap snapshot = TakeUserInputSnapshot();
2201
2202 if (!billing_country.empty())
2203 snapshot[ADDRESS_BILLING_COUNTRY] = billing_country;
2204
2205 if (!shipping_country.empty())
2206 snapshot[ADDRESS_HOME_COUNTRY] = shipping_country;
2207
2208 RestoreUserInputFromSnapshot(snapshot);
2209
2210 if (!billing_country.empty())
2211 UpdateSection(ActiveBillingSection());
2212
2213 if (!shipping_country.empty())
2214 UpdateSection(SECTION_SHIPPING);
2215 }
2216 }
2217
2161 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 2218 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
2162 DialogSection section = static_cast<DialogSection>(i); 2219 DialogSection section = static_cast<DialogSection>(i);
2163 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); 2220 wrapper->FillInputs(MutableRequestedFieldsForSection(section));
2164 view_->FillSection(section, popup_input_type_); 2221 view_->FillSection(section, popup_input_type_);
2165 } 2222 }
2166 2223
2167 GetMetricLogger().LogDialogPopupEvent( 2224 GetMetricLogger().LogDialogPopupEvent(
2168 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); 2225 AutofillMetrics::DIALOG_POPUP_FORM_FILLED);
2169 2226
2170 // TODO(estade): not sure why it's necessary to do this explicitly. 2227 // TODO(estade): not sure why it's necessary to do this explicitly.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 url = SectionForSuggestionsMenuModel(*model) == SECTION_SHIPPING ? 2287 url = SectionForSuggestionsMenuModel(*model) == SECTION_SHIPPING ?
2231 wallet::GetManageAddressesUrl(user_index) : 2288 wallet::GetManageAddressesUrl(user_index) :
2232 wallet::GetManageInstrumentsUrl(user_index); 2289 wallet::GetManageInstrumentsUrl(user_index);
2233 } 2290 }
2234 2291
2235 OpenTabWithUrl(url); 2292 OpenTabWithUrl(url);
2236 return; 2293 return;
2237 } 2294 }
2238 2295
2239 model->SetCheckedIndex(index); 2296 model->SetCheckedIndex(index);
2297
2240 DialogSection section = SectionForSuggestionsMenuModel(*model); 2298 DialogSection section = SectionForSuggestionsMenuModel(*model);
2299 SetEditingExistingData(section, false);
2300
2301 if (i18ninput::Enabled()) {
2302 if (section == SECTION_SHIPPING)
2303 shipping_country_combobox_model_.ResetDefault();
2304 else if (section == SECTION_BILLING || section == SECTION_CC_BILLING)
2305 billing_country_combobox_model_.ResetDefault();
2306 }
2307
2241 ResetSectionInput(section); 2308 ResetSectionInput(section);
2309
2242 ShowEditUiIfBadSuggestion(section); 2310 ShowEditUiIfBadSuggestion(section);
2243 UpdateSection(section); 2311 UpdateSection(section);
2244 view_->UpdateNotificationArea(); 2312 view_->UpdateNotificationArea();
2245 UpdateForErrors(); 2313 UpdateForErrors();
2246 2314
2247 LogSuggestionItemSelectedMetric(*model); 2315 LogSuggestionItemSelectedMetric(*model);
2248 } 2316 }
2249 2317
2250 //////////////////////////////////////////////////////////////////////////////// 2318 ////////////////////////////////////////////////////////////////////////////////
2251 // wallet::WalletClientDelegate implementation. 2319 // wallet::WalletClientDelegate implementation.
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2514 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), 2582 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())),
2515 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), 2583 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN),
2516 form_structure_(form_structure), 2584 form_structure_(form_structure),
2517 invoked_from_same_origin_(true), 2585 invoked_from_same_origin_(true),
2518 source_url_(source_url), 2586 source_url_(source_url),
2519 callback_(callback), 2587 callback_(callback),
2520 wallet_client_(profile_->GetRequestContext(), this, source_url), 2588 wallet_client_(profile_->GetRequestContext(), this, source_url),
2521 wallet_items_requested_(false), 2589 wallet_items_requested_(false),
2522 handling_use_wallet_link_click_(false), 2590 handling_use_wallet_link_click_(false),
2523 passive_failed_(false), 2591 passive_failed_(false),
2524 country_combobox_model_(*GetManager()), 2592 billing_country_combobox_model_(*GetManager()),
2593 shipping_country_combobox_model_(*GetManager()),
2525 suggested_cc_(this), 2594 suggested_cc_(this),
2526 suggested_billing_(this), 2595 suggested_billing_(this),
2527 suggested_cc_billing_(this), 2596 suggested_cc_billing_(this),
2528 suggested_shipping_(this), 2597 suggested_shipping_(this),
2529 cares_about_shipping_(true), 2598 cares_about_shipping_(true),
2530 popup_input_type_(UNKNOWN_TYPE), 2599 popup_input_type_(UNKNOWN_TYPE),
2531 weak_ptr_factory_(this), 2600 weak_ptr_factory_(this),
2532 waiting_for_explicit_sign_in_response_(false), 2601 waiting_for_explicit_sign_in_response_(false),
2533 has_accepted_legal_documents_(false), 2602 has_accepted_legal_documents_(false),
2534 is_submitting_(false), 2603 is_submitting_(false),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 2671
2603 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { 2672 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) {
2604 chrome::NavigateParams params( 2673 chrome::NavigateParams params(
2605 chrome::FindBrowserWithWebContents(web_contents()), 2674 chrome::FindBrowserWithWebContents(web_contents()),
2606 url, 2675 url,
2607 content::PAGE_TRANSITION_LINK); 2676 content::PAGE_TRANSITION_LINK);
2608 params.disposition = NEW_FOREGROUND_TAB; 2677 params.disposition = NEW_FOREGROUND_TAB;
2609 chrome::Navigate(&params); 2678 chrome::Navigate(&params);
2610 } 2679 }
2611 2680
2681 DialogSection AutofillDialogControllerImpl::ActiveBillingSection() const {
2682 return IsPayingWithWallet() ? SECTION_CC_BILLING : SECTION_BILLING;
2683 }
2684
2612 bool AutofillDialogControllerImpl::IsEditingExistingData( 2685 bool AutofillDialogControllerImpl::IsEditingExistingData(
2613 DialogSection section) const { 2686 DialogSection section) const {
2614 return section_editing_state_.count(section) > 0; 2687 return section_editing_state_.count(section) > 0;
2615 } 2688 }
2616 2689
2617 bool AutofillDialogControllerImpl::IsManuallyEditingSection( 2690 bool AutofillDialogControllerImpl::IsManuallyEditingSection(
2618 DialogSection section) const { 2691 DialogSection section) const {
2619 return IsEditingExistingData(section) || 2692 return IsEditingExistingData(section) ||
2620 SuggestionsMenuModelForSection(section)-> 2693 SuggestionsMenuModelForSection(section)->
2621 GetItemKeyForCheckedItem() == kAddNewItemKey; 2694 GetItemKeyForCheckedItem() == kAddNewItemKey;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 model->SetCheckedItem(guid); 2887 model->SetCheckedItem(guid);
2815 if (GetAutofillChoice(section, &guid)) 2888 if (GetAutofillChoice(section, &guid))
2816 model->SetCheckedItem(guid); 2889 model->SetCheckedItem(guid);
2817 } 2890 }
2818 } 2891 }
2819 2892
2820 if (view_) 2893 if (view_)
2821 view_->ModelChanged(); 2894 view_->ModelChanged();
2822 2895
2823 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 2896 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
2824 ResetSectionInput(static_cast<DialogSection>(i)); 2897 DialogSection section = static_cast<DialogSection>(i);
2898 SetEditingExistingData(section, false);
2899 ResetSectionInput(section);
2825 } 2900 }
2826 2901
2827 RestoreUserInputFromSnapshot(snapshot); 2902 RestoreUserInputFromSnapshot(snapshot);
2828 2903
2829 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 2904 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
2830 DialogSection section = static_cast<DialogSection>(i); 2905 DialogSection section = static_cast<DialogSection>(i);
2831 if (!SectionIsActive(section)) 2906 if (!SectionIsActive(section))
2832 continue; 2907 continue;
2833 2908
2834 ShowEditUiIfBadSuggestion(section); 2909 ShowEditUiIfBadSuggestion(section);
2835 UpdateSection(section); 2910 UpdateSection(section);
2836 } 2911 }
2837 2912
2838 UpdateForErrors(); 2913 UpdateForErrors();
2839 } 2914 }
2840 2915
2841 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( 2916 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
2842 DialogSection section, 2917 DialogSection section,
2843 const InputFieldComparator& compare) { 2918 const InputFieldComparator& compare) {
2844 if (!SectionIsActive(section)) 2919 if (!SectionIsActive(section))
2845 return; 2920 return;
2846 2921
2847 const DetailInputs& inputs = RequestedFieldsForSection(section); 2922 DetailInputs inputs;
2923 std::string country_code = CountryCodeForSection(section);
2924 common::BuildInputsForSection(section, country_code, &inputs);
2925
2848 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 2926 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
2849 if (wrapper) { 2927 if (wrapper) {
2850 // Only fill in data that is associated with this section. 2928 // Only fill in data that is associated with this section.
2851 const DetailInputs& inputs = RequestedFieldsForSection(section);
2852 wrapper->FillFormStructure(inputs, compare, &form_structure_); 2929 wrapper->FillFormStructure(inputs, compare, &form_structure_);
2853 2930
2854 // CVC needs special-casing because the CreditCard class doesn't store or 2931 // CVC needs special-casing because the CreditCard class doesn't store or
2855 // handle them. This isn't necessary when filling the combined CC and 2932 // handle them. This isn't necessary when filling the combined CC and
2856 // billing section as CVC comes from |full_wallet_| in this case. 2933 // billing section as CVC comes from |full_wallet_| in this case.
2857 if (section == SECTION_CC) 2934 if (section == SECTION_CC)
2858 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); 2935 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc());
2859 2936
2860 // When filling from Wallet data, use the email address associated with the 2937 // When filling from Wallet data, use the email address associated with the
2861 // account. There is no other email address stored as part of a Wallet 2938 // account. There is no other email address stored as part of a Wallet
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2984 3061
2985 DCHECK_EQ(&model, &suggested_shipping_); 3062 DCHECK_EQ(&model, &suggested_shipping_);
2986 return SECTION_SHIPPING; 3063 return SECTION_SHIPPING;
2987 } 3064 }
2988 3065
2989 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( 3066 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
2990 DialogSection section) { 3067 DialogSection section) {
2991 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); 3068 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
2992 } 3069 }
2993 3070
3071 void AutofillDialogControllerImpl::OnComboboxModelChanged(
3072 ui::ComboboxModel* model) {
3073 DCHECK(model == &billing_country_combobox_model_ ||
3074 model == &shipping_country_combobox_model_);
3075
3076 const bool is_shipping = model == &shipping_country_combobox_model_;
3077 const std::string country_code = AutofillCountry::GetCountryCode(
3078 model->GetItemAt(model->GetDefaultIndex()),
3079 g_browser_process->GetApplicationLocale());
3080
3081 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
3082 DialogSection section = static_cast<DialogSection>(i);
3083
3084 if ((is_shipping && section != SECTION_SHIPPING) ||
Evan Stade 2014/01/15 23:12:29 this is the second place in this CL I've seen so f
Dan Beam 2014/01/16 01:39:13 Done.
3085 (!is_shipping && (section != SECTION_BILLING &&
3086 section != SECTION_CC_BILLING))) {
3087 continue;
3088 }
3089
3090 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
3091 inputs->clear();
3092
3093 common::BuildInputsForSection(section, country_code, inputs);
3094 }
3095 }
3096
3097 std::string AutofillDialogControllerImpl::CountryCodeForSection(
3098 DialogSection section) {
3099 if (section == SECTION_CC)
3100 return "US";
Evan Stade 2014/01/15 23:12:29 ditto -- return "" as it's international.
Dan Beam 2014/01/16 01:39:13 Done.
3101
3102 base::string16 country_name;
3103 if (IsEditingExistingData(section)) {
3104 ServerFieldType type = SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY :
3105 ADDRESS_BILLING_COUNTRY;
3106 return AutofillCountry::GetCountryCode(
3107 CreateWrapper(section)->GetInfo(AutofillType(type)),
3108 g_browser_process->GetApplicationLocale());
3109 }
3110
3111 CountryComboboxModel* model = section == SECTION_SHIPPING ?
Evan Stade 2014/01/15 23:12:29 third place
Dan Beam 2014/01/16 01:39:13 Done.
3112 &shipping_country_combobox_model_ : &billing_country_combobox_model_;
3113 return model->countries()[model->GetDefaultIndex()]->country_code();
3114 }
3115
2994 void AutofillDialogControllerImpl::HidePopup() { 3116 void AutofillDialogControllerImpl::HidePopup() {
2995 if (popup_controller_.get()) 3117 if (popup_controller_.get())
2996 popup_controller_->Hide(); 3118 popup_controller_->Hide();
2997 popup_input_type_ = UNKNOWN_TYPE; 3119 popup_input_type_ = UNKNOWN_TYPE;
2998 } 3120 }
2999 3121
3000 void AutofillDialogControllerImpl::SetEditingExistingData( 3122 void AutofillDialogControllerImpl::SetEditingExistingData(
3001 DialogSection section, bool editing) { 3123 DialogSection section, bool editing) {
3002 if (editing) 3124 if (editing)
3003 section_editing_state_.insert(section); 3125 section_editing_state_.insert(section);
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
3533 view_->UpdateButtonStrip(); 3655 view_->UpdateButtonStrip();
3534 } 3656 }
3535 3657
3536 void AutofillDialogControllerImpl::FetchWalletCookie() { 3658 void AutofillDialogControllerImpl::FetchWalletCookie() {
3537 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 3659 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
3538 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 3660 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
3539 signin_helper_->StartWalletCookieValueFetch(); 3661 signin_helper_->StartWalletCookieValueFetch();
3540 } 3662 }
3541 3663
3542 } // namespace autofill 3664 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698