| 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 "components/payments/content/payment_request.h" | 5 #include "components/payments/content/payment_request.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/payments/content/payment_details_validation.h" | 10 #include "components/payments/content/payment_details_validation.h" |
| 11 #include "components/payments/content/payment_request_web_contents_manager.h" | 11 #include "components/payments/content/payment_request_web_contents_manager.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 | 14 |
| 15 namespace payments { | 15 namespace payments { |
| 16 | 16 |
| 17 PaymentRequest::PaymentRequest( | 17 PaymentRequest::PaymentRequest( |
| 18 content::WebContents* web_contents, | 18 content::WebContents* web_contents, |
| 19 std::unique_ptr<PaymentRequestDelegate> delegate, | 19 std::unique_ptr<PaymentRequestDelegate> delegate, |
| 20 PaymentRequestWebContentsManager* manager, | 20 PaymentRequestWebContentsManager* manager, |
| 21 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) | 21 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request, |
| 22 ObserverForTest* observer_for_testing) |
| 22 : web_contents_(web_contents), | 23 : web_contents_(web_contents), |
| 23 delegate_(std::move(delegate)), | 24 delegate_(std::move(delegate)), |
| 24 manager_(manager), | 25 manager_(manager), |
| 25 binding_(this, std::move(request)) { | 26 binding_(this, std::move(request)), |
| 27 observer_for_testing_(observer_for_testing) { |
| 26 // OnConnectionTerminated will be called when the Mojo pipe is closed. This | 28 // OnConnectionTerminated will be called when the Mojo pipe is closed. This |
| 27 // will happen as a result of many renderer-side events (both successful and | 29 // will happen as a result of many renderer-side events (both successful and |
| 28 // erroneous in nature). | 30 // erroneous in nature). |
| 29 // TODO(crbug.com/683636): Investigate using | 31 // TODO(crbug.com/683636): Investigate using |
| 30 // set_connection_error_with_reason_handler with Binding::CloseWithReason. | 32 // set_connection_error_with_reason_handler with Binding::CloseWithReason. |
| 31 binding_.set_connection_error_handler(base::Bind( | 33 binding_.set_connection_error_handler(base::Bind( |
| 32 &PaymentRequest::OnConnectionTerminated, base::Unretained(this))); | 34 &PaymentRequest::OnConnectionTerminated, base::Unretained(this))); |
| 33 } | 35 } |
| 34 | 36 |
| 35 PaymentRequest::~PaymentRequest() {} | 37 PaymentRequest::~PaymentRequest() {} |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 client_->OnComplete(); | 85 client_->OnComplete(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void PaymentRequest::CanMakePayment() { | 88 void PaymentRequest::CanMakePayment() { |
| 87 // TODO(crbug.com/704676): Implement a quota policy for this method. | 89 // TODO(crbug.com/704676): Implement a quota policy for this method. |
| 88 // PaymentRequest.canMakePayments() never returns false in incognito mode. | 90 // PaymentRequest.canMakePayments() never returns false in incognito mode. |
| 89 client_->OnCanMakePayment( | 91 client_->OnCanMakePayment( |
| 90 delegate_->IsIncognito() || state()->CanMakePayment() | 92 delegate_->IsIncognito() || state()->CanMakePayment() |
| 91 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT | 93 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT |
| 92 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT); | 94 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT); |
| 95 if (observer_for_testing_) |
| 96 observer_for_testing_->OnCanMakePaymentCalled(); |
| 93 } | 97 } |
| 94 | 98 |
| 95 void PaymentRequest::OnInvalidSpecProvided() { | 99 void PaymentRequest::OnInvalidSpecProvided() { |
| 96 OnConnectionTerminated(); | 100 OnConnectionTerminated(); |
| 97 } | 101 } |
| 98 | 102 |
| 99 void PaymentRequest::OnPaymentResponseAvailable( | 103 void PaymentRequest::OnPaymentResponseAvailable( |
| 100 mojom::PaymentResponsePtr response) { | 104 mojom::PaymentResponsePtr response) { |
| 101 client_->OnPaymentResponse(std::move(response)); | 105 client_->OnPaymentResponse(std::move(response)); |
| 102 } | 106 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 126 binding_.Close(); | 130 binding_.Close(); |
| 127 delegate_->CloseDialog(); | 131 delegate_->CloseDialog(); |
| 128 manager_->DestroyRequest(this); | 132 manager_->DestroyRequest(this); |
| 129 } | 133 } |
| 130 | 134 |
| 131 void PaymentRequest::Pay() { | 135 void PaymentRequest::Pay() { |
| 132 state_->GeneratePaymentResponse(); | 136 state_->GeneratePaymentResponse(); |
| 133 } | 137 } |
| 134 | 138 |
| 135 } // namespace payments | 139 } // namespace payments |
| OLD | NEW |