diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 60757e6ee5..180427f9d5 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -582,6 +582,14 @@ void BrowserWindow::create_new_tab(URL url, bool activate) return active_tab().view().get_session_storage_entries(); }; + new_tab.on_get_document_element = [this]() { + return active_tab().view().get_document_element(); + }; + + new_tab.on_query_selector_all = [this](i32 start_node_id, String const& selector) { + return active_tab().view().query_selector_all(start_node_id, selector); + }; + new_tab.load(url); dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url); diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 7d176c455a..b0489b679c 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -68,6 +68,8 @@ public: Function()> on_get_cookies_entries; Function()> on_get_local_storage_entries; Function()> on_get_session_storage_entries; + Function()> on_get_document_element; + Function>(i32 start_node_id, String const&)> on_query_selector_all; enum class InspectorTarget { Document, diff --git a/Userland/Applications/Browser/WebDriverConnection.cpp b/Userland/Applications/Browser/WebDriverConnection.cpp index 0ffd65df22..5097b98bfc 100644 --- a/Userland/Applications/Browser/WebDriverConnection.cpp +++ b/Userland/Applications/Browser/WebDriverConnection.cpp @@ -121,4 +121,26 @@ void WebDriverConnection::update_cookie(Web::Cookie::Cookie const& cookie) } } +Messages::WebDriverSessionClient::GetDocumentElementResponse WebDriverConnection::get_document_element() +{ + dbgln("WebDriverConnection: get_document_element"); + if (auto browser_window = m_browser_window.strong_ref()) { + auto& tab = browser_window->active_tab(); + if (tab.on_get_document_element) + return { tab.on_get_document_element() }; + } + return { {} }; +} + +Messages::WebDriverSessionClient::QuerySelectorAllResponse WebDriverConnection::query_selector_all(i32 start_node_id, String const& selector) +{ + dbgln("WebDriverConnection: query_selector_all"); + if (auto browser_window = m_browser_window.strong_ref()) { + auto& tab = browser_window->active_tab(); + if (tab.on_query_selector_all) + return { tab.on_query_selector_all(start_node_id, selector) }; + } + return { {} }; +} + } diff --git a/Userland/Applications/Browser/WebDriverConnection.h b/Userland/Applications/Browser/WebDriverConnection.h index 263984cd3a..ac47d60d0a 100644 --- a/Userland/Applications/Browser/WebDriverConnection.h +++ b/Userland/Applications/Browser/WebDriverConnection.h @@ -47,6 +47,8 @@ public: virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override; virtual void add_cookie(Web::Cookie::ParsedCookie const&) override; virtual void update_cookie(Web::Cookie::Cookie const&) override; + virtual Messages::WebDriverSessionClient::GetDocumentElementResponse get_document_element() override; + virtual Messages::WebDriverSessionClient::QuerySelectorAllResponse query_selector_all(i32 start_node_id, String const& selector) override; private: WebDriverConnection(NonnullOwnPtr socket, NonnullRefPtr browser_window); diff --git a/Userland/Applications/Browser/WebDriverSessionClient.ipc b/Userland/Applications/Browser/WebDriverSessionClient.ipc index 457bc43610..f2f4ec9a84 100644 --- a/Userland/Applications/Browser/WebDriverSessionClient.ipc +++ b/Userland/Applications/Browser/WebDriverSessionClient.ipc @@ -16,5 +16,7 @@ endpoint WebDriverSessionClient { get_named_cookie(String name) => (Optional cookie) add_cookie(Web::Cookie::ParsedCookie cookie) =| update_cookie(Web::Cookie::Cookie cookie) =| + get_document_element() => (Optional document_element_id) + query_selector_all(i32 start_node_id, String selector) => (Optional> elements_ids) } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index f51b8a0a52..dc934da070 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -515,6 +515,16 @@ OrderedHashMap OutOfProcessWebView::get_session_storage_entries( return client().get_session_storage_entries(); } +Optional OutOfProcessWebView::get_document_element() +{ + return client().get_document_element(); +} + +Optional> OutOfProcessWebView::query_selector_all(i32 start_node_id, String const& selector) +{ + return client().query_selector_all(start_node_id, selector); +} + void OutOfProcessWebView::set_content_filters(Vector filters) { client().async_set_content_filters(filters); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index d8a2878696..90765ef547 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -58,6 +58,9 @@ public: OrderedHashMap get_local_storage_entries(); OrderedHashMap get_session_storage_entries(); + Optional get_document_element(); + Optional> query_selector_all(i32 start_node_id, String const& selector); + void set_content_filters(Vector); void set_proxy_mappings(Vector proxies, HashMap mappings); void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);