1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:37:46 +00:00

Ladybird: Add ability to create a tab without creating a new WebContent

This commit is contained in:
Andrew Kaster 2024-01-30 09:12:14 -07:00 committed by Tim Flynn
parent 506707cc2b
commit 48ce8fb4e9
11 changed files with 36 additions and 21 deletions

View file

@ -53,7 +53,7 @@ static QIcon create_tvg_icon_with_theme_colors(QString name, QPalette const& pal
return QIcon(icon_engine);
}
Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path)
Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, RefPtr<WebView::WebContentClient> parent_client, size_t page_index)
: QWidget(window)
, m_window(window)
{
@ -61,7 +61,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
m_layout->setSpacing(0);
m_layout->setContentsMargins(0, 0, 0, 0);
m_view = new WebContentView(web_content_options, webdriver_content_ipc_path);
m_view = new WebContentView(web_content_options, webdriver_content_ipc_path, parent_client, page_index);
m_toolbar = new QToolBar(this);
m_location_edit = new LocationEdit(this);

View file

@ -28,7 +28,7 @@ class Tab final : public QWidget {
Q_OBJECT
public:
Tab(BrowserWindow* window, WebContentOptions const&, StringView webdriver_content_ipc_path);
Tab(BrowserWindow* window, WebContentOptions const&, StringView webdriver_content_ipc_path, RefPtr<WebView::WebContentClient> parent_client = nullptr, size_t page_index = 0);
virtual ~Tab() override;
WebContentView& view() { return *m_view; }

View file

@ -54,10 +54,13 @@ namespace Ladybird {
bool is_using_dark_system_theme(QWidget&);
WebContentView::WebContentView(WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path)
WebContentView::WebContentView(WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, RefPtr<WebView::WebContentClient> parent_client, size_t page_index)
: m_web_content_options(web_content_options)
, m_webdriver_content_ipc_path(webdriver_content_ipc_path)
{
m_client_state.client = parent_client;
m_client_state.page_index = page_index;
setMouseTracking(true);
setAcceptDrops(true);
@ -75,7 +78,7 @@ WebContentView::WebContentView(WebContentOptions const& web_content_options, Str
update_viewport_rect();
});
create_client();
initialize_client((parent_client == nullptr) ? CreateNewClient::Yes : CreateNewClient::No);
on_did_layout = [this](auto content_size) {
verticalScrollBar()->setMinimum(0);
@ -599,14 +602,17 @@ void WebContentView::update_palette(PaletteMode mode)
client().async_update_system_theme(make_system_theme_from_qt_palette(*this, mode));
}
void WebContentView::create_client()
void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewClient create_new_client)
{
m_client_state = {};
if (create_new_client == CreateNewClient::Yes) {
m_client_state = {};
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(*this, candidate_web_content_paths, m_web_content_options).release_value_but_fixme_should_propagate_errors();
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(*this, candidate_web_content_paths, m_web_content_options).release_value_but_fixme_should_propagate_errors();
m_client_state.client = new_client;
}
m_client_state.client = new_client;
m_client_state.client->on_web_content_process_crash = [this] {
Core::deferred_invoke([this] {
handle_web_content_process_crash();

View file

@ -42,7 +42,7 @@ class WebContentView final
, public WebView::ViewImplementation {
Q_OBJECT
public:
WebContentView(WebContentOptions const&, StringView webdriver_content_ipc_path);
WebContentView(WebContentOptions const&, StringView webdriver_content_ipc_path, RefPtr<WebView::WebContentClient> parent_client = nullptr, size_t page_index = 0);
virtual ~WebContentView() override;
Function<String(const AK::URL&, Web::HTML::ActivateTab)> on_tab_open_request;
@ -82,7 +82,7 @@ signals:
private:
// ^WebView::ViewImplementation
virtual void create_client() override;
virtual void initialize_client(CreateNewClient) override;
virtual void update_zoom() override;
virtual Web::DevicePixelRect viewport_rect() const override;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;