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 "modules/payments/PaymentManager.h" | 5 #include "modules/payments/PaymentManager.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "modules/payments/PaymentAppManifest.h" | 10 #include "modules/payments/PaymentAppManifest.h" |
11 #include "modules/payments/PaymentAppOption.h" | 11 #include "modules/payments/PaymentAppOption.h" |
| 12 #include "modules/payments/PaymentInstruments.h" |
12 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 13 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
13 #include "platform/mojo/MojoHelper.h" | 14 #include "platform/mojo/MojoHelper.h" |
14 #include "public/platform/InterfaceProvider.h" | 15 #include "public/platform/InterfaceProvider.h" |
15 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 | 19 |
19 using payments::mojom::blink::PaymentAppManifest; | 20 using payments::mojom::blink::PaymentAppManifest; |
20 using payments::mojom::blink::PaymentAppManifestPtr; | 21 using payments::mojom::blink::PaymentAppManifestPtr; |
21 using payments::mojom::blink::PaymentAppOption; | 22 using payments::mojom::blink::PaymentAppOption; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 122 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
122 ScriptPromise promise = resolver->promise(); | 123 ScriptPromise promise = resolver->promise(); |
123 | 124 |
124 m_manager->GetManifest(convertToBaseCallback( | 125 m_manager->GetManifest(convertToBaseCallback( |
125 WTF::bind(&PaymentManager::onGetManifest, wrapPersistent(this), | 126 WTF::bind(&PaymentManager::onGetManifest, wrapPersistent(this), |
126 wrapPersistent(resolver)))); | 127 wrapPersistent(resolver)))); |
127 | 128 |
128 return promise; | 129 return promise; |
129 } | 130 } |
130 | 131 |
| 132 PaymentInstruments* PaymentManager::instruments() { |
| 133 if (!m_instruments) |
| 134 m_instruments = new PaymentInstruments(); |
| 135 return m_instruments; |
| 136 } |
| 137 |
131 DEFINE_TRACE(PaymentManager) { | 138 DEFINE_TRACE(PaymentManager) { |
132 visitor->trace(m_registration); | 139 visitor->trace(m_registration); |
| 140 visitor->trace(m_instruments); |
133 } | 141 } |
134 | 142 |
135 PaymentManager::PaymentManager(ServiceWorkerRegistration* registration) | 143 PaymentManager::PaymentManager(ServiceWorkerRegistration* registration) |
136 : m_registration(registration) { | 144 : m_registration(registration), m_instruments(nullptr) { |
137 DCHECK(registration); | 145 DCHECK(registration); |
138 Platform::current()->interfaceProvider()->getInterface( | 146 Platform::current()->interfaceProvider()->getInterface( |
139 mojo::MakeRequest(&m_manager)); | 147 mojo::MakeRequest(&m_manager)); |
140 | 148 |
141 m_manager.set_connection_error_handler(convertToBaseCallback(WTF::bind( | 149 m_manager.set_connection_error_handler(convertToBaseCallback(WTF::bind( |
142 &PaymentManager::onServiceConnectionError, wrapWeakPersistent(this)))); | 150 &PaymentManager::onServiceConnectionError, wrapWeakPersistent(this)))); |
143 | 151 |
144 m_manager->Init(m_registration->scope()); | 152 m_manager->Init(m_registration->scope()); |
145 } | 153 } |
146 | 154 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 "No payment app manifest associated with the service worker.")); | 198 "No payment app manifest associated with the service worker.")); |
191 break; | 199 break; |
192 } | 200 } |
193 } | 201 } |
194 | 202 |
195 void PaymentManager::onServiceConnectionError() { | 203 void PaymentManager::onServiceConnectionError() { |
196 m_manager.reset(); | 204 m_manager.reset(); |
197 } | 205 } |
198 | 206 |
199 } // namespace blink | 207 } // namespace blink |
OLD | NEW |