Skip to content

Commit

Permalink
feat: support exclude from capture on Windows (#24274)
Browse files Browse the repository at this point in the history
* 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.
microsoft/Windows.UI.Composition-Win32-Samples#64 (comment)

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.
  • Loading branch information
BenRussert committed Oct 16, 2020
1 parent 55fdc17 commit bf68405
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit bf68405

Please sign in to comment.