Repository: electron/electron
File: shell/browser/serial/serial_chooser_controller.cc (C++)

Code before:
}

bool SerialChooserController::DisplayDevice(
    const device::mojom::SerialPortInfo& port) const {
  bool blocklist_disabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
      kDisableSerialBlocklist);
  if (!blocklist_disabled && SerialBlocklist::Get().IsExcluded(port)) {
    if (port.has_vendor_id && port.has_product_id) {
      AddMessageToConsole(
          blink::mojom::ConsoleMessageLevel::kInfo,
          base::StringPrintf(
              "Chooser dialog is not displaying a port blocked by "
              "the Serial blocklist: vendorId=%d, "
              "productId=%d, name='%s', serial='%s'",
              port.vendor_id, port.product_id,
              port.display_name ? port.display_name.value().c_str() : "",
              port.serial_number ? port.serial_number.value().c_str() : ""));
    } else if (port.bluetooth_service_class_id) {
      AddMessageToConsole(
          blink::mojom::ConsoleMessageLevel::kInfo,
          base::StringPrintf(
              "Chooser dialog is not displaying a port blocked by "
              "the Serial blocklist: bluetoothServiceClassId=%s, "
              "name='%s'",
              port.bluetooth_service_class_id->value().c_str(),
              port.display_name ? port.display_name.value().c_str() : ""));
    } else {
      NOTREACHED();
    }
    return false;
  }

  if (filters_.empty()) {
    return BluetoothPortIsAllowed(allowed_bluetooth_service_class_ids_, port);
  }

  for (const auto& filter : filters_) {
    if (FilterMatchesPort(*filter, port) &&
        BluetoothPortIsAllowed(allowed_bluetooth_service_class_ids_, port)) {
      return true;
    }
  }

  return false;
}

void SerialChooserController::AddMessageToConsole(
    blink::mojom::ConsoleMessageLevel level,
    const std::string& message) const {
  if (content::RenderFrameHost* rfh =
          initiator_document_.AsRenderFrameHostIfValid()) {

Review comment (suggestion):
I see this is copied upstream from https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/serial/serial_chooser_controller.cc;l=422.  I think the console text might be a bit confusing because Electron doesn't use a chooser dialog

Code after:
}

bool SerialChooserController::DisplayDevice(
    const device::mojom::SerialPortInfo& port) const {
  bool blocklist_disabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
      kDisableSerialBlocklist);
  if (!blocklist_disabled && SerialBlocklist::Get().IsExcluded(port)) {
    if (port.has_vendor_id && port.has_product_id) {
      AddMessageToConsole(
          blink::mojom::ConsoleMessageLevel::kInfo,
          base::StringPrintf(
              "Skipping a port blocked by "
              "the Serial blocklist: vendorId=%d, "
              "productId=%d, name='%s', serial='%s'",
              port.vendor_id, port.product_id,
              port.display_name ? port.display_name.value().c_str() : "",
              port.serial_number ? port.serial_number.value().c_str() : ""));
    } else if (port.bluetooth_service_class_id) {
      AddMessageToConsole(
          blink::mojom::ConsoleMessageLevel::kInfo,
          base::StringPrintf(
              "Skipping a port blocked by "
              "the Serial blocklist: bluetoothServiceClassId=%s, "
              "name='%s'",
              port.bluetooth_service_class_id->value().c_str(),
              port.display_name ? port.display_name.value().c_str() : ""));
    } else {
      NOTREACHED();
    }
    return false;
  }

  if (filters_.empty()) {
    return BluetoothPortIsAllowed(allowed_bluetooth_service_class_ids_, port);
  }

  for (const auto& filter : filters_) {
    if (FilterMatchesPort(*filter, port) &&
        BluetoothPortIsAllowed(allowed_bluetooth_service_class_ids_, port)) {
      return true;
    }
  }

  return false;
}

void SerialChooserController::AddMessageToConsole(
    blink::mojom::ConsoleMessageLevel level,
    const std::string& message) const {
  if (content::RenderFrameHost* rfh =
          initiator_document_.AsRenderFrameHostIfValid()) {