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. | |
|
Jeffrey Yasskin
2016/01/21 23:44:33
We should allow folks to turn on notifications, li
ortuno
2016/01/22 21:34:12
Done.
| |
| 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. When the tab is no longer in the foreground e.g. change tabs. | |
|
Jeffrey Yasskin
2016/01/21 23:44:33
I'd phrase this something like "For now (https://c
ortuno
2016/01/22 21:34:12
Done.
| |
| 51 // pageVisibilityChanged() is called in this case. | |
| 52 // TODO(ortuno): Allow connections when the tab is in the background. | |
| 53 // This is a short term solution instead of implementing a tab indicator | |
| 54 // for bluetooth connections. | |
| 55 // https://crbug.com/579746 | |
| 56 | |
| 57 // USING_PRE_FINALIZER interface. | |
| 58 // Called before the object gets garbage collected. | |
| 59 void dispose(); | |
| 60 | |
| 61 // ActiveDOMObject interface. | |
| 62 void stop() override; | |
| 63 | |
| 64 // PageLifecycleObserver interface. | |
| 65 void pageVisibilityChanged() override; | |
| 66 | |
| 67 void disconnectIfConnected(); | |
| 68 | |
| 39 // Interface required by Garbage Collectoin: | 69 // Interface required by Garbage Collectoin: |
| 40 DEFINE_INLINE_TRACE() { } | 70 DECLARE_VIRTUAL_TRACE(); |
| 41 | 71 |
| 42 // IDL exposed interface: | 72 // IDL exposed interface: |
| 43 bool connected() { return m_webGATT->connected; } | 73 bool connected() { return m_webGATT->connected; } |
| 44 void disconnect(ScriptState*); | 74 void disconnect(ScriptState*); |
| 45 ScriptPromise getPrimaryService(ScriptState*, const StringOrUnsignedLong& se rvice, ExceptionState&); | 75 ScriptPromise getPrimaryService(ScriptState*, const StringOrUnsignedLong& se rvice, ExceptionState&); |
| 46 | 76 |
| 47 private: | 77 private: |
| 48 OwnPtr<WebBluetoothGATTRemoteServer> m_webGATT; | 78 OwnPtr<WebBluetoothGATTRemoteServer> m_webGATT; |
| 49 }; | 79 }; |
| 50 | 80 |
| 51 } // namespace blink | 81 } // namespace blink |
| 52 | 82 |
| 53 #endif // BluetoothDevice_h | 83 #endif // BluetoothDevice_h |
| OLD | NEW |