|
@@ -241,6 +241,67 @@ std::string MakePartitionName(const std::string& input) {
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
+bool DoesDeviceMatch(const base::Value& device,
|
|
|
+ const base::Value& device_to_compare,
|
|
|
+ const blink::PermissionType permission_type) {
|
|
|
+ if (permission_type ==
|
|
|
+ static_cast<blink::PermissionType>(
|
|
|
+ WebContentsPermissionHelper::PermissionType::HID) ||
|
|
|
+ permission_type ==
|
|
|
+ static_cast<blink::PermissionType>(
|
|
|
+ WebContentsPermissionHelper::PermissionType::USB)) {
|
|
|
+ if (device.GetDict().FindInt(kDeviceVendorIdKey) !=
|
|
|
+ device_to_compare.GetDict().FindInt(kDeviceVendorIdKey) ||
|
|
|
+ device.GetDict().FindInt(kDeviceProductIdKey) !=
|
|
|
+ device_to_compare.GetDict().FindInt(kDeviceProductIdKey)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const auto* serial_number =
|
|
|
+ device_to_compare.GetDict().FindString(kDeviceSerialNumberKey);
|
|
|
+ const auto* device_serial_number =
|
|
|
+ device.GetDict().FindString(kDeviceSerialNumberKey);
|
|
|
+
|
|
|
+ if (serial_number && device_serial_number &&
|
|
|
+ *device_serial_number == *serial_number)
|
|
|
+ return true;
|
|
|
+ } else if (permission_type ==
|
|
|
+ static_cast<blink::PermissionType>(
|
|
|
+ WebContentsPermissionHelper::PermissionType::SERIAL)) {
|
|
|
+#if BUILDFLAG(IS_WIN)
|
|
|
+ const auto* instance_id = device.GetDict().FindString(kDeviceInstanceIdKey);
|
|
|
+ const auto* port_instance_id =
|
|
|
+ device_to_compare.GetDict().FindString(kDeviceInstanceIdKey);
|
|
|
+ if (instance_id && port_instance_id && *instance_id == *port_instance_id)
|
|
|
+ return true;
|
|
|
+#else
|
|
|
+ const auto* serial_number = device.GetDict().FindString(kSerialNumberKey);
|
|
|
+ const auto* port_serial_number =
|
|
|
+ device_to_compare.GetDict().FindString(kSerialNumberKey);
|
|
|
+ if (device.GetDict().FindInt(kVendorIdKey) !=
|
|
|
+ device_to_compare.GetDict().FindInt(kVendorIdKey) ||
|
|
|
+ device.GetDict().FindInt(kProductIdKey) !=
|
|
|
+ device_to_compare.GetDict().FindInt(kProductIdKey) ||
|
|
|
+ (serial_number && port_serial_number &&
|
|
|
+ *port_serial_number != *serial_number)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+#if BUILDFLAG(IS_MAC)
|
|
|
+ const auto* usb_driver_key = device.GetDict().FindString(kUsbDriverKey);
|
|
|
+ const auto* port_usb_driver_key =
|
|
|
+ device_to_compare.GetDict().FindString(kUsbDriverKey);
|
|
|
+ if (usb_driver_key && port_usb_driver_key &&
|
|
|
+ *usb_driver_key != *port_usb_driver_key) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+#endif // BUILDFLAG(IS_MAC)
|
|
|
+ return true;
|
|
|
+#endif // BUILDFLAG(IS_WIN)
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|
|
|
|
|
|
// static
|
|
@@ -721,7 +782,7 @@ void ElectronBrowserContext::GrantDevicePermission(
|
|
|
void ElectronBrowserContext::RevokeDevicePermission(
|
|
|
const url::Origin& origin,
|
|
|
const base::Value& device,
|
|
|
- blink::PermissionType permission_type) {
|
|
|
+ const blink::PermissionType permission_type) {
|
|
|
const auto& current_devices_it = granted_devices_.find(permission_type);
|
|
|
if (current_devices_it == granted_devices_.end())
|
|
|
return;
|
|
@@ -730,76 +791,10 @@ void ElectronBrowserContext::RevokeDevicePermission(
|
|
|
if (origin_devices_it == current_devices_it->second.end())
|
|
|
return;
|
|
|
|
|
|
- for (auto it = origin_devices_it->second.begin();
|
|
|
- it != origin_devices_it->second.end();) {
|
|
|
- if (DoesDeviceMatch(device, it->get(), permission_type)) {
|
|
|
- it = origin_devices_it->second.erase(it);
|
|
|
- } else {
|
|
|
- ++it;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-bool ElectronBrowserContext::DoesDeviceMatch(
|
|
|
- const base::Value& device,
|
|
|
- const base::Value* device_to_compare,
|
|
|
- blink::PermissionType permission_type) {
|
|
|
- if (permission_type ==
|
|
|
- static_cast<blink::PermissionType>(
|
|
|
- WebContentsPermissionHelper::PermissionType::HID) ||
|
|
|
- permission_type ==
|
|
|
- static_cast<blink::PermissionType>(
|
|
|
- WebContentsPermissionHelper::PermissionType::USB)) {
|
|
|
- if (device.GetDict().FindInt(kDeviceVendorIdKey) !=
|
|
|
- device_to_compare->GetDict().FindInt(kDeviceVendorIdKey) ||
|
|
|
- device.GetDict().FindInt(kDeviceProductIdKey) !=
|
|
|
- device_to_compare->GetDict().FindInt(kDeviceProductIdKey)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- const auto* serial_number =
|
|
|
- device_to_compare->GetDict().FindString(kDeviceSerialNumberKey);
|
|
|
- const auto* device_serial_number =
|
|
|
- device.GetDict().FindString(kDeviceSerialNumberKey);
|
|
|
-
|
|
|
- if (serial_number && device_serial_number &&
|
|
|
- *device_serial_number == *serial_number)
|
|
|
- return true;
|
|
|
- } else if (permission_type ==
|
|
|
- static_cast<blink::PermissionType>(
|
|
|
- WebContentsPermissionHelper::PermissionType::SERIAL)) {
|
|
|
-#if BUILDFLAG(IS_WIN)
|
|
|
- const auto* instance_id = device.GetDict().FindString(kDeviceInstanceIdKey);
|
|
|
- const auto* port_instance_id =
|
|
|
- device_to_compare->GetDict().FindString(kDeviceInstanceIdKey);
|
|
|
- if (instance_id && port_instance_id && *instance_id == *port_instance_id)
|
|
|
- return true;
|
|
|
-#else
|
|
|
- const auto* serial_number = device.GetDict().FindString(kSerialNumberKey);
|
|
|
- const auto* port_serial_number =
|
|
|
- device_to_compare->GetDict().FindString(kSerialNumberKey);
|
|
|
- if (device.GetDict().FindInt(kVendorIdKey) !=
|
|
|
- device_to_compare->GetDict().FindInt(kVendorIdKey) ||
|
|
|
- device.GetDict().FindInt(kProductIdKey) !=
|
|
|
- device_to_compare->GetDict().FindInt(kProductIdKey) ||
|
|
|
- (serial_number && port_serial_number &&
|
|
|
- *port_serial_number != *serial_number)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
-#if BUILDFLAG(IS_MAC)
|
|
|
- const auto* usb_driver_key = device.GetDict().FindString(kUsbDriverKey);
|
|
|
- const auto* port_usb_driver_key =
|
|
|
- device_to_compare->GetDict().FindString(kUsbDriverKey);
|
|
|
- if (usb_driver_key && port_usb_driver_key &&
|
|
|
- *usb_driver_key != *port_usb_driver_key) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-#endif // BUILDFLAG(IS_MAC)
|
|
|
- return true;
|
|
|
-#endif // BUILDFLAG(IS_WIN)
|
|
|
- }
|
|
|
- return false;
|
|
|
+ std::erase_if(origin_devices_it->second,
|
|
|
+ [&device, &permission_type](auto const& val) {
|
|
|
+ return DoesDeviceMatch(device, *val, permission_type);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
bool ElectronBrowserContext::CheckDevicePermission(
|
|
@@ -815,7 +810,7 @@ bool ElectronBrowserContext::CheckDevicePermission(
|
|
|
return false;
|
|
|
|
|
|
for (const auto& device_to_compare : origin_devices_it->second) {
|
|
|
- if (DoesDeviceMatch(device, device_to_compare.get(), permission_type))
|
|
|
+ if (DoesDeviceMatch(device, *device_to_compare, permission_type))
|
|
|
return true;
|
|
|
}
|
|
|
|