mirror of
https://github.com/servo/servo.git
synced 2025-06-13 19:04:30 +00:00
Auto merge of #5962 - jgraham:webdriver_navigation, r=jdm
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5962) <!-- Reviewable:end -->
This commit is contained in:
commit
72c20d8491
5 changed files with 47 additions and 5 deletions
|
@ -226,7 +226,7 @@ pub enum Msg {
|
||||||
ChangeRunningAnimationsState(PipelineId, AnimationState),
|
ChangeRunningAnimationsState(PipelineId, AnimationState),
|
||||||
/// Requests that the constellation instruct layout to begin a new tick of the animation.
|
/// Requests that the constellation instruct layout to begin a new tick of the animation.
|
||||||
TickAnimation(PipelineId),
|
TickAnimation(PipelineId),
|
||||||
// Request that the constellation send the current root pipeline id over a provided channel
|
/// Request that the constellation send the current root pipeline id over a provided channel
|
||||||
GetRootPipeline(Sender<Option<PipelineId>>),
|
GetRootPipeline(Sender<Option<PipelineId>>),
|
||||||
/// Notifies the constellation that this frame has received focus.
|
/// Notifies the constellation that this frame has received focus.
|
||||||
Focus(PipelineId),
|
Focus(PipelineId),
|
||||||
|
|
|
@ -791,7 +791,9 @@ impl ScriptTask {
|
||||||
let page = self.root_page();
|
let page = self.root_page();
|
||||||
match msg {
|
match msg {
|
||||||
WebDriverScriptCommand::EvaluateJS(script, reply) =>
|
WebDriverScriptCommand::EvaluateJS(script, reply) =>
|
||||||
webdriver_handlers::handle_evaluate_js(&page, pipeline_id, script, reply)
|
webdriver_handlers::handle_evaluate_js(&page, pipeline_id, script, reply),
|
||||||
|
WebDriverScriptCommand::GetTitle(reply) =>
|
||||||
|
webdriver_handlers::handle_get_title(&page, pipeline_id, reply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use webdriver_traits::{EvaluateJSReply};
|
use webdriver_traits::{EvaluateJSReply};
|
||||||
use dom::bindings::conversions::FromJSValConvertible;
|
use dom::bindings::conversions::FromJSValConvertible;
|
||||||
use dom::bindings::conversions::StringificationBehavior;
|
use dom::bindings::conversions::StringificationBehavior;
|
||||||
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::js::{OptionalRootable, Rootable};
|
use dom::bindings::js::{OptionalRootable, Rootable};
|
||||||
use dom::window::ScriptHelpers;
|
use dom::window::ScriptHelpers;
|
||||||
use dom::document::DocumentHelpers;
|
use dom::document::DocumentHelpers;
|
||||||
|
@ -36,3 +37,7 @@ pub fn handle_evaluate_js(page: &Rc<Page>, pipeline: PipelineId, eval: String, r
|
||||||
Err(())
|
Err(())
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: Sender<String>) {
|
||||||
|
reply.send(page.document().root().r().Title()).unwrap();
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ extern crate rustc_serialize;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
extern crate webdriver_traits;
|
extern crate webdriver_traits;
|
||||||
|
|
||||||
use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId};
|
use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId, NavigationDirection};
|
||||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use webdriver_traits::WebDriverScriptCommand;
|
use webdriver_traits::WebDriverScriptCommand;
|
||||||
|
@ -110,6 +110,29 @@ impl Handler {
|
||||||
Ok(WebDriverResponse::Void)
|
Ok(WebDriverResponse::Void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_go_back(&self) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
let ConstellationChan(ref const_chan) = self.constellation_chan;
|
||||||
|
const_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back)).unwrap();
|
||||||
|
Ok(WebDriverResponse::Void)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_go_forward(&self) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
let ConstellationChan(ref const_chan) = self.constellation_chan;
|
||||||
|
const_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Forward)).unwrap();
|
||||||
|
Ok(WebDriverResponse::Void)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_get_title(&self) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
let pipeline_id = self.get_root_pipeline();
|
||||||
|
|
||||||
|
let (sender, reciever) = channel();
|
||||||
|
let ConstellationChan(ref const_chan) = self.constellation_chan;
|
||||||
|
const_chan.send(ConstellationMsg::WebDriverCommand(pipeline_id,
|
||||||
|
WebDriverScriptCommand::GetTitle(sender))).unwrap();
|
||||||
|
let value = reciever.recv().unwrap();
|
||||||
|
Ok(WebDriverResponse::Generic(ValueResponse::new(value.to_json())))
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_get_window_handle(&self) -> WebDriverResult<WebDriverResponse> {
|
fn handle_get_window_handle(&self) -> WebDriverResult<WebDriverResponse> {
|
||||||
// For now we assume there's only one window so just use the session
|
// For now we assume there's only one window so just use the session
|
||||||
// id as the window id
|
// id as the window id
|
||||||
|
@ -117,6 +140,13 @@ impl Handler {
|
||||||
Ok(WebDriverResponse::Generic(ValueResponse::new(handle.to_json())))
|
Ok(WebDriverResponse::Generic(ValueResponse::new(handle.to_json())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_get_window_handles(&self) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
// For now we assume there's only one window so just use the session
|
||||||
|
// id as the window id
|
||||||
|
let handles = vec![self.session.as_ref().unwrap().id.to_string().to_json()];
|
||||||
|
Ok(WebDriverResponse::Generic(ValueResponse::new(handles.to_json())))
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_execute_script(&self, parameters: &JavascriptCommandParameters) -> WebDriverResult<WebDriverResponse> {
|
fn handle_execute_script(&self, parameters: &JavascriptCommandParameters) -> WebDriverResult<WebDriverResponse> {
|
||||||
// TODO: This isn't really right because it always runs the script in the
|
// TODO: This isn't really right because it always runs the script in the
|
||||||
// root window
|
// root window
|
||||||
|
@ -149,7 +179,11 @@ impl WebDriverHandler for Handler {
|
||||||
match msg.command {
|
match msg.command {
|
||||||
WebDriverCommand::NewSession => self.handle_new_session(),
|
WebDriverCommand::NewSession => self.handle_new_session(),
|
||||||
WebDriverCommand::Get(ref parameters) => self.handle_get(parameters),
|
WebDriverCommand::Get(ref parameters) => self.handle_get(parameters),
|
||||||
|
WebDriverCommand::GoBack => self.handle_go_back(),
|
||||||
|
WebDriverCommand::GoForward => self.handle_go_forward(),
|
||||||
|
WebDriverCommand::GetTitle => self.handle_get_title(),
|
||||||
WebDriverCommand::GetWindowHandle => self.handle_get_window_handle(),
|
WebDriverCommand::GetWindowHandle => self.handle_get_window_handle(),
|
||||||
|
WebDriverCommand::GetWindowHandles => self.handle_get_window_handles(),
|
||||||
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
|
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
|
||||||
_ => Err(WebDriverError::new(ErrorStatus::UnsupportedOperation,
|
_ => Err(WebDriverError::new(ErrorStatus::UnsupportedOperation,
|
||||||
"Command not implemented"))
|
"Command not implemented"))
|
||||||
|
|
|
@ -11,7 +11,8 @@ use rustc_serialize::json::{Json, ToJson};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
pub enum WebDriverScriptCommand {
|
pub enum WebDriverScriptCommand {
|
||||||
EvaluateJS(String, Sender<Result<EvaluateJSReply, ()>>)
|
EvaluateJS(String, Sender<Result<EvaluateJSReply, ()>>),
|
||||||
|
GetTitle(Sender<String>)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum EvaluateJSReply {
|
pub enum EvaluateJSReply {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue