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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 } 1219 }
1220 1220
1221 // TODO(estade): Replace all the error messages here with more helpful and 1221 // TODO(estade): Replace all the error messages here with more helpful and
1222 // translateable ones. TODO(groby): Also add tests. 1222 // translateable ones. TODO(groby): Also add tests.
1223 ValidityData AutofillDialogControllerImpl::InputsAreValid( 1223 ValidityData AutofillDialogControllerImpl::InputsAreValid(
1224 const DetailOutputMap& inputs, ValidationType validation_type) const { 1224 const DetailOutputMap& inputs, ValidationType validation_type) const {
1225 ValidityData invalid_messages; 1225 ValidityData invalid_messages;
1226 std::map<AutofillFieldType, string16> field_values; 1226 std::map<AutofillFieldType, string16> field_values;
1227 for (DetailOutputMap::const_iterator iter = inputs.begin(); 1227 for (DetailOutputMap::const_iterator iter = inputs.begin();
1228 iter != inputs.end(); ++iter) { 1228 iter != inputs.end(); ++iter) {
1229 // Skip empty fields in edit mode. 1229 // Skip empty fields in edit mode or when selecting a suggestion.
1230 if (validation_type == VALIDATE_EDIT && iter->second.empty()) 1230 if ((validation_type == VALIDATE_EDIT ||
1231 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.
1231 continue; 1232 continue;
1233 }
1232 1234
1233 const AutofillFieldType type = iter->first->type; 1235 const AutofillFieldType type = iter->first->type;
1234 string16 message = InputValidityMessage(type, iter->second); 1236 string16 message = InputValidityMessage(type, iter->second);
1235 if (!message.empty()) 1237 if (!message.empty())
1236 invalid_messages[type] = message; 1238 invalid_messages[type] = message;
1237 else 1239 else
1238 field_values[type] = iter->second; 1240 field_values[type] = iter->second;
1239 } 1241 }
1240 1242
1241 // Validate the date formed by month and year field. (Autofill dialog is 1243 // Validate the date formed by month and year field. (Autofill dialog is
1242 // never supposed to have 2-digit years, so not checked). 1244 // never supposed to have 2-digit years, so not checked).
1243 if (field_values.count(CREDIT_CARD_EXP_MONTH) && 1245 if (field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR) &&
1244 field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)) { 1246 field_values.count(CREDIT_CARD_EXP_MONTH) &&
1245 if (!autofill::IsValidCreditCardExpirationDate( 1247 !IsCCExpirationValid(field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR],
1246 field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR], 1248 field_values[CREDIT_CARD_EXP_MONTH])) {
1247 field_values[CREDIT_CARD_EXP_MONTH], 1249 invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] =
1248 base::Time::Now())) { 1250 ASCIIToUTF16("more complicated message");
1249 invalid_messages[CREDIT_CARD_EXP_MONTH] = 1251 invalid_messages[CREDIT_CARD_EXP_MONTH] =
1250 ASCIIToUTF16("more complicated message"); 1252 ASCIIToUTF16("more complicated message");
1251 invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] =
1252 ASCIIToUTF16("more complicated message");
1253 }
1254 } 1253 }
1255 1254
1256 // If there is a credit card number and a CVC, validate them together. 1255 // If there is a credit card number and a CVC, validate them together.
1257 if (field_values.count(CREDIT_CARD_NUMBER) && 1256 if (field_values.count(CREDIT_CARD_NUMBER) &&
1258 field_values.count(CREDIT_CARD_VERIFICATION_CODE) && 1257 field_values.count(CREDIT_CARD_VERIFICATION_CODE) &&
1259 InputValidityMessage(CREDIT_CARD_NUMBER, 1258 InputValidityMessage(CREDIT_CARD_NUMBER,
1260 field_values[CREDIT_CARD_NUMBER]).empty()) { 1259 field_values[CREDIT_CARD_NUMBER]).empty() &&
1261 if (!autofill::IsValidCreditCardSecurityCode( 1260 !autofill::IsValidCreditCardSecurityCode(
1262 field_values[CREDIT_CARD_VERIFICATION_CODE], 1261 field_values[CREDIT_CARD_VERIFICATION_CODE],
1263 field_values[CREDIT_CARD_NUMBER])) { 1262 field_values[CREDIT_CARD_NUMBER])) {
1264 invalid_messages[CREDIT_CARD_VERIFICATION_CODE] = 1263 invalid_messages[CREDIT_CARD_VERIFICATION_CODE] =
1265 ASCIIToUTF16("CVC doesn't match card type!"); 1264 ASCIIToUTF16("CVC doesn't match card type!");
1266 }
1267 } 1265 }
1268 1266
1269 // Validate the phone number against the country code of the address. 1267 // Validate the phone number against the country code of the address.
1270 if (field_values.count(ADDRESS_HOME_COUNTRY) && 1268 if (field_values.count(ADDRESS_HOME_COUNTRY) &&
1271 field_values.count(PHONE_HOME_WHOLE_NUMBER)) { 1269 field_values.count(PHONE_HOME_WHOLE_NUMBER)) {
1272 i18n::PhoneObject phone_object( 1270 i18n::PhoneObject phone_object(
1273 field_values[PHONE_HOME_WHOLE_NUMBER], 1271 field_values[PHONE_HOME_WHOLE_NUMBER],
1274 AutofillCountry::GetCountryCode( 1272 AutofillCountry::GetCountryCode(
1275 field_values[ADDRESS_HOME_COUNTRY], 1273 field_values[ADDRESS_HOME_COUNTRY],
1276 g_browser_process->GetApplicationLocale())); 1274 g_browser_process->GetApplicationLocale()));
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2411 bool AutofillDialogControllerImpl::SectionIsValid( 2409 bool AutofillDialogControllerImpl::SectionIsValid(
2412 DialogSection section) const { 2410 DialogSection section) const {
2413 if (!IsManuallyEditingSection(section)) 2411 if (!IsManuallyEditingSection(section))
2414 return true; 2412 return true;
2415 2413
2416 DetailOutputMap detail_outputs; 2414 DetailOutputMap detail_outputs;
2417 view_->GetUserInput(section, &detail_outputs); 2415 view_->GetUserInput(section, &detail_outputs);
2418 return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty(); 2416 return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty();
2419 } 2417 }
2420 2418
2419 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
2420 const base::string16& year,
2421 const base::string16& month) const {
2422 // If the expiration is in the past as per the local clock, it's invalid.
2423 base::Time now = base::Time::Now();
2424 if (!autofill::IsValidCreditCardExpirationDate(year, month, now))
2425 return true;
2426
2427 if (IsPayingWithWallet() && IsEditingExistingData(SECTION_CC_BILLING)) {
2428 const SuggestionsMenuModel* model =
2429 SuggestionsMenuModelForSection(SECTION_CC_BILLING);
2430 int instrument_index = -1;
2431 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
2432 const wallet::WalletItems::MaskedInstrument* instrument =
2433 wallet_items_->instruments()[instrument_index];
2434 const std::string& locale = g_browser_process->GetApplicationLocale();
2435 if (instrument->status() ==
2436 wallet::WalletItems::MaskedInstrument::EXPIRED &&
2437 year == instrument->GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, locale) &&
2438 month == instrument->GetInfo(CREDIT_CARD_EXP_MONTH, locale)) {
2439 // Otherwise, if the user is editing an instrument that's deemed expired
2440 // by the Online Wallet server, mark it invalid on selection.
2441 return true;
2442 }
2443 }
2444
2445 return false;
2446 }
2447
2421 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { 2448 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
2422 return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; 2449 return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
2423 } 2450 }
2424 2451
2425 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { 2452 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() {
2426 // It's possible that the user checked [X] Save details locally before 2453 // It's possible that the user checked [X] Save details locally before
2427 // switching payment methods, so only ask the view whether to save details 2454 // switching payment methods, so only ask the view whether to save details
2428 // locally if that checkbox is showing (currently if not paying with wallet). 2455 // locally if that checkbox is showing (currently if not paying with wallet).
2429 // Also, if the user isn't editing any sections, there's no data to save 2456 // Also, if the user isn't editing any sections, there's no data to save
2430 // locally. 2457 // locally.
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 2913 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
2887 } 2914 }
2888 2915
2889 // Has Wallet items. 2916 // Has Wallet items.
2890 return has_autofill_profiles ? 2917 return has_autofill_profiles ?
2891 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 2918 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
2892 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 2919 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
2893 } 2920 }
2894 2921
2895 } // namespace autofill 2922 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698