summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreillyg@chromium.org <reillyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-28 22:01:26 +0000
committerreillyg@chromium.org <reillyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-28 22:01:26 +0000
commit054293034c1e79f6ee7ff5b11e6a35673d7f38a3 (patch)
tree8f1a63690fbcdb0396c25c57d9de79d04a3853f8
parent3e65977489925662657d91d334d6e9d1b520c60a (diff)
downloadchromium_src-054293034c1e79f6ee7ff5b11e6a35673d7f38a3.zip
chromium_src-054293034c1e79f6ee7ff5b11e6a35673d7f38a3.tar.gz
chromium_src-054293034c1e79f6ee7ff5b11e6a35673d7f38a3.tar.bz2
hid: Remove size from receive APIs and return report ID separately.
The size parameter is unnecessary when calling chrome.hid.receive and chrome.hid.receiveFeatureReport because, since the caller does not know which report ID will be returned, it should always be set to the maximum input or feature report size provided by the device. The size of the report ID is now not included in the maximum report sizes for the device since it no longer effects buffer size. In addition increase consistency by always providing the report ID to the chrome.hid.receive callback instead of including it as the first byte of the data buffer only if it is non-zero. BUG= Review URL: https://codereview.chromium.org/413913003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285989 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--device/hid/hid_connection.cc14
-rw-r--r--device/hid/hid_connection.h2
-rw-r--r--device/hid/hid_connection_mac.cc14
-rw-r--r--device/hid/hid_connection_win.cc14
-rw-r--r--device/hid/hid_device_info.cc1
-rw-r--r--device/hid/hid_device_info.h1
-rw-r--r--device/hid/hid_report_descriptor.cc24
-rw-r--r--device/hid/hid_report_descriptor.h1
-rw-r--r--device/hid/hid_report_descriptor_unittest.cc17
-rw-r--r--device/hid/hid_service_linux.cc1
-rw-r--r--device/hid/hid_service_mac.cc35
-rw-r--r--device/hid/hid_service_win.cc10
-rw-r--r--extensions/browser/api/hid/hid_api.cc32
-rw-r--r--extensions/browser/api/hid/hid_api.h8
-rw-r--r--extensions/common/api/hid.idl20
15 files changed, 121 insertions, 73 deletions
diff --git a/device/hid/hid_connection.cc b/device/hid/hid_connection.cc
index 76809d3..04fe329 100644
--- a/device/hid/hid_connection.cc
+++ b/device/hid/hid_connection.cc
@@ -56,11 +56,6 @@ bool FindCollectionByReportId(const HidDeviceInfo& device_info,
return false;
}
-bool HasReportId(const HidDeviceInfo& device_info) {
- return FindCollectionByReportId(
- device_info, HidConnection::kAnyReportId, NULL);
-}
-
bool HasProtectedCollection(const HidDeviceInfo& device_info) {
return std::find_if(device_info.collections.begin(),
device_info.collections.end(),
@@ -72,7 +67,6 @@ bool HasProtectedCollection(const HidDeviceInfo& device_info) {
HidConnection::HidConnection(const HidDeviceInfo& device_info)
: device_info_(device_info) {
has_protected_collection_ = HasProtectedCollection(device_info);
- has_report_id_ = HasReportId(device_info);
}
HidConnection::~HidConnection() {
@@ -88,8 +82,8 @@ void HidConnection::Read(scoped_refptr<net::IOBufferWithSize> buffer,
return;
}
int expected_buffer_size = device_info_.max_input_report_size;
- if (!has_report_id()) {
- expected_buffer_size--;
+ if (device_info().has_report_id) {
+ expected_buffer_size++;
}
if (buffer->size() < expected_buffer_size) {
// Receive buffer is too small.
@@ -132,8 +126,8 @@ void HidConnection::GetFeatureReport(
return;
}
int expected_buffer_size = device_info_.max_feature_report_size;
- if (!has_report_id()) {
- expected_buffer_size--;
+ if (device_info().has_report_id) {
+ expected_buffer_size++;
}
if (buffer->size() < expected_buffer_size) {
// Receive buffer is too small.
diff --git a/device/hid/hid_connection.h b/device/hid/hid_connection.h
index 963b89f..bf29985 100644
--- a/device/hid/hid_connection.h
+++ b/device/hid/hid_connection.h
@@ -26,7 +26,6 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
const HidDeviceInfo& device_info() const { return device_info_; }
bool has_protected_collection() const { return has_protected_collection_; }
- bool has_report_id() const { return has_report_id_; }
const base::ThreadChecker& thread_checker() const { return thread_checker_; }
void Read(scoped_refptr<net::IOBufferWithSize> buffer,
@@ -73,7 +72,6 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
bool IsReportIdProtected(const uint8_t report_id);
const HidDeviceInfo device_info_;
- bool has_report_id_;
bool has_protected_collection_;
base::ThreadChecker thread_checker_;
diff --git a/device/hid/hid_connection_mac.cc b/device/hid/hid_connection_mac.cc
index 521f287..d497ac0 100644
--- a/device/hid/hid_connection_mac.cc
+++ b/device/hid/hid_connection_mac.cc
@@ -17,10 +17,14 @@ HidConnectionMac::HidConnectionMac(HidDeviceInfo device_info)
message_loop_ = base::MessageLoopProxy::current();
DCHECK(device_.get());
- inbound_buffer_.reset((uint8_t*)malloc(device_info.max_input_report_size));
+ size_t expected_report_size = device_info.max_input_report_size;
+ if (device_info.has_report_id) {
+ expected_report_size++;
+ }
+ inbound_buffer_.reset((uint8_t*)malloc(expected_report_size));
IOHIDDeviceRegisterInputReportCallback(device_.get(),
inbound_buffer_.get(),
- device_info.max_input_report_size,
+ expected_report_size,
&HidConnectionMac::InputReportCallback,
this);
IOHIDDeviceOpen(device_, kIOHIDOptionsTypeNone);
@@ -62,14 +66,14 @@ void HidConnectionMac::PlatformGetFeatureReport(
}
uint8_t* feature_report_buffer = reinterpret_cast<uint8_t*>(buffer->data());
- CFIndex max_feature_report_size = device_info().max_feature_report_size;
+ CFIndex report_size = buffer->size();
IOReturn result = IOHIDDeviceGetReport(device_,
kIOHIDReportTypeFeature,
report_id,
feature_report_buffer,
- &max_feature_report_size);
+ &report_size);
if (result == kIOReturnSuccess)
- callback.Run(true, max_feature_report_size);
+ callback.Run(true, report_size);
else
callback.Run(false, 0);
}
diff --git a/device/hid/hid_connection_win.cc b/device/hid/hid_connection_win.cc
index 767feac..ccdb224 100644
--- a/device/hid/hid_connection_win.cc
+++ b/device/hid/hid_connection_win.cc
@@ -124,8 +124,12 @@ HidConnectionWin::~HidConnectionWin() {
void HidConnectionWin::PlatformRead(scoped_refptr<net::IOBufferWithSize> buffer,
const HidConnection::IOCallback& callback) {
+ int expected_report_size = device_info().max_input_report_size;
+ if (device_info().has_report_id) {
+ expected_report_size++;
+ }
scoped_refptr<net::IOBufferWithSize> receive_buffer =
- new net::IOBufferWithSize(device_info().max_input_report_size);
+ new net::IOBufferWithSize(expected_report_size);
scoped_refptr<PendingHidTransfer> transfer(
new PendingHidTransfer(this, buffer, receive_buffer, callback));
@@ -164,8 +168,12 @@ void HidConnectionWin::PlatformGetFeatureReport(
uint8_t report_id,
scoped_refptr<net::IOBufferWithSize> buffer,
const IOCallback& callback) {
+ int expected_report_size = device_info().max_feature_report_size;
+ if (device_info().has_report_id) {
+ expected_report_size++;
+ }
scoped_refptr<net::IOBufferWithSize> receive_buffer =
- new net::IOBufferWithSize(device_info().max_feature_report_size);
+ new net::IOBufferWithSize(expected_report_size);
// The first byte of the destination buffer is the report ID being requested.
receive_buffer->data()[0] = report_id;
@@ -224,7 +232,7 @@ void HidConnectionWin::OnTransferFinished(
// copy the receive buffer into the target buffer, discarding the first
// byte. This is because the target buffer's owner is not expecting a
// report ID but Windows will always provide one.
- if (!has_report_id()) {
+ if (!device_info().has_report_id) {
uint8_t report_id = transfer->receive_buffer_->data()[0];
// Assert first byte is 0x00
if (report_id != HidConnection::kNullReportId) {
diff --git a/device/hid/hid_device_info.cc b/device/hid/hid_device_info.cc
index 26891f8..8601151 100644
--- a/device/hid/hid_device_info.cc
+++ b/device/hid/hid_device_info.cc
@@ -15,6 +15,7 @@ HidDeviceInfo::HidDeviceInfo()
vendor_id(0),
product_id(0),
bus_type(kHIDBusTypeUSB),
+ has_report_id(false),
max_input_report_size(0),
max_output_report_size(0),
max_feature_report_size(0) {
diff --git a/device/hid/hid_device_info.h b/device/hid/hid_device_info.h
index 2ed51ac..dde2f12 100644
--- a/device/hid/hid_device_info.h
+++ b/device/hid/hid_device_info.h
@@ -44,6 +44,7 @@ struct HidDeviceInfo {
// Top-Level Collections information.
std::vector<HidCollectionInfo> collections;
+ bool has_report_id;
int max_input_report_size;
int max_output_report_size;
int max_feature_report_size;
diff --git a/device/hid/hid_report_descriptor.cc b/device/hid/hid_report_descriptor.cc
index a06d284..c461004 100644
--- a/device/hid/hid_report_descriptor.cc
+++ b/device/hid/hid_report_descriptor.cc
@@ -28,6 +28,7 @@ HidReportDescriptor::~HidReportDescriptor() {}
void HidReportDescriptor::GetDetails(
std::vector<HidCollectionInfo>* top_level_collections,
+ bool* has_report_id,
int* max_input_report_size,
int* max_output_report_size,
int* max_feature_report_size) {
@@ -37,6 +38,7 @@ void HidReportDescriptor::GetDetails(
DCHECK(max_feature_report_size);
STLClearObject(top_level_collections);
+ *has_report_id = false;
*max_input_report_size = 0;
*max_output_report_size = 0;
*max_feature_report_size = 0;
@@ -92,14 +94,7 @@ void HidReportDescriptor::GetDetails(
// Store report ID.
top_level_collections->back().report_ids.insert(
current_item->GetShortData());
-
- // We need to increase report sizes by report ID field length.
- if (current_input_report_size > 0)
- current_input_report_size += kBitsPerByte;
- if (current_output_report_size > 0)
- current_output_report_size += kBitsPerByte;
- if (current_feature_report_size > 0)
- current_feature_report_size += kBitsPerByte;
+ *has_report_id = true;
// Update max report sizes.
*max_input_report_size =
@@ -109,7 +104,7 @@ void HidReportDescriptor::GetDetails(
*max_feature_report_size =
std::max(*max_feature_report_size, current_feature_report_size);
- // Set report sizes to be 1-byte long (report ID field).
+ // Reset the report sizes for the next report ID.
current_input_report_size = 0;
current_output_report_size = 0;
current_feature_report_size = 0;
@@ -145,17 +140,6 @@ void HidReportDescriptor::GetDetails(
}
}
- if (top_level_collections->size() > 0 &&
- top_level_collections->back().report_ids.size() > 0) {
- // We need to increase report sizes by report ID field length.
- if (current_input_report_size > 0)
- current_input_report_size += kBitsPerByte;
- if (current_output_report_size > 0)
- current_output_report_size += kBitsPerByte;
- if (current_feature_report_size > 0)
- current_feature_report_size += kBitsPerByte;
- }
-
// Update max report sizes
*max_input_report_size =
std::max(*max_input_report_size, current_input_report_size);
diff --git a/device/hid/hid_report_descriptor.h b/device/hid/hid_report_descriptor.h
index 94d90ad..b5017b7 100644
--- a/device/hid/hid_report_descriptor.h
+++ b/device/hid/hid_report_descriptor.h
@@ -28,6 +28,7 @@ class HidReportDescriptor {
// Returns top-level collections present in the descriptor,
// together with max report sizes
void GetDetails(std::vector<HidCollectionInfo>* top_level_collections,
+ bool* has_report_id,
int* max_input_report_size,
int* max_output_report_size,
int* max_feature_report_size);
diff --git a/device/hid/hid_report_descriptor_unittest.cc b/device/hid/hid_report_descriptor_unittest.cc
index 619e682..0cce2e6 100644
--- a/device/hid/hid_report_descriptor_unittest.cc
+++ b/device/hid/hid_report_descriptor_unittest.cc
@@ -297,6 +297,7 @@ class HidReportDescriptorTest : public testing::Test {
public:
void ValidateDetails(
const std::vector<HidCollectionInfo>& expected_collections,
+ const bool expected_has_report_id,
const int expected_max_input_report_size,
const int expected_max_output_report_size,
const int expected_max_feature_report_size,
@@ -305,10 +306,12 @@ class HidReportDescriptorTest : public testing::Test {
descriptor_ = new HidReportDescriptor(bytes, size);
std::vector<HidCollectionInfo> actual_collections;
+ bool actual_has_report_id;
int actual_max_input_report_size;
int actual_max_output_report_size;
int actual_max_feature_report_size;
descriptor_->GetDetails(&actual_collections,
+ &actual_has_report_id,
&actual_max_input_report_size,
&actual_max_output_report_size,
&actual_max_feature_report_size);
@@ -335,6 +338,7 @@ class HidReportDescriptorTest : public testing::Test {
actual_collections_iter++;
}
+ ASSERT_EQ(expected_has_report_id, actual_has_report_id);
ASSERT_EQ(expected_max_input_report_size, actual_max_input_report_size);
ASSERT_EQ(expected_max_output_report_size, actual_max_output_report_size);
ASSERT_EQ(expected_max_feature_report_size, actual_max_feature_report_size);
@@ -353,7 +357,8 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Digitizer) {
HidCollectionInfo expected[] = {digitizer};
ValidateDetails(std::vector<HidCollectionInfo>(
expected, expected + ARRAYSIZE_UNSAFE(expected)),
- 7,
+ true,
+ 6,
0,
0,
kDigitizer,
@@ -366,6 +371,7 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Keyboard) {
HidCollectionInfo expected[] = {keyboard};
ValidateDetails(std::vector<HidCollectionInfo>(
expected, expected + ARRAYSIZE_UNSAFE(expected)),
+ false,
8,
1,
0,
@@ -384,9 +390,10 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Monitor) {
HidCollectionInfo expected[] = {monitor};
ValidateDetails(std::vector<HidCollectionInfo>(
expected, expected + ARRAYSIZE_UNSAFE(expected)),
+ true,
0,
0,
- 244,
+ 243,
kMonitor,
sizeof(kMonitor));
}
@@ -397,6 +404,7 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_Mouse) {
HidCollectionInfo expected[] = {mouse};
ValidateDetails(std::vector<HidCollectionInfo>(
expected, expected + ARRAYSIZE_UNSAFE(expected)),
+ false,
3,
0,
0,
@@ -419,8 +427,9 @@ TEST_F(HidReportDescriptorTest, ValidateDetails_LogitechUnifyingReceiver) {
HidCollectionInfo expected[] = {hidpp_short, hidpp_long, hidpp_dj};
ValidateDetails(std::vector<HidCollectionInfo>(
expected, expected + ARRAYSIZE_UNSAFE(expected)),
- 32,
- 32,
+ true,
+ 31,
+ 31,
0,
kLogitechUnifyingReceiver,
sizeof(kLogitechUnifyingReceiver));
diff --git a/device/hid/hid_service_linux.cc b/device/hid/hid_service_linux.cc
index 25230e7..8146c14 100644
--- a/device/hid/hid_service_linux.cc
+++ b/device/hid/hid_service_linux.cc
@@ -190,6 +190,7 @@ void HidServiceLinux::OnRequestAccessComplete(
HidReportDescriptor report_descriptor(rpt_desc.value, rpt_desc.size);
report_descriptor.GetDetails(&device_info->collections,
+ &device_info->has_report_id,
&device_info->max_input_report_size,
&device_info->max_output_report_size,
&device_info->max_feature_report_size);
diff --git a/device/hid/hid_service_mac.cc b/device/hid/hid_service_mac.cc
index d7afb28..640c138 100644
--- a/device/hid/hid_service_mac.cc
+++ b/device/hid/hid_service_mac.cc
@@ -84,23 +84,27 @@ std::string GetHidStringProperty(IOHIDDeviceRef device, CFStringRef key) {
return value;
}
-void GetReportIds(IOHIDElementRef element, std::set<int>& reportIDs) {
+void GetReportIds(IOHIDElementRef element, std::set<int>* reportIDs) {
+ uint32_t reportID = IOHIDElementGetReportID(element);
+ if (reportID) {
+ reportIDs->insert(reportID);
+ }
+
CFArrayRef children = IOHIDElementGetChildren(element);
- if (!children)
+ if (!children) {
return;
+ }
+
CFIndex childrenCount = CFArrayGetCount(children);
for (CFIndex j = 0; j < childrenCount; ++j) {
const IOHIDElementRef child = static_cast<IOHIDElementRef>(
const_cast<void*>(CFArrayGetValueAtIndex(children, j)));
- uint32_t reportID = IOHIDElementGetReportID(child);
- if (reportID) {
- reportIDs.insert(reportID);
- }
GetReportIds(child, reportIDs);
}
}
void GetCollectionInfos(IOHIDDeviceRef device,
+ bool* has_report_id,
std::vector<HidCollectionInfo>* top_level_collections) {
STLClearObject(top_level_collections);
CFMutableDictionaryRef collections_filter =
@@ -117,6 +121,7 @@ void GetCollectionInfos(IOHIDDeviceRef device,
CFArrayRef collections = IOHIDDeviceCopyMatchingElements(
device, collections_filter, kIOHIDOptionsTypeNone);
CFIndex collectionsCount = CFArrayGetCount(collections);
+ *has_report_id = false;
for (CFIndex i = 0; i < collectionsCount; i++) {
const IOHIDElementRef collection = static_cast<IOHIDElementRef>(
const_cast<void*>(CFArrayGetValueAtIndex(collections, i)));
@@ -128,7 +133,10 @@ void GetCollectionInfos(IOHIDDeviceRef device,
uint16_t usage = IOHIDElementGetUsage(collection);
collection_info.usage = HidUsageAndPage(usage, page);
// Explore children recursively and retrieve their report IDs
- GetReportIds(collection, collection_info.report_ids);
+ GetReportIds(collection, &collection_info.report_ids);
+ if (collection_info.report_ids.size() > 0) {
+ *has_report_id = true;
+ }
top_level_collections->push_back(collection_info);
}
}
@@ -232,13 +240,24 @@ void HidServiceMac::PlatformAddDevice(IOHIDDeviceRef hid_device) {
GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey));
device_info.serial_number =
GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey));
- GetCollectionInfos(hid_device, &device_info.collections);
+ GetCollectionInfos(hid_device,
+ &device_info.has_report_id,
+ &device_info.collections);
device_info.max_input_report_size =
GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxInputReportSizeKey));
+ if (device_info.has_report_id && device_info.max_input_report_size > 0) {
+ device_info.max_input_report_size--;
+ }
device_info.max_output_report_size =
GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxOutputReportSizeKey));
+ if (device_info.has_report_id && device_info.max_output_report_size > 0) {
+ device_info.max_output_report_size--;
+ }
device_info.max_feature_report_size =
GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxFeatureReportSizeKey));
+ if (device_info.has_report_id && device_info.max_feature_report_size > 0) {
+ device_info.max_feature_report_size--;
+ }
AddDevice(device_info);
}
diff --git a/device/hid/hid_service_win.cc b/device/hid/hid_service_win.cc
index c3de09a..a0d6c89 100644
--- a/device/hid/hid_service_win.cc
+++ b/device/hid/hid_service_win.cc
@@ -243,12 +243,22 @@ void HidServiceWin::PlatformAddDevice(const std::string& device_path) {
int report_id = value_caps[i].ReportID;
if (report_id != 0) {
collection_info.report_ids.insert(report_id);
+ device_info.has_report_id = true;
}
}
}
}
device_info.collections.push_back(collection_info);
}
+ if (device_info.has_report_id && device_info.max_input_report_size > 0) {
+ device_info.max_input_report_size--;
+ }
+ if (device_info.has_report_id && device_info.max_output_report_size > 0) {
+ device_info.max_output_report_size--;
+ }
+ if (device_info.has_report_id && device_info.max_feature_report_size > 0) {
+ device_info.max_feature_report_size--;
+ }
HidD_FreePreparsedData(preparsed_data);
}
diff --git a/extensions/browser/api/hid/hid_api.cc b/extensions/browser/api/hid/hid_api.cc
index 7124d7b8..4e15052 100644
--- a/extensions/browser/api/hid/hid_api.cc
+++ b/extensions/browser/api/hid/hid_api.cc
@@ -182,9 +182,11 @@ void HidReceiveFunction::AsyncWorkStart() {
return;
}
- buffer_ = new net::IOBufferWithSize(parameters_->size);
- resource->connection()->Read(
- buffer_, base::Bind(&HidReceiveFunction::OnFinished, this));
+ scoped_refptr<device::HidConnection> connection = resource->connection();
+ has_report_id_ = connection->device_info().has_report_id;
+ const int size = connection->device_info().max_input_report_size;
+ buffer_ = new net::IOBufferWithSize(size + 1); // 1 byte for the report ID
+ connection->Read(buffer_, base::Bind(&HidReceiveFunction::OnFinished, this));
}
void HidReceiveFunction::OnFinished(bool success, size_t bytes) {
@@ -193,7 +195,22 @@ void HidReceiveFunction::OnFinished(bool success, size_t bytes) {
return;
}
- SetResult(base::BinaryValue::CreateWithCopiedBuffer(buffer_->data(), bytes));
+ int report_id = 0;
+ const char* data = buffer_->data();
+ if (has_report_id_) {
+ if (bytes < 1) {
+ CompleteWithError(kErrorTransfer);
+ return;
+ }
+ report_id = data[0];
+ data++;
+ bytes--;
+ }
+
+ scoped_ptr<base::ListValue> result(new base::ListValue());
+ result->Append(new base::FundamentalValue(report_id));
+ result->Append(base::BinaryValue::CreateWithCopiedBuffer(data, bytes));
+ SetResultList(result.Pass());
AsyncWorkCompleted();
}
@@ -250,8 +267,11 @@ void HidReceiveFeatureReportFunction::AsyncWorkStart() {
CompleteWithError(kErrorConnectionNotFound);
return;
}
- buffer_ = new net::IOBufferWithSize(parameters_->size);
- resource->connection()->GetFeatureReport(
+
+ scoped_refptr<device::HidConnection> connection = resource->connection();
+ const int size = connection->device_info().max_feature_report_size;
+ buffer_ = new net::IOBufferWithSize(size);
+ connection->GetFeatureReport(
static_cast<uint8_t>(parameters_->report_id),
buffer_,
base::Bind(&HidReceiveFeatureReportFunction::OnFinished, this));
diff --git a/extensions/browser/api/hid/hid_api.h b/extensions/browser/api/hid/hid_api.h
index d9ea2de..6a8808f 100644
--- a/extensions/browser/api/hid/hid_api.h
+++ b/extensions/browser/api/hid/hid_api.h
@@ -57,7 +57,6 @@ class HidGetDevicesFunction : public HidAsyncApiFunction {
virtual ~HidGetDevicesFunction();
- scoped_ptr<base::ListValue> result_;
scoped_ptr<core_api::hid::GetDevices::Params> parameters_;
private:
@@ -77,7 +76,6 @@ class HidConnectFunction : public HidAsyncApiFunction {
private:
virtual ~HidConnectFunction();
- scoped_ptr<base::ListValue> result_;
scoped_ptr<core_api::hid::Connect::Params> parameters_;
DISALLOW_COPY_AND_ASSIGN(HidConnectFunction);
@@ -96,7 +94,6 @@ class HidDisconnectFunction : public HidAsyncApiFunction {
private:
virtual ~HidDisconnectFunction();
- scoped_ptr<base::ListValue> result_;
scoped_ptr<core_api::hid::Disconnect::Params> parameters_;
DISALLOW_COPY_AND_ASSIGN(HidDisconnectFunction);
@@ -117,8 +114,8 @@ class HidReceiveFunction : public HidAsyncApiFunction {
void OnFinished(bool success, size_t bytes);
+ bool has_report_id_;
scoped_refptr<net::IOBufferWithSize> buffer_;
- scoped_ptr<base::ListValue> result_;
scoped_ptr<core_api::hid::Receive::Params> parameters_;
DISALLOW_COPY_AND_ASSIGN(HidReceiveFunction);
@@ -139,7 +136,6 @@ class HidSendFunction : public HidAsyncApiFunction {
void OnFinished(bool success, size_t bytes);
- scoped_ptr<base::ListValue> result_;
scoped_ptr<core_api::hid::Send::Params> parameters_;
DISALLOW_COPY_AND_ASSIGN(HidSendFunction);
@@ -162,7 +158,6 @@ class HidReceiveFeatureReportFunction : public HidAsyncApiFunction {
void OnFinished(bool success, size_t bytes);
scoped_refptr<net::IOBufferWithSize> buffer_;
- scoped_ptr<base::ListValue> result_;
scoped_ptr<core_api::hid::ReceiveFeatureReport::Params> parameters_;
DISALLOW_COPY_AND_ASSIGN(HidReceiveFeatureReportFunction);
@@ -183,7 +178,6 @@ class HidSendFeatureReportFunction : public HidAsyncApiFunction {
void OnFinished(bool success, size_t bytes);
- scoped_ptr<base::ListValue> result_;
scoped_ptr<core_api::hid::SendFeatureReport::Params> parameters_;
DISALLOW_COPY_AND_ASSIGN(HidSendFeatureReportFunction);
diff --git a/extensions/common/api/hid.idl b/extensions/common/api/hid.idl
index bf2cad4..c6bb316 100644
--- a/extensions/common/api/hid.idl
+++ b/extensions/common/api/hid.idl
@@ -52,10 +52,18 @@ namespace hid {
callback ConnectCallback = void (HidConnectInfo connection);
callback DisconnectCallback = void ();
- // The callback to be invoked when a <code>receive</code> or
- // <code>receiveFeatureReport</code> call is finished.
+ // The callback to be invoked when a <code>receive</code> call is finished.
+ // |reportId|: The ID of the report.
// |data|: The content of the report.
- callback ReceiveCallback = void (ArrayBuffer data);
+ callback ReceiveCallback = void (long reportId, ArrayBuffer data);
+
+ // The callback to be invoked when a <code>receiveFeatureReport</code> call
+ // is finished.
+ // |data|: The content of the report.
+ callback ReceiveFeatureReportCallback = void (ArrayBuffer data);
+
+ // The callback to be invoked when a <code>send</code> or
+ // <code>sendFeatureReport</code> call is finished.
callback SendCallback = void();
interface Functions {
@@ -83,10 +91,8 @@ namespace hid {
//
// Input reports are returned to the host through the INTERRUPT IN endpoint.
// |connectionId|: The connection from which to receive a report.
- // |size|: The size of the Input report to receive.
// |callback|: The callback to invoke with received report.
static void receive(long connectionId,
- long size,
ReceiveCallback callback);
// Send an Output report to an HID device.
@@ -107,12 +113,10 @@ namespace hid {
//
// |connectionId|: The connection to read Input report from.
// |reportId|: The report ID, or zero if none.
- // |size|: The size of the Feature report to receive.
// |callback|: The callback to invoke once the write is finished.
static void receiveFeatureReport(long connectionId,
long reportId,
- long size,
- ReceiveCallback callback);
+ ReceiveFeatureReportCallback callback);
// Send a Feature report to the device.
//