Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when calling BrowserWindow.moveTop() on modal children #39528

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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');
Expand Down Expand Up @@ -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)', () => {
Expand Down