Skip to content

Commit 6428bf3

Browse files
fix: use the new MediaPlayPause key listener for internal chrome logic (electron#21959)
1 parent 7c070c5 commit 6428bf3

File tree

5 files changed

+66
-18
lines changed

5 files changed

+66
-18
lines changed

buildflags/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ buildflag_header("buildflags") {
2121
"ENABLE_ELECTRON_EXTENSIONS=$enable_electron_extensions",
2222
"ENABLE_BUILTIN_SPELLCHECKER=$enable_builtin_spellchecker",
2323
"ENABLE_PICTURE_IN_PICTURE=$enable_picture_in_picture",
24-
"ENABLE_MEDIA_KEY_OVERRIDES=$enable_media_key_overrides",
2524
"OVERRIDE_LOCATION_PROVIDER=$enable_fake_location_provider",
2625
]
2726
}

buildflags/buildflags.gni

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ declare_args() {
2222

2323
enable_picture_in_picture = true
2424

25-
enable_media_key_overrides = true
26-
2725
# Provide a fake location provider for mocking
2826
# the geolocation responses. Disable it if you
2927
# need to test with chromium's location provider.

patches/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ feat_allow_disabling_blink_scheduler_throttling_per_renderview.patch
8181
accessible_pane_view.patch
8282
fixme_grit_conflicts.patch
8383
fix_add_executable_to_chromedriver_s_rpath_for_electron_8.patch
84+
fix_use_the_new_mediaplaypause_key_listener_for_internal_chrome.patch

patches/chromium/command-ismediakey.patch

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,3 @@ index 85378bb565de617b1bd611d28c8714361747a357..94a899e76586d2c7bb199828bfa4aa1e
112112
return event;
113113
}
114114

115-
@@ -223,12 +233,14 @@ static CGEventRef EventTapCallback(CGEventTapProxy proxy,
116-
// For Mac OS 10.12.2 or later, we want to use MPRemoteCommandCenter for
117-
// getting media keys globally if there is a RemoteCommandCenterDelegate
118-
// available.
119-
+#if !BUILDFLAG(ENABLE_MEDIA_KEY_OVERRIDES)
120-
if (scope == Scope::kGlobal) {
121-
auto listener =
122-
std::make_unique<SystemMediaControlsMediaKeysListener>(delegate);
123-
if (listener->Initialize())
124-
return listener;
125-
}
126-
+#endif
127-
128-
return std::make_unique<MediaKeysListenerImpl>(delegate, scope);
129-
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Samuel Attard <sattard@slack-corp.com>
3+
Date: Wed, 29 Jan 2020 12:28:48 -0800
4+
Subject: fix: use the new MediaPlayPause key listener for internal chrome
5+
logic
6+
7+
The new kGlobalRequiresAccessibility Scope type should be upstreamed
8+
and then we can use that and minimize this patch to just the change in
9+
global_shortcut_listener_mac.mm
10+
11+
diff --git a/chrome/browser/extensions/global_shortcut_listener_mac.mm b/chrome/browser/extensions/global_shortcut_listener_mac.mm
12+
index befe726af9c10b1563a7fc0bb77cc55f65943d5c..bac51f33f35f96fe4ecc764cf5ca887176642f74 100644
13+
--- a/chrome/browser/extensions/global_shortcut_listener_mac.mm
14+
+++ b/chrome/browser/extensions/global_shortcut_listener_mac.mm
15+
@@ -39,7 +39,7 @@
16+
// global MediaKeysListener to receive media keys.
17+
if (!content::MediaKeysListenerManager::IsMediaKeysListenerManagerEnabled()) {
18+
media_keys_listener_ = ui::MediaKeysListener::Create(
19+
- this, ui::MediaKeysListener::Scope::kGlobal);
20+
+ this, ui::MediaKeysListener::Scope::kGlobalRequiresAccessibility);
21+
DCHECK(media_keys_listener_);
22+
}
23+
}
24+
diff --git a/ui/base/accelerators/media_keys_listener.h b/ui/base/accelerators/media_keys_listener.h
25+
index 997718d8affaa193fcaabff4cd4c8b0c23df8891..e121598d46e7c62a3b14cb7960136f655cc69ab6 100644
26+
--- a/ui/base/accelerators/media_keys_listener.h
27+
+++ b/ui/base/accelerators/media_keys_listener.h
28+
@@ -20,8 +20,9 @@ class Accelerator;
29+
class UI_BASE_EXPORT MediaKeysListener {
30+
public:
31+
enum class Scope {
32+
- kGlobal, // Listener works whenever application in focus or not.
33+
- kFocused, // Listener only works whan application has focus.
34+
+ kGlobalRequiresAccessibility, // Listener works whenever application in focus or not but requires accessibility permissions on macOS
35+
+ kGlobal, // Listener works whenever application in focus or not but requires media to be playnig.
36+
+ kFocused, // Listener only works whan application has focus.
37+
};
38+
39+
// Media keys accelerators receiver.
40+
diff --git a/ui/base/accelerators/media_keys_listener_linux.cc b/ui/base/accelerators/media_keys_listener_linux.cc
41+
index c74807dfae799851bb2e40996e634d8513e590a0..48f459941cae385e49af09410bb1812db5e6d971 100644
42+
--- a/ui/base/accelerators/media_keys_listener_linux.cc
43+
+++ b/ui/base/accelerators/media_keys_listener_linux.cc
44+
@@ -13,7 +13,7 @@ std::unique_ptr<MediaKeysListener> MediaKeysListener::Create(
45+
MediaKeysListener::Scope scope) {
46+
DCHECK(delegate);
47+
48+
- if (scope == Scope::kGlobal) {
49+
+ if (scope == Scope::kGlobal || scope == Scope::kGlobalRequiresAccessibility) {
50+
if (!SystemMediaControlsMediaKeysListener::has_instance()) {
51+
auto listener =
52+
std::make_unique<SystemMediaControlsMediaKeysListener>(delegate);
53+
diff --git a/ui/base/accelerators/media_keys_listener_win.cc b/ui/base/accelerators/media_keys_listener_win.cc
54+
index c50ea0ca2b8d612b96c0c822f5d36e9eb4ff861d..8b89fea7c09be007d8a020eb4d75f783c887f1a7 100644
55+
--- a/ui/base/accelerators/media_keys_listener_win.cc
56+
+++ b/ui/base/accelerators/media_keys_listener_win.cc
57+
@@ -14,7 +14,7 @@ std::unique_ptr<MediaKeysListener> MediaKeysListener::Create(
58+
MediaKeysListener::Scope scope) {
59+
DCHECK(delegate);
60+
61+
- if (scope == Scope::kGlobal) {
62+
+ if (scope == Scope::kGlobal || scope == Scope::kGlobalRequiresAccessibility) {
63+
// We should never have more than one global media keys listener.
64+
if (!SystemMediaControlsMediaKeysListener::has_instance() &&
65+
!GlobalMediaKeysListenerWin::has_instance()) {

0 commit comments

Comments
 (0)