diff --git a/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp b/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp index 5200df0f4ed..19a108bc525 100644 --- a/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp +++ b/Ladybird/AppKit/UI/LadybirdWebViewBridge.cpp @@ -36,7 +36,7 @@ WebViewBridge::WebViewBridge(Vector 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)); diff --git a/Ladybird/AppKit/UI/LadybirdWebViewBridge.h b/Ladybird/AppKit/UI/LadybirdWebViewBridge.h index a914d9046fd..c64c79bee1c 100644 --- a/Ladybird/AppKit/UI/LadybirdWebViewBridge.h +++ b/Ladybird/AppKit/UI/LadybirdWebViewBridge.h @@ -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 m_screen_rects; Gfx::IntRect m_viewport_rect; diff --git a/Ladybird/Qt/Tab.cpp b/Ladybird/Qt/Tab.cpp index c482e967fe5..1bd629aa7d1 100644 --- a/Ladybird/Qt/Tab.cpp +++ b/Ladybird/Qt/Tab.cpp @@ -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 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); diff --git a/Ladybird/Qt/Tab.h b/Ladybird/Qt/Tab.h index 71d5b89aca8..b5b9e833f50 100644 --- a/Ladybird/Qt/Tab.h +++ b/Ladybird/Qt/Tab.h @@ -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 parent_client = nullptr, size_t page_index = 0); virtual ~Tab() override; WebContentView& view() { return *m_view; } diff --git a/Ladybird/Qt/WebContentView.cpp b/Ladybird/Qt/WebContentView.cpp index b74aef9bf19..6c17cfb0f9a 100644 --- a/Ladybird/Qt/WebContentView.cpp +++ b/Ladybird/Qt/WebContentView.cpp @@ -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 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(); diff --git a/Ladybird/Qt/WebContentView.h b/Ladybird/Qt/WebContentView.h index d3af87da715..28022ea334a 100644 --- a/Ladybird/Qt/WebContentView.h +++ b/Ladybird/Qt/WebContentView.h @@ -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 parent_client = nullptr, size_t page_index = 0); virtual ~WebContentView() override; Function 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; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index d57e62b926d..f077c8b16ef 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -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(); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 4ec2224d1f9..ab8c8f16eae 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -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; diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 2fd611d0e10..029fcbeee78 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -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. diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index b216e2238d7..005911a954a 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -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; diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 08c5280f027..fc6d326f3f1 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -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(); } virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; }