2022-07-03 18:44:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2022-07-03 19:26:51 +00:00
|
|
|
#include "BrowserWindow.h"
|
2022-07-14 03:41:13 +00:00
|
|
|
#include "Settings.h"
|
2022-10-05 13:23:41 +00:00
|
|
|
#include "Utilities.h"
|
2023-01-27 09:41:24 +00:00
|
|
|
#include "WebContentView.h"
|
2022-12-05 18:09:42 +00:00
|
|
|
#include <Browser/CookieJar.h>
|
|
|
|
#include <Browser/Database.h>
|
2022-07-03 18:36:07 +00:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2022-10-05 13:23:41 +00:00
|
|
|
#include <LibCore/EventLoop.h>
|
2022-10-09 17:32:45 +00:00
|
|
|
#include <LibCore/File.h>
|
2022-10-24 09:18:22 +00:00
|
|
|
#include <LibCore/Stream.h>
|
|
|
|
#include <LibCore/System.h>
|
2022-10-05 13:23:41 +00:00
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
2022-07-03 18:36:07 +00:00
|
|
|
#include <LibMain/Main.h>
|
2022-12-05 18:09:42 +00:00
|
|
|
#include <LibSQL/SQLClient.h>
|
2022-07-03 18:36:07 +00:00
|
|
|
#include <QApplication>
|
|
|
|
|
2022-07-14 03:41:13 +00:00
|
|
|
Browser::Settings* s_settings;
|
2022-07-03 18:36:07 +00:00
|
|
|
|
2022-10-24 09:18:22 +00:00
|
|
|
static ErrorOr<void> handle_attached_debugger()
|
|
|
|
{
|
|
|
|
#ifdef AK_OS_LINUX
|
|
|
|
// Let's ignore SIGINT if we're being debugged because GDB
|
|
|
|
// incorrectly forwards the signal to us even when it's set to
|
|
|
|
// "nopass". See https://sourceware.org/bugzilla/show_bug.cgi?id=9425
|
|
|
|
// for details.
|
|
|
|
auto unbuffered_status_file = TRY(Core::Stream::File::open("/proc/self/status"sv, Core::Stream::OpenMode::Read));
|
|
|
|
auto status_file = TRY(Core::Stream::BufferedFile::create(move(unbuffered_status_file)));
|
|
|
|
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
|
|
|
|
while (TRY(status_file->can_read_line())) {
|
|
|
|
auto line = TRY(status_file->read_line(buffer));
|
|
|
|
auto const parts = line.split_view(':');
|
|
|
|
if (parts.size() < 2 || parts[0] != "TracerPid"sv)
|
|
|
|
continue;
|
|
|
|
auto tracer_pid = parts[1].to_uint<u32>();
|
|
|
|
if (tracer_pid != 0UL) {
|
|
|
|
dbgln("Debugger is attached, ignoring SIGINT");
|
|
|
|
TRY(Core::System::signal(SIGINT, SIG_IGN));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-07-03 18:36:07 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
|
|
{
|
2022-10-05 13:23:41 +00:00
|
|
|
// NOTE: This is only used for the Core::Socket inside the IPC connections.
|
|
|
|
// FIXME: Refactor things so we can get rid of this somehow.
|
|
|
|
Core::EventLoop event_loop;
|
|
|
|
|
2022-10-24 09:18:22 +00:00
|
|
|
TRY(handle_attached_debugger());
|
|
|
|
|
2022-10-05 13:23:41 +00:00
|
|
|
QApplication app(arguments.argc, arguments.argv);
|
2022-07-03 18:36:07 +00:00
|
|
|
|
2022-10-07 23:08:29 +00:00
|
|
|
platform_init();
|
|
|
|
|
|
|
|
// NOTE: We only instantiate this to ensure that Gfx::FontDatabase has its default queries initialized.
|
|
|
|
Gfx::FontDatabase::set_default_font_query("Katica 10 400 0");
|
|
|
|
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");
|
|
|
|
|
2022-10-09 17:32:45 +00:00
|
|
|
StringView raw_url;
|
2022-12-15 14:18:52 +00:00
|
|
|
StringView webdriver_content_ipc_path;
|
2023-01-31 13:42:00 +00:00
|
|
|
bool dump_layout_tree = false;
|
2022-11-14 16:08:44 +00:00
|
|
|
|
2022-07-03 18:36:07 +00:00
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
args_parser.set_general_help("The Ladybird web browser :^)");
|
2022-10-09 17:32:45 +00:00
|
|
|
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
|
2022-12-15 14:18:52 +00:00
|
|
|
args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path");
|
2023-01-27 09:41:24 +00:00
|
|
|
args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd');
|
2022-07-03 18:36:07 +00:00
|
|
|
args_parser.parse(arguments);
|
|
|
|
|
2023-01-27 09:41:24 +00:00
|
|
|
URL url = raw_url;
|
|
|
|
if (Core::File::exists(raw_url))
|
|
|
|
url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url));
|
|
|
|
else if (!url.is_valid())
|
|
|
|
url = DeprecatedString::formatted("http://{}", raw_url);
|
|
|
|
|
|
|
|
if (dump_layout_tree) {
|
|
|
|
WebContentView view({});
|
|
|
|
view.on_load_finish = [&](auto&) {
|
|
|
|
auto dump = view.dump_layout_tree().release_value_but_fixme_should_propagate_errors();
|
|
|
|
outln("{}", dump);
|
2023-01-29 00:05:20 +00:00
|
|
|
fflush(stdout);
|
2023-01-31 13:46:12 +00:00
|
|
|
|
|
|
|
event_loop.quit(0);
|
|
|
|
app.quit();
|
2023-01-27 09:41:24 +00:00
|
|
|
};
|
2023-01-31 13:46:12 +00:00
|
|
|
|
2023-01-27 09:41:24 +00:00
|
|
|
view.load(url);
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|
2023-01-29 04:20:20 +00:00
|
|
|
auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client("./SQLServer/SQLServer"sv));
|
|
|
|
auto database = TRY(Browser::Database::create(move(sql_client)));
|
|
|
|
|
2022-12-05 18:09:42 +00:00
|
|
|
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
|
|
|
|
|
2022-12-15 14:18:52 +00:00
|
|
|
BrowserWindow window(cookie_jar, webdriver_content_ipc_path);
|
2022-10-01 18:46:24 +00:00
|
|
|
s_settings = new Browser::Settings(&window);
|
2022-07-03 18:36:07 +00:00
|
|
|
window.setWindowTitle("Ladybird");
|
|
|
|
window.resize(800, 600);
|
|
|
|
window.show();
|
|
|
|
|
2022-10-09 17:32:45 +00:00
|
|
|
if (url.is_valid())
|
2022-07-03 19:26:51 +00:00
|
|
|
window.view().load(url);
|
2022-07-03 18:36:07 +00:00
|
|
|
|
2022-09-07 18:33:15 +00:00
|
|
|
return app.exec();
|
2022-07-03 18:36:07 +00:00
|
|
|
}
|