diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-06-22 19:11:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-22 19:11:59 -0400 |
commit | 2cbd177082ee801e3d6ebcde17ab76625639c1d7 (patch) | |
tree | ffd4e37d1b5fa382214363234a3367f8618efd00 /components/script | |
parent | 5592682c4b8326fd0e31c500782061b025fe8a30 (diff) | |
parent | 13d908ab15c7f6bba59911a54d3f5f7610f4ef46 (diff) | |
download | servo-2cbd177082ee801e3d6ebcde17ab76625639c1d7.tar.gz servo-2cbd177082ee801e3d6ebcde17ab76625639c1d7.zip |
Auto merge of #23581 - georgeroman:implement_get_page_source_wd_command, r=jdm
Implement GetPageSource WebDriver command
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
<!-- Either: -->
- [X] There are tests for these changes
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23581)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/script_thread.rs | 3 | ||||
-rw-r--r-- | components/script/webdriver_handlers.rs | 27 |
2 files changed, 30 insertions, 0 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 9264b7b9312..b81ff6d5fc7 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1902,6 +1902,9 @@ impl ScriptThread { WebDriverScriptCommand::GetActiveElement(reply) => { webdriver_handlers::handle_get_active_element(&*documents, pipeline_id, reply) }, + WebDriverScriptCommand::GetPageSource(reply) => { + webdriver_handlers::handle_get_page_source(&*documents, pipeline_id, reply) + }, WebDriverScriptCommand::GetCookies(reply) => { webdriver_handlers::handle_get_cookies(&*documents, pipeline_id, reply) }, diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index 81f45283c9a..5574451bd5b 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -10,6 +10,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputE use crate::dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods; use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use crate::dom::bindings::codegen::Bindings::XMLSerializerBinding::XMLSerializerMethods; use crate::dom::bindings::conversions::{ ConversionResult, FromJSValConvertible, StringificationBehavior, }; @@ -24,6 +25,7 @@ use crate::dom::htmlinputelement::HTMLInputElement; use crate::dom::htmloptionelement::HTMLOptionElement; use crate::dom::node::{window_from_node, Node, ShadowIncluding}; use crate::dom::window::Window; +use crate::dom::xmlserializer::XMLSerializer; use crate::script_thread::Documents; use cookie::Cookie; use euclid::{Point2D, Rect, Size2D}; @@ -281,6 +283,31 @@ pub fn handle_get_active_element( .unwrap(); } +pub fn handle_get_page_source( + documents: &Documents, + pipeline: PipelineId, + reply: IpcSender<Result<String, ()>>, +) { + reply + .send(documents.find_document(pipeline).ok_or(()).and_then(|doc| { + match doc.GetDocumentElement() { + Some(elem) => match elem.GetOuterHTML() { + Ok(source) => Ok(source.to_string()), + Err(_) => { + match XMLSerializer::new(doc.window()) + .SerializeToString(elem.upcast::<Node>()) + { + Ok(source) => Ok(source.to_string()), + Err(_) => Err(()), + } + }, + }, + None => Err(()), + } + })) + .unwrap(); +} + pub fn handle_get_cookies( documents: &Documents, pipeline: PipelineId, |