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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 15961007: Highlight fields we know to be invalid but have no way of locally checking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 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/autofill/autofill_dialog_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
index 1d301d479fbc024da7f74e66bdc2fa86467bb1b1..c9578751da3d958f756115077bf8e6f28f16b36c 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -1226,9 +1226,11 @@ ValidityData AutofillDialogControllerImpl::InputsAreValid(
std::map<AutofillFieldType, string16> field_values;
for (DetailOutputMap::const_iterator iter = inputs.begin();
iter != inputs.end(); ++iter) {
- // Skip empty fields in edit mode.
- if (validation_type == VALIDATE_EDIT && iter->second.empty())
+ // Skip empty fields in edit mode or when selecting a suggestion.
+ if ((validation_type == VALIDATE_EDIT ||
+ validation_type == VALIDATE_SUGGESTION) && iter->second.empty()) {
Evan Stade 2013/06/01 00:39:19 I thought you suggested we could get rid of this
Dan Beam 2013/06/01 01:15:04 Done.
continue;
+ }
const AutofillFieldType type = iter->first->type;
string16 message = InputValidityMessage(type, iter->second);
@@ -1240,30 +1242,26 @@ ValidityData AutofillDialogControllerImpl::InputsAreValid(
// Validate the date formed by month and year field. (Autofill dialog is
// never supposed to have 2-digit years, so not checked).
- if (field_values.count(CREDIT_CARD_EXP_MONTH) &&
- field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)) {
- if (!autofill::IsValidCreditCardExpirationDate(
- field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR],
- field_values[CREDIT_CARD_EXP_MONTH],
- base::Time::Now())) {
- invalid_messages[CREDIT_CARD_EXP_MONTH] =
- ASCIIToUTF16("more complicated message");
- invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] =
- ASCIIToUTF16("more complicated message");
- }
+ if (field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR) &&
+ field_values.count(CREDIT_CARD_EXP_MONTH) &&
+ !IsCCExpirationValid(field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR],
+ field_values[CREDIT_CARD_EXP_MONTH])) {
+ invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] =
+ ASCIIToUTF16("more complicated message");
+ invalid_messages[CREDIT_CARD_EXP_MONTH] =
+ ASCIIToUTF16("more complicated message");
}
// If there is a credit card number and a CVC, validate them together.
if (field_values.count(CREDIT_CARD_NUMBER) &&
field_values.count(CREDIT_CARD_VERIFICATION_CODE) &&
InputValidityMessage(CREDIT_CARD_NUMBER,
- field_values[CREDIT_CARD_NUMBER]).empty()) {
- if (!autofill::IsValidCreditCardSecurityCode(
- field_values[CREDIT_CARD_VERIFICATION_CODE],
- field_values[CREDIT_CARD_NUMBER])) {
- invalid_messages[CREDIT_CARD_VERIFICATION_CODE] =
- ASCIIToUTF16("CVC doesn't match card type!");
- }
+ field_values[CREDIT_CARD_NUMBER]).empty() &&
+ !autofill::IsValidCreditCardSecurityCode(
+ field_values[CREDIT_CARD_VERIFICATION_CODE],
+ field_values[CREDIT_CARD_NUMBER])) {
+ invalid_messages[CREDIT_CARD_VERIFICATION_CODE] =
+ ASCIIToUTF16("CVC doesn't match card type!");
}
// Validate the phone number against the country code of the address.
@@ -2418,6 +2416,35 @@ bool AutofillDialogControllerImpl::SectionIsValid(
return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty();
}
+bool AutofillDialogControllerImpl::IsCCExpirationValid(
Dan Beam 2013/06/01 00:25:56 whoops, return values are inverted, fixing
Evan Stade 2013/06/01 00:39:19 nit: IsCreditCardExpirationValid (preferred) or Is
+ const base::string16& year,
+ const base::string16& month) const {
+ // If the expiration is in the past as per the local clock, it's invalid.
+ base::Time now = base::Time::Now();
+ if (!autofill::IsValidCreditCardExpirationDate(year, month, now))
+ return true;
+
+ if (IsPayingWithWallet() && IsEditingExistingData(SECTION_CC_BILLING)) {
+ const SuggestionsMenuModel* model =
+ SuggestionsMenuModelForSection(SECTION_CC_BILLING);
+ int instrument_index = -1;
+ base::StringToInt(model->GetItemKeyForCheckedItem(), &instrument_index);
Evan Stade 2013/06/01 00:39:19 I see a lot of uses of StringToInt in this file fo
+ const wallet::WalletItems::MaskedInstrument* instrument =
+ wallet_items_->instruments()[instrument_index];
+ const std::string& locale = g_browser_process->GetApplicationLocale();
+ if (instrument->status() ==
+ wallet::WalletItems::MaskedInstrument::EXPIRED &&
+ year == instrument->GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, locale) &&
+ month == instrument->GetInfo(CREDIT_CARD_EXP_MONTH, locale)) {
+ // Otherwise, if the user is editing an instrument that's deemed expired
+ // by the Online Wallet server, mark it invalid on selection.
+ return true;
+ }
+ }
+
+ return false;
+}
+
bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
}

Powered by Google App Engine
This is Rietveld 408576698