1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:15:07 +00:00

Browser+WebContent+WebDriver: Move Get Page Source to WebContent

This commit is contained in:
Timothy Flynn 2022-11-10 18:00:01 -05:00 committed by Linus Groh
parent 561f9f36f7
commit 88dcdf681f
16 changed files with 26 additions and 61 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_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) {
return active_tab().view().webdriver_execute_script(body, json_arguments, timeout, async);
};

View file

@ -58,18 +58,6 @@ void WebDriverConnection::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)
{
dbgln("WebDriverConnection: execute_script");

View file

@ -42,7 +42,6 @@ public:
virtual void refresh() override;
virtual void back() 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::GetAllCookiesResponse get_all_cookies() override;
virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;

View file

@ -23,7 +23,6 @@ public:
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;
};

View file

@ -18,7 +18,6 @@ endpoint WebDriverSessionClient {
refresh() =|
back() =|
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)
get_all_cookies() => (Vector<Web::Cookie::Cookie> cookies)
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)

View file

@ -481,11 +481,6 @@ void OutOfProcessWebView::get_source()
client().async_get_source();
}
String OutOfProcessWebView::serialize_source()
{
return client().serialize_source();
}
void OutOfProcessWebView::inspect_dom_tree()
{
client().async_inspect_dom_tree();

View file

@ -37,7 +37,6 @@ public:
void debug_request(String const& request, String const& argument = {});
void get_source();
String serialize_source();
void inspect_dom_tree();
struct DOMNodeProperties {

View file

@ -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()
{
if (auto* doc = page().top_level_browsing_context().active_document()) {

View file

@ -64,7 +64,6 @@ private:
virtual void remove_backing_store(i32) override;
virtual void debug_request(String const&, String const&) override;
virtual void get_source() override;
virtual Messages::WebContentServer::SerializeSourceResponse serialize_source() 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::GetHoveredNodeIdResponse get_hovered_node_id() override;

View file

@ -35,7 +35,6 @@ endpoint WebContentServer
debug_request(String request, String argument) =|
get_source() =|
serialize_source() => (String source)
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)
get_hovered_node_id() => (i32 node_id)

View file

@ -21,6 +21,7 @@ endpoint WebDriverClient {
get_element_tag_name(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)
get_source() => (Web::WebDriver::Response response)
take_screenshot() => (Web::WebDriver::Response response)
take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
}

View file

@ -731,6 +731,29 @@ Messages::WebDriverClient::IsElementEnabledResponse WebDriverConnection::is_elem
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
Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot()
{

View file

@ -51,6 +51,7 @@ private:
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::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::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;

View file

@ -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");
auto* session = TRY(find_session_with_id(parameters[0]));
auto result = TRY(session->get_source());
return make_json_value(result);
return session->web_content_connection().get_source();
}
// 13.2.1 Execute Script, https://w3c.github.io/webdriver/#dfn-execute-script

View file

@ -297,23 +297,6 @@ Web::WebDriver::Response Session::get_window_handles() const
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 {
String script;
JsonArray const& arguments;

View file

@ -58,7 +58,6 @@ public:
Web::WebDriver::Response get_window_handle();
ErrorOr<void, Variant<Web::WebDriver::Error, Error>> close_window();
Web::WebDriver::Response get_window_handles() const;
Web::WebDriver::Response get_source();
Web::WebDriver::Response execute_script(JsonValue const& payload);
Web::WebDriver::Response execute_async_script(JsonValue const& payload);
Web::WebDriver::Response get_all_cookies();