aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/webdriver_handlers.rs
diff options
context:
space:
mode:
authorJames Graham <james@hoppipolla.co.uk>2015-04-29 19:49:38 +0100
committerJames Graham <james@hoppipolla.co.uk>2015-05-14 10:59:17 +0100
commit8d10fa1f2d2d26cfb5ca5bcbee0bd6d0f77b730a (patch)
tree0fd6ebf5227dcd46475fdcbb3eb22ed7de678810 /components/script/webdriver_handlers.rs
parent98cb65ca0a7d6c940e69f77275b6941499a434a3 (diff)
downloadservo-8d10fa1f2d2d26cfb5ca5bcbee0bd6d0f77b730a.tar.gz
servo-8d10fa1f2d2d26cfb5ca5bcbee0bd6d0f77b730a.zip
Add basic support for executeAsyncScript.
This relies on a global webdriverCallback function, which is visible to content. Obviously that's not a long term solution for a number of reasons, but it allows us to experiment for now
Diffstat (limited to 'components/script/webdriver_handlers.rs')
-rw-r--r--components/script/webdriver_handlers.rs44
1 files changed, 29 insertions, 15 deletions
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index cdaea5f5fb3..5ab1aa50a21 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -12,8 +12,10 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
use dom::bindings::js::{OptionalRootable, Rootable, Temporary};
use dom::node::{Node, NodeHelpers};
-use dom::window::ScriptHelpers;
+use dom::window::{ScriptHelpers, WindowHelpers};
use dom::document::DocumentHelpers;
+use js::jsapi::JSContext;
+use js::jsval::JSVal;
use page::Page;
use msg::constellation_msg::PipelineId;
use script_task::get_page;
@@ -35,26 +37,38 @@ fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String
None
}
+pub fn jsval_to_webdriver(cx: *mut JSContext, val: JSVal) -> Result<EvaluateJSReply, ()> {
+ if val.is_undefined() {
+ Ok(EvaluateJSReply::VoidValue)
+ } else if val.is_boolean() {
+ Ok(EvaluateJSReply::BooleanValue(val.to_boolean()))
+ } else if val.is_double() {
+ Ok(EvaluateJSReply::NumberValue(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
+ } else if val.is_string() {
+ //FIXME: use jsstring_to_str when jsval grows to_jsstring
+ Ok(EvaluateJSReply::StringValue(FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap()))
+ } else if val.is_null() {
+ Ok(EvaluateJSReply::NullValue)
+ } else {
+ Err(())
+ }
+}
+
pub fn handle_execute_script(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();
+ reply.send(jsval_to_webdriver(cx, rval)).unwrap();
+}
+
+
+pub fn handle_execute_async_script(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<Result<EvaluateJSReply, ()>>) {
+ let page = get_page(&*page, pipeline);
+ let window = page.window().root();
+ window.r().set_webdriver_script_chan(Some(reply));
+ window.r().evaluate_js_on_global_with_result(&eval);
}
pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String, reply: Sender<Result<Option<String>, ()>>) {