From c65f41dfbd7671ab15b64f9bb6a2c3c30fd1da1f Mon Sep 17 00:00:00 2001 From: CezaryKulakowski <50166166+CezaryKulakowski@users.noreply.github.com> Date: Mon, 13 Apr 2020 10:25:55 +0200 Subject: [PATCH] fix: don't assign NSAlert to window which is not visible (#22672) * fix: don't assign NSAlert to window which is not visible Without this change it's possible to create message box which can't be dismissed on mac. * fixup! fix: don't assign NSAlert to window which is not visible * fixup! fix: don't assign NSAlert to window which is not visible --- docs/api/dialog.md | 1 + shell/browser/ui/message_box_mac.mm | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 678700a58600..c3903ce73af6 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -269,6 +269,7 @@ Shows a message box, it will block the process until the message box is closed. It returns the index of the clicked button. The `browserWindow` argument allows the dialog to attach itself to a parent window, making it modal. +If `browserWindow` is not shown dialog will not be attached to it. In such case It will be displayed as independed window. ### `dialog.showMessageBox([browserWindow, ]options)` diff --git a/shell/browser/ui/message_box_mac.mm b/shell/browser/ui/message_box_mac.mm index cdfc4797f990..63820e6e3167 100644 --- a/shell/browser/ui/message_box_mac.mm +++ b/shell/browser/ui/message_box_mac.mm @@ -97,8 +97,10 @@ int ShowMessageBoxSync(const MessageBoxSettings& settings) { NSAlert* alert = CreateNSAlert(settings); // Use runModal for synchronous alert without parent, since we don't have a - // window to wait for. - if (!settings.parent_window) + // window to wait for. Also use it when window is provided but it is not + // shown as it would be impossible to dismiss the alert if it is connected + // to invisible window (see #22671). + if (!settings.parent_window || !settings.parent_window->IsVisible()) return [[alert autorelease] runModal]; __block int ret_code = -1;