| 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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_CREDIT_CARD_EDITOR_VIEW_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_CREDIT_CARD_EDITOR_VIEW_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_CREDIT_CARD_EDITOR_VIEW_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_CREDIT_CARD_EDITOR_VIEW_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 autofill::ServerFieldType type) override; | 56 autofill::ServerFieldType type) override; |
| 57 std::vector<EditorField> GetFieldDefinitions() override; | 57 std::vector<EditorField> GetFieldDefinitions() override; |
| 58 base::string16 GetInitialValueForType( | 58 base::string16 GetInitialValueForType( |
| 59 autofill::ServerFieldType type) override; | 59 autofill::ServerFieldType type) override; |
| 60 bool ValidateModelAndSave() override; | 60 bool ValidateModelAndSave() override; |
| 61 std::unique_ptr<ValidationDelegate> CreateValidationDelegate( | 61 std::unique_ptr<ValidationDelegate> CreateValidationDelegate( |
| 62 const EditorField& field) override; | 62 const EditorField& field) override; |
| 63 std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( | 63 std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( |
| 64 const autofill::ServerFieldType& type) override; | 64 const autofill::ServerFieldType& type) override; |
| 65 | 65 |
| 66 // Exposed for validation delegate. |
| 67 bool IsValidCreditCardNumber(const base::string16& card_number, |
| 68 base::string16* error_message); |
| 69 |
| 66 protected: | 70 protected: |
| 67 // PaymentRequestSheetController: | 71 // PaymentRequestSheetController: |
| 68 void FillContentView(views::View* content_view) override; | 72 void FillContentView(views::View* content_view) override; |
| 69 base::string16 GetSheetTitle() override; | 73 base::string16 GetSheetTitle() override; |
| 70 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 74 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 71 | 75 |
| 72 private: | 76 private: |
| 73 class CreditCardValidationDelegate : public ValidationDelegate { | 77 class CreditCardValidationDelegate : public ValidationDelegate { |
| 74 public: | 78 public: |
| 75 // Used to validate |field| type. A reference to the |controller| should | 79 // Used to validate |field| type. A reference to the |controller| should |
| 76 // outlive this delegate, and a list of |supported_card_networks| can be | 80 // outlive this delegate. |
| 77 // passed in to validate |field| (the data will be copied to the delegate). | 81 CreditCardValidationDelegate(const EditorField& field, |
| 78 CreditCardValidationDelegate( | 82 CreditCardEditorViewController* controller); |
| 79 const EditorField& field, | |
| 80 EditorViewController* controller, | |
| 81 const std::vector<std::string>& supported_card_networks); | |
| 82 ~CreditCardValidationDelegate() override; | 83 ~CreditCardValidationDelegate() override; |
| 83 | 84 |
| 84 // ValidationDelegate: | 85 // ValidationDelegate: |
| 85 bool IsValidTextfield(views::Textfield* textfield) override; | 86 bool IsValidTextfield(views::Textfield* textfield) override; |
| 86 bool IsValidCombobox(views::Combobox* combobox) override; | 87 bool IsValidCombobox(views::Combobox* combobox) override; |
| 87 bool TextfieldValueChanged(views::Textfield* textfield) override; | 88 bool TextfieldValueChanged(views::Textfield* textfield) override; |
| 88 bool ComboboxValueChanged(views::Combobox* combobox) override; | 89 bool ComboboxValueChanged(views::Combobox* combobox) override; |
| 89 void ComboboxModelChanged(views::Combobox* combobox) override {} | 90 void ComboboxModelChanged(views::Combobox* combobox) override {} |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 // Validates a specific |value|/|combobox|. | 93 // Validates a specific |value|/|combobox|. |
| 93 bool ValidateValue(const base::string16& value, | 94 bool ValidateValue(const base::string16& value, |
| 94 base::string16* error_message); | 95 base::string16* error_message); |
| 95 bool ValidateCombobox(views::Combobox* combobox, | 96 bool ValidateCombobox(views::Combobox* combobox, |
| 96 base::string16* error_message); | 97 base::string16* error_message); |
| 97 | 98 |
| 98 EditorField field_; | 99 EditorField field_; |
| 99 // Outlives this class. | 100 // Outlives this class. |
| 100 EditorViewController* controller_; | 101 CreditCardEditorViewController* controller_; |
| 101 // The list of supported basic card networks. | |
| 102 std::set<std::string> supported_card_networks_; | |
| 103 | 102 |
| 104 DISALLOW_COPY_AND_ASSIGN(CreditCardValidationDelegate); | 103 DISALLOW_COPY_AND_ASSIGN(CreditCardValidationDelegate); |
| 105 }; | 104 }; |
| 106 | 105 |
| 107 bool GetSheetId(DialogViewID* sheet_id) override; | 106 bool GetSheetId(DialogViewID* sheet_id) override; |
| 108 | 107 |
| 109 // Called when a new address was created to be used as the billing address. | 108 // Called when a new address was created to be used as the billing address. |
| 110 // The lifespan of |profile| beyond this call is undefined but it's OK, it's | 109 // The lifespan of |profile| beyond this call is undefined but it's OK, it's |
| 111 // simply propagated to the address combobox model. | 110 // simply propagated to the address combobox model. |
| 112 void AddAndSelectNewBillingAddress(const autofill::AutofillProfile& profile); | 111 void AddAndSelectNewBillingAddress(const autofill::AutofillProfile& profile); |
| 113 | 112 |
| 114 // Called when |credit_card_to_edit_| was successfully edited. | 113 // Called when |credit_card_to_edit_| was successfully edited. |
| 115 base::OnceClosure on_edited_; | 114 base::OnceClosure on_edited_; |
| 116 // Called when a new card was added. The const reference is short-lived, and | 115 // Called when a new card was added. The const reference is short-lived, and |
| 117 // the callee should make a copy. | 116 // the callee should make a copy. |
| 118 base::OnceCallback<void(const autofill::CreditCard&)> on_added_; | 117 base::OnceCallback<void(const autofill::CreditCard&)> on_added_; |
| 119 | 118 |
| 120 // If non-nullptr, a pointer to an object to be edited. Must outlive this | 119 // If non-nullptr, a pointer to an object to be edited. Must outlive this |
| 121 // controller. | 120 // controller. |
| 122 autofill::CreditCard* credit_card_to_edit_; | 121 autofill::CreditCard* credit_card_to_edit_; |
| 123 | 122 |
| 124 // The value to use for the add billing address button tag. | 123 // The value to use for the add billing address button tag. |
| 125 int add_billing_address_button_tag_; | 124 int add_billing_address_button_tag_; |
| 126 | 125 |
| 126 // The list of supported basic card networks. |
| 127 std::set<std::string> supported_card_networks_; |
| 128 |
| 127 DISALLOW_COPY_AND_ASSIGN(CreditCardEditorViewController); | 129 DISALLOW_COPY_AND_ASSIGN(CreditCardEditorViewController); |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 } // namespace payments | 132 } // namespace payments |
| 131 | 133 |
| 132 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_CREDIT_CARD_EDITOR_VIEW_CONTROLLER_H
_ | 134 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_CREDIT_CARD_EDITOR_VIEW_CONTROLLER_H
_ |
| OLD | NEW |