mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Introduce GlobalScope::devtools_chan
This commit is contained in:
parent
14a0b8d88c
commit
fe6fca9e1f
8 changed files with 33 additions and 38 deletions
|
@ -272,7 +272,8 @@ pub fn handle_request_animation_frame(context: &BrowsingContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
let doc = context.active_document();
|
let doc = context.active_document();
|
||||||
let devtools_sender = context.active_window().devtools_chan().unwrap();
|
let devtools_sender =
|
||||||
|
context.active_window().upcast::<GlobalScope>().devtools_chan().unwrap().clone();
|
||||||
doc.request_animation_frame(box move |time| {
|
doc.request_animation_frame(box move |time| {
|
||||||
let msg = ScriptToDevtoolsControlMsg::FramerateTick(actor_name, time);
|
let msg = ScriptToDevtoolsControlMsg::FramerateTick(actor_name, time);
|
||||||
devtools_sender.send(msg).unwrap();
|
devtools_sender.send(msg).unwrap();
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
//! This module contains smart pointers to global scopes, to simplify writing
|
//! This module contains smart pointers to global scopes, to simplify writing
|
||||||
//! code that works in workers as well as window scopes.
|
//! code that works in workers as well as window scopes.
|
||||||
|
|
||||||
use devtools_traits::ScriptToDevtoolsControlMsg;
|
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::conversions::root_from_object;
|
use dom::bindings::conversions::root_from_object;
|
||||||
use dom::bindings::error::{ErrorInfo, report_pending_exception};
|
use dom::bindings::error::{ErrorInfo, report_pending_exception};
|
||||||
|
@ -122,15 +121,6 @@ impl<'a> GlobalRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an `IpcSender<ScriptToDevtoolsControlMsg>` to send messages to Devtools
|
|
||||||
/// thread when available.
|
|
||||||
pub fn devtools_chan(&self) -> Option<IpcSender<ScriptToDevtoolsControlMsg>> {
|
|
||||||
match *self {
|
|
||||||
GlobalRef::Window(window) => window.devtools_chan(),
|
|
||||||
GlobalRef::Worker(worker) => worker.devtools_chan(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the `ResourceThreads` for this global scope.
|
/// Get the `ResourceThreads` for this global scope.
|
||||||
pub fn resource_threads(&self) -> ResourceThreads {
|
pub fn resource_threads(&self) -> ResourceThreads {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct Console(());
|
||||||
|
|
||||||
impl Console {
|
impl Console {
|
||||||
fn send_to_devtools(global: GlobalRef, level: LogLevel, message: DOMString) {
|
fn send_to_devtools(global: GlobalRef, level: LogLevel, message: DOMString) {
|
||||||
if let Some(chan) = global.devtools_chan() {
|
if let Some(chan) = global.as_global_scope().devtools_chan() {
|
||||||
let console_message = prepare_message(level, message);
|
let console_message = prepare_message(level, message);
|
||||||
let worker_id = if let GlobalRef::Worker(worker) = global {
|
let worker_id = if let GlobalRef::Worker(worker) = global {
|
||||||
Some(worker.get_worker_id())
|
Some(worker.get_worker_id())
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use devtools_traits::WorkerId;
|
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
use dom::bindings::reflector::Reflectable;
|
use dom::bindings::reflector::Reflectable;
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::crypto::Crypto;
|
use dom::crypto::Crypto;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
use ipc_channel::ipc::IpcSender;
|
||||||
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
|
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -27,16 +28,23 @@ pub struct GlobalScope {
|
||||||
|
|
||||||
/// Timers used by the Console API.
|
/// Timers used by the Console API.
|
||||||
console_timers: DOMRefCell<HashMap<DOMString, u64>>,
|
console_timers: DOMRefCell<HashMap<DOMString, u64>>,
|
||||||
|
|
||||||
|
/// For providing instructions to an optional devtools server.
|
||||||
|
#[ignore_heap_size_of = "channels are hard"]
|
||||||
|
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalScope {
|
impl GlobalScope {
|
||||||
pub fn new_inherited() -> GlobalScope {
|
pub fn new_inherited(
|
||||||
|
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>)
|
||||||
|
-> Self {
|
||||||
GlobalScope {
|
GlobalScope {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
crypto: Default::default(),
|
crypto: Default::default(),
|
||||||
next_worker_id: Cell::new(WorkerId(0)),
|
next_worker_id: Cell::new(WorkerId(0)),
|
||||||
devtools_wants_updates: Default::default(),
|
devtools_wants_updates: Default::default(),
|
||||||
console_timers: DOMRefCell::new(Default::default()),
|
console_timers: DOMRefCell::new(Default::default()),
|
||||||
|
devtools_chan: devtools_chan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +99,12 @@ impl GlobalScope {
|
||||||
timestamp_in_ms(get_time()) - start
|
timestamp_in_ms(get_time()) - start
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get an `&IpcSender<ScriptToDevtoolsControlMsg>` to send messages
|
||||||
|
/// to the devtools thread when available.
|
||||||
|
pub fn devtools_chan(&self) -> Option<&IpcSender<ScriptToDevtoolsControlMsg>> {
|
||||||
|
self.devtools_chan.as_ref()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||||
|
|
|
@ -57,13 +57,15 @@ impl ServiceWorkerRegistration {
|
||||||
pipeline_id: Some(global.pipeline_id())
|
pipeline_id: Some(global.pipeline_id())
|
||||||
};
|
};
|
||||||
|
|
||||||
let worker_id = global.as_global_scope().get_next_worker_id();
|
let global_scope = global.as_global_scope();
|
||||||
|
let worker_id = global_scope.get_next_worker_id();
|
||||||
|
let devtools_chan = global_scope.devtools_chan().cloned();
|
||||||
let init = prepare_workerscope_init(global, None);
|
let init = prepare_workerscope_init(global, None);
|
||||||
ScopeThings {
|
ScopeThings {
|
||||||
script_url: script_url,
|
script_url: script_url,
|
||||||
init: init,
|
init: init,
|
||||||
worker_load_origin: worker_load_origin,
|
worker_load_origin: worker_load_origin,
|
||||||
devtools_chan: global.devtools_chan(),
|
devtools_chan: devtools_chan,
|
||||||
worker_id: worker_id
|
worker_id: worker_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,9 +182,6 @@ pub struct Window {
|
||||||
#[ignore_heap_size_of = "channels are hard"]
|
#[ignore_heap_size_of = "channels are hard"]
|
||||||
time_profiler_chan: ProfilerChan,
|
time_profiler_chan: ProfilerChan,
|
||||||
|
|
||||||
/// For providing instructions to an optional devtools server.
|
|
||||||
#[ignore_heap_size_of = "channels are hard"]
|
|
||||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
|
||||||
/// For sending timeline markers. Will be ignored if
|
/// For sending timeline markers. Will be ignored if
|
||||||
/// no devtools server
|
/// no devtools server
|
||||||
devtools_markers: DOMRefCell<HashSet<TimelineMarkerType>>,
|
devtools_markers: DOMRefCell<HashSet<TimelineMarkerType>>,
|
||||||
|
@ -1391,10 +1388,6 @@ impl Window {
|
||||||
&self.time_profiler_chan
|
&self.time_profiler_chan
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn devtools_chan(&self) -> Option<IpcSender<ScriptToDevtoolsControlMsg>> {
|
|
||||||
self.devtools_chan.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn layout_chan(&self) -> &Sender<Msg> {
|
pub fn layout_chan(&self) -> &Sender<Msg> {
|
||||||
&self.layout_chan
|
&self.layout_chan
|
||||||
}
|
}
|
||||||
|
@ -1608,7 +1601,7 @@ impl Window {
|
||||||
};
|
};
|
||||||
let current_time = time::get_time();
|
let current_time = time::get_time();
|
||||||
let win = box Window {
|
let win = box Window {
|
||||||
globalscope: GlobalScope::new_inherited(),
|
globalscope: GlobalScope::new_inherited(devtools_chan),
|
||||||
script_chan: script_chan,
|
script_chan: script_chan,
|
||||||
dom_manipulation_task_source: dom_task_source,
|
dom_manipulation_task_source: dom_task_source,
|
||||||
user_interaction_task_source: user_task_source,
|
user_interaction_task_source: user_task_source,
|
||||||
|
@ -1620,7 +1613,6 @@ impl Window {
|
||||||
image_cache_thread: image_cache_thread,
|
image_cache_thread: image_cache_thread,
|
||||||
mem_profiler_chan: mem_profiler_chan,
|
mem_profiler_chan: mem_profiler_chan,
|
||||||
time_profiler_chan: time_profiler_chan,
|
time_profiler_chan: time_profiler_chan,
|
||||||
devtools_chan: devtools_chan,
|
|
||||||
history: Default::default(),
|
history: Default::default(),
|
||||||
browsing_context: Default::default(),
|
browsing_context: Default::default(),
|
||||||
performance: Default::default(),
|
performance: Default::default(),
|
||||||
|
|
|
@ -91,8 +91,9 @@ impl Worker {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (devtools_sender, devtools_receiver) = ipc::channel().unwrap();
|
let (devtools_sender, devtools_receiver) = ipc::channel().unwrap();
|
||||||
let worker_id = global.as_global_scope().get_next_worker_id();
|
let global_scope = global.as_global_scope();
|
||||||
if let Some(ref chan) = global.devtools_chan() {
|
let worker_id = global_scope.get_next_worker_id();
|
||||||
|
if let Some(ref chan) = global_scope.devtools_chan() {
|
||||||
let pipeline_id = global.pipeline_id();
|
let pipeline_id = global.pipeline_id();
|
||||||
let title = format!("Worker for {}", worker_url);
|
let title = format!("Worker for {}", worker_url);
|
||||||
let page_info = DevtoolsPageInfo {
|
let page_info = DevtoolsPageInfo {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
|
use devtools_traits::{DevtoolScriptControlMsg, WorkerId};
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||||
use dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
use dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
||||||
|
@ -55,11 +55,13 @@ use url::Url;
|
||||||
|
|
||||||
pub fn prepare_workerscope_init(global: GlobalRef,
|
pub fn prepare_workerscope_init(global: GlobalRef,
|
||||||
devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>) -> WorkerGlobalScopeInit {
|
devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>) -> WorkerGlobalScopeInit {
|
||||||
let worker_id = global.as_global_scope().get_next_worker_id();
|
let global_scope = global.as_global_scope();
|
||||||
|
let worker_id = global_scope.get_next_worker_id();
|
||||||
|
let to_devtools_sender = global_scope.devtools_chan().cloned();
|
||||||
let init = WorkerGlobalScopeInit {
|
let init = WorkerGlobalScopeInit {
|
||||||
resource_threads: global.resource_threads(),
|
resource_threads: global.resource_threads(),
|
||||||
mem_profiler_chan: global.mem_profiler_chan().clone(),
|
mem_profiler_chan: global.mem_profiler_chan().clone(),
|
||||||
to_devtools_sender: global.devtools_chan(),
|
to_devtools_sender: to_devtools_sender,
|
||||||
time_profiler_chan: global.time_profiler_chan().clone(),
|
time_profiler_chan: global.time_profiler_chan().clone(),
|
||||||
from_devtools_sender: devtools_sender,
|
from_devtools_sender: devtools_sender,
|
||||||
constellation_chan: global.constellation_chan().clone(),
|
constellation_chan: global.constellation_chan().clone(),
|
||||||
|
@ -93,8 +95,6 @@ pub struct WorkerGlobalScope {
|
||||||
mem_profiler_chan: mem::ProfilerChan,
|
mem_profiler_chan: mem::ProfilerChan,
|
||||||
#[ignore_heap_size_of = "Defined in std"]
|
#[ignore_heap_size_of = "Defined in std"]
|
||||||
time_profiler_chan: time::ProfilerChan,
|
time_profiler_chan: time::ProfilerChan,
|
||||||
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
|
||||||
to_devtools_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
|
||||||
|
|
||||||
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
||||||
/// Optional `IpcSender` for sending the `DevtoolScriptControlMsg`
|
/// Optional `IpcSender` for sending the `DevtoolScriptControlMsg`
|
||||||
|
@ -127,7 +127,7 @@ impl WorkerGlobalScope {
|
||||||
closing: Option<Arc<AtomicBool>>)
|
closing: Option<Arc<AtomicBool>>)
|
||||||
-> WorkerGlobalScope {
|
-> WorkerGlobalScope {
|
||||||
WorkerGlobalScope {
|
WorkerGlobalScope {
|
||||||
globalscope: GlobalScope::new_inherited(),
|
globalscope: GlobalScope::new_inherited(init.to_devtools_sender),
|
||||||
worker_id: init.worker_id,
|
worker_id: init.worker_id,
|
||||||
pipeline_id: init.pipeline_id,
|
pipeline_id: init.pipeline_id,
|
||||||
worker_url: worker_url,
|
worker_url: worker_url,
|
||||||
|
@ -139,7 +139,6 @@ impl WorkerGlobalScope {
|
||||||
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan.clone()),
|
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan.clone()),
|
||||||
mem_profiler_chan: init.mem_profiler_chan,
|
mem_profiler_chan: init.mem_profiler_chan,
|
||||||
time_profiler_chan: init.time_profiler_chan,
|
time_profiler_chan: init.time_profiler_chan,
|
||||||
to_devtools_sender: init.to_devtools_sender,
|
|
||||||
from_devtools_sender: init.from_devtools_sender,
|
from_devtools_sender: init.from_devtools_sender,
|
||||||
from_devtools_receiver: from_devtools_receiver,
|
from_devtools_receiver: from_devtools_receiver,
|
||||||
constellation_chan: init.constellation_chan,
|
constellation_chan: init.constellation_chan,
|
||||||
|
@ -157,10 +156,6 @@ impl WorkerGlobalScope {
|
||||||
&self.time_profiler_chan
|
&self.time_profiler_chan
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn devtools_chan(&self) -> Option<IpcSender<ScriptToDevtoolsControlMsg>> {
|
|
||||||
self.to_devtools_sender.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_devtools_sender(&self) -> Option<IpcSender<DevtoolScriptControlMsg>> {
|
pub fn from_devtools_sender(&self) -> Option<IpcSender<DevtoolScriptControlMsg>> {
|
||||||
self.from_devtools_sender.clone()
|
self.from_devtools_sender.clone()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue