| 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 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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? |
| 608 // instead when the country combobox is visible. http://crbug.com/331544 | 608 common::BuildInputsForSection(SECTION_CC, "US", &requested_cc_fields_); |
| 609 std::string country_code = "US"; | 609 OnCountryComboboxModelChanged(&billing_country_combobox_model_); |
| 610 common::BuildInputsForSection(SECTION_CC, | 610 OnCountryComboboxModelChanged(&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_.AddCountryComboboxObserver(this); |
| 638 shipping_country_combobox_model_.AddCountryComboboxObserver(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 Loading... |
| 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 Loading... |
| 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_.SelectCountry( |
| 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_.SelectCountry( |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 1960 billing_country_combobox_model_.RemoveCountryComboboxObserver(this); |
| 1961 shipping_country_combobox_model_.RemoveCountryComboboxObserver(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 Loading... |
| 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. |
| 2191 base::string16 billing_country; |
| 2192 if (billing_country_combobox_model_.IsDefaultIndexSelected()) |
| 2193 billing_country = wrapper->GetInfo(AutofillType(ADDRESS_BILLING_COUNTRY)); |
| 2194 |
| 2195 base::string16 shipping_country; |
| 2196 if (shipping_country_combobox_model_.IsDefaultIndexSelected()) |
| 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 Loading... |
| 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_.SelectDefaultIndex(); |
| 2304 else if (section == SECTION_BILLING || section == SECTION_CC_BILLING) |
| 2305 billing_country_combobox_model_.SelectDefaultIndex(); |
| 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 Loading... |
| 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 Loading... |
| 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(¶ms); | 2678 chrome::Navigate(¶ms); |
| 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 Loading... |
| 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 Loading... |
| 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::OnCountryComboboxModelChanged( |
| 3072 CountryComboboxModel* 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 = model->GetSelectedCountryCode(); |
| 3078 |
| 3079 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 3080 DialogSection section = static_cast<DialogSection>(i); |
| 3081 |
| 3082 if ((is_shipping && section != SECTION_SHIPPING) || |
| 3083 (!is_shipping && (section != SECTION_BILLING && |
| 3084 section != SECTION_CC_BILLING))) { |
| 3085 continue; |
| 3086 } |
| 3087 |
| 3088 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 3089 inputs->clear(); |
| 3090 |
| 3091 common::BuildInputsForSection(section, country_code, inputs); |
| 3092 } |
| 3093 } |
| 3094 |
| 3095 std::string AutofillDialogControllerImpl::CountryCodeForSection( |
| 3096 DialogSection section) { |
| 3097 if (section == SECTION_CC) |
| 3098 return "US"; |
| 3099 |
| 3100 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 3101 if (wrapper) { |
| 3102 return AutofillCountry::GetCountryCode( |
| 3103 wrapper->GetInfo(AutofillType(section == SECTION_SHIPPING ? |
| 3104 ADDRESS_HOME_COUNTRY : ADDRESS_BILLING_COUNTRY)), |
| 3105 g_browser_process->GetApplicationLocale()); |
| 3106 } |
| 3107 |
| 3108 if (section == SECTION_BILLING || section == SECTION_CC_BILLING) |
| 3109 return billing_country_combobox_model_.GetSelectedCountryCode(); |
| 3110 |
| 3111 DCHECK_EQ(SECTION_SHIPPING, section); |
| 3112 return shipping_country_combobox_model_.GetSelectedCountryCode(); |
| 3113 } |
| 3114 |
| 2994 void AutofillDialogControllerImpl::HidePopup() { | 3115 void AutofillDialogControllerImpl::HidePopup() { |
| 2995 if (popup_controller_.get()) | 3116 if (popup_controller_.get()) |
| 2996 popup_controller_->Hide(); | 3117 popup_controller_->Hide(); |
| 2997 popup_input_type_ = UNKNOWN_TYPE; | 3118 popup_input_type_ = UNKNOWN_TYPE; |
| 2998 } | 3119 } |
| 2999 | 3120 |
| 3000 void AutofillDialogControllerImpl::SetEditingExistingData( | 3121 void AutofillDialogControllerImpl::SetEditingExistingData( |
| 3001 DialogSection section, bool editing) { | 3122 DialogSection section, bool editing) { |
| 3002 if (editing) | 3123 if (editing) |
| 3003 section_editing_state_.insert(section); | 3124 section_editing_state_.insert(section); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3533 view_->UpdateButtonStrip(); | 3654 view_->UpdateButtonStrip(); |
| 3534 } | 3655 } |
| 3535 | 3656 |
| 3536 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3657 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 3537 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3658 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3538 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3659 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3539 signin_helper_->StartWalletCookieValueFetch(); | 3660 signin_helper_->StartWalletCookieValueFetch(); |
| 3540 } | 3661 } |
| 3541 | 3662 |
| 3542 } // namespace autofill | 3663 } // namespace autofill |
| OLD | NEW |