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

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 <string> 8 #include <string>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } 1218 }
1219 1219
1220 // TODO(estade): Replace all the error messages here with more helpful and 1220 // TODO(estade): Replace all the error messages here with more helpful and
1221 // translateable ones. TODO(groby): Also add tests. 1221 // translateable ones. TODO(groby): Also add tests.
1222 ValidityData AutofillDialogControllerImpl::InputsAreValid( 1222 ValidityData AutofillDialogControllerImpl::InputsAreValid(
1223 const DetailOutputMap& inputs, ValidationType validation_type) const { 1223 const DetailOutputMap& inputs, ValidationType validation_type) const {
1224 ValidityData invalid_messages; 1224 ValidityData invalid_messages;
1225 std::map<AutofillFieldType, string16> field_values; 1225 std::map<AutofillFieldType, string16> field_values;
1226 for (DetailOutputMap::const_iterator iter = inputs.begin(); 1226 for (DetailOutputMap::const_iterator iter = inputs.begin();
1227 iter != inputs.end(); ++iter) { 1227 iter != inputs.end(); ++iter) {
1228 // Skip empty fields in edit mode. 1228 // Skip empty fields in edit mode or when selecting a suggestion.
1229 if (validation_type == VALIDATE_EDIT && iter->second.empty()) 1229 if ((validation_type == VALIDATE_EDIT ||
1230 validation_type == VALIDATE_SELECT) && iter->second.empty()) {
1230 continue; 1231 continue;
1232 }
1231 1233
1232 const AutofillFieldType type = iter->first->type; 1234 const AutofillFieldType type = iter->first->type;
1233 string16 message = InputValidityMessage(type, iter->second); 1235 string16 message = InputValidityMessage(type, iter->second);
1234 if (!message.empty()) 1236 if (!message.empty())
1235 invalid_messages[type] = message; 1237 invalid_messages[type] = message;
1236 else 1238 else
1237 field_values[type] = iter->second; 1239 field_values[type] = iter->second;
1238 } 1240 }
1239 1241
1240 // Validate the date formed by month and year field. (Autofill dialog is 1242 // Validate the date formed by month and year field. (Autofill dialog is
1241 // never supposed to have 2-digit years, so not checked). 1243 // never supposed to have 2-digit years, so not checked).
1242 if (field_values.count(CREDIT_CARD_EXP_MONTH) && 1244 if (field_values.count(CREDIT_CARD_EXP_MONTH) &&
1243 field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)) { 1245 field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)) {
1246 bool invalid_exp = false;
groby-ooo-7-16 2013/05/31 04:12:51 nit: invalid_expiration. invalid_date. Something t
Dan Beam 2013/05/31 05:08:50 Done.
1247
1248 // If the expiration is in the past as per the local clock, it's invalid.
1244 if (!autofill::IsValidCreditCardExpirationDate( 1249 if (!autofill::IsValidCreditCardExpirationDate(
1245 field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR], 1250 field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR],
1246 field_values[CREDIT_CARD_EXP_MONTH], 1251 field_values[CREDIT_CARD_EXP_MONTH],
1247 base::Time::Now())) { 1252 base::Time::Now())) {
1253 invalid_exp = true;
1254 } else if (validation_type == VALIDATE_SELECT && IsPayingWithWallet()) {
1255 std::map<DialogSection, bool>::const_iterator it =
groby-ooo-7-16 2013/05/31 04:12:51 You can skip the "find" hoops - just section_editi
Dan Beam 2013/05/31 05:08:50 const, the hoops must stay std::set, a better way
1256 section_editing_state_.find(SECTION_CC_BILLING);
1257 if (it != section_editing_state_.end() && it->second) {
1258 const SuggestionsMenuModel* model =
1259 SuggestionsMenuModelForSection(SECTION_CC_BILLING);
1260 int instrument_index = -1;
1261 base::StringToInt(model->GetItemKeyForCheckedItem(), &instrument_index);
1262 if (wallet_items_->instruments()[instrument_index]->status() ==
1263 wallet::WalletItems::MaskedInstrument::EXPIRED) {
1264 // Otherwise, if the user is editing an instrument that's deemed
1265 // expired by the Online Wallet server, mark it invalid on selection.
1266 invalid_exp = true;
1267 }
1268 }
1269 }
1270
1271 if (invalid_exp) {
1248 invalid_messages[CREDIT_CARD_EXP_MONTH] = 1272 invalid_messages[CREDIT_CARD_EXP_MONTH] =
1249 ASCIIToUTF16("more complicated message"); 1273 ASCIIToUTF16("more complicated message");
1250 invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] = 1274 invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] =
1251 ASCIIToUTF16("more complicated message"); 1275 ASCIIToUTF16("more complicated message");
1252 } 1276 }
1253 } 1277 }
1254 1278
1255 // If there is a credit card number and a CVC, validate them together. 1279 // If there is a credit card number and a CVC, validate them together.
1256 if (field_values.count(CREDIT_CARD_NUMBER) && 1280 if (field_values.count(CREDIT_CARD_NUMBER) &&
1257 field_values.count(CREDIT_CARD_VERIFICATION_CODE) && 1281 field_values.count(CREDIT_CARD_VERIFICATION_CODE) &&
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 2900 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
2877 } 2901 }
2878 2902
2879 // Has Wallet items. 2903 // Has Wallet items.
2880 return has_autofill_profiles ? 2904 return has_autofill_profiles ?
2881 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 2905 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
2882 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 2906 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
2883 } 2907 }
2884 2908
2885 } // namespace autofill 2909 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller.h ('k') | chrome/browser/ui/views/autofill/autofill_dialog_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698