| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/validation.h" | 5 #include "components/autofill/core/browser/validation.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/autofill/core/browser/autofill_data_util.h" | 15 #include "components/autofill/core/browser/autofill_data_util.h" |
| 16 #include "components/autofill/core/browser/autofill_regex_constants.h" | 16 #include "components/autofill/core/browser/autofill_regex_constants.h" |
| 17 #include "components/autofill/core/browser/credit_card.h" | 17 #include "components/autofill/core/browser/credit_card.h" |
| 18 #include "components/autofill/core/browser/personal_data_manager.h" |
| 18 #include "components/autofill/core/browser/state_names.h" | 19 #include "components/autofill/core/browser/state_names.h" |
| 19 #include "components/autofill/core/common/autofill_clock.h" | 20 #include "components/autofill/core/common/autofill_clock.h" |
| 20 #include "components/autofill/core/common/autofill_regexes.h" | 21 #include "components/autofill/core/common/autofill_regexes.h" |
| 21 #include "components/strings/grit/components_strings.h" | 22 #include "components/strings/grit/components_strings.h" |
| 22 #include "third_party/libphonenumber/phonenumber_api.h" | 23 #include "third_party/libphonenumber/phonenumber_api.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 | 25 |
| 25 namespace autofill { | 26 namespace autofill { |
| 26 | 27 |
| 27 bool IsValidCreditCardExpirationDate(int year, | 28 bool IsValidCreditCardExpirationDate(int year, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (IsValidCreditCardNumber(text)) | 121 if (IsValidCreditCardNumber(text)) |
| 121 return true; | 122 return true; |
| 122 | 123 |
| 123 *error_message = l10n_util::GetStringUTF16( | 124 *error_message = l10n_util::GetStringUTF16( |
| 124 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); | 125 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); |
| 125 return false; | 126 return false; |
| 126 } | 127 } |
| 127 | 128 |
| 128 CreditCardCompletionStatus GetCompletionStatusForCard( | 129 CreditCardCompletionStatus GetCompletionStatusForCard( |
| 129 const CreditCard& card, | 130 const CreditCard& card, |
| 130 const std::string& app_locale) { | 131 const std::string& app_locale, |
| 132 const std::vector<AutofillProfile*> billing_addresses) { |
| 131 CreditCardCompletionStatus status = CREDIT_CARD_COMPLETE; | 133 CreditCardCompletionStatus status = CREDIT_CARD_COMPLETE; |
| 132 if (card.IsExpired(autofill::AutofillClock::Now())) | 134 if (card.IsExpired(autofill::AutofillClock::Now())) |
| 133 status |= CREDIT_CARD_EXPIRED; | 135 status |= CREDIT_CARD_EXPIRED; |
| 134 | 136 |
| 135 if (card.number().empty()) | 137 if (card.number().empty()) |
| 136 status |= CREDIT_CARD_NO_NUMBER; | 138 status |= CREDIT_CARD_NO_NUMBER; |
| 137 | 139 |
| 138 if (card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), | 140 if (card.GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
| 139 app_locale) | 141 app_locale) |
| 140 .empty()) { | 142 .empty()) { |
| 141 status |= CREDIT_CARD_NO_CARDHOLDER; | 143 status |= CREDIT_CARD_NO_CARDHOLDER; |
| 142 } | 144 } |
| 143 | 145 |
| 146 if (card.billing_address_id().empty() || |
| 147 !autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
| 148 card.billing_address_id(), billing_addresses)) { |
| 149 status |= CREDIT_CARD_NO_BILLING_ADDRESS; |
| 150 } |
| 151 |
| 144 return status; | 152 return status; |
| 145 } | 153 } |
| 146 | 154 |
| 147 base::string16 GetCompletionMessageForCard(CreditCardCompletionStatus status) { | 155 base::string16 GetCompletionMessageForCard(CreditCardCompletionStatus status) { |
| 148 switch (status) { | 156 switch (status) { |
| 149 case CREDIT_CARD_COMPLETE: | 157 case CREDIT_CARD_COMPLETE: |
| 150 return base::string16(); | 158 return base::string16(); |
| 151 case CREDIT_CARD_EXPIRED: | 159 case CREDIT_CARD_EXPIRED: |
| 152 return l10n_util::GetStringUTF16( | 160 return l10n_util::GetStringUTF16( |
| 153 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED); | 161 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED); |
| 154 case CREDIT_CARD_NO_CARDHOLDER: | 162 case CREDIT_CARD_NO_CARDHOLDER: |
| 155 return l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED); | 163 return l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED); |
| 156 case CREDIT_CARD_NO_NUMBER: | 164 case CREDIT_CARD_NO_NUMBER: |
| 157 return l10n_util::GetStringUTF16( | 165 return l10n_util::GetStringUTF16( |
| 158 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); | 166 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE); |
| 167 case CREDIT_CARD_NO_BILLING_ADDRESS: |
| 168 return l10n_util::GetStringUTF16( |
| 169 IDS_PAYMENTS_CARD_BILLING_ADDRESS_REQUIRED); |
| 159 default: | 170 default: |
| 160 // Multiple things are missing | 171 // Multiple things are missing |
| 161 return l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED); | 172 return l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED); |
| 162 } | 173 } |
| 163 } | 174 } |
| 164 | 175 |
| 165 bool IsValidEmailAddress(const base::string16& text) { | 176 bool IsValidEmailAddress(const base::string16& text) { |
| 166 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) | 177 // E-Mail pattern as defined by the WhatWG. (4.10.7.1.5 E-Mail state) |
| 167 const base::string16 kEmailPattern = base::ASCIIToUTF16( | 178 const base::string16 kEmailPattern = base::ASCIIToUTF16( |
| 168 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" | 179 "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 return AMEX_CVC_LENGTH; | 376 return AMEX_CVC_LENGTH; |
| 366 | 377 |
| 367 return GENERAL_CVC_LENGTH; | 378 return GENERAL_CVC_LENGTH; |
| 368 } | 379 } |
| 369 | 380 |
| 370 bool IsUPIVirtualPaymentAddress(const base::string16& value) { | 381 bool IsUPIVirtualPaymentAddress(const base::string16& value) { |
| 371 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); | 382 return MatchesPattern(value, base::ASCIIToUTF16(kUPIVirtualPaymentAddressRe)); |
| 372 } | 383 } |
| 373 | 384 |
| 374 } // namespace autofill | 385 } // namespace autofill |
| OLD | NEW |