| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 82 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 83 ScriptPromise promise = resolver->Promise(); | 83 ScriptPromise promise = resolver->Promise(); |
| 84 | 84 |
| 85 manager_->GetPaymentInstrument( | 85 manager_->GetPaymentInstrument( |
| 86 instrument_key, ConvertToBaseCallback(WTF::Bind( | 86 instrument_key, ConvertToBaseCallback(WTF::Bind( |
| 87 &PaymentInstruments::onGetPaymentInstrument, | 87 &PaymentInstruments::onGetPaymentInstrument, |
| 88 WrapPersistent(this), WrapPersistent(resolver)))); | 88 WrapPersistent(this), WrapPersistent(resolver)))); |
| 89 return promise; | 89 return promise; |
| 90 } | 90 } |
| 91 | 91 |
| 92 ScriptPromise PaymentInstruments::keys() { | 92 ScriptPromise PaymentInstruments::keys(ScriptState* script_state) { |
| 93 NOTIMPLEMENTED(); | 93 if (!manager_.is_bound()) { |
| 94 return ScriptPromise(); | 94 return ScriptPromise::RejectWithDOMException( |
| 95 script_state, |
| 96 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
| 97 } |
| 98 |
| 99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 100 ScriptPromise promise = resolver->Promise(); |
| 101 |
| 102 manager_->KeysOfPaymentInstruments(ConvertToBaseCallback( |
| 103 WTF::Bind(&PaymentInstruments::onKeysOfPaymentInstruments, |
| 104 WrapPersistent(this), WrapPersistent(resolver)))); |
| 105 return promise; |
| 95 } | 106 } |
| 96 | 107 |
| 97 ScriptPromise PaymentInstruments::has(ScriptState* script_state, | 108 ScriptPromise PaymentInstruments::has(ScriptState* script_state, |
| 98 const String& instrument_key) { | 109 const String& instrument_key) { |
| 99 if (!manager_.is_bound()) { | 110 if (!manager_.is_bound()) { |
| 100 return ScriptPromise::RejectWithDOMException( | 111 return ScriptPromise::RejectWithDOMException( |
| 101 script_state, | 112 script_state, |
| 102 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); | 113 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
| 103 } | 114 } |
| 104 | 115 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 stored_instrument->stringified_capabilities, | 201 stored_instrument->stringified_capabilities, |
| 191 exception_state))); | 202 exception_state))); |
| 192 if (exception_state.HadException()) { | 203 if (exception_state.HadException()) { |
| 193 exception_state.Reject(resolver); | 204 exception_state.Reject(resolver); |
| 194 return; | 205 return; |
| 195 } | 206 } |
| 196 } | 207 } |
| 197 resolver->Resolve(instrument); | 208 resolver->Resolve(instrument); |
| 198 } | 209 } |
| 199 | 210 |
| 211 void PaymentInstruments::onKeysOfPaymentInstruments( |
| 212 ScriptPromiseResolver* resolver, |
| 213 const Vector<String>& keys, |
| 214 payments::mojom::blink::PaymentHandlerStatus status) { |
| 215 DCHECK(resolver); |
| 216 if (rejectError(resolver, status)) |
| 217 return; |
| 218 resolver->Resolve(keys); |
| 219 } |
| 220 |
| 200 void PaymentInstruments::onHasPaymentInstrument( | 221 void PaymentInstruments::onHasPaymentInstrument( |
| 201 ScriptPromiseResolver* resolver, | 222 ScriptPromiseResolver* resolver, |
| 202 payments::mojom::blink::PaymentHandlerStatus status) { | 223 payments::mojom::blink::PaymentHandlerStatus status) { |
| 203 DCHECK(resolver); | 224 DCHECK(resolver); |
| 204 resolver->Resolve(status == | 225 resolver->Resolve(status == |
| 205 payments::mojom::blink::PaymentHandlerStatus::SUCCESS); | 226 payments::mojom::blink::PaymentHandlerStatus::SUCCESS); |
| 206 } | 227 } |
| 207 | 228 |
| 208 void PaymentInstruments::onSetPaymentInstrument( | 229 void PaymentInstruments::onSetPaymentInstrument( |
| 209 ScriptPromiseResolver* resolver, | 230 ScriptPromiseResolver* resolver, |
| 210 payments::mojom::blink::PaymentHandlerStatus status) { | 231 payments::mojom::blink::PaymentHandlerStatus status) { |
| 211 DCHECK(resolver); | 232 DCHECK(resolver); |
| 212 if (rejectError(resolver, status)) | 233 if (rejectError(resolver, status)) |
| 213 return; | 234 return; |
| 214 resolver->Resolve(); | 235 resolver->Resolve(); |
| 215 } | 236 } |
| 216 | 237 |
| 217 } // namespace blink | 238 } // namespace blink |
| OLD | NEW |