| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bluetooth/Bluetooth.h" | 5 #include "modules/bluetooth/Bluetooth.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 class RequestDeviceCallback : public WebBluetoothRequestDeviceCallbacks { | 149 class RequestDeviceCallback : public WebBluetoothRequestDeviceCallbacks { |
| 150 public: | 150 public: |
| 151 RequestDeviceCallback(Bluetooth* bluetooth, ScriptPromiseResolver* resolver) | 151 RequestDeviceCallback(Bluetooth* bluetooth, ScriptPromiseResolver* resolver) |
| 152 : m_bluetooth(bluetooth), m_resolver(resolver) {} | 152 : m_bluetooth(bluetooth), m_resolver(resolver) {} |
| 153 | 153 |
| 154 void onSuccess(std::unique_ptr<WebBluetoothDeviceInit> deviceInit) override { | 154 void onSuccess(std::unique_ptr<WebBluetoothDeviceInit> deviceInit) override { |
| 155 if (!m_resolver->getExecutionContext() || | 155 if (!m_resolver->getExecutionContext() || |
| 156 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 156 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 BluetoothDevice* device = m_bluetooth->getBluetoothDeviceRepresentingDevice( | 159 BluetoothDevice* device = m_bluetooth->getBluetoothDeviceRepresentingDevice( |
| 160 std::move(deviceInit), m_resolver); | 160 std::move(deviceInit), m_resolver); |
| 161 | 161 |
| 162 m_resolver->resolve(device); | 162 m_resolver->resolve(device); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void onError( | 165 void onError( |
| 166 int32_t | 166 int32_t |
| 167 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) | 167 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) |
| 168 override { | 168 override { |
| 169 if (!m_resolver->getExecutionContext() || | 169 if (!m_resolver->getExecutionContext() || |
| 170 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 170 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 171 return; | 171 return; |
| 172 m_resolver->reject(BluetoothError::take(m_resolver, error)); | 172 m_resolver->reject(BluetoothError::take(m_resolver, error)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 Persistent<Bluetooth> m_bluetooth; | 176 Persistent<Bluetooth> m_bluetooth; |
| 177 Persistent<ScriptPromiseResolver> m_resolver; | 177 Persistent<ScriptPromiseResolver> m_resolver; |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice | 180 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 String deviceId = deviceInit->id; | 234 String deviceId = deviceInit->id; |
| 235 device = BluetoothDevice::take(resolver, std::move(deviceInit)); | 235 device = BluetoothDevice::take(resolver, std::move(deviceInit)); |
| 236 | 236 |
| 237 auto result = m_deviceInstanceMap.add(deviceId, device); | 237 auto result = m_deviceInstanceMap.add(deviceId, device); |
| 238 DCHECK(result.isNewEntry); | 238 DCHECK(result.isNewEntry); |
| 239 } | 239 } |
| 240 return device; | 240 return device; |
| 241 } | 241 } |
| 242 | 242 |
| 243 } // namespace blink | 243 } // namespace blink |
| OLD | NEW |