mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 12:55:08 +00:00
Browser+LibWebView: Add WebDriver IPC plumbing for executing scripts
This commit is contained in:
parent
b572a91a6f
commit
747ba2a88f
7 changed files with 40 additions and 0 deletions
|
@ -42,6 +42,7 @@
|
||||||
#include <LibWeb/Layout/InitialContainingBlock.h>
|
#include <LibWeb/Layout/InitialContainingBlock.h>
|
||||||
#include <LibWeb/Loader/ResourceLoader.h>
|
#include <LibWeb/Loader/ResourceLoader.h>
|
||||||
#include <LibWebView/OutOfProcessWebView.h>
|
#include <LibWebView/OutOfProcessWebView.h>
|
||||||
|
#include <LibWebView/WebContentClient.h>
|
||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
|
@ -630,6 +631,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
||||||
return active_tab().view().get_element_tag_name(element_id);
|
return active_tab().view().get_element_tag_name(element_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
new_tab.webdriver_endpoints().on_execute_script = [this](String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async) {
|
||||||
|
return active_tab().view().webdriver_execute_script(body, json_arguments, timeout, async);
|
||||||
|
};
|
||||||
|
|
||||||
new_tab.load(url);
|
new_tab.load(url);
|
||||||
|
|
||||||
dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url);
|
dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibWeb/Cookie/Cookie.h>
|
#include <LibWeb/Cookie/Cookie.h>
|
||||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||||
|
#include <LibWebView/WebContentClient.h>
|
||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
|
@ -116,6 +117,21 @@ void WebDriverConnection::minimize_window()
|
||||||
browser_window->set_minimized(true);
|
browser_window->set_minimized(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Messages::WebDriverSessionClient::ExecuteScriptResponse WebDriverConnection::execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)
|
||||||
|
{
|
||||||
|
dbgln("WebDriverConnection: execute_script");
|
||||||
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
|
auto& tab = browser_window->active_tab();
|
||||||
|
if (tab.webdriver_endpoints().on_execute_script) {
|
||||||
|
auto response = tab.webdriver_endpoints().on_execute_script(body, json_arguments, timeout, async);
|
||||||
|
// WebContentServer's and WebDriverSessionClient's ExecuteScriptResponse have an identical
|
||||||
|
// structure but are distinct types, so we have to convert here.
|
||||||
|
return { response.result_type(), response.json_result() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { {} };
|
||||||
|
}
|
||||||
|
|
||||||
Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
|
Messages::WebDriverSessionClient::GetAllCookiesResponse WebDriverConnection::get_all_cookies()
|
||||||
{
|
{
|
||||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies");
|
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: get_cookies");
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
virtual void set_window_position(Gfx::IntPoint const&) override;
|
virtual void set_window_position(Gfx::IntPoint const&) override;
|
||||||
virtual void maximize_window() override;
|
virtual void maximize_window() override;
|
||||||
virtual void minimize_window() override;
|
virtual void minimize_window() override;
|
||||||
|
virtual Messages::WebDriverSessionClient::ExecuteScriptResponse execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async) override;
|
||||||
virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override;
|
virtual Messages::WebDriverSessionClient::GetAllCookiesResponse get_all_cookies() override;
|
||||||
virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
||||||
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
|
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
|
namespace Messages::WebContentServer {
|
||||||
|
class WebdriverExecuteScriptResponse;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
class WebDriverEndpoints {
|
class WebDriverEndpoints {
|
||||||
|
@ -25,6 +29,7 @@ public:
|
||||||
Function<String(i32 element_id, String const&)> on_get_computed_value_for_element;
|
Function<String(i32 element_id, String const&)> on_get_computed_value_for_element;
|
||||||
Function<String(i32 element_id)> on_get_element_text;
|
Function<String(i32 element_id)> on_get_element_text;
|
||||||
Function<String(i32 element_id)> on_get_element_tag_name;
|
Function<String(i32 element_id)> on_get_element_tag_name;
|
||||||
|
Function<Messages::WebContentServer::WebdriverExecuteScriptResponse(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)> on_execute_script;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <LibGfx/Size.h>
|
#include <LibGfx/Size.h>
|
||||||
#include <LibWeb/Cookie/Cookie.h>
|
#include <LibWeb/Cookie/Cookie.h>
|
||||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||||
|
#include <LibWeb/WebDriver/ExecuteScript.h>
|
||||||
|
|
||||||
endpoint WebDriverSessionClient {
|
endpoint WebDriverSessionClient {
|
||||||
quit() =|
|
quit() =|
|
||||||
|
@ -22,6 +23,7 @@ endpoint WebDriverSessionClient {
|
||||||
set_window_position(Gfx::IntPoint position) =|
|
set_window_position(Gfx::IntPoint position) =|
|
||||||
maximize_window() =|
|
maximize_window() =|
|
||||||
minimize_window() =|
|
minimize_window() =|
|
||||||
|
execute_script(String body, Vector<String> json_arguments, Optional<u64> timeout, bool async) => (Web::WebDriver::ExecuteScriptResultType result_type, String json_result)
|
||||||
get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
|
get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
|
||||||
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
|
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
|
||||||
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
||||||
|
|
|
@ -592,6 +592,11 @@ Gfx::ShareableBitmap OutOfProcessWebView::take_screenshot() const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Messages::WebContentServer::WebdriverExecuteScriptResponse OutOfProcessWebView::webdriver_execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)
|
||||||
|
{
|
||||||
|
return client().webdriver_execute_script(body, json_arguments, timeout, async);
|
||||||
|
}
|
||||||
|
|
||||||
void OutOfProcessWebView::focusin_event(GUI::FocusEvent&)
|
void OutOfProcessWebView::focusin_event(GUI::FocusEvent&)
|
||||||
{
|
{
|
||||||
client().async_set_has_focus(true);
|
client().async_set_has_focus(true);
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
#include <LibWeb/Page/Page.h>
|
#include <LibWeb/Page/Page.h>
|
||||||
#include <LibWebView/ViewImplementation.h>
|
#include <LibWebView/ViewImplementation.h>
|
||||||
|
|
||||||
|
namespace Messages::WebContentServer {
|
||||||
|
class WebdriverExecuteScriptResponse;
|
||||||
|
}
|
||||||
|
|
||||||
namespace WebView {
|
namespace WebView {
|
||||||
|
|
||||||
class WebContentClient;
|
class WebContentClient;
|
||||||
|
@ -77,6 +81,8 @@ public:
|
||||||
|
|
||||||
Gfx::ShareableBitmap take_screenshot() const;
|
Gfx::ShareableBitmap take_screenshot() const;
|
||||||
|
|
||||||
|
Messages::WebContentServer::WebdriverExecuteScriptResponse webdriver_execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async);
|
||||||
|
|
||||||
Function<void(Gfx::IntPoint const& screen_position)> on_context_menu_request;
|
Function<void(Gfx::IntPoint const& screen_position)> on_context_menu_request;
|
||||||
Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_click;
|
Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_click;
|
||||||
Function<void(const AK::URL&, Gfx::IntPoint const& screen_position)> on_link_context_menu_request;
|
Function<void(const AK::URL&, Gfx::IntPoint const& screen_position)> on_link_context_menu_request;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue