mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
Ladybird: Construct a WebDriverConnection when instructed to do so
The WebDriver will pass the --webdriver-fd-passing-socket command line option when it launches Ladybird. Forward this flag onto the WebContent process, where it will create the WebDriverConnection for IPC.
This commit is contained in:
parent
7021d30288
commit
4031630b49
Notes:
sideshowbarker
2024-07-17 02:39:24 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/4031630b49 Pull-request: https://github.com/SerenityOS/serenity/pull/16583 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling ✅ Reviewed-by: https://github.com/linusg
@ -21,7 +21,8 @@
|
||||
extern String s_serenity_resource_root;
|
||||
extern Browser::Settings* s_settings;
|
||||
|
||||
BrowserWindow::BrowserWindow()
|
||||
BrowserWindow::BrowserWindow(int webdriver_fd_passing_socket)
|
||||
: m_webdriver_fd_passing_socket(webdriver_fd_passing_socket)
|
||||
{
|
||||
m_tabs_container = new QTabWidget(this);
|
||||
m_tabs_container->setElideMode(Qt::TextElideMode::ElideRight);
|
||||
@ -282,7 +283,7 @@ void BrowserWindow::debug_request(String const& request, String const& argument)
|
||||
|
||||
void BrowserWindow::new_tab()
|
||||
{
|
||||
auto tab = make<Tab>(this);
|
||||
auto tab = make<Tab>(this, m_webdriver_fd_passing_socket);
|
||||
auto tab_ptr = tab.ptr();
|
||||
m_tabs.append(std::move(tab));
|
||||
|
||||
|
@ -22,7 +22,7 @@ class WebContentView;
|
||||
class BrowserWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BrowserWindow();
|
||||
explicit BrowserWindow(int webdriver_fd_passing_socket);
|
||||
|
||||
WebContentView& view() const { return m_current_tab->view(); }
|
||||
|
||||
@ -48,4 +48,6 @@ private:
|
||||
Tab* m_current_tab { nullptr };
|
||||
|
||||
Browser::CookieJar m_cookie_jar;
|
||||
|
||||
int m_webdriver_fd_passing_socket { -1 };
|
||||
};
|
||||
|
@ -20,7 +20,7 @@
|
||||
extern String s_serenity_resource_root;
|
||||
extern Browser::Settings* s_settings;
|
||||
|
||||
Tab::Tab(BrowserWindow* window)
|
||||
Tab::Tab(BrowserWindow* window, int webdriver_fd_passing_socket)
|
||||
: QWidget(window)
|
||||
, m_window(window)
|
||||
{
|
||||
@ -28,7 +28,7 @@ Tab::Tab(BrowserWindow* window)
|
||||
m_layout->setSpacing(0);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_view = new WebContentView;
|
||||
m_view = new WebContentView(webdriver_fd_passing_socket);
|
||||
m_toolbar = new QToolBar(this);
|
||||
m_location_edit = new QLineEdit(this);
|
||||
|
||||
@ -115,8 +115,13 @@ Tab::Tab(BrowserWindow* window)
|
||||
// FIXME: This is a hack to make the JS console usable in new windows.
|
||||
// Something else should ensure that there's an initial about:blank document loaded in the view.
|
||||
// We set m_is_history_navigation = true so that the initial about:blank doesn't get added to the history.
|
||||
m_is_history_navigation = true;
|
||||
m_view->load("about:blank"sv);
|
||||
//
|
||||
// Note we *don't* do this if we are connected to a WebDriver, as the Set URL command may come in very
|
||||
// quickly, and become replaced by this load.
|
||||
if (webdriver_fd_passing_socket == -1) {
|
||||
m_is_history_navigation = true;
|
||||
m_view->load("about:blank"sv);
|
||||
}
|
||||
}
|
||||
|
||||
void Tab::focus_location_editor()
|
||||
|
@ -22,7 +22,7 @@ class BrowserWindow;
|
||||
class Tab final : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Tab(BrowserWindow* window);
|
||||
Tab(BrowserWindow* window, int webdriver_fd_passing_socket);
|
||||
|
||||
WebContentView& view() { return *m_view; }
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <QSocketNotifier>
|
||||
#include <QTimer>
|
||||
#include <WebContent/ConnectionFromClient.h>
|
||||
#include <WebContent/WebDriverConnection.h>
|
||||
|
||||
static ErrorOr<void> load_content_filters();
|
||||
|
||||
@ -89,14 +90,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
dbgln("Failed to load content filters: {}", maybe_content_filter_error.error());
|
||||
|
||||
int webcontent_fd_passing_socket { -1 };
|
||||
int webdriver_fd_passing_socket { -1 };
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(webcontent_fd_passing_socket, "File descriptor of the passing socket for the WebContent connection", "webcontent-fd-passing-socket", 'c', "webcontent_fd_passing_socket");
|
||||
args_parser.add_option(webdriver_fd_passing_socket, "File descriptor of the passing socket for the WebDriver connection", "webdriver-fd-passing-socket", 'd', "webdriver_fd_passing_socket");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
QSocketNotifier webcontent_notifier(QSocketNotifier::Type::Read);
|
||||
auto webcontent_client = TRY(create_connection_from_passed_socket<WebContent::ConnectionFromClient>(webcontent_fd_passing_socket, "WebContent"sv, webcontent_notifier));
|
||||
|
||||
QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read);
|
||||
RefPtr<WebContent::WebDriverConnection> webdriver_client;
|
||||
if (webdriver_fd_passing_socket >= 0)
|
||||
webdriver_client = TRY(create_connection_from_passed_socket<WebContent::WebDriverConnection>(webdriver_fd_passing_socket, "WebDriver"sv, webdriver_notifier, *webcontent_client, webcontent_client->page_host()));
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,8 @@
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
WebContentView::WebContentView()
|
||||
WebContentView::WebContentView(int webdriver_fd_passing_socket)
|
||||
: m_webdriver_fd_passing_socket(webdriver_fd_passing_socket)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
|
||||
@ -589,12 +590,15 @@ void WebContentView::create_client()
|
||||
auto takeover_string = String::formatted("WebContent:{}", wc_fd);
|
||||
MUST(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
|
||||
|
||||
auto fd_passing_socket_string = String::number(wc_fd_passing_fd);
|
||||
auto webcontent_fd_passing_socket_string = String::number(wc_fd_passing_fd);
|
||||
auto webdriver_fd_passing_socket_string = String::number(m_webdriver_fd_passing_socket);
|
||||
|
||||
char const* argv[] = {
|
||||
"WebContent",
|
||||
"--webcontent-fd-passing-socket",
|
||||
fd_passing_socket_string.characters(),
|
||||
webcontent_fd_passing_socket_string.characters(),
|
||||
"--webdriver-fd-passing-socket",
|
||||
webdriver_fd_passing_socket_string.characters(),
|
||||
nullptr,
|
||||
};
|
||||
|
||||
|
@ -48,7 +48,7 @@ class WebContentView final
|
||||
, public WebView::ViewImplementation {
|
||||
Q_OBJECT
|
||||
public:
|
||||
WebContentView();
|
||||
explicit WebContentView(int webdriver_fd_passing_socket);
|
||||
virtual ~WebContentView() override;
|
||||
|
||||
void load(AK::URL const&);
|
||||
@ -201,4 +201,6 @@ private:
|
||||
} m_client_state;
|
||||
|
||||
RefPtr<Gfx::Bitmap> m_backup_bitmap;
|
||||
|
||||
int m_webdriver_fd_passing_socket { -1 };
|
||||
};
|
||||
|
@ -61,12 +61,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
Gfx::FontDatabase::set_fixed_width_font_query("Csilla 10 400 0");
|
||||
|
||||
StringView raw_url;
|
||||
int webdriver_fd_passing_socket { -1 };
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.set_general_help("The Ladybird web browser :^)");
|
||||
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
|
||||
args_parser.add_option(webdriver_fd_passing_socket, "File descriptor of the passing socket for the WebDriver connection", "webdriver-fd-passing-socket", 'd', "webdriver_fd_passing_socket");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
BrowserWindow window;
|
||||
BrowserWindow window(webdriver_fd_passing_socket);
|
||||
s_settings = new Browser::Settings(&window);
|
||||
window.setWindowTitle("Ladybird");
|
||||
window.resize(800, 600);
|
||||
|
Loading…
Reference in New Issue
Block a user