fix: hide content protected windows during screen capture with ScreenCaptureKitMac (#34362)

fix: hide content protected windows during screen capture
This commit is contained in:
Samuel Attard 2022-05-30 05:13:48 -07:00 committed by GitHub
parent 34a9268e97
commit fd88908457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -110,3 +110,4 @@ introduce_ozoneplatform_electron_can_call_x11_property.patch
make_gtk_getlibgtk_public.patch make_gtk_getlibgtk_public.patch
build_disable_print_content_analysis.patch build_disable_print_content_analysis.patch
custom_protocols_plzserviceworker.patch custom_protocols_plzserviceworker.patch
feat_filter_out_non-shareable_windows_in_the_current_application_in.patch

View file

@ -0,0 +1,29 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@salesforce.com>
Date: Thu, 26 May 2022 15:38:32 -0700
Subject: feat: filter out non-shareable windows in the current application in
ScreenCaptureKitDevice
This patch ensures that windows protected via win.setContentProtection(true) do not appear in full display captures via desktopCapturer. This patch could be upstreamed but as the check is limited to in-process windows it doesn't make a lot of sense for Chromium itself. This patch currently has a limitation that it only function for windows created / protected BEFORE the stream is started. There is theoretical future work we can do via polling / observers to automatically update the SCContentFilter when new windows are made but for now this will solve 99+% of the problem and folks can re-order their logic a bit to get it working for their use cases.
diff --git a/content/browser/media/capture/screen_capture_kit_device_mac.mm b/content/browser/media/capture/screen_capture_kit_device_mac.mm
index 50a779be2e7d3a95496e2791187a6b56266786eb..5876babb99b5e98b151e13e4091305763a417a9e 100644
--- a/content/browser/media/capture/screen_capture_kit_device_mac.mm
+++ b/content/browser/media/capture/screen_capture_kit_device_mac.mm
@@ -100,7 +100,15 @@ void OnShareableContentCreated(
case DesktopMediaID::TYPE_SCREEN:
for (SCDisplay* display : [content displays]) {
if (source_.id == [display displayID]) {
- NSArray<SCWindow*>* exclude_windows = nil;
+ NSArray<NSWindow*>* exclude_ns_windows = [[[NSApplication sharedApplication] windows] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSWindow* win, NSDictionary *bindings) {
+ return [win sharingType] == NSWindowSharingNone;
+ }]];
+ NSArray<SCWindow*>* exclude_windows = [[content windows] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(SCWindow* win, NSDictionary *bindings) {
+ for (NSWindow* excluded : exclude_ns_windows) {
+ if ((CGWindowID)[excluded windowNumber] == [win windowID]) return true;
+ }
+ return false;
+ }]];
filter.reset([[SCContentFilter alloc]
initWithDisplay:display
excludingWindows:exclude_windows]);