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

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

Issue 2713033004: Layered component for web payments (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_
6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "components/autofill/core/browser/personal_data_manager.h"
13 #include "components/payments/currency_formatter.h"
14 #include "components/payments/payment_request.mojom.h"
15 #include "components/payments/payment_request_delegate.h"
16 #include "mojo/public/cpp/bindings/binding.h"
17
18 namespace autofill {
19 class AutofillProfile;
20 class CreditCard;
21 }
22
23 namespace content {
24 class WebContents;
25 }
26
27 namespace payments {
28
29 class PaymentRequestWebContentsManager;
30
31 class PaymentRequest : payments::mojom::PaymentRequest {
32 public:
33 PaymentRequest(
34 content::WebContents* web_contents,
35 std::unique_ptr<PaymentRequestDelegate> delegate,
36 PaymentRequestWebContentsManager* manager,
37 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request);
38 ~PaymentRequest() override;
39
40 // payments::mojom::PaymentRequest "stub"
41 void Init(payments::mojom::PaymentRequestClientPtr client,
42 std::vector<payments::mojom::PaymentMethodDataPtr> method_data,
43 payments::mojom::PaymentDetailsPtr details,
44 payments::mojom::PaymentOptionsPtr options) override;
45 void Show() override;
46 void UpdateWith(payments::mojom::PaymentDetailsPtr details) override {}
47 void Abort() override;
48 void Complete(payments::mojom::PaymentComplete result) override {}
49 void CanMakePayment() override {}
50
51 // Called when the user explicitely cancelled the flow. Will send a message
52 // to the renderer which will indirectly destroy this object (through
53 // OnConnectionTerminated).
54 void UserCancelled();
55
56 // As a result of a browser-side error or renderer-initiated mojo channel
57 // closure (e.g. there was an error on the renderer side, or payment was
58 // successful), this method is called. It is responsible for cleaning up,
59 // such as possibly closing the dialog.
60 void OnConnectionTerminated();
61
62 // Returns the CurrencyFormatter instance for this PaymentRequest.
63 // |locale_name| should be the result of the browser's GetApplicationLocale().
64 // Note: Having multiple currencies per PaymentRequest is not supported; hence
65 // the CurrencyFormatter is cached here.
66 CurrencyFormatter* GetOrCreateCurrencyFormatter(
67 const std::string& currency_code,
68 const std::string& currency_system,
69 const std::string& locale_name);
70
71 // Returns the appropriate Autofill Profiles for this user. On the first
72 // invocation of either getter, the profiles are fetched from the
73 // PersonalDataManager; on subsequent invocations, a cached version is
74 // returned. The profiles returned are owned by the request object.
75 const std::vector<autofill::AutofillProfile*>& shipping_profiles();
76 const std::vector<autofill::AutofillProfile*>& contact_profiles();
77
78 // Gets/sets the Autofill Profile representing the shipping address or contact
79 // information currently selected for this PaymentRequest flow. Can return
80 // null.
81 autofill::AutofillProfile* selected_shipping_profile() const {
82 return selected_shipping_profile_;
83 }
84 void set_selected_shipping_profile(autofill::AutofillProfile* profile) {
85 selected_shipping_profile_ = profile;
86 }
87 autofill::AutofillProfile* selected_contact_profile() const {
88 return selected_contact_profile_;
89 }
90 void set_selected_contact_profile(autofill::AutofillProfile* profile) {
91 selected_contact_profile_ = profile;
92 }
93
94 const std::vector<autofill::CreditCard*>& credit_cards() {
95 return credit_cards_;
96 }
97
98 // Returns the currently selected credit card for this PaymentRequest flow.
99 // It's not guaranteed to be complete. Returns nullptr if there is no selected
100 // card.
101 autofill::CreditCard* selected_credit_card() { return selected_credit_card_; }
102
103 void set_selected_credit_card(autofill::CreditCard* credit_card) {
104 selected_credit_card_ = credit_card;
105 }
106
107 autofill::PersonalDataManager* personal_data_manager() {
108 return delegate_->GetPersonalDataManager();
109 }
110
111 payments::mojom::PaymentDetails* details() { return details_.get(); }
112 const std::vector<std::string>& supported_card_networks() {
113 return supported_card_networks_;
114 }
115 content::WebContents* web_contents() { return web_contents_; }
116
117 private:
118 // Fetches the Autofill Profiles for this user from the PersonalDataManager,
119 // and stores copies of them, owned by this Request, in profile_cache_.
120 void PopulateProfileCache();
121
122 // Sets the default values for the selected Shipping and Contact profiles, as
123 // well as the selected Credit Card.
124 void SetDefaultProfileSelections();
125
126 // Validates the |method_data| and fills |supported_card_networks_|.
127 void PopulateValidatedMethodData(
128 const std::vector<payments::mojom::PaymentMethodDataPtr>& method_data);
129
130 content::WebContents* web_contents_;
131 std::unique_ptr<PaymentRequestDelegate> delegate_;
132 // |manager_| owns this PaymentRequest.
133 PaymentRequestWebContentsManager* manager_;
134 mojo::Binding<payments::mojom::PaymentRequest> binding_;
135 payments::mojom::PaymentRequestClientPtr client_;
136 payments::mojom::PaymentDetailsPtr details_;
137 std::unique_ptr<CurrencyFormatter> currency_formatter_;
138 // A set of supported basic card networks.
139 std::vector<std::string> supported_card_networks_;
140
141 // Profiles may change due to (e.g.) sync events, so profiles are cached after
142 // loading and owned here. They are populated once only, and ordered by
143 // frecency.
144 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_;
145 std::vector<autofill::AutofillProfile*> shipping_profiles_;
146 std::vector<autofill::AutofillProfile*> contact_profiles_;
147 autofill::AutofillProfile* selected_shipping_profile_;
148 autofill::AutofillProfile* selected_contact_profile_;
149 std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_;
150 std::vector<autofill::CreditCard*> credit_cards_;
151 autofill::CreditCard* selected_credit_card_;
152
153 DISALLOW_COPY_AND_ASSIGN(PaymentRequest);
154 };
155
156 } // namespace payments
157
158 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_H_
OLDNEW
« no previous file with comments | « components/payments/payment_details_validation.cc ('k') | components/payments/payment_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698