Skip to content

Commit

Permalink
fix: crash when calling moveTop() on modal children
Browse files Browse the repository at this point in the history
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Aug 16, 2023
1 parent ec4c609 commit 940096b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions shell/browser/native_window_mac.mm
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions spec/api-browser-window-spec.ts
Expand Up @@ -921,6 +921,8 @@ describe('BrowserWindow module', () => {
});

describe('BrowserWindow.moveTop()', () => {
afterEach(closeAllWindows);

it('should not steal focus', async () => {
const posDelta = 50;
const wShownInactive = emittedOnce(w, 'show');
Expand Down Expand Up @@ -962,6 +964,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)', () => {
Expand Down

0 comments on commit 940096b

Please sign in to comment.