Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: Source/modules/bluetooth/Bluetooth.cpp

Issue 1228283003: Attach a WebBluetooth to the LocalFrame and use it if it's available. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@error-enum-cleanup
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/Platform.h"
19 #include "public/platform/modules/bluetooth/WebBluetooth.h" 20 #include "public/platform/modules/bluetooth/WebBluetooth.h"
20 #include "public/platform/modules/bluetooth/WebRequestDeviceOptions.h" 21 #include "public/platform/modules/bluetooth/WebRequestDeviceOptions.h"
21 22
22 namespace blink { 23 namespace blink {
23 24
24 // Returns a DOMException if the conversion fails, or null if it succeeds. 25 // Returns a DOMException if the conversion fails, or null if it succeeds.
(...skipping 26 matching lines...) Expand all
51 } 52 }
52 53
53 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi ce 54 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi ce
54 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDe viceOptions& options, ExceptionState& exceptionState) 55 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDe viceOptions& options, ExceptionState& exceptionState)
55 { 56 {
56 // 2. If the algorithm is not allowed to show a popup, reject promise with a SecurityError and abort these steps. 57 // 2. If the algorithm is not allowed to show a popup, reject promise with a SecurityError and abort these steps.
57 if (!UserGestureIndicator::consumeUserGesture()) { 58 if (!UserGestureIndicator::consumeUserGesture()) {
58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SecurityError, "Must be handling a user gesture to show a permission requ est.")); 59 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SecurityError, "Must be handling a user gesture to show a permission requ est."));
59 } 60 }
60 61
61 WebBluetooth* webbluetooth = Platform::current()->bluetooth(); 62 WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
62 if (!webbluetooth) 63 if (!webbluetooth)
63 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); 64 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError));
64 65
65 // 3. In order to convert the arguments from service names and aliases to ju st UUIDs, do the following substeps: 66 // 3. In order to convert the arguments from service names and aliases to ju st UUIDs, do the following substeps:
66 WebRequestDeviceOptions webOptions; 67 WebRequestDeviceOptions webOptions;
67 convertRequestDeviceOptions(options, webOptions, exceptionState); 68 convertRequestDeviceOptions(options, webOptions, exceptionState);
68 if (exceptionState.hadException()) 69 if (exceptionState.hadException())
69 return exceptionState.reject(scriptState); 70 return exceptionState.reject(scriptState);
70 71
71 // Subsequent steps are handled in the browser process. 72 // Subsequent steps are handled in the browser process.
72 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 73 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
73 ScriptPromise promise = resolver->promise(); 74 ScriptPromise promise = resolver->promise();
74 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth Device, BluetoothError>(resolver)); 75 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth Device, BluetoothError>(resolver));
75 return promise; 76 return promise;
76 77
77 } 78 }
78 79
79 } // namespace blink 80 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/modules/bluetooth/BluetoothError.cpp » ('j') | Source/modules/bluetooth/BluetoothSupplement.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698