Commit 83c2b507 authored by Gary Kacmarcik's avatar Gary Kacmarcik Committed by Commit Bot

[Chromoting] Update the heuristic that checks if Screen Capture is available

Change-Id: I453e48c84bba191a63f524d81a3817c3c4f5a961
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1994673
Auto-Submit: Gary Kacmarcik <garykac@chromium.org>
Commit-Queue: Lambros Lambrou <lambroslambrou@chromium.org>
Reviewed-by: default avatarLambros Lambrou <lambroslambrou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730239}
parent fd84ab8a
...@@ -118,24 +118,42 @@ bool CanInjectInput() { ...@@ -118,24 +118,42 @@ bool CanInjectInput() {
} }
// Heuristic to check screen capture permission. See http://crbug.com/993692 // Heuristic to check screen capture permission. See http://crbug.com/993692
// Screen capture is considered allowed if the name of at least one normal
// or dock window running on another process is visible.
// Copied from // Copied from
// chrome/browser/media/webrtc/system_media_capture_permissions_mac.mm // chrome/browser/media/webrtc/system_media_capture_permissions_mac.mm
// TODO(garykac) Move webrtc version where it can be shared. // TODO(garykac) Move webrtc version where it can be shared.
bool CanRecordScreen() { bool CanRecordScreen() {
if (@available(macOS 10.15, *)) { if (@available(macOS 10.15, *)) {
base::ScopedCFTypeRef<CFArrayRef> window_list(CGWindowListCopyWindowInfo( base::ScopedCFTypeRef<CFArrayRef> window_list(
kCGWindowListOptionOnScreenOnly, kCGNullWindowID)); CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
NSUInteger num_windows = CFArrayGetCount(window_list); int current_pid = [[NSProcessInfo processInfo] processIdentifier];
NSUInteger num_windows_with_name = 0; for (NSDictionary* window in base::mac::CFToNSCast(window_list.get())) {
for (NSDictionary* dict in base::mac::CFToNSCast(window_list.get())) { NSNumber* window_pid =
if ([dict objectForKey:base::mac::CFToNSCast(kCGWindowName)]) { [window objectForKey:base::mac::CFToNSCast(kCGWindowOwnerPID)];
num_windows_with_name++; if (!window_pid || [window_pid integerValue] == current_pid)
} else { continue;
// No kCGWindowName detected implies no permission.
break; NSString* window_name =
[window objectForKey:base::mac::CFToNSCast(kCGWindowName)];
if (!window_name)
continue;
NSNumber* layer =
[window objectForKey:base::mac::CFToNSCast(kCGWindowLayer)];
if (!layer)
continue;
NSInteger layer_integer = [layer integerValue];
if (layer_integer == CGWindowLevelForKey(kCGNormalWindowLevelKey) ||
layer_integer == CGWindowLevelForKey(kCGDockWindowLevelKey)) {
return true;
} }
return false;
} }
return num_windows == num_windows_with_name;
// Screen capture is always allowed in older macOS versions.
return true;
} }
// Previous to 10.15, screen capture was always allowed. // Previous to 10.15, screen capture was always allowed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment