From d731a676f5c06544d9943e75212770b62e7a38fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 2 Mar 2020 23:50:44 +0300 Subject: [PATCH] feat: add disableDialogs option to WebPreferences (#22395) Allows to disable dialogs completely in a similar way of how safeDialogs option can be used. Overrides safeDialogs option. --- docs/api/browser-window.md | 2 ++ shell/browser/electron_javascript_dialog_manager.cc | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 8e3798806a64..338d83ddf0db 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -369,6 +369,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. consecutive dialog protection is triggered. If not defined the default message would be used, note that currently the default message is in English and not localized. + * `disableDialogs` Boolean (optional) - Whether to disable dialogs + completely. Overrides `safeDialogs`. Default is `false`. * `navigateOnDragDrop` Boolean (optional) - Whether dragging and dropping a file or link onto the page causes a navigation. Default is `false`. * `autoplayPolicy` String (optional) - Autoplay policy to apply to diff --git a/shell/browser/electron_javascript_dialog_manager.cc b/shell/browser/electron_javascript_dialog_manager.cc index 307ffd6b5e54..1aa1247d1b71 100644 --- a/shell/browser/electron_javascript_dialog_manager.cc +++ b/shell/browser/electron_javascript_dialog_manager.cc @@ -61,6 +61,12 @@ void ElectronJavaScriptDialogManager::RunJavaScriptDialog( return; } + auto* web_preferences = WebContentsPreferences::From(web_contents); + + if (web_preferences && web_preferences->IsEnabled("disableDialogs")) { + return std::move(callback).Run(false, base::string16()); + } + // No default button int default_id = -1; int cancel_id = 0; @@ -75,7 +81,6 @@ void ElectronJavaScriptDialogManager::RunJavaScriptDialog( origin_counts_[origin]++; - auto* web_preferences = WebContentsPreferences::From(web_contents); std::string checkbox; if (origin_counts_[origin] > 1 && web_preferences && web_preferences->IsEnabled("safeDialogs") &&