From 66c1cabe151fafe65b552524882ba0f096601be4 Mon Sep 17 00:00:00 2001 From: palashgo Date: Mon, 10 Jun 2024 17:04:04 +0000 Subject: [PATCH] Bug 1772233: Fix macOS screen recording permission check, skip StatusIndicator window. r=jib,spohl Differential Revision: https://phabricator.services.mozilla.com/D208291 --- widget/cocoa/nsCocoaUtils.mm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/widget/cocoa/nsCocoaUtils.mm b/widget/cocoa/nsCocoaUtils.mm index 769eb05a85fd..3919bd383f96 100644 --- a/widget/cocoa/nsCocoaUtils.mm +++ b/widget/cocoa/nsCocoaUtils.mm @@ -935,12 +935,11 @@ struct KeyConversionData { static const KeyConversionData gKeyConversions[] = { -#define KEYCODE_ENTRY(aStr, aCode) \ - { #aStr, sizeof(#aStr) - 1, NS_##aStr, aCode } +#define KEYCODE_ENTRY(aStr, aCode) {#aStr, sizeof(#aStr) - 1, NS_##aStr, aCode} // Some keycodes may have different name in KeyboardEvent from its key name. #define KEYCODE_ENTRY2(aStr, aNSName, aCode) \ - { #aStr, sizeof(#aStr) - 1, NS_##aNSName, aCode } + {#aStr, sizeof(#aStr) - 1, NS_##aNSName, aCode} KEYCODE_ENTRY(VK_CANCEL, 0x001B), KEYCODE_ENTRY(VK_DELETE, NSDeleteFunctionKey), @@ -1387,6 +1386,19 @@ nsresult nsCocoaUtils::GetScreenCapturePermissionState( continue; } + // macOS versions 12.2 (Monterey) or later have a status indicator when the + // microphone is in use (an orange dot). This is implemented as a window + // owned by the window server process. The permission check logic queries + // window server for all windows and assumes it has the required permission + // if it can read any window name that is at dock or normal level. + // The StatusIndicator window is an exception and needs to be skipped + // because it is owned by window server process and therefore when querying + // the window server, the name is always readable. + if (kCFCompareEqualTo == + CFStringCompare(windowName, CFSTR("StatusIndicator"), 0)) { + continue; + } + CFNumberRef windowLayerRef = reinterpret_cast( CFDictionaryGetValue(windowDict, kCGWindowLayer)); int32_t windowLayer;