From 478d76e92c3d9b01527fc7d017ae1c3370dd1761 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:28:59 +0000 Subject: [PATCH] fix: crash when calling moveTop() on modal children Co-authored-by: Shelley Vohr --- shell/browser/native_window_mac.mm | 7 ++++--- spec/api-browser-window-spec.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index af74a9e6686bf..87d6e5729e673 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -815,7 +815,7 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) { if (!webrtc::GetWindowOwnerPid(window_id)) return false; - if (!parent()) { + if (!parent() || is_modal()) { [window_ orderWindow:NSWindowAbove relativeTo:window_id]; } else { NSWindow* other_window = [NSApp windowWithWindowNumber:window_id]; @@ -826,10 +826,11 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) { } void NativeWindowMac::MoveTop() { - if (!parent()) + if (!parent() || is_modal()) { [window_ orderWindow:NSWindowAbove relativeTo:0]; - else + } else { ReorderChildWindowAbove(window_, nullptr); + } } void NativeWindowMac::SetResizable(bool resizable) { diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 820f1901993f0..70c63002762b1 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -1285,6 +1285,8 @@ describe('BrowserWindow module', () => { }); describe('BrowserWindow.moveTop()', () => { + afterEach(closeAllWindows); + it('should not steal focus', async () => { const posDelta = 50; const wShownInactive = once(w, 'show'); @@ -1326,6 +1328,15 @@ describe('BrowserWindow module', () => { await closeWindow(otherWindow, { assertNotWindows: false }); expect(BrowserWindow.getAllWindows()).to.have.lengthOf(1); }); + + it('should not crash when called on a modal child window', async () => { + const shown = once(w, 'show'); + w.show(); + await shown; + + const child = new BrowserWindow({ modal: true, parent: w }); + expect(() => { child.moveTop(); }).to.not.throw(); + }); }); ifdescribe(features.isDesktopCapturerEnabled())('BrowserWindow.moveAbove(mediaSourceId)', () => {