diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index bea09a8b3fa..70beed1c2e1 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -35,7 +35,7 @@ use actors::root::RootActor; use actors::tab::TabActor; use protocol::JsonPacketStream; -use devtools_traits::{ServerExitMsg, DevtoolsControlMsg, NewGlobal, DevtoolScriptControlMsg}; +use devtools_traits::{ServerExitMsg, DevtoolsControlMsg, NewGlobal, DevtoolScriptControlMsg, DevtoolsPageInfo}; use servo_msg::constellation_msg::PipelineId; use servo_util::task::spawn_named; @@ -127,7 +127,8 @@ fn run_server(receiver: Receiver, port: u16) { fn handle_new_global(actors: Arc>, pipeline: PipelineId, sender: Sender, - actor_pipelines: &mut HashMap) { + actor_pipelines: &mut HashMap, + page_info: DevtoolsPageInfo) { let mut actors = actors.lock(); //TODO: move all this actor creation into a constructor method on TabActor @@ -146,11 +147,12 @@ fn run_server(receiver: Receiver, port: u16) { script_chan: sender, pipeline: pipeline, }; - //TODO: send along the current page title and URL + + let DevtoolsPageInfo { title, url } = page_info; let tab = TabActor { name: actors.new_name("tab"), - title: "".to_string(), - url: "about:blank".to_string(), + title: title, + url: url.serialize(), console: console.name(), inspector: inspector.name(), }; @@ -177,7 +179,7 @@ fn run_server(receiver: Receiver, port: u16) { Err(ref e) if e.kind == TimedOut => { match receiver.try_recv() { Ok(ServerExitMsg) | Err(Disconnected) => break, - Ok(NewGlobal(id, sender)) => handle_new_global(actors.clone(), id, sender, &mut actor_pipelines), + Ok(NewGlobal(id, sender, pageinfo)) => handle_new_global(actors.clone(), id, sender, &mut actor_pipelines, pageinfo), Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)), } } diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 5c437bd6e56..3e5261bd69b 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -12,6 +12,8 @@ extern crate "msg" as servo_msg; extern crate serialize; +extern crate url; +extern crate "util" as servo_util; /// This module contains shared types and messages for use by devtools/script. /// The traits are here instead of in script so that the devtools crate can be @@ -19,14 +21,23 @@ extern crate serialize; use serialize::{Decodable, Decoder}; use servo_msg::constellation_msg::PipelineId; +use servo_util::str::DOMString; +use url::Url; pub type DevtoolsControlChan = Sender; pub type DevtoolsControlPort = Receiver; +// Information would be attached to NewGlobal to be received and show in devtools. +// Extend these fields if we need more information. +pub struct DevtoolsPageInfo { + pub title: DOMString, + pub url: Url +} + /// Messages to the instruct the devtools server to update its known actors/state /// according to changes in the browser. pub enum DevtoolsControlMsg { - NewGlobal(PipelineId, Sender), + NewGlobal(PipelineId, Sender, DevtoolsPageInfo), ServerExitMsg } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index dd29d9e31d3..e0b6025d238 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -35,7 +35,7 @@ use page::{Page, IterablePage, Frame}; use timers::TimerId; use devtools; -use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, NewGlobal, GetRootNode}; +use devtools_traits::{DevtoolsControlChan, DevtoolsControlPort, NewGlobal, GetRootNode, DevtoolsPageInfo}; use devtools_traits::{DevtoolScriptControlMsg, EvaluateJS, GetDocumentElement}; use devtools_traits::{GetChildren, GetLayout, ModifyAttribute}; use script_traits::{CompositorEvent, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent}; @@ -185,6 +185,7 @@ pub struct ScriptTask { /// For receiving commands from an optional devtools server. Will be ignored if /// no such server exists. devtools_port: DevtoolsControlPort, + devtools_sender: Sender, /// The JavaScript runtime. js_runtime: js::rust::rt, @@ -344,13 +345,7 @@ impl ScriptTask { constellation_chan.clone(), js_context.clone()); - // Notify devtools that a new script global exists. - //FIXME: Move this into handle_load after we create a window instead. let (devtools_sender, devtools_receiver) = channel(); - devtools_chan.as_ref().map(|chan| { - chan.send(NewGlobal(id, devtools_sender.clone())); - }); - ScriptTask { page: DOMRefCell::new(Rc::new(page)), @@ -365,6 +360,7 @@ impl ScriptTask { compositor: DOMRefCell::new(compositor), devtools_chan: devtools_chan, devtools_port: devtools_receiver, + devtools_sender: devtools_sender, js_runtime: js_runtime, js_context: DOMRefCell::new(Some(js_context)), @@ -824,10 +820,23 @@ impl ScriptTask { let wintarget: JSRef = EventTargetCast::from_ref(*window); let _ = wintarget.dispatch_event_with_target(Some(doctarget), *event); - *page.fragment_name.borrow_mut() = final_url.fragment; + *page.fragment_name.borrow_mut() = final_url.fragment.clone(); let ConstellationChan(ref chan) = self.constellation_chan; chan.send(LoadCompleteMsg); + + // Notify devtools that a new script global exists. + match self.devtools_chan { + None => {} + Some(ref chan) => { + let page_info = DevtoolsPageInfo { + title: document.Title(), + url: final_url + }; + chan.send(NewGlobal(pipeline_id, self.devtools_sender.clone(), + page_info)); + } + } } fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: JSRef) {