OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef Bluetooth_h | 5 #ifndef Bluetooth_h |
6 #define Bluetooth_h | 6 #define Bluetooth_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
10 #include "modules/bluetooth/BluetoothDevice.h" | 10 #include "modules/bluetooth/BluetoothDevice.h" |
11 #include "mojo/public/cpp/bindings/associated_binding.h" | |
12 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
13 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" | 12 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
14 #include <memory> | 13 #include <memory> |
15 | 14 |
16 namespace blink { | 15 namespace blink { |
17 | 16 |
18 class BluetoothRemoteGATTCharacteristic; | |
19 class RequestDeviceOptions; | 17 class RequestDeviceOptions; |
20 class ScriptPromise; | 18 class ScriptPromise; |
21 class ScriptState; | 19 class ScriptState; |
22 | 20 |
23 class Bluetooth : public GarbageCollectedFinalized<Bluetooth>, | 21 class Bluetooth final : public GarbageCollectedFinalized<Bluetooth>, |
24 public ScriptWrappable, | 22 public ScriptWrappable { |
25 public mojom::blink::WebBluetoothServiceClient { | |
26 DEFINE_WRAPPERTYPEINFO(); | 23 DEFINE_WRAPPERTYPEINFO(); |
27 USING_PRE_FINALIZER(Bluetooth, dispose); | |
28 | 24 |
29 public: | 25 public: |
30 static Bluetooth* create() { return new Bluetooth(); } | 26 static Bluetooth* create() { return new Bluetooth(); } |
31 | 27 |
32 void dispose(); | |
33 | |
34 // BluetoothDiscovery interface | 28 // BluetoothDiscovery interface |
35 ScriptPromise requestDevice(ScriptState*, | 29 ScriptPromise requestDevice(ScriptState*, |
36 const RequestDeviceOptions&, | 30 const RequestDeviceOptions&, |
37 ExceptionState&); | 31 ExceptionState&); |
38 | 32 |
39 mojom::blink::WebBluetoothService* service() { return m_service.get(); } | 33 mojom::blink::WebBluetoothService* service() { return m_service.get(); } |
40 | 34 |
41 void addToConnectedDevicesMap(const String& deviceId, BluetoothDevice*); | |
42 | |
43 void removeFromConnectedDevicesMap(const String& deviceId); | |
44 | |
45 void registerCharacteristicObject(const String& characteristicInstanceId, | |
46 BluetoothRemoteGATTCharacteristic*); | |
47 void characteristicObjectRemoved(const String& characteristicInstanceId); | |
48 | |
49 // Interface required by Garbage Collection: | 35 // Interface required by Garbage Collection: |
50 DECLARE_VIRTUAL_TRACE(); | 36 DECLARE_VIRTUAL_TRACE(); |
51 | 37 |
52 private: | 38 private: |
53 Bluetooth(); | 39 Bluetooth(); |
54 | 40 |
55 // mojom::blink::WebBluetoothServiceClient: | |
56 void RemoteCharacteristicValueChanged( | |
57 const WTF::String& characteristicInstanceId, | |
58 const WTF::Vector<uint8_t>& value) override; | |
59 void GattServerDisconnected(const WTF::String& deviceId) override; | |
60 | |
61 BluetoothDevice* getBluetoothDeviceRepresentingDevice( | 41 BluetoothDevice* getBluetoothDeviceRepresentingDevice( |
62 mojom::blink::WebBluetoothDevicePtr, | 42 mojom::blink::WebBluetoothDevicePtr, |
63 ScriptPromiseResolver*); | 43 ScriptPromiseResolver*); |
64 | 44 |
65 void RequestDeviceCallback(ScriptPromiseResolver*, | 45 void RequestDeviceCallback(ScriptPromiseResolver*, |
66 mojom::blink::WebBluetoothResult, | 46 mojom::blink::WebBluetoothResult, |
67 mojom::blink::WebBluetoothDevicePtr); | 47 mojom::blink::WebBluetoothDevicePtr); |
68 | 48 |
69 // Map of device ids to BluetoothDevice objects. | 49 // Map of device ids to BluetoothDevice objects. |
70 // Ensures only one BluetoothDevice instance represents each | 50 // Ensures only one BluetoothDevice instance represents each |
71 // Bluetooth device inside a single global object. | 51 // Bluetooth device inside a single global object. |
72 HeapHashMap<String, Member<BluetoothDevice>> m_deviceInstanceMap; | 52 HeapHashMap<String, Member<BluetoothDevice>> m_deviceInstanceMap; |
73 | 53 |
74 // Map of characteristic instance ids to BluetoothRemoteGATTCharacteristic. | |
75 // When characteristicObjectRemoved is called the characteristic should be | |
76 // removed from the map. Keeps track of what characteristics have listeners. | |
77 HeapHashMap<String, Member<BluetoothRemoteGATTCharacteristic>> | |
78 m_activeCharacteristics; | |
79 | |
80 // Map of device ids to BluetoothDevice. Added in | |
81 // BluetoothRemoteGATTServer::connect() and removed in | |
82 // BluetoothRemoteGATTServer::disconnect(). This means a device may not | |
83 // actually be connected while in this map, but that it will definitely be | |
84 // removed when the page navigates. | |
85 HeapHashMap<String, Member<BluetoothDevice>> m_connectedDevices; | |
86 | |
87 mojom::blink::WebBluetoothServicePtr m_service; | 54 mojom::blink::WebBluetoothServicePtr m_service; |
88 | |
89 // Binding associated with |m_service|. | |
90 mojo::AssociatedBinding<mojom::blink::WebBluetoothServiceClient> | |
91 m_clientBinding; | |
92 }; | 55 }; |
93 | 56 |
94 } // namespace blink | 57 } // namespace blink |
95 | 58 |
96 #endif // Bluetooth_h | 59 #endif // Bluetooth_h |
OLD | NEW |