mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Enable executing JS snippets in the context of the main Servo window and viewing the responses from the Firefox remote console.
This commit is contained in:
parent
f0f7e98dfa
commit
cdb4037ca2
7 changed files with 262 additions and 58 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -3,7 +3,6 @@ name = "servo"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compositing 0.0.1",
|
"compositing 0.0.1",
|
||||||
"devtools 0.0.1",
|
|
||||||
"gfx 0.0.1",
|
"gfx 0.0.1",
|
||||||
"layout 0.0.1",
|
"layout 0.0.1",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
|
@ -113,11 +112,15 @@ name = "devtools"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"devtools_traits 0.0.1",
|
"devtools_traits 0.0.1",
|
||||||
|
"msg 0.0.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "devtools_traits"
|
name = "devtools_traits"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"msg 0.0.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egl"
|
name = "egl"
|
||||||
|
|
|
@ -46,8 +46,5 @@ path = "components/layout"
|
||||||
[dependencies.gfx]
|
[dependencies.gfx]
|
||||||
path = "components/gfx"
|
path = "components/gfx"
|
||||||
|
|
||||||
[dependencies.devtools]
|
|
||||||
path = "components/devtools"
|
|
||||||
|
|
||||||
[dependencies.url]
|
[dependencies.url]
|
||||||
git = "https://github.com/servo/rust-url"
|
git = "https://github.com/servo/rust-url"
|
||||||
|
|
|
@ -6,7 +6,9 @@ authors = ["The Servo Project Developers"]
|
||||||
[lib]
|
[lib]
|
||||||
name = "devtools"
|
name = "devtools"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
crate-type = ["dylib"]
|
|
||||||
|
|
||||||
[dependencies.devtools_traits]
|
[dependencies.devtools_traits]
|
||||||
path = "../devtools_traits"
|
path = "../devtools_traits"
|
||||||
|
|
||||||
|
[dependencies.msg]
|
||||||
|
path = "../msg"
|
||||||
|
|
|
@ -21,19 +21,26 @@ extern crate debug;
|
||||||
extern crate std;
|
extern crate std;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate sync;
|
extern crate sync;
|
||||||
|
extern crate servo_msg = "msg";
|
||||||
|
|
||||||
use devtools_traits::{ServerExitMsg, DevtoolsControlMsg, NewGlobal};
|
use devtools_traits::{ServerExitMsg, DevtoolsControlMsg, NewGlobal, DevtoolScriptControlMsg};
|
||||||
|
use devtools_traits::{EvaluateJS, NullValue, VoidValue, NumberValue, StringValue, BooleanValue};
|
||||||
|
use devtools_traits::ActorValue;
|
||||||
|
use servo_msg::constellation_msg::PipelineId;
|
||||||
|
|
||||||
use collections::TreeMap;
|
use collections::TreeMap;
|
||||||
use std::any::{Any, AnyRefExt};
|
use std::any::{Any, AnyRefExt, AnyMutRefExt};
|
||||||
use std::collections::hashmap::HashMap;
|
use std::collections::hashmap::HashMap;
|
||||||
use std::comm;
|
use std::comm;
|
||||||
use std::comm::{Disconnected, Empty};
|
use std::comm::{Disconnected, Empty};
|
||||||
use std::io::{TcpListener, TcpStream};
|
use std::io::{TcpListener, TcpStream};
|
||||||
use std::io::{Acceptor, Listener, EndOfFile, IoError, TimedOut};
|
use std::io::{Acceptor, Listener, EndOfFile, IoError, TimedOut};
|
||||||
|
use std::mem::{transmute, transmute_copy};
|
||||||
use std::num;
|
use std::num;
|
||||||
|
use std::raw::TraitObject;
|
||||||
use std::task::TaskBuilder;
|
use std::task::TaskBuilder;
|
||||||
use serialize::{json, Encodable};
|
use serialize::{json, Encodable};
|
||||||
|
use serialize::json::ToJson;
|
||||||
use sync::{Arc, Mutex};
|
use sync::{Arc, Mutex};
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
|
@ -49,6 +56,7 @@ struct RootActorMsg {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RootActor {
|
struct RootActor {
|
||||||
|
next: u32,
|
||||||
tabs: Vec<String>,
|
tabs: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +82,12 @@ struct TabActor {
|
||||||
url: String,
|
url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ConsoleActor {
|
||||||
|
name: String,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
script_chan: Sender<DevtoolScriptControlMsg>,
|
||||||
|
}
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
struct ListTabsReply {
|
struct ListTabsReply {
|
||||||
from: String,
|
from: String,
|
||||||
|
@ -82,16 +96,14 @@ struct ListTabsReply {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
struct TabTraits {
|
struct TabTraits;
|
||||||
reconfigure: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
struct TabAttachedReply {
|
struct TabAttachedReply {
|
||||||
from: String,
|
from: String,
|
||||||
__type__: String,
|
__type__: String,
|
||||||
threadActor: String,
|
threadActor: String,
|
||||||
cacheEnabled: bool,
|
cacheDisabled: bool,
|
||||||
javascriptEnabled: bool,
|
javascriptEnabled: bool,
|
||||||
traits: TabTraits,
|
traits: TabTraits,
|
||||||
}
|
}
|
||||||
|
@ -102,11 +114,18 @@ struct TabDetachedReply {
|
||||||
__type__: String,
|
__type__: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
struct StartedListenersTraits {
|
||||||
|
customNetworkRequest: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
struct StartedListenersReply {
|
struct StartedListenersReply {
|
||||||
from: String,
|
from: String,
|
||||||
nativeConsoleAPI: bool,
|
nativeConsoleAPI: bool,
|
||||||
startedListeners: Vec<String>,
|
startedListeners: Vec<String>,
|
||||||
|
traits: StartedListenersTraits,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
|
@ -186,13 +205,24 @@ impl ActorRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register(&mut self, actor: Box<Actor+Send+Sized>) {
|
fn register<T: 'static>(&mut self, actor: Box<Actor+Send+Sized>) {
|
||||||
|
/*{
|
||||||
|
let actor2: &Actor+Send+Sized = actor;
|
||||||
|
assert!((actor2 as &Any).is::<T>());
|
||||||
|
};*/
|
||||||
self.actors.insert(actor.name().to_string(), actor);
|
self.actors.insert(actor.name().to_string(), actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find<'a, T: 'static>(&'a self, name: &str) -> &'a T {
|
fn find<'a, T: 'static>(&'a self, name: &str) -> &'a T {
|
||||||
let actor: &Actor+Send+Sized = *self.actors.find(&name.to_string()).unwrap();
|
/*let actor: &Actor+Send+Sized = *self.actors.find(&name.to_string()).unwrap();
|
||||||
(actor as &Any).downcast_ref::<T>().unwrap()
|
(actor as &Any).downcast_ref::<T>().unwrap()*/
|
||||||
|
self.actors.find(&name.to_string()).unwrap().as_ref::<T>().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_mut<'a, T: 'static>(&'a mut self, name: &str) -> &'a mut T {
|
||||||
|
/*let actor: &mut Actor+Send+Sized = *self.actors.find_mut(&name.to_string()).unwrap();
|
||||||
|
(actor as &mut Any).downcast_mut::<T>().unwrap()*/
|
||||||
|
self.actors.find_mut(&name.to_string()).unwrap().downcast_mut::<T>().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_message(&self, msg: &json::Object, stream: &mut TcpStream) {
|
fn handle_message(&self, msg: &json::Object, stream: &mut TcpStream) {
|
||||||
|
@ -220,6 +250,45 @@ trait Actor: Any {
|
||||||
fn name(&self) -> String;
|
fn name(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> AnyMutRefExt<'a> for &'a mut Actor {
|
||||||
|
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T> {
|
||||||
|
if self.is::<T>() {
|
||||||
|
unsafe {
|
||||||
|
// Get the raw representation of the trait object
|
||||||
|
let to: TraitObject = transmute_copy(&self);
|
||||||
|
|
||||||
|
// Extract the data pointer
|
||||||
|
Some(transmute(to.data))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AnyRefExt<'a> for &'a Actor {
|
||||||
|
fn is<T: 'static>(self) -> bool {
|
||||||
|
/*let t = TypeId::of::<T>();
|
||||||
|
let boxed = self.get_type_id();
|
||||||
|
t == boxed*/
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn downcast_ref<T: 'static>(self) -> Option<&'a T> {
|
||||||
|
if self.is::<T>() {
|
||||||
|
unsafe {
|
||||||
|
// Get the raw representation of the trait object
|
||||||
|
let to: TraitObject = transmute_copy(&self);
|
||||||
|
|
||||||
|
// Extract the data pointer
|
||||||
|
Some(transmute(to.data))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Actor for RootActor {
|
impl Actor for RootActor {
|
||||||
fn name(&self) -> String {
|
fn name(&self) -> String {
|
||||||
"root".to_string()
|
"root".to_string()
|
||||||
|
@ -268,6 +337,11 @@ impl RootActor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
struct ReconfigureReply {
|
||||||
|
from: String
|
||||||
|
}
|
||||||
|
|
||||||
impl Actor for TabActor {
|
impl Actor for TabActor {
|
||||||
fn name(&self) -> String {
|
fn name(&self) -> String {
|
||||||
self.name.clone()
|
self.name.clone()
|
||||||
|
@ -276,19 +350,21 @@ impl Actor for TabActor {
|
||||||
fn handle_message(&self,
|
fn handle_message(&self,
|
||||||
_registry: &ActorRegistry,
|
_registry: &ActorRegistry,
|
||||||
msg_type: &String,
|
msg_type: &String,
|
||||||
msg: &json::Object,
|
_msg: &json::Object,
|
||||||
stream: &mut TcpStream) -> bool {
|
stream: &mut TcpStream) -> bool {
|
||||||
match msg_type.as_slice() {
|
match msg_type.as_slice() {
|
||||||
|
"reconfigure" => {
|
||||||
|
stream.write_json_packet(&ReconfigureReply { from: self.name() });
|
||||||
|
true
|
||||||
|
}
|
||||||
"attach" => {
|
"attach" => {
|
||||||
let msg = TabAttachedReply {
|
let msg = TabAttachedReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
__type__: "tabAttached".to_string(),
|
__type__: "tabAttached".to_string(),
|
||||||
threadActor: self.name(),
|
threadActor: self.name(),
|
||||||
cacheEnabled: false,
|
cacheDisabled: false,
|
||||||
javascriptEnabled: true,
|
javascriptEnabled: true,
|
||||||
traits: TabTraits {
|
traits: TabTraits,
|
||||||
reconfigure: true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
true
|
true
|
||||||
|
@ -301,16 +377,34 @@ impl Actor for TabActor {
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
"startListeners" => {
|
_ => false
|
||||||
let msg = StartedListenersReply {
|
}
|
||||||
from: self.name(),
|
}
|
||||||
nativeConsoleAPI: true,
|
}
|
||||||
startedListeners:
|
|
||||||
vec!("PageError".to_string(), "ConsoleAPI".to_string()),
|
impl TabActor {
|
||||||
};
|
fn encodable(&self) -> TabActorMsg {
|
||||||
stream.write_json_packet(&msg);
|
TabActorMsg {
|
||||||
true
|
actor: self.name(),
|
||||||
}
|
title: self.title.clone(),
|
||||||
|
url: self.url.clone(),
|
||||||
|
outerWindowID: 0,
|
||||||
|
consoleActor: "console0".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Actor for ConsoleActor {
|
||||||
|
fn name(&self) -> String {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_message(&self,
|
||||||
|
_registry: &ActorRegistry,
|
||||||
|
msg_type: &String,
|
||||||
|
msg: &json::Object,
|
||||||
|
stream: &mut TcpStream) -> bool {
|
||||||
|
match msg_type.as_slice() {
|
||||||
"getCachedMessages" => {
|
"getCachedMessages" => {
|
||||||
let types = msg.find(&"messageTypes".to_string()).unwrap().as_list().unwrap();
|
let types = msg.find(&"messageTypes".to_string()).unwrap().as_list().unwrap();
|
||||||
let mut messages = vec!();
|
let mut messages = vec!();
|
||||||
|
@ -356,6 +450,20 @@ impl Actor for TabActor {
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
"startListeners" => {
|
||||||
|
let msg = StartedListenersReply {
|
||||||
|
from: self.name(),
|
||||||
|
nativeConsoleAPI: true,
|
||||||
|
startedListeners:
|
||||||
|
vec!("PageError".to_string(), "ConsoleAPI".to_string(),
|
||||||
|
"NetworkActivity".to_string(), "FileActivity".to_string()),
|
||||||
|
traits: StartedListenersTraits {
|
||||||
|
customNetworkRequest: true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
stream.write_json_packet(&msg);
|
||||||
|
true
|
||||||
|
}
|
||||||
"stopListeners" => {
|
"stopListeners" => {
|
||||||
let msg = StopListenersReply {
|
let msg = StopListenersReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
|
@ -380,10 +488,60 @@ impl Actor for TabActor {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
"evaluateJS" => {
|
"evaluateJS" => {
|
||||||
|
let input = msg.find(&"text".to_string()).unwrap().as_string().unwrap().to_string();
|
||||||
|
let (chan, port) = channel();
|
||||||
|
self.script_chan.send(EvaluateJS(self.pipeline, input.clone(), chan));
|
||||||
|
|
||||||
|
let result = match port.recv() {
|
||||||
|
VoidValue => {
|
||||||
|
let mut m = TreeMap::new();
|
||||||
|
m.insert("type".to_string(), "undefined".to_string().to_json());
|
||||||
|
json::Object(m)
|
||||||
|
}
|
||||||
|
NullValue => {
|
||||||
|
let mut m = TreeMap::new();
|
||||||
|
m.insert("type".to_string(), "null".to_string().to_json());
|
||||||
|
json::Object(m)
|
||||||
|
}
|
||||||
|
BooleanValue(val) => val.to_json(),
|
||||||
|
NumberValue(val) => {
|
||||||
|
if val.is_nan() {
|
||||||
|
let mut m = TreeMap::new();
|
||||||
|
m.insert("type".to_string(), "NaN".to_string().to_json());
|
||||||
|
json::Object(m)
|
||||||
|
} else if val.is_infinite() {
|
||||||
|
let mut m = TreeMap::new();
|
||||||
|
if val < 0. {
|
||||||
|
m.insert("type".to_string(), "Infinity".to_string().to_json());
|
||||||
|
} else {
|
||||||
|
m.insert("type".to_string(), "-Infinity".to_string().to_json());
|
||||||
|
}
|
||||||
|
json::Object(m)
|
||||||
|
} else if val == Float::neg_zero() {
|
||||||
|
let mut m = TreeMap::new();
|
||||||
|
m.insert("type".to_string(), "-0".to_string().to_json());
|
||||||
|
json::Object(m)
|
||||||
|
} else {
|
||||||
|
val.to_json()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringValue(s) => s.to_json(),
|
||||||
|
ActorValue(s) => {
|
||||||
|
let mut m = TreeMap::new();
|
||||||
|
m.insert("type".to_string(), "object".to_string().to_json());
|
||||||
|
m.insert("class".to_string(), "???".to_string().to_json());
|
||||||
|
m.insert("actor".to_string(), s.to_json());
|
||||||
|
m.insert("extensible".to_string(), true.to_json());
|
||||||
|
m.insert("frozen".to_string(), false.to_json());
|
||||||
|
m.insert("sealed".to_string(), false.to_json());
|
||||||
|
json::Object(m)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let msg = EvaluateJSReply {
|
let msg = EvaluateJSReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
input: msg.find(&"text".to_string()).unwrap().as_string().unwrap().to_string(),
|
input: input,
|
||||||
result: json::Object(TreeMap::new()),
|
result: result,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
exception: json::Object(TreeMap::new()),
|
exception: json::Object(TreeMap::new()),
|
||||||
exceptionMessage: "".to_string(),
|
exceptionMessage: "".to_string(),
|
||||||
|
@ -397,18 +555,6 @@ impl Actor for TabActor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TabActor {
|
|
||||||
fn encodable(&self) -> TabActorMsg {
|
|
||||||
TabActorMsg {
|
|
||||||
actor: self.name(),
|
|
||||||
title: self.title.clone(),
|
|
||||||
url: self.url.clone(),
|
|
||||||
outerWindowID: 0,
|
|
||||||
consoleActor: self.name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait JsonPacketSender {
|
trait JsonPacketSender {
|
||||||
fn write_json_packet<'a, T: Encodable<json::Encoder<'a>,IoError>>(&mut self, obj: &T);
|
fn write_json_packet<'a, T: Encodable<json::Encoder<'a>,IoError>>(&mut self, obj: &T);
|
||||||
}
|
}
|
||||||
|
@ -442,18 +588,13 @@ fn run_server(port: Receiver<DevtoolsControlMsg>) {
|
||||||
|
|
||||||
let mut registry = ActorRegistry::new();
|
let mut registry = ActorRegistry::new();
|
||||||
|
|
||||||
let tab = box TabActor {
|
|
||||||
name: "tab1".to_string(),
|
|
||||||
title: "Performing Layout".to_string(),
|
|
||||||
url: "about-mozilla.html".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let root = box RootActor {
|
let root = box RootActor {
|
||||||
tabs: vec!(tab.name().to_string()),
|
next: 0,
|
||||||
|
tabs: vec!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
registry.register(tab);
|
registry.register::<RootActor>(root);
|
||||||
registry.register(root);
|
registry.find::<RootActor>("root");
|
||||||
|
|
||||||
let actors = Arc::new(Mutex::new(registry));
|
let actors = Arc::new(Mutex::new(registry));
|
||||||
|
|
||||||
|
@ -496,13 +637,41 @@ fn run_server(port: Receiver<DevtoolsControlMsg>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_new_global(actors: Arc<Mutex<ActorRegistry>>,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
sender: Sender<DevtoolScriptControlMsg>) {
|
||||||
|
{
|
||||||
|
let mut actors = actors.lock();
|
||||||
|
|
||||||
|
let (tab, console) = {
|
||||||
|
let root = actors.find_mut::<RootActor>("root");
|
||||||
|
|
||||||
|
let tab = TabActor {
|
||||||
|
name: format!("tab{}", root.next),
|
||||||
|
title: "".to_string(),
|
||||||
|
url: "about:blank".to_string(),
|
||||||
|
};
|
||||||
|
let console = ConsoleActor {
|
||||||
|
name: format!("console{}", root.next),
|
||||||
|
script_chan: sender,
|
||||||
|
pipeline: pipeline,
|
||||||
|
};
|
||||||
|
root.next += 1;
|
||||||
|
root.tabs.push(tab.name.clone());
|
||||||
|
(tab, console)
|
||||||
|
};
|
||||||
|
actors.register::<TabActor>(box tab);
|
||||||
|
actors.register::<ConsoleActor>(box console);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// accept connections and process them, spawning a new tasks for each one
|
// accept connections and process them, spawning a new tasks for each one
|
||||||
for stream in acceptor.incoming() {
|
for stream in acceptor.incoming() {
|
||||||
match stream {
|
match stream {
|
||||||
Err(ref e) if e.kind == TimedOut => {
|
Err(ref e) if e.kind == TimedOut => {
|
||||||
match port.try_recv() {
|
match port.try_recv() {
|
||||||
Ok(ServerExitMsg) | Err(Disconnected) => break,
|
Ok(ServerExitMsg) | Err(Disconnected) => break,
|
||||||
Ok(NewGlobal(_)) => { /*TODO*/ },
|
Ok(NewGlobal(id, sender)) => handle_new_global(actors.clone(), id, sender),
|
||||||
Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)),
|
Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,3 +6,6 @@ authors = ["The Servo Project Developers"]
|
||||||
[lib]
|
[lib]
|
||||||
name = "devtools_traits"
|
name = "devtools_traits"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
|
[dependencies.msg]
|
||||||
|
path = "../msg"
|
||||||
|
|
|
@ -8,24 +8,29 @@
|
||||||
#![comment = "The Servo Parallel Browser Project"]
|
#![comment = "The Servo Parallel Browser Project"]
|
||||||
#![license = "MPL"]
|
#![license = "MPL"]
|
||||||
|
|
||||||
|
extern crate servo_msg = "msg";
|
||||||
|
|
||||||
|
use servo_msg::constellation_msg::PipelineId;
|
||||||
|
|
||||||
pub type DevtoolsControlChan = Sender<DevtoolsControlMsg>;
|
pub type DevtoolsControlChan = Sender<DevtoolsControlMsg>;
|
||||||
pub type DevtoolsControlPort = Receiver<DevtoolScriptControlMsg>;
|
pub type DevtoolsControlPort = Receiver<DevtoolScriptControlMsg>;
|
||||||
|
|
||||||
pub enum DevtoolsControlMsg {
|
pub enum DevtoolsControlMsg {
|
||||||
NewGlobal(Sender<DevtoolScriptControlMsg>),
|
NewGlobal(PipelineId, Sender<DevtoolScriptControlMsg>),
|
||||||
ServerExitMsg
|
ServerExitMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum EvaluateJSReply {
|
pub enum EvaluateJSReply {
|
||||||
VoidValue,
|
VoidValue,
|
||||||
NullValue,
|
NullValue,
|
||||||
|
BooleanValue(bool),
|
||||||
NumberValue(f64),
|
NumberValue(f64),
|
||||||
StringValue(String),
|
StringValue(String),
|
||||||
ActorValue(String),
|
ActorValue(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum DevtoolScriptControlMsg {
|
pub enum DevtoolScriptControlMsg {
|
||||||
EvaluateJS(String, Sender<EvaluateJSReply>),
|
EvaluateJS(PipelineId, String, Sender<EvaluateJSReply>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ScriptDevtoolControlMsg {
|
pub enum ScriptDevtoolControlMsg {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//! and layout tasks.
|
//! and layout tasks.
|
||||||
|
|
||||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast};
|
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast};
|
||||||
|
use dom::bindings::conversions;
|
||||||
use dom::bindings::conversions::{FromJSValConvertible, Empty};
|
use dom::bindings::conversions::{FromJSValConvertible, Empty};
|
||||||
use dom::bindings::global::Window;
|
use dom::bindings::global::Window;
|
||||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalSettable};
|
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalSettable};
|
||||||
|
@ -31,8 +32,9 @@ use layout_interface::ContentChangedDocumentDamage;
|
||||||
use layout_interface;
|
use layout_interface;
|
||||||
use page::{Page, IterablePage, Frame};
|
use page::{Page, IterablePage, Frame};
|
||||||
|
|
||||||
|
use devtools_traits;
|
||||||
use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, NewGlobal};
|
use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, NewGlobal};
|
||||||
use devtools_traits::{DevtoolScriptControlMsg, EvaluateJS};
|
use devtools_traits::{DevtoolScriptControlMsg, EvaluateJS, EvaluateJSReply};
|
||||||
use script_traits::{CompositorEvent, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent};
|
use script_traits::{CompositorEvent, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent};
|
||||||
use script_traits::{MouseMoveEvent, MouseUpEvent, ConstellationControlMsg, ScriptTaskFactory};
|
use script_traits::{MouseMoveEvent, MouseUpEvent, ConstellationControlMsg, ScriptTaskFactory};
|
||||||
use script_traits::{ResizeMsg, AttachLayoutMsg, LoadMsg, SendEventMsg, ResizeInactiveMsg};
|
use script_traits::{ResizeMsg, AttachLayoutMsg, LoadMsg, SendEventMsg, ResizeInactiveMsg};
|
||||||
|
@ -315,7 +317,7 @@ impl ScriptTask {
|
||||||
//FIXME: Move this into handle_load after we create a window instead.
|
//FIXME: Move this into handle_load after we create a window instead.
|
||||||
let (devtools_sender, devtools_receiver) = channel();
|
let (devtools_sender, devtools_receiver) = channel();
|
||||||
devtools_chan.as_ref().map(|chan| {
|
devtools_chan.as_ref().map(|chan| {
|
||||||
chan.send(NewGlobal(devtools_sender.clone()));
|
chan.send(NewGlobal(id, devtools_sender.clone()));
|
||||||
});
|
});
|
||||||
|
|
||||||
Rc::new(ScriptTask {
|
Rc::new(ScriptTask {
|
||||||
|
@ -496,13 +498,36 @@ impl ScriptTask {
|
||||||
FromScript(DOMMessage(..)) => fail!("unexpected message"),
|
FromScript(DOMMessage(..)) => fail!("unexpected message"),
|
||||||
FromScript(WorkerPostMessage(addr, data, nbytes)) => Worker::handle_message(addr, data, nbytes),
|
FromScript(WorkerPostMessage(addr, data, nbytes)) => Worker::handle_message(addr, data, nbytes),
|
||||||
FromScript(WorkerRelease(addr)) => Worker::handle_release(addr),
|
FromScript(WorkerRelease(addr)) => Worker::handle_release(addr),
|
||||||
FromDevtools(EvaluateJS(_s, _reply)) => {/*TODO*/}
|
FromDevtools(EvaluateJS(id, s, reply)) => self.handle_evaluate_js(id, s, reply),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_evaluate_js(&self, pipeline: PipelineId, eval: String, reply: Sender<EvaluateJSReply>) {
|
||||||
|
let page = get_page(&*self.page.borrow(), pipeline);
|
||||||
|
let frame = page.frame();
|
||||||
|
let window = frame.get_ref().window.root();
|
||||||
|
let cx = window.get_cx();
|
||||||
|
let rval = window.evaluate_js_with_result(eval.as_slice());
|
||||||
|
|
||||||
|
reply.send(if rval.is_undefined() {
|
||||||
|
devtools_traits::VoidValue
|
||||||
|
} else if rval.is_boolean() {
|
||||||
|
devtools_traits::BooleanValue(rval.to_boolean())
|
||||||
|
} else if rval.is_double() {
|
||||||
|
devtools_traits::NumberValue(FromJSValConvertible::from_jsval(cx, rval, ()).unwrap())
|
||||||
|
} else if rval.is_string() {
|
||||||
|
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
||||||
|
devtools_traits::StringValue(FromJSValConvertible::from_jsval(cx, rval, conversions::Default).unwrap())
|
||||||
|
} else {
|
||||||
|
//FIXME: jsvals don't have an is_int32/is_number yet
|
||||||
|
assert!(rval.is_object_or_null());
|
||||||
|
fail!("object values unimplemented")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_new_layout(&self, new_layout_info: NewLayoutInfo) {
|
fn handle_new_layout(&self, new_layout_info: NewLayoutInfo) {
|
||||||
debug!("Script: new layout: {:?}", new_layout_info);
|
debug!("Script: new layout: {:?}", new_layout_info);
|
||||||
let NewLayoutInfo {
|
let NewLayoutInfo {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue