mirror of
https://github.com/servo/servo.git
synced 2025-07-29 10:10:34 +01:00
Introduce InitialScriptState
This commit is contained in:
parent
9e1e2b8ed3
commit
a7738a5eef
3 changed files with 81 additions and 89 deletions
|
@ -4,8 +4,8 @@
|
|||
|
||||
use CompositorProxy;
|
||||
use layout_traits::{LayoutTaskFactory, LayoutControlChan};
|
||||
use script_traits::{LayoutControlMsg, ScriptTaskFactory};
|
||||
use script_traits::{NewLayoutInfo, ConstellationControlMsg};
|
||||
use script_traits::{ConstellationControlMsg, InitialScriptState};
|
||||
use script_traits::{LayoutControlMsg, NewLayoutInfo, ScriptTaskFactory};
|
||||
|
||||
use compositor_task;
|
||||
use devtools_traits::{DevtoolsControlMsg, ScriptToDevtoolsControlMsg};
|
||||
|
@ -340,23 +340,22 @@ impl PipelineContent {
|
|||
script_to_compositor_port)
|
||||
});
|
||||
|
||||
ScriptTaskFactory::create(None::<&mut STF>,
|
||||
self.id,
|
||||
self.parent_info,
|
||||
script_to_compositor_chan,
|
||||
&layout_pair,
|
||||
self.script_chan.clone(),
|
||||
mem::replace(&mut self.script_port, None).unwrap(),
|
||||
self.constellation_chan.clone(),
|
||||
self.failure.clone(),
|
||||
self.resource_task,
|
||||
self.storage_task.clone(),
|
||||
self.image_cache_task.clone(),
|
||||
self.time_profiler_chan.clone(),
|
||||
self.mem_profiler_chan.clone(),
|
||||
self.devtools_chan,
|
||||
self.window_size,
|
||||
self.load_data.clone());
|
||||
ScriptTaskFactory::create(None::<&mut STF>, InitialScriptState {
|
||||
id: self.id,
|
||||
parent_info: self.parent_info,
|
||||
compositor: script_to_compositor_chan,
|
||||
control_chan: self.script_chan.clone(),
|
||||
control_port: mem::replace(&mut self.script_port, None).unwrap(),
|
||||
constellation_chan: self.constellation_chan.clone(),
|
||||
failure_info: self.failure.clone(),
|
||||
resource_task: self.resource_task,
|
||||
storage_task: self.storage_task.clone(),
|
||||
image_cache_task: self.image_cache_task.clone(),
|
||||
time_profiler_chan: self.time_profiler_chan.clone(),
|
||||
mem_profiler_chan: self.mem_profiler_chan.clone(),
|
||||
devtools_chan: self.devtools_chan,
|
||||
window_size: self.window_size,
|
||||
}, &layout_pair, self.load_data.clone());
|
||||
|
||||
LayoutTaskFactory::create(None::<&mut LTF>,
|
||||
self.id,
|
||||
|
|
|
@ -55,9 +55,9 @@ use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker};
|
|||
use devtools_traits::{StartedTimelineMarker, TimelineMarkerType};
|
||||
use msg::compositor_msg::{LayerId, ScriptToCompositorMsg};
|
||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use msg::constellation_msg::{ConstellationChan, FocusType};
|
||||
use msg::constellation_msg::{Failure, WindowSizeData, PipelineExitType};
|
||||
use msg::constellation_msg::{LoadData, PipelineId, SubpageId, MozBrowserEvent, WorkerId};
|
||||
use msg::constellation_msg::{ConstellationChan, FocusType, LoadData};
|
||||
use msg::constellation_msg::{MozBrowserEvent, PipelineExitType, PipelineId};
|
||||
use msg::constellation_msg::{SubpageId, WindowSizeData, WorkerId};
|
||||
use msg::webdriver_msg::WebDriverScriptCommand;
|
||||
use net_traits::LoadData as NetLoadData;
|
||||
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask, ImageCacheResult};
|
||||
|
@ -68,10 +68,9 @@ use profile_traits::time::{self, ProfilerCategory, profile};
|
|||
use script_traits::CompositorEvent::{MouseDownEvent, MouseUpEvent};
|
||||
use script_traits::CompositorEvent::{MouseMoveEvent, KeyEvent};
|
||||
use script_traits::CompositorEvent::{ResizeEvent, ClickEvent};
|
||||
use script_traits::ConstellationControlMsg;
|
||||
use script_traits::{CompositorEvent, MouseButton};
|
||||
use script_traits::{NewLayoutInfo, OpaqueScriptLayoutChannel};
|
||||
use script_traits::{ScriptState, ScriptTaskFactory};
|
||||
use script_traits::{CompositorEvent, ConstellationControlMsg};
|
||||
use script_traits::{InitialScriptState, MouseButton, NewLayoutInfo};
|
||||
use script_traits::{OpaqueScriptLayoutChannel, ScriptState, ScriptTaskFactory};
|
||||
use string_cache::Atom;
|
||||
use util::opts;
|
||||
use util::str::DOMString;
|
||||
|
@ -471,42 +470,25 @@ impl ScriptTaskFactory for ScriptTask {
|
|||
}
|
||||
|
||||
fn create(_phantom: Option<&mut ScriptTask>,
|
||||
id: PipelineId,
|
||||
parent_info: Option<(PipelineId, SubpageId)>,
|
||||
compositor: IpcSender<ScriptToCompositorMsg>,
|
||||
state: InitialScriptState,
|
||||
layout_chan: &OpaqueScriptLayoutChannel,
|
||||
control_chan: Sender<ConstellationControlMsg>,
|
||||
control_port: Receiver<ConstellationControlMsg>,
|
||||
constellation_chan: ConstellationChan,
|
||||
failure_msg: Failure,
|
||||
resource_task: ResourceTask,
|
||||
storage_task: StorageTask,
|
||||
image_cache_task: ImageCacheTask,
|
||||
time_profiler_chan: time::ProfilerChan,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||
window_size: Option<WindowSizeData>,
|
||||
load_data: LoadData) {
|
||||
let ConstellationChan(const_chan) = constellation_chan.clone();
|
||||
let ConstellationChan(const_chan) = state.constellation_chan.clone();
|
||||
let (script_chan, script_port) = channel();
|
||||
let layout_chan = LayoutChan(layout_chan.sender());
|
||||
spawn_named_with_send_on_failure(format!("ScriptTask {:?}", id), task_state::SCRIPT, move || {
|
||||
let failure_info = state.failure_info;
|
||||
spawn_named_with_send_on_failure(format!("ScriptTask {:?}", state.id), task_state::SCRIPT, move || {
|
||||
let roots = RootCollection::new();
|
||||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
let chan = MainThreadScriptChan(script_chan);
|
||||
let channel_for_reporter = chan.clone();
|
||||
let script_task = ScriptTask::new(compositor,
|
||||
let id = state.id;
|
||||
let parent_info = state.parent_info;
|
||||
let mem_profiler_chan = state.mem_profiler_chan.clone();
|
||||
let window_size = state.window_size;
|
||||
let script_task = ScriptTask::new(state,
|
||||
script_port,
|
||||
chan,
|
||||
control_chan,
|
||||
control_port,
|
||||
constellation_chan,
|
||||
Arc::new(resource_task),
|
||||
storage_task,
|
||||
image_cache_task,
|
||||
time_profiler_chan.clone(),
|
||||
mem_profiler_chan.clone(),
|
||||
devtools_chan);
|
||||
chan);
|
||||
|
||||
SCRIPT_TASK_ROOT.with(|root| {
|
||||
*root.borrow_mut() = Some(&script_task as *const _);
|
||||
|
@ -525,7 +507,7 @@ impl ScriptTaskFactory for ScriptTask {
|
|||
|
||||
// This must always be the very last operation performed before the task completes
|
||||
failsafe.neuter();
|
||||
}, ConstellationMsg::Failure(failure_msg), const_chan);
|
||||
}, ConstellationMsg::Failure(failure_info), const_chan);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -611,18 +593,9 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
/// Creates a new script task.
|
||||
pub fn new(compositor: IpcSender<ScriptToCompositorMsg>,
|
||||
pub fn new(state: InitialScriptState,
|
||||
port: Receiver<MainThreadScriptMsg>,
|
||||
chan: MainThreadScriptChan,
|
||||
control_chan: Sender<ConstellationControlMsg>,
|
||||
control_port: Receiver<ConstellationControlMsg>,
|
||||
constellation_chan: ConstellationChan,
|
||||
resource_task: Arc<ResourceTask>,
|
||||
storage_task: StorageTask,
|
||||
image_cache_task: ImageCacheTask,
|
||||
time_profiler_chan: time::ProfilerChan,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>)
|
||||
chan: MainThreadScriptChan)
|
||||
-> ScriptTask {
|
||||
let runtime = ScriptTask::new_rt_and_cx();
|
||||
|
||||
|
@ -644,23 +617,23 @@ impl ScriptTask {
|
|||
page: DOMRefCell::new(None),
|
||||
incomplete_loads: DOMRefCell::new(vec!()),
|
||||
|
||||
image_cache_task: image_cache_task,
|
||||
image_cache_task: state.image_cache_task,
|
||||
image_cache_channel: ImageCacheChan(ipc_image_cache_channel),
|
||||
image_cache_port: image_cache_port,
|
||||
|
||||
resource_task: resource_task,
|
||||
storage_task: storage_task,
|
||||
resource_task: Arc::new(state.resource_task),
|
||||
storage_task: state.storage_task,
|
||||
|
||||
port: port,
|
||||
chan: chan,
|
||||
control_chan: control_chan,
|
||||
control_port: control_port,
|
||||
constellation_chan: constellation_chan,
|
||||
compositor: DOMRefCell::new(compositor),
|
||||
time_profiler_chan: time_profiler_chan,
|
||||
mem_profiler_chan: mem_profiler_chan,
|
||||
control_chan: state.control_chan,
|
||||
control_port: state.control_port,
|
||||
constellation_chan: state.constellation_chan,
|
||||
compositor: DOMRefCell::new(state.compositor),
|
||||
time_profiler_chan: state.time_profiler_chan,
|
||||
mem_profiler_chan: state.mem_profiler_chan,
|
||||
|
||||
devtools_chan: devtools_chan,
|
||||
devtools_chan: state.devtools_chan,
|
||||
devtools_port: devtools_port,
|
||||
devtools_sender: ipc_devtools_sender,
|
||||
devtools_markers: RefCell::new(HashSet::new()),
|
||||
|
|
|
@ -171,26 +171,46 @@ pub enum CompositorEvent {
|
|||
/// crates that don't need to know about them.
|
||||
pub struct OpaqueScriptLayoutChannel(pub (Box<Any + Send>, Box<Any + Send>));
|
||||
|
||||
/// Data needed to construct a script thread.
|
||||
pub struct InitialScriptState {
|
||||
/// The ID of the pipeline with which this script thread is associated.
|
||||
pub id: PipelineId,
|
||||
/// The subpage ID of this pipeline to create in its pipeline parent.
|
||||
/// If `None`, this is the root.
|
||||
pub parent_info: Option<(PipelineId, SubpageId)>,
|
||||
/// The compositor.
|
||||
pub compositor: IpcSender<ScriptToCompositorMsg>,
|
||||
/// A channel with which messages can be sent to us (the script task).
|
||||
pub control_chan: Sender<ConstellationControlMsg>,
|
||||
/// A port on which messages sent by the constellation to script can be received.
|
||||
pub control_port: Receiver<ConstellationControlMsg>,
|
||||
/// A channel on which messages can be sent to the constellation from script.
|
||||
pub constellation_chan: ConstellationChan,
|
||||
/// Information that script sends out when it panics.
|
||||
pub failure_info: Failure,
|
||||
/// A channel to the resource manager task.
|
||||
pub resource_task: ResourceTask,
|
||||
/// A channel to the storage task.
|
||||
pub storage_task: StorageTask,
|
||||
/// A channel to the image cache task.
|
||||
pub image_cache_task: ImageCacheTask,
|
||||
/// A channel to the time profiler thread.
|
||||
pub time_profiler_chan: time::ProfilerChan,
|
||||
/// A channel to the memory profiler thread.
|
||||
pub mem_profiler_chan: mem::ProfilerChan,
|
||||
/// A channel to the developer tools, if applicable.
|
||||
pub devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||
/// Information about the initial window size.
|
||||
pub window_size: Option<WindowSizeData>,
|
||||
}
|
||||
|
||||
/// This trait allows creating a `ScriptTask` without depending on the `script`
|
||||
/// crate.
|
||||
pub trait ScriptTaskFactory {
|
||||
/// Create a `ScriptTask`.
|
||||
fn create(_phantom: Option<&mut Self>,
|
||||
id: PipelineId,
|
||||
parent_info: Option<(PipelineId, SubpageId)>,
|
||||
compositor: IpcSender<ScriptToCompositorMsg>,
|
||||
state: InitialScriptState,
|
||||
layout_chan: &OpaqueScriptLayoutChannel,
|
||||
control_chan: Sender<ConstellationControlMsg>,
|
||||
control_port: Receiver<ConstellationControlMsg>,
|
||||
constellation_msg: ConstellationChan,
|
||||
failure_msg: Failure,
|
||||
resource_task: ResourceTask,
|
||||
storage_task: StorageTask,
|
||||
image_cache_task: ImageCacheTask,
|
||||
time_profiler_chan: time::ProfilerChan,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||
window_size: Option<WindowSizeData>,
|
||||
load_data: LoadData);
|
||||
/// Create a script -> layout channel (`Sender`, `Receiver` pair).
|
||||
fn create_layout_channel(_phantom: Option<&mut Self>) -> OpaqueScriptLayoutChannel;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue