Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: components/payments/content/payment_request.h

Issue 2645813006: Download web payment manifests. (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/payments/core/payment_instrument.h"
17 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/bindings/interface_request.h"
18 19
19 namespace autofill { 20 namespace autofill {
20 class AutofillProfile; 21 class AutofillProfile;
21 class CreditCard; 22 class CreditCard;
22 class PersonalDataManager; 23 class PersonalDataManager;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
26 class WebContents; 27 class WebContents;
27 } 28 }
28 29
29 namespace payments { 30 namespace payments {
30 31
31 class CurrencyFormatter; 32 class CurrencyFormatter;
32 class PaymentRequestWebContentsManager; 33 class PaymentRequestWebContentsManager;
33 34
34 class PaymentRequest : public mojom::PaymentRequest, 35 class PaymentRequest : public mojom::PaymentRequest,
35 public PaymentInstrument::Delegate { 36 public PaymentInstrument::Delegate {
36 public: 37 public:
37 class Observer { 38 class Observer {
38 public: 39 public:
39 // Called when the information (payment method, address/contact info, 40 // Called when the information (payment method, address/contact info,
40 // shipping option) changes. 41 // shipping option) changes.
41 virtual void OnSelectedInformationChanged() = 0; 42 virtual void OnSelectedInformationChanged() = 0;
42 43
43 protected: 44 protected:
44 virtual ~Observer() {} 45 virtual ~Observer() {}
45 }; 46 };
46 47
47 PaymentRequest( 48 PaymentRequest(content::WebContents* web_contents,
48 content::WebContents* web_contents, 49 std::unique_ptr<PaymentRequestDelegate> delegate,
49 std::unique_ptr<PaymentRequestDelegate> delegate, 50 PaymentRequestWebContentsManager* manager,
50 PaymentRequestWebContentsManager* manager, 51 mojo::InterfaceRequest<mojom::PaymentRequest> request);
51 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request);
52 ~PaymentRequest() override; 52 ~PaymentRequest() override;
53 53
54 // payments::mojom::PaymentRequest "stub" 54 // mojom::PaymentRequest
55 void Init(payments::mojom::PaymentRequestClientPtr client, 55 void Init(mojom::PaymentRequestClientPtr client,
56 std::vector<payments::mojom::PaymentMethodDataPtr> method_data, 56 std::vector<mojom::PaymentMethodDataPtr> method_data,
57 payments::mojom::PaymentDetailsPtr details, 57 mojom::PaymentDetailsPtr details,
58 payments::mojom::PaymentOptionsPtr options) override; 58 mojom::PaymentOptionsPtr options) override;
59 void Show() override; 59 void Show() override;
60 void UpdateWith(payments::mojom::PaymentDetailsPtr details) override {} 60 void UpdateWith(mojom::PaymentDetailsPtr details) override {}
61 void Abort() override; 61 void Abort() override;
62 void Complete(payments::mojom::PaymentComplete result) override; 62 void Complete(mojom::PaymentComplete result) override;
63 void CanMakePayment() override; 63 void CanMakePayment() override;
64 64
65 // PaymentInstrument::Delegate: 65 // PaymentInstrument::Delegate:
66 void OnInstrumentDetailsReady( 66 void OnInstrumentDetailsReady(
67 const std::string& method_name, 67 const std::string& method_name,
68 const std::string& stringified_details) override; 68 const std::string& stringified_details) override;
69 void OnInstrumentDetailsError() override {} 69 void OnInstrumentDetailsError() override {}
70 70
71 // 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
72 // to the renderer which will indirectly destroy this object (through 72 // to the renderer which will indirectly destroy this object (through
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Sets the |profile| to be the selected one and will update state and notify 137 // Sets the |profile| to be the selected one and will update state and notify
138 // observers. 138 // observers.
139 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); 139 void SetSelectedShippingProfile(autofill::AutofillProfile* profile);
140 void SetSelectedContactProfile(autofill::AutofillProfile* profile); 140 void SetSelectedContactProfile(autofill::AutofillProfile* profile);
141 void SetSelectedCreditCard(autofill::CreditCard* card); 141 void SetSelectedCreditCard(autofill::CreditCard* card);
142 142
143 autofill::PersonalDataManager* personal_data_manager() { 143 autofill::PersonalDataManager* personal_data_manager() {
144 return delegate_->GetPersonalDataManager(); 144 return delegate_->GetPersonalDataManager();
145 } 145 }
146 146
147 payments::mojom::PaymentDetails* details() { return details_.get(); } 147 mojom::PaymentDetails* details() { return details_.get(); }
148 payments::mojom::PaymentOptions* options() { return options_.get(); } 148 mojom::PaymentOptions* options() { return options_.get(); }
149 const std::vector<std::string>& supported_card_networks() { 149 const std::vector<std::string>& supported_card_networks() {
150 return supported_card_networks_; 150 return supported_card_networks_;
151 } 151 }
152 content::WebContents* web_contents() { return web_contents_; } 152 content::WebContents* web_contents() { return web_contents_; }
153 153
154 bool request_shipping() const { return options_->request_shipping; } 154 bool request_shipping() const { return options_->request_shipping; }
155 bool request_payer_name() const { return options_->request_payer_name; } 155 bool request_payer_name() const { return options_->request_payer_name; }
156 bool request_payer_phone() const { return options_->request_payer_phone; } 156 bool request_payer_phone() const { return options_->request_payer_phone; }
157 bool request_payer_email() const { return options_->request_payer_email; } 157 bool request_payer_email() const { return options_->request_payer_email; }
158 158
159 bool is_ready_to_pay() { return is_ready_to_pay_; } 159 bool is_ready_to_pay() { return is_ready_to_pay_; }
160 160
161 private: 161 private:
162 // Fetches the Autofill Profiles for this user from the PersonalDataManager, 162 // Fetches the Autofill Profiles for this user from the PersonalDataManager,
163 // and stores copies of them, owned by this Request, in profile_cache_. 163 // and stores copies of them, owned by this Request, in profile_cache_.
164 void PopulateProfileCache(); 164 void PopulateProfileCache();
165 165
166 // Sets the default values for the selected Shipping and Contact profiles, as 166 // Sets the default values for the selected Shipping and Contact profiles, as
167 // well as the selected Credit Card. 167 // well as the selected Credit Card.
168 void SetDefaultProfileSelections(); 168 void SetDefaultProfileSelections();
169 169
170 // Validates the |method_data| and fills |supported_card_networks_|. 170 // Validates the |method_data| and fills |supported_card_networks_|.
171 void PopulateValidatedMethodData( 171 void PopulateValidatedMethodData(
172 const std::vector<payments::mojom::PaymentMethodDataPtr>& method_data); 172 const std::vector<mojom::PaymentMethodDataPtr>& method_data);
173 173
174 // Updates |is_ready_to_pay_| with the current state, by validating that all 174 // Updates |is_ready_to_pay_| with the current state, by validating that all
175 // the required information is available and notify observers. 175 // the required information is available and notify observers.
176 void UpdateIsReadyToPayAndNotifyObservers(); 176 void UpdateIsReadyToPayAndNotifyObservers();
177 177
178 // Notifies all observers that selected information has changed. 178 // Notifies all observers that selected information has changed.
179 void NotifyOnSelectedInformationChanged(); 179 void NotifyOnSelectedInformationChanged();
180 180
181 // Returns whether the selected data satisfies the PaymentDetails requirements 181 // Returns whether the selected data satisfies the PaymentDetails requirements
182 // (payment methods). 182 // (payment methods).
183 bool ArePaymentDetailsSatisfied(); 183 bool ArePaymentDetailsSatisfied();
184 // Returns whether the selected data satisfies the PaymentOptions requirements 184 // Returns whether the selected data satisfies the PaymentOptions requirements
185 // (contact info, shipping address). 185 // (contact info, shipping address).
186 bool ArePaymentOptionsSatisfied(); 186 bool ArePaymentOptionsSatisfied();
187 187
188 // Updates the selected_shipping_option based on the data passed to this 188 // Updates the selected_shipping_option based on the data passed to this
189 // payment request by the website. This will set selected_shipping_option_ to 189 // payment request by the website. This will set selected_shipping_option_ to
190 // the last option marked selected in the options array. 190 // the last option marked selected in the options array.
191 void UpdateSelectedShippingOptionFromDetails(); 191 void UpdateSelectedShippingOptionFromDetails();
192 192
193 content::WebContents* web_contents_; 193 content::WebContents* web_contents_;
194 std::unique_ptr<PaymentRequestDelegate> delegate_; 194 std::unique_ptr<PaymentRequestDelegate> delegate_;
195 // |manager_| owns this PaymentRequest. 195 // |manager_| owns this PaymentRequest.
196 PaymentRequestWebContentsManager* manager_; 196 PaymentRequestWebContentsManager* manager_;
197 mojo::Binding<payments::mojom::PaymentRequest> binding_; 197 mojo::Binding<mojom::PaymentRequest> binding_;
198 payments::mojom::PaymentRequestClientPtr client_; 198 mojom::PaymentRequestClientPtr client_;
199 payments::mojom::PaymentDetailsPtr details_; 199 mojom::PaymentDetailsPtr details_;
200 payments::mojom::PaymentOptionsPtr options_; 200 mojom::PaymentOptionsPtr options_;
201 std::unique_ptr<CurrencyFormatter> currency_formatter_; 201 std::unique_ptr<CurrencyFormatter> currency_formatter_;
202 // A set of supported basic card networks. 202 // A set of supported basic card networks.
203 std::vector<std::string> supported_card_networks_; 203 std::vector<std::string> supported_card_networks_;
204 bool is_ready_to_pay_; 204 bool is_ready_to_pay_;
205 std::unique_ptr<PaymentInstrument> selected_payment_instrument_; 205 std::unique_ptr<PaymentInstrument> selected_payment_instrument_;
206 mojom::PaymentResponsePtr payment_response_; 206 mojom::PaymentResponsePtr payment_response_;
207 207
208 base::ObserverList<Observer> observers_; 208 base::ObserverList<Observer> observers_;
209 209
210 // Profiles may change due to (e.g.) sync events, so profiles are cached after 210 // Profiles may change due to (e.g.) sync events, so profiles are cached after
(...skipping 10 matching lines...) Expand all
221 // This is owned by |details_|, which is owned by this object and lives until 221 // This is owned by |details_|, which is owned by this object and lives until
222 // |this| is destructed so it's safe to keep this raw pointer. 222 // |this| is destructed so it's safe to keep this raw pointer.
223 payments::mojom::PaymentShippingOption* selected_shipping_option_; 223 payments::mojom::PaymentShippingOption* selected_shipping_option_;
224 224
225 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); 225 DISALLOW_COPY_AND_ASSIGN(PaymentRequest);
226 }; 226 };
227 227
228 } // namespace payments 228 } // namespace payments
229 229
230 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_ 230 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698