mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Implement GetPageSource WebDriver command
This commit is contained in:
parent
fd174c54ef
commit
13d908ab15
5 changed files with 52 additions and 1 deletions
|
@ -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)
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue