Chromium Code Reviews| 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/ui/browser_dialogs.h" | 10 #include "chrome/browser/ui/browser_dialogs.h" |
| 11 #include "components/payments/payment_details_validation.h" | |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class PaymentRequestFactory { | 17 class PaymentRequestFactory { |
| 17 public: | 18 public: |
| 18 bool AssignPaymentRequest( | 19 bool AssignPaymentRequest( |
| 19 content::WebContents* web_contents, | 20 content::WebContents* web_contents, |
| 20 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | 21 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 | 56 |
| 56 PaymentRequestImpl::~PaymentRequestImpl() {} | 57 PaymentRequestImpl::~PaymentRequestImpl() {} |
| 57 | 58 |
| 58 void PaymentRequestImpl::Init( | 59 void PaymentRequestImpl::Init( |
| 59 payments::mojom::PaymentRequestClientPtr client, | 60 payments::mojom::PaymentRequestClientPtr client, |
| 60 std::vector<payments::mojom::PaymentMethodDataPtr> methodData, | 61 std::vector<payments::mojom::PaymentMethodDataPtr> methodData, |
| 61 payments::mojom::PaymentDetailsPtr details, | 62 payments::mojom::PaymentDetailsPtr details, |
| 62 payments::mojom::PaymentOptionsPtr options) { | 63 payments::mojom::PaymentOptionsPtr options) { |
| 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 64 client_ = std::move(client); | 65 client_ = std::move(client); |
| 66 std::string err_msg; | |
| 67 if (!validatePaymentDetails(details, &err_msg)) { | |
|
please use gerrit instead
2017/01/05 20:11:58
Also:
LOG(ERROR) << err_msg;
By the way, you may
| |
| 68 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); | |
| 69 client_.reset(); | |
| 70 } | |
| 65 } | 71 } |
| 66 | 72 |
| 67 void PaymentRequestImpl::Show() { | 73 void PaymentRequestImpl::Show() { |
| 68 chrome::ShowPaymentRequestDialog(this); | 74 if (client_.is_bound() && binding_.is_bound()) |
| 75 chrome::ShowPaymentRequestDialog(this); | |
| 69 } | 76 } |
|
please use gerrit instead
2017/01/05 20:11:58
Can you do this? it should ensure that PaymentRequ
| |
| 70 | 77 |
| 71 void PaymentRequestImpl::Cancel() { | 78 void PaymentRequestImpl::Cancel() { |
| 72 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); | 79 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); |
| 73 } | 80 } |
| 74 | 81 |
| 75 void PaymentRequestImpl::OnError() { | 82 void PaymentRequestImpl::OnError() { |
| 76 binding_.Close(); | 83 binding_.Close(); |
| 77 // TODO(krb): Close the dialog here, but avoid double-free | 84 // TODO(krb): Close the dialog here, but avoid double-free |
| 78 payment_request_factory.Get().UnassignPaymentRequest(web_contents_); | 85 payment_request_factory.Get().UnassignPaymentRequest(web_contents_); |
| 79 } | 86 } |
| 80 | 87 |
| 81 } // namespace payments | 88 } // namespace payments |
| 82 | 89 |
| 83 void CreatePaymentRequestHandler( | 90 void CreatePaymentRequestHandler( |
| 84 content::WebContents* web_contents, | 91 content::WebContents* web_contents, |
| 85 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | 92 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { |
| 86 payment_request_factory.Get().AssignPaymentRequest(web_contents, | 93 payment_request_factory.Get().AssignPaymentRequest(web_contents, |
| 87 std::move(request)); | 94 std::move(request)); |
| 88 } | 95 } |
| OLD | NEW |