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

Side by Side Diff: chrome/browser/payments/payment_request_impl.cc

Issue 2446093004: [Web Payments] Initial plumb of Payment Request dialog (Closed)
Patch Set: Handle new member function Created 4 years, 1 month 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 #include "chrome/browser/payments/payment_request_impl.h"
6
7 #include <map>
8
9 #include "base/lazy_instance.h"
10 #include "chrome/browser/payments/ui/payment_request_dialog.h"
11 #include "components/web_modal/web_contents_modal_dialog_host.h"
12 #include "components/web_modal/web_contents_modal_dialog_manager.h"
13 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h"
16
17 namespace {
18
19 class PaymentRequestFactory {
20 public:
21 bool AssignPaymentRequest(
22 content::WebContents* web_contents,
23 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) {
24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
25 if (map_.find(web_contents) == map_.end()) {
26 scoped_refptr<payments::PaymentRequestImpl> p(
27 new payments::PaymentRequestImpl(web_contents, std::move(request)));
28 map_[web_contents] = p;
29 return true;
30 }
31 return false;
32 }
33
34 void UnassignPaymentRequest(content::WebContents* web_contents) {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
36 map_.erase(web_contents);
37 }
38
39 private:
40 std::map<content::WebContents*, scoped_refptr<payments::PaymentRequestImpl>>
41 map_;
42 };
43
44 base::LazyInstance<PaymentRequestFactory> payment_request_factory;
45
46 } // namespace
47
48 namespace payments {
49
50 PaymentRequestImpl::PaymentRequestImpl(
51 content::WebContents* web_contents,
52 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request)
53 : web_contents_(web_contents),
54 binding_(this, std::move(request)),
55 dialog_(nullptr) {
56 binding_.set_connection_error_handler(
57 base::Bind(&PaymentRequestImpl::OnError, this));
58 }
59
60 PaymentRequestImpl::~PaymentRequestImpl() {}
61
62 void PaymentRequestImpl::Init(
63 payments::mojom::PaymentRequestClientPtr client,
64 std::vector<payments::mojom::PaymentMethodDataPtr> methodData,
65 payments::mojom::PaymentDetailsPtr details,
66 payments::mojom::PaymentOptionsPtr options) {
67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
68 dialog_ = new PaymentRequestDialog(std::move(client));
69 views::DialogDelegate::CreateDialogWidget(
70 dialog_, nullptr,
71 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_)
72 ->delegate()
73 ->GetWebContentsModalDialogHost()
74 ->GetHostView())
75 ->Show();
76 }
77
78 void PaymentRequestImpl::OnError() {
79 binding_.Close();
80 // TODO(krb): Call dialog_->Close() here, but avoid double-free
81 payment_request_factory.Get().UnassignPaymentRequest(web_contents_);
82 }
83
84 } // namespace payments
85
86 void CreatePaymentRequestHandler(
87 content::WebContents* web_contents,
88 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) {
89 payment_request_factory.Get().AssignPaymentRequest(web_contents,
90 std::move(request));
91 }
OLDNEW
« no previous file with comments | « chrome/browser/payments/payment_request_impl.h ('k') | chrome/browser/payments/ui/payment_request_dialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698