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

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

Issue 145553009: rAc: use libaddressinput to validate international addresses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "apps/shell_window.h" 11 #include "apps/shell_window.h"
12 #include "apps/shell_window_registry.h" 12 #include "apps/shell_window_registry.h"
13 #include "apps/ui/native_app_window.h" 13 #include "apps/ui/native_app_window.h"
14 #include "base/base64.h" 14 #include "base/base64.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/files/file_path.h"
16 #include "base/i18n/case_conversion.h" 17 #include "base/i18n/case_conversion.h"
17 #include "base/i18n/rtl.h" 18 #include "base/i18n/rtl.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/prefs/pref_filter.h"
19 #include "base/prefs/pref_registry_simple.h" 21 #include "base/prefs/pref_registry_simple.h"
20 #include "base/prefs/pref_service.h" 22 #include "base/prefs/pref_service.h"
21 #include "base/prefs/scoped_user_pref_update.h" 23 #include "base/prefs/scoped_user_pref_update.h"
22 #include "base/rand_util.h" 24 #include "base/rand_util.h"
23 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_split.h" 26 #include "base/strings/string_split.h"
25 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
27 #include "base/time/time.h" 29 #include "base/time/time.h"
30 #include "chrome/browser/autofill/address_storage_factory.h"
28 #include "chrome/browser/autofill/personal_data_manager_factory.h" 31 #include "chrome/browser/autofill/personal_data_manager_factory.h"
29 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" 34 #include "chrome/browser/ui/autofill/autofill_dialog_common.h"
32 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" 35 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h"
33 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 36 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
34 #include "chrome/browser/ui/autofill/data_model_wrapper.h" 37 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
35 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" 38 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h"
36 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" 39 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h"
37 #include "chrome/browser/ui/browser.h" 40 #include "chrome/browser/ui/browser.h"
38 #include "chrome/browser/ui/browser_finder.h" 41 #include "chrome/browser/ui/browser_finder.h"
39 #include "chrome/browser/ui/browser_navigator.h" 42 #include "chrome/browser/ui/browser_navigator.h"
40 #include "chrome/browser/ui/browser_window.h" 43 #include "chrome/browser/ui/browser_window.h"
44 #include "chrome/common/chrome_constants.h"
41 #include "chrome/common/chrome_version_info.h" 45 #include "chrome/common/chrome_version_info.h"
42 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
43 #include "chrome/common/render_messages.h" 47 #include "chrome/common/render_messages.h"
44 #include "chrome/common/url_constants.h" 48 #include "chrome/common/url_constants.h"
45 #include "components/autofill/content/browser/risk/fingerprint.h" 49 #include "components/autofill/content/browser/risk/fingerprint.h"
46 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" 50 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
47 #include "components/autofill/content/browser/wallet/form_field_error.h" 51 #include "components/autofill/content/browser/wallet/form_field_error.h"
48 #include "components/autofill/content/browser/wallet/full_wallet.h" 52 #include "components/autofill/content/browser/wallet/full_wallet.h"
49 #include "components/autofill/content/browser/wallet/gaia_account.h" 53 #include "components/autofill/content/browser/wallet/gaia_account.h"
50 #include "components/autofill/content/browser/wallet/instrument.h" 54 #include "components/autofill/content/browser/wallet/instrument.h"
(...skipping 21 matching lines...) Expand all
72 #include "content/public/browser/web_contents.h" 76 #include "content/public/browser/web_contents.h"
73 #include "content/public/browser/web_contents_view.h" 77 #include "content/public/browser/web_contents_view.h"
74 #include "content/public/common/url_constants.h" 78 #include "content/public/common/url_constants.h"
75 #include "grit/chromium_strings.h" 79 #include "grit/chromium_strings.h"
76 #include "grit/component_strings.h" 80 #include "grit/component_strings.h"
77 #include "grit/generated_resources.h" 81 #include "grit/generated_resources.h"
78 #include "grit/platform_locale_settings.h" 82 #include "grit/platform_locale_settings.h"
79 #include "grit/theme_resources.h" 83 #include "grit/theme_resources.h"
80 #include "grit/webkit_resources.h" 84 #include "grit/webkit_resources.h"
81 #include "net/cert/cert_status_flags.h" 85 #include "net/cert/cert_status_flags.h"
86 #include "third_party/libaddressinput/chromium/chrome_downloader_impl.h"
87 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h"
88 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_problem.h"
82 #include "ui/base/base_window.h" 89 #include "ui/base/base_window.h"
83 #include "ui/base/l10n/l10n_util.h" 90 #include "ui/base/l10n/l10n_util.h"
84 #include "ui/base/models/combobox_model.h" 91 #include "ui/base/models/combobox_model.h"
85 #include "ui/base/resource/resource_bundle.h" 92 #include "ui/base/resource/resource_bundle.h"
86 #include "ui/events/event.h" 93 #include "ui/events/event.h"
87 #include "ui/gfx/canvas.h" 94 #include "ui/gfx/canvas.h"
88 #include "ui/gfx/image/image_skia_operations.h" 95 #include "ui/gfx/image/image_skia_operations.h"
89 #include "ui/gfx/skia_util.h" 96 #include "ui/gfx/skia_util.h"
90 97
98 using ::i18n::addressinput::AddressData;
99 using ::i18n::addressinput::AddressProblem;
100 using ::i18n::addressinput::AddressProblemFilter;
101 using ::i18n::addressinput::AddressProblems;
102 using ::i18n::addressinput::AddressValidator;
103
91 namespace autofill { 104 namespace autofill {
92 105
93 namespace { 106 namespace {
94 107
95 const char kAddNewItemKey[] = "add-new-item"; 108 const char kAddNewItemKey[] = "add-new-item";
96 const char kManageItemsKey[] = "manage-items"; 109 const char kManageItemsKey[] = "manage-items";
97 const char kSameAsBillingKey[] = "same-as-billing"; 110 const char kSameAsBillingKey[] = "same-as-billing";
98 111
99 // URLs for Wallet error messages. 112 // URLs for Wallet error messages.
100 const char kBuyerLegalAddressStatusUrl[] = 113 const char kBuyerLegalAddressStatusUrl[] =
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 486 }
474 487
475 gfx::Image CvcIconForCreditCardType(const base::string16& credit_card_type) { 488 gfx::Image CvcIconForCreditCardType(const base::string16& credit_card_type) {
476 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 489 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
477 if (credit_card_type == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX)) 490 if (credit_card_type == l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX))
478 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX); 491 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX);
479 492
480 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); 493 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
481 } 494 }
482 495
483 ServerFieldType CountryTypeForSection(DialogSection section) { 496 ServerFieldType TypeForSection(DialogSection section, ServerFieldType type) {
484 return section == SECTION_SHIPPING ? ADDRESS_HOME_COUNTRY : 497 return section == SECTION_SHIPPING ?
485 ADDRESS_BILLING_COUNTRY; 498 AutofillType(type).GetStorableType() :
499 AutofillType::GetEquivalentBillingFieldType(type);
486 } 500 }
487 501
488 } // namespace 502 } // namespace
489 503
490 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} 504 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {}
491 505
492 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { 506 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
493 if (popup_controller_) 507 if (popup_controller_)
494 popup_controller_->Hide(); 508 popup_controller_->Hide();
495 509
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 // 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
1101 // 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.
1102 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 1116 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
1103 base::string16 unused, unused2; 1117 base::string16 unused, unused2;
1104 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && 1118 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) &&
1105 !SuggestionTextForSection(section, &unused, &unused2)) { 1119 !SuggestionTextForSection(section, &unused, &unused2)) {
1106 SetEditingExistingData(section, true); 1120 SetEditingExistingData(section, true);
1107 } 1121 }
1108 1122
1109 if (wrapper && IsEditingExistingData(section)) { 1123 if (wrapper && IsEditingExistingData(section)) {
1110 base::string16 country = 1124 base::string16 country = wrapper->GetInfo(AutofillType(
1111 wrapper->GetInfo(AutofillType(CountryTypeForSection(section))); 1125 TypeForSection(section, ADDRESS_HOME_COUNTRY)));
1112 if (!country.empty()) { 1126 if (!country.empty()) {
1113 // There's no user input to restore here as this is only called after 1127 // There's no user input to restore here as this is only called after
1114 // resetting all section input. 1128 // resetting all section input.
1115 if (RebuildInputsForCountry(section, country, false)) 1129 if (RebuildInputsForCountry(section, country, false))
1116 UpdateSection(section); 1130 UpdateSection(section);
1117 } 1131 }
1118 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); 1132 wrapper->FillInputs(MutableRequestedFieldsForSection(section));
1119 } 1133 }
1120 } 1134 }
1121 1135
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 case ADDRESS_HOME_LINE2: 1707 case ADDRESS_HOME_LINE2:
1694 case ADDRESS_HOME_DEPENDENT_LOCALITY: 1708 case ADDRESS_HOME_DEPENDENT_LOCALITY:
1695 case ADDRESS_HOME_SORTING_CODE: 1709 case ADDRESS_HOME_SORTING_CODE:
1696 return base::string16(); // Optional until we have better validation. 1710 return base::string16(); // Optional until we have better validation.
1697 1711
1698 case ADDRESS_HOME_CITY: 1712 case ADDRESS_HOME_CITY:
1699 case ADDRESS_HOME_COUNTRY: 1713 case ADDRESS_HOME_COUNTRY:
1700 break; 1714 break;
1701 1715
1702 case ADDRESS_HOME_STATE: 1716 case ADDRESS_HOME_STATE:
1703 if (!value.empty() && !autofill::IsValidState(value) && 1717 if (!i18ninput::Enabled() && !value.empty() &&
1718 !autofill::IsValidState(value) &&
1704 CountryCodeForSection(section) == "US") { 1719 CountryCodeForSection(section) == "US") {
1705 return l10n_util::GetStringUTF16( 1720 return l10n_util::GetStringUTF16(
1706 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION); 1721 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION);
1707 } 1722 }
1708 break; 1723 break;
1709 1724
1710 case ADDRESS_HOME_ZIP: 1725 case ADDRESS_HOME_ZIP:
1711 if (!value.empty() && !autofill::IsValidZip(value) && 1726 if (!i18ninput::Enabled() && !value.empty() &&
1727 !autofill::IsValidZip(value) &&
1712 CountryCodeForSection(section) == "US") { 1728 CountryCodeForSection(section) == "US") {
1713 return l10n_util::GetStringUTF16( 1729 return l10n_util::GetStringUTF16(
1714 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE); 1730 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE);
1715 } 1731 }
1716 break; 1732 break;
1717 1733
1718 case NAME_FULL: 1734 case NAME_FULL:
1719 // Wallet requires a first and last billing name. 1735 // Wallet requires a first and last billing name.
1720 if (section == SECTION_CC_BILLING && !value.empty() && 1736 if (section == SECTION_CC_BILLING && !value.empty() &&
1721 !IsCardHolderNameValidForWallet(value)) { 1737 !IsCardHolderNameValidForWallet(value)) {
(...skipping 18 matching lines...) Expand all
1740 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) : 1756 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VALIDATION_MISSING_VALUE) :
1741 base::string16(); 1757 base::string16();
1742 } 1758 }
1743 1759
1744 // TODO(groby): Also add tests. 1760 // TODO(groby): Also add tests.
1745 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( 1761 ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
1746 DialogSection section, 1762 DialogSection section,
1747 const FieldValueMap& inputs) { 1763 const FieldValueMap& inputs) {
1748 ValidityMessages messages; 1764 ValidityMessages messages;
1749 FieldValueMap field_values; 1765 FieldValueMap field_values;
1766
1767 if (section != SECTION_CC) {
1768 FieldValueMap values = inputs;
1769
1770 AddressData address_data;
1771 address_data.language_code = g_browser_process->GetApplicationLocale();
1772 address_data.country_code = AutofillCountry::GetCountryCode(
1773 values[TypeForSection(section, ADDRESS_HOME_COUNTRY)],
1774 g_browser_process->GetApplicationLocale());
1775 address_data.administrative_area = UTF16ToUTF8(
1776 values[TypeForSection(section, ADDRESS_HOME_STATE)]);
1777 address_data.locality = UTF16ToUTF8(
1778 values[TypeForSection(section, ADDRESS_HOME_CITY)]);
1779 address_data.dependent_locality = UTF16ToUTF8(
1780 values[TypeForSection(section, ADDRESS_HOME_DEPENDENT_LOCALITY)]);
1781 address_data.sorting_code = UTF16ToUTF8(
1782 values[TypeForSection(section, ADDRESS_HOME_SORTING_CODE)]);
1783 address_data.postal_code = UTF16ToUTF8(
1784 values[TypeForSection(section, ADDRESS_HOME_ZIP)]);
1785 address_data.recipient = UTF16ToUTF8(
1786 values[TypeForSection(section, NAME_FULL)]);
1787
1788 base::string16 street_line1 =
1789 values[TypeForSection(section, ADDRESS_HOME_LINE1)];
1790 if (!street_line1.empty())
1791 address_data.address_lines.push_back(UTF16ToUTF8(street_line1));
1792
1793 base::string16 street_line2 =
1794 values[TypeForSection(section, ADDRESS_HOME_LINE2)];
1795 if (!street_line2.empty())
1796 address_data.address_lines.push_back(UTF16ToUTF8(street_line2));
1797
1798 AddressProblems problems;
1799 AddressValidator::Status status = validator_->ValidateAddress(
1800 address_data, AddressProblemFilter(), &problems);
1801 if (status == AddressValidator::SUCCESS) {
1802 common::AddressType address_type = section == SECTION_SHIPPING ?
1803 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING;
1804 for (size_t i = 0; i < problems.size(); ++i) {
1805 const AddressProblem& problem = problems[i];
1806 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD;
1807 base::string16 text = l10n_util::GetStringUTF16(problem.description_id);
1808 messages.Set(i18ninput::TypeForField(problem.field, address_type),
1809 ValidityMessage(text, sure));
1810 }
1811 }
1812 }
1813
1750 for (FieldValueMap::const_iterator iter = inputs.begin(); 1814 for (FieldValueMap::const_iterator iter = inputs.begin();
1751 iter != inputs.end(); ++iter) { 1815 iter != inputs.end(); ++iter) {
1752 const ServerFieldType type = iter->first; 1816 const ServerFieldType type = iter->first;
1817 if (messages.HasSureError(type))
1818 continue;
1753 1819
1754 base::string16 text = InputValidityMessage(section, type, iter->second); 1820 base::string16 text = InputValidityMessage(section, type, iter->second);
1755 1821
1756 // Skip empty/unchanged fields in edit mode. Ignore country as it always has 1822 // Skip empty/unchanged fields in edit mode. Ignore country as it always has
1757 // a value. If the individual field does not have validation errors, assume 1823 // a value. If the individual field does not have validation errors, assume
1758 // it to be valid unless later proven otherwise. 1824 // it to be valid unless later proven otherwise.
1759 bool sure = InputWasEdited(type, iter->second) || 1825 bool sure = InputWasEdited(type, iter->second) ||
1760 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY; 1826 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY;
1761 1827
1762 // Consider only individually valid fields for inter-field validation. 1828 // Consider only individually valid fields for inter-field validation.
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 handling_use_wallet_link_click_(false), 2639 handling_use_wallet_link_click_(false),
2574 passive_failed_(false), 2640 passive_failed_(false),
2575 billing_country_combobox_model_(*GetManager()), 2641 billing_country_combobox_model_(*GetManager()),
2576 shipping_country_combobox_model_(*GetManager()), 2642 shipping_country_combobox_model_(*GetManager()),
2577 suggested_cc_(this), 2643 suggested_cc_(this),
2578 suggested_billing_(this), 2644 suggested_billing_(this),
2579 suggested_cc_billing_(this), 2645 suggested_cc_billing_(this),
2580 suggested_shipping_(this), 2646 suggested_shipping_(this),
2581 cares_about_shipping_(true), 2647 cares_about_shipping_(true),
2582 popup_input_type_(UNKNOWN_TYPE), 2648 popup_input_type_(UNKNOWN_TYPE),
2583 weak_ptr_factory_(this),
2584 waiting_for_explicit_sign_in_response_(false), 2649 waiting_for_explicit_sign_in_response_(false),
2585 has_accepted_legal_documents_(false), 2650 has_accepted_legal_documents_(false),
2586 is_submitting_(false), 2651 is_submitting_(false),
2587 choose_another_instrument_or_address_(false), 2652 choose_another_instrument_or_address_(false),
2588 wallet_server_validation_recoverable_(true), 2653 wallet_server_validation_recoverable_(true),
2589 data_was_passed_back_(false), 2654 data_was_passed_back_(false),
2590 was_ui_latency_logged_(false), 2655 was_ui_latency_logged_(false),
2591 card_generated_animation_(2000, 60, this) { 2656 card_generated_animation_(2000, 60, this),
2657 weak_ptr_factory_(this) {
2592 // TODO(estade): remove duplicates from |form_structure|? 2658 // TODO(estade): remove duplicates from |form_structure|?
2593 DCHECK(!callback_.is_null()); 2659 DCHECK(!callback_.is_null());
2660
2661 scoped_ptr<autofill::ChromeDownloaderImpl> downloader(
Evan Stade 2014/01/27 23:11:15 change this type then you don't have to PassAs (I
Dan Beam 2014/01/28 02:22:36 Done.
2662 new autofill::ChromeDownloaderImpl(profile_->GetRequestContext()));
2663 validator_ = AddressValidator::Build(
2664 downloader.PassAs< ::i18n::addressinput::Downloader>(),
2665 AddressStorageFactory::CreateStorage(),
2666 this);
2667
2668 validator_->LoadRules(
2669 billing_country_combobox_model_.GetDefaultCountryCode());
Evan Stade 2014/01/27 23:11:15 I think you could just make this: validator_->Loa
Dan Beam 2014/01/28 02:22:36 Done.
2670 validator_->LoadRules(
2671 shipping_country_combobox_model_.GetDefaultCountryCode());
2594 } 2672 }
2595 2673
2596 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { 2674 AutofillDialogView* AutofillDialogControllerImpl::CreateView() {
2597 return AutofillDialogView::Create(this); 2675 return AutofillDialogView::Create(this);
2598 } 2676 }
2599 2677
2600 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const { 2678 PersonalDataManager* AutofillDialogControllerImpl::GetManager() const {
2601 return PersonalDataManagerFactory::GetForProfile(profile_); 2679 return PersonalDataManagerFactory::GetForProfile(profile_);
2602 } 2680 }
2603 2681
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
3068 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( 3146 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
3069 DialogSection section) { 3147 DialogSection section) {
3070 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); 3148 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
3071 } 3149 }
3072 3150
3073 std::string AutofillDialogControllerImpl::CountryCodeForSection( 3151 std::string AutofillDialogControllerImpl::CountryCodeForSection(
3074 DialogSection section) { 3152 DialogSection section) {
3075 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 3153 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
3076 if (wrapper) { 3154 if (wrapper) {
3077 return AutofillCountry::GetCountryCode( 3155 return AutofillCountry::GetCountryCode(
3078 wrapper->GetInfo(AutofillType(CountryTypeForSection(section))), 3156 wrapper->GetInfo(
3157 AutofillType(TypeForSection(section, ADDRESS_HOME_COUNTRY))),
3079 g_browser_process->GetApplicationLocale()); 3158 g_browser_process->GetApplicationLocale());
3080 } 3159 }
3081 3160
3082 CountryComboboxModel* model = CountryComboboxModelForSection(section); 3161 CountryComboboxModel* model = CountryComboboxModelForSection(section);
3083 return model ? model->GetDefaultCountryCode() : std::string(); 3162 return model ? model->GetDefaultCountryCode() : std::string();
3084 } 3163 }
3085 3164
3086 bool AutofillDialogControllerImpl::RebuildInputsForCountry( 3165 bool AutofillDialogControllerImpl::RebuildInputsForCountry(
3087 DialogSection section, 3166 DialogSection section,
3088 const base::string16& country_name, 3167 const base::string16& country_name,
3089 bool should_clobber) { 3168 bool should_clobber) {
3090 DCHECK_NE(SECTION_CC, section); 3169 DCHECK_NE(SECTION_CC, section);
3091 3170
3092 if (view_ && !should_clobber) { 3171 if (view_ && !should_clobber) {
3093 FieldValueMap outputs; 3172 FieldValueMap outputs;
3094 view_->GetUserInput(section, &outputs); 3173 view_->GetUserInput(section, &outputs);
3095 3174
3096 // If |country_name| is the same as the view, no-op and let the caller know. 3175 // If |country_name| is the same as the view, no-op and let the caller know.
3097 if (outputs[CountryTypeForSection(section)] == country_name) 3176 if (outputs[TypeForSection(section, ADDRESS_HOME_COUNTRY)] == country_name)
3098 return false; 3177 return false;
3099 } 3178 }
3100 3179
3101 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 3180 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
3102 inputs->clear(); 3181 inputs->clear();
3103 3182
3104 std::string country_code = AutofillCountry::GetCountryCode( 3183 std::string country_code = AutofillCountry::GetCountryCode(
3105 country_name, g_browser_process->GetApplicationLocale()); 3184 country_name, g_browser_process->GetApplicationLocale());
3106 common::BuildInputsForSection(section, country_code, inputs); 3185 common::BuildInputsForSection(section, country_code, inputs);
3107 return true; 3186 return true;
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 DCHECK_EQ(animation, &card_generated_animation_); 3469 DCHECK_EQ(animation, &card_generated_animation_);
3391 PushOverlayUpdate(); 3470 PushOverlayUpdate();
3392 } 3471 }
3393 3472
3394 void AutofillDialogControllerImpl::AnimationEnded( 3473 void AutofillDialogControllerImpl::AnimationEnded(
3395 const gfx::Animation* animation) { 3474 const gfx::Animation* animation) {
3396 DCHECK_EQ(animation, &card_generated_animation_); 3475 DCHECK_EQ(animation, &card_generated_animation_);
3397 DoFinishSubmit(); 3476 DoFinishSubmit();
3398 } 3477 }
3399 3478
3479 void AutofillDialogControllerImpl::OnAddressValidationRulesLoaded(
3480 const std::string& country_code,
3481 bool success) {
3482 // TODO(dbeam): ask |view_| to re-validate its contents if necessary.
3483 }
3484
3400 void AutofillDialogControllerImpl::DoFinishSubmit() { 3485 void AutofillDialogControllerImpl::DoFinishSubmit() {
3401 FillOutputForSection(SECTION_CC); 3486 FillOutputForSection(SECTION_CC);
3402 FillOutputForSection(SECTION_BILLING); 3487 FillOutputForSection(SECTION_BILLING);
3403 FillOutputForSection(SECTION_CC_BILLING); 3488 FillOutputForSection(SECTION_CC_BILLING);
3404 3489
3405 if (ShouldUseBillingForShipping()) { 3490 if (ShouldUseBillingForShipping()) {
3406 FillOutputForSectionWithComparator( 3491 FillOutputForSectionWithComparator(
3407 SECTION_BILLING, 3492 SECTION_BILLING,
3408 base::Bind(ServerTypeMatchesShippingField)); 3493 base::Bind(ServerTypeMatchesShippingField));
3409 FillOutputForSectionWithComparator( 3494 FillOutputForSectionWithComparator(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3647 view_->UpdateButtonStrip(); 3732 view_->UpdateButtonStrip();
3648 } 3733 }
3649 3734
3650 void AutofillDialogControllerImpl::FetchWalletCookie() { 3735 void AutofillDialogControllerImpl::FetchWalletCookie() {
3651 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); 3736 net::URLRequestContextGetter* request_context = profile_->GetRequestContext();
3652 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); 3737 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context));
3653 signin_helper_->StartWalletCookieValueFetch(); 3738 signin_helper_->StartWalletCookieValueFetch();
3654 } 3739 }
3655 3740
3656 } // namespace autofill 3741 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698