| 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 "core/page/PageLifecycleObserver.h" | |
| 11 #include "modules/EventTargetModules.h" | 10 #include "modules/EventTargetModules.h" |
| 12 #include "modules/bluetooth/BluetoothAdvertisingData.h" | 11 #include "modules/bluetooth/BluetoothAdvertisingData.h" |
| 13 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" | 12 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" |
| 14 #include "platform/heap/Heap.h" | 13 #include "platform/heap/Heap.h" |
| 15 #include "public/platform/modules/bluetooth/WebBluetoothDevice.h" | 14 #include "public/platform/modules/bluetooth/WebBluetoothDevice.h" |
| 16 #include "wtf/OwnPtr.h" | 15 #include "wtf/OwnPtr.h" |
| 17 #include "wtf/PassOwnPtr.h" | 16 #include "wtf/PassOwnPtr.h" |
| 18 #include "wtf/text/WTFString.h" | 17 #include "wtf/text/WTFString.h" |
| 19 | 18 |
| 20 namespace blink { | 19 namespace blink { |
| 21 | 20 |
| 22 class BluetoothRemoteGATTServer; | 21 class BluetoothRemoteGATTServer; |
| 23 class ScriptPromise; | 22 class ScriptPromise; |
| 24 class ScriptPromiseResolver; | 23 class ScriptPromiseResolver; |
| 25 class ScriptState; | 24 class ScriptState; |
| 26 | 25 |
| 27 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. | 26 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. |
| 28 // | 27 // |
| 29 // Callbacks providing WebBluetoothDevice objects are handled by | 28 // Callbacks providing WebBluetoothDevice objects are handled by |
| 30 // CallbackPromiseAdapter templatized with this class. See this class's | 29 // CallbackPromiseAdapter templatized with this class. See this class's |
| 31 // "Interface required by CallbackPromiseAdapter" section and the | 30 // "Interface required by CallbackPromiseAdapter" section and the |
| 32 // CallbackPromiseAdapter class comments. | 31 // CallbackPromiseAdapter class comments. |
| 33 class BluetoothDevice final | 32 class BluetoothDevice final |
| 34 : public RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothDevice
> | 33 : public RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothDevice
> |
| 35 , public ActiveDOMObject | 34 , public ActiveDOMObject { |
| 36 , public PageLifecycleObserver { | |
| 37 USING_PRE_FINALIZER(BluetoothDevice, dispose); | 35 USING_PRE_FINALIZER(BluetoothDevice, dispose); |
| 38 DEFINE_WRAPPERTYPEINFO(); | 36 DEFINE_WRAPPERTYPEINFO(); |
| 39 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(BluetoothDevice); | 37 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(BluetoothDevice); |
| 40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); | 38 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); |
| 41 public: | 39 public: |
| 42 BluetoothDevice(ExecutionContext*, PassOwnPtr<WebBluetoothDevice>); | 40 BluetoothDevice(ExecutionContext*, PassOwnPtr<WebBluetoothDevice>); |
| 43 | 41 |
| 44 // Interface required by CallbackPromiseAdapter: | 42 // Interface required by CallbackPromiseAdapter: |
| 45 using WebType = OwnPtr<WebBluetoothDevice>; | 43 using WebType = OwnPtr<WebBluetoothDevice>; |
| 46 static BluetoothDevice* take(ScriptPromiseResolver*, PassOwnPtr<WebBluetooth
Device>); | 44 static BluetoothDevice* take(ScriptPromiseResolver*, PassOwnPtr<WebBluetooth
Device>); |
| 47 | 45 |
| 48 // We should disconnect from the device in all of the following cases: | 46 // We should disconnect from the device in all of the following cases: |
| 49 // 1. When the object gets GarbageCollected e.g. it went out of scope. | 47 // 1. When the object gets GarbageCollected e.g. it went out of scope. |
| 50 // dispose() is called in this case. | 48 // dispose() is called in this case. |
| 51 // 2. When the parent document gets detached e.g. reloading a page. | 49 // 2. When the parent document gets detached e.g. reloading a page. |
| 52 // stop() is called in this case. | 50 // stop() is called in this case. |
| 53 // 3. For now (https://crbug.com/579746), when the tab is no longer in the | |
| 54 // foreground e.g. change tabs. | |
| 55 // pageVisibilityChanged() is called in this case. | |
| 56 // TODO(ortuno): Users should be able to turn on notifications for | 51 // TODO(ortuno): Users should be able to turn on notifications for |
| 57 // events on navigator.bluetooth and still remain connected even if the | 52 // events on navigator.bluetooth and still remain connected even if the |
| 58 // BluetoothDevice object is garbage collected. | 53 // BluetoothDevice object is garbage collected. |
| 59 // TODO(ortuno): Allow connections when the tab is in the background. | |
| 60 // This is a short term solution instead of implementing a tab indicator | |
| 61 // for bluetooth connections. | |
| 62 | 54 |
| 63 // USING_PRE_FINALIZER interface. | 55 // USING_PRE_FINALIZER interface. |
| 64 // Called before the object gets garbage collected. | 56 // Called before the object gets garbage collected. |
| 65 void dispose(); | 57 void dispose(); |
| 66 | 58 |
| 67 // ActiveDOMObject interface. | 59 // ActiveDOMObject interface. |
| 68 void stop() override; | 60 void stop() override; |
| 69 | 61 |
| 70 // PageLifecycleObserver interface. | |
| 71 void pageVisibilityChanged() override; | |
| 72 | |
| 73 // If gatt is connected then disconnects and sets gatt.connected to false. | 62 // If gatt is connected then disconnects and sets gatt.connected to false. |
| 74 // Returns true if gatt was disconnected. | 63 // Returns true if gatt was disconnected. |
| 75 bool disconnectGATTIfConnected(); | 64 bool disconnectGATTIfConnected(); |
| 76 | 65 |
| 77 // EventTarget methods: | 66 // EventTarget methods: |
| 78 const AtomicString& interfaceName() const override; | 67 const AtomicString& interfaceName() const override; |
| 79 ExecutionContext* getExecutionContext() const override; | 68 ExecutionContext* getExecutionContext() const override; |
| 80 | 69 |
| 81 // Interface required by Garbage Collection: | 70 // Interface required by Garbage Collection: |
| 82 DECLARE_VIRTUAL_TRACE(); | 71 DECLARE_VIRTUAL_TRACE(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 100 | 89 |
| 101 private: | 90 private: |
| 102 OwnPtr<WebBluetoothDevice> m_webDevice; | 91 OwnPtr<WebBluetoothDevice> m_webDevice; |
| 103 Member<BluetoothAdvertisingData> m_adData; | 92 Member<BluetoothAdvertisingData> m_adData; |
| 104 Member<BluetoothRemoteGATTServer> m_gatt; | 93 Member<BluetoothRemoteGATTServer> m_gatt; |
| 105 }; | 94 }; |
| 106 | 95 |
| 107 } // namespace blink | 96 } // namespace blink |
| 108 | 97 |
| 109 #endif // BluetoothDevice_h | 98 #endif // BluetoothDevice_h |
| OLD | NEW |