| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 m_webDevice->rssi)) | 27 m_webDevice->rssi)) |
| 28 , m_gatt(BluetoothRemoteGATTServer::create(this)) | 28 , m_gatt(BluetoothRemoteGATTServer::create(this)) |
| 29 { | 29 { |
| 30 // See example in Source/platform/heap/ThreadState.h | 30 // See example in Source/platform/heap/ThreadState.h |
| 31 ThreadState::current()->registerPreFinalizer(this); | 31 ThreadState::current()->registerPreFinalizer(this); |
| 32 } | 32 } |
| 33 | 33 |
| 34 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, PassOwnP
tr<WebBluetoothDevice> webDevice) | 34 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver* resolver, PassOwnP
tr<WebBluetoothDevice> webDevice) |
| 35 { | 35 { |
| 36 ASSERT(webDevice); | 36 ASSERT(webDevice); |
| 37 BluetoothDevice* device = new BluetoothDevice(resolver->executionContext(),
webDevice); | 37 BluetoothDevice* device = new BluetoothDevice(resolver->getExecutionContext(
), webDevice); |
| 38 device->suspendIfNeeded(); | 38 device->suspendIfNeeded(); |
| 39 return device; | 39 return device; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void BluetoothDevice::dispose() | 42 void BluetoothDevice::dispose() |
| 43 { | 43 { |
| 44 disconnectGATTIfConnected(); | 44 disconnectGATTIfConnected(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void BluetoothDevice::stop() | 47 void BluetoothDevice::stop() |
| 48 { | 48 { |
| 49 disconnectGATTIfConnected(); | 49 disconnectGATTIfConnected(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void BluetoothDevice::pageVisibilityChanged() | 52 void BluetoothDevice::pageVisibilityChanged() |
| 53 { | 53 { |
| 54 if (!page()->isPageVisible() && disconnectGATTIfConnected()) { | 54 if (!page()->isPageVisible() && disconnectGATTIfConnected()) { |
| 55 dispatchEvent(Event::create(EventTypeNames::gattserverdisconnected)); | 55 dispatchEvent(Event::create(EventTypeNames::gattserverdisconnected)); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool BluetoothDevice::disconnectGATTIfConnected() | 59 bool BluetoothDevice::disconnectGATTIfConnected() |
| 60 { | 60 { |
| 61 if (m_gatt->connected()) { | 61 if (m_gatt->connected()) { |
| 62 m_gatt->setConnected(false); | 62 m_gatt->setConnected(false); |
| 63 BluetoothSupplement::fromExecutionContext(executionContext())->disconnec
t(id()); | 63 BluetoothSupplement::fromExecutionContext(getExecutionContext())->discon
nect(id()); |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 | 68 |
| 69 const WTF::AtomicString& BluetoothDevice::interfaceName() const | 69 const WTF::AtomicString& BluetoothDevice::interfaceName() const |
| 70 { | 70 { |
| 71 return EventTargetNames::BluetoothDevice; | 71 return EventTargetNames::BluetoothDevice; |
| 72 } | 72 } |
| 73 | 73 |
| 74 ExecutionContext* BluetoothDevice::executionContext() const | 74 ExecutionContext* BluetoothDevice::getExecutionContext() const |
| 75 { | 75 { |
| 76 return ActiveDOMObject::executionContext(); | 76 return ActiveDOMObject::getExecutionContext(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 DEFINE_TRACE(BluetoothDevice) | 79 DEFINE_TRACE(BluetoothDevice) |
| 80 { | 80 { |
| 81 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothDevice>::trace(
visitor); | 81 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothDevice>::trace(
visitor); |
| 82 ActiveDOMObject::trace(visitor); | 82 ActiveDOMObject::trace(visitor); |
| 83 PageLifecycleObserver::trace(visitor); | 83 PageLifecycleObserver::trace(visitor); |
| 84 visitor->trace(m_adData); | 84 visitor->trace(m_adData); |
| 85 visitor->trace(m_gatt); | 85 visitor->trace(m_gatt); |
| 86 } | 86 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 uuids[i] = m_webDevice->uuids[i]; | 127 uuids[i] = m_webDevice->uuids[i]; |
| 128 return uuids; | 128 return uuids; |
| 129 } | 129 } |
| 130 | 130 |
| 131 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) | 131 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) |
| 132 { | 132 { |
| 133 return m_gatt->connect(scriptState); | 133 return m_gatt->connect(scriptState); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |