Commit 3478c079 authored by scheib's avatar scheib Committed by Commit bot

bluetooth: Provide more device attributes in requestDevice reply.

BluetoothDispatcherHost is extended to supply all the
attributes of the BluetoothDevice web API.

Also, add device::BluetoothDevice::VENDOR_ID_MAX_VALUE for
use in the IPC message.

Depends on https://codereview.chromium.org/882223002/ to
define new attributes on WebBluetoothDevice, and will not
be visible to script until
https://codereview.chromium.org/876623003/

BUG=438305

Review URL: https://codereview.chromium.org/885723002

Cr-Commit-Position: refs/heads/master@{#313999}
parent f27dd1d7
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/browser/bluetooth/bluetooth_dispatcher_host.h" #include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
#include "base/strings/utf_string_conversions.h"
#include "content/common/bluetooth/bluetooth_messages.h" #include "content/common/bluetooth/bluetooth_messages.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
...@@ -11,10 +12,12 @@ ...@@ -11,10 +12,12 @@
using device::BluetoothAdapter; using device::BluetoothAdapter;
using device::BluetoothAdapterFactory; using device::BluetoothAdapterFactory;
using device::BluetoothDevice;
namespace content { namespace content {
const uint32 kUnspecifiedDeviceClass =
0x1F00; // bluetooth.org/en-us/specification/assigned-numbers/baseband
scoped_refptr<BluetoothDispatcherHost> BluetoothDispatcherHost::Create() { scoped_refptr<BluetoothDispatcherHost> BluetoothDispatcherHost::Create() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -75,9 +78,21 @@ void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) { ...@@ -75,9 +78,21 @@ void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) {
Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
BluetoothError::NOT_FOUND)); BluetoothError::NOT_FOUND));
} else { } else {
BluetoothDevice* device = *devices.begin(); device::BluetoothDevice* device = *devices.begin();
content::BluetoothDevice device_ipc(
device->GetAddress(), // instance_id
device->GetName(), // name
device->GetBluetoothClass(), // device_class
device->GetVendorIDSource(), // vendor_id_source
device->GetVendorID(), // vendor_id
device->GetProductID(), // product_id
device->GetDeviceID(), // product_version
device->IsPaired(), // paired
device->IsConnected(), // connected
content::BluetoothDevice::UUIDsFromBluetoothUUIDs(
device->GetUUIDs())); // uuids
Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id,
device->GetAddress())); device_ipc));
} }
return; return;
} }
...@@ -87,8 +102,22 @@ void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) { ...@@ -87,8 +102,22 @@ void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) {
return; return;
} }
case MockData::RESOLVE: { case MockData::RESOLVE: {
std::vector<std::string> uuids;
uuids.push_back("00001800-0000-1000-8000-00805f9b34fb");
uuids.push_back("00001801-0000-1000-8000-00805f9b34fb");
content::BluetoothDevice device_ipc(
"Empty Mock Device instanceID", // instance_id
base::UTF8ToUTF16("Empty Mock Device name"), // name
kUnspecifiedDeviceClass, // device_class
device::BluetoothDevice::VENDOR_ID_BLUETOOTH, // vendor_id_source
0xFFFF, // vendor_id
1, // product_id
2, // product_version
true, // paired
false, // connected
uuids); // uuids
Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id,
"Empty Mock deviceId")); device_ipc));
return; return;
} }
} }
......
...@@ -18,6 +18,7 @@ using blink::WebBluetoothDevice; ...@@ -18,6 +18,7 @@ using blink::WebBluetoothDevice;
using blink::WebBluetoothError; using blink::WebBluetoothError;
using blink::WebBluetoothRequestDeviceCallbacks; using blink::WebBluetoothRequestDeviceCallbacks;
using blink::WebString; using blink::WebString;
using blink::WebVector;
namespace content { namespace content {
...@@ -45,6 +46,20 @@ WebBluetoothError::ErrorType WebBluetoothErrorFromBluetoothError( ...@@ -45,6 +46,20 @@ WebBluetoothError::ErrorType WebBluetoothErrorFromBluetoothError(
return WebBluetoothError::NotFoundError; return WebBluetoothError::NotFoundError;
} }
WebBluetoothDevice::VendorIDSource GetWebVendorIdSource(
device::BluetoothDevice::VendorIDSource vendor_id_source) {
switch (vendor_id_source) {
case device::BluetoothDevice::VENDOR_ID_UNKNOWN:
return WebBluetoothDevice::VendorIDSource::Unknown;
case device::BluetoothDevice::VENDOR_ID_BLUETOOTH:
return WebBluetoothDevice::VendorIDSource::Bluetooth;
case device::BluetoothDevice::VENDOR_ID_USB:
return WebBluetoothDevice::VendorIDSource::USB;
}
NOTREACHED();
return WebBluetoothDevice::VendorIDSource::Unknown;
}
} // namespace } // namespace
BluetoothDispatcher::BluetoothDispatcher(ThreadSafeSender* sender) BluetoothDispatcher::BluetoothDispatcher(ThreadSafeSender* sender)
...@@ -104,11 +119,19 @@ void BluetoothDispatcher::OnWorkerRunLoopStopped() { ...@@ -104,11 +119,19 @@ void BluetoothDispatcher::OnWorkerRunLoopStopped() {
void BluetoothDispatcher::OnRequestDeviceSuccess( void BluetoothDispatcher::OnRequestDeviceSuccess(
int thread_id, int thread_id,
int request_id, int request_id,
const std::string& device_instance_id) { const BluetoothDevice& device) {
DCHECK(pending_requests_.Lookup(request_id)) << request_id; DCHECK(pending_requests_.Lookup(request_id)) << request_id;
WebVector<WebString> uuids(device.uuids.size());
for (size_t i = 0; i < device.uuids.size(); ++i)
uuids[i] = WebString::fromUTF8(device.uuids[i].c_str());
pending_requests_.Lookup(request_id) pending_requests_.Lookup(request_id)
->onSuccess( ->onSuccess(new WebBluetoothDevice(
new WebBluetoothDevice(WebString::fromUTF8(device_instance_id))); WebString::fromUTF8(device.instance_id), WebString(device.name),
device.device_class, GetWebVendorIdSource(device.vendor_id_source),
device.vendor_id, device.product_id, device.product_version,
device.paired, device.connected, uuids));
pending_requests_.Remove(request_id); pending_requests_.Remove(request_id);
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/id_map.h" #include "base/id_map.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/child/worker_task_runner.h" #include "content/child/worker_task_runner.h"
#include "content/common/bluetooth/bluetooth_device.h"
#include "content/common/bluetooth/bluetooth_error.h" #include "content/common/bluetooth/bluetooth_error.h"
#include "third_party/WebKit/public/platform/WebBluetooth.h" #include "third_party/WebKit/public/platform/WebBluetooth.h"
...@@ -56,7 +57,7 @@ class BluetoothDispatcher : public WorkerTaskRunner::Observer { ...@@ -56,7 +57,7 @@ class BluetoothDispatcher : public WorkerTaskRunner::Observer {
// IPC Handlers, see definitions in bluetooth_messages.h. // IPC Handlers, see definitions in bluetooth_messages.h.
void OnRequestDeviceSuccess(int thread_id, void OnRequestDeviceSuccess(int thread_id,
int request_id, int request_id,
const std::string& device_instance_id); const BluetoothDevice& device);
void OnRequestDeviceError(int thread_id, void OnRequestDeviceError(int thread_id,
int request_id, int request_id,
BluetoothError error_type); BluetoothError error_type);
......
include_rules = [
"+device/bluetooth",
]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/bluetooth/bluetooth_device.h"
#include "base/strings/string_util.h"
namespace content {
BluetoothDevice::BluetoothDevice()
: instance_id(""),
name(base::string16()),
device_class(0),
vendor_id_source(
device::BluetoothDevice::VendorIDSource::VENDOR_ID_UNKNOWN),
vendor_id(0),
product_id(0),
product_version(0),
paired(false),
connected(false),
uuids() {
}
BluetoothDevice::BluetoothDevice(
const std::string& instance_id,
const base::string16& name,
uint32 device_class,
device::BluetoothDevice::VendorIDSource vendor_id_source,
uint16 vendor_id,
uint16 product_id,
uint16 product_version,
bool paired,
bool connected,
const std::vector<std::string>& uuids)
: instance_id(instance_id),
name(name),
device_class(device_class),
vendor_id_source(vendor_id_source),
vendor_id(vendor_id),
product_id(product_id),
product_version(product_version),
paired(paired),
connected(connected),
uuids(uuids) {
}
BluetoothDevice::~BluetoothDevice() {
}
// static
std::vector<std::string> BluetoothDevice::UUIDsFromBluetoothUUIDs(
const device::BluetoothDevice::UUIDList& uuid_list) {
std::vector<std::string> uuids;
uuids.reserve(uuid_list.size());
for (const auto& it : uuid_list)
uuids.push_back(it.canonical_value());
return uuids;
}
} // namespace content
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_H_
#define CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_H_
#include <string>
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "content/common/content_export.h"
#include "device/bluetooth/bluetooth_device.h"
namespace content {
// Data sent over IPC representing a Bluetooth device, corresponding to
// blink::WebBluetoothDevice.
struct CONTENT_EXPORT BluetoothDevice {
BluetoothDevice();
BluetoothDevice(const std::string& instance_id,
const base::string16& name,
uint32 device_class,
device::BluetoothDevice::VendorIDSource vendor_id_source,
uint16 vendor_id,
uint16 product_id,
uint16 product_version,
bool paired,
bool connected,
const std::vector<std::string>& uuids);
~BluetoothDevice();
static std::vector<std::string> UUIDsFromBluetoothUUIDs(
const device::BluetoothDevice::UUIDList& uuid_list);
std::string instance_id;
base::string16 name;
uint32 device_class;
device::BluetoothDevice::VendorIDSource vendor_id_source;
uint16 vendor_id;
uint16 product_id;
uint16 product_version;
bool paired;
bool connected;
std::vector<std::string> uuids; // 128bit UUIDs with dashes. 36 chars.
};
} // namespace content
#endif // CONTENT_COMMON_BLUETOOTH_BLUETOOTH_DEVICE_H_
...@@ -79,10 +79,28 @@ ...@@ -79,10 +79,28 @@
// """ // """
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
#include "content/common/bluetooth/bluetooth_device.h"
#include "content/common/bluetooth/bluetooth_error.h" #include "content/common/bluetooth/bluetooth_error.h"
#define IPC_MESSAGE_START BluetoothMsgStart #define IPC_MESSAGE_START BluetoothMsgStart
IPC_ENUM_TRAITS_MAX_VALUE(
device::BluetoothDevice::VendorIDSource,
device::BluetoothDevice::VendorIDSource::VENDOR_ID_MAX_VALUE)
IPC_STRUCT_TRAITS_BEGIN(content::BluetoothDevice)
IPC_STRUCT_TRAITS_MEMBER(instance_id)
IPC_STRUCT_TRAITS_MEMBER(name)
IPC_STRUCT_TRAITS_MEMBER(device_class)
IPC_STRUCT_TRAITS_MEMBER(vendor_id_source)
IPC_STRUCT_TRAITS_MEMBER(vendor_id)
IPC_STRUCT_TRAITS_MEMBER(product_id)
IPC_STRUCT_TRAITS_MEMBER(product_version)
IPC_STRUCT_TRAITS_MEMBER(paired)
IPC_STRUCT_TRAITS_MEMBER(connected)
IPC_STRUCT_TRAITS_MEMBER(uuids)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MAX_VALUE(content::BluetoothError, IPC_ENUM_TRAITS_MAX_VALUE(content::BluetoothError,
content::BluetoothError::ENUM_MAX_VALUE) content::BluetoothError::ENUM_MAX_VALUE)
...@@ -92,7 +110,7 @@ IPC_ENUM_TRAITS_MAX_VALUE(content::BluetoothError, ...@@ -92,7 +110,7 @@ IPC_ENUM_TRAITS_MAX_VALUE(content::BluetoothError,
IPC_MESSAGE_CONTROL3(BluetoothMsg_RequestDeviceSuccess, IPC_MESSAGE_CONTROL3(BluetoothMsg_RequestDeviceSuccess,
int /* thread_id */, int /* thread_id */,
int /* request_id */, int /* request_id */,
std::string /* device_instance_id */) content::BluetoothDevice /* device */)
// Informs the renderer that the device request |request_id| failed. // Informs the renderer that the device request |request_id| failed.
IPC_MESSAGE_CONTROL3(BluetoothMsg_RequestDeviceError, IPC_MESSAGE_CONTROL3(BluetoothMsg_RequestDeviceError,
......
...@@ -171,6 +171,8 @@ ...@@ -171,6 +171,8 @@
'common/appcache_interfaces.cc', 'common/appcache_interfaces.cc',
'common/appcache_interfaces.h', 'common/appcache_interfaces.h',
'common/appcache_messages.h', 'common/appcache_messages.h',
'common/bluetooth/bluetooth_device.cc',
'common/bluetooth/bluetooth_device.h',
'common/bluetooth/bluetooth_error.h', 'common/bluetooth/bluetooth_error.h',
'common/bluetooth/bluetooth_messages.h', 'common/bluetooth/bluetooth_messages.h',
'common/browser_plugin/browser_plugin_constants.cc', 'common/browser_plugin/browser_plugin_constants.cc',
......
...@@ -47,7 +47,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { ...@@ -47,7 +47,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
enum VendorIDSource { enum VendorIDSource {
VENDOR_ID_UNKNOWN, VENDOR_ID_UNKNOWN,
VENDOR_ID_BLUETOOTH, VENDOR_ID_BLUETOOTH,
VENDOR_ID_USB VENDOR_ID_USB,
VENDOR_ID_MAX_VALUE = VENDOR_ID_USB
}; };
// Possible values that may be returned by GetDeviceType(), representing // Possible values that may be returned by GetDeviceType(), representing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment