Chromium Code Reviews| 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 "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 Loading... | |
| 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 // If the expiration is in the past as per the local clock, it's invalid. | |
| 1247 bool invalid_expiration = false; | |
| 1244 if (!autofill::IsValidCreditCardExpirationDate( | 1248 if (!autofill::IsValidCreditCardExpirationDate( |
| 1245 field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR], | 1249 field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR], |
| 1246 field_values[CREDIT_CARD_EXP_MONTH], | 1250 field_values[CREDIT_CARD_EXP_MONTH], |
| 1247 base::Time::Now())) { | 1251 base::Time::Now())) { |
| 1252 invalid_expiration = true; | |
| 1253 } else if (validation_type == VALIDATE_SELECT && IsPayingWithWallet()) { | |
|
Evan Stade
2013/05/31 23:06:45
instead of VALIDATE_SELECT, can you check if input
Evan Stade
2013/05/31 23:06:45
It also might be easier to read if you moved the i
Dan Beam
2013/06/01 00:23:06
Done.
Dan Beam
2013/06/01 00:23:06
Done.
| |
| 1254 std::map<DialogSection, bool>::const_iterator it = | |
| 1255 section_editing_state_.find(SECTION_CC_BILLING); | |
| 1256 if (it != section_editing_state_.end() && it->second) { | |
| 1257 const SuggestionsMenuModel* model = | |
| 1258 SuggestionsMenuModelForSection(SECTION_CC_BILLING); | |
| 1259 int instrument_index = -1; | |
| 1260 base::StringToInt(model->GetItemKeyForCheckedItem(), &instrument_index); | |
| 1261 if (wallet_items_->instruments()[instrument_index]->status() == | |
| 1262 wallet::WalletItems::MaskedInstrument::EXPIRED) { | |
| 1263 // Otherwise, if the user is editing an instrument that's deemed | |
| 1264 // expired by the Online Wallet server, mark it invalid on selection. | |
| 1265 invalid_expiration = true; | |
| 1266 } | |
| 1267 } | |
| 1268 } | |
| 1269 | |
| 1270 if (invalid_expiration) { | |
| 1248 invalid_messages[CREDIT_CARD_EXP_MONTH] = | 1271 invalid_messages[CREDIT_CARD_EXP_MONTH] = |
| 1249 ASCIIToUTF16("more complicated message"); | 1272 ASCIIToUTF16("more complicated message"); |
| 1250 invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] = | 1273 invalid_messages[CREDIT_CARD_EXP_4_DIGIT_YEAR] = |
| 1251 ASCIIToUTF16("more complicated message"); | 1274 ASCIIToUTF16("more complicated message"); |
| 1252 } | 1275 } |
| 1253 } | 1276 } |
| 1254 | 1277 |
| 1255 // If there is a credit card number and a CVC, validate them together. | 1278 // If there is a credit card number and a CVC, validate them together. |
| 1256 if (field_values.count(CREDIT_CARD_NUMBER) && | 1279 if (field_values.count(CREDIT_CARD_NUMBER) && |
| 1257 field_values.count(CREDIT_CARD_VERIFICATION_CODE) && | 1280 field_values.count(CREDIT_CARD_VERIFICATION_CODE) && |
| (...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2876 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 2899 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
| 2877 } | 2900 } |
| 2878 | 2901 |
| 2879 // Has Wallet items. | 2902 // Has Wallet items. |
| 2880 return has_autofill_profiles ? | 2903 return has_autofill_profiles ? |
| 2881 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 2904 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
| 2882 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 2905 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
| 2883 } | 2906 } |
| 2884 | 2907 |
| 2885 } // namespace autofill | 2908 } // namespace autofill |
| OLD | NEW |