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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 if (!credit_card_to_edit_ || type == kBillingAddressType) | 401 if (!credit_card_to_edit_ || type == kBillingAddressType) |
402 return base::string16(); | 402 return base::string16(); |
403 | 403 |
404 base::string16 info = credit_card_to_edit_->GetInfo( | 404 base::string16 info = credit_card_to_edit_->GetInfo( |
405 autofill::AutofillType(type), state()->GetApplicationLocale()); | 405 autofill::AutofillType(type), state()->GetApplicationLocale()); |
406 | 406 |
407 return type == autofill::CREDIT_CARD_NUMBER ? FormatCardNumber(info) : info; | 407 return type == autofill::CREDIT_CARD_NUMBER ? FormatCardNumber(info) : info; |
408 } | 408 } |
409 | 409 |
410 bool CreditCardEditorViewController::ValidateModelAndSave() { | 410 bool CreditCardEditorViewController::ValidateModelAndSave() { |
411 const std::string& locale = state()->GetApplicationLocale(); | 411 const std::string& locale = state()->GetApplicationLocale(); |
Mathieu
2017/05/29 16:45:36
this function changed a little bit recently, can y
tmartino
2017/05/29 21:06:58
Done
| |
412 // Use a temporary object for validation. | 412 // Use a temporary object for validation. |
413 autofill::CreditCard credit_card; | 413 autofill::CreditCard credit_card; |
414 credit_card.set_origin(autofill::kSettingsOrigin); | 414 credit_card.set_origin(autofill::kSettingsOrigin); |
415 | 415 |
416 if (!ValidateModel()) { | |
417 return false; | |
418 } | |
419 | |
416 for (const auto& field : text_fields()) { | 420 for (const auto& field : text_fields()) { |
417 // ValidatingTextfield* is the key, EditorField is the value. | 421 // ValidatingTextfield* is the key, EditorField is the value. |
418 DCHECK_EQ(autofill::CREDIT_CARD, | 422 DCHECK_EQ(autofill::CREDIT_CARD, |
419 autofill::AutofillType(field.second.type).group()); | 423 autofill::AutofillType(field.second.type).group()); |
420 if (field.first->invalid()) | |
421 return false; | |
422 | |
423 credit_card.SetInfo(autofill::AutofillType(field.second.type), | 424 credit_card.SetInfo(autofill::AutofillType(field.second.type), |
424 field.first->text(), locale); | 425 field.first->text(), locale); |
425 } | 426 } |
426 for (const auto& field : comboboxes()) { | 427 for (const auto& field : comboboxes()) { |
427 // ValidatingCombobox* is the key, EditorField is the value. | 428 // ValidatingCombobox* is the key, EditorField is the value. |
428 ValidatingCombobox* combobox = field.first; | 429 ValidatingCombobox* combobox = field.first; |
429 if (combobox->invalid()) | |
430 return false; | |
431 | 430 |
432 if (field.second.type == kBillingAddressType) { | 431 if (field.second.type == kBillingAddressType) { |
433 views::Combobox* address_combobox = static_cast<views::Combobox*>( | 432 views::Combobox* address_combobox = static_cast<views::Combobox*>( |
434 dialog()->GetViewByID(GetInputFieldViewId(kBillingAddressType))); | 433 dialog()->GetViewByID(GetInputFieldViewId(kBillingAddressType))); |
435 autofill::AddressComboboxModel* model = | 434 autofill::AddressComboboxModel* model = |
436 static_cast<autofill::AddressComboboxModel*>( | 435 static_cast<autofill::AddressComboboxModel*>( |
437 address_combobox->model()); | 436 address_combobox->model()); |
438 | 437 |
439 credit_card.set_billing_address_id( | 438 credit_card.set_billing_address_id( |
440 model->GetItemIdentifierAt(address_combobox->selected_index())); | 439 model->GetItemIdentifierAt(address_combobox->selected_index())); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()), | 738 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()), |
740 error_message); | 739 error_message); |
741 } | 740 } |
742 | 741 |
743 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) { | 742 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) { |
744 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET; | 743 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET; |
745 return true; | 744 return true; |
746 } | 745 } |
747 | 746 |
748 } // namespace payments | 747 } // namespace payments |
OLD | NEW |