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

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: Always use BluetoothSupplement to get the WebBluetooth instance. 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
« no previous file with comments | « no previous file | Source/modules/bluetooth/BluetoothDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
OLDNEW
« no previous file with comments | « no previous file | Source/modules/bluetooth/BluetoothDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698