OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "modules/payments/PaymentInstruments.h" | 5 #include "modules/payments/PaymentInstruments.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 | 159 |
160 manager_->SetPaymentInstrument( | 160 manager_->SetPaymentInstrument( |
161 instrument_key, std::move(instrument), | 161 instrument_key, std::move(instrument), |
162 ConvertToBaseCallback( | 162 ConvertToBaseCallback( |
163 WTF::Bind(&PaymentInstruments::onSetPaymentInstrument, | 163 WTF::Bind(&PaymentInstruments::onSetPaymentInstrument, |
164 WrapPersistent(this), WrapPersistent(resolver)))); | 164 WrapPersistent(this), WrapPersistent(resolver)))); |
165 return promise; | 165 return promise; |
166 } | 166 } |
167 | 167 |
| 168 ScriptPromise PaymentInstruments::clear(ScriptState* script_state) { |
| 169 if (!manager_.is_bound()) { |
| 170 return ScriptPromise::RejectWithDOMException( |
| 171 script_state, |
| 172 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
| 173 } |
| 174 |
| 175 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 176 ScriptPromise promise = resolver->Promise(); |
| 177 |
| 178 manager_->ClearPaymentInstruments(ConvertToBaseCallback( |
| 179 WTF::Bind(&PaymentInstruments::onClearPaymentInstruments, |
| 180 WrapPersistent(this), WrapPersistent(resolver)))); |
| 181 return promise; |
| 182 } |
| 183 |
168 DEFINE_TRACE(PaymentInstruments) {} | 184 DEFINE_TRACE(PaymentInstruments) {} |
169 | 185 |
170 void PaymentInstruments::onDeletePaymentInstrument( | 186 void PaymentInstruments::onDeletePaymentInstrument( |
171 ScriptPromiseResolver* resolver, | 187 ScriptPromiseResolver* resolver, |
172 payments::mojom::blink::PaymentHandlerStatus status) { | 188 payments::mojom::blink::PaymentHandlerStatus status) { |
173 DCHECK(resolver); | 189 DCHECK(resolver); |
174 resolver->Resolve(status == | 190 resolver->Resolve(status == |
175 payments::mojom::blink::PaymentHandlerStatus::SUCCESS); | 191 payments::mojom::blink::PaymentHandlerStatus::SUCCESS); |
176 } | 192 } |
177 | 193 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 244 |
229 void PaymentInstruments::onSetPaymentInstrument( | 245 void PaymentInstruments::onSetPaymentInstrument( |
230 ScriptPromiseResolver* resolver, | 246 ScriptPromiseResolver* resolver, |
231 payments::mojom::blink::PaymentHandlerStatus status) { | 247 payments::mojom::blink::PaymentHandlerStatus status) { |
232 DCHECK(resolver); | 248 DCHECK(resolver); |
233 if (rejectError(resolver, status)) | 249 if (rejectError(resolver, status)) |
234 return; | 250 return; |
235 resolver->Resolve(); | 251 resolver->Resolve(); |
236 } | 252 } |
237 | 253 |
| 254 void PaymentInstruments::onClearPaymentInstruments( |
| 255 ScriptPromiseResolver* resolver, |
| 256 payments::mojom::blink::PaymentHandlerStatus status) { |
| 257 DCHECK(resolver); |
| 258 if (rejectError(resolver, status)) |
| 259 return; |
| 260 resolver->Resolve(); |
| 261 } |
| 262 |
238 } // namespace blink | 263 } // namespace blink |
OLD | NEW |