Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 BluetoothGATTRemoteServer_h | 5 #ifndef BluetoothGATTRemoteServer_h |
| 6 #define BluetoothGATTRemoteServer_h | 6 #define BluetoothGATTRemoteServer_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "bindings/modules/v8/UnionTypesModules.h" | 9 #include "bindings/modules/v8/UnionTypesModules.h" |
| 10 #include "core/dom/ActiveDOMObject.h" | |
| 11 #include "core/page/PageLifecycleObserver.h" | |
| 10 #include "platform/heap/Heap.h" | 12 #include "platform/heap/Heap.h" |
| 11 #include "public/platform/modules/bluetooth/WebBluetoothGATTRemoteServer.h" | 13 #include "public/platform/modules/bluetooth/WebBluetoothGATTRemoteServer.h" |
| 12 #include "wtf/OwnPtr.h" | 14 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/PassOwnPtr.h" | 15 #include "wtf/PassOwnPtr.h" |
| 14 #include "wtf/text/WTFString.h" | 16 #include "wtf/text/WTFString.h" |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 class ScriptPromise; | 20 class ScriptPromise; |
| 19 class ScriptPromiseResolver; | 21 class ScriptPromiseResolver; |
| 20 class ScriptState; | 22 class ScriptState; |
| 21 | 23 |
| 22 // BluetoothGATTRemoteServer provides a way to interact with a connected bluetoo th peripheral. | 24 // BluetoothGATTRemoteServer provides a way to interact with a connected bluetoo th peripheral. |
| 23 // | 25 // |
| 24 // Callbacks providing WebBluetoothGATTRemoteServer objects are handled by | 26 // Callbacks providing WebBluetoothGATTRemoteServer objects are handled by |
| 25 // CallbackPromiseAdapter templatized with this class. See this class's | 27 // CallbackPromiseAdapter templatized with this class. See this class's |
| 26 // "Interface required by CallbackPromiseAdapter" section and the | 28 // "Interface required by CallbackPromiseAdapter" section and the |
| 27 // CallbackPromiseAdapter class comments. | 29 // CallbackPromiseAdapter class comments. |
| 28 class BluetoothGATTRemoteServer final | 30 class BluetoothGATTRemoteServer final |
| 29 : public GarbageCollectedFinalized<BluetoothGATTRemoteServer> | 31 : public GarbageCollectedFinalized<BluetoothGATTRemoteServer> |
| 32 , public ActiveDOMObject | |
| 33 , public PageLifecycleObserver | |
| 30 , public ScriptWrappable { | 34 , public ScriptWrappable { |
| 35 USING_PRE_FINALIZER(BluetoothGATTRemoteServer, dispose); | |
| 31 DEFINE_WRAPPERTYPEINFO(); | 36 DEFINE_WRAPPERTYPEINFO(); |
| 37 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BluetoothGATTRemoteServer); | |
| 32 public: | 38 public: |
| 33 BluetoothGATTRemoteServer(PassOwnPtr<WebBluetoothGATTRemoteServer>); | 39 BluetoothGATTRemoteServer(ExecutionContext*, PassOwnPtr<WebBluetoothGATTRemo teServer>); |
| 34 | 40 |
| 35 // Interface required by CallbackPromiseAdapter: | 41 // Interface required by CallbackPromiseAdapter: |
| 36 using WebType = OwnPtr<WebBluetoothGATTRemoteServer>; | 42 using WebType = OwnPtr<WebBluetoothGATTRemoteServer>; |
| 37 static BluetoothGATTRemoteServer* take(ScriptPromiseResolver*, PassOwnPtr<We bBluetoothGATTRemoteServer>); | 43 static BluetoothGATTRemoteServer* take(ScriptPromiseResolver*, PassOwnPtr<We bBluetoothGATTRemoteServer>); |
| 38 | 44 |
| 45 // 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. | |
| 47 // dispose() is called in this case. | |
| 48 // 2. When the parent document gets detached e.g. reloading a page. | |
| 49 // stop() is called in this case. | |
| 50 // 3. For now (https://crbug.com/579746), when the tab is no longer in the | |
| 51 // foreground e.g. change tabs. | |
| 52 // pageVisibilityChanged() is called in this case. | |
| 53 // TODO(ortuno): Users should be able to turn on notifications listen for | |
| 54 // events on navigator.bluetooth and still remain connected even if the | |
| 55 // BluetoothGATTRemoteServer object is garbage collected. | |
| 56 // TODO(ortuno): Allow connections when the tab is in the background. | |
| 57 // This is a short term solution instead of implementing a tab indicator | |
| 58 // for bluetooth connections. | |
| 59 // https://crbug.com/579746 | |
|
Jeffrey Yasskin
2016/01/22 21:59:02
You can probably remove this line.
ortuno
2016/01/22 22:18:14
Done.
| |
| 60 | |
| 61 // USING_PRE_FINALIZER interface. | |
| 62 // Called before the object gets garbage collected. | |
| 63 void dispose(); | |
| 64 | |
| 65 // ActiveDOMObject interface. | |
| 66 void stop() override; | |
| 67 | |
| 68 // PageLifecycleObserver interface. | |
| 69 void pageVisibilityChanged() override; | |
| 70 | |
| 71 void disconnectIfConnected(); | |
| 72 | |
| 39 // Interface required by Garbage Collectoin: | 73 // Interface required by Garbage Collectoin: |
| 40 DEFINE_INLINE_TRACE() { } | 74 DECLARE_VIRTUAL_TRACE(); |
| 41 | 75 |
| 42 // IDL exposed interface: | 76 // IDL exposed interface: |
| 43 bool connected() { return m_webGATT->connected; } | 77 bool connected() { return m_webGATT->connected; } |
| 44 void disconnect(ScriptState*); | 78 void disconnect(ScriptState*); |
| 45 ScriptPromise getPrimaryService(ScriptState*, const StringOrUnsignedLong& se rvice, ExceptionState&); | 79 ScriptPromise getPrimaryService(ScriptState*, const StringOrUnsignedLong& se rvice, ExceptionState&); |
| 46 | 80 |
| 47 private: | 81 private: |
| 48 OwnPtr<WebBluetoothGATTRemoteServer> m_webGATT; | 82 OwnPtr<WebBluetoothGATTRemoteServer> m_webGATT; |
| 49 }; | 83 }; |
| 50 | 84 |
| 51 } // namespace blink | 85 } // namespace blink |
| 52 | 86 |
| 53 #endif // BluetoothDevice_h | 87 #endif // BluetoothDevice_h |
| OLD | NEW |