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

fix: crash when calling moveTop() on modal children

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2023-08-16 16:00:49 +02:00
committed by GitHub
parent e033c294fc
commit 0f817ef646
2 changed files with 15 additions and 3 deletions

View File

@@ -815,7 +815,7 @@ bool NativeWindowMac::MoveAbove(const std::string& sourceId) {
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 @@ bool NativeWindowMac::MoveAbove(const std::string& sourceId) {
}
void NativeWindowMac::MoveTop() {
if (!parent())
if (!parent() || is_modal()) {
[window_ orderWindow:NSWindowAbove relativeTo:0];
else
} else {
ReorderChildWindowAbove(window_, nullptr);
}
}
void NativeWindowMac::SetResizable(bool resizable) {

View File

@@ -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)', () => {