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

Unified Diff: chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc

Issue 2713873002: [Payments] Add validation for unsupported credit card types in editor. (Closed)
Patch Set: addressed comments Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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 22fa5538c2c0a8520e2b878779e0046a630d8a91..4fdaea8c606f1041f6b7045fb65b354c611e1254 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
@@ -189,9 +189,14 @@ bool CreditCardEditorViewController::ValidateModelAndSave() {
std::unique_ptr<ValidationDelegate>
CreditCardEditorViewController::CreateValidationDelegate(
const EditorField& field) {
+ // The supported card networks for non-cc-number types are not passed to avoid
+ // the data copy in the delegate.
return base::MakeUnique<
- CreditCardEditorViewController::CreditCardValidationDelegate>(field,
- this);
+ CreditCardEditorViewController::CreditCardValidationDelegate>(
+ field, this,
+ field.type == autofill::CREDIT_CARD_NUMBER
+ ? request()->supported_card_networks()
+ : std::vector<std::string>());
}
std::unique_ptr<ui::ComboboxModel>
@@ -216,9 +221,14 @@ CreditCardEditorViewController::GetComboboxModelForType(
}
CreditCardEditorViewController::CreditCardValidationDelegate::
- CreditCardValidationDelegate(const EditorField& field,
- EditorViewController* controller)
- : field_(field), controller_(controller) {}
+ CreditCardValidationDelegate(
+ const EditorField& field,
+ EditorViewController* controller,
+ const std::vector<std::string>& supported_card_networks)
+ : field_(field),
+ controller_(controller),
+ supported_card_networks_(supported_card_networks.begin(),
+ supported_card_networks.end()) {}
CreditCardEditorViewController::CreditCardValidationDelegate::
~CreditCardValidationDelegate() {}
@@ -237,7 +247,10 @@ bool CreditCardEditorViewController::CreditCardValidationDelegate::
if (!value.empty()) {
base::string16 error_message;
bool is_valid =
- autofill::IsValidForType(value, field_.type, &error_message);
+ field_.type == autofill::CREDIT_CARD_NUMBER
+ ? autofill::IsValidCreditCardNumberForBasicCardNetworks(
+ value, supported_card_networks_, &error_message)
+ : autofill::IsValidForType(value, field_.type, &error_message);
controller_->DisplayErrorMessageForField(field_, error_message);
return is_valid;
}

Powered by Google App Engine
This is Rietveld 408576698