Commit 91fcb1ca authored by Ke He's avatar Ke He Committed by Commit Bot

Remove the duplicated Hid structure definitions in C++

The HidCollectionInfo and HidUsageAndPage were defined in mojom,
so the duplicated definitions in C++ should be removed.

The hid.typemap and struct traits are also removed.

BUG=728223

Change-Id: Id53d19ebb930b9b60910c8b23a145dbf058a7f8a
Reviewed-on: https://chromium-review.googlesource.com/708775
Commit-Queue: Ke He <ke.he@intel.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509324}
parent ef60662c
......@@ -11,8 +11,6 @@ source_set("hid") {
assert(!is_android)
sources = [
"hid_collection_info.cc",
"hid_collection_info.h",
"hid_connection.cc",
"hid_connection.h",
"hid_connection_impl.cc",
......@@ -39,8 +37,6 @@ source_set("hid") {
"hid_service_mac.h",
"hid_service_win.cc",
"hid_service_win.h",
"hid_usage_and_page.cc",
"hid_usage_and_page.h",
]
deps = [
......@@ -51,6 +47,7 @@ source_set("hid") {
]
public_deps = [
"//device/hid/public/cpp",
"//device/hid/public/interfaces",
]
......
// 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.
#ifndef DEVICE_HID_HID_COLLECTION_INFO_H_
#define DEVICE_HID_HID_COLLECTION_INFO_H_
#include <set>
#include "device/hid/hid_usage_and_page.h"
namespace device {
struct HidCollectionInfo {
HidCollectionInfo();
HidCollectionInfo(const HidCollectionInfo& other);
~HidCollectionInfo();
// Collection's usage ID.
HidUsageAndPage usage;
// HID report IDs which belong
// to this collection or to its
// embedded collections.
std::set<int> report_ids;
};
} // namespace device"
#endif // DEVICE_HID_HID_COLLECTION_INFO_H_
......@@ -8,6 +8,8 @@
#include "base/stl_util.h"
#include "components/device_event_log/device_event_log.h"
#include "device/hid/public/cpp/hid_usage_and_page.h"
#include "device/hid/public/interfaces/hid.mojom.h"
namespace device {
......@@ -17,15 +19,15 @@ namespace {
struct CollectionHasReportId {
explicit CollectionHasReportId(uint8_t report_id) : report_id_(report_id) {}
bool operator()(const HidCollectionInfo& info) const {
if (info.report_ids.size() == 0 ||
bool operator()(const device::mojom::HidCollectionInfoPtr& info) const {
if (info->report_ids.size() == 0 ||
report_id_ == HidConnection::kNullReportId)
return false;
if (report_id_ == HidConnection::kAnyReportId)
return true;
return base::ContainsKey(info.report_ids, report_id_);
return base::ContainsValue(info->report_ids, report_id_);
}
private:
......@@ -34,27 +36,26 @@ struct CollectionHasReportId {
// Functor returning true if collection has a protected usage.
struct CollectionIsProtected {
bool operator()(const HidCollectionInfo& info) const {
return info.usage.IsProtected();
bool operator()(const device::mojom::HidCollectionInfoPtr& info) const {
return IsProtected(*info->usage);
}
};
bool FindCollectionByReportId(const std::vector<HidCollectionInfo>& collections,
uint8_t report_id,
HidCollectionInfo* collection_info) {
std::vector<HidCollectionInfo>::const_iterator collection_iter = std::find_if(
collections.begin(), collections.end(), CollectionHasReportId(report_id));
const device::mojom::HidCollectionInfo* FindCollectionByReportId(
const std::vector<device::mojom::HidCollectionInfoPtr>& collections,
uint8_t report_id) {
auto collection_iter = std::find_if(collections.begin(), collections.end(),
CollectionHasReportId(report_id));
if (collection_iter != collections.end()) {
if (collection_info) {
*collection_info = *collection_iter;
}
return true;
DCHECK(collection_iter->get());
return collection_iter->get();
}
return false;
return nullptr;
}
bool HasProtectedCollection(const std::vector<HidCollectionInfo>& collections) {
bool HasProtectedCollection(
const std::vector<device::mojom::HidCollectionInfoPtr>& collections) {
return std::find_if(collections.begin(), collections.end(),
CollectionIsProtected()) != collections.end();
}
......@@ -169,10 +170,10 @@ void HidConnection::SendFeatureReport(scoped_refptr<net::IOBuffer> buffer,
}
bool HidConnection::IsReportIdProtected(uint8_t report_id) {
HidCollectionInfo collection_info;
if (FindCollectionByReportId(device_info_->collections(), report_id,
&collection_info)) {
return collection_info.usage.IsProtected();
auto* collection_info =
FindCollectionByReportId(device_info_->collections(), report_id);
if (collection_info) {
return IsProtected(*collection_info->usage);
}
return has_protected_collection();
......
......@@ -52,11 +52,11 @@ bool HidDeviceFilter::Matches(
if (usage_page_set_) {
bool found_matching_collection = false;
for (const HidCollectionInfo& collection : device_info.collections) {
if (collection.usage.usage_page != usage_page_) {
for (const auto& collection : device_info.collections) {
if (collection->usage->usage_page != usage_page_) {
continue;
}
if (usage_set_ && collection.usage.usage != usage_) {
if (usage_set_ && collection->usage->usage != usage_) {
continue;
}
found_matching_collection = true;
......
......@@ -69,33 +69,33 @@ TEST_F(HidFilterTest, MatchProductIdNegative) {
TEST_F(HidFilterTest, MatchUsagePage) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filter.SetUsagePage(device::mojom::kPageGenericDesktop);
ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchUsagePageNegative) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageLed);
filter.SetUsagePage(device::mojom::kPageLed);
ASSERT_FALSE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchVendorAndUsagePage) {
HidDeviceFilter filter;
filter.SetVendorId(0x046d);
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filter.SetUsagePage(device::mojom::kPageGenericDesktop);
ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchUsageAndPage) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filter.SetUsage(HidUsageAndPage::kGenericDesktopKeyboard);
filter.SetUsagePage(device::mojom::kPageGenericDesktop);
filter.SetUsage(device::mojom::kGenericDesktopKeyboard);
ASSERT_TRUE(filter.Matches(*device_info_->device()));
}
TEST_F(HidFilterTest, MatchUsageAndPageNegative) {
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filter.SetUsagePage(device::mojom::kPageGenericDesktop);
filter.SetUsage(0x02);
ASSERT_FALSE(filter.Matches(*device_info_->device()));
}
......@@ -108,7 +108,7 @@ TEST_F(HidFilterTest, MatchEmptyFilterListNegative) {
TEST_F(HidFilterTest, MatchFilterList) {
std::vector<HidDeviceFilter> filters;
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageGenericDesktop);
filter.SetUsagePage(device::mojom::kPageGenericDesktop);
filters.push_back(filter);
ASSERT_TRUE(HidDeviceFilter::MatchesAny(*device_info_->device(), filters));
}
......@@ -116,7 +116,7 @@ TEST_F(HidFilterTest, MatchFilterList) {
TEST_F(HidFilterTest, MatchFilterListNegative) {
std::vector<HidDeviceFilter> filters;
HidDeviceFilter filter;
filter.SetUsagePage(HidUsageAndPage::kPageLed);
filter.SetUsagePage(device::mojom::kPageLed);
filters.push_back(filter);
ASSERT_FALSE(HidDeviceFilter::MatchesAny(*device_info_->device(), filters));
}
......
......@@ -19,7 +19,7 @@ HidDeviceInfo::HidDeviceInfo(const HidPlatformDeviceId& platform_device_id,
const std::vector<uint8_t> report_descriptor,
std::string device_node)
: platform_device_id_(platform_device_id) {
std::vector<HidCollectionInfo> collections;
std::vector<device::mojom::HidCollectionInfoPtr> collections;
bool has_report_id;
size_t max_input_report_size;
size_t max_output_report_size;
......@@ -32,7 +32,7 @@ HidDeviceInfo::HidDeviceInfo(const HidPlatformDeviceId& platform_device_id,
device_ = device::mojom::HidDeviceInfo::New(
base::GenerateGUID(), vendor_id, product_id, product_name, serial_number,
bus_type, report_descriptor, collections, has_report_id,
bus_type, report_descriptor, std::move(collections), has_report_id,
max_input_report_size, max_output_report_size, max_feature_report_size,
device_node);
}
......@@ -43,19 +43,19 @@ HidDeviceInfo::HidDeviceInfo(const HidPlatformDeviceId& platform_device_id,
const std::string& product_name,
const std::string& serial_number,
device::mojom::HidBusType bus_type,
const HidCollectionInfo& collection,
device::mojom::HidCollectionInfoPtr collection,
size_t max_input_report_size,
size_t max_output_report_size,
size_t max_feature_report_size)
: platform_device_id_(platform_device_id) {
std::vector<HidCollectionInfo> collections;
collections.push_back(collection);
bool has_report_id = !collection.report_ids.empty();
std::vector<device::mojom::HidCollectionInfoPtr> collections;
bool has_report_id = !collection->report_ids.empty();
collections.push_back(std::move(collection));
std::vector<uint8_t> report_descriptor;
device_ = device::mojom::HidDeviceInfo::New(
base::GenerateGUID(), vendor_id, product_id, product_name, serial_number,
bus_type, report_descriptor, collections, has_report_id,
bus_type, report_descriptor, std::move(collections), has_report_id,
max_input_report_size, max_output_report_size, max_feature_report_size,
"");
}
......
......@@ -14,7 +14,6 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "build/build_config.h"
#include "device/hid/hid_collection_info.h"
#include "device/hid/public/interfaces/hid.mojom.h"
namespace device {
......@@ -42,7 +41,7 @@ class HidDeviceInfo : public base::RefCountedThreadSafe<HidDeviceInfo> {
const std::string& product_name,
const std::string& serial_number,
device::mojom::HidBusType bus_type,
const HidCollectionInfo& collection,
device::mojom::HidCollectionInfoPtr collection,
size_t max_input_report_size,
size_t max_output_report_size,
size_t max_feature_report_size);
......@@ -61,7 +60,7 @@ class HidDeviceInfo : public base::RefCountedThreadSafe<HidDeviceInfo> {
device::mojom::HidBusType bus_type() const { return device_->bus_type; }
// Top-Level Collections information.
const std::vector<HidCollectionInfo>& collections() const {
const std::vector<device::mojom::HidCollectionInfoPtr>& collections() const {
return device_->collections;
}
bool has_report_id() const { return device_->has_report_id; };
......
......@@ -29,7 +29,7 @@ HidReportDescriptor::HidReportDescriptor(const std::vector<uint8_t>& bytes) {
HidReportDescriptor::~HidReportDescriptor() {}
void HidReportDescriptor::GetDetails(
std::vector<HidCollectionInfo>* top_level_collections,
std::vector<device::mojom::HidCollectionInfoPtr>* top_level_collections,
bool* has_report_id,
size_t* max_input_report_size,
size_t* max_output_report_size,
......@@ -46,7 +46,7 @@ void HidReportDescriptor::GetDetails(
*max_feature_report_size = 0;
// Global tags data:
HidUsageAndPage::Page current_usage_page = HidUsageAndPage::kPageUndefined;
auto current_usage_page = device::mojom::kPageUndefined;
size_t current_report_count = 0;
size_t cached_report_count = 0;
size_t current_report_size = 0;
......@@ -65,10 +65,11 @@ void HidReportDescriptor::GetDetails(
if (!current_item->parent() &&
(current_usage <= std::numeric_limits<uint16_t>::max())) {
// This is a top-level collection.
HidCollectionInfo collection;
collection.usage = HidUsageAndPage(
static_cast<uint16_t>(current_usage), current_usage_page);
top_level_collections->push_back(collection);
auto collection = device::mojom::HidCollectionInfo::New();
collection->usage = device::mojom::HidUsageAndPage::New(
static_cast<uint16_t>(current_usage),
static_cast<uint16_t>(current_usage_page));
top_level_collections->push_back(std::move(collection));
}
break;
case HidReportDescriptorItem::kTagInput:
......@@ -85,13 +86,12 @@ void HidReportDescriptor::GetDetails(
// Global tags:
case HidReportDescriptorItem::kTagUsagePage:
current_usage_page =
static_cast<HidUsageAndPage::Page>(current_item->GetShortData());
current_usage_page = current_item->GetShortData();
break;
case HidReportDescriptorItem::kTagReportId:
if (top_level_collections->size() > 0) {
// Store report ID.
top_level_collections->back().report_ids.insert(
top_level_collections->back()->report_ids.push_back(
current_item->GetShortData());
*has_report_id = true;
......
......@@ -11,8 +11,8 @@
#include <memory>
#include <vector>
#include "device/hid/hid_collection_info.h"
#include "device/hid/hid_report_descriptor_item.h"
#include "device/hid/public/interfaces/hid.mojom.h"
namespace device {
......@@ -30,11 +30,12 @@ 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,
size_t* max_input_report_size,
size_t* max_output_report_size,
size_t* max_feature_report_size);
void GetDetails(
std::vector<device::mojom::HidCollectionInfoPtr>* top_level_collections,
bool* has_report_id,
size_t* max_input_report_size,
size_t* max_output_report_size,
size_t* max_feature_report_size);
private:
std::vector<std::unique_ptr<HidReportDescriptorItem>> items_;
......
......@@ -6,10 +6,11 @@
#include <stdint.h>
#include "device/hid/hid_report_descriptor.h"
#include "device/hid/public/interfaces/hid.mojom.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
device::HidReportDescriptor desc(std::vector<uint8_t>(data, data + size));
std::vector<device::HidCollectionInfo> top_level_collections;
std::vector<device::mojom::HidCollectionInfoPtr> top_level_collections;
bool has_report_id;
size_t max_input_report_size;
size_t max_output_report_size;
......
......@@ -7,7 +7,6 @@
#include <stdlib.h>
#include "base/logging.h"
#include "device/hid/hid_usage_and_page.h"
namespace device {
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "device/hid/hid_report_descriptor.h"
#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/hid/test_report_descriptors.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -20,6 +21,10 @@ namespace device {
class HidReportDescriptorTest : public testing::Test {
protected:
using HidUsageAndPage = device::mojom::HidUsageAndPage;
using HidCollectionInfo = device::mojom::HidCollectionInfo;
using HidCollectionInfoPtr = device::mojom::HidCollectionInfoPtr;
void SetUp() override { descriptor_ = NULL; }
void TearDown() override {
......@@ -30,7 +35,7 @@ class HidReportDescriptorTest : public testing::Test {
public:
void ValidateDetails(
const std::vector<HidCollectionInfo>& expected_collections,
const std::vector<HidCollectionInfoPtr>& expected_collections,
const bool expected_has_report_id,
const size_t expected_max_input_report_size,
const size_t expected_max_output_report_size,
......@@ -40,7 +45,7 @@ class HidReportDescriptorTest : public testing::Test {
descriptor_ =
new HidReportDescriptor(std::vector<uint8_t>(bytes, bytes + size));
std::vector<HidCollectionInfo> actual_collections;
std::vector<HidCollectionInfoPtr> actual_collections;
bool actual_has_report_id;
size_t actual_max_input_report_size;
size_t actual_max_output_report_size;
......@@ -53,21 +58,21 @@ class HidReportDescriptorTest : public testing::Test {
ASSERT_EQ(expected_collections.size(), actual_collections.size());
std::vector<HidCollectionInfo>::const_iterator actual_collections_iter =
actual_collections.begin();
std::vector<HidCollectionInfo>::const_iterator expected_collections_iter =
expected_collections.begin();
auto actual_collections_iter = actual_collections.begin();
auto expected_collections_iter = expected_collections.begin();
while (expected_collections_iter != expected_collections.end() &&
actual_collections_iter != actual_collections.end()) {
HidCollectionInfo expected_collection = *expected_collections_iter;
HidCollectionInfo actual_collection = *actual_collections_iter;
const HidCollectionInfoPtr& expected_collection =
*expected_collections_iter;
const HidCollectionInfoPtr& actual_collection = *actual_collections_iter;
ASSERT_EQ(expected_collection.usage.usage_page,
actual_collection.usage.usage_page);
ASSERT_EQ(expected_collection.usage.usage, actual_collection.usage.usage);
ASSERT_THAT(actual_collection.report_ids,
ContainerEq(expected_collection.report_ids));
ASSERT_EQ(expected_collection->usage->usage_page,
actual_collection->usage->usage_page);
ASSERT_EQ(expected_collection->usage->usage,
actual_collection->usage->usage);
ASSERT_THAT(actual_collection->report_ids,
ContainerEq(expected_collection->report_ids));
expected_collections_iter++;
actual_collections_iter++;
......@@ -84,66 +89,64 @@ class HidReportDescriptorTest : public testing::Test {
};
TEST_F(HidReportDescriptorTest, ValidateDetails_Digitizer) {
HidCollectionInfo digitizer;
digitizer.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageDigitizer);
digitizer.report_ids.insert(1);
digitizer.report_ids.insert(2);
digitizer.report_ids.insert(3);
HidCollectionInfo expected[] = {digitizer};
ValidateDetails(
std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
true, 6, 0, 0, kDigitizer, kDigitizerSize);
auto digitizer = HidCollectionInfo::New();
digitizer->usage = HidUsageAndPage::New(0x01, device::mojom::kPageDigitizer);
digitizer->report_ids.push_back(1);
digitizer->report_ids.push_back(2);
digitizer->report_ids.push_back(3);
std::vector<HidCollectionInfoPtr> expected;
expected.push_back(std::move(digitizer));
ValidateDetails(expected, true, 6, 0, 0, kDigitizer, kDigitizerSize);
}
TEST_F(HidReportDescriptorTest, ValidateDetails_Keyboard) {
HidCollectionInfo keyboard;
keyboard.usage = HidUsageAndPage(0x06, HidUsageAndPage::kPageGenericDesktop);
HidCollectionInfo expected[] = {keyboard};
ValidateDetails(
std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
false, 8, 1, 0, kKeyboard, kKeyboardSize);
auto keyboard = HidCollectionInfo::New();
keyboard->usage =
HidUsageAndPage::New(0x06, device::mojom::kPageGenericDesktop);
std::vector<HidCollectionInfoPtr> expected;
expected.push_back(std::move(keyboard));
ValidateDetails(expected, false, 8, 1, 0, kKeyboard, kKeyboardSize);
}
TEST_F(HidReportDescriptorTest, ValidateDetails_Monitor) {
HidCollectionInfo monitor;
monitor.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageMonitor0);
monitor.report_ids.insert(1);
monitor.report_ids.insert(2);
monitor.report_ids.insert(3);
monitor.report_ids.insert(4);
monitor.report_ids.insert(5);
HidCollectionInfo expected[] = {monitor};
ValidateDetails(
std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
true, 0, 0, 243, kMonitor, kMonitorSize);
auto monitor = HidCollectionInfo::New();
monitor->usage = HidUsageAndPage::New(0x01, device::mojom::kPageMonitor0);
monitor->report_ids.push_back(1);
monitor->report_ids.push_back(2);
monitor->report_ids.push_back(3);
monitor->report_ids.push_back(4);
monitor->report_ids.push_back(5);
std::vector<HidCollectionInfoPtr> expected;
expected.push_back(std::move(monitor));
ValidateDetails(expected, true, 0, 0, 243, kMonitor, kMonitorSize);
}
TEST_F(HidReportDescriptorTest, ValidateDetails_Mouse) {
HidCollectionInfo mouse;
mouse.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageGenericDesktop);
HidCollectionInfo expected[] = {mouse};
ValidateDetails(
std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
false, 3, 0, 0, kMouse, kMouseSize);
auto mouse = HidCollectionInfo::New();
mouse->usage = HidUsageAndPage::New(0x02, device::mojom::kPageGenericDesktop);
std::vector<HidCollectionInfoPtr> expected;
expected.push_back(std::move(mouse));
ValidateDetails(expected, false, 3, 0, 0, kMouse, kMouseSize);
}
TEST_F(HidReportDescriptorTest, ValidateDetails_LogitechUnifyingReceiver) {
HidCollectionInfo hidpp_short;
hidpp_short.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageVendor);
hidpp_short.report_ids.insert(0x10);
HidCollectionInfo hidpp_long;
hidpp_long.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageVendor);
hidpp_long.report_ids.insert(0x11);
HidCollectionInfo hidpp_dj;
hidpp_dj.usage = HidUsageAndPage(0x04, HidUsageAndPage::kPageVendor);
hidpp_dj.report_ids.insert(0x20);
hidpp_dj.report_ids.insert(0x21);
HidCollectionInfo expected[] = {hidpp_short, hidpp_long, hidpp_dj};
ValidateDetails(
std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
true, 31, 31, 0, kLogitechUnifyingReceiver,
kLogitechUnifyingReceiverSize);
auto hidpp_short = HidCollectionInfo::New();
hidpp_short->usage = HidUsageAndPage::New(0x01, device::mojom::kPageVendor);
hidpp_short->report_ids.push_back(0x10);
auto hidpp_long = HidCollectionInfo::New();
hidpp_long->usage = HidUsageAndPage::New(0x02, device::mojom::kPageVendor);
hidpp_long->report_ids.push_back(0x11);
auto hidpp_dj = HidCollectionInfo::New();
hidpp_dj->usage = HidUsageAndPage::New(0x04, device::mojom::kPageVendor);
hidpp_dj->report_ids.push_back(0x20);
hidpp_dj->report_ids.push_back(0x21);
std::vector<HidCollectionInfoPtr> expected;
expected.push_back(std::move(hidpp_short));
expected.push_back(std::move(hidpp_long));
expected.push_back(std::move(hidpp_dj));
ValidateDetails(expected, true, 31, 31, 0, kLogitechUnifyingReceiver,
kLogitechUnifyingReceiverSize);
}
} // namespace device
......@@ -130,7 +130,7 @@ void HidServiceWin::CollectInfoFromButtonCaps(
PHIDP_PREPARSED_DATA preparsed_data,
HIDP_REPORT_TYPE report_type,
USHORT button_caps_length,
HidCollectionInfo* collection_info) {
device::mojom::HidCollectionInfo* collection_info) {
if (button_caps_length > 0) {
std::unique_ptr<HIDP_BUTTON_CAPS[]> button_caps(
new HIDP_BUTTON_CAPS[button_caps_length]);
......@@ -141,7 +141,7 @@ void HidServiceWin::CollectInfoFromButtonCaps(
for (size_t i = 0; i < button_caps_length; i++) {
int report_id = button_caps[i].ReportID;
if (report_id != 0) {
collection_info->report_ids.insert(report_id);
collection_info->report_ids.push_back(report_id);
}
}
}
......@@ -153,7 +153,7 @@ void HidServiceWin::CollectInfoFromValueCaps(
PHIDP_PREPARSED_DATA preparsed_data,
HIDP_REPORT_TYPE report_type,
USHORT value_caps_length,
HidCollectionInfo* collection_info) {
device::mojom::HidCollectionInfo* collection_info) {
if (value_caps_length > 0) {
std::unique_ptr<HIDP_VALUE_CAPS[]> value_caps(
new HIDP_VALUE_CAPS[value_caps_length]);
......@@ -163,7 +163,7 @@ void HidServiceWin::CollectInfoFromValueCaps(
for (size_t i = 0; i < value_caps_length; i++) {
int report_id = value_caps[i].ReportID;
if (report_id != 0) {
collection_info->report_ids.insert(report_id);
collection_info->report_ids.push_back(report_id);
}
}
}
......@@ -217,27 +217,27 @@ void HidServiceWin::AddDeviceBlocking(
max_feature_report_size = capabilities.FeatureReportByteLength - 1;
}
HidCollectionInfo collection_info;
collection_info.usage = HidUsageAndPage(
capabilities.Usage,
static_cast<HidUsageAndPage::Page>(capabilities.UsagePage));
auto collection_info = device::mojom::HidCollectionInfo::New();
collection_info->usage = device::mojom::HidUsageAndPage::New(
capabilities.Usage, capabilities.UsagePage);
CollectInfoFromButtonCaps(preparsed_data, HidP_Input,
capabilities.NumberInputButtonCaps,
&collection_info);
collection_info.get());
CollectInfoFromButtonCaps(preparsed_data, HidP_Output,
capabilities.NumberOutputButtonCaps,
&collection_info);
collection_info.get());
CollectInfoFromButtonCaps(preparsed_data, HidP_Feature,
capabilities.NumberFeatureButtonCaps,
&collection_info);
collection_info.get());
CollectInfoFromValueCaps(preparsed_data, HidP_Input,
capabilities.NumberInputValueCaps, &collection_info);
capabilities.NumberInputValueCaps,
collection_info.get());
CollectInfoFromValueCaps(preparsed_data, HidP_Output,
capabilities.NumberOutputValueCaps,
&collection_info);
collection_info.get());
CollectInfoFromValueCaps(preparsed_data, HidP_Feature,
capabilities.NumberFeatureValueCaps,
&collection_info);
collection_info.get());
// 1023 characters plus NULL terminator is more than enough for a USB string
// descriptor which is limited to 126 characters.
......@@ -261,7 +261,7 @@ void HidServiceWin::AddDeviceBlocking(
device_path, attrib.VendorID, attrib.ProductID, product_name,
serial_number,
// TODO(reillyg): Detect Bluetooth. crbug.com/443335
device::mojom::HidBusType::kHIDBusTypeUSB, collection_info,
device::mojom::HidBusType::kHIDBusTypeUSB, std::move(collection_info),
max_input_report_size, max_output_report_size, max_feature_report_size));
HidD_FreePreparsedData(preparsed_data);
......
......@@ -42,14 +42,16 @@ class HidServiceWin : public HidService, public DeviceMonitorWin::Observer {
static void EnumerateBlocking(
base::WeakPtr<HidServiceWin> service,
scoped_refptr<base::SequencedTaskRunner> task_runner);
static void CollectInfoFromButtonCaps(PHIDP_PREPARSED_DATA preparsed_data,
HIDP_REPORT_TYPE report_type,
USHORT button_caps_length,
HidCollectionInfo* collection_info);
static void CollectInfoFromValueCaps(PHIDP_PREPARSED_DATA preparsed_data,
HIDP_REPORT_TYPE report_type,
USHORT value_caps_length,
HidCollectionInfo* collection_info);
static void CollectInfoFromButtonCaps(
PHIDP_PREPARSED_DATA preparsed_data,
HIDP_REPORT_TYPE report_type,
USHORT button_caps_length,
device::mojom::HidCollectionInfo* collection_info);
static void CollectInfoFromValueCaps(
PHIDP_PREPARSED_DATA preparsed_data,
HIDP_REPORT_TYPE report_type,
USHORT value_caps_length,
device::mojom::HidCollectionInfo* collection_info);
static void AddDeviceBlocking(
base::WeakPtr<HidServiceWin> service,
scoped_refptr<base::SequencedTaskRunner> task_runner,
......
// 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 "device/hid/hid_usage_and_page.h"
namespace device {
bool HidUsageAndPage::IsProtected() const {
if (usage_page == HidUsageAndPage::kPageKeyboard)
return true;
if (usage_page != HidUsageAndPage::kPageGenericDesktop)
return false;
if (usage == HidUsageAndPage::kGenericDesktopPointer ||
usage == HidUsageAndPage::kGenericDesktopMouse ||
usage == HidUsageAndPage::kGenericDesktopKeyboard ||
usage == HidUsageAndPage::kGenericDesktopKeypad) {
return true;
}
if (usage >= HidUsageAndPage::kGenericDesktopSystemControl &&
usage <= HidUsageAndPage::kGenericDesktopSystemWarmRestart) {
return true;
}
if (usage >= HidUsageAndPage::kGenericDesktopSystemDock &&
usage <= HidUsageAndPage::kGenericDesktopSystemDisplaySwap) {
return true;
}
return false;
}
} // namespace device
// 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.
#ifndef DEVICE_HID_HID_USAGE_AND_PAGE_H_
#define DEVICE_HID_HID_USAGE_AND_PAGE_H_
#include <stdint.h>
namespace device {
struct HidUsageAndPage {
enum Page {
kPageUndefined = 0x00,
kPageGenericDesktop = 0x01,
kPageSimulation = 0x02,
kPageVirtualReality = 0x03,
kPageSport = 0x04,
kPageGame = 0x05,
kPageKeyboard = 0x07,
kPageLed = 0x08,
kPageButton = 0x09,
kPageOrdinal = 0x0A,
kPageTelephony = 0x0B,
kPageConsumer = 0x0C,
kPageDigitizer = 0x0D,
kPagePidPage = 0x0F,
kPageUnicode = 0x10,
kPageAlphanumericDisplay = 0x14,
kPageMedicalInstruments = 0x40,
kPageMonitor0 = 0x80,
kPageMonitor1 = 0x81,
kPageMonitor2 = 0x82,
kPageMonitor3 = 0x83,
kPagePower0 = 0x84,
kPagePower1 = 0x85,
kPagePower2 = 0x86,
kPagePower3 = 0x87,
kPageBarCodeScanner = 0x8C,
kPageScale = 0x8D,
kPageMagneticStripeReader = 0x8E,
kPageReservedPointOfSale = 0x8F,
kPageCameraControl = 0x90,
kPageArcade = 0x91,
kPageVendor = 0xFF00,
kPageMediaCenter = 0xFFBC
};
// These usage enumerations are derived from the HID Usage Tables v1.11 spec.
enum GenericDesktopUsage {
kGenericDesktopUndefined = 0,
kGenericDesktopPointer = 1,
kGenericDesktopMouse = 2,
kGenericDesktopJoystick = 4,
kGenericDesktopGamePad = 5,
kGenericDesktopKeyboard = 6,
kGenericDesktopKeypad = 7,
kGenericDesktopMultiAxisController = 8,
kGenericDesktopX = 0x30,
kGenericDesktopY = 0x31,
kGenericDesktopZ = 0x32,
kGenericDesktopRx = 0x33,
kGenericDesktopRy = 0x34,
kGenericDesktopRz = 0x35,
kGenericDesktopSlider = 0x36,
kGenericDesktopDial = 0x37,
kGenericDesktopWheel = 0x38,
kGenericDesktopHatSwitch = 0x39,
kGenericDesktopCountedBuffer = 0x3a,
kGenericDesktopByteCount = 0x3b,
kGenericDesktopMotionWakeup = 0x3c,
kGenericDesktopStart = 0x3d,
kGenericDesktopSelect = 0x3e,
kGenericDesktopVx = 0x40,
kGenericDesktopVy = 0x41,
kGenericDesktopVz = 0x42,
kGenericDesktopVbrx = 0x43,
kGenericDesktopVbry = 0x44,
kGenericDesktopVbrz = 0x45,
kGenericDesktopVno = 0x46,
kGenericDesktopSystemControl = 0x80,
kGenericDesktopSystemPowerDown = 0x81,
kGenericDesktopSystemSleep = 0x82,
kGenericDesktopSystemWakeUp = 0x83,
kGenericDesktopSystemContextMenu = 0x84,
kGenericDesktopSystemMainMenu = 0x85,
kGenericDesktopSystemAppMenu = 0x86,
kGenericDesktopSystemMenuHelp = 0x87,
kGenericDesktopSystemMenuExit = 0x88,
kGenericDesktopSystemMenuSelect = 0x89,
kGenericDesktopSystemMenuRight = 0x8a,
kGenericDesktopSystemMenuLeft = 0x8b,
kGenericDesktopSystemMenuUp = 0x8c,
kGenericDesktopSystemMenuDown = 0x8d,
kGenericDesktopSystemColdRestart = 0x8e,
kGenericDesktopSystemWarmRestart = 0x8f,
kGenericDesktopDPadUp = 0x90,
kGenericDesktopDPadDown = 0x91,
kGenericDesktopDPadLeft = 0x92,
kGenericDesktopDPadRight = 0x93,
kGenericDesktopSystemDock = 0xa0,
kGenericDesktopSystemUndock = 0xa1,
kGenericDesktopSystemSetup = 0xa2,
kGenericDesktopSystemBreak = 0xa3,
kGenericDesktopSystemDebuggerBreak = 0xa4,
kGenericDesktopApplicationBreak = 0xa5,
kGenericDesktopApplicationDebuggerBreak = 0xa6,
kGenericDesktopSystemSpeakerMute = 0xa7,
kGenericDesktopSystemHibernate = 0xa8,
kGenericDesktopSystemDisplayInvert = 0xb0,
kGenericDesktopSystemDisplayInternal = 0xb1,
kGenericDesktopSystemDisplayExternal = 0xb2,
kGenericDesktopSystemDisplayBoth = 0xb3,
kGenericDesktopSystemDisplayDual = 0xb4,
kGenericDesktopSystemDisplayToggle = 0xb5,
kGenericDesktopSystemDisplaySwap = 0xb6,
};
HidUsageAndPage() {}
HidUsageAndPage(uint16_t usage, uint16_t usage_page)
: usage(usage), usage_page(usage_page) {}
~HidUsageAndPage() {}
uint16_t usage;
uint16_t usage_page;
// Indicates whether this usage is protected by Chrome.
bool IsProtected() const;
};
} // namespace device
#endif // DEVICE_HID_HID_USAGE_AND_PAGE_H_
......@@ -2,4 +2,15 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
typemaps = [ "//device/hid/public/interfaces/hid.typemap" ]
import("//build/config/features.gni")
source_set("cpp") {
sources = [
"hid_usage_and_page.cc",
"hid_usage_and_page.h",
]
deps = [
"//device/hid/public/interfaces",
]
}
// 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 "device/hid/public/cpp/hid_usage_and_page.h"
namespace device {
bool IsProtected(const device::mojom::HidUsageAndPage& hid_usage_and_page) {
const uint16_t usage = hid_usage_and_page.usage;
const uint16_t usage_page = hid_usage_and_page.usage_page;
if (usage_page == device::mojom::kPageKeyboard)
return true;
if (usage_page != device::mojom::kPageGenericDesktop)
return false;
if (usage == device::mojom::kGenericDesktopPointer ||
usage == device::mojom::kGenericDesktopMouse ||
usage == device::mojom::kGenericDesktopKeyboard ||
usage == device::mojom::kGenericDesktopKeypad) {
return true;
}
if (usage >= device::mojom::kGenericDesktopSystemControl &&
usage <= device::mojom::kGenericDesktopSystemWarmRestart) {
return true;
}
if (usage >= device::mojom::kGenericDesktopSystemDock &&
usage <= device::mojom::kGenericDesktopSystemDisplaySwap) {
return true;
}
return false;
}
} // namespace device
......@@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/hid/hid_collection_info.h"
#ifndef DEVICE_HID_PUBLIC_CPP_HID_USAGE_AND_PAGE_H_
#define DEVICE_HID_PUBLIC_CPP_HID_USAGE_AND_PAGE_H_
namespace device {
HidCollectionInfo::HidCollectionInfo()
: usage(HidUsageAndPage::kGenericDesktopUndefined,
HidUsageAndPage::kPageUndefined) {
}
#include "device/hid/public/interfaces/hid.mojom.h"
HidCollectionInfo::HidCollectionInfo(const HidCollectionInfo& other) = default;
namespace device {
HidCollectionInfo::~HidCollectionInfo() {
}
// Indicates whether this usage is protected by Chrome.
bool IsProtected(const device::mojom::HidUsageAndPage& hid_usage_and_page);
} // namespace device
#endif // DEVICE_HID_PUBLIC_CPP_HID_USAGE_AND_PAGE_H_
......@@ -9,13 +9,123 @@ enum HidBusType {
kHIDBusTypeBluetooth = 1,
};
// Usage pages.
const uint16 kPageUndefined = 0x00;
const uint16 kPageGenericDesktop = 0x01;
const uint16 kPageSimulation = 0x02;
const uint16 kPageVirtualReality = 0x03;
const uint16 kPageSport = 0x04;
const uint16 kPageGame = 0x05;
const uint16 kPageKeyboard = 0x07;
const uint16 kPageLed = 0x08;
const uint16 kPageButton = 0x09;
const uint16 kPageOrdinal = 0x0A;
const uint16 kPageTelephony = 0x0B;
const uint16 kPageConsumer = 0x0C;
const uint16 kPageDigitizer = 0x0D;
const uint16 kPagePidPage = 0x0F;
const uint16 kPageUnicode = 0x10;
const uint16 kPageAlphanumericDisplay = 0x14;
const uint16 kPageMedicalInstruments = 0x40;
const uint16 kPageMonitor0 = 0x80;
const uint16 kPageMonitor1 = 0x81;
const uint16 kPageMonitor2 = 0x82;
const uint16 kPageMonitor3 = 0x83;
const uint16 kPagePower0 = 0x84;
const uint16 kPagePower1 = 0x85;
const uint16 kPagePower2 = 0x86;
const uint16 kPagePower3 = 0x87;
const uint16 kPageBarCodeScanner = 0x8C;
const uint16 kPageScale = 0x8D;
const uint16 kPageMagneticStripeReader = 0x8E;
const uint16 kPageReservedPointOfSale = 0x8F;
const uint16 kPageCameraControl = 0x90;
const uint16 kPageArcade = 0x91;
const uint16 kPageVendor = 0xFF00;
const uint16 kPageMediaCenter = 0xFFBC;
// These usage enumerations are derived from the HID Usage Tables v1.11 spec.
const uint16 kGenericDesktopUndefined = 0x00;
const uint16 kGenericDesktopPointer = 0x01;
const uint16 kGenericDesktopMouse = 0x02;
const uint16 kGenericDesktopJoystick = 0x04;
const uint16 kGenericDesktopGamePad = 0x05;
const uint16 kGenericDesktopKeyboard = 0x06;
const uint16 kGenericDesktopKeypad = 0x07;
const uint16 kGenericDesktopMultiAxisController = 0x08;
const uint16 kGenericDesktopX = 0x30;
const uint16 kGenericDesktopY = 0x31;
const uint16 kGenericDesktopZ = 0x32;
const uint16 kGenericDesktopRx = 0x33;
const uint16 kGenericDesktopRy = 0x34;
const uint16 kGenericDesktopRz = 0x35;
const uint16 kGenericDesktopSlider = 0x36;
const uint16 kGenericDesktopDial = 0x37;
const uint16 kGenericDesktopWheel = 0x38;
const uint16 kGenericDesktopHatSwitch = 0x39;
const uint16 kGenericDesktopCountedBuffer = 0x3a;
const uint16 kGenericDesktopByteCount = 0x3b;
const uint16 kGenericDesktopMotionWakeup = 0x3c;
const uint16 kGenericDesktopStart = 0x3d;
const uint16 kGenericDesktopSelect = 0x3e;
const uint16 kGenericDesktopVx = 0x40;
const uint16 kGenericDesktopVy = 0x41;
const uint16 kGenericDesktopVz = 0x42;
const uint16 kGenericDesktopVbrx = 0x43;
const uint16 kGenericDesktopVbry = 0x44;
const uint16 kGenericDesktopVbrz = 0x45;
const uint16 kGenericDesktopVno = 0x46;
const uint16 kGenericDesktopSystemControl = 0x80;
const uint16 kGenericDesktopSystemPowerDown = 0x81;
const uint16 kGenericDesktopSystemSleep = 0x82;
const uint16 kGenericDesktopSystemWakeUp = 0x83;
const uint16 kGenericDesktopSystemContextMenu = 0x84;
const uint16 kGenericDesktopSystemMainMenu = 0x85;
const uint16 kGenericDesktopSystemAppMenu = 0x86;
const uint16 kGenericDesktopSystemMenuHelp = 0x87;
const uint16 kGenericDesktopSystemMenuExit = 0x88;
const uint16 kGenericDesktopSystemMenuSelect = 0x89;
const uint16 kGenericDesktopSystemMenuRight = 0x8a;
const uint16 kGenericDesktopSystemMenuLeft = 0x8b;
const uint16 kGenericDesktopSystemMenuUp = 0x8c;
const uint16 kGenericDesktopSystemMenuDown = 0x8d;
const uint16 kGenericDesktopSystemColdRestart = 0x8e;
const uint16 kGenericDesktopSystemWarmRestart = 0x8f;
const uint16 kGenericDesktopDPadUp = 0x90;
const uint16 kGenericDesktopDPadDown = 0x91;
const uint16 kGenericDesktopDPadLeft = 0x92;
const uint16 kGenericDesktopDPadRight = 0x93;
const uint16 kGenericDesktopSystemDock = 0xa0;
const uint16 kGenericDesktopSystemUndock = 0xa1;
const uint16 kGenericDesktopSystemSetup = 0xa2;
const uint16 kGenericDesktopSystemBreak = 0xa3;
const uint16 kGenericDesktopSystemDebuggerBreak = 0xa4;
const uint16 kGenericDesktopApplicationBreak = 0xa5;
const uint16 kGenericDesktopApplicationDebuggerBreak = 0xa6;
const uint16 kGenericDesktopSystemSpeakerMute = 0xa7;
const uint16 kGenericDesktopSystemHibernate = 0xa8;
const uint16 kGenericDesktopSystemDisplayInvert = 0xb0;
const uint16 kGenericDesktopSystemDisplayInternal = 0xb1;
const uint16 kGenericDesktopSystemDisplayExternal = 0xb2;
const uint16 kGenericDesktopSystemDisplayBoth = 0xb3;
const uint16 kGenericDesktopSystemDisplayDual = 0xb4;
const uint16 kGenericDesktopSystemDisplayToggle = 0xb5;
const uint16 kGenericDesktopSystemDisplaySwap = 0xb6;
struct HidUsageAndPage {
uint16 usage;
uint16 usage_page;
};
struct HidCollectionInfo {
// Collection's usage ID.
HidUsageAndPage usage;
// HID report IDs which belong to this collection or to its
// embedded collections.
array<int32> report_ids;
};
......@@ -39,7 +149,7 @@ interface HidManagerClient {
// Notifies the client that a device is added.
DeviceAdded(HidDeviceInfo device_info);
// Notifies the client that a device is being removed, called before
// Notifies the client that a device is being removed; called before
// removing the device from HidService.
DeviceRemoved(HidDeviceInfo device_info);
};
......
# Copyright 2017 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.
mojom = "//device/hid/public/interfaces/hid.mojom"
public_headers = [
"//device/hid/hid_collection_info.h",
"//device/hid/hid_usage_and_page.h",
]
traits_headers = [ "//device/hid/public/interfaces/hid_struct_traits.h" ]
sources = [
"//device/hid/public/interfaces/hid_struct_traits.cc",
]
deps = [
"//mojo/public/cpp/bindings",
]
type_mappings = [
"device.mojom.HidPage=device::HidUsageAndPage::Page",
"device.mojom.HidUsageAndPage=device::HidUsageAndPage",
"device.mojom.HidCollectionInfo=device::HidCollectionInfo",
]
// Copyright 2017 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 "device/hid/public/interfaces/hid_struct_traits.h"
namespace mojo {
// static
bool StructTraits<
device::mojom::HidUsageAndPageDataView,
device::HidUsageAndPage>::Read(device::mojom::HidUsageAndPageDataView data,
device::HidUsageAndPage* out) {
out->usage = data.usage();
out->usage_page = data.usage_page();
return true;
}
// static
bool StructTraits<device::mojom::HidCollectionInfoDataView,
device::HidCollectionInfo>::
Read(device::mojom::HidCollectionInfoDataView data,
device::HidCollectionInfo* out) {
if (!data.ReadUsage(&out->usage))
return false;
std::vector<int> vec;
if (!data.ReadReportIds(&vec))
return false;
out->report_ids.clear();
out->report_ids.insert(vec.begin(), vec.end());
return true;
}
} // namespace mojo
// Copyright 2017 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 DEVICE_HID_PUBLIC_INTERFACES_HID_STRUCT_TRAITS_H_
#define DEVICE_HID_PUBLIC_INTERFACES_HID_STRUCT_TRAITS_H_
#include <stddef.h>
#include "device/hid/hid_collection_info.h"
#include "device/hid/hid_usage_and_page.h"
#include "device/hid/public/interfaces/hid.mojom.h"
#include "mojo/public/cpp/bindings/array_traits_stl.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
namespace mojo {
template <>
struct StructTraits<device::mojom::HidUsageAndPageDataView,
device::HidUsageAndPage> {
static uint16_t usage(const device::HidUsageAndPage& r) { return r.usage; }
static uint16_t usage_page(const device::HidUsageAndPage& r) {
return r.usage_page;
}
static bool Read(device::mojom::HidUsageAndPageDataView data,
device::HidUsageAndPage* out);
};
template <>
struct StructTraits<device::mojom::HidCollectionInfoDataView,
device::HidCollectionInfo> {
static const device::HidUsageAndPage& usage(
const device::HidCollectionInfo& r) {
return r.usage;
}
static const std::set<int>& report_ids(const device::HidCollectionInfo& r) {
return r.report_ids;
}
static bool Read(device::mojom::HidCollectionInfoDataView data,
device::HidCollectionInfo* out);
};
} // namespace mojo
#endif // DEVICE_HID_PUBLIC_INTERFACES_HID_STRUCT_TRAITS_H_
......@@ -193,15 +193,15 @@ TEST_F(U2fHidDeviceTest, TestConnectionFailure) {
// Setup and enumerate mock device
U2fDeviceEnumerate callback(hid_manager_.get());
HidCollectionInfo c_info;
c_info.usage = HidUsageAndPage(1, 0xf1d0);
auto c_info = device::mojom::HidCollectionInfo::New();
c_info->usage = device::mojom::HidUsageAndPage::New(1, 0xf1d0);
auto hid_device = device::mojom::HidDeviceInfo::New();
hid_device->guid = "A";
hid_device->product_name = "Test Fido device";
hid_device->serial_number = "123FIDO";
hid_device->bus_type = device::mojom::HidBusType::kHIDBusTypeUSB;
hid_device->collections.push_back(c_info);
hid_device->collections.push_back(std::move(c_info));
hid_device->max_input_report_size = 64;
hid_device->max_output_report_size = 64;
......@@ -244,15 +244,15 @@ TEST_F(U2fHidDeviceTest, TestDeviceError) {
// Setup and enumerate mock device
U2fDeviceEnumerate callback(hid_manager_.get());
HidCollectionInfo c_info;
c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
auto c_info = device::mojom::HidCollectionInfo::New();
c_info->usage = device::mojom::HidUsageAndPage::New(1, 0xf1d0);
auto hid_device = device::mojom::HidDeviceInfo::New();
hid_device->guid = "A";
hid_device->product_name = "Test Fido device";
hid_device->serial_number = "123FIDO";
hid_device->bus_type = device::mojom::HidBusType::kHIDBusTypeUSB;
hid_device->collections.push_back(c_info);
hid_device->collections.push_back(std::move(c_info));
hid_device->max_input_report_size = 64;
hid_device->max_output_report_size = 64;
......
......@@ -8,7 +8,6 @@
#include <utility>
#include "base/test/scoped_task_environment.h"
#include "device/hid/hid_collection_info.h"
#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/u2f/fake_hid_impl_for_testing.h"
#include "device/u2f/mock_u2f_discovery.h"
......@@ -24,15 +23,15 @@ namespace device {
namespace {
device::mojom::HidDeviceInfoPtr MakeU2fDevice(std::string guid) {
HidCollectionInfo c_info;
c_info.usage = HidUsageAndPage(1, static_cast<HidUsageAndPage::Page>(0xf1d0));
auto c_info = device::mojom::HidCollectionInfo::New();
c_info->usage = device::mojom::HidUsageAndPage::New(1, 0xf1d0);
auto u2f_device = device::mojom::HidDeviceInfo::New();
u2f_device->guid = std::move(guid);
u2f_device->product_name = "Test Fido Device";
u2f_device->serial_number = "123FIDO";
u2f_device->bus_type = device::mojom::HidBusType::kHIDBusTypeUSB;
u2f_device->collections.push_back(c_info);
u2f_device->collections.push_back(std::move(c_info));
u2f_device->max_input_report_size = 64;
u2f_device->max_output_report_size = 64;
return u2f_device;
......
......@@ -16,6 +16,7 @@
#include "content/public/common/service_manager_connection.h"
#include "device/base/device_client.h"
#include "device/hid/hid_device_filter.h"
#include "device/hid/public/cpp/hid_usage_and_page.h"
#include "device/hid/public/interfaces/hid.mojom.h"
#include "device/usb/public/cpp/filter_utils.h"
#include "device/usb/usb_device.h"
......@@ -290,7 +291,7 @@ class HidDevicePermissionsPrompt : public DevicePermissionsPrompt::Prompt,
bool HasUnprotectedCollections(const device::mojom::HidDeviceInfo& device) {
for (const auto& collection : device.collections) {
if (!collection.usage.IsProtected()) {
if (!device::IsProtected(*collection->usage)) {
return true;
}
}
......
......@@ -10,9 +10,7 @@
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "device/hid/hid_collection_info.h"
#include "device/hid/hid_report_descriptor.h"
#include "device/hid/hid_usage_and_page.h"
#include "device/hid/public/interfaces/hid.mojom.h"
#include "extensions/browser/api/device_permissions_prompt.h"
#include "extensions/shell/browser/shell_extensions_api_client.h"
......@@ -25,9 +23,7 @@
#include "services/service_manager/public/cpp/service_context.h"
using base::ThreadTaskRunnerHandle;
using device::HidCollectionInfo;
using device::HidReportDescriptor;
using device::HidUsageAndPage;
const char* const kTestDeviceGuids[] = {"A", "B", "C", "D", "E"};
......@@ -288,7 +284,7 @@ class HidApiTest : public ShellApiTest {
kReportDescriptor + sizeof(kReportDescriptor));
}
std::vector<HidCollectionInfo> collections;
std::vector<device::mojom::HidCollectionInfoPtr> collections;
bool has_report_id;
size_t max_input_report_size;
size_t max_output_report_size;
......@@ -302,7 +298,7 @@ class HidApiTest : public ShellApiTest {
auto device = device::mojom::HidDeviceInfo::New(
device_guid, vendor_id, product_id, "Test Device", serial_number,
device::mojom::HidBusType::kHIDBusTypeUSB, report_descriptor,
collections, has_report_id, max_input_report_size,
std::move(collections), has_report_id, max_input_report_size,
max_output_report_size, max_feature_report_size, "");
fake_hid_manager_->AddDevice(std::move(device));
......
......@@ -19,6 +19,7 @@
#include "content/public/common/service_manager_connection.h"
#include "device/base/device_client.h"
#include "device/hid/hid_device_filter.h"
#include "device/hid/public/cpp/hid_usage_and_page.h"
#include "extensions/browser/api/device_permissions_manager.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/permissions/usb_device_permission.h"
......@@ -45,19 +46,17 @@ void PopulateHidDeviceInfo(hid::HidDeviceInfo* output,
output->max_output_report_size = input.max_output_report_size;
output->max_feature_report_size = input.max_feature_report_size;
for (const device::HidCollectionInfo& collection : input.collections) {
for (const auto& collection : input.collections) {
// Don't expose sensitive data.
if (collection.usage.IsProtected()) {
if (device::IsProtected(*collection->usage)) {
continue;
}
hid::HidCollectionInfo api_collection;
api_collection.usage_page = collection.usage.usage_page;
api_collection.usage = collection.usage.usage;
api_collection.usage_page = collection->usage->usage_page;
api_collection.usage = collection->usage->usage;
api_collection.report_ids.resize(collection.report_ids.size());
std::copy(collection.report_ids.begin(), collection.report_ids.end(),
api_collection.report_ids.begin());
api_collection.report_ids = collection->report_ids;
output->collections.push_back(std::move(api_collection));
}
......
......@@ -19,7 +19,6 @@ _typemap_imports = [
"//content/public/common/typemaps.gni",
"//device/bluetooth/public/interfaces/typemaps.gni",
"//device/gamepad/public/interfaces/typemaps.gni",
"//device/hid/public/interfaces/typemaps.gni",
"//extensions/common/typemaps.gni",
"//gpu/ipc/common/typemaps.gni",
"//media/capture/mojo/typemaps.gni",
......
......@@ -220,11 +220,11 @@ TEST_F(HidManagerTest, GetDevicesAndSetClient) {
// Test the Connect and the device::mojom::HidConnection interface.
TEST_F(HidManagerTest, TestHidConnectionInterface) {
// Add one hid device.
HidCollectionInfo c_info;
c_info.usage = HidUsageAndPage(1, 0xf1d0);
auto c_info = device::mojom::HidCollectionInfo::New();
c_info->usage = device::mojom::HidUsageAndPage::New(1, 0xf1d0);
auto device0 = base::MakeRefCounted<device::HidDeviceInfo>(
kTestDeviceIds[0], 0, 0, "Hid Service Unit Test", "HidDevice-0",
device::mojom::HidBusType::kHIDBusTypeUSB, c_info, 64, 64, 64);
device::mojom::HidBusType::kHIDBusTypeUSB, std::move(c_info), 64, 64, 64);
mock_hid_service_->AddDevice(device0);
mock_hid_service_->FirstEnumerationComplete();
......
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