1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

Ladybird: Render web content in a separate process :^)

This patch brings over the WebContent process over from SerenityOS
to Ladybird, along with a new WebContentView widget that renders
web content in a separate process.

There's a lot of jank and FIXME material here, notably I had to re-add
manually pumped Core::EventLoop instances on both sides, in order to get
the IPC protocol running. This introduces a lot of latency and we should
work towards replacing those loops with improved abstractions.

The WebContent process is built separately here (not part of Lagom) and
we provide our own main.cpp for it. Like everything, this can be better
architected, it's just a starting point. :^)
This commit is contained in:
Andreas Kling 2022-10-05 15:23:41 +02:00 committed by Andrew Kaster
parent 2451a447f5
commit 26a7ea0e0f
14 changed files with 1313 additions and 795 deletions

View file

@ -13,6 +13,7 @@
#include <QCoreApplication>
#include <QFont>
#include <QFontMetrics>
#include <QPlainTextEdit>
#include <QPoint>
#include <QResizeEvent>
@ -27,7 +28,7 @@ Tab::Tab(BrowserWindow* window)
m_layout->setSpacing(0);
m_layout->setContentsMargins(0, 0, 0, 0);
m_view = new SimpleWebView;
m_view = new WebContentView;
m_toolbar = new QToolBar(this);
m_location_edit = new QLineEdit(this);
@ -63,30 +64,39 @@ Tab::Tab(BrowserWindow* window)
m_toolbar->addAction(m_home_action);
m_toolbar->addWidget(m_location_edit);
QObject::connect(m_view, &SimpleWebView::link_hovered, [this](QString const& title) {
QObject::connect(m_view, &WebContentView::link_hovered, [this](QString const& title) {
m_hover_label->setText(title);
update_hover_label();
m_hover_label->show();
});
QObject::connect(m_view, &SimpleWebView::link_unhovered, [this] {
QObject::connect(m_view, &WebContentView::link_unhovered, [this] {
m_hover_label->hide();
});
QObject::connect(m_view, &SimpleWebView::load_started, [this](const URL& url) {
QObject::connect(m_view, &WebContentView::load_started, [this](const URL& url) {
m_location_edit->setText(url.to_string().characters());
m_history.push(url, m_title.toUtf8().data());
m_back_action->setEnabled(m_history.can_go_back());
m_forward_action->setEnabled(m_history.can_go_forward());
});
QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed);
QObject::connect(m_view, &SimpleWebView::title_changed, this, &Tab::page_title_changed);
QObject::connect(m_view, &SimpleWebView::favicon_changed, this, &Tab::page_favicon_changed);
QObject::connect(m_view, &WebContentView::title_changed, this, &Tab::page_title_changed);
QObject::connect(m_view, &WebContentView::favicon_changed, this, &Tab::page_favicon_changed);
QObject::connect(m_back_action, &QAction::triggered, this, &Tab::back);
QObject::connect(m_forward_action, &QAction::triggered, this, &Tab::forward);
QObject::connect(m_home_action, &QAction::triggered, this, &Tab::home);
QObject::connect(m_reload_action, &QAction::triggered, this, &Tab::reload);
QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor);
QObject::connect(m_view, &WebContentView::got_source, this, [this](AK::URL, QString const& source) {
auto* text_edit = new QPlainTextEdit(this);
text_edit->setWindowFlags(Qt::Window);
text_edit->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont));
text_edit->resize(800, 600);
text_edit->setPlainText(source);
text_edit->show();
});
}
void Tab::focus_location_editor()
@ -99,7 +109,7 @@ void Tab::navigate(QString url)
{
if (!url.startsWith("http://", Qt::CaseInsensitive) && !url.startsWith("https://", Qt::CaseInsensitive) && !url.startsWith("file://", Qt::CaseInsensitive))
url = "http://" + url;
view().load(url.toUtf8().data());
view().load(akstring_from_qstring(url));
}
void Tab::back()