Index: chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc |
diff --git a/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc b/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc |
index fd14fbea612ae0725ee0912a2b40955cb7512868..b4c941044e05d65463c0748b5325414fd2abec5f 100644 |
--- a/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc |
+++ b/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc |
@@ -10,9 +10,13 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
#include "chrome/grit/generated_resources.h" |
+#include "components/autofill/core/browser/autofill_type.h" |
+#include "components/autofill/core/browser/credit_card.h" |
#include "components/autofill/core/browser/field_types.h" |
+#include "components/autofill/core/common/autofill_constants.h" |
#include "components/payments/payment_request.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/views/controls/textfield/textfield.h" |
namespace payments { |
@@ -25,19 +29,38 @@ CreditCardEditorViewController::~CreditCardEditorViewController() {} |
std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { |
return std::vector<EditorField>{ |
- {autofill::CREDIT_CARD_NUMBER, |
- l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), |
- EditorField::LengthHint::HINT_LONG}, |
{autofill::CREDIT_CARD_NAME_FULL, |
l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), |
EditorField::LengthHint::HINT_LONG}, |
+ {autofill::CREDIT_CARD_NUMBER, |
+ l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), |
+ EditorField::LengthHint::HINT_LONG}, |
{autofill::CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, |
l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_DATE), |
EditorField::LengthHint::HINT_SHORT}}; |
} |
bool CreditCardEditorViewController::ValidateModelAndSave() { |
- // TODO(mathp): Actual validation and saving the model on disk. |
+ autofill::CreditCard credit_card; |
+ credit_card.set_origin(autofill::kSettingsOrigin); |
+ for (const auto& field : text_fields()) { |
+ // ValidatingTextfield* is the key, EditorField is the value. |
+ base::string16 value = field.first->text(); |
+ DCHECK_EQ(autofill::CREDIT_CARD, |
+ autofill::AutofillType(field.second.type).group()); |
+ if (!ValidateTextfield(field.first)) |
+ return false; |
+ |
+ credit_card.SetRawInfo(field.second.type, value); |
+ } |
+ |
+ // TODO(mathp): Display global error message. |
+ if (!credit_card.IsValid()) |
+ return false; |
+ |
+ // Add the card (will not add a duplicate). |
+ request()->personal_data_manager()->AddCreditCard(credit_card); |
+ |
return true; |
} |