feat: add support for HIDDevice.forget() (#34210)
* feat: add support for HIDDevice.forget() * chore: remove whitespace * chore: use `SetGetter` to serialize the render_frame_host Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> * fixup chore: use `SetGetter` to serialize the render_frame_host * fixup after rebase * fixup for crash on navigator.serial.getPorts() * fixup for lint Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com>
This commit is contained in:
parent
df9383cb3c
commit
ba573f5583
15 changed files with 359 additions and 114 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "shell/browser/javascript_environment.h"
|
||||
#include "shell/common/gin_converters/callback_converter.h"
|
||||
#include "shell/common/gin_converters/content_converter.h"
|
||||
#include "shell/common/gin_converters/hid_device_info_converter.h"
|
||||
#include "shell/common/gin_converters/value_converter.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
|
@ -28,18 +29,6 @@
|
|||
|
||||
namespace {
|
||||
|
||||
std::string PhysicalDeviceIdFromDeviceInfo(
|
||||
const device::mojom::HidDeviceInfo& device) {
|
||||
// A single physical device may expose multiple HID interfaces, each
|
||||
// represented by a HidDeviceInfo object. When a device exposes multiple
|
||||
// HID interfaces, the HidDeviceInfo objects will share a common
|
||||
// |physical_device_id|. Group these devices so that a single chooser item
|
||||
// is shown for each physical device. If a device's physical device ID is
|
||||
// empty, use its GUID instead.
|
||||
return device.physical_device_id.empty() ? device.guid
|
||||
: device.physical_device_id;
|
||||
}
|
||||
|
||||
bool FilterMatch(const blink::mojom::HidDeviceFilterPtr& filter,
|
||||
const device::mojom::HidDeviceInfo& device) {
|
||||
if (filter->device_ids) {
|
||||
|
@ -83,21 +72,6 @@ bool FilterMatch(const blink::mojom::HidDeviceFilterPtr& filter,
|
|||
|
||||
} // namespace
|
||||
|
||||
namespace gin {
|
||||
|
||||
template <>
|
||||
struct Converter<device::mojom::HidDeviceInfoPtr> {
|
||||
static v8::Local<v8::Value> ToV8(
|
||||
v8::Isolate* isolate,
|
||||
const device::mojom::HidDeviceInfoPtr& device) {
|
||||
base::Value value = electron::HidChooserContext::DeviceInfoToValue(*device);
|
||||
value.SetStringKey("deviceId", PhysicalDeviceIdFromDeviceInfo(*device));
|
||||
return gin::ConvertToV8(isolate, value);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
namespace electron {
|
||||
|
||||
HidChooserController::HidChooserController(
|
||||
|
@ -131,6 +105,19 @@ HidChooserController::~HidChooserController() {
|
|||
std::move(callback_).Run(std::vector<device::mojom::HidDeviceInfoPtr>());
|
||||
}
|
||||
|
||||
// static
|
||||
std::string HidChooserController::PhysicalDeviceIdFromDeviceInfo(
|
||||
const device::mojom::HidDeviceInfo& device) {
|
||||
// A single physical device may expose multiple HID interfaces, each
|
||||
// represented by a HidDeviceInfo object. When a device exposes multiple
|
||||
// HID interfaces, the HidDeviceInfo objects will share a common
|
||||
// |physical_device_id|. Group these devices so that a single chooser item
|
||||
// is shown for each physical device. If a device's physical device ID is
|
||||
// empty, use its GUID instead.
|
||||
return device.physical_device_id.empty() ? device.guid
|
||||
: device.physical_device_id;
|
||||
}
|
||||
|
||||
api::Session* HidChooserController::GetSession() {
|
||||
if (!web_contents()) {
|
||||
return nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue