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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/bluetooth/BluetoothDevice.h" | 6 #include "modules/bluetooth/BluetoothDevice.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "modules/bluetooth/BluetoothError.h" | 13 #include "modules/bluetooth/BluetoothError.h" |
| 14 #include "modules/bluetooth/BluetoothGATTRemoteServer.h" | 14 #include "modules/bluetooth/BluetoothGATTRemoteServer.h" |
| 15 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 16 #include "public/platform/modules/bluetooth/WebBluetooth.h" | 16 #include "public/platform/modules/bluetooth/WebBluetooth.h" |
| 17 #include "wtf/OwnPtr.h" | 17 #include "wtf/OwnPtr.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 BluetoothDevice::BluetoothDevice(const WebBluetoothDevice& webDevice) | 21 BluetoothDevice::BluetoothDevice(PassOwnPtr<WebBluetoothDevice> webDevice) |
|
Jeffrey Yasskin
2015/06/03 23:39:22
It does work to take OwnPtr<> here as long as you
| |
| 22 : m_webDevice(webDevice) | 22 : m_webDevice(webDevice) |
| 23 { | 23 { |
| 24 } | 24 } |
| 25 | 25 |
| 26 BluetoothDevice* BluetoothDevice::create(const WebBluetoothDevice& webDevice) | |
| 27 { | |
| 28 return new BluetoothDevice(webDevice); | |
| 29 } | |
| 30 | |
| 31 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver*, WebBluetoothDevic e* webDeviceRawPointer) | 26 BluetoothDevice* BluetoothDevice::take(ScriptPromiseResolver*, WebBluetoothDevic e* webDeviceRawPointer) |
| 32 { | 27 { |
| 33 OwnPtr<WebBluetoothDevice> webDevice = adoptPtr(webDeviceRawPointer); | 28 return new BluetoothDevice(adoptPtr(webDeviceRawPointer)); |
| 34 return BluetoothDevice::create(*webDevice); | |
| 35 } | 29 } |
| 36 | 30 |
| 37 void BluetoothDevice::dispose(WebBluetoothDevice* webDeviceRaw) | 31 void BluetoothDevice::dispose(WebBluetoothDevice* webDeviceRaw) |
| 38 { | 32 { |
| 39 delete webDeviceRaw; | 33 delete webDeviceRaw; |
| 40 } | 34 } |
| 41 | 35 |
| 42 unsigned BluetoothDevice::deviceClass(bool& isNull) | 36 unsigned BluetoothDevice::deviceClass(bool& isNull) |
| 43 { | 37 { |
| 44 isNull = false; | 38 isNull = false; |
| 45 return m_webDevice.deviceClass; | 39 return m_webDevice->deviceClass; |
| 46 } | 40 } |
| 47 | 41 |
| 48 String BluetoothDevice::vendorIDSource() | 42 String BluetoothDevice::vendorIDSource() |
| 49 { | 43 { |
| 50 switch (m_webDevice.vendorIDSource) { | 44 switch (m_webDevice->vendorIDSource) { |
| 51 case WebBluetoothDevice::VendorIDSource::Unknown: return String(); | 45 case WebBluetoothDevice::VendorIDSource::Unknown: return String(); |
| 52 case WebBluetoothDevice::VendorIDSource::Bluetooth: return "bluetooth"; | 46 case WebBluetoothDevice::VendorIDSource::Bluetooth: return "bluetooth"; |
| 53 case WebBluetoothDevice::VendorIDSource::USB: return "usb"; | 47 case WebBluetoothDevice::VendorIDSource::USB: return "usb"; |
| 54 } | 48 } |
| 55 ASSERT_NOT_REACHED(); | 49 ASSERT_NOT_REACHED(); |
| 56 return String(); | 50 return String(); |
| 57 } | 51 } |
| 58 | 52 |
| 59 unsigned BluetoothDevice::vendorID(bool& isNull) | 53 unsigned BluetoothDevice::vendorID(bool& isNull) |
| 60 { | 54 { |
| 61 isNull = false; | 55 isNull = false; |
| 62 return m_webDevice.vendorID; | 56 return m_webDevice->vendorID; |
| 63 } | 57 } |
| 64 | 58 |
| 65 unsigned BluetoothDevice::productID(bool& isNull) | 59 unsigned BluetoothDevice::productID(bool& isNull) |
| 66 { | 60 { |
| 67 isNull = false; | 61 isNull = false; |
| 68 return m_webDevice.productID; | 62 return m_webDevice->productID; |
| 69 } | 63 } |
| 70 | 64 |
| 71 unsigned BluetoothDevice::productVersion(bool& isNull) | 65 unsigned BluetoothDevice::productVersion(bool& isNull) |
| 72 { | 66 { |
| 73 isNull = false; | 67 isNull = false; |
| 74 return m_webDevice.productVersion; | 68 return m_webDevice->productVersion; |
| 75 } | 69 } |
| 76 | 70 |
| 77 bool BluetoothDevice::paired() | 71 bool BluetoothDevice::paired() |
| 78 { | 72 { |
| 79 return m_webDevice.paired; | 73 return m_webDevice->paired; |
| 80 } | 74 } |
| 81 | 75 |
| 82 Vector<String> BluetoothDevice::uuids() | 76 Vector<String> BluetoothDevice::uuids() |
| 83 { | 77 { |
| 84 Vector<String> uuids(m_webDevice.uuids.size()); | 78 Vector<String> uuids(m_webDevice->uuids.size()); |
| 85 for (size_t i = 0; i < m_webDevice.uuids.size(); ++i) | 79 for (size_t i = 0; i < m_webDevice->uuids.size(); ++i) |
| 86 uuids[i] = m_webDevice.uuids[i]; | 80 uuids[i] = m_webDevice->uuids[i]; |
| 87 return uuids; | 81 return uuids; |
| 88 } | 82 } |
| 89 | 83 |
| 90 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) | 84 ScriptPromise BluetoothDevice::connectGATT(ScriptState* scriptState) |
| 91 { | 85 { |
| 92 WebBluetooth* webbluetooth = Platform::current()->bluetooth(); | 86 WebBluetooth* webbluetooth = Platform::current()->bluetooth(); |
| 93 if (!webbluetooth) | 87 if (!webbluetooth) |
| 94 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | 88 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); |
| 95 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 89 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
| 96 ScriptPromise promise = resolver->promise(); | 90 ScriptPromise promise = resolver->promise(); |
| 97 webbluetooth->connectGATT(instanceID(), new CallbackPromiseAdapter<Bluetooth GATTRemoteServer, BluetoothError>(resolver)); | 91 webbluetooth->connectGATT(instanceID(), new CallbackPromiseAdapter<Bluetooth GATTRemoteServer, BluetoothError>(resolver)); |
| 98 return promise; | 92 return promise; |
| 99 } | 93 } |
| 100 | 94 |
| 101 } // namespace blink | 95 } // namespace blink |
| OLD | NEW |