| OLD | NEW |
| 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 #import "ios/chrome/browser/ui/payments/address_edit_mediator.h" | 5 #import "ios/chrome/browser/ui/payments/address_edit_mediator.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "components/autofill/core/browser/autofill_address_util.h" | 17 #include "components/autofill/core/browser/autofill_address_util.h" |
| 18 #include "components/autofill/core/browser/autofill_country.h" | 18 #include "components/autofill/core/browser/autofill_country.h" |
| 19 #include "components/autofill/core/browser/autofill_profile.h" | 19 #include "components/autofill/core/browser/autofill_profile.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/payments/core/payment_request_data_util.h" | 24 #include "components/payments/core/payment_request_data_util.h" |
| 25 #include "components/strings/grit/components_strings.h" | 25 #include "components/strings/grit/components_strings.h" |
| 26 #include "ios/chrome/browser/application_context.h" | |
| 27 #include "ios/chrome/browser/payments/payment_request.h" | 26 #include "ios/chrome/browser/payments/payment_request.h" |
| 28 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 27 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
| 29 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" | 28 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" |
| 30 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" | 29 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" |
| 31 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 30 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
| 32 #include "ios/chrome/grit/ios_strings.h" | 31 #include "ios/chrome/grit/ios_strings.h" |
| 33 #include "third_party/libaddressinput/messages.h" | 32 #include "third_party/libaddressinput/messages.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 35 | 34 |
| 36 #if !defined(__has_feature) || !__has_feature(objc_arc) | 35 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 }); | 165 }); |
| 167 } | 166 } |
| 168 | 167 |
| 169 #pragma mark - Helper methods | 168 #pragma mark - Helper methods |
| 170 | 169 |
| 171 // Loads the country codes and names and sets the default selected country code. | 170 // Loads the country codes and names and sets the default selected country code. |
| 172 - (void)loadCountries { | 171 - (void)loadCountries { |
| 173 autofill::CountryComboboxModel countryModel; | 172 autofill::CountryComboboxModel countryModel; |
| 174 countryModel.SetCountries(*_paymentRequest->GetPersonalDataManager(), | 173 countryModel.SetCountries(*_paymentRequest->GetPersonalDataManager(), |
| 175 base::Callback<bool(const std::string&)>(), | 174 base::Callback<bool(const std::string&)>(), |
| 176 GetApplicationContext()->GetApplicationLocale()); | 175 _paymentRequest->GetApplicationLocale()); |
| 177 const autofill::CountryComboboxModel::CountryVector& countriesVector = | 176 const autofill::CountryComboboxModel::CountryVector& countriesVector = |
| 178 countryModel.countries(); | 177 countryModel.countries(); |
| 179 | 178 |
| 180 NSMutableDictionary<NSString*, NSString*>* countries = | 179 NSMutableDictionary<NSString*, NSString*>* countries = |
| 181 [[NSMutableDictionary alloc] | 180 [[NSMutableDictionary alloc] |
| 182 initWithCapacity:static_cast<NSUInteger>(countriesVector.size())]; | 181 initWithCapacity:static_cast<NSUInteger>(countriesVector.size())]; |
| 183 for (size_t i = 0; i < countriesVector.size(); ++i) { | 182 for (size_t i = 0; i < countriesVector.size(); ++i) { |
| 184 if (countriesVector[i].get()) { | 183 if (countriesVector[i].get()) { |
| 185 [countries setObject:base::SysUTF16ToNSString(countriesVector[i]->name()) | 184 [countries setObject:base::SysUTF16ToNSString(countriesVector[i]->name()) |
| 186 forKey:base::SysUTF8ToNSString( | 185 forKey:base::SysUTF8ToNSString( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // the fields to be reused when the selected country code changes. | 219 // the fields to be reused when the selected country code changes. |
| 221 - (NSArray<EditorField*>*)createEditorFields { | 220 - (NSArray<EditorField*>*)createEditorFields { |
| 222 self.fields = [[NSMutableArray alloc] init]; | 221 self.fields = [[NSMutableArray alloc] init]; |
| 223 | 222 |
| 224 self.regionField = nil; | 223 self.regionField = nil; |
| 225 | 224 |
| 226 base::ListValue addressComponents; | 225 base::ListValue addressComponents; |
| 227 std::string unused; | 226 std::string unused; |
| 228 autofill::GetAddressComponents( | 227 autofill::GetAddressComponents( |
| 229 base::SysNSStringToUTF8(self.selectedCountryCode), | 228 base::SysNSStringToUTF8(self.selectedCountryCode), |
| 230 GetApplicationContext()->GetApplicationLocale(), &addressComponents, | 229 _paymentRequest->GetApplicationLocale(), &addressComponents, &unused); |
| 231 &unused); | |
| 232 | 230 |
| 233 for (size_t lineIndex = 0; lineIndex < addressComponents.GetSize(); | 231 for (size_t lineIndex = 0; lineIndex < addressComponents.GetSize(); |
| 234 ++lineIndex) { | 232 ++lineIndex) { |
| 235 const base::ListValue* line = nullptr; | 233 const base::ListValue* line = nullptr; |
| 236 if (!addressComponents.GetList(lineIndex, &line)) { | 234 if (!addressComponents.GetList(lineIndex, &line)) { |
| 237 NOTREACHED(); | 235 NOTREACHED(); |
| 238 return @[]; | 236 return @[]; |
| 239 } | 237 } |
| 240 for (size_t componentIndex = 0; componentIndex < line->GetSize(); | 238 for (size_t componentIndex = 0; componentIndex < line->GetSize(); |
| 241 ++componentIndex) { | 239 ++componentIndex) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 319 |
| 322 // Always add phone number field at the end. | 320 // Always add phone number field at the end. |
| 323 NSNumber* phoneNumberFieldKey = | 321 NSNumber* phoneNumberFieldKey = |
| 324 [NSNumber numberWithInt:AutofillUITypeProfileHomePhoneWholeNumber]; | 322 [NSNumber numberWithInt:AutofillUITypeProfileHomePhoneWholeNumber]; |
| 325 EditorField* field = self.fieldsMap[phoneNumberFieldKey]; | 323 EditorField* field = self.fieldsMap[phoneNumberFieldKey]; |
| 326 if (!field) { | 324 if (!field) { |
| 327 NSString* value = | 325 NSString* value = |
| 328 self.address | 326 self.address |
| 329 ? base::SysUTF16ToNSString( | 327 ? base::SysUTF16ToNSString( |
| 330 payments::data_util::GetFormattedPhoneNumberForDisplay( | 328 payments::data_util::GetFormattedPhoneNumberForDisplay( |
| 331 *self.address, | 329 *self.address, _paymentRequest->GetApplicationLocale())) |
| 332 GetApplicationContext()->GetApplicationLocale())) | |
| 333 : nil; | 330 : nil; |
| 334 field = [[EditorField alloc] | 331 field = [[EditorField alloc] |
| 335 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber | 332 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber |
| 336 fieldType:EditorFieldTypeTextField | 333 fieldType:EditorFieldTypeTextField |
| 337 label:l10n_util::GetNSString(IDS_IOS_AUTOFILL_PHONE) | 334 label:l10n_util::GetNSString(IDS_IOS_AUTOFILL_PHONE) |
| 338 value:value | 335 value:value |
| 339 required:YES]; | 336 required:YES]; |
| 340 field.keyboardType = UIKeyboardTypePhonePad; | 337 field.keyboardType = UIKeyboardTypePhonePad; |
| 341 field.returnKeyType = UIReturnKeyDone; | 338 field.returnKeyType = UIReturnKeyDone; |
| 342 [self.fieldsMap setObject:field forKey:phoneNumberFieldKey]; | 339 [self.fieldsMap setObject:field forKey:phoneNumberFieldKey]; |
| 343 } | 340 } |
| 344 [self.fields addObject:field]; | 341 [self.fields addObject:field]; |
| 345 | 342 |
| 346 return self.fields; | 343 return self.fields; |
| 347 } | 344 } |
| 348 | 345 |
| 349 // Takes in an autofill profile and an autofill field type and returns the | 346 // Takes in an autofill profile and an autofill field type and returns the |
| 350 // corresponding field value. Returns nil if |profile| is nullptr. | 347 // corresponding field value. Returns nil if |profile| is nullptr. |
| 351 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile | 348 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile |
| 352 fieldType:(autofill::ServerFieldType)fieldType { | 349 fieldType:(autofill::ServerFieldType)fieldType { |
| 353 return profile ? base::SysUTF16ToNSString(profile->GetInfo( | 350 return profile ? base::SysUTF16ToNSString(profile->GetInfo( |
| 354 autofill::AutofillType(fieldType), | 351 autofill::AutofillType(fieldType), |
| 355 GetApplicationContext()->GetApplicationLocale())) | 352 _paymentRequest->GetApplicationLocale())) |
| 356 : nil; | 353 : nil; |
| 357 } | 354 } |
| 358 | 355 |
| 359 @end | 356 @end |
| OLD | NEW |