mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Add script execution support via WebDriver
This commit is contained in:
parent
1b08211a5e
commit
c2fc6e311a
19 changed files with 223 additions and 18 deletions
|
@ -42,6 +42,9 @@ path = "../gfx"
|
|||
[dependencies.canvas]
|
||||
path = "../canvas"
|
||||
|
||||
[dependencies.webdriver_traits]
|
||||
path = "../webdriver_traits"
|
||||
|
||||
[dependencies.cssparser]
|
||||
git = "https://github.com/servo/rust-cssparser"
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ extern crate style;
|
|||
extern crate url;
|
||||
extern crate uuid;
|
||||
extern crate string_cache;
|
||||
extern crate webdriver_traits;
|
||||
|
||||
pub mod cors;
|
||||
|
||||
|
@ -67,3 +68,4 @@ pub mod script_task;
|
|||
mod timers;
|
||||
pub mod textinput;
|
||||
mod devtools;
|
||||
mod webdriver_handlers;
|
||||
|
|
|
@ -45,6 +45,7 @@ use layout_interface;
|
|||
use page::{Page, IterablePage, Frame};
|
||||
use timers::TimerId;
|
||||
use devtools;
|
||||
use webdriver_handlers;
|
||||
|
||||
use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, DevtoolsPageInfo};
|
||||
use devtools_traits::{DevtoolsControlMsg, DevtoolScriptControlMsg};
|
||||
|
@ -56,6 +57,7 @@ use script_traits::CompositorEvent::{MouseMoveEvent, KeyEvent};
|
|||
use script_traits::{NewLayoutInfo, OpaqueScriptLayoutChannel};
|
||||
use script_traits::{ConstellationControlMsg, ScriptControlChan};
|
||||
use script_traits::ScriptTaskFactory;
|
||||
use webdriver_traits::WebDriverScriptCommand;
|
||||
use msg::compositor_msg::ReadyState::{FinishedLoading, Loading, PerformingLayout};
|
||||
use msg::compositor_msg::{LayerId, ScriptListener};
|
||||
use msg::constellation_msg::{ConstellationChan, FocusType};
|
||||
|
@ -727,6 +729,9 @@ impl ScriptTask {
|
|||
self.handle_update_subpage_id(containing_pipeline_id, old_subpage_id, new_subpage_id),
|
||||
ConstellationControlMsg::FocusIFrameMsg(containing_pipeline_id, subpage_id) =>
|
||||
self.handle_focus_iframe_msg(containing_pipeline_id, subpage_id),
|
||||
ConstellationControlMsg::WebDriverCommandMsg(pipeline_id, msg) => {
|
||||
self.handle_webdriver_msg(pipeline_id, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,6 +788,14 @@ impl ScriptTask {
|
|||
msg.responder.unwrap().respond(msg.image);
|
||||
}
|
||||
|
||||
fn handle_webdriver_msg(&self, pipeline_id: PipelineId, msg: WebDriverScriptCommand) {
|
||||
let page = self.root_page();
|
||||
match msg {
|
||||
WebDriverScriptCommand::EvaluateJS(script, reply) =>
|
||||
webdriver_handlers::handle_evaluate_js(&page, pipeline_id, script, reply)
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_resize(&self, id: PipelineId, size: WindowSizeData) {
|
||||
let page = self.page.borrow();
|
||||
if let Some(ref page) = page.as_ref() {
|
||||
|
|
38
components/script/webdriver_handlers.rs
Normal file
38
components/script/webdriver_handlers.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use webdriver_traits::{EvaluateJSReply};
|
||||
use dom::bindings::conversions::FromJSValConvertible;
|
||||
use dom::bindings::conversions::StringificationBehavior;
|
||||
use dom::bindings::js::OptionalRootable;
|
||||
use dom::window::ScriptHelpers;
|
||||
use dom::document::DocumentHelpers;
|
||||
use page::Page;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use script_task::get_page;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub fn handle_evaluate_js(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<Result<EvaluateJSReply, ()>>){
|
||||
let page = get_page(&*page, pipeline);
|
||||
let window = page.window().root();
|
||||
let cx = window.r().get_cx();
|
||||
let rval = window.r().evaluate_js_on_global_with_result(&eval);
|
||||
|
||||
reply.send(if rval.is_undefined() {
|
||||
Ok(EvaluateJSReply::VoidValue)
|
||||
} else if rval.is_boolean() {
|
||||
Ok(EvaluateJSReply::BooleanValue(rval.to_boolean()))
|
||||
} else if rval.is_double() {
|
||||
Ok(EvaluateJSReply::NumberValue(FromJSValConvertible::from_jsval(cx, rval, ()).unwrap()))
|
||||
} else if rval.is_string() {
|
||||
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
||||
Ok(EvaluateJSReply::StringValue(FromJSValConvertible::from_jsval(cx, rval, StringificationBehavior::Default).unwrap()))
|
||||
} else if rval.is_null() {
|
||||
Ok(EvaluateJSReply::NullValue)
|
||||
} else {
|
||||
Err(())
|
||||
}).unwrap();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue