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 "config.h" | 5 #include "config.h" |
6 #include "modules/bluetooth/Bluetooth.h" | 6 #include "modules/bluetooth/Bluetooth.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
13 #include "modules/bluetooth/BluetoothDevice.h" | 13 #include "modules/bluetooth/BluetoothDevice.h" |
14 #include "modules/bluetooth/BluetoothError.h" | 14 #include "modules/bluetooth/BluetoothError.h" |
| 15 #include "modules/bluetooth/BluetoothSupplement.h" |
15 #include "modules/bluetooth/BluetoothUUID.h" | 16 #include "modules/bluetooth/BluetoothUUID.h" |
16 #include "modules/bluetooth/RequestDeviceOptions.h" | 17 #include "modules/bluetooth/RequestDeviceOptions.h" |
17 #include "platform/UserGestureIndicator.h" | 18 #include "platform/UserGestureIndicator.h" |
18 #include "public/platform/Platform.h" | |
19 #include "public/platform/modules/bluetooth/WebBluetooth.h" | 19 #include "public/platform/modules/bluetooth/WebBluetooth.h" |
20 #include "public/platform/modules/bluetooth/WebRequestDeviceOptions.h" | 20 #include "public/platform/modules/bluetooth/WebRequestDeviceOptions.h" |
21 | 21 |
22 namespace blink { | 22 namespace blink { |
23 | 23 |
24 // Returns a DOMException if the conversion fails, or null if it succeeds. | 24 // Returns a DOMException if the conversion fails, or null if it succeeds. |
25 static void convertRequestDeviceOptions(const RequestDeviceOptions& options, Web
RequestDeviceOptions& result, ExceptionState& exceptionState) | 25 static void convertRequestDeviceOptions(const RequestDeviceOptions& options, Web
RequestDeviceOptions& result, ExceptionState& exceptionState) |
26 { | 26 { |
27 if (options.hasFilters()) { | 27 if (options.hasFilters()) { |
28 Vector<WebBluetoothScanFilter> filters; | 28 Vector<WebBluetoothScanFilter> filters; |
(...skipping 22 matching lines...) Expand all Loading... |
51 } | 51 } |
52 | 52 |
53 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi
ce | 53 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi
ce |
54 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDe
viceOptions& options, ExceptionState& exceptionState) | 54 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDe
viceOptions& options, ExceptionState& exceptionState) |
55 { | 55 { |
56 // 2. If the algorithm is not allowed to show a popup, reject promise with a
SecurityError and abort these steps. | 56 // 2. If the algorithm is not allowed to show a popup, reject promise with a
SecurityError and abort these steps. |
57 if (!UserGestureIndicator::consumeUserGesture()) { | 57 if (!UserGestureIndicator::consumeUserGesture()) { |
58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); | 58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); |
59 } | 59 } |
60 | 60 |
61 WebBluetooth* webbluetooth = Platform::current()->bluetooth(); | 61 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState); |
62 if (!webbluetooth) | 62 if (!webbluetooth) |
63 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 63 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
64 | 64 |
65 // 3. In order to convert the arguments from service names and aliases to ju
st UUIDs, do the following substeps: | 65 // 3. In order to convert the arguments from service names and aliases to ju
st UUIDs, do the following substeps: |
66 WebRequestDeviceOptions webOptions; | 66 WebRequestDeviceOptions webOptions; |
67 convertRequestDeviceOptions(options, webOptions, exceptionState); | 67 convertRequestDeviceOptions(options, webOptions, exceptionState); |
68 if (exceptionState.hadException()) | 68 if (exceptionState.hadException()) |
69 return exceptionState.reject(scriptState); | 69 return exceptionState.reject(scriptState); |
70 | 70 |
71 // Subsequent steps are handled in the browser process. | 71 // Subsequent steps are handled in the browser process. |
72 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 72 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
73 ScriptPromise promise = resolver->promise(); | 73 ScriptPromise promise = resolver->promise(); |
74 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); | 74 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); |
75 return promise; | 75 return promise; |
76 | 76 |
77 } | 77 } |
78 | 78 |
79 } // namespace blink | 79 } // namespace blink |
OLD | NEW |