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 #include "chrome/browser/payments/payment_request_impl.h" | 5 #include "chrome/browser/payments/payment_request_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/payments/ui/payment_request_dialog.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
11 #include "components/web_modal/web_contents_modal_dialog_host.h" | 11 #include "chrome/browser/ui/browser_window.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" | 12 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
16 | 14 |
17 namespace { | 15 namespace { |
18 | 16 |
19 class PaymentRequestFactory { | 17 class PaymentRequestFactory { |
20 public: | 18 public: |
21 bool AssignPaymentRequest( | 19 bool AssignPaymentRequest( |
22 content::WebContents* web_contents, | 20 content::WebContents* web_contents, |
23 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | 21 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { |
(...skipping 20 matching lines...) Expand all Loading... |
44 base::LazyInstance<PaymentRequestFactory> payment_request_factory; | 42 base::LazyInstance<PaymentRequestFactory> payment_request_factory; |
45 | 43 |
46 } // namespace | 44 } // namespace |
47 | 45 |
48 namespace payments { | 46 namespace payments { |
49 | 47 |
50 PaymentRequestImpl::PaymentRequestImpl( | 48 PaymentRequestImpl::PaymentRequestImpl( |
51 content::WebContents* web_contents, | 49 content::WebContents* web_contents, |
52 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) | 50 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) |
53 : web_contents_(web_contents), | 51 : web_contents_(web_contents), |
54 binding_(this, std::move(request)), | 52 binding_(this, std::move(request)) { |
55 dialog_(nullptr) { | |
56 binding_.set_connection_error_handler( | 53 binding_.set_connection_error_handler( |
57 base::Bind(&PaymentRequestImpl::OnError, this)); | 54 base::Bind(&PaymentRequestImpl::OnError, this)); |
58 } | 55 } |
59 | 56 |
60 PaymentRequestImpl::~PaymentRequestImpl() {} | 57 PaymentRequestImpl::~PaymentRequestImpl() {} |
61 | 58 |
62 void PaymentRequestImpl::Init( | 59 void PaymentRequestImpl::Init( |
63 payments::mojom::PaymentRequestClientPtr client, | 60 payments::mojom::PaymentRequestClientPtr client, |
64 std::vector<payments::mojom::PaymentMethodDataPtr> methodData, | 61 std::vector<payments::mojom::PaymentMethodDataPtr> methodData, |
65 payments::mojom::PaymentDetailsPtr details, | 62 payments::mojom::PaymentDetailsPtr details, |
66 payments::mojom::PaymentOptionsPtr options) { | 63 payments::mojom::PaymentOptionsPtr options) { |
67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
68 dialog_ = new PaymentRequestDialog(std::move(client)); | 65 client_ = std::move(client); |
69 views::DialogDelegate::CreateDialogWidget( | 66 chrome::FindBrowserWithWebContents(web_contents_) |
70 dialog_, nullptr, | 67 ->window() |
71 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_) | 68 ->ShowWebPaymentsDialog(this); |
72 ->delegate() | 69 } |
73 ->GetWebContentsModalDialogHost() | 70 |
74 ->GetHostView()) | 71 void PaymentRequestImpl::Cancel() { |
75 ->Show(); | 72 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); |
76 } | 73 } |
77 | 74 |
78 void PaymentRequestImpl::OnError() { | 75 void PaymentRequestImpl::OnError() { |
79 binding_.Close(); | 76 binding_.Close(); |
80 // TODO(krb): Call dialog_->Close() here, but avoid double-free | 77 // TODO(krb): Close the dialog here, but avoid double-free |
81 payment_request_factory.Get().UnassignPaymentRequest(web_contents_); | 78 payment_request_factory.Get().UnassignPaymentRequest(web_contents_); |
82 } | 79 } |
83 | 80 |
84 } // namespace payments | 81 } // namespace payments |
85 | 82 |
86 void CreatePaymentRequestHandler( | 83 void CreatePaymentRequestHandler( |
87 content::WebContents* web_contents, | 84 content::WebContents* web_contents, |
88 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | 85 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { |
89 payment_request_factory.Get().AssignPaymentRequest(web_contents, | 86 payment_request_factory.Get().AssignPaymentRequest(web_contents, |
90 std::move(request)); | 87 std::move(request)); |
91 } | 88 } |
OLD | NEW |