From 7c953552b7d2b7931bcd95dc37d337fb2c13b899 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 4 Sep 2024 07:13:40 +0100 Subject: [PATCH] UI: Add the `--disable-scripting` option to disable scripting by default --- Ladybird/AppKit/UI/TabController.h | 1 + Ladybird/AppKit/UI/TabController.mm | 13 +++++++++++-- Ladybird/Qt/BrowserWindow.cpp | 2 +- Userland/Libraries/LibWebView/Application.cpp | 3 +++ Userland/Libraries/LibWebView/Options.h | 6 ++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Ladybird/AppKit/UI/TabController.h b/Ladybird/AppKit/UI/TabController.h index fb13e13998d..0ddb2e7afba 100644 --- a/Ladybird/AppKit/UI/TabController.h +++ b/Ladybird/AppKit/UI/TabController.h @@ -43,6 +43,7 @@ struct TabSettings { - (void)clearHistory; - (void)setPopupBlocking:(BOOL)block_popups; +- (void)setScripting:(BOOL)enabled; - (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument; - (void)focusLocationToolbarItem; diff --git a/Ladybird/AppKit/UI/TabController.mm b/Ladybird/AppKit/UI/TabController.mm index 2888e187979..ea6cb186a38 100644 --- a/Ladybird/AppKit/UI/TabController.mm +++ b/Ladybird/AppKit/UI/TabController.mm @@ -92,7 +92,10 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde [self.toolbar setAllowsUserCustomization:NO]; [self.toolbar setSizeMode:NSToolbarSizeModeRegular]; - m_settings = { .block_popups = WebView::Application::chrome_options().allow_popups == WebView::AllowPopups::Yes ? NO : YES }; + m_settings = { + .block_popups = WebView::Application::chrome_options().allow_popups == WebView::AllowPopups::Yes ? NO : YES, + .scripting_enabled = WebView::Application::chrome_options().disable_scripting == WebView::DisableScripting::Yes ? NO : YES, + }; if (auto const& user_agent_preset = WebView::Application::web_content_options().user_agent_preset; user_agent_preset.has_value()) m_settings.user_agent_name = *user_agent_preset; @@ -142,6 +145,7 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde - (void)onCreateNewTab { [self setPopupBlocking:m_settings.block_popups]; + [self setScripting:m_settings.scripting_enabled]; } - (void)zoomIn:(id)sender @@ -347,7 +351,12 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde - (void)toggleScripting:(id)sender { m_settings.scripting_enabled = !m_settings.scripting_enabled; - [self debugRequest:"scripting" argument:m_settings.scripting_enabled ? "on" : "off"]; + [self setScripting:m_settings.scripting_enabled]; +} + +- (void)setScripting:(BOOL)enabled +{ + [self debugRequest:"scripting" argument:enabled ? "on" : "off"]; } - (void)togglePopupBlocking:(id)sender diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index ea474f70d0b..5cd0a5d6c5f 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -551,7 +551,7 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, IsPopupWindow m_enable_scripting_action = new QAction("Enable Scripting", this); m_enable_scripting_action->setCheckable(true); - m_enable_scripting_action->setChecked(true); + m_enable_scripting_action->setChecked(WebView::Application::chrome_options().disable_scripting == WebView::DisableScripting::No); debug_menu->addAction(m_enable_scripting_action); QObject::connect(m_enable_scripting_action, &QAction::triggered, this, [this] { bool state = m_enable_scripting_action->isChecked(); diff --git a/Userland/Libraries/LibWebView/Application.cpp b/Userland/Libraries/LibWebView/Application.cpp index a94ebebef96..ba7ec3d74dd 100644 --- a/Userland/Libraries/LibWebView/Application.cpp +++ b/Userland/Libraries/LibWebView/Application.cpp @@ -60,6 +60,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_ bool new_window = false; bool force_new_process = false; bool allow_popups = false; + bool disable_scripting = false; bool disable_sql_database = false; Optional debug_process; Optional profile_process; @@ -79,6 +80,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_ args_parser.add_option(new_window, "Force opening in a new window", "new-window", 'n'); args_parser.add_option(force_new_process, "Force creation of new browser/chrome process", "force-new-process"); args_parser.add_option(allow_popups, "Disable popup blocking by default", "allow-popups"); + args_parser.add_option(disable_scripting, "Disable scripting by default", "disable-scripting"); args_parser.add_option(disable_sql_database, "Disable SQL database", "disable-sql-database"); args_parser.add_option(debug_process, "Wait for a debugger to attach to the given process name (WebContent, RequestServer, etc.)", "debug-process", 0, "process-name"); args_parser.add_option(profile_process, "Enable callgrind profiling of the given process name (WebContent, RequestServer, etc.)", "profile-process", 0, "process-name"); @@ -119,6 +121,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_ .new_window = new_window ? NewWindow::Yes : NewWindow::No, .force_new_process = force_new_process ? ForceNewProcess::Yes : ForceNewProcess::No, .allow_popups = allow_popups ? AllowPopups::Yes : AllowPopups::No, + .disable_scripting = disable_scripting ? DisableScripting::Yes : DisableScripting::No, .disable_sql_database = disable_sql_database ? DisableSQLDatabase::Yes : DisableSQLDatabase::No, .debug_helper_process = move(debug_process_type), .profile_helper_process = move(profile_process_type), diff --git a/Userland/Libraries/LibWebView/Options.h b/Userland/Libraries/LibWebView/Options.h index 624331f8a21..b5c9803f3b5 100644 --- a/Userland/Libraries/LibWebView/Options.h +++ b/Userland/Libraries/LibWebView/Options.h @@ -30,6 +30,11 @@ enum class AllowPopups { Yes, }; +enum class DisableScripting { + No, + Yes, +}; + enum class DisableSQLDatabase { No, Yes, @@ -43,6 +48,7 @@ struct ChromeOptions { NewWindow new_window { NewWindow::No }; ForceNewProcess force_new_process { ForceNewProcess::No }; AllowPopups allow_popups { AllowPopups::No }; + DisableScripting disable_scripting { DisableScripting::No }; DisableSQLDatabase disable_sql_database { DisableSQLDatabase::No }; Optional debug_helper_process {}; Optional profile_helper_process {};