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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX); | 502 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX); |
| 502 | 503 |
| 503 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); | 504 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); |
| 504 } | 505 } |
| 505 | 506 |
| 506 } // namespace | 507 } // namespace |
| 507 | 508 |
| 508 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} | 509 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} |
| 509 | 510 |
| 510 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { | 511 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { |
| 512 billing_country_combobox_model_.RemoveObserver(this); | |
| 513 shipping_country_combobox_model_.RemoveObserver(this); | |
| 514 | |
| 511 if (popup_controller_) | 515 if (popup_controller_) |
| 512 popup_controller_->Hide(); | 516 popup_controller_->Hide(); |
| 513 | 517 |
| 514 GetMetricLogger().LogDialogInitialUserState(initial_user_state_); | 518 GetMetricLogger().LogDialogInitialUserState(initial_user_state_); |
| 515 } | 519 } |
| 516 | 520 |
| 517 // static | 521 // static |
| 518 base::WeakPtr<AutofillDialogControllerImpl> | 522 base::WeakPtr<AutofillDialogControllerImpl> |
| 519 AutofillDialogControllerImpl::Create( | 523 AutofillDialogControllerImpl::Create( |
| 520 content::WebContents* contents, | 524 content::WebContents* contents, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 // access checks. | 600 // access checks. |
| 597 const GURL& current_url = web_contents()->GetLastCommittedURL(); | 601 const GURL& current_url = web_contents()->GetLastCommittedURL(); |
| 598 invoked_from_same_origin_ = | 602 invoked_from_same_origin_ = |
| 599 current_url.GetOrigin() == source_url_.GetOrigin(); | 603 current_url.GetOrigin() == source_url_.GetOrigin(); |
| 600 | 604 |
| 601 if (!invoked_from_same_origin_) { | 605 if (!invoked_from_same_origin_) { |
| 602 GetMetricLogger().LogDialogSecurityMetric( | 606 GetMetricLogger().LogDialogSecurityMetric( |
| 603 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); | 607 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); |
| 604 } | 608 } |
| 605 | 609 |
| 610 // Fail if the author didn't specify autocomplete types. | |
| 611 if (!has_types) { | |
| 612 callback_.Run(NULL); | |
| 613 delete this; | |
| 614 return; | |
| 615 } | |
| 616 | |
| 617 std::string country_code = GetManager()->GetDefaultCountryCodeForNewAddress(); | |
| 606 common::BuildInputsForSection(SECTION_CC, | 618 common::BuildInputsForSection(SECTION_CC, |
| 607 &requested_cc_fields_); | 619 &requested_cc_fields_, |
| 620 country_code); | |
| 608 common::BuildInputsForSection(SECTION_BILLING, | 621 common::BuildInputsForSection(SECTION_BILLING, |
| 609 &requested_billing_fields_); | 622 &requested_billing_fields_, |
| 623 country_code); | |
| 610 common::BuildInputsForSection(SECTION_CC_BILLING, | 624 common::BuildInputsForSection(SECTION_CC_BILLING, |
| 611 &requested_cc_billing_fields_); | 625 &requested_cc_billing_fields_, |
| 626 country_code); | |
| 612 common::BuildInputsForSection(SECTION_SHIPPING, | 627 common::BuildInputsForSection(SECTION_SHIPPING, |
| 613 &requested_shipping_fields_); | 628 &requested_shipping_fields_, |
| 629 country_code); | |
| 614 | 630 |
| 615 // Test whether we need to show the shipping section. If filling that section | 631 // Test whether we need to show the shipping section. If filling that section |
| 616 // would be a no-op, don't show it. | 632 // would be a no-op, don't show it. |
| 617 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); | 633 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); |
| 618 EmptyDataModelWrapper empty_wrapper; | 634 EmptyDataModelWrapper empty_wrapper; |
| 619 cares_about_shipping_ = empty_wrapper.FillFormStructure( | 635 cares_about_shipping_ = empty_wrapper.FillFormStructure( |
| 620 inputs, | 636 inputs, |
| 621 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), | 637 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), |
| 622 &form_structure_); | 638 &form_structure_); |
| 623 | 639 |
| 624 account_chooser_model_.reset( | 640 account_chooser_model_.reset( |
| 625 new AccountChooserModel(this, | 641 new AccountChooserModel(this, |
| 626 profile_, | 642 profile_, |
| 627 !ShouldShowAccountChooser(), | 643 !ShouldShowAccountChooser(), |
| 628 metric_logger_)); | 644 metric_logger_)); |
| 629 | 645 |
| 630 if (account_chooser_model_->WalletIsSelected()) | 646 if (account_chooser_model_->WalletIsSelected()) |
| 631 FetchWalletCookie(); | 647 FetchWalletCookie(); |
| 632 | 648 |
| 633 // TODO(estade): don't show the dialog if the site didn't specify the right | 649 // TODO(estade): don't show the dialog if the site didn't specify the right |
| 634 // fields. First we must figure out what the "right" fields are. | 650 // fields. First we must figure out what the "right" fields are. |
| 635 SuggestionsUpdated(); | 651 SuggestionsUpdated(); |
| 636 SubmitButtonDelayBegin(); | 652 SubmitButtonDelayBegin(); |
| 637 view_.reset(CreateView()); | 653 view_.reset(CreateView()); |
| 638 view_->Show(); | 654 view_->Show(); |
| 655 | |
| 639 GetManager()->AddObserver(this); | 656 GetManager()->AddObserver(this); |
| 657 billing_country_combobox_model_.AddObserver(this); | |
| 658 shipping_country_combobox_model_.AddObserver(this); | |
| 640 | 659 |
| 641 if (!account_chooser_model_->WalletIsSelected()) | 660 if (!account_chooser_model_->WalletIsSelected()) |
| 642 LogDialogLatencyToShow(); | 661 LogDialogLatencyToShow(); |
| 643 } | 662 } |
| 644 | 663 |
| 645 void AutofillDialogControllerImpl::Hide() { | 664 void AutofillDialogControllerImpl::Hide() { |
| 646 if (view_) | 665 if (view_) |
| 647 view_->Hide(); | 666 view_->Hide(); |
| 648 } | 667 } |
| 649 | 668 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1090 legal_document_link_ranges_.push_back(gfx::Range( | 1109 legal_document_link_ranges_.push_back(gfx::Range( |
| 1091 link_start, link_start + documents[i]->display_name().size())); | 1110 link_start, link_start + documents[i]->display_name().size())); |
| 1092 } | 1111 } |
| 1093 legal_documents_text_ = text; | 1112 legal_documents_text_ = text; |
| 1094 } | 1113 } |
| 1095 | 1114 |
| 1096 void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { | 1115 void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { |
| 1097 SetEditingExistingData(section, false); | 1116 SetEditingExistingData(section, false); |
| 1098 | 1117 |
| 1099 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1118 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1119 std::string country_code = GetCountryCodeForSection(section); | |
| 1100 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { | 1120 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { |
| 1101 it->initial_value = common::GetHardcodedValueForType(it->type); | 1121 it->initial_value = common::GetInitialValueForType(it->type, country_code); |
|
Evan Stade
2014/01/02 22:59:26
Isn't the purpose of setting the default index on
| |
| 1102 } | 1122 } |
| 1103 } | 1123 } |
| 1104 | 1124 |
| 1105 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( | 1125 void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
| 1106 DialogSection section) { | 1126 DialogSection section) { |
| 1107 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so | 1127 // |CreateWrapper()| returns an empty wrapper if |IsEditingExistingData()|, so |
| 1108 // get the wrapper before this potentially happens below. | 1128 // get the wrapper before this potentially happens below. |
| 1109 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 1129 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 1110 | 1130 |
| 1111 // If the chosen item in |model| yields an empty suggestion text, it is | 1131 // If the chosen item in |model| yields an empty suggestion text, it is |
| 1112 // invalid. In this case, show the edit UI and highlight invalid fields. | 1132 // invalid. In this case, show the edit UI and highlight invalid fields. |
| 1113 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1133 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1114 base::string16 unused, unused2; | 1134 base::string16 unused, unused2; |
| 1115 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && | 1135 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && |
| 1116 !SuggestionTextForSection(section, &unused, &unused2)) { | 1136 !SuggestionTextForSection(section, &unused, &unused2)) { |
| 1117 SetEditingExistingData(section, true); | 1137 SetEditingExistingData(section, true); |
| 1118 } | 1138 } |
| 1119 | 1139 |
| 1120 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1140 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1121 if (wrapper && IsEditingExistingData(section)) | 1141 if (wrapper && IsEditingExistingData(section)) |
| 1122 wrapper->FillInputs(inputs); | 1142 wrapper->FillInputs(inputs, GetCountryCodeForSection(section)); |
| 1123 } | 1143 } |
| 1124 | 1144 |
| 1125 bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type, | 1145 bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type, |
| 1126 const base::string16& value) { | 1146 const base::string16& value) { |
| 1127 if (value.empty()) | 1147 if (value.empty()) |
| 1128 return false; | 1148 return false; |
| 1129 | 1149 |
| 1130 // If this is a combobox at the default value, don't preserve it. | 1150 // If this is a combobox at the default value, don't preserve it. |
| 1131 ui::ComboboxModel* model = ComboboxModelForAutofillType(type); | 1151 ui::ComboboxModel* model = ComboboxModelForAutofillType(type); |
| 1132 if (model && model->GetItemAt(model->GetDefaultIndex()) == value) | 1152 if (model && model->GetItemAt(model->GetDefaultIndex()) == value) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 if (snapshot.empty()) | 1186 if (snapshot.empty()) |
| 1167 return; | 1187 return; |
| 1168 | 1188 |
| 1169 FieldMapWrapper wrapper(snapshot); | 1189 FieldMapWrapper wrapper(snapshot); |
| 1170 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 1190 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 1171 DialogSection section = static_cast<DialogSection>(i); | 1191 DialogSection section = static_cast<DialogSection>(i); |
| 1172 if (!SectionIsActive(section)) | 1192 if (!SectionIsActive(section)) |
| 1173 continue; | 1193 continue; |
| 1174 | 1194 |
| 1175 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 1195 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 1176 wrapper.FillInputs(inputs); | 1196 wrapper.FillInputs(inputs, GetCountryCodeForSection(section)); |
| 1177 | 1197 |
| 1178 for (size_t i = 0; i < inputs->size(); ++i) { | 1198 for (size_t i = 0; i < inputs->size(); ++i) { |
| 1179 if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { | 1199 if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { |
| 1180 SuggestionsMenuModelForSection(section)->SetCheckedItem(kAddNewItemKey); | 1200 SuggestionsMenuModelForSection(section)->SetCheckedItem(kAddNewItemKey); |
| 1181 break; | 1201 break; |
| 1182 } | 1202 } |
| 1183 } | 1203 } |
| 1184 } | 1204 } |
| 1185 } | 1205 } |
| 1186 | 1206 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1292 | 1312 |
| 1293 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( | 1313 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( |
| 1294 ServerFieldType type) { | 1314 ServerFieldType type) { |
| 1295 switch (type) { | 1315 switch (type) { |
| 1296 case CREDIT_CARD_EXP_MONTH: | 1316 case CREDIT_CARD_EXP_MONTH: |
| 1297 return &cc_exp_month_combobox_model_; | 1317 return &cc_exp_month_combobox_model_; |
| 1298 | 1318 |
| 1299 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 1319 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 1300 return &cc_exp_year_combobox_model_; | 1320 return &cc_exp_year_combobox_model_; |
| 1301 | 1321 |
| 1322 case ADDRESS_BILLING_COUNTRY: | |
| 1323 return &billing_country_combobox_model_; | |
| 1324 | |
| 1302 case ADDRESS_HOME_COUNTRY: | 1325 case ADDRESS_HOME_COUNTRY: |
| 1303 case ADDRESS_BILLING_COUNTRY: | 1326 return &shipping_country_combobox_model_; |
| 1304 return &country_combobox_model_; | |
| 1305 | 1327 |
| 1306 default: | 1328 default: |
| 1307 return NULL; | 1329 return NULL; |
| 1308 } | 1330 } |
| 1309 } | 1331 } |
| 1310 | 1332 |
| 1333 bool AutofillDialogControllerImpl::IsCountryComboboxModel( | |
| 1334 const ui::ComboboxModel* model) const { | |
| 1335 return model == &billing_country_combobox_model_ || | |
| 1336 model == &shipping_country_combobox_model_; | |
| 1337 } | |
| 1338 | |
| 1311 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( | 1339 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
| 1312 DialogSection section) { | 1340 DialogSection section) { |
| 1313 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1341 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 1314 // The shipping section menu is special. It will always show because there is | 1342 // The shipping section menu is special. It will always show because there is |
| 1315 // a choice between "Use billing" and "enter new". | 1343 // a choice between "Use billing" and "enter new". |
| 1316 if (section == SECTION_SHIPPING) | 1344 if (section == SECTION_SHIPPING) |
| 1317 return model; | 1345 return model; |
| 1318 | 1346 |
| 1319 // For other sections, only show a menu if there's at least one suggestion. | 1347 // For other sections, only show a menu if there's at least one suggestion. |
| 1320 for (int i = 0; i < model->GetItemCount(); ++i) { | 1348 for (int i = 0; i < model->GetItemCount(); ++i) { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1688 } | 1716 } |
| 1689 break; | 1717 break; |
| 1690 | 1718 |
| 1691 case ADDRESS_HOME_LINE1: | 1719 case ADDRESS_HOME_LINE1: |
| 1692 break; | 1720 break; |
| 1693 | 1721 |
| 1694 case ADDRESS_HOME_LINE2: | 1722 case ADDRESS_HOME_LINE2: |
| 1695 return base::string16(); // Line 2 is optional - always valid. | 1723 return base::string16(); // Line 2 is optional - always valid. |
| 1696 | 1724 |
| 1697 case ADDRESS_HOME_CITY: | 1725 case ADDRESS_HOME_CITY: |
| 1726 case ADDRESS_HOME_DEPENDENT_LOCALITY: | |
| 1698 case ADDRESS_HOME_COUNTRY: | 1727 case ADDRESS_HOME_COUNTRY: |
| 1699 break; | 1728 break; |
| 1700 | 1729 |
| 1701 case ADDRESS_HOME_STATE: | 1730 case ADDRESS_HOME_STATE: |
| 1702 if (!value.empty() && !autofill::IsValidState(value)) { | 1731 if (!value.empty() && !autofill::IsValidState(value)) { |
| 1703 return l10n_util::GetStringUTF16( | 1732 return l10n_util::GetStringUTF16( |
| 1704 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); | 1733 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); |
| 1705 } | 1734 } |
| 1706 break; | 1735 break; |
| 1707 | 1736 |
| 1708 case ADDRESS_HOME_ZIP: | 1737 case ADDRESS_HOME_ZIP: |
| 1709 if (!value.empty() && !autofill::IsValidZip(value)) { | 1738 if (!value.empty() && !autofill::IsValidZip(value)) { |
| 1710 return l10n_util::GetStringUTF16( | 1739 return l10n_util::GetStringUTF16( |
| 1711 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); | 1740 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); |
| 1712 } | 1741 } |
| 1713 break; | 1742 break; |
| 1714 | 1743 |
| 1744 case ADDRESS_HOME_SORTING_CODE: | |
| 1745 break; | |
| 1746 | |
| 1715 case NAME_FULL: | 1747 case NAME_FULL: |
| 1716 // Wallet requires a first and last billing name. | 1748 // Wallet requires a first and last billing name. |
| 1717 if (section == SECTION_CC_BILLING && !value.empty() && | 1749 if (section == SECTION_CC_BILLING && !value.empty() && |
| 1718 !IsCardHolderNameValidForWallet(value)) { | 1750 !IsCardHolderNameValidForWallet(value)) { |
| 1719 DCHECK(IsPayingWithWallet()); | 1751 DCHECK(IsPayingWithWallet()); |
| 1720 return l10n_util::GetStringUTF16( | 1752 return l10n_util::GetStringUTF16( |
| 1721 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES); | 1753 IDS_AUTOFILL_DIALOG_VALIDATION_WALLET_REQUIRES_TWO_NAMES); |
| 1722 } | 1754 } |
| 1723 break; | 1755 break; |
| 1724 | 1756 |
| 1757 case COMPANY_NAME: | |
| 1758 break; | |
| 1759 | |
| 1725 case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section. | 1760 case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section. |
| 1726 break; | 1761 break; |
| 1727 | 1762 |
| 1728 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. | 1763 case PHONE_BILLING_WHOLE_NUMBER: // Used in billing section. |
| 1729 break; | 1764 break; |
| 1730 | 1765 |
| 1731 default: | 1766 default: |
| 1732 NOTREACHED(); // Trying to validate unknown field. | 1767 NOTREACHED(); // Trying to validate unknown field. |
| 1733 break; | 1768 break; |
| 1734 } | 1769 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1747 for (FieldValueMap::const_iterator iter = inputs.begin(); | 1782 for (FieldValueMap::const_iterator iter = inputs.begin(); |
| 1748 iter != inputs.end(); ++iter) { | 1783 iter != inputs.end(); ++iter) { |
| 1749 const ServerFieldType type = iter->first; | 1784 const ServerFieldType type = iter->first; |
| 1750 | 1785 |
| 1751 base::string16 text = InputValidityMessage(section, type, iter->second); | 1786 base::string16 text = InputValidityMessage(section, type, iter->second); |
| 1752 | 1787 |
| 1753 // Skip empty/unchanged fields in edit mode. Ignore country code as it | 1788 // Skip empty/unchanged fields in edit mode. Ignore country code as it |
| 1754 // always has a value. If the individual field does not have validation | 1789 // always has a value. If the individual field does not have validation |
| 1755 // errors, assume it to be valid unless later proven otherwise. | 1790 // errors, assume it to be valid unless later proven otherwise. |
| 1756 bool sure = InputWasEdited(type, iter->second) || | 1791 bool sure = InputWasEdited(type, iter->second) || |
| 1757 ComboboxModelForAutofillType(type) == &country_combobox_model_; | 1792 IsCountryComboboxModel(ComboboxModelForAutofillType(type)); |
| 1758 | 1793 |
| 1759 // Consider only individually valid fields for inter-field validation. | 1794 // Consider only individually valid fields for inter-field validation. |
| 1760 if (text.empty()) { | 1795 if (text.empty()) { |
| 1761 field_values[type] = iter->second; | 1796 field_values[type] = iter->second; |
| 1762 // If the field is valid but can be invalidated by inter-field validation, | 1797 // If the field is valid but can be invalidated by inter-field validation, |
| 1763 // assume it to be unsure. | 1798 // assume it to be unsure. |
| 1764 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 1799 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
| 1765 type == CREDIT_CARD_EXP_MONTH || | 1800 type == CREDIT_CARD_EXP_MONTH || |
| 1766 type == CREDIT_CARD_VERIFICATION_CODE || | 1801 type == CREDIT_CARD_VERIFICATION_CODE || |
| 1767 type == PHONE_HOME_WHOLE_NUMBER || | 1802 type == PHONE_HOME_WHOLE_NUMBER || |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1920 content_bounds, | 1955 content_bounds, |
| 1921 base::i18n::IsRTL() ? | 1956 base::i18n::IsRTL() ? |
| 1922 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT); | 1957 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT); |
| 1923 popup_controller_->set_hide_on_outside_click(true); | 1958 popup_controller_->set_hide_on_outside_click(true); |
| 1924 popup_controller_->Show(popup_values, | 1959 popup_controller_->Show(popup_values, |
| 1925 popup_labels, | 1960 popup_labels, |
| 1926 popup_icons, | 1961 popup_icons, |
| 1927 popup_ids); | 1962 popup_ids); |
| 1928 } | 1963 } |
| 1929 | 1964 |
| 1965 void AutofillDialogControllerImpl::ComboboxItemSelected(ServerFieldType type, | |
| 1966 int index) { | |
| 1967 ui::ComboboxModel* model = ComboboxModelForAutofillType(type); | |
| 1968 if (IsCountryComboboxModel(model)) | |
|
Evan Stade
2014/01/02 22:59:26
imo avoid the cast by doing:
if (type == ADDRESS_
| |
| 1969 static_cast<CountryComboboxModel*>(model)->SetDefaultIndex(index); | |
|
Evan Stade
2014/01/02 22:59:26
can you call OnComboboxModelChanged from here inst
| |
| 1970 } | |
| 1971 | |
| 1930 void AutofillDialogControllerImpl::FocusMoved() { | 1972 void AutofillDialogControllerImpl::FocusMoved() { |
| 1931 HidePopup(); | 1973 HidePopup(); |
| 1932 } | 1974 } |
| 1933 | 1975 |
| 1934 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const { | 1976 bool AutofillDialogControllerImpl::ShouldShowErrorBubble() const { |
| 1935 return !input_showing_popup_; | 1977 return !input_showing_popup_; |
| 1936 } | 1978 } |
| 1937 | 1979 |
| 1938 void AutofillDialogControllerImpl::ViewClosed() { | 1980 void AutofillDialogControllerImpl::ViewClosed() { |
| 1939 GetManager()->RemoveObserver(this); | 1981 GetManager()->RemoveObserver(this); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2156 GetManager()->GetCreditCardByGUID(pair.first))); | 2198 GetManager()->GetCreditCardByGUID(pair.first))); |
| 2157 } else { | 2199 } else { |
| 2158 wrapper.reset(new AutofillProfileWrapper( | 2200 wrapper.reset(new AutofillProfileWrapper( |
| 2159 GetManager()->GetProfileByGUID(pair.first), | 2201 GetManager()->GetProfileByGUID(pair.first), |
| 2160 AutofillType(input_showing_popup_->type), | 2202 AutofillType(input_showing_popup_->type), |
| 2161 pair.second)); | 2203 pair.second)); |
| 2162 } | 2204 } |
| 2163 | 2205 |
| 2164 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 2206 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 2165 DialogSection section = static_cast<DialogSection>(i); | 2207 DialogSection section = static_cast<DialogSection>(i); |
| 2166 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); | 2208 wrapper->FillInputs(MutableRequestedFieldsForSection(section), |
| 2209 GetCountryCodeForSection(section)); | |
| 2167 view_->FillSection(section, *input_showing_popup_); | 2210 view_->FillSection(section, *input_showing_popup_); |
| 2168 } | 2211 } |
| 2169 | 2212 |
| 2170 GetMetricLogger().LogDialogPopupEvent( | 2213 GetMetricLogger().LogDialogPopupEvent( |
| 2171 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); | 2214 AutofillMetrics::DIALOG_POPUP_FORM_FILLED); |
| 2172 | 2215 |
| 2173 // TODO(estade): not sure why it's necessary to do this explicitly. | 2216 // TODO(estade): not sure why it's necessary to do this explicitly. |
| 2174 HidePopup(); | 2217 HidePopup(); |
| 2175 } | 2218 } |
| 2176 | 2219 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2517 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2560 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 2518 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2561 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 2519 form_structure_(form_structure), | 2562 form_structure_(form_structure), |
| 2520 invoked_from_same_origin_(true), | 2563 invoked_from_same_origin_(true), |
| 2521 source_url_(source_url), | 2564 source_url_(source_url), |
| 2522 callback_(callback), | 2565 callback_(callback), |
| 2523 wallet_client_(profile_->GetRequestContext(), this, source_url), | 2566 wallet_client_(profile_->GetRequestContext(), this, source_url), |
| 2524 wallet_items_requested_(false), | 2567 wallet_items_requested_(false), |
| 2525 handling_use_wallet_link_click_(false), | 2568 handling_use_wallet_link_click_(false), |
| 2526 passive_failed_(false), | 2569 passive_failed_(false), |
| 2527 country_combobox_model_(*GetManager()), | 2570 billing_country_combobox_model_( |
| 2571 GetManager()->GetDefaultCountryCodeForNewAddress()), | |
| 2572 shipping_country_combobox_model_( | |
| 2573 GetManager()->GetDefaultCountryCodeForNewAddress()), | |
| 2528 suggested_cc_(this), | 2574 suggested_cc_(this), |
| 2529 suggested_billing_(this), | 2575 suggested_billing_(this), |
| 2530 suggested_cc_billing_(this), | 2576 suggested_cc_billing_(this), |
| 2531 suggested_shipping_(this), | 2577 suggested_shipping_(this), |
| 2532 cares_about_shipping_(true), | 2578 cares_about_shipping_(true), |
| 2533 input_showing_popup_(NULL), | 2579 input_showing_popup_(NULL), |
| 2534 weak_ptr_factory_(this), | 2580 weak_ptr_factory_(this), |
| 2535 waiting_for_explicit_sign_in_response_(false), | 2581 waiting_for_explicit_sign_in_response_(false), |
| 2536 has_accepted_legal_documents_(false), | 2582 has_accepted_legal_documents_(false), |
| 2537 is_submitting_(false), | 2583 is_submitting_(false), |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2752 suggested_cc_.AddKeyedItemWithIcon( | 2798 suggested_cc_.AddKeyedItemWithIcon( |
| 2753 cards[i]->guid(), | 2799 cards[i]->guid(), |
| 2754 cards[i]->Label(), | 2800 cards[i]->Label(), |
| 2755 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); | 2801 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); |
| 2756 } | 2802 } |
| 2757 | 2803 |
| 2758 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 2804 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
| 2759 std::vector<base::string16> labels; | 2805 std::vector<base::string16> labels; |
| 2760 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); | 2806 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); |
| 2761 DCHECK_EQ(labels.size(), profiles.size()); | 2807 DCHECK_EQ(labels.size(), profiles.size()); |
| 2762 const std::string app_locale = g_browser_process->GetApplicationLocale(); | |
| 2763 for (size_t i = 0; i < profiles.size(); ++i) { | 2808 for (size_t i = 0; i < profiles.size(); ++i) { |
| 2764 const AutofillProfile& profile = *profiles[i]; | 2809 const AutofillProfile& profile = *profiles[i]; |
| 2765 if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) || | 2810 if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) || |
| 2766 HasInvalidAddress(*profiles[i])) { | 2811 HasInvalidAddress(*profiles[i])) { |
| 2767 continue; | 2812 continue; |
| 2768 } | 2813 } |
| 2769 | 2814 |
| 2770 // Don't add variants for addresses: name is part of credit card and we'll | 2815 // Don't add variants for addresses: name is part of credit card and we'll |
| 2771 // just ignore email and phone number variants. | 2816 // just ignore email and phone number variants. |
| 2772 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); | 2817 suggested_shipping_.AddKeyedItem(profile.guid(), labels[i]); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2838 ShowEditUiIfBadSuggestion(section); | 2883 ShowEditUiIfBadSuggestion(section); |
| 2839 UpdateSection(section); | 2884 UpdateSection(section); |
| 2840 } | 2885 } |
| 2841 | 2886 |
| 2842 UpdateForErrors(); | 2887 UpdateForErrors(); |
| 2843 } | 2888 } |
| 2844 | 2889 |
| 2845 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 2890 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| 2846 DialogSection section, | 2891 DialogSection section, |
| 2847 const InputFieldComparator& compare) { | 2892 const InputFieldComparator& compare) { |
| 2848 const DetailInputs& inputs = RequestedFieldsForSection(section); | |
| 2849 | |
| 2850 if (!SectionIsActive(section)) | 2893 if (!SectionIsActive(section)) |
| 2851 return; | 2894 return; |
| 2852 | 2895 |
| 2896 const DetailInputs& inputs = RequestedFieldsForSection(section); | |
| 2853 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 2897 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 2854 if (wrapper) { | 2898 if (wrapper) { |
| 2855 // Only fill in data that is associated with this section. | 2899 // Only fill in data that is associated with this section. |
| 2856 const DetailInputs& inputs = RequestedFieldsForSection(section); | 2900 const DetailInputs& inputs = RequestedFieldsForSection(section); |
| 2857 wrapper->FillFormStructure(inputs, compare, &form_structure_); | 2901 wrapper->FillFormStructure(inputs, compare, &form_structure_); |
| 2858 | 2902 |
| 2859 // CVC needs special-casing because the CreditCard class doesn't store or | 2903 // CVC needs special-casing because the CreditCard class doesn't store or |
| 2860 // handle them. This isn't necessary when filling the combined CC and | 2904 // handle them. This isn't necessary when filling the combined CC and |
| 2861 // billing section as CVC comes from |full_wallet_| in this case. | 2905 // billing section as CVC comes from |full_wallet_| in this case. |
| 2862 if (section == SECTION_CC) | 2906 if (section == SECTION_CC) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2989 | 3033 |
| 2990 DCHECK_EQ(&model, &suggested_shipping_); | 3034 DCHECK_EQ(&model, &suggested_shipping_); |
| 2991 return SECTION_SHIPPING; | 3035 return SECTION_SHIPPING; |
| 2992 } | 3036 } |
| 2993 | 3037 |
| 2994 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 3038 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| 2995 DialogSection section) { | 3039 DialogSection section) { |
| 2996 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 3040 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 2997 } | 3041 } |
| 2998 | 3042 |
| 3043 std::string AutofillDialogControllerImpl::GetCountryCodeForSection( | |
| 3044 DialogSection section) const { | |
| 3045 if (section == SECTION_BILLING || section == SECTION_CC_BILLING) | |
| 3046 return billing_country_combobox_model_.GetDefaultCountryCode(); | |
| 3047 if (section == SECTION_SHIPPING) | |
| 3048 return shipping_country_combobox_model_.GetDefaultCountryCode(); | |
| 3049 return "US"; | |
| 3050 } | |
| 3051 | |
| 3052 void AutofillDialogControllerImpl::OnComboboxModelChanged( | |
| 3053 ui::ComboboxModel* model) { | |
| 3054 DCHECK(IsCountryComboboxModel(model)); | |
| 3055 | |
| 3056 ScopedViewUpdates updates(view_.get()); | |
| 3057 const FieldValueMap snapshot = TakeUserInputSnapshot(); | |
| 3058 | |
| 3059 const bool is_shipping = model == &shipping_country_combobox_model_; | |
| 3060 const std::string country_code = | |
| 3061 static_cast<CountryComboboxModel*>(model)->GetDefaultCountryCode(); | |
| 3062 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | |
| 3063 DialogSection section = static_cast<DialogSection>(i); | |
| 3064 | |
| 3065 if ((is_shipping && section != SECTION_SHIPPING) || | |
| 3066 !(section == SECTION_BILLING || section == SECTION_CC_BILLING)) { | |
| 3067 continue; | |
| 3068 } | |
| 3069 | |
| 3070 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | |
| 3071 inputs->clear(); | |
| 3072 common::BuildInputsForSection(section, inputs, country_code); | |
| 3073 } | |
| 3074 | |
| 3075 RestoreUserInputFromSnapshot(snapshot); | |
| 3076 | |
| 3077 UpdateSection(is_shipping ? SECTION_SHIPPING : | |
| 3078 IsPayingWithWallet() ? SECTION_CC_BILLING : SECTION_BILLING); | |
| 3079 } | |
| 3080 | |
| 2999 void AutofillDialogControllerImpl::HidePopup() { | 3081 void AutofillDialogControllerImpl::HidePopup() { |
| 3000 if (popup_controller_.get()) | 3082 if (popup_controller_.get()) |
| 3001 popup_controller_->Hide(); | 3083 popup_controller_->Hide(); |
| 3002 input_showing_popup_ = NULL; | 3084 input_showing_popup_ = NULL; |
| 3003 } | 3085 } |
| 3004 | 3086 |
| 3005 void AutofillDialogControllerImpl::SetEditingExistingData( | 3087 void AutofillDialogControllerImpl::SetEditingExistingData( |
| 3006 DialogSection section, bool editing) { | 3088 DialogSection section, bool editing) { |
| 3007 if (editing) | 3089 if (editing) |
| 3008 section_editing_state_.insert(section); | 3090 section_editing_state_.insert(section); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3538 view_->UpdateButtonStrip(); | 3620 view_->UpdateButtonStrip(); |
| 3539 } | 3621 } |
| 3540 | 3622 |
| 3541 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3623 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 3542 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3624 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3543 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3625 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3544 signin_helper_->StartWalletCookieValueFetch(); | 3626 signin_helper_->StartWalletCookieValueFetch(); |
| 3545 } | 3627 } |
| 3546 | 3628 |
| 3547 } // namespace autofill | 3629 } // namespace autofill |
| OLD | NEW |