| 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/credit_card_editor_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 base::Time::Exploded now_exploded; | 83 base::Time::Exploded now_exploded; |
| 84 autofill::AutofillClock::Now().LocalExplode(&now_exploded); | 84 autofill::AutofillClock::Now().LocalExplode(&now_exploded); |
| 85 for (int i = 0; i < kNumberOfExpirationYears; i++) { | 85 for (int i = 0; i < kNumberOfExpirationYears; i++) { |
| 86 years.push_back(base::UTF8ToUTF16(std::to_string(now_exploded.year + i))); | 86 years.push_back(base::UTF8ToUTF16(std::to_string(now_exploded.year + i))); |
| 87 } | 87 } |
| 88 return years; | 88 return years; |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool IsCardExpired(const base::string16& month, | 91 bool IsCardExpired(const base::string16& month, |
| 92 base::string16& year, | 92 const base::string16& year, |
| 93 const std::string& app_locale) { | 93 const std::string& app_locale) { |
| 94 autofill::CreditCard card; | 94 autofill::CreditCard card; |
| 95 card.SetExpirationMonthFromString(month, app_locale); | 95 card.SetExpirationMonthFromString(month, app_locale); |
| 96 card.SetExpirationYearFromString(year); | 96 card.SetExpirationYearFromString(year); |
| 97 return card.IsExpired(autofill::AutofillClock::Now()); | 97 return card.IsExpired(autofill::AutofillClock::Now()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Validates the two comboboxes used for expiration date. | 100 // Validates the two comboboxes used for expiration date. |
| 101 class ExpirationDateValidationDelegate : public ValidationDelegate { | 101 class ExpirationDateValidationDelegate : public ValidationDelegate { |
| 102 public: | 102 public: |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 &CreditCardEditorViewController::AddAndSelectNewBillingAddress, | 495 &CreditCardEditorViewController::AddAndSelectNewBillingAddress, |
| 496 base::Unretained(this)), | 496 base::Unretained(this)), |
| 497 /*profile=*/nullptr); | 497 /*profile=*/nullptr); |
| 498 } else { | 498 } else { |
| 499 EditorViewController::ButtonPressed(sender, event); | 499 EditorViewController::ButtonPressed(sender, event); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 | 502 |
| 503 void CreditCardEditorViewController::AddAndSelectNewBillingAddress( | 503 void CreditCardEditorViewController::AddAndSelectNewBillingAddress( |
| 504 const autofill::AutofillProfile& profile) { | 504 const autofill::AutofillProfile& profile) { |
| 505 state()->AddAutofillShippingProfile(false, profile); |
| 505 views::Combobox* address_combobox = static_cast<views::Combobox*>( | 506 views::Combobox* address_combobox = static_cast<views::Combobox*>( |
| 506 dialog()->GetViewByID(GetInputFieldViewId(kBillingAddressType))); | 507 dialog()->GetViewByID(GetInputFieldViewId(kBillingAddressType))); |
| 507 autofill::AddressComboboxModel* model = | 508 autofill::AddressComboboxModel* model = |
| 508 static_cast<autofill::AddressComboboxModel*>(address_combobox->model()); | 509 static_cast<autofill::AddressComboboxModel*>(address_combobox->model()); |
| 509 int index = model->AddNewProfile(profile); | 510 int index = model->AddNewProfile(profile); |
| 510 // SetSelectedIndex doesn't trigger a perform action notification, which is | 511 // SetSelectedIndex doesn't trigger a perform action notification, which is |
| 511 // needed to update the valid state. | 512 // needed to update the valid state. |
| 512 address_combobox->SetSelectedRow(index); | 513 address_combobox->SetSelectedRow(index); |
| 513 // But it needs to be blured at least once. | 514 // But it needs to be blured at least once. |
| 514 address_combobox->OnBlur(); | 515 address_combobox->OnBlur(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()), | 596 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()), |
| 596 error_message); | 597 error_message); |
| 597 } | 598 } |
| 598 | 599 |
| 599 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) { | 600 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) { |
| 600 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET; | 601 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET; |
| 601 return true; | 602 return true; |
| 602 } | 603 } |
| 603 | 604 |
| 604 } // namespace payments | 605 } // namespace payments |
| OLD | NEW |