Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothGATTRemoteServer.cpp

Issue 1611773002: bluetooth: Disconnect if the page becomes hidden or is closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address haraken's comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a6f0956a84696dcec66145d9cd96bbd59f9075d9 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"
@@ -18,15 +19,56 @@
namespace blink {
-BluetoothGATTRemoteServer::BluetoothGATTRemoteServer(PassOwnPtr<WebBluetoothGATTRemoteServer> webGATT)
- : m_webGATT(webGATT)
+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 (!server->page()->isPageVisible()) {
+ server->disconnectIfConnected();
+ }
+ server->suspendIfNeeded();
+ return server;
+}
+
+void BluetoothGATTRemoteServer::dispose()
+{
+ disconnectIfConnected();
+}
+
+void BluetoothGATTRemoteServer::stop()
+{
+ disconnectIfConnected();
+}
+
+void BluetoothGATTRemoteServer::pageVisibilityChanged()
+{
+ if (!page()->isPageVisible()) {
+ disconnectIfConnected();
+ }
+}
+
+void BluetoothGATTRemoteServer::disconnectIfConnected()
+{
+ if (m_webGATT->connected) {
+ m_webGATT->connected = false;
+ WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(executionContext());
+ webbluetooth->disconnect(m_webGATT->deviceId);
+ }
+}
+
+DEFINE_TRACE(BluetoothGATTRemoteServer)
+{
+ ActiveDOMObject::trace(visitor);
+ PageLifecycleObserver::trace(visitor);
}
void BluetoothGATTRemoteServer::disconnect(ScriptState* scriptState)

Powered by Google App Engine
This is Rietveld 408576698