OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "modules/bluetooth/BluetoothDevice.h" | 5 #include "modules/bluetooth/BluetoothDevice.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/Document.h" |
11 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/page/PageVisibilityState.h" |
12 #include "modules/bluetooth/BluetoothError.h" | 14 #include "modules/bluetooth/BluetoothError.h" |
13 #include "modules/bluetooth/BluetoothGATTRemoteServer.h" | 15 #include "modules/bluetooth/BluetoothGATTRemoteServer.h" |
14 #include "modules/bluetooth/BluetoothSupplement.h" | 16 #include "modules/bluetooth/BluetoothSupplement.h" |
15 #include "public/platform/modules/bluetooth/WebBluetooth.h" | 17 #include "public/platform/modules/bluetooth/WebBluetooth.h" |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 | 20 |
19 BluetoothDevice::BluetoothDevice(PassOwnPtr<WebBluetoothDevice> webDevice) | 21 BluetoothDevice::BluetoothDevice(PassOwnPtr<WebBluetoothDevice> webDevice) |
20 : m_webDevice(webDevice) | 22 : m_webDevice(webDevice) |
21 , m_adData(BluetoothAdvertisingData::create(m_webDevice->txPower, | 23 , m_adData(BluetoothAdvertisingData::create(m_webDevice->txPower, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 Vector<String> BluetoothDevice::uuids() | 74 Vector<String> BluetoothDevice::uuids() |
73 { | 75 { |
74 Vector<String> uuids(m_webDevice->uuids.size()); | 76 Vector<String> uuids(m_webDevice->uuids.size()); |
75 for (size_t i = 0; i < m_webDevice->uuids.size(); ++i) | 77 for (size_t i = 0; i < m_webDevice->uuids.size(); ++i) |
76 uuids[i] = m_webDevice->uuids[i]; | 78 uuids[i] = m_webDevice->uuids[i]; |
77 return uuids; | 79 return uuids; |
78 } | 80 } |
79 | 81 |
80 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) | 82 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) |
81 { | 83 { |
| 84 // TODO(ortuno): Allow connections when the tab is in the background. |
| 85 // This is a short term solution instead of implementing a tab indicator |
| 86 // for bluetooth connections. |
| 87 // https://crbug.com/579746 |
| 88 if (!toDocument(scriptState->executionContext())->page()->isPageVisible()) { |
| 89 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Connection is only allowed while the page is visible. Thi
s is a temporary measure until we are able to effectively communicate to the use
r that a page is connected to a device.")); |
| 90 } |
82 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); | 91 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); |
83 if (!webbluetooth) | 92 if (!webbluetooth) |
84 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 93 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
86 ScriptPromise promise = resolver->promise(); | 95 ScriptPromise promise = resolver->promise(); |
87 webbluetooth->connectGATT(id(), new CallbackPromiseAdapter<BluetoothGATTRemo
teServer, BluetoothError>(resolver)); | 96 webbluetooth->connectGATT(id(), new CallbackPromiseAdapter<BluetoothGATTRemo
teServer, BluetoothError>(resolver)); |
88 return promise; | 97 return promise; |
89 } | 98 } |
90 | 99 |
91 } // namespace blink | 100 } // namespace blink |
OLD | NEW |