mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 22:55:06 +00:00
Browser+WebContent+WebDriver: Move Get Page Source to WebContent
This commit is contained in:
parent
561f9f36f7
commit
88dcdf681f
16 changed files with 26 additions and 61 deletions
|
@ -607,10 +607,6 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
||||||
return active_tab().view().take_screenshot();
|
return active_tab().view().take_screenshot();
|
||||||
};
|
};
|
||||||
|
|
||||||
new_tab.webdriver_endpoints().on_serialize_source = [this]() {
|
|
||||||
return active_tab().view().serialize_source();
|
|
||||||
};
|
|
||||||
|
|
||||||
new_tab.webdriver_endpoints().on_execute_script = [this](String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async) {
|
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);
|
return active_tab().view().webdriver_execute_script(body, json_arguments, timeout, async);
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,18 +58,6 @@ void WebDriverConnection::forward()
|
||||||
browser_window->active_tab().go_forward();
|
browser_window->active_tab().go_forward();
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages::WebDriverSessionClient::SerializeSourceResponse WebDriverConnection::serialize_source()
|
|
||||||
{
|
|
||||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection: serialize_source");
|
|
||||||
if (auto browser_window = m_browser_window.strong_ref()) {
|
|
||||||
auto& tab = browser_window->active_tab();
|
|
||||||
if (tab.webdriver_endpoints().on_serialize_source)
|
|
||||||
return { tab.webdriver_endpoints().on_serialize_source() };
|
|
||||||
}
|
|
||||||
|
|
||||||
return { {} };
|
|
||||||
}
|
|
||||||
|
|
||||||
Messages::WebDriverSessionClient::ExecuteScriptResponse WebDriverConnection::execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)
|
Messages::WebDriverSessionClient::ExecuteScriptResponse WebDriverConnection::execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)
|
||||||
{
|
{
|
||||||
dbgln("WebDriverConnection: execute_script");
|
dbgln("WebDriverConnection: execute_script");
|
||||||
|
|
|
@ -42,7 +42,6 @@ public:
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
virtual void back() override;
|
virtual void back() override;
|
||||||
virtual void forward() override;
|
virtual void forward() override;
|
||||||
virtual Messages::WebDriverSessionClient::SerializeSourceResponse serialize_source() 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::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;
|
||||||
|
|
|
@ -23,7 +23,6 @@ public:
|
||||||
WebDriverEndpoints() = default;
|
WebDriverEndpoints() = default;
|
||||||
~WebDriverEndpoints() = default;
|
~WebDriverEndpoints() = default;
|
||||||
|
|
||||||
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;
|
Function<Messages::WebContentServer::WebdriverExecuteScriptResponse(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)> on_execute_script;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ endpoint WebDriverSessionClient {
|
||||||
refresh() =|
|
refresh() =|
|
||||||
back() =|
|
back() =|
|
||||||
forward() =|
|
forward() =|
|
||||||
serialize_source() => (String source)
|
|
||||||
execute_script(String body, Vector<String> json_arguments, Optional<u64> timeout, bool async) => (Web::WebDriver::ExecuteScriptResultType result_type, String json_result)
|
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)
|
||||||
|
|
|
@ -481,11 +481,6 @@ void OutOfProcessWebView::get_source()
|
||||||
client().async_get_source();
|
client().async_get_source();
|
||||||
}
|
}
|
||||||
|
|
||||||
String OutOfProcessWebView::serialize_source()
|
|
||||||
{
|
|
||||||
return client().serialize_source();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutOfProcessWebView::inspect_dom_tree()
|
void OutOfProcessWebView::inspect_dom_tree()
|
||||||
{
|
{
|
||||||
client().async_inspect_dom_tree();
|
client().async_inspect_dom_tree();
|
||||||
|
|
|
@ -37,7 +37,6 @@ public:
|
||||||
|
|
||||||
void debug_request(String const& request, String const& argument = {});
|
void debug_request(String const& request, String const& argument = {});
|
||||||
void get_source();
|
void get_source();
|
||||||
String serialize_source();
|
|
||||||
|
|
||||||
void inspect_dom_tree();
|
void inspect_dom_tree();
|
||||||
struct DOMNodeProperties {
|
struct DOMNodeProperties {
|
||||||
|
|
|
@ -263,20 +263,6 @@ void ConnectionFromClient::get_source()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages::WebContentServer::SerializeSourceResponse ConnectionFromClient::serialize_source()
|
|
||||||
{
|
|
||||||
if (auto* doc = page().top_level_browsing_context().active_document()) {
|
|
||||||
auto result = doc->serialize_fragment(Web::DOMParsing::RequireWellFormed::Yes);
|
|
||||||
if (!result.is_error())
|
|
||||||
return { result.release_value() };
|
|
||||||
|
|
||||||
auto source = MUST(doc->serialize_fragment(Web::DOMParsing::RequireWellFormed::No));
|
|
||||||
return { move(source) };
|
|
||||||
}
|
|
||||||
|
|
||||||
return { {} };
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConnectionFromClient::inspect_dom_tree()
|
void ConnectionFromClient::inspect_dom_tree()
|
||||||
{
|
{
|
||||||
if (auto* doc = page().top_level_browsing_context().active_document()) {
|
if (auto* doc = page().top_level_browsing_context().active_document()) {
|
||||||
|
|
|
@ -64,7 +64,6 @@ private:
|
||||||
virtual void remove_backing_store(i32) override;
|
virtual void remove_backing_store(i32) override;
|
||||||
virtual void debug_request(String const&, String const&) override;
|
virtual void debug_request(String const&, String const&) override;
|
||||||
virtual void get_source() override;
|
virtual void get_source() override;
|
||||||
virtual Messages::WebContentServer::SerializeSourceResponse serialize_source() override;
|
|
||||||
virtual void inspect_dom_tree() override;
|
virtual void inspect_dom_tree() override;
|
||||||
virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element) override;
|
virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element) override;
|
||||||
virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
|
virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
|
||||||
|
|
|
@ -35,7 +35,6 @@ endpoint WebContentServer
|
||||||
|
|
||||||
debug_request(String request, String argument) =|
|
debug_request(String request, String argument) =|
|
||||||
get_source() =|
|
get_source() =|
|
||||||
serialize_source() => (String source)
|
|
||||||
inspect_dom_tree() =|
|
inspect_dom_tree() =|
|
||||||
inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element) => (bool has_style, String specified_style, String computed_style, String custom_properties, String node_box_sizing)
|
inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element) => (bool has_style, String specified_style, String computed_style, String custom_properties, String node_box_sizing)
|
||||||
get_hovered_node_id() => (i32 node_id)
|
get_hovered_node_id() => (i32 node_id)
|
||||||
|
|
|
@ -21,6 +21,7 @@ endpoint WebDriverClient {
|
||||||
get_element_tag_name(String element_id) => (Web::WebDriver::Response response)
|
get_element_tag_name(String element_id) => (Web::WebDriver::Response response)
|
||||||
get_element_rect(String element_id) => (Web::WebDriver::Response response)
|
get_element_rect(String element_id) => (Web::WebDriver::Response response)
|
||||||
is_element_enabled(String element_id) => (Web::WebDriver::Response response)
|
is_element_enabled(String element_id) => (Web::WebDriver::Response response)
|
||||||
|
get_source() => (Web::WebDriver::Response response)
|
||||||
take_screenshot() => (Web::WebDriver::Response response)
|
take_screenshot() => (Web::WebDriver::Response response)
|
||||||
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
|
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
|
||||||
}
|
}
|
||||||
|
|
|
@ -731,6 +731,29 @@ Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_elem
|
||||||
return make_success_response(enabled);
|
return make_success_response(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
|
||||||
|
Messages::WebDriverClient::GetSourceResponse WebDriverConnection::get_source()
|
||||||
|
{
|
||||||
|
// 1. If the current browsing context is no longer open, return error with error code no such window.
|
||||||
|
TRY(ensure_open_top_level_browsing_context());
|
||||||
|
|
||||||
|
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
||||||
|
|
||||||
|
auto* document = m_page_host.page().top_level_browsing_context().active_document();
|
||||||
|
Optional<String> source;
|
||||||
|
|
||||||
|
// 3. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only child is the document element providing true for the require well-formed flag. If this causes an exception to be thrown, let source be null.
|
||||||
|
if (auto result = document->serialize_fragment(Web::DOMParsing::RequireWellFormed::Yes); !result.is_error())
|
||||||
|
source = result.release_value();
|
||||||
|
|
||||||
|
// 4. Let source be the result of serializing to string the current browsing context active document, if source is null.
|
||||||
|
if (!source.has_value())
|
||||||
|
source = MUST(document->serialize_fragment(Web::DOMParsing::RequireWellFormed::No));
|
||||||
|
|
||||||
|
// 5. Return success with data source.
|
||||||
|
return make_success_response(source.release_value());
|
||||||
|
}
|
||||||
|
|
||||||
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
||||||
Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
|
Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override;
|
virtual Messages::WebDriverClient::GetElementTagNameResponse get_element_tag_name(String const& element_id) override;
|
||||||
virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(String const& element_id) override;
|
virtual Messages::WebDriverClient::GetElementRectResponse get_element_rect(String const& element_id) override;
|
||||||
virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(String const& element_id) override;
|
virtual Messages::WebDriverClient::IsElementEnabledResponse is_element_enabled(String const& element_id) override;
|
||||||
|
virtual Messages::WebDriverClient::GetSourceResponse get_source() override;
|
||||||
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
|
||||||
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
|
||||||
|
|
||||||
|
|
|
@ -726,8 +726,7 @@ Web::WebDriver::Response Client::handle_get_source(Vector<StringView> const& par
|
||||||
{
|
{
|
||||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/source");
|
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/source");
|
||||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||||
auto result = TRY(session->get_source());
|
return session->web_content_connection().get_source();
|
||||||
return make_json_value(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.2.1 Execute Script, https://w3c.github.io/webdriver/#dfn-execute-script
|
// 13.2.1 Execute Script, https://w3c.github.io/webdriver/#dfn-execute-script
|
||||||
|
|
|
@ -297,23 +297,6 @@ Web::WebDriver::Response Session::get_window_handles() const
|
||||||
return JsonValue { handles };
|
return JsonValue { handles };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source
|
|
||||||
Web::WebDriver::Response Session::get_source()
|
|
||||||
{
|
|
||||||
// 1. If the current browsing context is no longer open, return error with error code no such window.
|
|
||||||
TRY(check_for_open_top_level_browsing_context_or_return_error());
|
|
||||||
|
|
||||||
// FIXME: 2. Handle any user prompts and return its value if it is an error.
|
|
||||||
|
|
||||||
// 3. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only child is the document element providing true for the require well-formed flag. If this causes an exception to be thrown, let source be null.
|
|
||||||
// 4. Let source be the result of serializing to string the current browsing context active document, if source is null.
|
|
||||||
// NOTE: Both of the above cases are handled in the remote WebContent process.
|
|
||||||
auto source = m_browser_connection->serialize_source();
|
|
||||||
|
|
||||||
// 5. Return success with data source.
|
|
||||||
return JsonValue { source };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ScriptArguments {
|
struct ScriptArguments {
|
||||||
String script;
|
String script;
|
||||||
JsonArray const& arguments;
|
JsonArray const& arguments;
|
||||||
|
|
|
@ -58,7 +58,6 @@ public:
|
||||||
Web::WebDriver::Response get_window_handle();
|
Web::WebDriver::Response get_window_handle();
|
||||||
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
|
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
|
||||||
Web::WebDriver::Response get_window_handles() const;
|
Web::WebDriver::Response get_window_handles() const;
|
||||||
Web::WebDriver::Response get_source();
|
|
||||||
Web::WebDriver::Response execute_script(JsonValue const& payload);
|
Web::WebDriver::Response execute_script(JsonValue const& payload);
|
||||||
Web::WebDriver::Response execute_async_script(JsonValue const& payload);
|
Web::WebDriver::Response execute_async_script(JsonValue const& payload);
|
||||||
Web::WebDriver::Response get_all_cookies();
|
Web::WebDriver::Response get_all_cookies();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue