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