| 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/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 BluetoothRemoteGATTServer; | 20 class BluetoothRemoteGATTServer; |
| 21 class ScriptPromise; | 21 class ScriptPromise; |
| 22 class ScriptPromiseResolver; | 22 class ScriptPromiseResolver; |
| 23 | 23 |
| 24 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. | 24 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. |
| 25 // | 25 // |
| 26 // Callbacks providing WebBluetoothDevice objects are handled by | 26 // Callbacks providing WebBluetoothDevice objects are handled by |
| 27 // CallbackPromiseAdapter templatized with this class. See this class's | 27 // CallbackPromiseAdapter templatized with this class. See this class's |
| 28 // "Interface required by CallbackPromiseAdapter" section and the | 28 // "Interface required by CallbackPromiseAdapter" section and the |
| 29 // CallbackPromiseAdapter class comments. | 29 // CallbackPromiseAdapter class comments. |
| 30 class BluetoothDevice final | 30 class BluetoothDevice final |
| 31 : public EventTargetWithInlineData | 31 : public EventTargetWithInlineData |
| 32 , public ActiveDOMObject | 32 , public ContextLifecycleObserver |
| 33 , public WebBluetoothDevice { | 33 , public WebBluetoothDevice { |
| 34 USING_PRE_FINALIZER(BluetoothDevice, dispose); | 34 USING_PRE_FINALIZER(BluetoothDevice, dispose); |
| 35 DEFINE_WRAPPERTYPEINFO(); | 35 DEFINE_WRAPPERTYPEINFO(); |
| 36 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); | 36 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); |
| 37 public: | 37 public: |
| 38 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); | 38 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); |
| 39 | 39 |
| 40 // Interface required by CallbackPromiseAdapter: | 40 // Interface required by CallbackPromiseAdapter: |
| 41 using WebType = std::unique_ptr<WebBluetoothDeviceInit>; | 41 using WebType = std::unique_ptr<WebBluetoothDeviceInit>; |
| 42 static BluetoothDevice* take(ScriptPromiseResolver*, std::unique_ptr<WebBlue
toothDeviceInit>); | 42 static BluetoothDevice* take(ScriptPromiseResolver*, std::unique_ptr<WebBlue
toothDeviceInit>); |
| 43 | 43 |
| 44 // 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: |
| 45 // 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. |
| 46 // dispose() is called in this case. | 46 // dispose() is called in this case. |
| 47 // 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. |
| 48 // stop() is called in this case. | 48 // stop() is called in this case. |
| 49 // TODO(ortuno): Users should be able to turn on notifications for | 49 // TODO(ortuno): Users should be able to turn on notifications for |
| 50 // events on navigator.bluetooth and still remain connected even if the | 50 // events on navigator.bluetooth and still remain connected even if the |
| 51 // BluetoothDevice object is garbage collected. | 51 // BluetoothDevice object is garbage collected. |
| 52 | 52 |
| 53 // USING_PRE_FINALIZER interface. | 53 // USING_PRE_FINALIZER interface. |
| 54 // Called before the object gets garbage collected. | 54 // Called before the object gets garbage collected. |
| 55 void dispose(); | 55 void dispose(); |
| 56 | 56 |
| 57 // ActiveDOMObject interface. | 57 // ContextLifecycleObserver interface. |
| 58 void stop() override; | 58 void contextDestroyed() override; |
| 59 | 59 |
| 60 // If gatt is connected then disconnects and sets gatt.connected to false. | 60 // If gatt is connected then disconnects and sets gatt.connected to false. |
| 61 // Returns true if gatt was disconnected. | 61 // Returns true if gatt was disconnected. |
| 62 bool disconnectGATTIfConnected(); | 62 bool disconnectGATTIfConnected(); |
| 63 | 63 |
| 64 // EventTarget methods: | 64 // EventTarget methods: |
| 65 const AtomicString& interfaceName() const override; | 65 const AtomicString& interfaceName() const override; |
| 66 ExecutionContext* getExecutionContext() const override; | 66 ExecutionContext* getExecutionContext() const override; |
| 67 | 67 |
| 68 // WebBluetoothDevice interface: | 68 // WebBluetoothDevice interface: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 80 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); | 80 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; | 83 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; |
| 84 Member<BluetoothRemoteGATTServer> m_gatt; | 84 Member<BluetoothRemoteGATTServer> m_gatt; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 } // namespace blink | 87 } // namespace blink |
| 88 | 88 |
| 89 #endif // BluetoothDevice_h | 89 #endif // BluetoothDevice_h |
| OLD | NEW |