From 4397d8a02156a009d16d8b79796b1e54ca635624 Mon Sep 17 00:00:00 2001 From: Samson <16504129+sagudev@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:44:47 +0200 Subject: [PATCH] Add `dom.allow_scripts_to_close_windows` pref. (#33187) It's also present in firefox: https://searchfox.org/mozilla-central/search?q=allow_scripts_to_close_windows Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- components/config/prefs.rs | 1 + components/script/dom/window.rs | 5 ++++- resources/prefs.json | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/config/prefs.rs b/components/config/prefs.rs index 65d7b987253..9e2c161a32c 100644 --- a/components/config/prefs.rs +++ b/components/config/prefs.rs @@ -238,6 +238,7 @@ mod gen { enabled: bool, } }, + allow_scripts_to_close_windows: bool, canvas_capture: { enabled: bool, }, diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 08e1d5edf4f..5e7e1f8988c 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -60,6 +60,7 @@ use script_traits::{ use selectors::attr::CaseSensitivity; use servo_arc::Arc as ServoArc; use servo_atoms::Atom; +use servo_config::pref; use servo_geometry::{f32_rect_to_au_rect, MaxRect}; use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl}; use style::dom::OpaqueNode; @@ -757,7 +758,9 @@ impl WindowMethods for Window { let is_auxiliary = window_proxy.is_auxiliary(); // https://html.spec.whatwg.org/multipage/#script-closable - let is_script_closable = (self.is_top_level() && history_length == 1) || is_auxiliary; + let is_script_closable = (self.is_top_level() && history_length == 1) || + is_auxiliary || + pref!(dom.allow_scripts_to_close_windows); // TODO: rest of Step 3: // Is the incumbent settings object's responsible browsing context familiar with current? diff --git a/resources/prefs.json b/resources/prefs.json index 5f6d2f1fd16..bbef61ef194 100644 --- a/resources/prefs.json +++ b/resources/prefs.json @@ -1,6 +1,7 @@ { "devtools.server.enabled": false, "devtools.server.port": 0, + "dom.allow_scripts_to_close_windows": false, "dom.bluetooth.enabled": false, "dom.bluetooth.testing.enabled": false, "dom.canvas_capture.enabled": false,