| 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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 void PaymentRequest::Show() { | 65 void PaymentRequest::Show() { |
| 66 if (!client_.is_bound() || !binding_.is_bound()) { | 66 if (!client_.is_bound() || !binding_.is_bound()) { |
| 67 LOG(ERROR) << "Attempted Show(), but binding(s) missing."; | 67 LOG(ERROR) << "Attempted Show(), but binding(s) missing."; |
| 68 OnConnectionTerminated(); | 68 OnConnectionTerminated(); |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 delegate_->ShowDialog(this); | 71 delegate_->ShowDialog(this); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) { |
| 75 std::string error; |
| 76 if (!payments::validatePaymentDetails(details, &error)) { |
| 77 LOG(ERROR) << error; |
| 78 OnConnectionTerminated(); |
| 79 return; |
| 80 } |
| 81 spec_->UpdateWith(std::move(details)); |
| 82 } |
| 83 |
| 74 void PaymentRequest::Abort() { | 84 void PaymentRequest::Abort() { |
| 75 // The API user has decided to abort. We return a successful abort message to | 85 // The API user has decided to abort. We return a successful abort message to |
| 76 // the renderer, which closes the Mojo message pipe, which triggers | 86 // the renderer, which closes the Mojo message pipe, which triggers |
| 77 // PaymentRequest::OnConnectionTerminated, which destroys this object. | 87 // PaymentRequest::OnConnectionTerminated, which destroys this object. |
| 78 if (client_.is_bound()) | 88 if (client_.is_bound()) |
| 79 client_->OnAbort(true /* aborted_successfully */); | 89 client_->OnAbort(true /* aborted_successfully */); |
| 80 } | 90 } |
| 81 | 91 |
| 82 void PaymentRequest::Complete(mojom::PaymentComplete result) { | 92 void PaymentRequest::Complete(mojom::PaymentComplete result) { |
| 83 if (!client_.is_bound()) | 93 if (!client_.is_bound()) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 105 | 115 |
| 106 void PaymentRequest::OnInvalidSpecProvided() { | 116 void PaymentRequest::OnInvalidSpecProvided() { |
| 107 OnConnectionTerminated(); | 117 OnConnectionTerminated(); |
| 108 } | 118 } |
| 109 | 119 |
| 110 void PaymentRequest::OnPaymentResponseAvailable( | 120 void PaymentRequest::OnPaymentResponseAvailable( |
| 111 mojom::PaymentResponsePtr response) { | 121 mojom::PaymentResponsePtr response) { |
| 112 client_->OnPaymentResponse(std::move(response)); | 122 client_->OnPaymentResponse(std::move(response)); |
| 113 } | 123 } |
| 114 | 124 |
| 125 void PaymentRequest::OnShippingOptionIdSelected( |
| 126 std::string shipping_option_id) { |
| 127 client_->OnShippingOptionChange(shipping_option_id); |
| 128 } |
| 129 |
| 130 void PaymentRequest::OnShippingAddressSelected( |
| 131 mojom::PaymentAddressPtr address) { |
| 132 client_->OnShippingAddressChange(std::move(address)); |
| 133 } |
| 134 |
| 115 void PaymentRequest::UserCancelled() { | 135 void PaymentRequest::UserCancelled() { |
| 116 // If |client_| is not bound, then the object is already being destroyed as | 136 // If |client_| is not bound, then the object is already being destroyed as |
| 117 // a result of a renderer event. | 137 // a result of a renderer event. |
| 118 if (!client_.is_bound()) | 138 if (!client_.is_bound()) |
| 119 return; | 139 return; |
| 120 | 140 |
| 121 // This sends an error to the renderer, which informs the API user. | 141 // This sends an error to the renderer, which informs the API user. |
| 122 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); | 142 client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); |
| 123 | 143 |
| 124 // We close all bindings and ask to be destroyed. | 144 // We close all bindings and ask to be destroyed. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 137 binding_.Close(); | 157 binding_.Close(); |
| 138 delegate_->CloseDialog(); | 158 delegate_->CloseDialog(); |
| 139 manager_->DestroyRequest(this); | 159 manager_->DestroyRequest(this); |
| 140 } | 160 } |
| 141 | 161 |
| 142 void PaymentRequest::Pay() { | 162 void PaymentRequest::Pay() { |
| 143 state_->GeneratePaymentResponse(); | 163 state_->GeneratePaymentResponse(); |
| 144 } | 164 } |
| 145 | 165 |
| 146 } // namespace payments | 166 } // namespace payments |
| OLD | NEW |