mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:57:44 +00:00
Ladybird: Remove Web::Platform plugins for Qt in favor of LibCore
Now that the Core::EventLoop is driven by a QEventLoop in Ladybird, we don't need to patch LibWeb with Web::Platform plugins. This patch removes EventLoopPluginQt and TimerQt. Note that we can't just replace the Web::Platform abstractions with LibCore stuff immediately, since the Web::Platform APIs use JS::SafeFunction for callbacks.
This commit is contained in:
parent
3494c2382d
commit
1c6c3685c4
8 changed files with 4 additions and 258 deletions
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "EventLoopPluginQt.h"
|
||||
#include "TimerQt.h"
|
||||
#include <AK/Function.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
EventLoopPluginQt::EventLoopPluginQt() = default;
|
||||
EventLoopPluginQt::~EventLoopPluginQt() = default;
|
||||
|
||||
void EventLoopPluginQt::spin_until(JS::SafeFunction<bool()> goal_condition)
|
||||
{
|
||||
while (!goal_condition())
|
||||
QCoreApplication::processEvents(QEventLoop::ProcessEventsFlag::AllEvents | QEventLoop::ProcessEventsFlag::WaitForMoreEvents);
|
||||
}
|
||||
|
||||
void EventLoopPluginQt::deferred_invoke(JS::SafeFunction<void()> function)
|
||||
{
|
||||
VERIFY(function);
|
||||
QTimer::singleShot(0, [function = move(function)] {
|
||||
function();
|
||||
});
|
||||
}
|
||||
|
||||
NonnullRefPtr<Web::Platform::Timer> EventLoopPluginQt::create_timer()
|
||||
{
|
||||
return TimerQt::create();
|
||||
}
|
||||
|
||||
void EventLoopPluginQt::quit()
|
||||
{
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
class EventLoopPluginQt final : public Web::Platform::EventLoopPlugin {
|
||||
public:
|
||||
EventLoopPluginQt();
|
||||
virtual ~EventLoopPluginQt() override;
|
||||
|
||||
virtual void spin_until(JS::SafeFunction<bool()> goal_condition) override;
|
||||
virtual void deferred_invoke(JS::SafeFunction<void()>) override;
|
||||
virtual NonnullRefPtr<Web::Platform::Timer> create_timer() override;
|
||||
virtual void quit() override;
|
||||
};
|
||||
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "TimerQt.h"
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
NonnullRefPtr<TimerQt> TimerQt::create()
|
||||
{
|
||||
return adopt_ref(*new TimerQt);
|
||||
}
|
||||
|
||||
TimerQt::TimerQt()
|
||||
{
|
||||
m_timer = new QTimer;
|
||||
QObject::connect(m_timer, &QTimer::timeout, [this] {
|
||||
if (on_timeout)
|
||||
on_timeout();
|
||||
});
|
||||
}
|
||||
|
||||
TimerQt::~TimerQt()
|
||||
{
|
||||
delete m_timer;
|
||||
}
|
||||
|
||||
void TimerQt::start()
|
||||
{
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
void TimerQt::start(int interval_ms)
|
||||
{
|
||||
m_timer->start(interval_ms);
|
||||
}
|
||||
|
||||
void TimerQt::restart()
|
||||
{
|
||||
restart(interval());
|
||||
}
|
||||
|
||||
void TimerQt::restart(int interval_ms)
|
||||
{
|
||||
if (is_active())
|
||||
stop();
|
||||
start(interval_ms);
|
||||
}
|
||||
|
||||
void TimerQt::stop()
|
||||
{
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
void TimerQt::set_active(bool active)
|
||||
{
|
||||
if (active)
|
||||
m_timer->start();
|
||||
else
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
bool TimerQt::is_active() const
|
||||
{
|
||||
return m_timer->isActive();
|
||||
}
|
||||
|
||||
int TimerQt::interval() const
|
||||
{
|
||||
return m_timer->interval();
|
||||
}
|
||||
|
||||
void TimerQt::set_interval(int interval_ms)
|
||||
{
|
||||
m_timer->setInterval(interval_ms);
|
||||
}
|
||||
|
||||
bool TimerQt::is_single_shot() const
|
||||
{
|
||||
return m_timer->isSingleShot();
|
||||
}
|
||||
|
||||
void TimerQt::set_single_shot(bool single_shot)
|
||||
{
|
||||
m_timer->setSingleShot(single_shot);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
|
||||
class QTimer;
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
class TimerQt final : public Web::Platform::Timer {
|
||||
public:
|
||||
static NonnullRefPtr<TimerQt> create();
|
||||
|
||||
virtual ~TimerQt();
|
||||
|
||||
virtual void start() override;
|
||||
virtual void start(int interval_ms) override;
|
||||
virtual void restart() override;
|
||||
virtual void restart(int interval_ms) override;
|
||||
virtual void stop() override;
|
||||
|
||||
virtual void set_active(bool) override;
|
||||
|
||||
virtual bool is_active() const override;
|
||||
virtual int interval() const override;
|
||||
virtual void set_interval(int interval_ms) override;
|
||||
|
||||
virtual bool is_single_shot() const override;
|
||||
virtual void set_single_shot(bool) override;
|
||||
|
||||
private:
|
||||
TimerQt();
|
||||
|
||||
QTimer* m_timer { nullptr };
|
||||
};
|
||||
|
||||
}
|
|
@ -7,11 +7,9 @@ set(WEBCONTENT_SOURCES
|
|||
${WEBCONTENT_SOURCE_DIR}/WebContentConsoleClient.cpp
|
||||
${WEBCONTENT_SOURCE_DIR}/WebDriverConnection.cpp
|
||||
../EventLoopImplementationQt.cpp
|
||||
../EventLoopPluginQt.cpp
|
||||
../FontPluginQt.cpp
|
||||
../ImageCodecPluginLadybird.cpp
|
||||
../RequestManagerQt.cpp
|
||||
../TimerQt.cpp
|
||||
../Utilities.cpp
|
||||
../WebSocketClientManagerLadybird.cpp
|
||||
../WebSocketLadybird.cpp
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include "../EventLoopImplementationQt.h"
|
||||
#include "../EventLoopPluginQt.h"
|
||||
#include "../FontPluginQt.h"
|
||||
#include "../ImageCodecPluginLadybird.h"
|
||||
#include "../RequestManagerQt.h"
|
||||
|
@ -25,9 +23,9 @@
|
|||
#include <LibWeb/Loader/FrameLoader.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
#include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
|
||||
#include <LibWeb/Platform/EventLoopPluginSerenity.h>
|
||||
#include <LibWeb/WebSockets/WebSocket.h>
|
||||
#include <QGuiApplication>
|
||||
#include <QSocketNotifier>
|
||||
#include <QTimer>
|
||||
#include <WebContent/ConnectionFromClient.h>
|
||||
#include <WebContent/PageHost.h>
|
||||
|
@ -38,27 +36,6 @@ static ErrorOr<void> load_autoplay_allowlist();
|
|||
|
||||
extern DeprecatedString s_serenity_resource_root;
|
||||
|
||||
struct DeferredInvokerQt final : IPC::DeferredInvoker {
|
||||
virtual ~DeferredInvokerQt() = default;
|
||||
virtual void schedule(Function<void()> callback) override
|
||||
{
|
||||
QTimer::singleShot(0, move(callback));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ClientType>
|
||||
static void proxy_socket_through_notifier(ClientType& client, QSocketNotifier& notifier)
|
||||
{
|
||||
notifier.setSocket(client.socket().fd().value());
|
||||
notifier.setEnabled(true);
|
||||
|
||||
QObject::connect(¬ifier, &QSocketNotifier::activated, [&client]() mutable {
|
||||
client.socket().notifier()->on_activation();
|
||||
});
|
||||
|
||||
client.set_deferred_invoker(make<DeferredInvokerQt>());
|
||||
}
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
QGuiApplication app(arguments.argc, arguments.argv);
|
||||
|
@ -68,7 +45,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
platform_init();
|
||||
|
||||
Web::Platform::EventLoopPlugin::install(*new Ladybird::EventLoopPluginQt);
|
||||
Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);
|
||||
Web::Platform::ImageCodecPlugin::install(*new Ladybird::ImageCodecPluginLadybird);
|
||||
|
||||
Web::ResourceLoader::initialize(RequestManagerQt::create());
|
||||
|
@ -102,14 +79,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto webcontent_client = TRY(WebContent::ConnectionFromClient::try_create(move(webcontent_socket)));
|
||||
webcontent_client->set_fd_passing_socket(TRY(Core::LocalSocket::adopt_fd(webcontent_fd_passing_socket)));
|
||||
|
||||
QSocketNotifier webcontent_notifier(QSocketNotifier::Type::Read);
|
||||
proxy_socket_through_notifier(*webcontent_client, webcontent_notifier);
|
||||
|
||||
QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read);
|
||||
webcontent_client->page_host().on_webdriver_connection = [&](auto& webdriver) {
|
||||
proxy_socket_through_notifier(webdriver, webdriver_notifier);
|
||||
};
|
||||
|
||||
return event_loop.exec();
|
||||
}
|
||||
|
||||
|
|
|
@ -605,27 +605,9 @@ void WebContentView::create_client(WebView::EnableCallgrindProfiling enable_call
|
|||
auto candidate_web_content_paths = get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors();
|
||||
auto new_client = launch_web_content_process(candidate_web_content_paths, enable_callgrind_profiling).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
m_web_content_notifier.setSocket(new_client->socket().fd().value());
|
||||
m_web_content_notifier.setEnabled(true);
|
||||
|
||||
QObject::connect(&m_web_content_notifier, &QSocketNotifier::activated, [new_client = new_client.ptr()] {
|
||||
if (auto notifier = new_client->socket().notifier())
|
||||
notifier->on_activation();
|
||||
});
|
||||
|
||||
struct DeferredInvokerQt final : IPC::DeferredInvoker {
|
||||
virtual ~DeferredInvokerQt() = default;
|
||||
virtual void schedule(Function<void()> callback) override
|
||||
{
|
||||
QTimer::singleShot(0, std::move(callback));
|
||||
}
|
||||
};
|
||||
|
||||
new_client->set_deferred_invoker(make<DeferredInvokerQt>());
|
||||
|
||||
m_client_state.client = new_client;
|
||||
m_client_state.client->on_web_content_process_crash = [this] {
|
||||
QTimer::singleShot(0, [this] {
|
||||
Core::deferred_invoke([this] {
|
||||
handle_web_content_process_crash();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <LibWebView/ViewImplementation.h>
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QPointer>
|
||||
#include <QSocketNotifier>
|
||||
|
||||
class QTextEdit;
|
||||
class QLineEdit;
|
||||
|
@ -215,7 +214,6 @@ private:
|
|||
Gfx::IntRect m_viewport_rect;
|
||||
|
||||
void handle_web_content_process_crash();
|
||||
QSocketNotifier m_web_content_notifier { QSocketNotifier::Type::Read };
|
||||
|
||||
RefPtr<Gfx::Bitmap> m_backup_bitmap;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue