From bf68405a2f2a1be6218076186118b16b74a687b5 Mon Sep 17 00:00:00 2001 From: Ben Russert Date: Fri, 16 Oct 2020 05:02:49 -0600 Subject: [PATCH] feat: support exclude from capture on Windows (#24274) * feat: support exclude from capture on Windows Check for WDA_EXCLUDEFROMCAPTURE support, and fallback to WDA_MONITOR. Windows versions that support exclude from capture will exclude the window entirely when `setContentProtection` is enabled similar to how Mac behaves. Fall back to `WDA_MONITOR` for windows verisions that do not support. This flag is mentioned at the very end of a Microsoft blog post here: https://blogs.windows.com/windowsdeveloper/2019/09/16/new-ways-to-do-screen-capture/ Use WDA_EXCLUDEFROMCAPTURE for content protection on windows Starting with Windows 10, version 2004 this will exclude a window similar to the expected behavior on mac. It is safe to use WDA_EXCLUDEFROMCAPTURE on older Windows versions, as it will still behave as if WDA_MONITOR is applied. https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/64#issuecomment-697074762 See the docs here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowdisplayaffinity * docs: update setContentProtection docs Update `setContentProtection` docs with `WDA_EXCLUDEFROMCAPTURE` info. This is to support screen capture fully excluding a particular window instead of showing it as a black screen. --- docs/api/browser-window.md | 4 +++- shell/browser/native_window_views.cc | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 1727e1f53a3c..c0c63673a32b 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1734,7 +1734,9 @@ events. Prevents the window contents from being captured by other apps. On macOS it sets the NSWindow's sharingType to NSWindowSharingNone. -On Windows it calls SetWindowDisplayAffinity with `WDA_MONITOR`. +On Windows it calls SetWindowDisplayAffinity with `WDA_EXCLUDEFROMCAPTURE`. +For Windows 10 version 2004 and up the window will be removed from capture entirely, +older Windows versions behave as if `WDA_MONITOR` is applied capturing a black window. #### `win.setFocusable(focusable)` _macOS_ _Windows_ diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 31fa04d56ffd..898c28d399f1 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1003,7 +1003,7 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) { void NativeWindowViews::SetContentProtection(bool enable) { #if defined(OS_WIN) - DWORD affinity = enable ? WDA_MONITOR : WDA_NONE; + DWORD affinity = enable ? WDA_EXCLUDEFROMCAPTURE : WDA_NONE; ::SetWindowDisplayAffinity(GetAcceleratedWidget(), affinity); #endif }