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

Side by Side Diff: chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc

Issue 2951743002: Merge-60[Payments] Make state combobox def. value work with state abbrv. (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/views/payments/shipping_address_editor_view_controll er.h" 5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
15 #include "chrome/browser/ui/views/payments/validating_combobox.h" 15 #include "chrome/browser/ui/views/payments/validating_combobox.h"
16 #include "chrome/browser/ui/views/payments/validating_textfield.h" 16 #include "chrome/browser/ui/views/payments/validating_textfield.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "components/autofill/core/browser/autofill_address_util.h" 18 #include "components/autofill/core/browser/autofill_address_util.h"
19 #include "components/autofill/core/browser/autofill_country.h" 19 #include "components/autofill/core/browser/autofill_country.h"
20 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
21 #include "components/autofill/core/browser/country_combobox_model.h" 21 #include "components/autofill/core/browser/country_combobox_model.h"
22 #include "components/autofill/core/browser/field_types.h" 22 #include "components/autofill/core/browser/field_types.h"
23 #include "components/autofill/core/browser/personal_data_manager.h" 23 #include "components/autofill/core/browser/personal_data_manager.h"
24 #include "components/autofill/core/browser/region_combobox_model.h"
25 #include "components/autofill/core/browser/validation.h" 24 #include "components/autofill/core/browser/validation.h"
26 #include "components/autofill/core/common/autofill_constants.h" 25 #include "components/autofill/core/common/autofill_constants.h"
26 #include "components/autofill/core/common/autofill_l10n_util.h"
27 #include "components/payments/content/payment_request_state.h" 27 #include "components/payments/content/payment_request_state.h"
28 #include "components/payments/core/payment_request_data_util.h" 28 #include "components/payments/core/payment_request_data_util.h"
29 #include "components/payments/core/payments_profile_comparator.h" 29 #include "components/payments/core/payments_profile_comparator.h"
30 #include "components/strings/grit/components_strings.h" 30 #include "components/strings/grit/components_strings.h"
31 #include "third_party/libaddressinput/messages.h" 31 #include "third_party/libaddressinput/messages.h"
32 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/views/controls/textfield/textfield.h" 33 #include "ui/views/controls/textfield/textfield.h"
34 34
35 namespace payments { 35 namespace payments {
36 36
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 state()->GetApplicationLocale()); 77 state()->GetApplicationLocale());
78 78
79 if (!profile_to_edit_) 79 if (!profile_to_edit_)
80 return base::string16(); 80 return base::string16();
81 81
82 if (type == autofill::PHONE_HOME_WHOLE_NUMBER) { 82 if (type == autofill::PHONE_HOME_WHOLE_NUMBER) {
83 return data_util::GetFormattedPhoneNumberForDisplay( 83 return data_util::GetFormattedPhoneNumberForDisplay(
84 *profile_to_edit_, state()->GetApplicationLocale()); 84 *profile_to_edit_, state()->GetApplicationLocale());
85 } 85 }
86 86
87 if (type == autofill::ADDRESS_HOME_STATE) {
88 // For the state, check if the inital value matches either a region code or
89 // a region name.
90 base::string16 initial_region = profile_to_edit_->GetInfo(
91 autofill::AutofillType(type), state()->GetApplicationLocale());
92 autofill::l10n::CaseInsensitiveCompare compare;
93
94 for (const auto& region : region_model_->GetRegions()) {
95 base::string16 region_name = base::UTF8ToUTF16(region.second);
96 if (compare.StringsEqual(initial_region,
97 base::UTF8ToUTF16(region.first)) ||
98 compare.StringsEqual(initial_region, region_name)) {
99 return region_name;
100 }
101 }
102
103 return initial_region;
104 }
105
87 return profile_to_edit_->GetInfo(autofill::AutofillType(type), 106 return profile_to_edit_->GetInfo(autofill::AutofillType(type),
88 state()->GetApplicationLocale()); 107 state()->GetApplicationLocale());
89 } 108 }
90 109
91 bool ShippingAddressEditorViewController::ValidateModelAndSave() { 110 bool ShippingAddressEditorViewController::ValidateModelAndSave() {
92 // To validate the profile first, we use a temporary object. 111 // To validate the profile first, we use a temporary object.
93 autofill::AutofillProfile profile; 112 autofill::AutofillProfile profile;
94 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false)) 113 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false))
95 return false; 114 return false;
96 if (!profile_to_edit_) { 115 if (!profile_to_edit_) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 model->SetCountries(*state()->GetPersonalDataManager(), 154 model->SetCountries(*state()->GetPersonalDataManager(),
136 base::Callback<bool(const std::string&)>(), 155 base::Callback<bool(const std::string&)>(),
137 state()->GetApplicationLocale()); 156 state()->GetApplicationLocale());
138 if (model->countries().size() != countries_.size()) 157 if (model->countries().size() != countries_.size())
139 UpdateCountries(model.get()); 158 UpdateCountries(model.get());
140 return std::move(model); 159 return std::move(model);
141 } 160 }
142 case autofill::ADDRESS_HOME_STATE: { 161 case autofill::ADDRESS_HOME_STATE: {
143 std::unique_ptr<autofill::RegionComboboxModel> model = 162 std::unique_ptr<autofill::RegionComboboxModel> model =
144 base::MakeUnique<autofill::RegionComboboxModel>(); 163 base::MakeUnique<autofill::RegionComboboxModel>();
164 region_model_ = model.get();
145 if (chosen_country_index_ < countries_.size()) { 165 if (chosen_country_index_ < countries_.size()) {
146 model->LoadRegionData(countries_[chosen_country_index_].first, 166 model->LoadRegionData(countries_[chosen_country_index_].first,
147 state()->GetRegionDataLoader(), 167 state()->GetRegionDataLoader(),
148 /*timeout_ms=*/5000); 168 /*timeout_ms=*/5000);
149 if (!model->IsPendingRegionDataLoad()) { 169 if (!model->IsPendingRegionDataLoad()) {
150 // If the data was already pre-loaded, the observer won't get notified 170 // If the data was already pre-loaded, the observer won't get notified
151 // so we have to check for failure here. 171 // so we have to check for failure here.
152 failed_to_load_region_data_ = model->failed_to_load_data(); 172 failed_to_load_region_data_ = model->failed_to_load_data();
153 } 173 }
154 } else { 174 } else {
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 return true; 557 return true;
538 } 558 }
539 if (error_message && field_.required) { 559 if (error_message && field_.required) {
540 *error_message = l10n_util::GetStringUTF16( 560 *error_message = l10n_util::GetStringUTF16(
541 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); 561 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
542 } 562 }
543 return !field_.required; 563 return !field_.required;
544 } 564 }
545 565
546 } // namespace payments 566 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698