Ladybird: Move Qt-specific classes and functions to a Qt subdirectory

This will help a lot with developing chromes for different UI frameworks
where we can see which helper classes and processes are really using Qt
vs just using it to get at helper data.

As a bonus, remove Qt dependency from WebDriver.
This commit is contained in:
Andrew Kaster 2023-08-05 10:42:26 -06:00 committed by Andrew Kaster
parent ccaa423372
commit 391beef707
Notes: sideshowbarker 2024-07-17 08:59:18 +09:00
53 changed files with 160 additions and 157 deletions

View File

@ -81,22 +81,23 @@ set(SOURCES
${BROWSER_SOURCE_DIR}/CookieJar.cpp
${BROWSER_SOURCE_DIR}/Database.cpp
${BROWSER_SOURCE_DIR}/History.cpp
BrowserWindow.cpp
ConsoleWidget.cpp
EventLoopImplementationQt.cpp
EventLoopImplementationQtEventTarget.cpp
HelperProcess.cpp
InspectorWidget.cpp
LocationEdit.cpp
ModelTranslator.cpp
Settings.cpp
SettingsDialog.cpp
Tab.cpp
TVGIconEngine.cpp
Utilities.cpp
WebContentView.cpp
ladybird.qrc
main.cpp
Qt/BrowserWindow.cpp
Qt/ConsoleWidget.cpp
Qt/EventLoopImplementationQt.cpp
Qt/EventLoopImplementationQtEventTarget.cpp
Qt/InspectorWidget.cpp
Qt/LocationEdit.cpp
Qt/ModelTranslator.cpp
Qt/Settings.cpp
Qt/SettingsDialog.cpp
Qt/Tab.cpp
Qt/TVGIconEngine.cpp
Qt/StringUtils.cpp
Qt/WebContentView.cpp
Qt/ladybird.qrc
Qt/main.cpp
)
qt_add_executable(ladybird ${SOURCES})
@ -107,14 +108,14 @@ target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/)
target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Applications/)
target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services/)
qt_add_executable(headless-browser
add_executable(headless-browser
${SERENITY_SOURCE_DIR}/Userland/Utilities/headless-browser.cpp
${SERENITY_SOURCE_DIR}/Userland/Services/WebContent/WebDriverConnection.cpp
HelperProcess.cpp
Utilities.cpp)
target_include_directories(headless-browser PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(headless-browser PRIVATE Qt::Core LibWeb LibWebView LibWebSocket LibCrypto LibFileSystem LibGemini LibHTTP LibJS LibGfx LibMain LibTLS LibIPC LibDiff LibProtocol)
target_link_libraries(headless-browser PRIVATE LibWeb LibWebView LibWebSocket LibCrypto LibFileSystem LibGemini LibHTTP LibJS LibGfx LibMain LibTLS LibIPC LibDiff LibProtocol)
set_target_properties(ladybird PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER org.SerenityOS.Ladybird

View File

@ -11,10 +11,11 @@
#include "ConsoleWidget.h"
#include "Settings.h"
#include "SettingsDialog.h"
#include "Utilities.h"
#include "StringUtils.h"
#include "WebContentView.h"
#include <AK/TypeCasts.h>
#include <Browser/CookieJar.h>
#include <Ladybird/Utilities.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <QAction>
@ -25,8 +26,6 @@
#include <QPlainTextEdit>
#include <QTabBar>
extern DeprecatedString s_serenity_resource_root;
namespace Ladybird {
extern Settings* s_settings;

View File

@ -8,7 +8,7 @@
*/
#include "ConsoleWidget.h"
#include "Utilities.h"
#include "StringUtils.h"
#include "WebContentView.h"
#include <AK/StringBuilder.h>
#include <LibJS/MarkupGenerator.h>

View File

@ -5,7 +5,7 @@
*/
#include "LocationEdit.h"
#include "Utilities.h"
#include "StringUtils.h"
#include <AK/URL.h>
#include <QCoreApplication>
#include <QPalette>

View File

@ -5,7 +5,7 @@
*/
#include "ModelTranslator.h"
#include "Utilities.h"
#include "StringUtils.h"
#include <QIcon>
namespace Ladybird {

View File

@ -5,9 +5,10 @@
*/
#include "Settings.h"
#include "Utilities.h"
#include "StringUtils.h"
#include <AK/URL.h>
#include <BrowserSettings/Defaults.h>
#include <Ladybird/Utilities.h>
namespace Ladybird {

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "StringUtils.h"
AK::DeprecatedString ak_deprecated_string_from_qstring(QString const& qstring)
{
return AK::DeprecatedString(qstring.toUtf8().data());
}
ErrorOr<String> ak_string_from_qstring(QString const& qstring)
{
return String::from_utf8(StringView(qstring.toUtf8().data(), qstring.size()));
}
QString qstring_from_ak_deprecated_string(AK::DeprecatedString const& ak_deprecated_string)
{
return QString::fromUtf8(ak_deprecated_string.characters(), ak_deprecated_string.length());
}
QString qstring_from_ak_string(String const& ak_string)
{
auto view = ak_string.bytes_as_string_view();
return QString::fromUtf8(view.characters_without_null_termination(), view.length());
}

17
Ladybird/Qt/StringUtils.h Normal file
View File

@ -0,0 +1,17 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/String.h>
#include <QString>
AK::DeprecatedString ak_deprecated_string_from_qstring(QString const&);
ErrorOr<String> ak_string_from_qstring(QString const&);
QString qstring_from_ak_deprecated_string(AK::DeprecatedString const&);
QString qstring_from_ak_string(String const&);

View File

@ -5,7 +5,7 @@
*/
#include "TVGIconEngine.h"
#include "Utilities.h"
#include "StringUtils.h"
#include <AK/MemoryStream.h>
#include <AK/String.h>
#include <LibGfx/Painter.h>

View File

@ -9,8 +9,8 @@
#include "ConsoleWidget.h"
#include "InspectorWidget.h"
#include "Settings.h"
#include "StringUtils.h"
#include "TVGIconEngine.h"
#include "Utilities.h"
#include <Browser/History.h>
#include <LibGfx/ImageFormats/BMPWriter.h>
#include <LibGfx/Painter.h>

View File

@ -6,8 +6,7 @@
*/
#include "WebContentView.h"
#include "HelperProcess.h"
#include "Utilities.h"
#include "StringUtils.h"
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <AK/Format.h>
@ -17,6 +16,8 @@
#include <AK/StringBuilder.h>
#include <AK/Types.h>
#include <Kernel/API/KeyCode.h>
#include <Ladybird/HelperProcess.h>
#include <Ladybird/Utilities.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/System.h>

View File

@ -7,12 +7,12 @@
#pragma once
#include "Types.h"
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/URL.h>
#include <Ladybird/Types.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Rect.h>
#include <LibGfx/StandardCursor.h>

View File

@ -8,7 +8,7 @@
*/
#include "WebSocketImplQt.h"
#include "Utilities.h"
#include "StringUtils.h"
#include <LibCore/EventLoop.h>
#include <QSslSocket>
#include <QTcpSocket>

8
Ladybird/Qt/ladybird.qrc Normal file
View File

@ -0,0 +1,8 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>../Icons/ladybird.png</file>
<file>../Icons/back.tvg</file>
<file>../Icons/forward.tvg</file>
<file>../Icons/reload.tvg</file>
</qresource>
</RCC>

View File

@ -6,13 +6,13 @@
#include "BrowserWindow.h"
#include "EventLoopImplementationQt.h"
#include "HelperProcess.h"
#include "Settings.h"
#include "Utilities.h"
#include "WebContentView.h"
#include <AK/OwnPtr.h>
#include <Browser/CookieJar.h>
#include <Browser/Database.h>
#include <Ladybird/HelperProcess.h>
#include <Ladybird/Utilities.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Process.h>

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -7,30 +8,16 @@
#include "Utilities.h"
#include <AK/LexicalPath.h>
#include <AK/Platform.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
#include <QCoreApplication>
DeprecatedString s_serenity_resource_root;
AK::DeprecatedString ak_deprecated_string_from_qstring(QString const& qstring)
ErrorOr<String> application_directory()
{
return AK::DeprecatedString(qstring.toUtf8().data());
}
ErrorOr<String> ak_string_from_qstring(QString const& qstring)
{
return String::from_utf8(StringView(qstring.toUtf8().data(), qstring.size()));
}
QString qstring_from_ak_deprecated_string(AK::DeprecatedString const& ak_deprecated_string)
{
return QString::fromUtf8(ak_deprecated_string.characters(), ak_deprecated_string.length());
}
QString qstring_from_ak_string(String const& ak_string)
{
auto view = ak_string.bytes_as_string_view();
return QString::fromUtf8(view.characters_without_null_termination(), view.length());
auto current_executable_path = TRY(Core::System::current_executable_path());
auto dirname = LexicalPath::dirname(current_executable_path.to_deprecated_string());
return String::from_deprecated_string(dirname);
}
void platform_init()
@ -49,7 +36,7 @@ void platform_init()
auto home_lagom = DeprecatedString::formatted("{}/.lagom", home);
if (FileSystem::is_directory(home_lagom))
return home_lagom;
auto app_dir = ak_deprecated_string_from_qstring(QCoreApplication::applicationDirPath());
auto app_dir = application_directory().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
# ifdef AK_OS_MACOS
return LexicalPath(app_dir).parent().append("Resources"sv).string();
# else
@ -61,11 +48,9 @@ void platform_init()
ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name)
{
auto application_path = TRY(ak_string_from_qstring(QCoreApplication::applicationDirPath()));
auto application_path = TRY(application_directory());
Vector<String> paths;
TRY(paths.try_append(TRY(String::formatted("./{}/{}", process_name, process_name))));
TRY(paths.try_append(TRY(String::formatted("{}/{}/{}", application_path, process_name, process_name))));
TRY(paths.try_append(TRY(String::formatted("{}/{}", application_path, process_name))));
TRY(paths.try_append(TRY(String::formatted("./{}", process_name))));
// NOTE: Add platform-specific paths here

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -10,13 +11,9 @@
#include <AK/Error.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <QString>
AK::DeprecatedString ak_deprecated_string_from_qstring(QString const&);
ErrorOr<String> ak_string_from_qstring(QString const&);
QString qstring_from_ak_deprecated_string(AK::DeprecatedString const&);
QString qstring_from_ak_string(String const&);
void platform_init();
ErrorOr<String> application_directory();
ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name);
extern DeprecatedString s_serenity_resource_root;

View File

@ -6,18 +6,19 @@ set(WEBCONTENT_SOURCES
${WEBCONTENT_SOURCE_DIR}/PageHost.cpp
${WEBCONTENT_SOURCE_DIR}/WebContentConsoleClient.cpp
${WEBCONTENT_SOURCE_DIR}/WebDriverConnection.cpp
../AudioCodecPluginQt.cpp
../AudioThread.cpp
../EventLoopImplementationQt.cpp
../EventLoopImplementationQtEventTarget.cpp
../FontPlugin.cpp
../HelperProcess.cpp
../ImageCodecPlugin.cpp
../RequestManagerQt.cpp
../Utilities.cpp
../WebSocketClientManagerQt.cpp
../WebSocketQt.cpp
../WebSocketImplQt.cpp
../Qt/AudioCodecPluginQt.cpp
../Qt/AudioThread.cpp
../Qt/EventLoopImplementationQt.cpp
../Qt/EventLoopImplementationQtEventTarget.cpp
../Qt/RequestManagerQt.cpp
../Qt/StringUtils.cpp
../Qt/WebSocketClientManagerQt.cpp
../Qt/WebSocketQt.cpp
../Qt/WebSocketImplQt.cpp
main.cpp
)

View File

@ -4,15 +4,15 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "../AudioCodecPluginQt.h"
#include "../EventLoopImplementationQt.h"
#include "../FontPlugin.h"
#include "../HelperProcess.h"
#include "../ImageCodecPlugin.h"
#include "../RequestManagerQt.h"
#include "../Utilities.h"
#include "../WebSocketClientManagerQt.h"
#include <AK/LexicalPath.h>
#include <Ladybird/FontPlugin.h>
#include <Ladybird/HelperProcess.h>
#include <Ladybird/ImageCodecPlugin.h>
#include <Ladybird/Qt/AudioCodecPluginQt.h>
#include <Ladybird/Qt/EventLoopImplementationQt.h>
#include <Ladybird/Qt/RequestManagerQt.h>
#include <Ladybird/Qt/WebSocketClientManagerQt.h>
#include <Ladybird/Utilities.h>
#include <LibAudio/Loader.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
@ -41,8 +41,6 @@
static ErrorOr<void> load_content_filters();
static ErrorOr<void> load_autoplay_allowlist();
extern DeprecatedString s_serenity_resource_root;
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
QCoreApplication app(arguments.argc, arguments.argv);

View File

@ -8,13 +8,13 @@ set(SOURCES
main.cpp
)
qt_add_executable(WebDriver ${SOURCES})
add_executable(WebDriver ${SOURCES})
target_include_directories(WebDriver PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_include_directories(WebDriver PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..)
target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland)
target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services)
target_link_libraries(WebDriver PRIVATE Qt::Core Qt::Network LibCore LibFileSystem LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket)
target_link_libraries(WebDriver PRIVATE LibCore LibFileSystem LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket)
add_dependencies(WebDriver headless-browser)
if (ANDROID)
link_android_libs(WebDriver)

View File

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "../Utilities.h"
#include <AK/Platform.h>
#include <Ladybird/Utilities.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Directory.h>
#include <LibCore/EventLoop.h>
@ -14,11 +14,8 @@
#include <LibCore/System.h>
#include <LibCore/TCPServer.h>
#include <LibMain/Main.h>
#include <QCoreApplication>
#include <WebDriver/Client.h>
extern DeprecatedString s_serenity_resource_root;
static ErrorOr<pid_t> launch_process(StringView application, ReadonlySpan<char const*> arguments)
{
auto paths = TRY(get_paths_for_helper_process(application));
@ -57,9 +54,6 @@ static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_pat
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
// Note: only creating this to get access to its static methods in Utilities
QCoreApplication application(arguments.argc, arguments.argv);
auto listen_address = "0.0.0.0"sv;
int port = 8000;

View File

@ -1,8 +0,0 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>Icons/ladybird.png</file>
<file>Icons/back.tvg</file>
<file>Icons/forward.tvg</file>
<file>Icons/reload.tvg</file>
</qresource>
</RCC>

View File

@ -12,20 +12,20 @@ group("ladybird") {
moc_qt_objects("generate_moc") {
sources = [
"BrowserWindow.h",
"ConsoleWidget.h",
"EventLoopImplementationQtEventTarget.h",
"InspectorWidget.h",
"LocationEdit.h",
"ModelTranslator.h",
"SettingsDialog.h",
"Tab.h",
"WebContentView.h",
"Qt/BrowserWindow.h",
"Qt/ConsoleWidget.h",
"Qt/EventLoopImplementationQtEventTarget.h",
"Qt/InspectorWidget.h",
"Qt/LocationEdit.h",
"Qt/ModelTranslator.h",
"Qt/SettingsDialog.h",
"Qt/Tab.h",
"Qt/WebContentView.h",
]
}
compile_qt_resource_file("compile_resource_file") {
sources = [ "ladybird.qrc" ]
sources = [ "Qt/ladybird.qrc" ]
}
link_qt("ladybird_qt_components") {
@ -79,21 +79,22 @@ executable("ladybird_executable") {
"//Userland/Applications/Browser/CookieJar.cpp",
"//Userland/Applications/Browser/Database.cpp",
"//Userland/Applications/Browser/History.cpp",
"BrowserWindow.cpp",
"ConsoleWidget.cpp",
"EventLoopImplementationQt.cpp",
"EventLoopImplementationQtEventTarget.cpp",
"HelperProcess.cpp",
"InspectorWidget.cpp",
"LocationEdit.cpp",
"ModelTranslator.cpp",
"Settings.cpp",
"SettingsDialog.cpp",
"TVGIconEngine.cpp",
"Tab.cpp",
"Qt/BrowserWindow.cpp",
"Qt/ConsoleWidget.cpp",
"Qt/EventLoopImplementationQt.cpp",
"Qt/EventLoopImplementationQtEventTarget.cpp",
"Qt/InspectorWidget.cpp",
"Qt/LocationEdit.cpp",
"Qt/ModelTranslator.cpp",
"Qt/Settings.cpp",
"Qt/SettingsDialog.cpp",
"Qt/StringUtils.cpp",
"Qt/TVGIconEngine.cpp",
"Qt/Tab.cpp",
"Qt/WebContentView.cpp",
"Qt/main.cpp",
"Utilities.cpp",
"WebContentView.cpp",
"main.cpp",
]
sources += get_target_outputs(":generate_moc") +
get_target_outputs(":compile_resource_file")
@ -103,16 +104,9 @@ executable("ladybird_executable") {
output_name = "ladybird"
}
link_qt("headless_browser_qt") {
qt_components = [ "Core" ]
}
executable("headless-browser") {
include_dirs = [ "//Userland/Services" ]
configs += [
":ladybird_config",
":headless_browser_qt",
]
configs += [ ":ladybird_config" ]
deps = [
"//Userland/Libraries/LibCore",
"//Userland/Libraries/LibCrypto",

View File

@ -4,10 +4,10 @@ import("//Meta/gn/build/libs/pulse/enable.gni")
moc_qt_objects("generate_moc") {
sources = [
"//Ladybird/AudioCodecPluginQt.h",
"//Ladybird/AudioThread.h",
"//Ladybird/EventLoopImplementationQtEventTarget.h",
"//Ladybird/RequestManagerQt.h",
"//Ladybird/Qt/AudioCodecPluginQt.h",
"//Ladybird/Qt/AudioThread.h",
"//Ladybird/Qt/EventLoopImplementationQtEventTarget.h",
"//Ladybird/Qt/RequestManagerQt.h",
]
}
@ -48,18 +48,19 @@ executable("WebContent") {
"//Userland/Libraries/LibWebView:WebDriverServerEndpoint",
]
sources = [
"../AudioCodecPluginQt.cpp",
"../AudioThread.cpp",
"../EventLoopImplementationQt.cpp",
"../EventLoopImplementationQtEventTarget.cpp",
"../FontPlugin.cpp",
"../HelperProcess.cpp",
"../ImageCodecPlugin.cpp",
"../RequestManagerQt.cpp",
"../Utilities.cpp",
"../WebSocketClientManagerQt.cpp",
"../WebSocketImplQt.cpp",
"../WebSocketQt.cpp",
"//Ladybird/FontPlugin.cpp",
"//Ladybird/HelperProcess.cpp",
"//Ladybird/ImageCodecPlugin.cpp",
"//Ladybird/Qt/AudioCodecPluginQt.cpp",
"//Ladybird/Qt/AudioThread.cpp",
"//Ladybird/Qt/EventLoopImplementationQt.cpp",
"//Ladybird/Qt/EventLoopImplementationQtEventTarget.cpp",
"//Ladybird/Qt/RequestManagerQt.cpp",
"//Ladybird/Qt/StringUtils.cpp",
"//Ladybird/Qt/WebSocketClientManagerQt.cpp",
"//Ladybird/Qt/WebSocketImplQt.cpp",
"//Ladybird/Qt/WebSocketQt.cpp",
"//Ladybird/Utilities.cpp",
"//Userland/Services/WebContent/ConnectionFromClient.cpp",
"//Userland/Services/WebContent/ConsoleGlobalEnvironmentExtensions.cpp",
"//Userland/Services/WebContent/PageHost.cpp",

View File

@ -1,17 +1,7 @@
import("//Ladybird/link_qt.gni")
link_qt("WebDriver_qt") {
qt_components = [
"Core",
"Network",
]
}
executable("WebDriver") {
configs += [
"//Ladybird:ladybird_config",
":WebDriver_qt",
]
configs += [ "//Ladybird:ladybird_config" ]
include_dirs = [
"//Userland/Services",
"//Ladybird",
@ -31,7 +21,7 @@ executable("WebDriver") {
"//Userland/Libraries/LibWebView:WebDriverServerEndpoint",
]
sources = [
"../Utilities.cpp",
"//Ladybird/Utilities.cpp",
"//Userland/Services/WebDriver/Client.cpp",
"//Userland/Services/WebDriver/Session.cpp",
"//Userland/Services/WebDriver/WebContentConnection.cpp",

View File

@ -43,7 +43,6 @@
#if !defined(AK_OS_SERENITY)
# include <Ladybird/HelperProcess.h>
# include <Ladybird/Utilities.h>
# include <QCoreApplication>
#endif
class HeadlessWebContentView final : public WebView::ViewImplementation {
@ -374,9 +373,6 @@ static ErrorOr<int> run_tests(HeadlessWebContentView& view, StringView test_root
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
#if !defined(AK_OS_SERENITY)
QCoreApplication app(arguments.argc, arguments.argv);
#endif
Core::EventLoop event_loop;
int screenshot_timeout = 1;