UI: Add the --disable-scripting option to disable scripting by default

This commit is contained in:
Tim Ledbetter 2024-09-04 07:13:40 +01:00 committed by Andreas Kling
parent 256b56dde8
commit 7c953552b7
Notes: github-actions[bot] 2024-09-07 09:38:29 +00:00
5 changed files with 22 additions and 3 deletions

View file

@ -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;

View file

@ -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

View file

@ -551,7 +551,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> 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();

View file

@ -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<StringView> debug_process;
Optional<StringView> 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),

View file

@ -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<ProcessType> debug_helper_process {};
Optional<ProcessType> profile_helper_process {};