| 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 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 return years; | 77 return years; |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 CreditCardEditorViewController::CreditCardEditorViewController( | 82 CreditCardEditorViewController::CreditCardEditorViewController( |
| 83 PaymentRequestSpec* spec, | 83 PaymentRequestSpec* spec, |
| 84 PaymentRequestState* state, | 84 PaymentRequestState* state, |
| 85 PaymentRequestDialogView* dialog, | 85 PaymentRequestDialogView* dialog, |
| 86 base::OnceClosure on_edited, |
| 87 base::OnceCallback<void(const autofill::CreditCard&)> on_added, |
| 86 autofill::CreditCard* credit_card) | 88 autofill::CreditCard* credit_card) |
| 87 : EditorViewController(spec, state, dialog), | 89 : EditorViewController(spec, state, dialog), |
| 90 on_edited_(std::move(on_edited)), |
| 91 on_added_(std::move(on_added)), |
| 88 credit_card_to_edit_(credit_card) {} | 92 credit_card_to_edit_(credit_card) {} |
| 89 | 93 |
| 90 CreditCardEditorViewController::~CreditCardEditorViewController() {} | 94 CreditCardEditorViewController::~CreditCardEditorViewController() {} |
| 91 | 95 |
| 92 // Creates the "Cards accepted" view with a row of icons at the top of the | 96 // Creates the "Cards accepted" view with a row of icons at the top of the |
| 93 // credit card editor. | 97 // credit card editor. |
| 94 // +----------------------------------------------+ | 98 // +----------------------------------------------+ |
| 95 // | Cards Accepted | | 99 // | Cards Accepted | |
| 96 // | | | 100 // | | |
| 97 // | | VISA | | MC | | AMEX | | | 101 // | | VISA | | MC | | AMEX | | |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 locale); | 204 locale); |
| 201 } | 205 } |
| 202 | 206 |
| 203 // TODO(mathp): Display global error message. | 207 // TODO(mathp): Display global error message. |
| 204 if (!credit_card.IsValid()) | 208 if (!credit_card.IsValid()) |
| 205 return false; | 209 return false; |
| 206 | 210 |
| 207 if (!credit_card_to_edit_) { | 211 if (!credit_card_to_edit_) { |
| 208 // Add the card (will not add a duplicate). | 212 // Add the card (will not add a duplicate). |
| 209 state()->GetPersonalDataManager()->AddCreditCard(credit_card); | 213 state()->GetPersonalDataManager()->AddCreditCard(credit_card); |
| 214 std::move(on_added_).Run(credit_card); |
| 210 } else { | 215 } else { |
| 211 // We were in edit mode. Copy the data from the temporary object to retain | 216 // We were in edit mode. Copy the data from the temporary object to retain |
| 212 // the edited object's other properties (use count, use date, guid, etc.). | 217 // the edited object's other properties (use count, use date, guid, etc.). |
| 213 for (const auto& field : text_fields()) { | 218 for (const auto& field : text_fields()) { |
| 214 credit_card_to_edit_->SetInfo( | 219 credit_card_to_edit_->SetInfo( |
| 215 autofill::AutofillType(field.second.type), | 220 autofill::AutofillType(field.second.type), |
| 216 credit_card.GetInfo(autofill::AutofillType(field.second.type), | 221 credit_card.GetInfo(autofill::AutofillType(field.second.type), |
| 217 locale), | 222 locale), |
| 218 locale); | 223 locale); |
| 219 } | 224 } |
| 220 for (const auto& field : comboboxes()) { | 225 for (const auto& field : comboboxes()) { |
| 221 credit_card_to_edit_->SetInfo( | 226 credit_card_to_edit_->SetInfo( |
| 222 autofill::AutofillType(field.second.type), | 227 autofill::AutofillType(field.second.type), |
| 223 credit_card.GetInfo(autofill::AutofillType(field.second.type), | 228 credit_card.GetInfo(autofill::AutofillType(field.second.type), |
| 224 locale), | 229 locale), |
| 225 locale); | 230 locale); |
| 226 } | 231 } |
| 227 state()->GetPersonalDataManager()->UpdateCreditCard(*credit_card_to_edit_); | 232 state()->GetPersonalDataManager()->UpdateCreditCard(*credit_card_to_edit_); |
| 233 std::move(on_edited_).Run(); |
| 228 } | 234 } |
| 229 | 235 |
| 230 return true; | 236 return true; |
| 231 } | 237 } |
| 232 | 238 |
| 233 std::unique_ptr<ValidationDelegate> | 239 std::unique_ptr<ValidationDelegate> |
| 234 CreditCardEditorViewController::CreateValidationDelegate( | 240 CreditCardEditorViewController::CreateValidationDelegate( |
| 235 const EditorField& field) { | 241 const EditorField& field) { |
| 236 // The supported card networks for non-cc-number types are not passed to avoid | 242 // The supported card networks for non-cc-number types are not passed to avoid |
| 237 // the data copy in the delegate. | 243 // the data copy in the delegate. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 bool is_required_valid = !field_.required; | 313 bool is_required_valid = !field_.required; |
| 308 const base::string16 displayed_message = | 314 const base::string16 displayed_message = |
| 309 is_required_valid ? base::ASCIIToUTF16("") | 315 is_required_valid ? base::ASCIIToUTF16("") |
| 310 : l10n_util::GetStringUTF16( | 316 : l10n_util::GetStringUTF16( |
| 311 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 317 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
| 312 controller_->DisplayErrorMessageForField(field_, displayed_message); | 318 controller_->DisplayErrorMessageForField(field_, displayed_message); |
| 313 return is_required_valid; | 319 return is_required_valid; |
| 314 } | 320 } |
| 315 | 321 |
| 316 } // namespace payments | 322 } // namespace payments |
| OLD | NEW |