1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:17:45 +00:00

Browser+WebDriver: Remove the connection between Browser and WebDriver

WebDriver now only has an IPC connection to WebContent. WebDriver still
launches the browser, but now when the session ends, we simply send a
SIGTERM signal to the browser.
This commit is contained in:
Timothy Flynn 2022-11-11 14:14:58 -05:00 committed by Linus Groh
parent c64da0d00c
commit 7972916be7
11 changed files with 20 additions and 219 deletions

View file

@ -8,7 +8,6 @@
#include <AK/String.h>
#include <Applications/Browser/IconBag.h>
#include <Applications/Browser/WebDriverConnection.h>
namespace Browser {
@ -20,7 +19,6 @@ extern Vector<String> g_proxies;
extern HashMap<String, size_t> g_proxy_mappings;
extern bool g_content_filters_enabled;
extern IconBag g_icon_bag;
extern RefPtr<Browser::WebDriverConnection> g_web_driver_connection;
extern String g_webdriver_content_ipc_path;
}

View file

@ -5,9 +5,6 @@ serenity_component(
DEPENDS BrowserSettings ImageDecoder RequestServer WebContent WebSocket
)
compile_ipc(WebDriverSessionServer.ipc WebDriverSessionServerEndpoint.h)
compile_ipc(WebDriverSessionClient.ipc WebDriverSessionClientEndpoint.h)
compile_gml(BrowserWindow.gml BrowserWindowGML.h browser_window_gml)
compile_gml(EditBookmark.gml EditBookmarkGML.h edit_bookmark_gml)
compile_gml(StorageWidget.gml StorageWidgetGML.h storage_widget_gml)
@ -27,7 +24,6 @@ set(SOURCES
StorageModel.cpp
StorageWidget.cpp
Tab.cpp
WebDriverConnection.cpp
WindowActions.cpp
main.cpp
)
@ -37,8 +33,6 @@ set(GENERATED_SOURCES
EditBookmarkGML.h
StorageWidgetGML.h
TabGML.h
WebDriverSessionClientEndpoint.h
WebDriverSessionServerEndpoint.h
)
serenity_app(Browser ICON app-browser)

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "WebDriverConnection.h"
#include "BrowserWindow.h"
#include <AK/Vector.h>
#include <LibWebView/WebContentClient.h>
namespace Browser {
WebDriverConnection::WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window)
: IPC::ConnectionToServer<WebDriverSessionClientEndpoint, WebDriverSessionServerEndpoint>(*this, move(socket))
, m_browser_window(move(browser_window))
{
}
void WebDriverConnection::quit()
{
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: quit");
if (auto browser_window = m_browser_window.strong_ref())
browser_window->close();
}
}

View file

@ -1,48 +0,0 @@
/*
* Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "BrowserWindow.h"
#include <AK/Error.h>
#include <AK/String.h>
#include <Applications/Browser/WebDriverSessionClientEndpoint.h>
#include <Applications/Browser/WebDriverSessionServerEndpoint.h>
#include <LibCore/LocalServer.h>
#include <LibGUI/Application.h>
#include <LibIPC/ConnectionToServer.h>
#include <unistd.h>
namespace Browser {
class WebDriverConnection final
: public IPC::ConnectionToServer<WebDriverSessionClientEndpoint, WebDriverSessionServerEndpoint> {
C_OBJECT_ABSTRACT(WebDriverConnection)
public:
static ErrorOr<NonnullRefPtr<WebDriverConnection>> connect_to_webdriver(NonnullRefPtr<BrowserWindow> browser_window, String path)
{
dbgln_if(WEBDRIVER_DEBUG, "Trying to connect to {}", path);
auto result = TRY(Core::Stream::LocalSocket::connect(path));
dbgln_if(WEBDRIVER_DEBUG, "Connected to WebDriver");
return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WebDriverConnection(move(result), browser_window)));
}
virtual ~WebDriverConnection() = default;
virtual void die() override { }
virtual void quit() override;
private:
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);
WeakPtr<BrowserWindow> m_browser_window;
};
}

View file

@ -1,16 +0,0 @@
#include <AK/URL.h>
#include <AK/Vector.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
#include <LibGfx/ShareableBitmap.h>
#include <LibGfx/Size.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/WebDriver/ExecuteScript.h>
// FIXME: This isn't used here, but the generated IPC fails to compile without this include.
#include <LibWeb/WebDriver/Response.h>
endpoint WebDriverSessionClient {
quit() =|
}

View file

@ -11,7 +11,6 @@
#include <Applications/Browser/BrowserWindow.h>
#include <Applications/Browser/CookieJar.h>
#include <Applications/Browser/Tab.h>
#include <Applications/Browser/WebDriverConnection.h>
#include <Applications/Browser/WindowActions.h>
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
@ -40,7 +39,6 @@ bool g_content_filters_enabled { true };
Vector<String> g_proxies;
HashMap<String, size_t> g_proxy_mappings;
IconBag g_icon_bag;
RefPtr<Browser::WebDriverConnection> g_web_driver_connection;
String g_webdriver_content_ipc_path;
}
@ -69,11 +67,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio recvfd sendfd unix fattr cpath rpath wpath proc exec"));
Vector<String> specified_urls;
String webdriver_browser_ipc_path;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(specified_urls, "URLs to open", "url", Core::ArgsParser::Required::No);
args_parser.add_option(webdriver_browser_ipc_path, "Path to WebDriver IPC file for Browser", "webdriver-browser-path", 0, "path");
args_parser.add_option(Browser::g_webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path");
args_parser.parse(arguments);
@ -89,10 +85,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Desktop::Launcher::add_allowed_url(URL::create_with_file_scheme(Core::StandardPaths::downloads_directory())));
TRY(Desktop::Launcher::seal_allowlist());
if (!webdriver_browser_ipc_path.is_empty()) {
if (!Browser::g_webdriver_content_ipc_path.is_empty())
specified_urls.empend("about:blank");
TRY(Core::System::unveil(webdriver_browser_ipc_path, "rw"sv));
}
TRY(Core::System::unveil("/sys/kernel/processes", "r"));
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
@ -149,9 +143,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Browser::CookieJar cookie_jar;
auto window = Browser::BrowserWindow::construct(cookie_jar, first_url);
if (!webdriver_browser_ipc_path.is_empty())
Browser::g_web_driver_connection = TRY(Browser::WebDriverConnection::connect_to_webdriver(window, webdriver_browser_ipc_path));
auto content_filters_watcher = TRY(Core::FileWatcher::create());
content_filters_watcher->on_change = [&](Core::FileWatcherEvent const&) {
dbgln("Reloading content filters because config file changed");