Repository: electron/electron
Pull request: fix: crash when generating shortcut text for super accelerator (33-x-y)

Manually backport #44341 to 33-x-y. See that PR for details.

No manual changes to either the new .patch or the spec; trop only failed because of index shear in the patchfiles.

Notes: fix crash when rendering super menu accelerator on linux.

Changed files:
filename: patches/chromium/.patches
patch: @@ -131,3 +131,4 @@ feat_enable_customizing_symbol_color_in_framecaptionbutton.patch
 build_expose_webplugininfo_interface_to_electron.patch
 feat_allow_usage_of_sccontentsharingpicker_on_supported_platforms.patch
 fix_software_compositing_infinite_loop.patch
+ui_add_missing_shortcut_text_for_vkey_command_on_linux.patch

filename: patches/chromium/build_do_not_depend_on_packed_resource_integrity.patch
patch: @@ -46,10 +46,10 @@ index 7f1c26990d8d43e92615bd3a5f4046d121d6ac6b..89d03b68cab5cec6095c2df2159a2f1c
        # than here in :chrome_dll.
        deps += [ "//chrome:packed_resources_integrity_header" ]
 diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
-index c53d7af88b3570e6c320b408afa449e51e355b6b..61aecb395632212911d57545cb068ca67bbac7d5 100644
+index 26702ebe305dae944d7f425ec610058e51c43656..855bd8f541db112929e5cca4473bde5e577d0d4d 100644
 --- a/chrome/test/BUILD.gn
 +++ b/chrome/test/BUILD.gn
-@@ -7173,9 +7173,12 @@ test("unit_tests") {
+@@ -7174,9 +7174,12 @@ test("unit_tests") {
        "//chrome/notification_helper",
      ]
  
@@ -63,7 +63,7 @@ index c53d7af88b3570e6c320b408afa449e51e355b6b..61aecb395632212911d57545cb068ca6
        "//chrome//services/util_win:unit_tests",
        "//chrome/app:chrome_dll_resources",
        "//chrome/app:win_unit_tests",
-@@ -8181,6 +8184,10 @@ test("unit_tests") {
+@@ -8182,6 +8185,10 @@ test("unit_tests") {
        "../browser/performance_manager/policies/background_tab_loading_policy_unittest.cc",
      ]
  
@@ -74,7 +74,7 @@ index c53d7af88b3570e6c320b408afa449e51e355b6b..61aecb395632212911d57545cb068ca6
      sources += [
        # The importer code is not used on Android.
        "../common/importer/firefox_importer_utils_unittest.cc",
-@@ -8237,7 +8244,6 @@ test("unit_tests") {
+@@ -8238,7 +8245,6 @@ test("unit_tests") {
      # Non-android deps for "unit_tests" target.
      deps += [
        "../browser/screen_ai:screen_ai_install_state",

filename: patches/chromium/ui_add_missing_shortcut_text_for_vkey_command_on_linux.patch
patch: @@ -0,0 +1,50 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: deepak1556 <hop2deep@gmail.com>
+Date: Tue, 22 Oct 2024 00:27:27 +0900
+Subject: Add missing shortcut text for VKEY_COMMAND on linux
+
+Backports https://chromium-review.googlesource.com/c/chromium/src/+/5947724
+
+diff --git a/ui/base/accelerators/accelerator.cc b/ui/base/accelerators/accelerator.cc
+index 32a3fc0843656eaa87b85dd63ac1ade6d83b6e5b..ed1ff076b1db6b77d0684bae1931714bf575ebe8 100644
+--- a/ui/base/accelerators/accelerator.cc
++++ b/ui/base/accelerators/accelerator.cc
+@@ -419,6 +419,8 @@ std::u16string Accelerator::ApplyLongFormModifiers(
+     result = ApplyModifierToAcceleratorString(result, IDS_APP_SEARCH_KEY);
+ #elif BUILDFLAG(IS_WIN)
+     result = ApplyModifierToAcceleratorString(result, IDS_APP_WINDOWS_KEY);
++#elif BUILDFLAG(IS_LINUX)
++    result = ApplyModifierToAcceleratorString(result, IDS_APP_SUPER_KEY);
+ #else
+     NOTREACHED();
+ #endif
+diff --git a/ui/base/accelerators/accelerator_unittest.cc b/ui/base/accelerators/accelerator_unittest.cc
+index 246cfe906786c1586e15acbae063a77cb5cc84e7..7627da94c48473870b127b57edad2a2845d76d4c 100644
+--- a/ui/base/accelerators/accelerator_unittest.cc
++++ b/ui/base/accelerators/accelerator_unittest.cc
+@@ -58,6 +58,9 @@ TEST(AcceleratorTest, MAYBE_GetShortcutText) {
+     {VKEY_OEM_COMMA, EF_CONTROL_DOWN, u"Ctrl+Comma", u"⌃,"},
+ #if BUILDFLAG(IS_MAC)
+     {VKEY_T, EF_COMMAND_DOWN | EF_CONTROL_DOWN, nullptr, u"⌃⌘T"},
++#endif
++#if BUILDFLAG(IS_LINUX)
++    {VKEY_T, EF_COMMAND_DOWN | EF_CONTROL_DOWN, u"Super+Ctrl+T", nullptr},
+ #endif
+   };
+ 
+diff --git a/ui/strings/ui_strings.grd b/ui/strings/ui_strings.grd
+index c7e58d4820443f3af9b494259e160ad27b9dbfdd..8937506c5594404c916d3a73907c883bc86198e7 100644
+--- a/ui/strings/ui_strings.grd
++++ b/ui/strings/ui_strings.grd
+@@ -764,6 +764,11 @@ need to be translated for each locale.-->
+           Win
+         </message>
+       </if>
++      <if expr="is_linux">
++        <message name="IDS_APP_SUPER_KEY" desc="Windows key on Windows keyboards, and Command key on Mac keyboards.">
++          Super
++        </message>
++      </if>
+       <if expr="chromeos_ash">
+         <message name="IDS_APP_META_KEY" desc="External Meta key (Search key on ChromeOS keyboards, Windows key on Windows keyboards, and Command key on Mac keyboards)">
+           Meta

filename: spec/api-menu-spec.ts
patch: @@ -926,6 +926,20 @@ describe('Menu module', function () {
       });
       w.show();
     });
+
+    it('does not crash when rendering menu item with Super or meta accelerator', async () => {
+      const menu = Menu.buildFromTemplate([{
+        label: 'Test Super',
+        accelerator: 'Super+Ctrl+T'
+      }, {
+        label: 'Test Meta',
+        accelerator: 'Meta+Ctrl+T'
+      }]);
+      const menuWillClose = once(menu, 'menu-will-close');
+      menu.popup({ window: w });
+      menu.closePopup();
+      await menuWillClose;
+    });
   });
 
   describe('Menu.setApplicationMenu', () => {