mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +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
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue