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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() { |
93 NOTIMPLEMENTED(); | 93 NOTIMPLEMENTED(); |
94 return ScriptPromise(); | 94 return ScriptPromise(); |
95 } | 95 } |
96 | 96 |
97 ScriptPromise PaymentInstruments::has(const String& instrument_key) { | 97 ScriptPromise PaymentInstruments::has(ScriptState* script_state, |
98 NOTIMPLEMENTED(); | 98 const String& instrument_key) { |
99 return ScriptPromise(); | 99 if (!manager_.is_bound()) { |
| 100 return ScriptPromise::RejectWithDOMException( |
| 101 script_state, |
| 102 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
| 103 } |
| 104 |
| 105 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 106 ScriptPromise promise = resolver->Promise(); |
| 107 |
| 108 manager_->HasPaymentInstrument( |
| 109 instrument_key, ConvertToBaseCallback(WTF::Bind( |
| 110 &PaymentInstruments::onHasPaymentInstrument, |
| 111 WrapPersistent(this), WrapPersistent(resolver)))); |
| 112 return promise; |
100 } | 113 } |
101 | 114 |
102 ScriptPromise PaymentInstruments::set(ScriptState* script_state, | 115 ScriptPromise PaymentInstruments::set(ScriptState* script_state, |
103 const String& instrument_key, | 116 const String& instrument_key, |
104 const PaymentInstrument& details, | 117 const PaymentInstrument& details, |
105 ExceptionState& exception_state) { | 118 ExceptionState& exception_state) { |
106 if (!manager_.is_bound()) { | 119 if (!manager_.is_bound()) { |
107 return ScriptPromise::RejectWithDOMException( | 120 return ScriptPromise::RejectWithDOMException( |
108 script_state, | 121 script_state, |
109 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); | 122 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 stored_instrument->stringified_capabilities, | 190 stored_instrument->stringified_capabilities, |
178 exception_state))); | 191 exception_state))); |
179 if (exception_state.HadException()) { | 192 if (exception_state.HadException()) { |
180 exception_state.Reject(resolver); | 193 exception_state.Reject(resolver); |
181 return; | 194 return; |
182 } | 195 } |
183 } | 196 } |
184 resolver->Resolve(instrument); | 197 resolver->Resolve(instrument); |
185 } | 198 } |
186 | 199 |
| 200 void PaymentInstruments::onHasPaymentInstrument( |
| 201 ScriptPromiseResolver* resolver, |
| 202 payments::mojom::blink::PaymentHandlerStatus status) { |
| 203 DCHECK(resolver); |
| 204 resolver->Resolve(status == |
| 205 payments::mojom::blink::PaymentHandlerStatus::SUCCESS); |
| 206 } |
| 207 |
187 void PaymentInstruments::onSetPaymentInstrument( | 208 void PaymentInstruments::onSetPaymentInstrument( |
188 ScriptPromiseResolver* resolver, | 209 ScriptPromiseResolver* resolver, |
189 payments::mojom::blink::PaymentHandlerStatus status) { | 210 payments::mojom::blink::PaymentHandlerStatus status) { |
190 DCHECK(resolver); | 211 DCHECK(resolver); |
191 if (rejectError(resolver, status)) | 212 if (rejectError(resolver, status)) |
192 return; | 213 return; |
193 resolver->Resolve(); | 214 resolver->Resolve(); |
194 } | 215 } |
195 | 216 |
196 } // namespace blink | 217 } // namespace blink |
OLD | NEW |