Chromium Code Reviews| Index: third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.cpp |
| diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.cpp |
| index 862d903186b11a82d6c2120023a66aad0d3e2c91..deddfc9bba6b73dc77f75ac6e3a77c9a7d6da388 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.cpp |
| @@ -8,6 +8,7 @@ |
| #include "bindings/core/v8/ScriptPromise.h" |
| #include "bindings/core/v8/ScriptPromiseResolver.h" |
| #include "core/dom/DOMException.h" |
| +#include "core/dom/Document.h" |
| #include "core/dom/ExceptionCode.h" |
| #include "modules/bluetooth/BluetoothError.h" |
| #include "modules/bluetooth/BluetoothGATTService.h" |
| @@ -17,16 +18,63 @@ |
| #include "wtf/OwnPtr.h" |
| namespace blink { |
| +namespace { |
| +bool isPageVisible(Page* page) |
|
Jeffrey Yasskin
2016/01/21 23:44:33
Add a blank line after "namespace {". (Ditto from
ortuno
2016/01/22 21:34:12
Done.
|
| +{ |
| + return page->visibilityState() == PageVisibilityStateVisible; |
| +} |
| -BluetoothGATTRemoteServer::BluetoothGATTRemoteServer(PassOwnPtr<WebBluetoothGATTRemoteServer> webGATT) |
| - : m_webGATT(webGATT) |
| +} // namespace |
| +BluetoothGATTRemoteServer::BluetoothGATTRemoteServer(ExecutionContext* context, PassOwnPtr<WebBluetoothGATTRemoteServer> webGATT) |
| + : ActiveDOMObject(context) |
| + , PageLifecycleObserver(toDocument(context)->page()) |
| + , m_webGATT(webGATT) |
| { |
| + // See example in Source/platform/heap/ThreadState.h |
| + ThreadState::current()->registerPreFinalizer(this); |
| } |
| -BluetoothGATTRemoteServer* BluetoothGATTRemoteServer::take(ScriptPromiseResolver*, PassOwnPtr<WebBluetoothGATTRemoteServer> webGATT) |
| +BluetoothGATTRemoteServer* BluetoothGATTRemoteServer::take(ScriptPromiseResolver* resolver, PassOwnPtr<WebBluetoothGATTRemoteServer> webGATT) |
| { |
| ASSERT(webGATT); |
| - return new BluetoothGATTRemoteServer(webGATT); |
| + BluetoothGATTRemoteServer* server = new BluetoothGATTRemoteServer(resolver->executionContext(), webGATT); |
| + if (!isPageVisible(server->page())) { |
| + server->disconnectIfConnected(); |
| + } |
| + server->suspendIfNeeded(); |
| + return server; |
| +} |
| + |
| +void BluetoothGATTRemoteServer::dispose() |
| +{ |
| + disconnectIfConnected(); |
| +} |
| + |
| +void BluetoothGATTRemoteServer::stop() |
| +{ |
| + disconnectIfConnected(); |
| +} |
| + |
| +void BluetoothGATTRemoteServer::pageVisibilityChanged() |
| +{ |
| + if (!isPageVisible(page())) { |
| + disconnectIfConnected(); |
| + } |
| +} |
| + |
| +void BluetoothGATTRemoteServer::disconnectIfConnected() |
| +{ |
| + if (m_webGATT->connected) { |
| + m_webGATT->connected = false; |
|
Jeffrey Yasskin
2016/01/21 23:44:33
FWIW (not for this CL), I'm uncomfortable having '
ortuno
2016/01/22 21:34:12
I agree. I think things will become clearer once w
|
| + WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(executionContext()); |
| + webbluetooth->disconnect(m_webGATT->deviceId); |
| + } |
| +} |
| + |
| +DEFINE_TRACE(BluetoothGATTRemoteServer) |
| +{ |
| + ActiveDOMObject::trace(visitor); |
| + PageLifecycleObserver::trace(visitor); |
| } |
| void BluetoothGATTRemoteServer::disconnect(ScriptState* scriptState) |