| OLD | NEW |
| (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 "components/payments/payment_request.h" |
| 6 |
| 7 #include "components/payments/payment_details_validation.h" |
| 8 #include "components/payments/payment_request_delegate.h" |
| 9 #include "components/payments/payment_request_web_contents_manager.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 |
| 13 namespace payments { |
| 14 |
| 15 PaymentRequest::PaymentRequest( |
| 16 content::WebContents* web_contents, |
| 17 std::unique_ptr<PaymentRequestDelegate> delegate, |
| 18 PaymentRequestWebContentsManager* manager, |
| 19 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) |
| 20 : web_contents_(web_contents), |
| 21 delegate_(std::move(delegate)), |
| 22 manager_(manager), |
| 23 binding_(this, std::move(request)) { |
| 24 binding_.set_connection_error_handler( |
| 25 base::Bind(&PaymentRequest::OnError, base::Unretained(this))); |
| 26 } |
| 27 |
| 28 PaymentRequest::~PaymentRequest() {} |
| 29 |
| 30 void PaymentRequest::Init( |
| 31 payments::mojom::PaymentRequestClientPtr client, |
| 32 std::vector<payments::mojom::PaymentMethodDataPtr> methodData, |
| 33 payments::mojom::PaymentDetailsPtr details, |
| 34 payments::mojom::PaymentOptionsPtr options) { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 36 std::string error; |
| 37 if (!payments::validatePaymentDetails(details, &error)) { |
| 38 LOG(ERROR) << error; |
| 39 OnError(); |
| 40 return; |
| 41 } |
| 42 client_ = std::move(client); |
| 43 details_ = std::move(details); |
| 44 } |
| 45 |
| 46 void PaymentRequest::Show() { |
| 47 delegate_->ShowPaymentRequestDialog(this); |
| 48 } |
| 49 |
| 50 void PaymentRequest::Cancel() { |
| 51 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); |
| 52 } |
| 53 |
| 54 void PaymentRequest::OnError() { |
| 55 binding_.Close(); |
| 56 manager_->DestroyRequest(this); |
| 57 } |
| 58 |
| 59 } // namespace payments |
| OLD | NEW |