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 #ifndef BluetoothRemoteGATTCharacteristic_h | 5 #ifndef BluetoothRemoteGATTCharacteristic_h |
6 #define BluetoothRemoteGATTCharacteristic_h | 6 #define BluetoothRemoteGATTCharacteristic_h |
7 | 7 |
| 8 #include <memory> |
8 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
9 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
10 #include "core/dom/DOMArrayPiece.h" | 11 #include "core/dom/DOMArrayPiece.h" |
11 #include "core/dom/DOMDataView.h" | 12 #include "core/dom/DOMDataView.h" |
12 #include "modules/EventTargetModules.h" | 13 #include "modules/EventTargetModules.h" |
13 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 14 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 15 #include "mojo/public/cpp/bindings/associated_binding.h" |
14 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
15 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" | 17 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
16 #include "wtf/text/WTFString.h" | 18 #include "wtf/text/WTFString.h" |
17 #include <memory> | |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 class BluetoothCharacteristicProperties; | 22 class BluetoothCharacteristicProperties; |
22 class BluetoothDevice; | 23 class BluetoothDevice; |
23 class ExecutionContext; | 24 class ExecutionContext; |
24 class ScriptPromise; | 25 class ScriptPromise; |
25 class ScriptState; | 26 class ScriptState; |
26 | 27 |
27 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is | 28 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is |
28 // a basic data element that provides further information about a peripheral's | 29 // a basic data element that provides further information about a peripheral's |
29 // service. | 30 // service. |
30 // | 31 // |
31 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are | 32 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are |
32 // handled by CallbackPromiseAdapter templatized with this class. See this | 33 // handled by CallbackPromiseAdapter templatized with this class. See this |
33 // class's "Interface required by CallbackPromiseAdapter" section and the | 34 // class's "Interface required by CallbackPromiseAdapter" section and the |
34 // CallbackPromiseAdapter class comments. | 35 // CallbackPromiseAdapter class comments. |
35 class BluetoothRemoteGATTCharacteristic final | 36 class BluetoothRemoteGATTCharacteristic final |
36 : public EventTargetWithInlineData, | 37 : public EventTargetWithInlineData, |
37 public ContextLifecycleObserver { | 38 public ContextLifecycleObserver, |
| 39 public mojom::blink::WebBluetoothCharacteristicClient { |
38 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, Dispose); | 40 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, Dispose); |
39 DEFINE_WRAPPERTYPEINFO(); | 41 DEFINE_WRAPPERTYPEINFO(); |
40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); | 42 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); |
41 | 43 |
42 public: | 44 public: |
43 explicit BluetoothRemoteGATTCharacteristic( | 45 explicit BluetoothRemoteGATTCharacteristic( |
44 ExecutionContext*, | 46 ExecutionContext*, |
45 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, | 47 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, |
46 BluetoothRemoteGATTService*, | 48 BluetoothRemoteGATTService*, |
47 BluetoothDevice*); | 49 BluetoothDevice*); |
48 | 50 |
49 static BluetoothRemoteGATTCharacteristic* Create( | 51 static BluetoothRemoteGATTCharacteristic* Create( |
50 ExecutionContext*, | 52 ExecutionContext*, |
51 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, | 53 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, |
52 BluetoothRemoteGATTService*, | 54 BluetoothRemoteGATTService*, |
53 BluetoothDevice*); | 55 BluetoothDevice*); |
54 | 56 |
55 // Save value. | 57 // Save value. |
56 void SetValue(DOMDataView*); | 58 void SetValue(DOMDataView*); |
57 | 59 |
58 void DispatchCharacteristicValueChanged(const Vector<uint8_t>& value); | 60 // mojom::blink::WebBluetoothCharacteristicClient: |
| 61 void RemoteCharacteristicValueChanged( |
| 62 const WTF::Vector<uint8_t>& value) override; |
59 | 63 |
60 // ContextLifecycleObserver interface. | 64 // ContextLifecycleObserver interface. |
61 void contextDestroyed(ExecutionContext*) override; | 65 void contextDestroyed(ExecutionContext*) override; |
62 | 66 |
63 // USING_PRE_FINALIZER interface. | 67 // USING_PRE_FINALIZER interface. |
64 // Called before the object gets garbage collected. | 68 // Called before the object gets garbage collected. |
65 void Dispose(); | 69 void Dispose(); |
66 | 70 |
67 // Notify our embedder that we should stop any notifications. | |
68 // The function only notifies the embedder once. | |
69 void NotifyCharacteristicObjectRemoved(); | |
70 | |
71 // EventTarget methods: | 71 // EventTarget methods: |
72 const AtomicString& interfaceName() const override; | 72 const AtomicString& interfaceName() const override; |
73 ExecutionContext* getExecutionContext() const; | 73 ExecutionContext* getExecutionContext() const; |
74 | 74 |
75 // Interface required by garbage collection. | 75 // Interface required by garbage collection. |
76 DECLARE_VIRTUAL_TRACE(); | 76 DECLARE_VIRTUAL_TRACE(); |
77 | 77 |
78 // IDL exposed interface: | 78 // IDL exposed interface: |
79 BluetoothRemoteGATTService* service() { return m_service; } | 79 BluetoothRemoteGATTService* service() { return m_service; } |
80 String uuid() { return m_characteristic->uuid; } | 80 String uuid() { return m_characteristic->uuid; } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 mojom::blink::WebBluetoothGATTQueryQuantity, | 123 mojom::blink::WebBluetoothGATTQueryQuantity, |
124 ScriptPromiseResolver*, | 124 ScriptPromiseResolver*, |
125 mojom::blink::WebBluetoothResult, | 125 mojom::blink::WebBluetoothResult, |
126 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> | 126 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> |
127 descriptors); | 127 descriptors); |
128 | 128 |
129 DOMException* CreateInvalidCharacteristicError(); | 129 DOMException* CreateInvalidCharacteristicError(); |
130 | 130 |
131 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; | 131 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; |
132 Member<BluetoothRemoteGATTService> m_service; | 132 Member<BluetoothRemoteGATTService> m_service; |
133 bool m_stopped; | |
134 Member<BluetoothCharacteristicProperties> m_properties; | 133 Member<BluetoothCharacteristicProperties> m_properties; |
135 Member<DOMDataView> m_value; | 134 Member<DOMDataView> m_value; |
136 Member<BluetoothDevice> m_device; | 135 Member<BluetoothDevice> m_device; |
| 136 mojo::AssociatedBinding<mojom::blink::WebBluetoothCharacteristicClient> |
| 137 m_clientBinding; |
137 }; | 138 }; |
138 | 139 |
139 } // namespace blink | 140 } // namespace blink |
140 | 141 |
141 #endif // BluetoothRemoteGATTCharacteristic_h | 142 #endif // BluetoothRemoteGATTCharacteristic_h |
OLD | NEW |