| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_ |
| 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_ | 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "components/payments/content/payment_request.mojom.h" | 14 #include "components/payments/content/payment_request.mojom.h" |
| 15 #include "components/payments/content/payment_request_delegate.h" | 15 #include "components/payments/content/payment_request_delegate.h" |
| 16 #include "components/payments/core/payment_instrument.h" |
| 16 #include "mojo/public/cpp/bindings/binding.h" | 17 #include "mojo/public/cpp/bindings/binding.h" |
| 17 | 18 |
| 18 namespace autofill { | 19 namespace autofill { |
| 19 class AutofillProfile; | 20 class AutofillProfile; |
| 20 class CreditCard; | 21 class CreditCard; |
| 21 class PersonalDataManager; | 22 class PersonalDataManager; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 class WebContents; | 26 class WebContents; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace payments { | 29 namespace payments { |
| 29 | 30 |
| 30 class CurrencyFormatter; | 31 class CurrencyFormatter; |
| 31 class PaymentRequestWebContentsManager; | 32 class PaymentRequestWebContentsManager; |
| 32 | 33 |
| 33 class PaymentRequest : payments::mojom::PaymentRequest { | 34 class PaymentRequest : public mojom::PaymentRequest, |
| 35 public PaymentInstrument::Delegate { |
| 34 public: | 36 public: |
| 35 class Observer { | 37 class Observer { |
| 36 public: | 38 public: |
| 37 // Called when the information (payment method, address/contact info, | 39 // Called when the information (payment method, address/contact info, |
| 38 // shipping option) changes. | 40 // shipping option) changes. |
| 39 virtual void OnSelectedInformationChanged() = 0; | 41 virtual void OnSelectedInformationChanged() = 0; |
| 40 | 42 |
| 41 protected: | 43 protected: |
| 42 virtual ~Observer() {} | 44 virtual ~Observer() {} |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 PaymentRequest( | 47 PaymentRequest( |
| 46 content::WebContents* web_contents, | 48 content::WebContents* web_contents, |
| 47 std::unique_ptr<PaymentRequestDelegate> delegate, | 49 std::unique_ptr<PaymentRequestDelegate> delegate, |
| 48 PaymentRequestWebContentsManager* manager, | 50 PaymentRequestWebContentsManager* manager, |
| 49 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); | 51 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); |
| 50 ~PaymentRequest() override; | 52 ~PaymentRequest() override; |
| 51 | 53 |
| 52 // payments::mojom::PaymentRequest "stub" | 54 // payments::mojom::PaymentRequest "stub" |
| 53 void Init(payments::mojom::PaymentRequestClientPtr client, | 55 void Init(payments::mojom::PaymentRequestClientPtr client, |
| 54 std::vector<payments::mojom::PaymentMethodDataPtr> method_data, | 56 std::vector<payments::mojom::PaymentMethodDataPtr> method_data, |
| 55 payments::mojom::PaymentDetailsPtr details, | 57 payments::mojom::PaymentDetailsPtr details, |
| 56 payments::mojom::PaymentOptionsPtr options) override; | 58 payments::mojom::PaymentOptionsPtr options) override; |
| 57 void Show() override; | 59 void Show() override; |
| 58 void UpdateWith(payments::mojom::PaymentDetailsPtr details) override {} | 60 void UpdateWith(payments::mojom::PaymentDetailsPtr details) override {} |
| 59 void Abort() override; | 61 void Abort() override; |
| 60 void Complete(payments::mojom::PaymentComplete result) override {} | 62 void Complete(payments::mojom::PaymentComplete result) override; |
| 61 void CanMakePayment() override {} | 63 void CanMakePayment() override; |
| 64 |
| 65 // PaymentInstrument::Delegate: |
| 66 void OnInstrumentDetailsReady( |
| 67 const std::string& method_name, |
| 68 const std::string& stringified_details) override; |
| 69 void OnInstrumentDetailsError() override {} |
| 62 | 70 |
| 63 // Called when the user explicitely cancelled the flow. Will send a message | 71 // Called when the user explicitely cancelled the flow. Will send a message |
| 64 // to the renderer which will indirectly destroy this object (through | 72 // to the renderer which will indirectly destroy this object (through |
| 65 // OnConnectionTerminated). | 73 // OnConnectionTerminated). |
| 66 void UserCancelled(); | 74 void UserCancelled(); |
| 67 | 75 |
| 68 // As a result of a browser-side error or renderer-initiated mojo channel | 76 // As a result of a browser-side error or renderer-initiated mojo channel |
| 69 // closure (e.g. there was an error on the renderer side, or payment was | 77 // closure (e.g. there was an error on the renderer side, or payment was |
| 70 // successful), this method is called. It is responsible for cleaning up, | 78 // successful), this method is called. It is responsible for cleaning up, |
| 71 // such as possibly closing the dialog. | 79 // such as possibly closing the dialog. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // |manager_| owns this PaymentRequest. | 185 // |manager_| owns this PaymentRequest. |
| 178 PaymentRequestWebContentsManager* manager_; | 186 PaymentRequestWebContentsManager* manager_; |
| 179 mojo::Binding<payments::mojom::PaymentRequest> binding_; | 187 mojo::Binding<payments::mojom::PaymentRequest> binding_; |
| 180 payments::mojom::PaymentRequestClientPtr client_; | 188 payments::mojom::PaymentRequestClientPtr client_; |
| 181 payments::mojom::PaymentDetailsPtr details_; | 189 payments::mojom::PaymentDetailsPtr details_; |
| 182 payments::mojom::PaymentOptionsPtr options_; | 190 payments::mojom::PaymentOptionsPtr options_; |
| 183 std::unique_ptr<CurrencyFormatter> currency_formatter_; | 191 std::unique_ptr<CurrencyFormatter> currency_formatter_; |
| 184 // A set of supported basic card networks. | 192 // A set of supported basic card networks. |
| 185 std::vector<std::string> supported_card_networks_; | 193 std::vector<std::string> supported_card_networks_; |
| 186 bool is_ready_to_pay_; | 194 bool is_ready_to_pay_; |
| 195 std::unique_ptr<PaymentInstrument> selected_payment_instrument_; |
| 196 mojom::PaymentResponsePtr payment_response_; |
| 187 | 197 |
| 188 base::ObserverList<Observer> observers_; | 198 base::ObserverList<Observer> observers_; |
| 189 | 199 |
| 190 // Profiles may change due to (e.g.) sync events, so profiles are cached after | 200 // Profiles may change due to (e.g.) sync events, so profiles are cached after |
| 191 // loading and owned here. They are populated once only, and ordered by | 201 // loading and owned here. They are populated once only, and ordered by |
| 192 // frecency. | 202 // frecency. |
| 193 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; | 203 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; |
| 194 std::vector<autofill::AutofillProfile*> shipping_profiles_; | 204 std::vector<autofill::AutofillProfile*> shipping_profiles_; |
| 195 std::vector<autofill::AutofillProfile*> contact_profiles_; | 205 std::vector<autofill::AutofillProfile*> contact_profiles_; |
| 196 autofill::AutofillProfile* selected_shipping_profile_; | 206 autofill::AutofillProfile* selected_shipping_profile_; |
| 197 autofill::AutofillProfile* selected_contact_profile_; | 207 autofill::AutofillProfile* selected_contact_profile_; |
| 198 std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_; | 208 std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_; |
| 199 std::vector<autofill::CreditCard*> credit_cards_; | 209 std::vector<autofill::CreditCard*> credit_cards_; |
| 200 autofill::CreditCard* selected_credit_card_; | 210 autofill::CreditCard* selected_credit_card_; |
| 201 | 211 |
| 202 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); | 212 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); |
| 203 }; | 213 }; |
| 204 | 214 |
| 205 } // namespace payments | 215 } // namespace payments |
| 206 | 216 |
| 207 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_ | 217 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_ |
| OLD | NEW |