1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-08-02 13:07:47 +00:00

Ladybird: Add IPC call for creating a new child tab

This will be used for choosing a navigable that requires opening a new
tab or new window. Such as calls to window.open(), or specific WebDriver
calls.
This commit is contained in:
Andrew Kaster 2024-01-30 20:05:00 -07:00 committed by Tim Flynn
parent 7245f6f11c
commit 677bdc2a4f
17 changed files with 144 additions and 19 deletions

View file

@ -593,7 +593,8 @@ Tab::Tab(BrowserWindow& window)
update_status();
};
view().on_new_tab = [this](auto activate_tab) {
view().on_new_web_view = [this](auto activate_tab, auto, auto) {
// FIXME: Create a child tab that re-uses the ConnectionFromClient of the parent tab
auto& tab = this->window().create_new_tab(URL("about:blank"), activate_tab);
return tab.view().handle();
};

View file

@ -402,6 +402,7 @@ set(SOURCES
HTML/TraversableNavigable.cpp
HTML/VideoTrack.cpp
HTML/VideoTrackList.cpp
HTML/WebViewHints.cpp
HTML/Window.cpp
HTML/WindowEventHandlers.cpp
HTML/WindowOrWorkerGlobalScope.cpp

View file

@ -499,7 +499,7 @@ JS::GCPtr<DOM::Node> BrowsingContext::currently_focused_area()
}
// https://html.spec.whatwg.org/#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name
BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_context(StringView name, TokenizedFeature::NoOpener no_opener, ActivateTab activate_tab)
BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_context(StringView name, TokenizedFeature::NoOpener no_opener, ActivateTab)
{
// The rules for choosing a browsing context, given a browsing context name name, a browsing context current, and
// a boolean noopener are as follows:
@ -591,8 +591,8 @@ BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_contex
// 3. If noopener is true, then set chosen to the result of creating a new top-level browsing context.
if (no_opener == TokenizedFeature::NoOpener::Yes) {
auto handle = m_page->client().page_did_request_new_tab(activate_tab);
chosen = RemoteBrowsingContext::create_a_new_remote_browsing_context(handle);
// FIXME: This is completely wrong, but all of this should be removed in favor of choose_a_navigable
chosen = this;
}
// 4. Otherwise:

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibWeb/HTML/WebViewHints.h>
namespace IPC {
template<>
ErrorOr<void> encode(Encoder& encoder, ::Web::HTML::WebViewHints const& data_holder)
{
TRY(encoder.encode(data_holder.popup));
TRY(encoder.encode(data_holder.width));
TRY(encoder.encode(data_holder.height));
TRY(encoder.encode(data_holder.screen_x));
TRY(encoder.encode(data_holder.screen_y));
return {};
}
template<>
ErrorOr<::Web::HTML::WebViewHints> decode(Decoder& decoder)
{
auto popup = TRY(decoder.decode<bool>());
auto width = TRY(decoder.decode<Optional<Web::DevicePixels>>());
auto height = TRY(decoder.decode<Optional<Web::DevicePixels>>());
auto screen_x = TRY(decoder.decode<Optional<Web::DevicePixels>>());
auto screen_y = TRY(decoder.decode<Optional<Web::DevicePixels>>());
return ::Web::HTML::WebViewHints {
.popup = popup,
.width = width,
.height = height,
.screen_x = screen_x,
.screen_y = screen_y,
};
}
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/Types.h>
#include <LibIPC/Forward.h>
#include <LibWeb/PixelUnits.h>
namespace Web::HTML {
struct WebViewHints {
bool popup = false;
Optional<DevicePixels> width = {};
Optional<DevicePixels> height = {};
Optional<DevicePixels> screen_x = {};
Optional<DevicePixels> screen_y = {};
};
}
namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, Web::HTML::WebViewHints const&);
template<>
ErrorOr<Web::HTML::WebViewHints> decode(Decoder&);
}

View file

@ -32,6 +32,7 @@
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/HTML/ColorPickerUpdateState.h>
#include <LibWeb/HTML/SelectItem.h>
#include <LibWeb/HTML/WebViewHints.h>
#include <LibWeb/Loader/FileRequest.h>
#include <LibWeb/PixelUnits.h>
#include <LibWebView/SocketPair.h>
@ -268,7 +269,7 @@ public:
virtual void page_did_set_cookie(const AK::URL&, Cookie::ParsedCookie const&, Cookie::Source) { }
virtual void page_did_update_cookie(Web::Cookie::Cookie) { }
virtual void page_did_update_resource_count(i32) { }
virtual String page_did_request_new_tab(HTML::ActivateTab) { return {}; }
virtual String page_did_request_new_web_view(HTML::ActivateTab, HTML::WebViewHints, Optional<u64> = {}) { return {}; }
virtual void page_did_request_activate_tab() { }
virtual void page_did_close_browsing_context(HTML::BrowsingContext const&) { }

View file

@ -112,7 +112,7 @@ public:
Function<void(Gfx::IntSize)> on_did_layout;
Function<void()> on_ready_to_paint;
Function<String(Web::HTML::ActivateTab)> on_new_tab;
Function<String(Web::HTML::ActivateTab, Web::HTML::WebViewHints, Optional<u64>)> on_new_web_view;
Function<void()> on_activate_tab;
Function<void()> on_close;
Function<void(Gfx::IntPoint screen_position)> on_context_menu_request;

View file

@ -328,10 +328,10 @@ void WebContentClient::did_update_cookie(Web::Cookie::Cookie const& cookie)
m_view.on_update_cookie(cookie);
}
Messages::WebContentClient::DidRequestNewTabResponse WebContentClient::did_request_new_tab(Web::HTML::ActivateTab const& activate_tab)
Messages::WebContentClient::DidRequestNewWebViewResponse WebContentClient::did_request_new_web_view(Web::HTML::ActivateTab const& activate_tab, Web::HTML::WebViewHints const& hints, Optional<u64> const& page_index)
{
if (m_view.on_new_tab)
return m_view.on_new_tab(activate_tab);
if (m_view.on_new_web_view)
return m_view.on_new_web_view(activate_tab, hints, page_index);
return String {};
}

View file

@ -10,6 +10,7 @@
#include <LibIPC/ConnectionToServer.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/HTML/SelectItem.h>
#include <LibWeb/HTML/WebViewHints.h>
#include <WebContent/WebContentClientEndpoint.h>
#include <WebContent/WebContentServerEndpoint.h>
@ -73,7 +74,7 @@ private:
virtual Messages::WebContentClient::DidRequestCookieResponse did_request_cookie(AK::URL const&, Web::Cookie::Source) override;
virtual void did_set_cookie(AK::URL const&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override;
virtual void did_update_cookie(Web::Cookie::Cookie const&) override;
virtual Messages::WebContentClient::DidRequestNewTabResponse did_request_new_tab(Web::HTML::ActivateTab const& activate_tab) override;
virtual Messages::WebContentClient::DidRequestNewWebViewResponse did_request_new_web_view(Web::HTML::ActivateTab const&, Web::HTML::WebViewHints const&, Optional<u64> const& page_index) override;
virtual void did_request_activate_tab() override;
virtual void did_close_browsing_context() override;
virtual void did_update_resource_count(i32 count_waiting) override;

View file

@ -497,9 +497,14 @@ void PageClient::page_did_update_resource_count(i32 count_waiting)
client().async_did_update_resource_count(count_waiting);
}
String PageClient::page_did_request_new_tab(Web::HTML::ActivateTab activate_tab)
String PageClient::page_did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Optional<u64> page_index)
{
return client().did_request_new_tab(activate_tab);
auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidRequestNewWebView>(activate_tab, hints, page_index);
if (!response) {
dbgln("WebContent client disconnected during DidRequestNewWebView. Exiting peacefully.");
exit(0);
}
return response->take_handle();
}
void PageClient::page_did_request_activate_tab()

View file

@ -118,7 +118,7 @@ private:
virtual void page_did_set_cookie(const URL&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override;
virtual void page_did_update_cookie(Web::Cookie::Cookie) override;
virtual void page_did_update_resource_count(i32) override;
virtual String page_did_request_new_tab(Web::HTML::ActivateTab activate_tab) override;
virtual String page_did_request_new_web_view(Web::HTML::ActivateTab, Web::HTML::WebViewHints, Optional<u64> page_index = {}) override;
virtual void page_did_request_activate_tab() override;
virtual void page_did_close_browsing_context(Web::HTML::BrowsingContext const&) override;
virtual void request_file(Web::FileRequest) override;

View file

@ -7,6 +7,7 @@
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/HTML/SelectItem.h>
#include <LibWeb/HTML/WebViewHints.h>
#include <LibWeb/Page/Page.h>
#include <LibWebView/Attribute.h>
#include <LibWebView/SocketPair.h>
@ -58,7 +59,7 @@ endpoint WebContentClient
did_set_cookie(URL url, Web::Cookie::ParsedCookie cookie, Web::Cookie::Source source) => ()
did_update_cookie(Web::Cookie::Cookie cookie) =|
did_update_resource_count(i32 count_waiting) =|
did_request_new_tab(Web::HTML::ActivateTab activate_tab) => (String handle)
did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Optional<u64> page_index) => (String handle)
did_request_activate_tab() =|
did_close_browsing_context() =|
did_request_restore_window() =|