OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" | 5 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 218 |
219 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { | 219 base::string16 CardUnmaskPromptControllerImpl::GetWindowTitle() const { |
220 #if defined(OS_IOS) | 220 #if defined(OS_IOS) |
221 // The iOS UI has less room for the title so it shows a shorter string. | 221 // The iOS UI has less room for the title so it shows a shorter string. |
222 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE); | 222 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE); |
223 #else | 223 #else |
224 return l10n_util::GetStringFUTF16( | 224 return l10n_util::GetStringFUTF16( |
225 ShouldRequestExpirationDate() | 225 ShouldRequestExpirationDate() |
226 ? IDS_AUTOFILL_CARD_UNMASK_PROMPT_EXPIRED_TITLE | 226 ? IDS_AUTOFILL_CARD_UNMASK_PROMPT_EXPIRED_TITLE |
227 : IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE, | 227 : IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE, |
228 card_.TypeAndLastFourDigits()); | 228 card_.NetworkAndLastFourDigits()); |
229 #endif | 229 #endif |
230 } | 230 } |
231 | 231 |
232 base::string16 CardUnmaskPromptControllerImpl::GetInstructionsMessage() const { | 232 base::string16 CardUnmaskPromptControllerImpl::GetInstructionsMessage() const { |
233 #if defined(OS_IOS) | 233 #if defined(OS_IOS) |
234 int ids; | 234 int ids; |
235 if (reason_ == AutofillClient::UNMASK_FOR_AUTOFILL && | 235 if (reason_ == AutofillClient::UNMASK_FOR_AUTOFILL && |
236 ShouldRequestExpirationDate()) { | 236 ShouldRequestExpirationDate()) { |
237 ids = IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS_EXPIRED; | 237 ids = IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS_EXPIRED; |
238 } else { | 238 } else { |
239 ids = IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS; | 239 ids = IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS; |
240 } | 240 } |
241 // The iOS UI shows the card details in the instructions text since they | 241 // The iOS UI shows the card details in the instructions text since they |
242 // don't fit in the title. | 242 // don't fit in the title. |
243 return l10n_util::GetStringFUTF16(ids, card_.TypeAndLastFourDigits()); | 243 return l10n_util::GetStringFUTF16(ids, card_.NetworkAndLastFourDigits()); |
244 #else | 244 #else |
245 return l10n_util::GetStringUTF16( | 245 return l10n_util::GetStringUTF16( |
246 IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS); | 246 IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS); |
247 #endif | 247 #endif |
248 } | 248 } |
249 | 249 |
250 base::string16 CardUnmaskPromptControllerImpl::GetOkButtonLabel() const { | 250 base::string16 CardUnmaskPromptControllerImpl::GetOkButtonLabel() const { |
251 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_CONFIRM_BUTTON); | 251 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_CONFIRM_BUTTON); |
252 } | 252 } |
253 | 253 |
254 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { | 254 int CardUnmaskPromptControllerImpl::GetCvcImageRid() const { |
255 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX | 255 return card_.network() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX |
256 : IDR_CREDIT_CARD_CVC_HINT; | 256 : IDR_CREDIT_CARD_CVC_HINT; |
257 } | 257 } |
258 | 258 |
259 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { | 259 bool CardUnmaskPromptControllerImpl::ShouldRequestExpirationDate() const { |
260 return card_.ShouldUpdateExpiration(AutofillClock::Now()) || | 260 return card_.ShouldUpdateExpiration(AutofillClock::Now()) || |
261 new_card_link_clicked_; | 261 new_card_link_clicked_; |
262 } | 262 } |
263 | 263 |
264 bool CardUnmaskPromptControllerImpl::CanStoreLocally() const { | 264 bool CardUnmaskPromptControllerImpl::CanStoreLocally() const { |
265 // Never offer to save for incognito. | 265 // Never offer to save for incognito. |
266 if (is_off_the_record_) | 266 if (is_off_the_record_) |
267 return false; | 267 return false; |
268 if (reason_ == AutofillClient::UNMASK_FOR_PAYMENT_REQUEST) | 268 if (reason_ == AutofillClient::UNMASK_FOR_PAYMENT_REQUEST) |
269 return false; | 269 return false; |
270 if (card_.record_type() == CreditCard::LOCAL_CARD) | 270 if (card_.record_type() == CreditCard::LOCAL_CARD) |
271 return false; | 271 return false; |
272 return OfferStoreUnmaskedCards(); | 272 return OfferStoreUnmaskedCards(); |
273 } | 273 } |
274 | 274 |
275 bool CardUnmaskPromptControllerImpl::GetStoreLocallyStartState() const { | 275 bool CardUnmaskPromptControllerImpl::GetStoreLocallyStartState() const { |
276 return pref_service_->GetBoolean( | 276 return pref_service_->GetBoolean( |
277 prefs::kAutofillWalletImportStorageCheckboxState); | 277 prefs::kAutofillWalletImportStorageCheckboxState); |
278 } | 278 } |
279 | 279 |
280 bool CardUnmaskPromptControllerImpl::InputCvcIsValid( | 280 bool CardUnmaskPromptControllerImpl::InputCvcIsValid( |
281 const base::string16& input_text) const { | 281 const base::string16& input_text) const { |
282 base::string16 trimmed_text; | 282 base::string16 trimmed_text; |
283 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); | 283 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); |
284 return IsValidCreditCardSecurityCode(trimmed_text, card_.type()); | 284 return IsValidCreditCardSecurityCode(trimmed_text, card_.network()); |
285 } | 285 } |
286 | 286 |
287 bool CardUnmaskPromptControllerImpl::InputExpirationIsValid( | 287 bool CardUnmaskPromptControllerImpl::InputExpirationIsValid( |
288 const base::string16& month, | 288 const base::string16& month, |
289 const base::string16& year) const { | 289 const base::string16& year) const { |
290 if ((month.size() != 2U && month.size() != 1U) || | 290 if ((month.size() != 2U && month.size() != 1U) || |
291 (year.size() != 4U && year.size() != 2U)) { | 291 (year.size() != 4U && year.size() != 2U)) { |
292 return false; | 292 return false; |
293 } | 293 } |
294 | 294 |
295 int month_value = 0, year_value = 0; | 295 int month_value = 0, year_value = 0; |
296 if (!base::StringToInt(month, &month_value) || | 296 if (!base::StringToInt(month, &month_value) || |
297 !base::StringToInt(year, &year_value)) { | 297 !base::StringToInt(year, &year_value)) { |
298 return false; | 298 return false; |
299 } | 299 } |
300 | 300 |
301 // Convert 2 digit year to 4 digit year. | 301 // Convert 2 digit year to 4 digit year. |
302 if (year_value < 100) { | 302 if (year_value < 100) { |
303 base::Time::Exploded now; | 303 base::Time::Exploded now; |
304 AutofillClock::Now().LocalExplode(&now); | 304 AutofillClock::Now().LocalExplode(&now); |
305 year_value += (now.year / 100) * 100; | 305 year_value += (now.year / 100) * 100; |
306 } | 306 } |
307 | 307 |
308 return IsValidCreditCardExpirationDate(year_value, month_value, | 308 return IsValidCreditCardExpirationDate(year_value, month_value, |
309 AutofillClock::Now()); | 309 AutofillClock::Now()); |
310 } | 310 } |
311 | 311 |
312 int CardUnmaskPromptControllerImpl::GetExpectedCvcLength() const { | 312 int CardUnmaskPromptControllerImpl::GetExpectedCvcLength() const { |
313 return GetCvcLengthForCardType(card_.type()); | 313 return GetCvcLengthForCardType(card_.network()); |
314 } | 314 } |
315 | 315 |
316 base::TimeDelta CardUnmaskPromptControllerImpl::GetSuccessMessageDuration() | 316 base::TimeDelta CardUnmaskPromptControllerImpl::GetSuccessMessageDuration() |
317 const { | 317 const { |
318 return base::TimeDelta::FromMilliseconds( | 318 return base::TimeDelta::FromMilliseconds( |
319 card_.record_type() == CreditCard::LOCAL_CARD || | 319 card_.record_type() == CreditCard::LOCAL_CARD || |
320 reason_ == AutofillClient::UNMASK_FOR_PAYMENT_REQUEST | 320 reason_ == AutofillClient::UNMASK_FOR_PAYMENT_REQUEST |
321 ? 0 : 500); | 321 ? 0 : 500); |
322 } | 322 } |
323 | 323 |
324 } // namespace autofill | 324 } // namespace autofill |
OLD | NEW |