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