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

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

Issue 2949813003: [Payment Request] Formats phone number and credit card number in editors. (Closed)
Patch Set: Fixed broken tests Created 3 years, 6 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
« no previous file with comments | « no previous file | components/payments/core/payment_request_data_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fdb9fa00dcb12b53916d28a2cd59fe35b0761f7c..7841f9b43412ee036f6f0707763d32d4b080d882 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
@@ -34,6 +34,7 @@
#include "components/autofill/core/common/autofill_constants.h"
#include "components/payments/content/payment_request_spec.h"
#include "components/payments/content/payment_request_state.h"
+#include "components/payments/core/payment_request_data_util.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/insets.h"
@@ -136,29 +137,6 @@ class ExpirationDateValidationDelegate : public ValidationDelegate {
DISALLOW_COPY_AND_ASSIGN(ExpirationDateValidationDelegate);
};
-// Formats card number. For example, "4111111111111111" is formatted into
-// "4111 1111 1111 1111".
-base::string16 FormatCardNumber(const base::string16& text) {
- // Do not format masked card numbers, which start with a letter.
- base::string16 number = autofill::CreditCard::StripSeparators(text);
- if (number.empty() || !base::IsAsciiDigit(number[0]))
- return text;
-
- std::vector<size_t> positions = {4U, 9U, 14U};
- if (autofill::CreditCard::GetCardNetwork(number) ==
- autofill::kAmericanExpressCard) {
- positions = {4U, 11U};
- }
-
- static const base::char16 kSeparator = base::ASCIIToUTF16(" ")[0];
- for (size_t i : positions) {
- if (number.size() > i)
- number.insert(i, 1U, kSeparator);
- }
-
- return number;
-}
-
} // namespace
CreditCardEditorViewController::CreditCardEditorViewController(
@@ -368,7 +346,9 @@ base::string16 CreditCardEditorViewController::GetInitialValueForType(
base::string16 info = credit_card_to_edit_->GetInfo(
autofill::AutofillType(type), state()->GetApplicationLocale());
- return type == autofill::CREDIT_CARD_NUMBER ? FormatCardNumber(info) : info;
+ return type == autofill::CREDIT_CARD_NUMBER
+ ? data_util::FormatCardNumberForDisplay(info)
+ : info;
}
bool CreditCardEditorViewController::ValidateModelAndSave() {
@@ -627,7 +607,7 @@ bool CreditCardEditorViewController::CreditCardValidationDelegate::
base::string16
CreditCardEditorViewController::CreditCardValidationDelegate::Format(
const base::string16& text) {
- return FormatCardNumber(text);
+ return data_util::FormatCardNumberForDisplay(text);
}
bool CreditCardEditorViewController::CreditCardValidationDelegate::
« no previous file with comments | « no previous file | components/payments/core/payment_request_data_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698