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

Browser+WebContent+WebDriver: Move Take Element Screenshot to WebContent

This commit is contained in:
Timothy Flynn 2022-11-10 13:33:18 -05:00 committed by Linus Groh
parent de1e882601
commit ea0561a0b3
15 changed files with 51 additions and 185 deletions

View file

@ -607,10 +607,6 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
return active_tab().view().take_screenshot();
};
new_tab.webdriver_endpoints().on_scroll_element_into_view = [this](i32 element_id) {
active_tab().view().scroll_element_into_view(element_id);
};
new_tab.webdriver_endpoints().on_serialize_source = [this]() {
return active_tab().view().serialize_source();
};
@ -619,10 +615,6 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
return active_tab().view().webdriver_execute_script(body, json_arguments, timeout, async);
};
new_tab.webdriver_endpoints().on_take_element_screenshot = [this](i32 element_id) {
return active_tab().view().take_element_screenshot(element_id);
};
new_tab.load(url);
dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url);

View file

@ -136,26 +136,4 @@ void WebDriverConnection::update_cookie(Web::Cookie::Cookie const& cookie)
}
}
void WebDriverConnection::scroll_element_into_view(i32 element_id)
{
dbgln("WebDriverConnection: scroll_element_into_view {}", element_id);
if (auto browser_window = m_browser_window.strong_ref()) {
auto& tab = browser_window->active_tab();
if (tab.webdriver_endpoints().on_scroll_element_into_view)
tab.webdriver_endpoints().on_scroll_element_into_view(element_id);
}
}
Messages::WebDriverSessionClient::TakeElementScreenshotResponse WebDriverConnection::take_element_screenshot(i32 element_id)
{
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: take_element_screenshot {}", element_id);
if (auto browser_window = m_browser_window.strong_ref()) {
auto& tab = browser_window->active_tab();
if (tab.webdriver_endpoints().on_take_element_screenshot)
return { tab.webdriver_endpoints().on_take_element_screenshot(element_id) };
}
return { {} };
}
}

View file

@ -48,8 +48,6 @@ 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 void scroll_element_into_view(i32 element_id) override;
virtual Messages::WebDriverSessionClient::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override;
private:
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);

View file

@ -23,8 +23,6 @@ public:
WebDriverEndpoints() = default;
~WebDriverEndpoints() = default;
Function<void(i32 element_id)> on_scroll_element_into_view;
Function<Gfx::ShareableBitmap(i32 element_id)> on_take_element_screenshot;
Function<String()> on_serialize_source;
Function<Messages::WebContentServer::WebdriverExecuteScriptResponse(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)> on_execute_script;
};

View file

@ -24,6 +24,4 @@ endpoint WebDriverSessionClient {
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
add_cookie(Web::Cookie::ParsedCookie cookie) =|
update_cookie(Web::Cookie::Cookie cookie) =|
scroll_element_into_view(i32 element_id) => ()
take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data)
}