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

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.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: Disconnect if page hidden when connected. Clean up 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/BluetoothDevice.cpp
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.cpp
index 9277df92745234fdef93a5f8b60f4bcb26df2b5c..8b36a829bdff1ec9ec077bd55b38eee8bf4f9f66 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.cpp
@@ -8,13 +8,22 @@
#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 "core/page/PageVisibilityState.h"
#include "modules/bluetooth/BluetoothError.h"
#include "modules/bluetooth/BluetoothGATTRemoteServer.h"
#include "modules/bluetooth/BluetoothSupplement.h"
#include "public/platform/modules/bluetooth/WebBluetooth.h"
namespace blink {
+namespace {
+PageVisibilityState getPageVisibilityState(ScriptState* scriptState)
Jeffrey Yasskin 2016/01/21 23:44:33 Either add a blank line after the "namespace {" or
ortuno 2016/01/22 21:34:12 Done.
+{
+ return toDocument(scriptState->executionContext())->page()->visibilityState();
+}
+
+} // namespace
BluetoothDevice::BluetoothDevice(PassOwnPtr<WebBluetoothDevice> webDevice)
: m_webDevice(webDevice)
@@ -79,6 +88,13 @@ Vector<String> BluetoothDevice::uuids()
ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState)
{
+ // TODO(ortuno): Allow connections when the tab is in the background.
+ // This is a short term solution instead of implementing a tab indicator
+ // for bluetooth connections.
+ // https://crbug.com/579746
+ if (getPageVisibilityState(scriptState) != PageVisibilityStateVisible) {
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, "Connection is only allowed while the page is visible. This is a temporary measure until we are able to effectively communicate to the user that a page is connected to a device."));
+ }
WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState);
if (!webbluetooth)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));

Powered by Google App Engine
This is Rietveld 408576698