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 BluetoothDevice_h | 5 #ifndef BluetoothDevice_h |
6 #define BluetoothDevice_h | 6 #define BluetoothDevice_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
9 #include "core/dom/ContextLifecycleObserver.h" | 9 #include "core/dom/ContextLifecycleObserver.h" |
10 #include "modules/EventTargetModules.h" | 10 #include "modules/EventTargetModules.h" |
11 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" | 11 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" |
12 #include "platform/heap/Heap.h" | 12 #include "platform/heap/Heap.h" |
13 #include "public/platform/modules/bluetooth/WebBluetoothDevice.h" | |
14 #include "public/platform/modules/bluetooth/WebBluetoothDeviceInit.h" | |
15 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
16 #include <memory> | 14 #include <memory> |
17 | 15 |
18 namespace blink { | 16 namespace blink { |
19 | 17 |
| 18 class Bluetooth; |
20 class BluetoothAttributeInstanceMap; | 19 class BluetoothAttributeInstanceMap; |
21 class BluetoothRemoteGATTCharacteristic; | 20 class BluetoothRemoteGATTCharacteristic; |
22 class BluetoothRemoteGATTServer; | 21 class BluetoothRemoteGATTServer; |
23 class BluetoothRemoteGATTService; | 22 class BluetoothRemoteGATTService; |
24 class ScriptPromiseResolver; | 23 class ScriptPromiseResolver; |
25 | 24 |
26 struct WebBluetoothRemoteGATTCharacteristicInit; | |
27 struct WebBluetoothRemoteGATTService; | |
28 | |
29 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. | 25 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. |
30 // | 26 // |
31 // Callbacks providing WebBluetoothDevice objects are handled by | 27 // Callbacks providing WebBluetoothDevice objects are handled by |
32 // CallbackPromiseAdapter templatized with this class. See this class's | 28 // CallbackPromiseAdapter templatized with this class. See this class's |
33 // "Interface required by CallbackPromiseAdapter" section and the | 29 // "Interface required by CallbackPromiseAdapter" section and the |
34 // CallbackPromiseAdapter class comments. | 30 // CallbackPromiseAdapter class comments. |
35 class BluetoothDevice final : public EventTargetWithInlineData, | 31 class BluetoothDevice final : public EventTargetWithInlineData, |
36 public ContextLifecycleObserver, | 32 public ContextLifecycleObserver { |
37 public WebBluetoothDevice { | |
38 USING_PRE_FINALIZER(BluetoothDevice, dispose); | 33 USING_PRE_FINALIZER(BluetoothDevice, dispose); |
39 DEFINE_WRAPPERTYPEINFO(); | 34 DEFINE_WRAPPERTYPEINFO(); |
40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); | 35 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); |
41 | 36 |
42 public: | 37 public: |
43 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); | 38 BluetoothDevice(ExecutionContext*, |
| 39 const String& id, |
| 40 const String& name, |
| 41 Bluetooth*); |
44 | 42 |
45 // Interface required by CallbackPromiseAdapter: | 43 // Interface required by CallbackPromiseAdapter: |
46 using WebType = std::unique_ptr<WebBluetoothDeviceInit>; | |
47 static BluetoothDevice* take(ScriptPromiseResolver*, | 44 static BluetoothDevice* take(ScriptPromiseResolver*, |
48 std::unique_ptr<WebBluetoothDeviceInit>); | 45 const String& id, |
| 46 const String& name, |
| 47 Bluetooth*); |
49 | 48 |
50 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( | 49 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( |
51 std::unique_ptr<WebBluetoothRemoteGATTService>); | 50 const String& serviceInstanceId, |
| 51 const String& uuid, |
| 52 bool isPrimary, |
| 53 const String& deviceInstanceId); |
52 bool isValidService(const String& serviceInstanceId); | 54 bool isValidService(const String& serviceInstanceId); |
53 | 55 |
54 BluetoothRemoteGATTCharacteristic* | 56 BluetoothRemoteGATTCharacteristic* |
55 getOrCreateBluetoothRemoteGATTCharacteristic( | 57 getOrCreateBluetoothRemoteGATTCharacteristic( |
56 ExecutionContext*, | 58 ExecutionContext*, |
57 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit>, | 59 const String& characteristicInstanceId, |
| 60 const String& serviceInstanceId, |
| 61 const String& uuid, |
| 62 uint32_t characteristicProperties, |
58 BluetoothRemoteGATTService*); | 63 BluetoothRemoteGATTService*); |
59 bool isValidCharacteristic(const String& characteristicInstanceId); | 64 bool isValidCharacteristic(const String& characteristicInstanceId); |
60 | 65 |
61 // We should disconnect from the device in all of the following cases: | 66 // We should disconnect from the device in all of the following cases: |
62 // 1. When the object gets GarbageCollected e.g. it went out of scope. | 67 // 1. When the object gets GarbageCollected e.g. it went out of scope. |
63 // dispose() is called in this case. | 68 // dispose() is called in this case. |
64 // 2. When the parent document gets detached e.g. reloading a page. | 69 // 2. When the parent document gets detached e.g. reloading a page. |
65 // stop() is called in this case. | 70 // stop() is called in this case. |
66 // TODO(ortuno): Users should be able to turn on notifications for | 71 // TODO(ortuno): Users should be able to turn on notifications for |
67 // events on navigator.bluetooth and still remain connected even if the | 72 // events on navigator.bluetooth and still remain connected even if the |
(...skipping 13 matching lines...) Expand all Loading... |
81 void disconnectGATTIfConnected(); | 86 void disconnectGATTIfConnected(); |
82 | 87 |
83 // Performs necessary cleanup when a device disconnects and fires | 88 // Performs necessary cleanup when a device disconnects and fires |
84 // gattserverdisconnected event. | 89 // gattserverdisconnected event. |
85 void cleanupDisconnectedDeviceAndFireEvent(); | 90 void cleanupDisconnectedDeviceAndFireEvent(); |
86 | 91 |
87 // EventTarget methods: | 92 // EventTarget methods: |
88 const AtomicString& interfaceName() const override; | 93 const AtomicString& interfaceName() const override; |
89 ExecutionContext* getExecutionContext() const override; | 94 ExecutionContext* getExecutionContext() const override; |
90 | 95 |
91 // WebBluetoothDevice interface: | 96 void dispatchGattServerDisconnected(); |
92 void dispatchGattServerDisconnected() override; | 97 |
| 98 Bluetooth* bluetooth() { return m_bluetooth; } |
93 | 99 |
94 // Interface required by Garbage Collection: | 100 // Interface required by Garbage Collection: |
95 DECLARE_VIRTUAL_TRACE(); | 101 DECLARE_VIRTUAL_TRACE(); |
96 | 102 |
97 // IDL exposed interface: | 103 // IDL exposed interface: |
98 String id() { return m_webDevice->id; } | 104 String id() { return m_id; } |
99 String name() { return m_webDevice->name; } | 105 String name() { return m_name; } |
100 BluetoothRemoteGATTServer* gatt() { return m_gatt; } | 106 BluetoothRemoteGATTServer* gatt() { return m_gatt; } |
101 | 107 |
102 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); | 108 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); |
103 | 109 |
104 private: | 110 private: |
105 // Holds all GATT Attributes associated with this BluetoothDevice. | 111 // Holds all GATT Attributes associated with this BluetoothDevice. |
106 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap; | 112 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap; |
107 | 113 |
108 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; | 114 const String m_id; |
| 115 const String m_name; |
109 Member<BluetoothRemoteGATTServer> m_gatt; | 116 Member<BluetoothRemoteGATTServer> m_gatt; |
| 117 Member<Bluetooth> m_bluetooth; |
110 }; | 118 }; |
111 | 119 |
112 } // namespace blink | 120 } // namespace blink |
113 | 121 |
114 #endif // BluetoothDevice_h | 122 #endif // BluetoothDevice_h |
OLD | NEW |