mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +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,
|
||||
|
|
|
@ -39,6 +39,7 @@ pub enum WebDriverScriptCommand {
|
|||
GetElementText(String, IpcSender<Result<String, ()>>),
|
||||
GetBrowsingContextId(WebDriverFrameId, IpcSender<Result<BrowsingContextId, ()>>),
|
||||
GetUrl(IpcSender<ServoUrl>),
|
||||
GetPageSource(IpcSender<Result<String, ()>>),
|
||||
IsEnabled(String, IpcSender<Result<bool, ()>>),
|
||||
IsSelected(String, IpcSender<Result<bool, ()>>),
|
||||
GetTitle(IpcSender<String>),
|
||||
|
|
|
@ -1188,6 +1188,23 @@ impl Handler {
|
|||
Ok(WebDriverResponse::Void)
|
||||
}
|
||||
|
||||
fn handle_get_page_source(&self) -> WebDriverResult<WebDriverResponse> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
|
||||
let cmd = WebDriverScriptCommand::GetPageSource(sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
|
||||
match receiver.recv().unwrap() {
|
||||
Ok(source) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||
serde_json::to_value(source)?,
|
||||
))),
|
||||
Err(_) => Err(WebDriverError::new(
|
||||
ErrorStatus::UnknownError,
|
||||
"Unknown error",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_execute_script(
|
||||
&self,
|
||||
parameters: &JavascriptCommandParameters,
|
||||
|
@ -1457,6 +1474,7 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
|
|||
WebDriverCommand::GetCSSValue(ref element, ref name) => {
|
||||
self.handle_element_css(element, name)
|
||||
},
|
||||
WebDriverCommand::GetPageSource => self.handle_get_page_source(),
|
||||
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
|
||||
WebDriverCommand::ExecuteAsyncScript(ref x) => self.handle_execute_async_script(x),
|
||||
WebDriverCommand::ElementSendKeys(ref element, ref keys) => {
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
[source.py]
|
||||
disabled: Unimplemented WebDriver command
|
||||
[test_no_browsing_context]
|
||||
expected: ERROR
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue