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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 PaymentInstruments::PaymentInstruments( | 51 PaymentInstruments::PaymentInstruments( |
52 const payments::mojom::blink::PaymentManagerPtr& manager) | 52 const payments::mojom::blink::PaymentManagerPtr& manager) |
53 : manager_(manager) {} | 53 : manager_(manager) {} |
54 | 54 |
55 ScriptPromise PaymentInstruments::deleteInstrument( | 55 ScriptPromise PaymentInstruments::deleteInstrument( |
| 56 ScriptState* script_state, |
56 const String& instrument_key) { | 57 const String& instrument_key) { |
57 NOTIMPLEMENTED(); | 58 if (!manager_.is_bound()) { |
58 return ScriptPromise(); | 59 return ScriptPromise::RejectWithDOMException( |
| 60 script_state, |
| 61 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
| 62 } |
| 63 |
| 64 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 65 ScriptPromise promise = resolver->Promise(); |
| 66 |
| 67 manager_->DeletePaymentInstrument( |
| 68 instrument_key, ConvertToBaseCallback(WTF::Bind( |
| 69 &PaymentInstruments::onDeletePaymentInstrument, |
| 70 WrapPersistent(this), WrapPersistent(resolver)))); |
| 71 return promise; |
59 } | 72 } |
60 | 73 |
61 ScriptPromise PaymentInstruments::get(ScriptState* script_state, | 74 ScriptPromise PaymentInstruments::get(ScriptState* script_state, |
62 const String& instrument_key) { | 75 const String& instrument_key) { |
63 if (!manager_.is_bound()) { | 76 if (!manager_.is_bound()) { |
64 return ScriptPromise::RejectWithDOMException( | 77 return ScriptPromise::RejectWithDOMException( |
65 script_state, | 78 script_state, |
66 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); | 79 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); |
67 } | 80 } |
68 | 81 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 manager_->SetPaymentInstrument( | 136 manager_->SetPaymentInstrument( |
124 instrument_key, std::move(instrument), | 137 instrument_key, std::move(instrument), |
125 ConvertToBaseCallback( | 138 ConvertToBaseCallback( |
126 WTF::Bind(&PaymentInstruments::onSetPaymentInstrument, | 139 WTF::Bind(&PaymentInstruments::onSetPaymentInstrument, |
127 WrapPersistent(this), WrapPersistent(resolver)))); | 140 WrapPersistent(this), WrapPersistent(resolver)))); |
128 return promise; | 141 return promise; |
129 } | 142 } |
130 | 143 |
131 DEFINE_TRACE(PaymentInstruments) {} | 144 DEFINE_TRACE(PaymentInstruments) {} |
132 | 145 |
| 146 void PaymentInstruments::onDeletePaymentInstrument( |
| 147 ScriptPromiseResolver* resolver, |
| 148 payments::mojom::blink::PaymentHandlerStatus status) { |
| 149 DCHECK(resolver); |
| 150 resolver->Resolve(status == |
| 151 payments::mojom::blink::PaymentHandlerStatus::SUCCESS); |
| 152 } |
| 153 |
133 void PaymentInstruments::onGetPaymentInstrument( | 154 void PaymentInstruments::onGetPaymentInstrument( |
134 ScriptPromiseResolver* resolver, | 155 ScriptPromiseResolver* resolver, |
135 payments::mojom::blink::PaymentInstrumentPtr stored_instrument, | 156 payments::mojom::blink::PaymentInstrumentPtr stored_instrument, |
136 payments::mojom::blink::PaymentHandlerStatus status) { | 157 payments::mojom::blink::PaymentHandlerStatus status) { |
137 DCHECK(resolver); | 158 DCHECK(resolver); |
138 if (rejectError(resolver, status)) | 159 if (rejectError(resolver, status)) |
139 return; | 160 return; |
140 PaymentInstrument instrument; | 161 PaymentInstrument instrument; |
141 instrument.setName(stored_instrument->name); | 162 instrument.setName(stored_instrument->name); |
142 Vector<String> enabled_methods; | 163 Vector<String> enabled_methods; |
(...skipping 23 matching lines...) Expand all Loading... |
166 void PaymentInstruments::onSetPaymentInstrument( | 187 void PaymentInstruments::onSetPaymentInstrument( |
167 ScriptPromiseResolver* resolver, | 188 ScriptPromiseResolver* resolver, |
168 payments::mojom::blink::PaymentHandlerStatus status) { | 189 payments::mojom::blink::PaymentHandlerStatus status) { |
169 DCHECK(resolver); | 190 DCHECK(resolver); |
170 if (rejectError(resolver, status)) | 191 if (rejectError(resolver, status)) |
171 return; | 192 return; |
172 resolver->Resolve(); | 193 resolver->Resolve(); |
173 } | 194 } |
174 | 195 |
175 } // namespace blink | 196 } // namespace blink |
OLD | NEW |