| 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() | |
| 608 // instead when the country combobox is visible. http://crbug.com/331544 | |
| 609 std::string country_code = "US"; | |
| 610 common::BuildInputsForSection(SECTION_CC, | 607 common::BuildInputsForSection(SECTION_CC, |
| 611 country_code, | 608 std::string(), |
| 612 &requested_cc_fields_); | 609 &requested_cc_fields_); |
| 613 common::BuildInputsForSection(SECTION_BILLING, | 610 OnComboboxModelChanged(&billing_country_combobox_model_); |
| 614 country_code, | 611 OnComboboxModelChanged(&shipping_country_combobox_model_); |
| 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 | 612 |
| 623 // Test whether we need to show the shipping section. If filling that section | 613 // Test whether we need to show the shipping section. If filling that section |
| 624 // would be a no-op, don't show it. | 614 // would be a no-op, don't show it. |
| 625 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); | 615 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); |
| 626 cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure( | 616 cares_about_shipping_ = EmptyDataModelWrapper().FillFormStructure( |
| 627 inputs, | 617 inputs, |
| 628 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), | 618 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), |
| 629 &form_structure_); | 619 &form_structure_); |
| 630 | 620 |
| 631 account_chooser_model_.reset( | 621 account_chooser_model_.reset( |
| 632 new AccountChooserModel(this, | 622 new AccountChooserModel(this, |
| 633 profile_, | 623 profile_, |
| 634 !ShouldShowAccountChooser(), | 624 !ShouldShowAccountChooser(), |
| 635 metric_logger_)); | 625 metric_logger_)); |
| 636 | 626 |
| 637 if (account_chooser_model_->WalletIsSelected()) | 627 if (account_chooser_model_->WalletIsSelected()) |
| 638 FetchWalletCookie(); | 628 FetchWalletCookie(); |
| 639 | 629 |
| 640 // TODO(estade): don't show the dialog if the site didn't specify the right | 630 // 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. | 631 // fields. First we must figure out what the "right" fields are. |
| 642 SuggestionsUpdated(); | 632 SuggestionsUpdated(); |
| 643 SubmitButtonDelayBegin(); | 633 SubmitButtonDelayBegin(); |
| 644 view_.reset(CreateView()); | 634 view_.reset(CreateView()); |
| 645 view_->Show(); | 635 view_->Show(); |
| 636 |
| 646 GetManager()->AddObserver(this); | 637 GetManager()->AddObserver(this); |
| 638 observer_.Add(&billing_country_combobox_model_); |
| 639 observer_.Add(&shipping_country_combobox_model_); |
| 647 | 640 |
| 648 if (!account_chooser_model_->WalletIsSelected()) | 641 if (!account_chooser_model_->WalletIsSelected()) |
| 649 LogDialogLatencyToShow(); | 642 LogDialogLatencyToShow(); |
| 650 } | 643 } |
| 651 | 644 |
| 652 void AutofillDialogControllerImpl::Hide() { | 645 void AutofillDialogControllerImpl::Hide() { |
| 653 if (view_) | 646 if (view_) |
| 654 view_->Hide(); | 647 view_->Hide(); |
| 655 } | 648 } |
| 656 | 649 |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 } | 1156 } |
| 1164 | 1157 |
| 1165 return snapshot; | 1158 return snapshot; |
| 1166 } | 1159 } |
| 1167 | 1160 |
| 1168 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( | 1161 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( |
| 1169 const FieldValueMap& snapshot) { | 1162 const FieldValueMap& snapshot) { |
| 1170 if (snapshot.empty()) | 1163 if (snapshot.empty()) |
| 1171 return; | 1164 return; |
| 1172 | 1165 |
| 1166 FieldValueMap::const_iterator it = snapshot.find(ADDRESS_BILLING_COUNTRY); |
| 1167 if (it != snapshot.end()) { |
| 1168 billing_country_combobox_model_.SetDefaultCountry( |
| 1169 AutofillCountry::GetCountryCode( |
| 1170 it->second, g_browser_process->GetApplicationLocale())); |
| 1171 } |
| 1172 |
| 1173 FieldValueMap::const_iterator ship_it = snapshot.find(ADDRESS_HOME_COUNTRY); |
| 1174 if (ship_it != snapshot.end()) { |
| 1175 shipping_country_combobox_model_.SetDefaultCountry( |
| 1176 AutofillCountry::GetCountryCode( |
| 1177 ship_it->second, g_browser_process->GetApplicationLocale())); |
| 1178 } |
| 1179 |
| 1173 FieldMapWrapper wrapper(snapshot); | 1180 FieldMapWrapper wrapper(snapshot); |
| 1174 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 1181 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 1175 DialogSection section = static_cast<DialogSection>(i); | 1182 DialogSection section = static_cast<DialogSection>(i); |
| 1176 if (!SectionIsActive(section)) | 1183 if (!SectionIsActive(section)) |
| 1177 continue; | 1184 continue; |
| 1178 | 1185 |
| 1179 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1186 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1180 wrapper.FillInputs(inputs); | 1187 wrapper.FillInputs(inputs); |
| 1181 | 1188 |
| 1182 for (size_t i = 0; i < inputs->size(); ++i) { | 1189 for (size_t i = 0; i < inputs->size(); ++i) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 | 1303 |
| 1297 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( | 1304 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( |
| 1298 ServerFieldType type) { | 1305 ServerFieldType type) { |
| 1299 switch (type) { | 1306 switch (type) { |
| 1300 case CREDIT_CARD_EXP_MONTH: | 1307 case CREDIT_CARD_EXP_MONTH: |
| 1301 return &cc_exp_month_combobox_model_; | 1308 return &cc_exp_month_combobox_model_; |
| 1302 | 1309 |
| 1303 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 1310 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 1304 return &cc_exp_year_combobox_model_; | 1311 return &cc_exp_year_combobox_model_; |
| 1305 | 1312 |
| 1313 case ADDRESS_BILLING_COUNTRY: |
| 1314 return &billing_country_combobox_model_; |
| 1315 |
| 1306 case ADDRESS_HOME_COUNTRY: | 1316 case ADDRESS_HOME_COUNTRY: |
| 1307 case ADDRESS_BILLING_COUNTRY: | 1317 return &shipping_country_combobox_model_; |
| 1308 return &country_combobox_model_; | |
| 1309 | 1318 |
| 1310 default: | 1319 default: |
| 1311 return NULL; | 1320 return NULL; |
| 1312 } | 1321 } |
| 1313 } | 1322 } |
| 1314 | 1323 |
| 1315 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( | 1324 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
| 1316 DialogSection section) { | 1325 DialogSection section) { |
| 1317 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1326 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1318 // The shipping section menu is special. It will always show because there is | 1327 // 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 } | 1701 } |
| 1693 break; | 1702 break; |
| 1694 | 1703 |
| 1695 case ADDRESS_HOME_LINE1: | 1704 case ADDRESS_HOME_LINE1: |
| 1696 break; | 1705 break; |
| 1697 | 1706 |
| 1698 case ADDRESS_HOME_LINE2: | 1707 case ADDRESS_HOME_LINE2: |
| 1699 return base::string16(); // Line 2 is optional - always valid. | 1708 return base::string16(); // Line 2 is optional - always valid. |
| 1700 | 1709 |
| 1701 case ADDRESS_HOME_CITY: | 1710 case ADDRESS_HOME_CITY: |
| 1711 case ADDRESS_HOME_DEPENDENT_LOCALITY: |
| 1702 case ADDRESS_HOME_COUNTRY: | 1712 case ADDRESS_HOME_COUNTRY: |
| 1703 break; | 1713 break; |
| 1704 | 1714 |
| 1705 case ADDRESS_HOME_STATE: | 1715 case ADDRESS_HOME_STATE: |
| 1706 if (!value.empty() && !autofill::IsValidState(value)) { | 1716 if (!value.empty() && !autofill::IsValidState(value) && |
| 1717 CountryCodeForSection(section) == "US") { |
| 1707 return l10n_util::GetStringUTF16( | 1718 return l10n_util::GetStringUTF16( |
| 1708 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); | 1719 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); |
| 1709 } | 1720 } |
| 1710 break; | 1721 break; |
| 1711 | 1722 |
| 1712 case ADDRESS_HOME_ZIP: | 1723 case ADDRESS_HOME_ZIP: |
| 1713 if (!value.empty() && !autofill::IsValidZip(value)) { | 1724 if (!value.empty() && !autofill::IsValidZip(value) && |
| 1725 CountryCodeForSection(section) == "US") { |
| 1714 return l10n_util::GetStringUTF16( | 1726 return l10n_util::GetStringUTF16( |
| 1715 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); | 1727 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); |
| 1716 } | 1728 } |
| 1717 break; | 1729 break; |
| 1718 | 1730 |
| 1731 case ADDRESS_HOME_SORTING_CODE: |
| 1732 break; |
| 1733 |
| 1719 case NAME_FULL: | 1734 case NAME_FULL: |
| 1720 // Wallet requires a first and last billing name. | 1735 // Wallet requires a first and last billing name. |
| 1721 if (section == SECTION_CC_BILLING && !value.empty() && | 1736 if (section == SECTION_CC_BILLING && !value.empty() && |
| 1722 !IsCardHolderNameValidForWallet(value)) { | 1737 !IsCardHolderNameValidForWallet(value)) { |
| 1723 DCHECK(IsPayingWithWallet()); | 1738 DCHECK(IsPayingWithWallet()); |
| 1724 return l10n_util::GetStringUTF16( | 1739 return l10n_util::GetStringUTF16( |
| 1725 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES); | 1740 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES); |
| 1726 } | 1741 } |
| 1727 break; | 1742 break; |
| 1728 | 1743 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1740 return value.empty() ? | 1755 return value.empty() ? |
| 1741 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : | 1756 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : |
| 1742 base::string16(); | 1757 base::string16(); |
| 1743 } | 1758 } |
| 1744 | 1759 |
| 1745 // TODO(groby): Also add tests. | 1760 // TODO(groby): Also add tests. |
| 1746 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( | 1761 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| 1747 DialogSection section, | 1762 DialogSection section, |
| 1748 const FieldValueMap& inputs) { | 1763 const FieldValueMap& inputs) { |
| 1749 ValidityMessages messages; | 1764 ValidityMessages messages; |
| 1750 std::map<ServerFieldType, base::string16> field_values; | 1765 FieldValueMap field_values; |
| 1751 for (FieldValueMap::const_iterator iter = inputs.begin(); | 1766 for (FieldValueMap::const_iterator iter = inputs.begin(); |
| 1752 iter != inputs.end(); ++iter) { | 1767 iter != inputs.end(); ++iter) { |
| 1753 const ServerFieldType type = iter->first; | 1768 const ServerFieldType type = iter->first; |
| 1754 | 1769 |
| 1755 base::string16 text = InputValidityMessage(section, type, iter->second); | 1770 base::string16 text = InputValidityMessage(section, type, iter->second); |
| 1756 | 1771 |
| 1757 // Skip empty/unchanged fields in edit mode. Ignore country code as it | 1772 // 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 | 1773 // a value. If the individual field does not have validation errors, assume |
| 1759 // errors, assume it to be valid unless later proven otherwise. | 1774 // it to be valid unless later proven otherwise. |
| 1760 bool sure = InputWasEdited(type, iter->second) || | 1775 bool sure = InputWasEdited(type, iter->second) || |
| 1761 ComboboxModelForAutofillType(type) == &country_combobox_model_; | 1776 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY; |
| 1762 | 1777 |
| 1763 // Consider only individually valid fields for inter-field validation. | 1778 // Consider only individually valid fields for inter-field validation. |
| 1764 if (text.empty()) { | 1779 if (text.empty()) { |
| 1765 field_values[type] = iter->second; | 1780 field_values[type] = iter->second; |
| 1766 // If the field is valid but can be invalidated by inter-field validation, | 1781 // If the field is valid but can be invalidated by inter-field validation, |
| 1767 // assume it to be unsure. | 1782 // assume it to be unsure. |
| 1768 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 1783 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
| 1769 type == CREDIT_CARD_EXP_MONTH || | 1784 type == CREDIT_CARD_EXP_MONTH || |
| 1770 type == CREDIT_CARD_VERIFICATION_CODE || | 1785 type == CREDIT_CARD_VERIFICATION_CODE || |
| 1771 type == PHONE_HOME_WHOLE_NUMBER || | 1786 type == PHONE_HOME_WHOLE_NUMBER || |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 return messages; | 1861 return messages; |
| 1847 } | 1862 } |
| 1848 | 1863 |
| 1849 void AutofillDialogControllerImpl::UserEditedOrActivatedInput( | 1864 void AutofillDialogControllerImpl::UserEditedOrActivatedInput( |
| 1850 DialogSection section, | 1865 DialogSection section, |
| 1851 ServerFieldType type, | 1866 ServerFieldType type, |
| 1852 gfx::NativeView parent_view, | 1867 gfx::NativeView parent_view, |
| 1853 const gfx::Rect& content_bounds, | 1868 const gfx::Rect& content_bounds, |
| 1854 const base::string16& field_contents, | 1869 const base::string16& field_contents, |
| 1855 bool was_edit) { | 1870 bool was_edit) { |
| 1871 ScopedViewUpdates updates(view_.get()); |
| 1872 |
| 1873 if (type == ADDRESS_BILLING_COUNTRY || type == ADDRESS_HOME_COUNTRY) { |
| 1874 FieldValueMap snapshot = TakeUserInputSnapshot(); |
| 1875 snapshot[type] = field_contents; |
| 1876 RestoreUserInputFromSnapshot(snapshot); |
| 1877 const bool is_billing = type == ADDRESS_BILLING_COUNTRY; |
| 1878 UpdateSection(is_billing ? ActiveBillingSection() : SECTION_SHIPPING); |
| 1879 } |
| 1880 |
| 1881 // The rest of this method applies only to textfields. If a combobox, bail. |
| 1882 if (ComboboxModelForAutofillType(type)) |
| 1883 return; |
| 1884 |
| 1856 // If the field is edited down to empty, don't show a popup. | 1885 // If the field is edited down to empty, don't show a popup. |
| 1857 if (was_edit && field_contents.empty()) { | 1886 if (was_edit && field_contents.empty()) { |
| 1858 HidePopup(); | 1887 HidePopup(); |
| 1859 return; | 1888 return; |
| 1860 } | 1889 } |
| 1861 | 1890 |
| 1862 // If the user clicks while the popup is already showing, be sure to hide | 1891 // If the user clicks while the popup is already showing, be sure to hide |
| 1863 // it. | 1892 // it. |
| 1864 if (!was_edit && popup_controller_.get()) { | 1893 if (!was_edit && popup_controller_.get()) { |
| 1865 HidePopup(); | 1894 HidePopup(); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 if (common::IsCreditCardType(popup_input_type_)) { | 2180 if (common::IsCreditCardType(popup_input_type_)) { |
| 2152 wrapper.reset(new AutofillCreditCardWrapper( | 2181 wrapper.reset(new AutofillCreditCardWrapper( |
| 2153 GetManager()->GetCreditCardByGUID(pair.first))); | 2182 GetManager()->GetCreditCardByGUID(pair.first))); |
| 2154 } else { | 2183 } else { |
| 2155 wrapper.reset(new AutofillProfileWrapper( | 2184 wrapper.reset(new AutofillProfileWrapper( |
| 2156 GetManager()->GetProfileByGUID(pair.first), | 2185 GetManager()->GetProfileByGUID(pair.first), |
| 2157 AutofillType(popup_input_type_), | 2186 AutofillType(popup_input_type_), |
| 2158 pair.second)); | 2187 pair.second)); |
| 2159 } | 2188 } |
| 2160 | 2189 |
| 2190 if (i18ninput::Enabled()) { |
| 2191 base::string16 billing_country = |
| 2192 wrapper->GetInfo(AutofillType(ADDRESS_BILLING_COUNTRY)); |
| 2193 base::string16 shipping_country = |
| 2194 wrapper->GetInfo(AutofillType(ADDRESS_HOME_COUNTRY)); |
| 2195 |
| 2196 if (!billing_country.empty() || !shipping_country.empty()) { |
| 2197 FieldValueMap snapshot = TakeUserInputSnapshot(); |
| 2198 if (!billing_country.empty()) |
| 2199 snapshot[ADDRESS_BILLING_COUNTRY] = billing_country; |
| 2200 if (!shipping_country.empty()) |
| 2201 snapshot[ADDRESS_HOME_COUNTRY] = shipping_country; |
| 2202 |
| 2203 RestoreUserInputFromSnapshot(snapshot); |
| 2204 |
| 2205 if (!billing_country.empty()) |
| 2206 UpdateSection(ActiveBillingSection()); |
| 2207 if (!shipping_country.empty()) |
| 2208 UpdateSection(SECTION_SHIPPING); |
| 2209 } |
| 2210 } |
| 2211 |
| 2161 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 2212 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 2162 DialogSection section = static_cast<DialogSection>(i); | 2213 DialogSection section = static_cast<DialogSection>(i); |
| 2163 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); | 2214 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); |
| 2164 view_->FillSection(section, popup_input_type_); | 2215 view_->FillSection(section, popup_input_type_); |
| 2165 } | 2216 } |
| 2166 | 2217 |
| 2167 GetMetricLogger().LogDialogPopupEvent( | 2218 GetMetricLogger().LogDialogPopupEvent( |
| 2168 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); | 2219 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); |
| 2169 | 2220 |
| 2170 // TODO(estade): not sure why it's necessary to do this explicitly. | 2221 // TODO(estade): not sure why it's necessary to do this explicitly. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2231 wallet::GetManageAddressesUrl(user_index) : | 2282 wallet::GetManageAddressesUrl(user_index) : |
| 2232 wallet::GetManageInstrumentsUrl(user_index); | 2283 wallet::GetManageInstrumentsUrl(user_index); |
| 2233 } | 2284 } |
| 2234 | 2285 |
| 2235 OpenTabWithUrl(url); | 2286 OpenTabWithUrl(url); |
| 2236 return; | 2287 return; |
| 2237 } | 2288 } |
| 2238 | 2289 |
| 2239 model->SetCheckedIndex(index); | 2290 model->SetCheckedIndex(index); |
| 2240 DialogSection section = SectionForSuggestionsMenuModel(*model); | 2291 DialogSection section = SectionForSuggestionsMenuModel(*model); |
| 2292 |
| 2293 if (i18ninput::Enabled()) |
| 2294 CountryComboboxModelForSection(section)->ResetDefault(); |
| 2295 |
| 2241 ResetSectionInput(section); | 2296 ResetSectionInput(section); |
| 2242 ShowEditUiIfBadSuggestion(section); | 2297 ShowEditUiIfBadSuggestion(section); |
| 2243 UpdateSection(section); | 2298 UpdateSection(section); |
| 2244 view_->UpdateNotificationArea(); | 2299 view_->UpdateNotificationArea(); |
| 2245 UpdateForErrors(); | 2300 UpdateForErrors(); |
| 2246 | 2301 |
| 2247 LogSuggestionItemSelectedMetric(*model); | 2302 LogSuggestionItemSelectedMetric(*model); |
| 2248 } | 2303 } |
| 2249 | 2304 |
| 2250 //////////////////////////////////////////////////////////////////////////////// | 2305 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2514 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2569 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 2515 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2570 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 2516 form_structure_(form_structure), | 2571 form_structure_(form_structure), |
| 2517 invoked_from_same_origin_(true), | 2572 invoked_from_same_origin_(true), |
| 2518 source_url_(source_url), | 2573 source_url_(source_url), |
| 2519 callback_(callback), | 2574 callback_(callback), |
| 2520 wallet_client_(profile_->GetRequestContext(), this, source_url), | 2575 wallet_client_(profile_->GetRequestContext(), this, source_url), |
| 2521 wallet_items_requested_(false), | 2576 wallet_items_requested_(false), |
| 2522 handling_use_wallet_link_click_(false), | 2577 handling_use_wallet_link_click_(false), |
| 2523 passive_failed_(false), | 2578 passive_failed_(false), |
| 2524 country_combobox_model_(*GetManager()), | 2579 billing_country_combobox_model_(*GetManager()), |
| 2580 shipping_country_combobox_model_(*GetManager()), |
| 2525 suggested_cc_(this), | 2581 suggested_cc_(this), |
| 2526 suggested_billing_(this), | 2582 suggested_billing_(this), |
| 2527 suggested_cc_billing_(this), | 2583 suggested_cc_billing_(this), |
| 2528 suggested_shipping_(this), | 2584 suggested_shipping_(this), |
| 2529 cares_about_shipping_(true), | 2585 cares_about_shipping_(true), |
| 2530 popup_input_type_(UNKNOWN_TYPE), | 2586 popup_input_type_(UNKNOWN_TYPE), |
| 2531 weak_ptr_factory_(this), | 2587 weak_ptr_factory_(this), |
| 2532 waiting_for_explicit_sign_in_response_(false), | 2588 waiting_for_explicit_sign_in_response_(false), |
| 2533 has_accepted_legal_documents_(false), | 2589 has_accepted_legal_documents_(false), |
| 2534 is_submitting_(false), | 2590 is_submitting_(false), |
| 2535 choose_another_instrument_or_address_(false), | 2591 choose_another_instrument_or_address_(false), |
| 2536 wallet_server_validation_recoverable_(true), | 2592 wallet_server_validation_recoverable_(true), |
| 2537 data_was_passed_back_(false), | 2593 data_was_passed_back_(false), |
| 2538 was_ui_latency_logged_(false), | 2594 was_ui_latency_logged_(false), |
| 2539 card_generated_animation_(2000, 60, this) { | 2595 card_generated_animation_(2000, 60, this), |
| 2596 observer_(this) { |
| 2540 // TODO(estade): remove duplicates from |form_structure|? | 2597 // TODO(estade): remove duplicates from |form_structure|? |
| 2541 DCHECK(!callback_.is_null()); | 2598 DCHECK(!callback_.is_null()); |
| 2542 } | 2599 } |
| 2543 | 2600 |
| 2544 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { | 2601 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
| 2545 return AutofillDialogView::Create(this); | 2602 return AutofillDialogView::Create(this); |
| 2546 } | 2603 } |
| 2547 | 2604 |
| 2548 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { | 2605 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { |
| 2549 return PersonalDataManagerFactory::GetForProfile(profile_); | 2606 return PersonalDataManagerFactory::GetForProfile(profile_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2602 | 2659 |
| 2603 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { | 2660 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { |
| 2604 chrome::NavigateParams params( | 2661 chrome::NavigateParams params( |
| 2605 chrome::FindBrowserWithWebContents(web_contents()), | 2662 chrome::FindBrowserWithWebContents(web_contents()), |
| 2606 url, | 2663 url, |
| 2607 content::PAGE_TRANSITION_LINK); | 2664 content::PAGE_TRANSITION_LINK); |
| 2608 params.disposition = NEW_FOREGROUND_TAB; | 2665 params.disposition = NEW_FOREGROUND_TAB; |
| 2609 chrome::Navigate(¶ms); | 2666 chrome::Navigate(¶ms); |
| 2610 } | 2667 } |
| 2611 | 2668 |
| 2669 DialogSection AutofillDialogControllerImpl::ActiveBillingSection() const { |
| 2670 return IsPayingWithWallet() ? SECTION_CC_BILLING : SECTION_BILLING; |
| 2671 } |
| 2672 |
| 2612 bool AutofillDialogControllerImpl::IsEditingExistingData( | 2673 bool AutofillDialogControllerImpl::IsEditingExistingData( |
| 2613 DialogSection section) const { | 2674 DialogSection section) const { |
| 2614 return section_editing_state_.count(section) > 0; | 2675 return section_editing_state_.count(section) > 0; |
| 2615 } | 2676 } |
| 2616 | 2677 |
| 2617 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2678 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
| 2618 DialogSection section) const { | 2679 DialogSection section) const { |
| 2619 return IsEditingExistingData(section) || | 2680 return IsEditingExistingData(section) || |
| 2620 SuggestionsMenuModelForSection(section)-> | 2681 SuggestionsMenuModelForSection(section)-> |
| 2621 GetItemKeyForCheckedItem() == kAddNewItemKey; | 2682 GetItemKeyForCheckedItem() == kAddNewItemKey; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2837 | 2898 |
| 2838 UpdateForErrors(); | 2899 UpdateForErrors(); |
| 2839 } | 2900 } |
| 2840 | 2901 |
| 2841 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 2902 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| 2842 DialogSection section, | 2903 DialogSection section, |
| 2843 const InputFieldComparator& compare) { | 2904 const InputFieldComparator& compare) { |
| 2844 if (!SectionIsActive(section)) | 2905 if (!SectionIsActive(section)) |
| 2845 return; | 2906 return; |
| 2846 | 2907 |
| 2847 const DetailInputs& inputs = RequestedFieldsForSection(section); | 2908 DetailInputs inputs; |
| 2909 std::string country_code = CountryCodeForSection(section); |
| 2910 common::BuildInputsForSection(section, country_code, &inputs); |
| 2911 |
| 2848 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 2912 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 2849 if (wrapper) { | 2913 if (wrapper) { |
| 2850 // Only fill in data that is associated with this section. | 2914 // Only fill in data that is associated with this section. |
| 2851 const DetailInputs& inputs = RequestedFieldsForSection(section); | |
| 2852 wrapper->FillFormStructure(inputs, compare, &form_structure_); | 2915 wrapper->FillFormStructure(inputs, compare, &form_structure_); |
| 2853 | 2916 |
| 2854 // CVC needs special-casing because the CreditCard class doesn't store or | 2917 // 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 | 2918 // handle them. This isn't necessary when filling the combined CC and |
| 2856 // billing section as CVC comes from |full_wallet_| in this case. | 2919 // billing section as CVC comes from |full_wallet_| in this case. |
| 2857 if (section == SECTION_CC) | 2920 if (section == SECTION_CC) |
| 2858 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); | 2921 SetOutputForFieldsOfType(CREDIT_CARD_VERIFICATION_CODE, view_->GetCvc()); |
| 2859 | 2922 |
| 2860 // When filling from Wallet data, use the email address associated with the | 2923 // 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 | 2924 // account. There is no other email address stored as part of a Wallet |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2979 if (&model == &suggested_billing_) | 3042 if (&model == &suggested_billing_) |
| 2980 return SECTION_BILLING; | 3043 return SECTION_BILLING; |
| 2981 | 3044 |
| 2982 if (&model == &suggested_cc_billing_) | 3045 if (&model == &suggested_cc_billing_) |
| 2983 return SECTION_CC_BILLING; | 3046 return SECTION_CC_BILLING; |
| 2984 | 3047 |
| 2985 DCHECK_EQ(&model, &suggested_shipping_); | 3048 DCHECK_EQ(&model, &suggested_shipping_); |
| 2986 return SECTION_SHIPPING; | 3049 return SECTION_SHIPPING; |
| 2987 } | 3050 } |
| 2988 | 3051 |
| 3052 CountryComboboxModel* AutofillDialogControllerImpl:: |
| 3053 CountryComboboxModelForSection(DialogSection section) { |
| 3054 switch (section) { |
| 3055 case SECTION_CC: |
| 3056 return NULL; |
| 3057 case SECTION_BILLING: |
| 3058 case SECTION_CC_BILLING: |
| 3059 return &billing_country_combobox_model_; |
| 3060 case SECTION_SHIPPING: |
| 3061 return &shipping_country_combobox_model_; |
| 3062 } |
| 3063 |
| 3064 NOTREACHED(); |
| 3065 return NULL; |
| 3066 } |
| 3067 |
| 2989 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 3068 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| 2990 DialogSection section) { | 3069 DialogSection section) { |
| 2991 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 3070 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 2992 } | 3071 } |
| 2993 | 3072 |
| 3073 void AutofillDialogControllerImpl::OnComboboxModelChanged( |
| 3074 ui::ComboboxModel* model) { |
| 3075 DCHECK(model == &billing_country_combobox_model_ || |
| 3076 model == &shipping_country_combobox_model_); |
| 3077 |
| 3078 const std::string country_code = AutofillCountry::GetCountryCode( |
| 3079 model->GetItemAt(model->GetDefaultIndex()), |
| 3080 g_browser_process->GetApplicationLocale()); |
| 3081 |
| 3082 const bool is_billing = model == &billing_country_combobox_model_; |
| 3083 DialogSection section = is_billing ? SECTION_BILLING : SECTION_SHIPPING; |
| 3084 |
| 3085 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 3086 inputs->clear(); |
| 3087 common::BuildInputsForSection(section, country_code, inputs); |
| 3088 |
| 3089 if (is_billing) { |
| 3090 // Also rebuild inputs for the combined credit card + billing section. |
| 3091 DetailInputs* inputs = MutableRequestedFieldsForSection(SECTION_CC_BILLING); |
| 3092 inputs->clear(); |
| 3093 common::BuildInputsForSection(SECTION_CC_BILLING, country_code, inputs); |
| 3094 } |
| 3095 } |
| 3096 |
| 3097 std::string AutofillDialogControllerImpl::CountryCodeForSection( |
| 3098 DialogSection section) { |
| 3099 if (section == SECTION_CC) |
| 3100 return std::string(); |
| 3101 |
| 3102 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 3103 if (wrapper) { |
| 3104 ServerFieldType type = section == SECTION_SHIPPING ? |
| 3105 ADDRESS_HOME_COUNTRY : ADDRESS_BILLING_COUNTRY; |
| 3106 return AutofillCountry::GetCountryCode( |
| 3107 wrapper->GetInfo(AutofillType(type)), |
| 3108 g_browser_process->GetApplicationLocale()); |
| 3109 } |
| 3110 |
| 3111 CountryComboboxModel* model = CountryComboboxModelForSection(section); |
| 3112 return model->countries()[model->GetDefaultIndex()]->country_code(); |
| 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 |