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

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 d6ee51ee9d4d7c5e23449951fae77984881fcf3a..f1c3254daee3e47f77737560ae6ac1f30107355d 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -1016,6 +1016,27 @@ string16 AutofillDialogControllerImpl::ExtraSuggestionTextForSection(
return string16();
}
+const wallet::WalletItems::MaskedInstrument* AutofillDialogControllerImpl::
+ ActiveInstrument() const {
Evan Stade 2013/06/03 21:24:46 could you make an ActiveShippingAddress() while yo
Dan Beam 2013/06/03 22:04:19 Done.
+ if (!IsPayingWithWallet())
+ return NULL;
+
+ const SuggestionsMenuModel* model =
+ SuggestionsMenuModelForSection(SECTION_CC_BILLING);
+ const std::string item_key = model->GetItemKeyForCheckedItem();
+ if (!IsASuggestionItemKey(item_key))
+ return NULL;
+
+ int index;
+ if (!base::StringToInt(item_key, &index) || index < 0 ||
+ static_cast<size_t>(index) >= wallet_items_->instruments().size()) {
+ NOTREACHED();
+ return NULL;
+ }
+
+ return wallet_items_->instruments()[index];
+}
+
scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper(
DialogSection section) {
if (IsPayingWithWallet() && full_wallet_ &&
@@ -1036,21 +1057,20 @@ scoped_ptr<DataModelWrapper> AutofillDialogControllerImpl::CreateWrapper(
return scoped_ptr<DataModelWrapper>();
if (IsPayingWithWallet()) {
- int index;
- bool success = base::StringToInt(item_key, &index);
- DCHECK(success);
-
if (section == SECTION_CC_BILLING) {
return scoped_ptr<DataModelWrapper>(
- new WalletInstrumentWrapper(wallet_items_->instruments()[index]));
+ new WalletInstrumentWrapper(ActiveInstrument()));
}
- if (section == SECTION_SHIPPING) {
- return scoped_ptr<DataModelWrapper>(
- new WalletAddressWrapper(wallet_items_->addresses()[index]));
- }
+ if (section != SECTION_SHIPPING)
+ return scoped_ptr<DataModelWrapper>();
- return scoped_ptr<DataModelWrapper>();
+ int index;
+ bool success = base::StringToInt(item_key, &index);
+ DCHECK(success);
+
+ return scoped_ptr<DataModelWrapper>(
+ new WalletAddressWrapper(wallet_items_->addresses()[index]));
}
if (section == SECTION_CC) {
@@ -1249,30 +1269,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) &&
+ !IsCreditCardExpirationValid(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.
@@ -2398,7 +2414,7 @@ bool AutofillDialogControllerImpl::IsManuallyEditingSection(
}
bool AutofillDialogControllerImpl::IsASuggestionItemKey(
- const std::string& key) {
+ const std::string& key) const {
return !key.empty() &&
key != kAddNewItemKey &&
key != kManageItemsKey &&
@@ -2443,6 +2459,33 @@ bool AutofillDialogControllerImpl::SectionIsValid(
return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty();
}
+bool AutofillDialogControllerImpl::IsCreditCardExpirationValid(
+ 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 false;
+
+ if (IsPayingWithWallet() && IsEditingExistingData(SECTION_CC_BILLING)) {
+ const wallet::WalletItems::MaskedInstrument* instrument =
+ ActiveInstrument();
+ const std::string& locale = g_browser_process->GetApplicationLocale();
+ int month_int;
+ if (base::StringToInt(month, &month_int) &&
+ instrument->status() ==
+ wallet::WalletItems::MaskedInstrument::EXPIRED &&
+ year == instrument->GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, locale) &&
+ month_int == instrument->expiration_month()) {
+ // Otherwise, if the user is editing an instrument that's deemed expired
+ // by the Online Wallet server, mark it invalid on selection.
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
return SectionIsActive(SECTION_SHIPPING) &&
suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
@@ -2494,14 +2537,10 @@ void AutofillDialogControllerImpl::SubmitWithWallet() {
if (AreLegalDocumentsCurrent())
LoadRiskFingerprintData();
- SuggestionsMenuModel* billing =
- SuggestionsMenuModelForSection(SECTION_CC_BILLING);
- int instrument_index = -1;
- base::StringToInt(billing->GetItemKeyForCheckedItem(), &instrument_index);
-
+ const wallet::WalletItems::MaskedInstrument* active_instrument =
+ ActiveInstrument();
if (!IsManuallyEditingSection(SECTION_CC_BILLING)) {
- active_instrument_id_ =
- wallet_items_->instruments()[instrument_index]->object_id();
+ active_instrument_id_ = active_instrument->object_id();
DCHECK(!active_instrument_id_.empty());
}
@@ -2523,14 +2562,13 @@ void AutofillDialogControllerImpl::SubmitWithWallet() {
CreateUpdateInstrumentRequest(
inputted_instrument.get(),
!IsEditingExistingData(SECTION_CC_BILLING) ? std::string() :
- wallet_items_->instruments()[instrument_index]->object_id());
+ active_instrument->object_id());
scoped_ptr<wallet::Address> inputted_address;
if (active_address_id_.empty()) {
if (ShouldUseBillingForShipping()) {
const wallet::Address& address = inputted_instrument ?
- inputted_instrument->address() :
- wallet_items_->instruments()[instrument_index]->address();
+ inputted_instrument->address() : active_instrument->address();
// Try to find an exact matched shipping address and use it for shipping,
// otherwise save it as a new shipping address. http://crbug.com/225442
const wallet::Address* duplicated_address =

Powered by Google App Engine
This is Rietveld 408576698