Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 28 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" | 31 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
| 32 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | |
| 32 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 33 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 33 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 34 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 34 #if !defined(OS_ANDROID) | 35 #if !defined(OS_ANDROID) |
| 35 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" | 36 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" |
| 36 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" | 37 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" |
| 37 #endif | 38 #endif |
| 38 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_finder.h" | 40 #include "chrome/browser/ui/browser_finder.h" |
| 40 #include "chrome/browser/ui/browser_navigator.h" | 41 #include "chrome/browser/ui/browser_navigator.h" |
| 41 #include "chrome/browser/ui/browser_window.h" | 42 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); | 609 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); |
| 609 } | 610 } |
| 610 | 611 |
| 611 // Fail if the author didn't specify autocomplete types. | 612 // Fail if the author didn't specify autocomplete types. |
| 612 if (!has_types) { | 613 if (!has_types) { |
| 613 callback_.Run(NULL); | 614 callback_.Run(NULL); |
| 614 delete this; | 615 delete this; |
| 615 return; | 616 return; |
| 616 } | 617 } |
| 617 | 618 |
| 618 common::BuildInputsForSection(SECTION_CC, | 619 std::string guess = i18ninput::GuessCountry(); |
| 619 &requested_cc_fields_); | 620 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { |
| 620 common::BuildInputsForSection(SECTION_BILLING, | 621 SetCountryCodeForSection(static_cast<DialogSection>(section), guess); |
| 621 &requested_billing_fields_); | 622 } |
| 622 common::BuildInputsForSection(SECTION_CC_BILLING, | |
| 623 &requested_cc_billing_fields_); | |
| 624 common::BuildInputsForSection(SECTION_SHIPPING, | |
| 625 &requested_shipping_fields_); | |
| 626 | 623 |
| 627 // Test whether we need to show the shipping section. If filling that section | 624 // Test whether we need to show the shipping section. If filling that section |
| 628 // would be a no-op, don't show it. | 625 // would be a no-op, don't show it. |
| 629 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); | 626 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); |
| 630 EmptyDataModelWrapper empty_wrapper; | 627 EmptyDataModelWrapper empty_wrapper; |
| 631 cares_about_shipping_ = empty_wrapper.FillFormStructure( | 628 cares_about_shipping_ = empty_wrapper.FillFormStructure( |
| 632 inputs, | 629 inputs, |
| 633 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), | 630 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), |
| 634 &form_structure_); | 631 &form_structure_); |
| 635 | 632 |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 legal_document_link_ranges_.push_back(gfx::Range( | 1092 legal_document_link_ranges_.push_back(gfx::Range( |
| 1096 link_start, link_start + documents[i]->display_name().size())); | 1093 link_start, link_start + documents[i]->display_name().size())); |
| 1097 } | 1094 } |
| 1098 legal_documents_text_ = text; | 1095 legal_documents_text_ = text; |
| 1099 } | 1096 } |
| 1100 | 1097 |
| 1101 void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { | 1098 void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { |
| 1102 SetEditingExistingData(section, false); | 1099 SetEditingExistingData(section, false); |
| 1103 | 1100 |
| 1104 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1101 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1102 std::string country_code = GetCountryCodeForSection(section); | |
| 1105 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { | 1103 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { |
| 1106 it->initial_value = common::GetHardcodedValueForType(it->type); | 1104 it->initial_value = common::GetInitialValueForType(it->type, country_code); |
| 1107 } | 1105 } |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( | 1108 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
| 1111 DialogSection section) { | 1109 DialogSection section) { |
| 1112 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so | 1110 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so |
| 1113 // get the wrapper before this potentially happens below. | 1111 // get the wrapper before this potentially happens below. |
| 1114 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1112 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 1115 | 1113 |
| 1116 // If the chosen item in |model| yields an empty suggestion text, it is | 1114 // If the chosen item in |model| yields an empty suggestion text, it is |
| 1117 // invalid. In this case, show the edit UI and highlight invalid fields. | 1115 // invalid. In this case, show the edit UI and highlight invalid fields. |
| 1118 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1116 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1119 string16 unused, unused2; | 1117 string16 unused, unused2; |
| 1120 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && | 1118 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && |
| 1121 !SuggestionTextForSection(section, &unused, &unused2)) { | 1119 !SuggestionTextForSection(section, &unused, &unused2)) { |
| 1122 SetEditingExistingData(section, true); | 1120 SetEditingExistingData(section, true); |
| 1123 } | 1121 } |
| 1124 | 1122 |
| 1125 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1123 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1126 if (wrapper && IsEditingExistingData(section)) | 1124 if (wrapper && IsEditingExistingData(section)) |
| 1127 wrapper->FillInputs(inputs); | 1125 wrapper->FillInputs(inputs, GetCountryCodeForSection(section)); |
| 1128 } | 1126 } |
| 1129 | 1127 |
| 1130 bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type, | 1128 bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type, |
| 1131 const base::string16& value) { | 1129 const base::string16& value) { |
| 1132 if (value.empty()) | 1130 if (value.empty()) |
| 1133 return false; | 1131 return false; |
| 1134 | 1132 |
| 1135 // If this is a combobox at the default value, don't preserve it. | 1133 // If this is a combobox at the default value, don't preserve it. |
| 1136 ui::ComboboxModel* model = ComboboxModelForAutofillType(type); | 1134 ui::ComboboxModel* model = ComboboxModelForAutofillType(type); |
| 1137 if (model && model->GetItemAt(model->GetDefaultIndex()) == value) | 1135 if (model && model->GetItemAt(model->GetDefaultIndex()) == value) |
| 1138 return false; | 1136 return false; |
| 1139 | 1137 |
| 1140 return true; | 1138 return true; |
| 1141 } | 1139 } |
| 1142 | 1140 |
| 1143 DetailOutputMap AutofillDialogControllerImpl::TakeUserInputSnapshot() { | 1141 UserInputSnapshot AutofillDialogControllerImpl::TakeUserInputSnapshot() { |
| 1144 DetailOutputMap snapshot; | 1142 UserInputSnapshot snapshot; |
| 1145 if (!view_) | 1143 if (!view_) |
| 1146 return snapshot; | 1144 return snapshot; |
| 1147 | 1145 |
| 1148 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 1146 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 1149 DialogSection section = static_cast<DialogSection>(i); | 1147 DialogSection section = static_cast<DialogSection>(i); |
| 1150 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1148 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1151 if (model->GetItemKeyForCheckedItem() != kAddNewItemKey) | 1149 if (model->GetItemKeyForCheckedItem() != kAddNewItemKey) |
| 1152 continue; | 1150 continue; |
| 1153 | 1151 |
| 1154 DetailOutputMap outputs; | 1152 DetailOutputMap outputs; |
| 1155 view_->GetUserInput(section, &outputs); | 1153 view_->GetUserInput(section, &outputs); |
| 1156 // Remove fields that are empty, at their default values, or invalid. | 1154 // Remove fields that are empty, at their default values, or invalid. |
| 1157 for (DetailOutputMap::iterator it = outputs.begin(); it != outputs.end(); | 1155 for (DetailOutputMap::iterator it = outputs.begin(); it != outputs.end(); |
| 1158 ++it) { | 1156 ++it) { |
| 1159 if (InputWasEdited(it->first->type, it->second) && | 1157 if (InputWasEdited(it->first->type, it->second) && |
| 1160 InputValidityMessage(section, it->first->type, it->second).empty()) { | 1158 InputValidityMessage(section, it->first->type, it->second).empty()) { |
| 1161 snapshot.insert(std::make_pair(it->first, it->second)); | 1159 snapshot.insert(std::make_pair(it->first->type, it->second)); |
| 1162 } | 1160 } |
| 1163 } | 1161 } |
| 1164 } | 1162 } |
| 1165 | 1163 |
| 1166 return snapshot; | 1164 return snapshot; |
| 1167 } | 1165 } |
| 1168 | 1166 |
| 1169 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( | 1167 void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( |
| 1170 const DetailOutputMap& snapshot) { | 1168 const UserInputSnapshot& snapshot) { |
| 1171 if (snapshot.empty()) | 1169 if (snapshot.empty()) |
| 1172 return; | 1170 return; |
| 1173 | 1171 |
| 1174 DetailOutputWrapper wrapper(snapshot); | 1172 SnapshotWrapper wrapper(snapshot); |
| 1175 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 1173 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 1176 DialogSection section = static_cast<DialogSection>(i); | 1174 DialogSection section = static_cast<DialogSection>(i); |
| 1177 if (!SectionIsActive(section)) | 1175 if (!SectionIsActive(section)) |
| 1178 continue; | 1176 continue; |
| 1179 | 1177 |
| 1180 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1178 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1181 wrapper.FillInputs(inputs); | 1179 wrapper.FillInputs(inputs, GetCountryCodeForSection(section)); |
| 1182 | 1180 |
| 1183 for (size_t i = 0; i < inputs->size(); ++i) { | 1181 for (size_t i = 0; i < inputs->size(); ++i) { |
| 1184 if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { | 1182 if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { |
| 1185 SuggestionsMenuModelForSection(section)->SetCheckedItem(kAddNewItemKey); | 1183 SuggestionsMenuModelForSection(section)->SetCheckedItem(kAddNewItemKey); |
| 1186 break; | 1184 break; |
| 1187 } | 1185 } |
| 1188 } | 1186 } |
| 1189 } | 1187 } |
| 1190 } | 1188 } |
| 1191 | 1189 |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1693 } | 1691 } |
| 1694 break; | 1692 break; |
| 1695 | 1693 |
| 1696 case ADDRESS_HOME_LINE1: | 1694 case ADDRESS_HOME_LINE1: |
| 1697 break; | 1695 break; |
| 1698 | 1696 |
| 1699 case ADDRESS_HOME_LINE2: | 1697 case ADDRESS_HOME_LINE2: |
| 1700 return base::string16(); // Line 2 is optional - always valid. | 1698 return base::string16(); // Line 2 is optional - always valid. |
| 1701 | 1699 |
| 1702 case ADDRESS_HOME_CITY: | 1700 case ADDRESS_HOME_CITY: |
| 1701 case ADDRESS_HOME_DEPENDENT_LOCALITY: | |
| 1703 case ADDRESS_HOME_COUNTRY: | 1702 case ADDRESS_HOME_COUNTRY: |
| 1704 break; | 1703 break; |
| 1705 | 1704 |
| 1706 case ADDRESS_HOME_STATE: | 1705 case ADDRESS_HOME_STATE: |
| 1707 if (!value.empty() && !autofill::IsValidState(value)) { | 1706 if (!value.empty() && !autofill::IsValidState(value)) { |
| 1708 return l10n_util::GetStringUTF16( | 1707 return l10n_util::GetStringUTF16( |
| 1709 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); | 1708 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); |
| 1710 } | 1709 } |
| 1711 break; | 1710 break; |
| 1712 | 1711 |
| 1713 case ADDRESS_HOME_ZIP: | 1712 case ADDRESS_HOME_ZIP: |
| 1714 if (!value.empty() && !autofill::IsValidZip(value)) { | 1713 if (!value.empty() && !autofill::IsValidZip(value)) { |
| 1715 return l10n_util::GetStringUTF16( | 1714 return l10n_util::GetStringUTF16( |
| 1716 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); | 1715 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); |
| 1717 } | 1716 } |
| 1718 break; | 1717 break; |
| 1719 | 1718 |
| 1719 case ADDRESS_HOME_SORTING_CODE: | |
| 1720 break; | |
| 1721 | |
| 1720 case NAME_FULL: | 1722 case NAME_FULL: |
| 1721 // Wallet requires a first and last billing name. | 1723 // Wallet requires a first and last billing name. |
| 1722 if (section == SECTION_CC_BILLING && !value.empty() && | 1724 if (section == SECTION_CC_BILLING && !value.empty() && |
| 1723 !IsCardHolderNameValidForWallet(value)) { | 1725 !IsCardHolderNameValidForWallet(value)) { |
| 1724 DCHECK(IsPayingWithWallet()); | 1726 DCHECK(IsPayingWithWallet()); |
| 1725 return l10n_util::GetStringUTF16( | 1727 return l10n_util::GetStringUTF16( |
| 1726 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES); | 1728 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES); |
| 1727 } | 1729 } |
| 1728 break; | 1730 break; |
| 1729 | 1731 |
| 1732 case COMPANY_NAME: | |
| 1733 break; | |
| 1734 | |
| 1730 case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section. | 1735 case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section. |
| 1731 break; | 1736 break; |
| 1732 | 1737 |
| 1733 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. | 1738 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. |
| 1734 break; | 1739 break; |
| 1735 | 1740 |
| 1736 default: | 1741 default: |
| 1737 NOTREACHED(); // Trying to validate unknown field. | 1742 NOTREACHED(); // Trying to validate unknown field. |
| 1738 break; | 1743 break; |
| 1739 } | 1744 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1810 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); | 1815 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_CREDIT_CARD_SECURITY_CODE); |
| 1811 } | 1816 } |
| 1812 messages.Set(CREDIT_CARD_VERIFICATION_CODE, ccv_message); | 1817 messages.Set(CREDIT_CARD_VERIFICATION_CODE, ccv_message); |
| 1813 } | 1818 } |
| 1814 | 1819 |
| 1815 // Validate the shipping phone number against the country code of the address. | 1820 // Validate the shipping phone number against the country code of the address. |
| 1816 if (field_values.count(ADDRESS_HOME_COUNTRY) && | 1821 if (field_values.count(ADDRESS_HOME_COUNTRY) && |
| 1817 field_values.count(PHONE_HOME_WHOLE_NUMBER)) { | 1822 field_values.count(PHONE_HOME_WHOLE_NUMBER)) { |
| 1818 i18n::PhoneObject phone_object( | 1823 i18n::PhoneObject phone_object( |
| 1819 field_values[PHONE_HOME_WHOLE_NUMBER], | 1824 field_values[PHONE_HOME_WHOLE_NUMBER], |
| 1820 AutofillCountry::GetCountryCode( | 1825 common::GetCountryCode(field_values[ADDRESS_HOME_COUNTRY])); |
| 1821 field_values[ADDRESS_HOME_COUNTRY], | |
| 1822 g_browser_process->GetApplicationLocale())); | |
| 1823 ValidityMessage phone_message(base::string16(), true); | 1826 ValidityMessage phone_message(base::string16(), true); |
| 1824 if (!phone_object.IsValidNumber()) { | 1827 if (!phone_object.IsValidNumber()) { |
| 1825 phone_message.text = l10n_util::GetStringUTF16( | 1828 phone_message.text = l10n_util::GetStringUTF16( |
| 1826 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_PHONE_NUMBER); | 1829 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_PHONE_NUMBER); |
| 1827 } | 1830 } |
| 1828 messages.Set(PHONE_HOME_WHOLE_NUMBER, phone_message); | 1831 messages.Set(PHONE_HOME_WHOLE_NUMBER, phone_message); |
| 1829 } | 1832 } |
| 1830 | 1833 |
| 1831 // Validate the billing phone number against the country code of the address. | 1834 // Validate the billing phone number against the country code of the address. |
| 1832 if (field_values.count(ADDRESS_BILLING_COUNTRY) && | 1835 if (field_values.count(ADDRESS_BILLING_COUNTRY) && |
| 1833 field_values.count(PHONE_BILLING_WHOLE_NUMBER)) { | 1836 field_values.count(PHONE_BILLING_WHOLE_NUMBER)) { |
| 1834 i18n::PhoneObject phone_object( | 1837 i18n::PhoneObject phone_object( |
| 1835 field_values[PHONE_BILLING_WHOLE_NUMBER], | 1838 field_values[PHONE_BILLING_WHOLE_NUMBER], |
| 1836 AutofillCountry::GetCountryCode( | 1839 common::GetCountryCode(field_values[ADDRESS_BILLING_COUNTRY])); |
| 1837 field_values[ADDRESS_BILLING_COUNTRY], | |
| 1838 g_browser_process->GetApplicationLocale())); | |
| 1839 ValidityMessage phone_message(base::string16(), true); | 1840 ValidityMessage phone_message(base::string16(), true); |
| 1840 if (!phone_object.IsValidNumber()) { | 1841 if (!phone_object.IsValidNumber()) { |
| 1841 phone_message.text = l10n_util::GetStringUTF16( | 1842 phone_message.text = l10n_util::GetStringUTF16( |
| 1842 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_PHONE_NUMBER); | 1843 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_PHONE_NUMBER); |
| 1843 } | 1844 } |
| 1844 messages.Set(PHONE_BILLING_WHOLE_NUMBER, phone_message); | 1845 messages.Set(PHONE_BILLING_WHOLE_NUMBER, phone_message); |
| 1845 } | 1846 } |
| 1846 | 1847 |
| 1847 return messages; | 1848 return messages; |
| 1848 } | 1849 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1916 | 1917 |
| 1917 // |input_showing_popup_| must be set before calling |Show()|. | 1918 // |input_showing_popup_| must be set before calling |Show()|. |
| 1918 input_showing_popup_ = input; | 1919 input_showing_popup_ = input; |
| 1919 | 1920 |
| 1920 popup_controller_->Show(popup_values, | 1921 popup_controller_->Show(popup_values, |
| 1921 popup_labels, | 1922 popup_labels, |
| 1922 popup_icons, | 1923 popup_icons, |
| 1923 popup_ids); | 1924 popup_ids); |
| 1924 } | 1925 } |
| 1925 | 1926 |
| 1927 void AutofillDialogControllerImpl::ComboboxItemSelected( | |
| 1928 ui::ComboboxModel* model, | |
| 1929 DialogSection section, | |
| 1930 int index) { | |
| 1931 if (model != &country_combobox_model_) | |
| 1932 return; | |
| 1933 | |
| 1934 const UserInputSnapshot snapshot = TakeUserInputSnapshot(); | |
| 1935 | |
| 1936 base::string16 country = model->GetItemAt(index); | |
|
Evan Stade
2013/11/25 19:52:06
country_combobox_model_.countries()[index].country
Dan Beam
2013/11/28 02:52:45
Done.
| |
| 1937 SetCountryCodeForSection(section, common::GetCountryCode(country)); | |
| 1938 | |
| 1939 ResetSectionInput(section); | |
| 1940 RestoreUserInputFromSnapshot(snapshot); | |
| 1941 UpdateSection(section); | |
| 1942 } | |
| 1943 | |
| 1926 void AutofillDialogControllerImpl::FocusMoved() { | 1944 void AutofillDialogControllerImpl::FocusMoved() { |
| 1927 HidePopup(); | 1945 HidePopup(); |
| 1928 } | 1946 } |
| 1929 | 1947 |
| 1930 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const { | 1948 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const { |
| 1931 return !input_showing_popup_; | 1949 return !input_showing_popup_; |
| 1932 } | 1950 } |
| 1933 | 1951 |
| 1934 void AutofillDialogControllerImpl::ViewClosed() { | 1952 void AutofillDialogControllerImpl::ViewClosed() { |
| 1935 GetManager()->RemoveObserver(this); | 1953 GetManager()->RemoveObserver(this); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2157 GetManager()->GetCreditCardByGUID(pair.first))); | 2175 GetManager()->GetCreditCardByGUID(pair.first))); |
| 2158 } else { | 2176 } else { |
| 2159 wrapper.reset(new AutofillProfileWrapper( | 2177 wrapper.reset(new AutofillProfileWrapper( |
| 2160 GetManager()->GetProfileByGUID(pair.first), | 2178 GetManager()->GetProfileByGUID(pair.first), |
| 2161 AutofillType(input_showing_popup_->type), | 2179 AutofillType(input_showing_popup_->type), |
| 2162 pair.second)); | 2180 pair.second)); |
| 2163 } | 2181 } |
| 2164 | 2182 |
| 2165 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 2183 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 2166 DialogSection section = static_cast<DialogSection>(i); | 2184 DialogSection section = static_cast<DialogSection>(i); |
| 2167 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); | 2185 wrapper->FillInputs(MutableRequestedFieldsForSection(section), |
| 2186 GetCountryCodeForSection(section)); | |
| 2168 view_->FillSection(section, *input_showing_popup_); | 2187 view_->FillSection(section, *input_showing_popup_); |
| 2169 } | 2188 } |
| 2170 | 2189 |
| 2171 GetMetricLogger().LogDialogPopupEvent( | 2190 GetMetricLogger().LogDialogPopupEvent( |
| 2172 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); | 2191 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); |
| 2173 | 2192 |
| 2174 // TODO(estade): not sure why it's necessary to do this explicitly. | 2193 // TODO(estade): not sure why it's necessary to do this explicitly. |
| 2175 HidePopup(); | 2194 HidePopup(); |
| 2176 } | 2195 } |
| 2177 | 2196 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2433 void AutofillDialogControllerImpl::UpdateAccountChooserView() { | 2452 void AutofillDialogControllerImpl::UpdateAccountChooserView() { |
| 2434 if (view_) { | 2453 if (view_) { |
| 2435 ScopedViewUpdates updates(view_.get()); | 2454 ScopedViewUpdates updates(view_.get()); |
| 2436 view_->UpdateAccountChooser(); | 2455 view_->UpdateAccountChooser(); |
| 2437 view_->UpdateNotificationArea(); | 2456 view_->UpdateNotificationArea(); |
| 2438 } | 2457 } |
| 2439 } | 2458 } |
| 2440 | 2459 |
| 2441 //////////////////////////////////////////////////////////////////////////////// | 2460 //////////////////////////////////////////////////////////////////////////////// |
| 2442 | 2461 |
| 2462 | |
|
Evan Stade
2013/11/25 19:52:06
intentional?
Dan Beam
2013/11/28 02:52:45
nope, removed
| |
| 2443 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( | 2463 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( |
| 2444 const content::NativeWebKeyboardEvent& event) { | 2464 const content::NativeWebKeyboardEvent& event) { |
| 2445 if (popup_controller_.get()) | 2465 if (popup_controller_.get()) |
| 2446 return popup_controller_->HandleKeyPressEvent(event); | 2466 return popup_controller_->HandleKeyPressEvent(event); |
| 2447 | 2467 |
| 2448 return false; | 2468 return false; |
| 2449 } | 2469 } |
| 2450 | 2470 |
| 2451 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { | 2471 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
| 2452 DCHECK_GT(form_structure_.field_count(), 0U); | 2472 DCHECK_GT(form_structure_.field_count(), 0U); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2634 wallet_errors_.clear(); | 2654 wallet_errors_.clear(); |
| 2635 GetWalletClient()->CancelRequests(); | 2655 GetWalletClient()->CancelRequests(); |
| 2636 SetIsSubmitting(false); | 2656 SetIsSubmitting(false); |
| 2637 wallet_error_notification_ = GetWalletError(error_type); | 2657 wallet_error_notification_ = GetWalletError(error_type); |
| 2638 account_chooser_model_.SetHadWalletError(); | 2658 account_chooser_model_.SetHadWalletError(); |
| 2639 } | 2659 } |
| 2640 | 2660 |
| 2641 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2661 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| 2642 ScopedViewUpdates updates(view_.get()); | 2662 ScopedViewUpdates updates(view_.get()); |
| 2643 | 2663 |
| 2644 const DetailOutputMap snapshot = TakeUserInputSnapshot(); | 2664 const UserInputSnapshot snapshot = TakeUserInputSnapshot(); |
| 2645 | 2665 |
| 2646 suggested_cc_.Reset(); | 2666 suggested_cc_.Reset(); |
| 2647 suggested_billing_.Reset(); | 2667 suggested_billing_.Reset(); |
| 2648 suggested_cc_billing_.Reset(); | 2668 suggested_cc_billing_.Reset(); |
| 2649 suggested_shipping_.Reset(); | 2669 suggested_shipping_.Reset(); |
| 2650 HidePopup(); | 2670 HidePopup(); |
| 2651 | 2671 |
| 2652 suggested_shipping_.AddKeyedItem( | 2672 suggested_shipping_.AddKeyedItem( |
| 2653 kSameAsBillingKey, | 2673 kSameAsBillingKey, |
| 2654 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); | 2674 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2734 if (!HasCompleteAndVerifiedData(*cards[i], requested_cc_fields_)) | 2754 if (!HasCompleteAndVerifiedData(*cards[i], requested_cc_fields_)) |
| 2735 continue; | 2755 continue; |
| 2736 | 2756 |
| 2737 suggested_cc_.AddKeyedItemWithIcon( | 2757 suggested_cc_.AddKeyedItemWithIcon( |
| 2738 cards[i]->guid(), | 2758 cards[i]->guid(), |
| 2739 cards[i]->Label(), | 2759 cards[i]->Label(), |
| 2740 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); | 2760 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); |
| 2741 } | 2761 } |
| 2742 | 2762 |
| 2743 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 2763 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
| 2744 const std::string app_locale = g_browser_process->GetApplicationLocale(); | |
| 2745 for (size_t i = 0; i < profiles.size(); ++i) { | 2764 for (size_t i = 0; i < profiles.size(); ++i) { |
| 2746 const AutofillProfile& profile = *profiles[i]; | 2765 const AutofillProfile& profile = *profiles[i]; |
| 2747 if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) || | 2766 if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) || |
| 2748 HasInvalidAddress(*profiles[i])) { | 2767 HasInvalidAddress(*profiles[i])) { |
| 2749 continue; | 2768 continue; |
| 2750 } | 2769 } |
| 2751 | 2770 |
| 2752 // Don't add variants for addresses: name is part of credit card and we'll | 2771 // Don't add variants for addresses: name is part of credit card and we'll |
| 2753 // just ignore email and phone number variants. | 2772 // just ignore email and phone number variants. |
| 2754 suggested_shipping_.AddKeyedItem(profile.guid(), profile.Label()); | 2773 suggested_shipping_.AddKeyedItem(profile.guid(), profile.Label()); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2971 | 2990 |
| 2972 DCHECK_EQ(&model, &suggested_shipping_); | 2991 DCHECK_EQ(&model, &suggested_shipping_); |
| 2973 return SECTION_SHIPPING; | 2992 return SECTION_SHIPPING; |
| 2974 } | 2993 } |
| 2975 | 2994 |
| 2976 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 2995 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| 2977 DialogSection section) { | 2996 DialogSection section) { |
| 2978 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 2997 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 2979 } | 2998 } |
| 2980 | 2999 |
| 3000 std::string AutofillDialogControllerImpl::GetCountryCodeForSection( | |
| 3001 DialogSection section) const { | |
| 3002 if (section == SECTION_BILLING || section == SECTION_CC_BILLING) | |
| 3003 return billing_country_code_; | |
| 3004 if (section == SECTION_SHIPPING) | |
| 3005 return shipping_country_code_; | |
| 3006 return "US"; | |
| 3007 } | |
| 3008 | |
| 3009 void AutofillDialogControllerImpl::SetCountryCodeForSection( | |
| 3010 DialogSection section, | |
| 3011 const std::string& country_code) { | |
| 3012 if (section == SECTION_BILLING || section == SECTION_CC_BILLING) | |
| 3013 billing_country_code_ = country_code; | |
| 3014 else if (section == SECTION_SHIPPING) | |
| 3015 shipping_country_code_ = country_code; | |
| 3016 | |
| 3017 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | |
| 3018 inputs->clear(); | |
| 3019 | |
| 3020 common::BuildInputsForSection(section, inputs, country_code); | |
| 3021 | |
| 3022 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { | |
| 3023 if (AutofillType(it->type).GetStorableType() == ADDRESS_HOME_COUNTRY) | |
| 3024 it->initial_value = common::GetCountryName(country_code); | |
| 3025 } | |
| 3026 } | |
| 3027 | |
| 2981 void AutofillDialogControllerImpl::HidePopup() { | 3028 void AutofillDialogControllerImpl::HidePopup() { |
| 2982 if (popup_controller_.get()) | 3029 if (popup_controller_.get()) |
| 2983 popup_controller_->Hide(); | 3030 popup_controller_->Hide(); |
| 2984 input_showing_popup_ = NULL; | 3031 input_showing_popup_ = NULL; |
| 2985 } | 3032 } |
| 2986 | 3033 |
| 2987 void AutofillDialogControllerImpl::SetEditingExistingData( | 3034 void AutofillDialogControllerImpl::SetEditingExistingData( |
| 2988 DialogSection section, bool editing) { | 3035 DialogSection section, bool editing) { |
| 2989 if (editing) | 3036 if (editing) |
| 2990 section_editing_state_.insert(section); | 3037 section_editing_state_.insert(section); |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3519 view_->UpdateButtonStrip(); | 3566 view_->UpdateButtonStrip(); |
| 3520 } | 3567 } |
| 3521 | 3568 |
| 3522 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3569 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 3523 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3570 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3524 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3571 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3525 signin_helper_->StartWalletCookieValueFetch(); | 3572 signin_helper_->StartWalletCookieValueFetch(); |
| 3526 } | 3573 } |
| 3527 | 3574 |
| 3528 } // namespace autofill | 3575 } // namespace autofill |
| OLD | NEW |