LibWebView+UI: Migrate Ladybird's command line flags to LibWebView

Currently, if we want to add a new e.g. WebContent command line option,
we have to add it to all of Qt, AppKit, and headless-browser. (Or worse,
we only add it to one of these, and we have feature disparity).

To prevent this, this moves command line flags to WebView::Application.
The flags are assigned to ChromeOptions and WebContentOptions structs.
Each chrome can still add its platform-specific options; for example,
the Qt chrome has a flag to enable Qt networking.

There should be no behavior change here, other than that AppKit will now
support command line flags that were previously only supported by Qt.
This commit is contained in:
Timothy Flynn 2024-07-30 14:01:05 -04:00 committed by Andreas Kling
commit 5f8d852dae
Notes: github-actions[bot] 2024-08-01 09:39:41 +00:00
35 changed files with 427 additions and 440 deletions

View file

@ -5,15 +5,17 @@
*/
#include <AK/Debug.h>
#include <LibCore/ArgsParser.h>
#include <LibImageDecoderClient/Client.h>
#include <LibWebView/Application.h>
#include <LibWebView/URL.h>
#include <LibWebView/WebContentClient.h>
namespace WebView {
Application* Application::s_the = nullptr;
Application::Application(int, char**)
Application::Application()
{
VERIFY(!s_the);
s_the = this;
@ -28,7 +30,70 @@ Application::~Application()
s_the = nullptr;
}
int Application::exec()
void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_page_url)
{
Vector<ByteString> raw_urls;
Vector<ByteString> certificates;
bool new_window = false;
bool force_new_process = false;
bool allow_popups = false;
bool disable_sql_database = false;
Optional<StringView> webdriver_content_ipc_path;
bool enable_callgrind_profiling = false;
bool debug_web_content = false;
bool log_all_js_exceptions = false;
bool enable_idl_tracing = false;
bool enable_http_cache = false;
bool expose_internals_object = false;
Core::ArgsParser args_parser;
args_parser.set_general_help("The Ladybird web browser :^)");
args_parser.add_positional_argument(raw_urls, "URLs to open", "url", Core::ArgsParser::Required::No);
args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
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_sql_database, "Disable SQL database", "disable-sql-database");
args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path", Core::ArgsParser::OptionHideMode::CommandLineAndMarkdown);
args_parser.add_option(enable_callgrind_profiling, "Enable Callgrind profiling", "enable-callgrind-profiling", 'P');
args_parser.add_option(debug_web_content, "Wait for debugger to attach to WebContent", "debug-web-content");
args_parser.add_option(log_all_js_exceptions, "Log all JavaScript exceptions", "log-all-js-exceptions");
args_parser.add_option(enable_idl_tracing, "Enable IDL tracing", "enable-idl-tracing");
args_parser.add_option(enable_http_cache, "Enable HTTP cache", "enable-http-cache");
args_parser.add_option(expose_internals_object, "Expose internals object", "expose-internals-object");
create_platform_arguments(args_parser);
args_parser.parse(arguments);
m_chrome_options = {
.urls = sanitize_urls(raw_urls, new_tab_page_url),
.raw_urls = move(raw_urls),
.new_tab_page_url = move(new_tab_page_url),
.certificates = move(certificates),
.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_sql_database = disable_sql_database ? DisableSQLDatabase::Yes : DisableSQLDatabase::No,
};
if (webdriver_content_ipc_path.has_value())
m_chrome_options.webdriver_content_ipc_path = *webdriver_content_ipc_path;
m_web_content_options = {
.command_line = MUST(String::join(' ', arguments.strings)),
.executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))),
.enable_callgrind_profiling = enable_callgrind_profiling ? EnableCallgrindProfiling::Yes : EnableCallgrindProfiling::No,
.wait_for_debugger = debug_web_content ? WaitForDebugger::Yes : WaitForDebugger::No,
.log_all_js_exceptions = log_all_js_exceptions ? LogAllJSExceptions::Yes : LogAllJSExceptions::No,
.enable_idl_tracing = enable_idl_tracing ? EnableIDLTracing::Yes : EnableIDLTracing::No,
.enable_http_cache = enable_http_cache ? EnableHTTPCache::Yes : EnableHTTPCache::No,
.expose_internals_object = expose_internals_object ? ExposeInternalsObject::Yes : ExposeInternalsObject::No,
};
create_platform_options(m_chrome_options, m_web_content_options);
}
int Application::execute()
{
int ret = m_event_loop.exec();
m_in_shutdown = true;