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/contact_info_edit_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/contact_info_edit_coordinator.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "components/autofill/core/browser/autofill_country.h" | 10 #include "components/autofill/core/browser/autofill_country.h" |
11 #include "components/autofill/core/browser/autofill_profile.h" | 11 #include "components/autofill/core/browser/autofill_profile.h" |
12 #include "components/autofill/core/browser/autofill_type.h" | 12 #include "components/autofill/core/browser/autofill_type.h" |
13 #include "components/autofill/core/browser/personal_data_manager.h" | 13 #include "components/autofill/core/browser/personal_data_manager.h" |
14 #include "components/autofill/core/browser/validation.h" | 14 #include "components/autofill/core/browser/validation.h" |
15 #include "components/autofill/core/common/autofill_constants.h" | 15 #include "components/autofill/core/common/autofill_constants.h" |
16 #include "components/payments/core/payments_profile_comparator.h" | 16 #include "components/payments/core/payments_profile_comparator.h" |
17 #include "components/strings/grit/components_strings.h" | 17 #include "components/strings/grit/components_strings.h" |
18 #include "ios/chrome/browser/application_context.h" | |
19 #include "ios/chrome/browser/payments/payment_request.h" | 18 #include "ios/chrome/browser/payments/payment_request.h" |
20 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" | 19 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" |
21 #import "ios/chrome/browser/ui/payments/contact_info_edit_mediator.h" | 20 #import "ios/chrome/browser/ui/payments/contact_info_edit_mediator.h" |
22 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 21 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
24 | 23 |
25 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
26 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
27 #endif | 26 #endif |
28 | 27 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 #pragma mark - PaymentRequestEditViewControllerValidator | 90 #pragma mark - PaymentRequestEditViewControllerValidator |
92 | 91 |
93 - (NSString*)paymentRequestEditViewController: | 92 - (NSString*)paymentRequestEditViewController: |
94 (PaymentRequestEditViewController*)controller | 93 (PaymentRequestEditViewController*)controller |
95 validateField:(EditorField*)field { | 94 validateField:(EditorField*)field { |
96 if (field.value.length) { | 95 if (field.value.length) { |
97 switch (field.autofillUIType) { | 96 switch (field.autofillUIType) { |
98 case AutofillUITypeProfileHomePhoneWholeNumber: { | 97 case AutofillUITypeProfileHomePhoneWholeNumber: { |
99 const std::string countryCode = | 98 const std::string countryCode = |
100 autofill::AutofillCountry::CountryCodeForLocale( | 99 autofill::AutofillCountry::CountryCodeForLocale( |
101 GetApplicationContext()->GetApplicationLocale()); | 100 self.paymentRequest->GetApplicationLocale()); |
102 if (!autofill::IsValidPhoneNumber(base::SysNSStringToUTF16(field.value), | 101 if (!autofill::IsValidPhoneNumber(base::SysNSStringToUTF16(field.value), |
103 countryCode)) { | 102 countryCode)) { |
104 return l10n_util::GetNSString( | 103 return l10n_util::GetNSString( |
105 IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE); | 104 IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE); |
106 } | 105 } |
107 break; | 106 break; |
108 } | 107 } |
109 case AutofillUITypeProfileEmailAddress: { | 108 case AutofillUITypeProfileEmailAddress: { |
110 if (!autofill::IsValidEmailAddress( | 109 if (!autofill::IsValidEmailAddress( |
111 base::SysNSStringToUTF16(field.value))) { | 110 base::SysNSStringToUTF16(field.value))) { |
(...skipping 21 matching lines...) Expand all Loading... |
133 // the information. | 132 // the information. |
134 autofill::AutofillProfile profile = | 133 autofill::AutofillProfile profile = |
135 self.profile ? *self.profile | 134 self.profile ? *self.profile |
136 : autofill::AutofillProfile(base::GenerateGUID(), | 135 : autofill::AutofillProfile(base::GenerateGUID(), |
137 autofill::kSettingsOrigin); | 136 autofill::kSettingsOrigin); |
138 | 137 |
139 for (EditorField* field in fields) { | 138 for (EditorField* field in fields) { |
140 profile.SetInfo(autofill::AutofillType( | 139 profile.SetInfo(autofill::AutofillType( |
141 AutofillTypeFromAutofillUIType(field.autofillUIType)), | 140 AutofillTypeFromAutofillUIType(field.autofillUIType)), |
142 base::SysNSStringToUTF16(field.value), | 141 base::SysNSStringToUTF16(field.value), |
143 GetApplicationContext()->GetApplicationLocale()); | 142 self.paymentRequest->GetApplicationLocale()); |
144 } | 143 } |
145 | 144 |
146 if (!self.profile) { | 145 if (!self.profile) { |
147 self.paymentRequest->GetPersonalDataManager()->AddProfile(profile); | 146 self.paymentRequest->GetPersonalDataManager()->AddProfile(profile); |
148 | 147 |
149 // Add the profile to the list of profiles in |self.paymentRequest|. | 148 // Add the profile to the list of profiles in |self.paymentRequest|. |
150 self.profile = self.paymentRequest->AddAutofillProfile(profile); | 149 self.profile = self.paymentRequest->AddAutofillProfile(profile); |
151 } else { | 150 } else { |
152 // Override the origin. | 151 // Override the origin. |
153 profile.set_origin(autofill::kSettingsOrigin); | 152 profile.set_origin(autofill::kSettingsOrigin); |
154 self.paymentRequest->GetPersonalDataManager()->UpdateProfile(profile); | 153 self.paymentRequest->GetPersonalDataManager()->UpdateProfile(profile); |
155 | 154 |
156 // Cached profile must be invalidated once the profile is modified. | 155 // Cached profile must be invalidated once the profile is modified. |
157 _paymentRequest->profile_comparator()->Invalidate(profile); | 156 _paymentRequest->profile_comparator()->Invalidate(profile); |
158 | 157 |
159 // Update the original profile instance that is being edited. | 158 // Update the original profile instance that is being edited. |
160 *self.profile = profile; | 159 *self.profile = profile; |
161 } | 160 } |
162 | 161 |
163 [self.delegate contactInfoEditCoordinator:self | 162 [self.delegate contactInfoEditCoordinator:self |
164 didFinishEditingProfile:self.profile]; | 163 didFinishEditingProfile:self.profile]; |
165 } | 164 } |
166 | 165 |
167 - (void)paymentRequestEditViewControllerDidCancel: | 166 - (void)paymentRequestEditViewControllerDidCancel: |
168 (PaymentRequestEditViewController*)controller { | 167 (PaymentRequestEditViewController*)controller { |
169 [self.delegate contactInfoEditCoordinatorDidCancel:self]; | 168 [self.delegate contactInfoEditCoordinatorDidCancel:self]; |
170 } | 169 } |
171 | 170 |
172 @end | 171 @end |
OLD | NEW |