| 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" | 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/text/WTFString.h" | 15 #include "wtf/text/WTFString.h" |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 class BluetoothAttributeInstanceMap; | 20 class BluetoothAttributeInstanceMap; |
| 21 class BluetoothRemoteGATTCharacteristic; |
| 21 class BluetoothRemoteGATTServer; | 22 class BluetoothRemoteGATTServer; |
| 22 class BluetoothRemoteGATTService; | 23 class BluetoothRemoteGATTService; |
| 23 class ScriptPromise; | 24 class ScriptPromise; |
| 24 class ScriptPromiseResolver; | 25 class ScriptPromiseResolver; |
| 25 | 26 |
| 27 struct WebBluetoothRemoteGATTCharacteristicInit; |
| 26 struct WebBluetoothRemoteGATTService; | 28 struct WebBluetoothRemoteGATTService; |
| 27 | 29 |
| 28 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. | 30 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. |
| 29 // | 31 // |
| 30 // Callbacks providing WebBluetoothDevice objects are handled by | 32 // Callbacks providing WebBluetoothDevice objects are handled by |
| 31 // CallbackPromiseAdapter templatized with this class. See this class's | 33 // CallbackPromiseAdapter templatized with this class. See this class's |
| 32 // "Interface required by CallbackPromiseAdapter" section and the | 34 // "Interface required by CallbackPromiseAdapter" section and the |
| 33 // CallbackPromiseAdapter class comments. | 35 // CallbackPromiseAdapter class comments. |
| 34 class BluetoothDevice final : public EventTargetWithInlineData, | 36 class BluetoothDevice final : public EventTargetWithInlineData, |
| 35 public ContextLifecycleObserver, | 37 public ContextLifecycleObserver, |
| 36 public WebBluetoothDevice { | 38 public WebBluetoothDevice { |
| 37 USING_PRE_FINALIZER(BluetoothDevice, dispose); | 39 USING_PRE_FINALIZER(BluetoothDevice, dispose); |
| 38 DEFINE_WRAPPERTYPEINFO(); | 40 DEFINE_WRAPPERTYPEINFO(); |
| 39 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); | 41 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); |
| 40 | 42 |
| 41 public: | 43 public: |
| 42 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); | 44 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); |
| 43 | 45 |
| 44 // Interface required by CallbackPromiseAdapter: | 46 // Interface required by CallbackPromiseAdapter: |
| 45 using WebType = std::unique_ptr<WebBluetoothDeviceInit>; | 47 using WebType = std::unique_ptr<WebBluetoothDeviceInit>; |
| 46 static BluetoothDevice* take(ScriptPromiseResolver*, | 48 static BluetoothDevice* take(ScriptPromiseResolver*, |
| 47 std::unique_ptr<WebBluetoothDeviceInit>); | 49 std::unique_ptr<WebBluetoothDeviceInit>); |
| 48 | 50 |
| 49 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( | 51 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( |
| 50 std::unique_ptr<WebBluetoothRemoteGATTService>); | 52 std::unique_ptr<WebBluetoothRemoteGATTService>); |
| 51 bool isValidService(const String& serviceInstanceId); | 53 bool isValidService(const String& serviceInstanceId); |
| 52 | 54 |
| 55 BluetoothRemoteGATTCharacteristic* |
| 56 getOrCreateBluetoothRemoteGATTCharacteristic( |
| 57 ExecutionContext*, |
| 58 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit>, |
| 59 BluetoothRemoteGATTService*); |
| 60 |
| 53 // We should disconnect from the device in all of the following cases: | 61 // We should disconnect from the device in all of the following cases: |
| 54 // 1. When the object gets GarbageCollected e.g. it went out of scope. | 62 // 1. When the object gets GarbageCollected e.g. it went out of scope. |
| 55 // dispose() is called in this case. | 63 // dispose() is called in this case. |
| 56 // 2. When the parent document gets detached e.g. reloading a page. | 64 // 2. When the parent document gets detached e.g. reloading a page. |
| 57 // stop() is called in this case. | 65 // stop() is called in this case. |
| 58 // TODO(ortuno): Users should be able to turn on notifications for | 66 // TODO(ortuno): Users should be able to turn on notifications for |
| 59 // events on navigator.bluetooth and still remain connected even if the | 67 // events on navigator.bluetooth and still remain connected even if the |
| 60 // BluetoothDevice object is garbage collected. | 68 // BluetoothDevice object is garbage collected. |
| 61 | 69 |
| 62 // USING_PRE_FINALIZER interface. | 70 // USING_PRE_FINALIZER interface. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Holds all GATT Attributes associated with this BluetoothDevice. | 105 // Holds all GATT Attributes associated with this BluetoothDevice. |
| 98 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap; | 106 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap; |
| 99 | 107 |
| 100 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; | 108 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; |
| 101 Member<BluetoothRemoteGATTServer> m_gatt; | 109 Member<BluetoothRemoteGATTServer> m_gatt; |
| 102 }; | 110 }; |
| 103 | 111 |
| 104 } // namespace blink | 112 } // namespace blink |
| 105 | 113 |
| 106 #endif // BluetoothDevice_h | 114 #endif // BluetoothDevice_h |
| OLD | NEW |