OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/autofill/credit_card.h" | 5 #include "chrome/browser/autofill/credit_card.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/autofill/autofill_type.h" | 9 #include "chrome/browser/autofill/autofill_type.h" |
10 #include "chrome/browser/autofill/field_types.h" | 10 #include "chrome/browser/autofill/field_types.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return Expiration2DigitYearAsString(); | 106 return Expiration2DigitYearAsString(); |
107 | 107 |
108 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 108 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
109 return Expiration4DigitYearAsString(); | 109 return Expiration4DigitYearAsString(); |
110 | 110 |
111 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: { | 111 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: { |
112 string16 month = ExpirationMonthAsString(); | 112 string16 month = ExpirationMonthAsString(); |
113 string16 year = Expiration2DigitYearAsString(); | 113 string16 year = Expiration2DigitYearAsString(); |
114 if (!month.empty() && !year.empty()) | 114 if (!month.empty() && !year.empty()) |
115 return month + ASCIIToUTF16("/") + year; | 115 return month + ASCIIToUTF16("/") + year; |
116 return EmptyString16(); | 116 return string16(); |
117 } | 117 } |
118 | 118 |
119 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { | 119 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { |
120 string16 month = ExpirationMonthAsString(); | 120 string16 month = ExpirationMonthAsString(); |
121 string16 year = Expiration4DigitYearAsString(); | 121 string16 year = Expiration4DigitYearAsString(); |
122 if (!month.empty() && !year.empty()) | 122 if (!month.empty() && !year.empty()) |
123 return month + ASCIIToUTF16("/") + year; | 123 return month + ASCIIToUTF16("/") + year; |
124 return EmptyString16(); | 124 return string16(); |
125 } | 125 } |
126 | 126 |
127 case CREDIT_CARD_TYPE: | 127 case CREDIT_CARD_TYPE: |
128 return this->type(); | 128 return this->type(); |
129 | 129 |
130 case CREDIT_CARD_NUMBER: | 130 case CREDIT_CARD_NUMBER: |
131 return number(); | 131 return number(); |
132 | 132 |
133 case CREDIT_CARD_VERIFICATION_CODE: | 133 case CREDIT_CARD_VERIFICATION_CODE: |
134 return verification_code(); | 134 return verification_code(); |
135 | 135 |
136 default: | 136 default: |
137 // ComputeDataPresentForArray will hit this repeatedly. | 137 // ComputeDataPresentForArray will hit this repeatedly. |
138 return EmptyString16(); | 138 return string16(); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 string16 CreditCard::GetPreviewText(const AutoFillType& type) const { | 142 string16 CreditCard::GetPreviewText(const AutoFillType& type) const { |
143 switch (type.field_type()) { | 143 switch (type.field_type()) { |
144 case CREDIT_CARD_NUMBER: | 144 case CREDIT_CARD_NUMBER: |
145 return last_four_digits(); | 145 return last_four_digits(); |
146 | 146 |
147 case CREDIT_CARD_VERIFICATION_CODE: | 147 case CREDIT_CARD_VERIFICATION_CODE: |
148 return ASCIIToUTF16("xxx"); | 148 return ASCIIToUTF16("xxx"); |
(...skipping 30 matching lines...) Expand all Loading... |
179 break; | 179 break; |
180 | 180 |
181 default: | 181 default: |
182 DLOG(ERROR) << "Attempting to set unknown info-type"; | 182 DLOG(ERROR) << "Attempting to set unknown info-type"; |
183 break; | 183 break; |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 string16 CreditCard::ExpirationMonthAsString() const { | 187 string16 CreditCard::ExpirationMonthAsString() const { |
188 if (expiration_month_ == 0) | 188 if (expiration_month_ == 0) |
189 return EmptyString16(); | 189 return string16(); |
190 | 190 |
191 string16 month = IntToString16(expiration_month_); | 191 string16 month = IntToString16(expiration_month_); |
192 if (expiration_month_ >= 10) | 192 if (expiration_month_ >= 10) |
193 return month; | 193 return month; |
194 | 194 |
195 string16 zero = ASCIIToUTF16("0"); | 195 string16 zero = ASCIIToUTF16("0"); |
196 zero.append(month); | 196 zero.append(month); |
197 return zero; | 197 return zero; |
198 } | 198 } |
199 | 199 |
200 string16 CreditCard::Expiration4DigitYearAsString() const { | 200 string16 CreditCard::Expiration4DigitYearAsString() const { |
201 if (expiration_year_ == 0) | 201 if (expiration_year_ == 0) |
202 return EmptyString16(); | 202 return string16(); |
203 | 203 |
204 return IntToString16(Expiration4DigitYear()); | 204 return IntToString16(Expiration4DigitYear()); |
205 } | 205 } |
206 | 206 |
207 string16 CreditCard::Expiration2DigitYearAsString() const { | 207 string16 CreditCard::Expiration2DigitYearAsString() const { |
208 if (expiration_year_ == 0) | 208 if (expiration_year_ == 0) |
209 return EmptyString16(); | 209 return string16(); |
210 | 210 |
211 return IntToString16(Expiration2DigitYear()); | 211 return IntToString16(Expiration2DigitYear()); |
212 } | 212 } |
213 | 213 |
214 void CreditCard::SetExpirationMonthFromString(const string16& text) { | 214 void CreditCard::SetExpirationMonthFromString(const string16& text) { |
215 int month; | 215 int month; |
216 if (!ConvertDate(text, &month)) | 216 if (!ConvertDate(text, &month)) |
217 return; | 217 return; |
218 | 218 |
219 set_expiration_month(month); | 219 set_expiration_month(month); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 DCHECK(converted); | 388 DCHECK(converted); |
389 if (!converted) | 389 if (!converted) |
390 return false; | 390 return false; |
391 } else { | 391 } else { |
392 // Clear the value. | 392 // Clear the value. |
393 *num = 0; | 393 *num = 0; |
394 } | 394 } |
395 | 395 |
396 return true; | 396 return true; |
397 } | 397 } |
OLD | NEW |