mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00:00
Ladybird: Add ability to create a tab without creating a new WebContent
This commit is contained in:
parent
506707cc2b
commit
48ce8fb4e9
Notes:
sideshowbarker
2024-07-17 05:18:58 +09:00
Author: https://github.com/ADKaster
Commit: 48ce8fb4e9
Pull-request: https://github.com/SerenityOS/serenity/pull/23051
Reviewed-by: https://github.com/kalenikaliaksandr
Reviewed-by: https://github.com/trflynn89 ✅
11 changed files with 36 additions and 21 deletions
|
@ -36,7 +36,7 @@ WebViewBridge::WebViewBridge(Vector<Web::DevicePixelRect> screen_rects, float de
|
|||
{
|
||||
m_device_pixel_ratio = device_pixel_ratio;
|
||||
|
||||
create_client();
|
||||
initialize_client(CreateNewClient::Yes);
|
||||
|
||||
on_scroll_by_delta = [this](auto x_delta, auto y_delta) {
|
||||
auto position = m_viewport_rect.location();
|
||||
|
@ -171,8 +171,10 @@ Gfx::IntPoint WebViewBridge::to_widget_position(Gfx::IntPoint content_position)
|
|||
return scale_for_device(content_position, inverse_device_pixel_ratio());
|
||||
}
|
||||
|
||||
void WebViewBridge::create_client()
|
||||
void WebViewBridge::initialize_client(CreateNewClient)
|
||||
{
|
||||
// FIXME: Don't create a new process when CreateNewClient is false
|
||||
// We should create a new tab/window in the UI instead, and re-use the existing WebContentClient object.
|
||||
m_client_state = {};
|
||||
|
||||
auto candidate_web_content_paths = MUST(get_paths_for_helper_process("WebContent"sv));
|
||||
|
|
|
@ -67,7 +67,7 @@ private:
|
|||
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
|
||||
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
|
||||
|
||||
virtual void create_client() override;
|
||||
virtual void initialize_client(CreateNewClient) override;
|
||||
|
||||
Vector<Web::DevicePixelRect> m_screen_rects;
|
||||
Gfx::IntRect m_viewport_rect;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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();
|
||||
|
||||
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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -28,7 +28,7 @@ OutOfProcessWebView::OutOfProcessWebView()
|
|||
set_should_hide_unnecessary_scrollbars(true);
|
||||
set_focus_policy(GUI::FocusPolicy::StrongFocus);
|
||||
|
||||
create_client();
|
||||
initialize_client(CreateNewClient::Yes);
|
||||
|
||||
on_did_layout = [this](auto content_size) {
|
||||
set_content_size(content_size);
|
||||
|
@ -81,8 +81,10 @@ OutOfProcessWebView::OutOfProcessWebView()
|
|||
|
||||
OutOfProcessWebView::~OutOfProcessWebView() = default;
|
||||
|
||||
void OutOfProcessWebView::create_client()
|
||||
void OutOfProcessWebView::initialize_client(WebView::ViewImplementation::CreateNewClient)
|
||||
{
|
||||
// FIXME: Don't create a new process when CreateNewClient is false
|
||||
// We should create a new tab/window in the UI instead, and re-use the existing WebContentClient object.
|
||||
m_client_state = {};
|
||||
|
||||
m_client_state.client = WebContentClient::try_create(*this).release_value_but_fixme_should_propagate_errors();
|
||||
|
|
|
@ -78,7 +78,7 @@ private:
|
|||
virtual void did_scroll() override;
|
||||
|
||||
// ^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;
|
||||
|
|
|
@ -334,7 +334,7 @@ void ViewImplementation::handle_web_content_process_crash()
|
|||
}
|
||||
m_repeated_crash_timer->restart();
|
||||
|
||||
create_client();
|
||||
initialize_client();
|
||||
VERIFY(m_client_state.client);
|
||||
|
||||
// Don't keep a stale backup bitmap around.
|
||||
|
|
|
@ -202,7 +202,11 @@ protected:
|
|||
|
||||
void handle_resize();
|
||||
|
||||
virtual void create_client() { }
|
||||
enum class CreateNewClient {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
virtual void initialize_client(CreateNewClient = CreateNewClient::Yes) { }
|
||||
|
||||
void handle_web_content_process_crash();
|
||||
|
||||
|
@ -217,6 +221,7 @@ protected:
|
|||
String client_handle;
|
||||
SharedBitmap front_bitmap;
|
||||
SharedBitmap back_bitmap;
|
||||
u64 page_index { 0 };
|
||||
i32 next_bitmap_id { 0 };
|
||||
bool has_usable_bitmap { false };
|
||||
} m_client_state;
|
||||
|
|
|
@ -187,7 +187,7 @@ private:
|
|||
}
|
||||
|
||||
void update_zoom() override { }
|
||||
void create_client() override { }
|
||||
void initialize_client(CreateNewClient) override { }
|
||||
|
||||
virtual Web::DevicePixelRect viewport_rect() const override { return m_viewport_rect.to_type<Web::DevicePixels>(); }
|
||||
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue