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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 mojom::blink::WebBluetoothDevicePtr device) { | 143 mojom::blink::WebBluetoothDevicePtr device) { |
144 if (!resolver->getExecutionContext() || | 144 if (!resolver->getExecutionContext() || |
145 resolver->getExecutionContext()->isContextDestroyed()) | 145 resolver->getExecutionContext()->isContextDestroyed()) |
146 return; | 146 return; |
147 | 147 |
148 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 148 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
149 BluetoothDevice* bluetoothDevice = | 149 BluetoothDevice* bluetoothDevice = |
150 getBluetoothDeviceRepresentingDevice(std::move(device), resolver); | 150 getBluetoothDeviceRepresentingDevice(std::move(device), resolver); |
151 resolver->resolve(bluetoothDevice); | 151 resolver->resolve(bluetoothDevice); |
152 } else { | 152 } else { |
153 resolver->reject(BluetoothError::take(resolver, result)); | 153 resolver->reject(BluetoothError::CreateDOMException(result)); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice | 157 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice |
158 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, | 158 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, |
159 const RequestDeviceOptions& options, | 159 const RequestDeviceOptions& options, |
160 ExceptionState& exceptionState) { | 160 ExceptionState& exceptionState) { |
161 ExecutionContext* context = scriptState->getExecutionContext(); | 161 ExecutionContext* context = scriptState->getExecutionContext(); |
162 | 162 |
163 // If the incumbent settings object is not a secure context, reject promise | 163 // If the incumbent settings object is not a secure context, reject promise |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 BluetoothDevice* device = m_deviceInstanceMap.get(id); | 284 BluetoothDevice* device = m_deviceInstanceMap.get(id); |
285 if (!device) { | 285 if (!device) { |
286 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); | 286 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); |
287 auto result = m_deviceInstanceMap.add(id, device); | 287 auto result = m_deviceInstanceMap.add(id, device); |
288 DCHECK(result.isNewEntry); | 288 DCHECK(result.isNewEntry); |
289 } | 289 } |
290 return device; | 290 return device; |
291 } | 291 } |
292 | 292 |
293 } // namespace blink | 293 } // namespace blink |
OLD | NEW |