mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: support Web Serial & WebUSB blocklists (#46600)
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "base/values.h"
|
||||
#include "chrome/browser/usb/usb_blocklist.h"
|
||||
#include "components/content_settings/core/common/content_settings.h"
|
||||
#include "content/public/browser/device_service.h"
|
||||
#include "services/device/public/cpp/usb/usb_ids.h"
|
||||
@@ -215,6 +217,12 @@ void UsbChooserContext::GrantDevicePermission(
|
||||
bool UsbChooserContext::HasDevicePermission(
|
||||
const url::Origin& origin,
|
||||
const device::mojom::UsbDeviceInfo& device_info) {
|
||||
bool blocklist_disabled =
|
||||
base::CommandLine::ForCurrentProcess()->HasSwitch(kDisableUSBBlocklist);
|
||||
if (!blocklist_disabled && UsbBlocklist::Get().IsExcluded(device_info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto it = ephemeral_devices_.find(origin);
|
||||
if (it != ephemeral_devices_.end() && it->second.contains(device_info.guid)) {
|
||||
return true;
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace electron {
|
||||
|
||||
class ElectronBrowserContext;
|
||||
|
||||
const char kDisableUSBBlocklist[] = "disable-usb-blocklist";
|
||||
|
||||
class UsbChooserContext : public KeyedService,
|
||||
public device::mojom::UsbDeviceManagerClient {
|
||||
public:
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "chrome/browser/usb/usb_blocklist.h"
|
||||
#include "components/strings/grit/components_strings.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
@@ -140,6 +142,8 @@ void UsbChooserController::GotUsbDeviceList(
|
||||
|
||||
bool UsbChooserController::DisplayDevice(
|
||||
const device::mojom::UsbDeviceInfo& device_info) const {
|
||||
bool blocklist_disabled =
|
||||
base::CommandLine::ForCurrentProcess()->HasSwitch(kDisableUSBBlocklist);
|
||||
if (!device::UsbDeviceFilterMatchesAny(options_->filters, device_info)) {
|
||||
return false;
|
||||
}
|
||||
@@ -151,6 +155,10 @@ bool UsbChooserController::DisplayDevice(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!blocklist_disabled && UsbBlocklist::Get().IsExcluded(device_info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user