| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/views/payments/cvc_unmask_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 CvcUnmaskViewController::CvcUnmaskViewController( | 47 CvcUnmaskViewController::CvcUnmaskViewController( |
| 48 PaymentRequestSpec* spec, | 48 PaymentRequestSpec* spec, |
| 49 PaymentRequestState* state, | 49 PaymentRequestState* state, |
| 50 PaymentRequestDialogView* dialog, | 50 PaymentRequestDialogView* dialog, |
| 51 const autofill::CreditCard& credit_card, | 51 const autofill::CreditCard& credit_card, |
| 52 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate> | 52 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate> |
| 53 result_delegate, | 53 result_delegate, |
| 54 content::WebContents* web_contents) | 54 content::WebContents* web_contents) |
| 55 : PaymentRequestSheetController(spec, state, dialog), | 55 : PaymentRequestSheetController(spec, state, dialog), |
| 56 year_combobox_model_(credit_card.expiration_year()), |
| 56 credit_card_(credit_card), | 57 credit_card_(credit_card), |
| 57 web_contents_(web_contents), | 58 web_contents_(web_contents), |
| 58 payments_client_( | 59 payments_client_( |
| 59 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 60 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 60 ->GetRequestContext(), | 61 ->GetRequestContext(), |
| 61 this), | 62 this), |
| 62 full_card_request_(this, | 63 full_card_request_(this, |
| 63 &payments_client_, | 64 &payments_client_, |
| 64 state->GetPersonalDataManager()), | 65 state->GetPersonalDataManager()), |
| 65 weak_ptr_factory_(this) { | 66 weak_ptr_factory_(this) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // CVC field | 199 // CVC field |
| 199 cvc_field_columns->AddColumn(views::GridLayout::Alignment::FILL, | 200 cvc_field_columns->AddColumn(views::GridLayout::Alignment::FILL, |
| 200 views::GridLayout::Alignment::BASELINE, 0, | 201 views::GridLayout::Alignment::BASELINE, 0, |
| 201 views::GridLayout::SizeType::FIXED, 80, 80); | 202 views::GridLayout::SizeType::FIXED, 80, 80); |
| 202 | 203 |
| 203 layout->StartRow(0, 1); | 204 layout->StartRow(0, 1); |
| 204 if (requesting_expiration) { | 205 if (requesting_expiration) { |
| 205 auto month = base::MakeUnique<views::Combobox>(&month_combobox_model_); | 206 auto month = base::MakeUnique<views::Combobox>(&month_combobox_model_); |
| 206 month->set_listener(this); | 207 month->set_listener(this); |
| 207 month->set_id(static_cast<int>(DialogViewID::CVC_MONTH)); | 208 month->set_id(static_cast<int>(DialogViewID::CVC_MONTH)); |
| 209 month->SelectValue(credit_card_.ExpirationMonthAsString()); |
| 210 month->SetInvalid(true); |
| 208 layout->AddView(month.release()); | 211 layout->AddView(month.release()); |
| 209 | 212 |
| 210 auto year = base::MakeUnique<views::Combobox>(&year_combobox_model_); | 213 auto year = base::MakeUnique<views::Combobox>(&year_combobox_model_); |
| 211 year->set_listener(this); | 214 year->set_listener(this); |
| 212 year->set_id(static_cast<int>(DialogViewID::CVC_YEAR)); | 215 year->set_id(static_cast<int>(DialogViewID::CVC_YEAR)); |
| 216 year->SelectValue(credit_card_.Expiration4DigitYearAsString()); |
| 217 year->SetInvalid(true); |
| 213 layout->AddView(year.release()); | 218 layout->AddView(year.release()); |
| 214 } | 219 } |
| 215 | 220 |
| 216 std::unique_ptr<views::ImageView> cvc_image = | 221 std::unique_ptr<views::ImageView> cvc_image = |
| 217 base::MakeUnique<views::ImageView>(); | 222 base::MakeUnique<views::ImageView>(); |
| 218 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 223 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 219 // TODO(anthonyvd): Consider using | 224 // TODO(anthonyvd): Consider using |
| 220 // CardUnmaskPromptControllerImpl::GetCvcImageRid. | 225 // CardUnmaskPromptControllerImpl::GetCvcImageRid. |
| 221 cvc_image->SetImage(rb.GetImageSkiaNamed( | 226 cvc_image->SetImage(rb.GetImageSkiaNamed( |
| 222 credit_card_.network() == autofill::kAmericanExpressCard | 227 credit_card_.network() == autofill::kAmericanExpressCard |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } else { | 340 } else { |
| 336 // Convert 2 digit year to 4 digit year. | 341 // Convert 2 digit year to 4 digit year. |
| 337 if (year_value < 100) { | 342 if (year_value < 100) { |
| 338 base::Time::Exploded now; | 343 base::Time::Exploded now; |
| 339 autofill::AutofillClock::Now().LocalExplode(&now); | 344 autofill::AutofillClock::Now().LocalExplode(&now); |
| 340 year_value += (now.year / 100) * 100; | 345 year_value += (now.year / 100) * 100; |
| 341 } | 346 } |
| 342 | 347 |
| 343 expiration_date_valid = autofill::IsValidCreditCardExpirationDate( | 348 expiration_date_valid = autofill::IsValidCreditCardExpirationDate( |
| 344 year_value, month_value, autofill::AutofillClock::Now()); | 349 year_value, month_value, autofill::AutofillClock::Now()); |
| 350 |
| 351 month->SetInvalid(!expiration_date_valid); |
| 352 year->SetInvalid(!expiration_date_valid); |
| 345 } | 353 } |
| 346 } | 354 } |
| 347 | 355 |
| 348 primary_button()->SetEnabled(cvc_valid && expiration_date_valid); | 356 primary_button()->SetEnabled(cvc_valid && expiration_date_valid); |
| 349 } | 357 } |
| 350 | 358 |
| 351 bool CvcUnmaskViewController::GetSheetId(DialogViewID* sheet_id) { | 359 bool CvcUnmaskViewController::GetSheetId(DialogViewID* sheet_id) { |
| 352 *sheet_id = DialogViewID::CVC_UNMASK_SHEET; | 360 *sheet_id = DialogViewID::CVC_UNMASK_SHEET; |
| 353 return true; | 361 return true; |
| 354 } | 362 } |
| 355 | 363 |
| 356 views::View* CvcUnmaskViewController::GetFirstFocusedView() { | 364 views::View* CvcUnmaskViewController::GetFirstFocusedView() { |
| 357 return cvc_field_; | 365 return cvc_field_; |
| 358 } | 366 } |
| 359 | 367 |
| 360 void CvcUnmaskViewController::ContentsChanged( | 368 void CvcUnmaskViewController::ContentsChanged( |
| 361 views::Textfield* sender, | 369 views::Textfield* sender, |
| 362 const base::string16& new_contents) { | 370 const base::string16& new_contents) { |
| 363 UpdatePayButtonState(); | 371 UpdatePayButtonState(); |
| 364 } | 372 } |
| 365 | 373 |
| 366 void CvcUnmaskViewController::OnPerformAction(views::Combobox* combobox) { | 374 void CvcUnmaskViewController::OnPerformAction(views::Combobox* combobox) { |
| 367 UpdatePayButtonState(); | 375 UpdatePayButtonState(); |
| 368 } | 376 } |
| 369 | 377 |
| 370 } // namespace payments | 378 } // namespace payments |
| OLD | NEW |