From 56811157446cbd79757245e26fc565842cd25fe9 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 12 Oct 2022 23:51:37 +0200 Subject: [PATCH] Browser: Set 'webdriver-active flag' when creating a new Tab --- Userland/Applications/Browser/Browser.h | 2 ++ Userland/Applications/Browser/Tab.cpp | 3 +++ Userland/Applications/Browser/main.cpp | 12 +++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Browser/Browser.h b/Userland/Applications/Browser/Browser.h index 14d7e7d3045..f6370730145 100644 --- a/Userland/Applications/Browser/Browser.h +++ b/Userland/Applications/Browser/Browser.h @@ -8,6 +8,7 @@ #include #include +#include namespace Browser { @@ -19,5 +20,6 @@ extern Vector g_proxies; extern HashMap g_proxy_mappings; extern bool g_content_filters_enabled; extern IconBag g_icon_bag; +extern RefPtr g_web_driver_connection; } diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 33c7d73a1d5..1306e1f0dfa 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -127,6 +127,9 @@ Tab::Tab(BrowserWindow& window) m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings); + if (!g_web_driver_connection.is_null()) + m_web_content_view->set_is_webdriver_active(true); + auto& go_back_button = toolbar.add_action(window.go_back_action()); go_back_button.on_context_menu_request = [&](auto&) { if (!m_history.can_go_back()) diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index f8d83a05b61..66f5d9a9501 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,7 @@ bool g_content_filters_enabled { true }; Vector g_proxies; HashMap g_proxy_mappings; IconBag g_icon_bag; +RefPtr g_web_driver_connection; } @@ -144,10 +146,14 @@ ErrorOr serenity_main(Main::Arguments arguments) Browser::CookieJar cookie_jar; auto window = Browser::BrowserWindow::construct(cookie_jar, first_url); - RefPtr web_driver_connection; - if (!webdriver_ipc_path.is_empty()) - web_driver_connection = TRY(Browser::WebDriverConnection::connect_to_webdriver(window, webdriver_ipc_path)); + if (!webdriver_ipc_path.is_empty()) { + Browser::g_web_driver_connection = TRY(Browser::WebDriverConnection::connect_to_webdriver(window, webdriver_ipc_path)); + + // The first tab is created with the BrowserWindow above, so we have to do this + // manually once after establishing the connection. + window->active_tab().view().set_is_webdriver_active(true); + } auto content_filters_watcher = TRY(Core::FileWatcher::create()); content_filters_watcher->on_change = [&](Core::FileWatcherEvent const&) {