From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Charles Kerr <charles@charleskerr.com>
Date: Thu, 17 Apr 2025 19:07:23 -0500
Subject: refactor: patch electron PermissionTypes into blink

6387077: [PermissionOptions] Generalize PermissionRequestDescription | https://chromium-review.googlesource.com/c/chromium/src/+/6387077

diff --git a/components/permissions/permission_util.cc b/components/permissions/permission_util.cc
index 2aa7d12c278dee9dd987aa5d1aba9d9ba798cff1..77625a7af1b3ba4d7959ca769cfc39e3dce50d67 100644
--- a/components/permissions/permission_util.cc
+++ b/components/permissions/permission_util.cc
@@ -526,7 +526,17 @@ ContentSettingsType PermissionUtil::PermissionTypeToContentSettingsTypeSafe(
       return ContentSettingsType::WEB_APP_INSTALLATION;
     case PermissionType::LOCAL_NETWORK_ACCESS:
       return ContentSettingsType::LOCAL_NETWORK_ACCESS;
+
+    // Permissions added by Electron
     case PermissionType::DEPRECATED_SYNC_CLIPBOARD_READ:
+    case PermissionType::ELECTRON_FULLSCREEN:
+    case PermissionType::FILE_SYSTEM:
+    case PermissionType::HID:
+    case PermissionType::OPEN_EXTERNAL:
+    case PermissionType::SERIAL:
+    case PermissionType::USB:
+      break;
+
     case PermissionType::NUM:
       break;
   }
diff --git a/content/browser/permissions/permission_controller_impl.cc b/content/browser/permissions/permission_controller_impl.cc
index cb3faf970f20047f1e0a1fd4c844a173f681776a..572ffd97e7bb49946d15bf85ee144066837ee17f 100644
--- a/content/browser/permissions/permission_controller_impl.cc
+++ b/content/browser/permissions/permission_controller_impl.cc
@@ -88,7 +88,15 @@ PermissionToSchedulingFeature(PermissionType permission_name) {
     case PermissionType::AUTOMATIC_FULLSCREEN:
     case PermissionType::WEB_APP_INSTALLATION:
     case PermissionType::LOCAL_NETWORK_ACCESS:
+
+    // Permissions added by Electron
     case PermissionType::DEPRECATED_SYNC_CLIPBOARD_READ:
+    case PermissionType::FILE_SYSTEM:
+    case PermissionType::ELECTRON_FULLSCREEN:
+    case PermissionType::HID:
+    case PermissionType::OPEN_EXTERNAL:
+    case PermissionType::SERIAL:
+    case PermissionType::USB:
       return std::nullopt;
   }
 }
diff --git a/content/browser/permissions/permission_descriptor_util.cc b/content/browser/permissions/permission_descriptor_util.cc
index 714d582d1060873765b24770b18eddcbbdcf5506..3746bafd72223a65c4183a59726601e84accf66f 100644
--- a/content/browser/permissions/permission_descriptor_util.cc
+++ b/content/browser/permissions/permission_descriptor_util.cc
@@ -171,9 +171,27 @@ content::PermissionDescriptorUtil::CreatePermissionDescriptorForPermissionType(
     case blink::PermissionType::LOCAL_NETWORK_ACCESS:
       return CreatePermissionDescriptor(
           blink::mojom::PermissionName::LOCAL_NETWORK_ACCESS);
+
+    // Permissions added by Electron
     case blink::PermissionType::DEPRECATED_SYNC_CLIPBOARD_READ:
       return CreatePermissionDescriptor(
           blink::mojom::PermissionName::DEPRECATED_SYNC_CLIPBOARD_READ);
+    case blink::PermissionType::FILE_SYSTEM:
+      return CreatePermissionDescriptor(
+          blink::mojom::PermissionName::FILE_SYSTEM);
+    case blink::PermissionType::ELECTRON_FULLSCREEN:
+      return CreatePermissionDescriptor(
+          blink::mojom::PermissionName::ELECTRON_FULLSCREEN);
+    case blink::PermissionType::HID:
+      return CreatePermissionDescriptor(blink::mojom::PermissionName::HID);
+    case blink::PermissionType::OPEN_EXTERNAL:
+      return CreatePermissionDescriptor(
+          blink::mojom::PermissionName::OPEN_EXTERNAL);
+    case blink::PermissionType::SERIAL:
+      return CreatePermissionDescriptor(blink::mojom::PermissionName::SERIAL);
+    case blink::PermissionType::USB:
+      return CreatePermissionDescriptor(blink::mojom::PermissionName::USB);
+
     case blink::PermissionType::NUM:
       NOTREACHED();
   }
diff --git a/third_party/blink/common/permissions/permission_utils.cc b/third_party/blink/common/permissions/permission_utils.cc
index 2d7d9e96522208835a867e0be12df4da56141ab1..3cdce77120c89631609c488d8256ab211d71ab03 100644
--- a/third_party/blink/common/permissions/permission_utils.cc
+++ b/third_party/blink/common/permissions/permission_utils.cc
@@ -104,6 +104,18 @@ std::string GetPermissionString(PermissionType permission) {
       return "LocalNetworkAccess";
     case PermissionType::DEPRECATED_SYNC_CLIPBOARD_READ:
       return "DeprecatedSyncClipboardRead";
+    case PermissionType::FILE_SYSTEM:
+      return "FileSystem";
+    case PermissionType::ELECTRON_FULLSCREEN:
+      return "Fullscreen";
+    case PermissionType::HID:
+      return "HID";
+    case PermissionType::OPEN_EXTERNAL:
+      return "OpenExternal";
+    case PermissionType::SERIAL:
+      return "Serial";
+    case PermissionType::USB:
+      return "USB";
     case PermissionType::NUM:
       NOTREACHED();
   }
@@ -178,7 +190,15 @@ PermissionTypeToPermissionsPolicyFeature(PermissionType permission) {
     case PermissionType::NOTIFICATIONS:
     case PermissionType::KEYBOARD_LOCK:
     case PermissionType::POINTER_LOCK:
+
+    // Permissions added by Electron
     case PermissionType::DEPRECATED_SYNC_CLIPBOARD_READ:
+    case PermissionType::ELECTRON_FULLSCREEN:
+    case PermissionType::FILE_SYSTEM:
+    case PermissionType::HID:
+    case PermissionType::OPEN_EXTERNAL:
+    case PermissionType::SERIAL:
+    case PermissionType::USB:
       return std::nullopt;
 
     case PermissionType::NUM:
@@ -348,6 +368,21 @@ std::optional<PermissionType> PermissionDescriptorInfoToPermissionType(
       return PermissionType::WEB_PRINTING;
     case PermissionName::SMART_CARD:
       return PermissionType::SMART_CARD;
+    // Permissions added by Electron
+    case PermissionName::DEPRECATED_SYNC_CLIPBOARD_READ:
+      return PermissionType::DEPRECATED_SYNC_CLIPBOARD_READ;
+    case PermissionName::FILE_SYSTEM:
+      return PermissionType::FILE_SYSTEM;
+    case PermissionName::ELECTRON_FULLSCREEN:
+      return PermissionType::ELECTRON_FULLSCREEN;
+    case PermissionName::HID:
+      return PermissionType::HID;
+    case PermissionName::OPEN_EXTERNAL:
+      return PermissionType::OPEN_EXTERNAL;
+    case PermissionName::SERIAL:
+      return PermissionType::SERIAL;
+    case PermissionName::USB:
+      return PermissionType::USB;
   }
 }
 
diff --git a/third_party/blink/public/common/permissions/permission_utils.h b/third_party/blink/public/common/permissions/permission_utils.h
index c286d87043ec4cb2e51ec9d82d08e4c84f5a270c..164a2a446947dae687922363d324a6d35b7ae0b8 100644
--- a/third_party/blink/public/common/permissions/permission_utils.h
+++ b/third_party/blink/public/common/permissions/permission_utils.h
@@ -65,7 +65,17 @@ enum class PermissionType {
   HAND_TRACKING = 41,
   WEB_APP_INSTALLATION = 42,
   LOCAL_NETWORK_ACCESS = 43,
-  DEPRECATED_SYNC_CLIPBOARD_READ = 44,
+
+  // Permissions added by Electron
+  ELECTRON_FIRST,
+  DEPRECATED_SYNC_CLIPBOARD_READ = ELECTRON_FIRST,
+  FILE_SYSTEM,
+  ELECTRON_FULLSCREEN,
+  HID,
+  OPEN_EXTERNAL,
+  SERIAL,
+  USB,
+  ELECTRON_LAST = USB,
 
   // Always keep this at the end.
   NUM,
diff --git a/third_party/blink/public/mojom/permissions/permission.mojom b/third_party/blink/public/mojom/permissions/permission.mojom
index 47c73522cbd7c1d12dabfecf6f55a74690ebc189..6b8ed935e8c440cbf655d122a398d33e3e4ad89b 100644
--- a/third_party/blink/public/mojom/permissions/permission.mojom
+++ b/third_party/blink/public/mojom/permissions/permission.mojom
@@ -44,7 +44,15 @@ enum PermissionName {
   HAND_TRACKING,
   WEB_PRINTING,
   SMART_CARD,
-  DEPRECATED_SYNC_CLIPBOARD_READ
+
+  // Permissions added by Electron
+  DEPRECATED_SYNC_CLIPBOARD_READ,
+  FILE_SYSTEM,
+  ELECTRON_FULLSCREEN,
+  HID,
+  OPEN_EXTERNAL,
+  SERIAL,
+  USB
 };
 
 struct MidiPermissionDescriptor {
diff --git a/third_party/blink/renderer/modules/permissions/permission_utils.cc b/third_party/blink/renderer/modules/permissions/permission_utils.cc
index a980ed6afb84eceef9c9b594b325e8e3783821ec..ff2898ca035ae5f2bc218615a87ec148e3764385 100644
--- a/third_party/blink/renderer/modules/permissions/permission_utils.cc
+++ b/third_party/blink/renderer/modules/permissions/permission_utils.cc
@@ -145,8 +145,22 @@ String PermissionNameToString(PermissionName name) {
       return "web-printing";
     case PermissionName::SMART_CARD:
       return "smart-card";
+
+    // Permissions added by Electron
     case PermissionName::DEPRECATED_SYNC_CLIPBOARD_READ:
       return "deprecated-sync-clipboard-read";
+    case PermissionName::FILE_SYSTEM:
+      return "file-system";
+    case PermissionName::ELECTRON_FULLSCREEN:
+      return "electron-fullscreen";
+    case PermissionName::HID:
+      return "hid";
+    case PermissionName::OPEN_EXTERNAL:
+      return "open-external";
+    case PermissionName::SERIAL:
+      return "serial";
+    case PermissionName::USB:
+      return "usb";
   }
 }
 
