From a0633d9e2507d7dd263edd31d1b1968f211660ea Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 5 Jun 2025 15:47:23 +0200 Subject: [PATCH] feat: expose `win.isContentProtected()` (#47311) * feat: expose win.isContentProtected() Co-authored-by: Shelley Vohr * chore: remove stray _isContentProtected Co-authored-by: Shelley Vohr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- docs/api/base-window.md | 4 ++++ docs/api/browser-window.md | 4 ++++ shell/browser/api/electron_api_base_window.cc | 2 +- spec/api-browser-window-spec.ts | 9 +++------ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/api/base-window.md b/docs/api/base-window.md index 52e6deb288f8..98909de846e2 100644 --- a/docs/api/base-window.md +++ b/docs/api/base-window.md @@ -1346,6 +1346,10 @@ 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.isContentProtected()` _macOS_ _Windows_ + +Returns `boolean` - whether or not content protection is currently enabled. + #### `win.setFocusable(focusable)` _macOS_ _Windows_ * `focusable` boolean diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index e61faa458fe2..78997aabd44f 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1528,6 +1528,10 @@ 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.isContentProtected()` _macOS_ _Windows_ + +Returns `boolean` - whether or not content protection is currently enabled. + #### `win.setFocusable(focusable)` _macOS_ _Windows_ * `focusable` boolean diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index 773d44b7f78c..81ada7acf929 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -1261,7 +1261,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate, .SetMethod("isDocumentEdited", &BaseWindow::IsDocumentEdited) .SetMethod("setIgnoreMouseEvents", &BaseWindow::SetIgnoreMouseEvents) .SetMethod("setContentProtection", &BaseWindow::SetContentProtection) - .SetMethod("_isContentProtected", &BaseWindow::IsContentProtected) + .SetMethod("isContentProtected", &BaseWindow::IsContentProtected) .SetMethod("setFocusable", &BaseWindow::SetFocusable) .SetMethod("isFocusable", &BaseWindow::IsFocusable) .SetMethod("setMenu", &BaseWindow::SetMenu) diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 36004ef59ca7..5cd300f481c4 100755 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -300,8 +300,7 @@ describe('BrowserWindow module', () => { afterEach(closeAllWindows); it('can set content protection', async () => { const w = new BrowserWindow({ show: false }); - // @ts-expect-error This is a private API - expect(w._isContentProtected()).to.equal(false); + expect(w.isContentProtected()).to.equal(false); const shown = once(w, 'show'); @@ -309,8 +308,7 @@ describe('BrowserWindow module', () => { await shown; w.setContentProtection(true); - // @ts-expect-error This is a private API - expect(w._isContentProtected()).to.equal(true); + expect(w.isContentProtected()).to.equal(true); }); it('does not remove content protection after the window is hidden and shown', async () => { @@ -329,8 +327,7 @@ describe('BrowserWindow module', () => { w.show(); await shown; - // @ts-expect-error This is a private API - expect(w._isContentProtected()).to.equal(true); + expect(w.isContentProtected()).to.equal(true); }); });