mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Upgrade to SM 39
This commit is contained in:
parent
a256f39796
commit
675267b782
205 changed files with 6546 additions and 5340 deletions
|
@ -10,27 +10,28 @@ use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
|||
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
||||
use dom::bindings::js::{OptionalRootable, Rootable, Temporary};
|
||||
use dom::bindings::js::Root;
|
||||
use dom::node::{Node, NodeHelpers};
|
||||
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, SubpageId};
|
||||
use msg::webdriver_msg::{WebDriverJSValue, WebDriverJSError, WebDriverJSResult, WebDriverFrameId};
|
||||
use script_task::get_page;
|
||||
use js::jsapi::{RootedValue, HandleValue};
|
||||
use js::jsval::UndefinedValue;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Temporary<Node>> {
|
||||
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
|
||||
let page = get_page(&*page, pipeline);
|
||||
let document = page.document().root();
|
||||
let document = page.document();
|
||||
let node = NodeCast::from_ref(document.r());
|
||||
|
||||
for candidate in node.traverse_preorder() {
|
||||
if candidate.root().r().get_unique_id() == node_id {
|
||||
if candidate.r().get_unique_id() == node_id {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
|
@ -38,19 +39,19 @@ 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) -> WebDriverJSResult {
|
||||
if val.is_undefined() {
|
||||
pub fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDriverJSResult {
|
||||
if val.get().is_undefined() {
|
||||
Ok(WebDriverJSValue::Undefined)
|
||||
} else if val.is_boolean() {
|
||||
Ok(WebDriverJSValue::Boolean(val.to_boolean()))
|
||||
} else if val.is_double() {
|
||||
} else if val.get().is_boolean() {
|
||||
Ok(WebDriverJSValue::Boolean(val.get().to_boolean()))
|
||||
} else if val.get().is_double() {
|
||||
Ok(WebDriverJSValue::Number(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
|
||||
} else if val.is_string() {
|
||||
} else if val.get().is_string() {
|
||||
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
||||
Ok(
|
||||
WebDriverJSValue::String(
|
||||
FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap()))
|
||||
} else if val.is_null() {
|
||||
} else if val.get().is_null() {
|
||||
Ok(WebDriverJSValue::Null)
|
||||
} else {
|
||||
Err(WebDriverJSError::UnknownType)
|
||||
|
@ -59,19 +60,22 @@ pub fn jsval_to_webdriver(cx: *mut JSContext, val: JSVal) -> WebDriverJSResult {
|
|||
|
||||
pub fn handle_execute_script(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<WebDriverJSResult>) {
|
||||
let page = get_page(&*page, pipeline);
|
||||
let window = page.window().root();
|
||||
let window = page.window();
|
||||
let cx = window.r().get_cx();
|
||||
let rval = window.r().evaluate_js_on_global_with_result(&eval);
|
||||
let mut rval = RootedValue::new(cx, UndefinedValue());
|
||||
window.r().evaluate_js_on_global_with_result(&eval, rval.handle_mut());
|
||||
|
||||
reply.send(jsval_to_webdriver(cx, rval)).unwrap();
|
||||
reply.send(jsval_to_webdriver(cx, rval.handle())).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_execute_async_script(page: &Rc<Page>, pipeline: PipelineId, eval: String,
|
||||
reply: Sender<WebDriverJSResult>) {
|
||||
let page = get_page(&*page, pipeline);
|
||||
let window = page.window().root();
|
||||
let window = page.window();
|
||||
let cx = window.r().get_cx();
|
||||
window.r().set_webdriver_script_chan(Some(reply));
|
||||
window.r().evaluate_js_on_global_with_result(&eval);
|
||||
let mut rval = RootedValue::new(cx, UndefinedValue());
|
||||
window.r().evaluate_js_on_global_with_result(&eval, rval.handle_mut());
|
||||
}
|
||||
|
||||
pub fn handle_get_frame_id(page: &Rc<Page>,
|
||||
|
@ -86,7 +90,7 @@ pub fn handle_get_frame_id(page: &Rc<Page>,
|
|||
WebDriverFrameId::Element(x) => {
|
||||
match find_node_by_unique_id(page, pipeline, x) {
|
||||
Some(ref node) => {
|
||||
match HTMLIFrameElementCast::to_ref(node.root().r()) {
|
||||
match HTMLIFrameElementCast::to_ref(node.r()) {
|
||||
Some(ref elem) => Ok(elem.GetContentWindow()),
|
||||
None => Err(())
|
||||
}
|
||||
|
@ -96,19 +100,19 @@ pub fn handle_get_frame_id(page: &Rc<Page>,
|
|||
},
|
||||
WebDriverFrameId::Parent => {
|
||||
let window = page.window();
|
||||
Ok(window.root().r().parent())
|
||||
Ok(window.r().parent())
|
||||
}
|
||||
};
|
||||
|
||||
let frame_id = window.map(|x| x.and_then(|x| x.root().r().parent_info()));
|
||||
let frame_id = window.map(|x| x.and_then(|x| x.r().parent_info()));
|
||||
reply.send(frame_id).unwrap()
|
||||
}
|
||||
|
||||
pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
|
||||
reply: Sender<Result<Option<String>, ()>>) {
|
||||
reply.send(match page.document().root().r().QuerySelector(selector.clone()) {
|
||||
reply.send(match page.document().r().QuerySelector(selector.clone()) {
|
||||
Ok(node) => {
|
||||
let result = node.map(|x| NodeCast::from_ref(x.root().r()).get_unique_id());
|
||||
let result = node.map(|x| NodeCast::from_ref(x.r()).get_unique_id());
|
||||
Ok(result)
|
||||
}
|
||||
Err(_) => Err(())
|
||||
|
@ -117,13 +121,12 @@ pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector:
|
|||
|
||||
pub fn handle_find_elements_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
|
||||
reply: Sender<Result<Vec<String>, ()>>) {
|
||||
reply.send(match page.document().root().r().QuerySelectorAll(selector.clone()) {
|
||||
Ok(ref node_list) => {
|
||||
let nodes = node_list.root();
|
||||
reply.send(match page.document().r().QuerySelectorAll(selector.clone()) {
|
||||
Ok(ref nodes) => {
|
||||
let mut result = Vec::with_capacity(nodes.r().Length() as usize);
|
||||
for i in 0..nodes.r().Length() {
|
||||
if let Some(ref node) = nodes.r().Item(i) {
|
||||
result.push(node.root().r().get_unique_id());
|
||||
result.push(node.r().get_unique_id());
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
|
@ -135,18 +138,18 @@ pub fn handle_find_elements_css(page: &Rc<Page>, _pipeline: PipelineId, selector
|
|||
}
|
||||
|
||||
pub fn handle_get_active_element(page: &Rc<Page>, _pipeline: PipelineId, reply: Sender<Option<String>>) {
|
||||
reply.send(page.document().root().r().GetActiveElement().map(
|
||||
|elem| NodeCast::from_ref(elem.root().r()).get_unique_id())).unwrap();
|
||||
reply.send(page.document().r().GetActiveElement().map(
|
||||
|elem| NodeCast::from_ref(elem.r()).get_unique_id())).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: Sender<String>) {
|
||||
reply.send(page.document().root().r().Title()).unwrap();
|
||||
reply.send(page.document().r().Title()).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_get_text(page: &Rc<Page>, pipeline: PipelineId, node_id: String, reply: Sender<Result<String, ()>>) {
|
||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||
Some(ref node) => {
|
||||
Ok(node.root().r().GetTextContent().unwrap_or("".to_owned()))
|
||||
Ok(node.r().GetTextContent().unwrap_or("".to_owned()))
|
||||
},
|
||||
None => Err(())
|
||||
}).unwrap();
|
||||
|
@ -154,8 +157,7 @@ pub fn handle_get_text(page: &Rc<Page>, pipeline: PipelineId, node_id: String, r
|
|||
|
||||
pub fn handle_get_name(page: &Rc<Page>, pipeline: PipelineId, node_id: String, reply: Sender<Result<String, ()>>) {
|
||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||
Some(tmp_node) => {
|
||||
let node = tmp_node.root();
|
||||
Some(node) => {
|
||||
let element = ElementCast::to_ref(node.r()).unwrap();
|
||||
Ok(element.TagName())
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue