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/ActiveDOMObject.h" | 9 #include "core/dom/ActiveDOMObject.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" | 13 #include "public/platform/modules/bluetooth/WebBluetoothDevice.h" |
14 #include "public/platform/modules/bluetooth/WebBluetoothDeviceInit.h" | 14 #include "public/platform/modules/bluetooth/WebBluetoothDeviceInit.h" |
15 #include "wtf/OwnPtr.h" | |
16 #include "wtf/PassOwnPtr.h" | |
17 #include "wtf/text/WTFString.h" | 15 #include "wtf/text/WTFString.h" |
| 16 #include <memory> |
18 | 17 |
19 namespace blink { | 18 namespace blink { |
20 | 19 |
21 class BluetoothRemoteGATTServer; | 20 class BluetoothRemoteGATTServer; |
22 class ScriptPromise; | 21 class ScriptPromise; |
23 class ScriptPromiseResolver; | 22 class ScriptPromiseResolver; |
24 | 23 |
25 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. | 24 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. |
26 // | 25 // |
27 // Callbacks providing WebBluetoothDevice objects are handled by | 26 // Callbacks providing WebBluetoothDevice objects are handled by |
28 // CallbackPromiseAdapter templatized with this class. See this class's | 27 // CallbackPromiseAdapter templatized with this class. See this class's |
29 // "Interface required by CallbackPromiseAdapter" section and the | 28 // "Interface required by CallbackPromiseAdapter" section and the |
30 // CallbackPromiseAdapter class comments. | 29 // CallbackPromiseAdapter class comments. |
31 class BluetoothDevice final | 30 class BluetoothDevice final |
32 : public EventTargetWithInlineData | 31 : public EventTargetWithInlineData |
33 , public ActiveDOMObject | 32 , public ActiveDOMObject |
34 , public WebBluetoothDevice { | 33 , public WebBluetoothDevice { |
35 USING_PRE_FINALIZER(BluetoothDevice, dispose); | 34 USING_PRE_FINALIZER(BluetoothDevice, dispose); |
36 DEFINE_WRAPPERTYPEINFO(); | 35 DEFINE_WRAPPERTYPEINFO(); |
37 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); | 36 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); |
38 public: | 37 public: |
39 BluetoothDevice(ExecutionContext*, PassOwnPtr<WebBluetoothDeviceInit>); | 38 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); |
40 | 39 |
41 // Interface required by CallbackPromiseAdapter: | 40 // Interface required by CallbackPromiseAdapter: |
42 using WebType = OwnPtr<WebBluetoothDeviceInit>; | 41 using WebType = std::unique_ptr<WebBluetoothDeviceInit>; |
43 static BluetoothDevice* take(ScriptPromiseResolver*, PassOwnPtr<WebBluetooth
DeviceInit>); | 42 static BluetoothDevice* take(ScriptPromiseResolver*, std::unique_ptr<WebBlue
toothDeviceInit>); |
44 | 43 |
45 // We should disconnect from the device in all of the following cases: | 44 // We should disconnect from the device in all of the following cases: |
46 // 1. When the object gets GarbageCollected e.g. it went out of scope. | 45 // 1. When the object gets GarbageCollected e.g. it went out of scope. |
47 // dispose() is called in this case. | 46 // dispose() is called in this case. |
48 // 2. When the parent document gets detached e.g. reloading a page. | 47 // 2. When the parent document gets detached e.g. reloading a page. |
49 // stop() is called in this case. | 48 // stop() is called in this case. |
50 // TODO(ortuno): Users should be able to turn on notifications for | 49 // TODO(ortuno): Users should be able to turn on notifications for |
51 // events on navigator.bluetooth and still remain connected even if the | 50 // events on navigator.bluetooth and still remain connected even if the |
52 // BluetoothDevice object is garbage collected. | 51 // BluetoothDevice object is garbage collected. |
53 | 52 |
(...skipping 20 matching lines...) Expand all Loading... |
74 | 73 |
75 // IDL exposed interface: | 74 // IDL exposed interface: |
76 String id() { return m_webDevice->id; } | 75 String id() { return m_webDevice->id; } |
77 String name() { return m_webDevice->name; } | 76 String name() { return m_webDevice->name; } |
78 BluetoothRemoteGATTServer* gatt() { return m_gatt; } | 77 BluetoothRemoteGATTServer* gatt() { return m_gatt; } |
79 Vector<String> uuids(); | 78 Vector<String> uuids(); |
80 | 79 |
81 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); | 80 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); |
82 | 81 |
83 private: | 82 private: |
84 OwnPtr<WebBluetoothDeviceInit> m_webDevice; | 83 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; |
85 Member<BluetoothRemoteGATTServer> m_gatt; | 84 Member<BluetoothRemoteGATTServer> m_gatt; |
86 }; | 85 }; |
87 | 86 |
88 } // namespace blink | 87 } // namespace blink |
89 | 88 |
90 #endif // BluetoothDevice_h | 89 #endif // BluetoothDevice_h |
OLD | NEW |