Chromium Code Reviews| 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 { |
| 20 namespace { | |
| 21 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.
| |
| 22 { | |
| 23 return toDocument(scriptState->executionContext())->page()->visibilityState( ); | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 18 | 27 |
| 19 BluetoothDevice::BluetoothDevice(PassOwnPtr<WebBluetoothDevice> webDevice) | 28 BluetoothDevice::BluetoothDevice(PassOwnPtr<WebBluetoothDevice> webDevice) |
| 20 : m_webDevice(webDevice) | 29 : m_webDevice(webDevice) |
| 21 , m_adData(BluetoothAdvertisingData::create(m_webDevice->txPower, | 30 , m_adData(BluetoothAdvertisingData::create(m_webDevice->txPower, |
| 22 m_webDevice->rssi)) | 31 m_webDevice->rssi)) |
| 23 { | 32 { |
| 24 } | 33 } |
| 25 | 34 |
| 26 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver*, PassOwnPtr<WebBlu etoothDevice> webDevice) | 35 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver*, PassOwnPtr<WebBlu etoothDevice> webDevice) |
| 27 { | 36 { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 Vector<String> BluetoothDevice::uuids() | 81 Vector<String> BluetoothDevice::uuids() |
| 73 { | 82 { |
| 74 Vector<String> uuids(m_webDevice->uuids.size()); | 83 Vector<String> uuids(m_webDevice->uuids.size()); |
| 75 for (size_t i = 0; i < m_webDevice->uuids.size(); ++i) | 84 for (size_t i = 0; i < m_webDevice->uuids.size(); ++i) |
| 76 uuids[i] = m_webDevice->uuids[i]; | 85 uuids[i] = m_webDevice->uuids[i]; |
| 77 return uuids; | 86 return uuids; |
| 78 } | 87 } |
| 79 | 88 |
| 80 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) | 89 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) |
| 81 { | 90 { |
| 91 // TODO(ortuno): Allow connections when the tab is in the background. | |
| 92 // This is a short term solution instead of implementing a tab indicator | |
| 93 // for bluetooth connections. | |
| 94 // https://crbug.com/579746 | |
| 95 if (getPageVisibilityState(scriptState) != PageVisibilityStateVisible) { | |
| 96 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.")); | |
| 97 } | |
| 82 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); | 98 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); |
| 83 if (!webbluetooth) | 99 if (!webbluetooth) |
| 84 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | 100 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); |
| 85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 101 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| 86 ScriptPromise promise = resolver->promise(); | 102 ScriptPromise promise = resolver->promise(); |
| 87 webbluetooth->connectGATT(id(), new CallbackPromiseAdapter<BluetoothGATTRemo teServer, BluetoothError>(resolver)); | 103 webbluetooth->connectGATT(id(), new CallbackPromiseAdapter<BluetoothGATTRemo teServer, BluetoothError>(resolver)); |
| 88 return promise; | 104 return promise; |
| 89 } | 105 } |
| 90 | 106 |
| 91 } // namespace blink | 107 } // namespace blink |
| OLD | NEW |