| 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" | |
| 12 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/events/Event.h" | 12 #include "core/events/Event.h" |
| 14 #include "core/page/PageVisibilityState.h" | |
| 15 #include "modules/bluetooth/BluetoothError.h" | 13 #include "modules/bluetooth/BluetoothError.h" |
| 16 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" | 14 #include "modules/bluetooth/BluetoothRemoteGATTServer.h" |
| 17 #include "modules/bluetooth/BluetoothSupplement.h" | 15 #include "modules/bluetooth/BluetoothSupplement.h" |
| 18 #include "public/platform/modules/bluetooth/WebBluetooth.h" | 16 #include "public/platform/modules/bluetooth/WebBluetooth.h" |
| 19 | 17 |
| 20 namespace blink { | 18 namespace blink { |
| 21 | 19 |
| 22 BluetoothDevice::BluetoothDevice(ExecutionContext* context, PassOwnPtr<WebBlueto
othDevice> webDevice) | 20 BluetoothDevice::BluetoothDevice(ExecutionContext* context, PassOwnPtr<WebBlueto
othDevice> webDevice) |
| 23 : ActiveDOMObject(context) | 21 : ActiveDOMObject(context) |
| 24 , PageLifecycleObserver(toDocument(context)->page()) | |
| 25 , m_webDevice(webDevice) | 22 , m_webDevice(webDevice) |
| 26 , m_adData(BluetoothAdvertisingData::create(m_webDevice->txPower, | 23 , m_adData(BluetoothAdvertisingData::create(m_webDevice->txPower, m_webDevic
e->rssi)) |
| 27 m_webDevice->rssi)) | |
| 28 , m_gatt(BluetoothRemoteGATTServer::create(this)) | 24 , m_gatt(BluetoothRemoteGATTServer::create(this)) |
| 29 { | 25 { |
| 30 // See example in Source/platform/heap/ThreadState.h | 26 // See example in Source/platform/heap/ThreadState.h |
| 31 ThreadState::current()->registerPreFinalizer(this); | 27 ThreadState::current()->registerPreFinalizer(this); |
| 32 } | 28 } |
| 33 | 29 |
| 34 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, PassOwnP
tr<WebBluetoothDevice> webDevice) | 30 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, PassOwnP
tr<WebBluetoothDevice> webDevice) |
| 35 { | 31 { |
| 36 ASSERT(webDevice); | 32 ASSERT(webDevice); |
| 37 BluetoothDevice* device = new BluetoothDevice(resolver->getExecutionContext(
), webDevice); | 33 BluetoothDevice* device = new BluetoothDevice(resolver->getExecutionContext(
), webDevice); |
| 38 device->suspendIfNeeded(); | 34 device->suspendIfNeeded(); |
| 39 return device; | 35 return device; |
| 40 } | 36 } |
| 41 | 37 |
| 42 void BluetoothDevice::dispose() | 38 void BluetoothDevice::dispose() |
| 43 { | 39 { |
| 44 disconnectGATTIfConnected(); | 40 disconnectGATTIfConnected(); |
| 45 } | 41 } |
| 46 | 42 |
| 47 void BluetoothDevice::stop() | 43 void BluetoothDevice::stop() |
| 48 { | 44 { |
| 49 disconnectGATTIfConnected(); | 45 disconnectGATTIfConnected(); |
| 50 } | 46 } |
| 51 | 47 |
| 52 void BluetoothDevice::pageVisibilityChanged() | |
| 53 { | |
| 54 if (!page()->isPageVisible() && disconnectGATTIfConnected()) { | |
| 55 dispatchEvent(Event::create(EventTypeNames::gattserverdisconnected)); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 bool BluetoothDevice::disconnectGATTIfConnected() | 48 bool BluetoothDevice::disconnectGATTIfConnected() |
| 60 { | 49 { |
| 61 if (m_gatt->connected()) { | 50 if (m_gatt->connected()) { |
| 62 m_gatt->setConnected(false); | 51 m_gatt->setConnected(false); |
| 63 BluetoothSupplement::fromExecutionContext(getExecutionContext())->discon
nect(id()); | 52 BluetoothSupplement::fromExecutionContext(getExecutionContext())->discon
nect(id()); |
| 64 return true; | 53 return true; |
| 65 } | 54 } |
| 66 return false; | 55 return false; |
| 67 } | 56 } |
| 68 | 57 |
| 69 const WTF::AtomicString& BluetoothDevice::interfaceName() const | 58 const WTF::AtomicString& BluetoothDevice::interfaceName() const |
| 70 { | 59 { |
| 71 return EventTargetNames::BluetoothDevice; | 60 return EventTargetNames::BluetoothDevice; |
| 72 } | 61 } |
| 73 | 62 |
| 74 ExecutionContext* BluetoothDevice::getExecutionContext() const | 63 ExecutionContext* BluetoothDevice::getExecutionContext() const |
| 75 { | 64 { |
| 76 return ActiveDOMObject::getExecutionContext(); | 65 return ActiveDOMObject::getExecutionContext(); |
| 77 } | 66 } |
| 78 | 67 |
| 79 DEFINE_TRACE(BluetoothDevice) | 68 DEFINE_TRACE(BluetoothDevice) |
| 80 { | 69 { |
| 81 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothDevice>::trace(
visitor); | 70 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothDevice>::trace(
visitor); |
| 82 ActiveDOMObject::trace(visitor); | 71 ActiveDOMObject::trace(visitor); |
| 83 PageLifecycleObserver::trace(visitor); | |
| 84 visitor->trace(m_adData); | 72 visitor->trace(m_adData); |
| 85 visitor->trace(m_gatt); | 73 visitor->trace(m_gatt); |
| 86 } | 74 } |
| 87 | 75 |
| 88 unsigned BluetoothDevice::deviceClass(bool& isNull) | 76 unsigned BluetoothDevice::deviceClass(bool& isNull) |
| 89 { | 77 { |
| 90 isNull = false; | 78 isNull = false; |
| 91 return m_webDevice->deviceClass; | 79 return m_webDevice->deviceClass; |
| 92 } | 80 } |
| 93 | 81 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 uuids[i] = m_webDevice->uuids[i]; | 115 uuids[i] = m_webDevice->uuids[i]; |
| 128 return uuids; | 116 return uuids; |
| 129 } | 117 } |
| 130 | 118 |
| 131 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) | 119 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) |
| 132 { | 120 { |
| 133 return m_gatt->connect(scriptState); | 121 return m_gatt->connect(scriptState); |
| 134 } | 122 } |
| 135 | 123 |
| 136 } // namespace blink | 124 } // namespace blink |
| OLD | NEW |