Auto merge of #10918 - Ms2ger:clones, r=SimonSapin

Avoid some clones.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10918)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-29 06:33:34 -07:00
commit 9770e3c1e3
15 changed files with 56 additions and 72 deletions

View file

@ -146,8 +146,8 @@ impl DocumentLoader {
} }
/// Mark an in-progress network request complete. /// Mark an in-progress network request complete.
pub fn finish_load(&mut self, load: LoadType) { pub fn finish_load(&mut self, load: &LoadType) {
let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == load); let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == *load);
self.blocking_loads.remove(idx.expect(&format!("unknown completed load {:?}", load))); self.blocking_loads.remove(idx.expect(&format!("unknown completed load {:?}", load)));
} }

View file

@ -74,7 +74,7 @@ impl<'a> GlobalRef<'a> {
} }
/// Get a `mem::ProfilerChan` to send messages to the memory profiler thread. /// Get a `mem::ProfilerChan` to send messages to the memory profiler thread.
pub fn mem_profiler_chan(&self) -> mem::ProfilerChan { pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
match *self { match *self {
GlobalRef::Window(window) => window.mem_profiler_chan(), GlobalRef::Window(window) => window.mem_profiler_chan(),
GlobalRef::Worker(worker) => worker.mem_profiler_chan(), GlobalRef::Worker(worker) => worker.mem_profiler_chan(),
@ -82,7 +82,7 @@ impl<'a> GlobalRef<'a> {
} }
/// Get a `ConstellationChan` to send messages to the constellation channel when available. /// Get a `ConstellationChan` to send messages to the constellation channel when available.
pub fn constellation_chan(&self) -> ConstellationChan<ConstellationMsg> { pub fn constellation_chan(&self) -> &ConstellationChan<ConstellationMsg> {
match *self { match *self {
GlobalRef::Window(window) => window.constellation_chan(), GlobalRef::Window(window) => window.constellation_chan(),
GlobalRef::Worker(worker) => worker.constellation_chan(), GlobalRef::Worker(worker) => worker.constellation_chan(),
@ -90,7 +90,7 @@ impl<'a> GlobalRef<'a> {
} }
/// Get the scheduler channel to request timer events. /// Get the scheduler channel to request timer events.
pub fn scheduler_chan(&self) -> IpcSender<TimerEventRequest> { pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
match *self { match *self {
GlobalRef::Window(window) => window.scheduler_chan(), GlobalRef::Window(window) => window.scheduler_chan(),
GlobalRef::Worker(worker) => worker.scheduler_chan(), GlobalRef::Worker(worker) => worker.scheduler_chan(),

View file

@ -401,7 +401,7 @@ impl Document {
self.quirks_mode.set(mode); self.quirks_mode.set(mode);
if mode == Quirks { if mode == Quirks {
let LayoutChan(ref layout_chan) = self.window.layout_chan(); let LayoutChan(ref layout_chan) = *self.window.layout_chan();
layout_chan.send(Msg::SetQuirksMode).unwrap(); layout_chan.send(Msg::SetQuirksMode).unwrap();
} }
} }
@ -615,7 +615,7 @@ impl Document {
// Update the focus state for all elements in the focus chain. // Update the focus state for all elements in the focus chain.
// https://html.spec.whatwg.org/multipage/#focus-chain // https://html.spec.whatwg.org/multipage/#focus-chain
if focus_type == FocusType::Element { if focus_type == FocusType::Element {
let ConstellationChan(ref chan) = self.window.constellation_chan(); let ConstellationChan(ref chan) = *self.window.constellation_chan();
let event = ConstellationMsg::Focus(self.window.pipeline()); let event = ConstellationMsg::Focus(self.window.pipeline());
chan.send(event).unwrap(); chan.send(event).unwrap();
} }
@ -1260,7 +1260,7 @@ impl Document {
pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) { pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) {
if htmliframeelement::mozbrowser_enabled() { if htmliframeelement::mozbrowser_enabled() {
if let Some((containing_pipeline_id, subpage_id)) = self.window.parent_info() { if let Some((containing_pipeline_id, subpage_id)) = self.window.parent_info() {
let ConstellationChan(ref chan) = self.window.constellation_chan(); let ConstellationChan(ref chan) = *self.window.constellation_chan();
let event = ConstellationMsg::MozBrowserEvent(containing_pipeline_id, let event = ConstellationMsg::MozBrowserEvent(containing_pipeline_id,
subpage_id, subpage_id,
event); event);
@ -1277,7 +1277,7 @@ impl Document {
self.animation_frame_list.borrow_mut().insert(ident, callback); self.animation_frame_list.borrow_mut().insert(ident, callback);
// TODO: Should tick animation only when document is visible // TODO: Should tick animation only when document is visible
let ConstellationChan(ref chan) = self.window.constellation_chan(); let ConstellationChan(ref chan) = *self.window.constellation_chan();
let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(), let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(),
AnimationState::AnimationCallbacksPresent); AnimationState::AnimationCallbacksPresent);
chan.send(event).unwrap(); chan.send(event).unwrap();
@ -1289,7 +1289,7 @@ impl Document {
pub fn cancel_animation_frame(&self, ident: u32) { pub fn cancel_animation_frame(&self, ident: u32) {
self.animation_frame_list.borrow_mut().remove(&ident); self.animation_frame_list.borrow_mut().remove(&ident);
if self.animation_frame_list.borrow().is_empty() { if self.animation_frame_list.borrow().is_empty() {
let ConstellationChan(ref chan) = self.window.constellation_chan(); let ConstellationChan(ref chan) = *self.window.constellation_chan();
let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(), let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(),
AnimationState::NoAnimationCallbacksPresent); AnimationState::NoAnimationCallbacksPresent);
chan.send(event).unwrap(); chan.send(event).unwrap();
@ -1313,7 +1313,7 @@ impl Document {
// the next frame (which is the common case), we won't send a NoAnimationCallbacksPresent // the next frame (which is the common case), we won't send a NoAnimationCallbacksPresent
// message quickly followed by an AnimationCallbacksPresent message. // message quickly followed by an AnimationCallbacksPresent message.
if self.animation_frame_list.borrow().is_empty() { if self.animation_frame_list.borrow().is_empty() {
let ConstellationChan(ref chan) = self.window.constellation_chan(); let ConstellationChan(ref chan) = *self.window.constellation_chan();
let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(), let event = ConstellationMsg::ChangeRunningAnimationsState(self.window.pipeline(),
AnimationState::NoAnimationCallbacksPresent); AnimationState::NoAnimationCallbacksPresent);
chan.send(event).unwrap(); chan.send(event).unwrap();
@ -1344,7 +1344,7 @@ impl Document {
// The parser might need the loader, so restrict the lifetime of the borrow. // The parser might need the loader, so restrict the lifetime of the borrow.
{ {
let mut loader = self.loader.borrow_mut(); let mut loader = self.loader.borrow_mut();
loader.finish_load(load.clone()); loader.finish_load(&load);
} }
if let LoadType::Script(_) = load { if let LoadType::Script(_) = load {
@ -1473,7 +1473,7 @@ impl Document {
pub fn notify_constellation_load(&self) { pub fn notify_constellation_load(&self) {
let pipeline_id = self.window.pipeline(); let pipeline_id = self.window.pipeline();
let ConstellationChan(ref chan) = self.window.constellation_chan(); let ConstellationChan(ref chan) = *self.window.constellation_chan();
let event = ConstellationMsg::DOMLoad(pipeline_id); let event = ConstellationMsg::DOMLoad(pipeline_id);
chan.send(event).unwrap(); chan.send(event).unwrap();

View file

@ -154,7 +154,7 @@ impl VirtualMethods for HTMLBodyElement {
let window = window_from_node(self); let window = window_from_node(self);
let document = window.Document(); let document = window.Document();
document.set_reflow_timeout(time::precise_time_ns() + INITIAL_REFLOW_DELAY); document.set_reflow_timeout(time::precise_time_ns() + INITIAL_REFLOW_DELAY);
let ConstellationChan(ref chan) = window.constellation_chan(); let ConstellationChan(ref chan) = *window.constellation_chan();
let event = ConstellationMsg::HeadParsed; let event = ConstellationMsg::HeadParsed;
chan.send(event).unwrap(); chan.send(event).unwrap();
} }

View file

@ -124,7 +124,7 @@ impl HTMLIFrameElement {
let new_pipeline_id = self.pipeline_id.get().unwrap(); let new_pipeline_id = self.pipeline_id.get().unwrap();
let private_iframe = self.privatebrowsing(); let private_iframe = self.privatebrowsing();
let ConstellationChan(ref chan) = window.constellation_chan(); let ConstellationChan(ref chan) = *window.constellation_chan();
let load_info = IFrameLoadInfo { let load_info = IFrameLoadInfo {
url: url, url: url,
containing_pipeline_id: window.pipeline(), containing_pipeline_id: window.pipeline(),
@ -144,7 +144,7 @@ impl HTMLIFrameElement {
pub fn process_the_iframe_attributes(&self) { pub fn process_the_iframe_attributes(&self) {
let url = match self.get_url() { let url = match self.get_url() {
Some(url) => url.clone(), Some(url) => url,
None => Url::parse("about:blank").unwrap(), None => Url::parse("about:blank").unwrap(),
}; };
@ -371,7 +371,7 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> E
let pipeline_info = Some((window.pipeline(), let pipeline_info = Some((window.pipeline(),
iframe.subpage_id().unwrap())); iframe.subpage_id().unwrap()));
let ConstellationChan(ref chan) = window.constellation_chan(); let ConstellationChan(ref chan) = *window.constellation_chan();
let msg = ConstellationMsg::Navigate(pipeline_info, direction); let msg = ConstellationMsg::Navigate(pipeline_info, direction);
chan.send(msg).unwrap(); chan.send(msg).unwrap();
} }
@ -575,7 +575,7 @@ impl VirtualMethods for HTMLIFrameElement {
// //
// Since most of this cleanup doesn't happen on same-origin // Since most of this cleanup doesn't happen on same-origin
// iframes, and since that would cause a deadlock, don't do it. // iframes, and since that would cause a deadlock, don't do it.
let ConstellationChan(ref chan) = window.constellation_chan(); let ConstellationChan(ref chan) = *window.constellation_chan();
let same_origin = if let Some(self_url) = self.get_url() { let same_origin = if let Some(self_url) = self.get_url() {
let win_url = window_from_node(self).get_url(); let win_url = window_from_node(self).get_url();
UrlHelper::SameOrigin(&self_url, &win_url) UrlHelper::SameOrigin(&self_url, &win_url)

View file

@ -122,7 +122,7 @@ static DEFAULT_MAX_LENGTH: i32 = -1;
impl HTMLInputElement { impl HTMLInputElement {
fn new_inherited(localName: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement { fn new_inherited(localName: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement {
let chan = document.window().constellation_chan(); let chan = document.window().constellation_chan().clone();
HTMLInputElement { HTMLInputElement {
htmlelement: htmlelement:
HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, HTMLElement::new_inherited_with_state(IN_ENABLED_STATE,

View file

@ -242,7 +242,7 @@ impl HTMLLinkElement {
let document = document_from_node(self); let document = document_from_node(self);
match document.base_url().join(href) { match document.base_url().join(href) {
Ok(url) => { Ok(url) => {
let ConstellationChan(ref chan) = document.window().constellation_chan(); let ConstellationChan(ref chan) = *document.window().constellation_chan();
let event = ConstellationMsg::NewFavicon(url.clone()); let event = ConstellationMsg::NewFavicon(url.clone());
chan.send(event).unwrap(); chan.send(event).unwrap();
@ -318,7 +318,7 @@ impl AsyncResponseListener for StylesheetContext {
let document = document.r(); let document = document.r();
let win = window_from_node(elem); let win = window_from_node(elem);
let LayoutChan(ref layout_chan) = win.r().layout_chan(); let LayoutChan(ref layout_chan) = *win.layout_chan();
layout_chan.send(Msg::AddStylesheet(sheet.clone())).unwrap(); layout_chan.send(Msg::AddStylesheet(sheet.clone())).unwrap();
*elem.stylesheet.borrow_mut() = Some(sheet); *elem.stylesheet.borrow_mut() = Some(sheet);

View file

@ -66,7 +66,7 @@ impl HTMLStyleElement {
sheet.set_media(Some(media)); sheet.set_media(Some(media));
let sheet = Arc::new(sheet); let sheet = Arc::new(sheet);
let LayoutChan(ref layout_chan) = win.layout_chan(); let LayoutChan(ref layout_chan) = *win.layout_chan();
layout_chan.send(Msg::AddStylesheet(sheet.clone())).unwrap(); layout_chan.send(Msg::AddStylesheet(sheet.clone())).unwrap();
*self.stylesheet.borrow_mut() = Some(sheet); *self.stylesheet.borrow_mut() = Some(sheet);
let doc = document_from_node(self); let doc = document_from_node(self);

View file

@ -100,7 +100,7 @@ impl HTMLTextAreaElement {
fn new_inherited(localName: Atom, fn new_inherited(localName: Atom,
prefix: Option<DOMString>, prefix: Option<DOMString>,
document: &Document) -> HTMLTextAreaElement { document: &Document) -> HTMLTextAreaElement {
let chan = document.window().constellation_chan(); let chan = document.window().constellation_chan().clone();
HTMLTextAreaElement { HTMLTextAreaElement {
htmlelement: htmlelement:
HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, HTMLElement::new_inherited_with_state(IN_ENABLED_STATE,

View file

@ -195,7 +195,7 @@ impl OpaqueStyleAndLayoutData {
pub fn dispose(self, node: &Node) { pub fn dispose(self, node: &Node) {
debug_assert!(thread_state::get().is_script()); debug_assert!(thread_state::get().is_script());
let win = window_from_node(node); let win = window_from_node(node);
let LayoutChan(chan) = win.layout_chan(); let LayoutChan(ref chan) = *win.layout_chan();
node.style_and_layout_data.set(None); node.style_and_layout_data.set(None);
chan.send(Msg::ReapStyleAndLayoutData(self)).unwrap(); chan.send(Msg::ReapStyleAndLayoutData(self)).unwrap();
} }

View file

@ -93,8 +93,8 @@ impl AsyncResponseListener for ParserContext {
Err(_) => None, Err(_) => None,
}; };
let content_type = metadata.clone().and_then(|meta| meta.content_type); let content_type = metadata.clone().and_then(|meta| meta.content_type);
let parser = match ScriptThread::page_fetch_complete(self.id.clone(), let parser = match ScriptThread::page_fetch_complete(&self.id,
self.subpage.clone(), self.subpage.as_ref(),
metadata) { metadata) {
Some(parser) => parser, Some(parser) => parser,
None => return, None => return,

View file

@ -1234,24 +1234,24 @@ impl Window {
(*self.resource_thread).clone() (*self.resource_thread).clone()
} }
pub fn mem_profiler_chan(&self) -> mem::ProfilerChan { pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
self.mem_profiler_chan.clone() &self.mem_profiler_chan
} }
pub fn devtools_chan(&self) -> Option<IpcSender<ScriptToDevtoolsControlMsg>> { pub fn devtools_chan(&self) -> Option<IpcSender<ScriptToDevtoolsControlMsg>> {
self.devtools_chan.clone() self.devtools_chan.clone()
} }
pub fn layout_chan(&self) -> LayoutChan { pub fn layout_chan(&self) -> &LayoutChan {
self.layout_chan.clone() &self.layout_chan
} }
pub fn constellation_chan(&self) -> ConstellationChan<ConstellationMsg> { pub fn constellation_chan(&self) -> &ConstellationChan<ConstellationMsg> {
self.constellation_chan.clone() &self.constellation_chan
} }
pub fn scheduler_chan(&self) -> IpcSender<TimerEventRequest> { pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
self.scheduler_chan.clone() &self.scheduler_chan
} }
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle { pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {

View file

@ -75,8 +75,8 @@ impl Worker {
}; };
let resource_thread = global.resource_thread(); let resource_thread = global.resource_thread();
let constellation_chan = global.constellation_chan(); let constellation_chan = global.constellation_chan().clone();
let scheduler_chan = global.scheduler_chan(); let scheduler_chan = global.scheduler_chan().clone();
let (sender, receiver) = channel(); let (sender, receiver) = channel();
let closing = Arc::new(AtomicBool::new(false)); let closing = Arc::new(AtomicBool::new(false));
@ -103,7 +103,7 @@ impl Worker {
let init = WorkerGlobalScopeInit { let init = WorkerGlobalScopeInit {
resource_thread: resource_thread, resource_thread: resource_thread,
mem_profiler_chan: global.mem_profiler_chan(), mem_profiler_chan: global.mem_profiler_chan().clone(),
to_devtools_sender: global.devtools_chan(), to_devtools_sender: global.devtools_chan(),
from_devtools_sender: optional_sender, from_devtools_sender: optional_sender,
constellation_chan: constellation_chan, constellation_chan: constellation_chan,

View file

@ -126,8 +126,8 @@ impl WorkerGlobalScope {
} }
} }
pub fn mem_profiler_chan(&self) -> mem::ProfilerChan { pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
self.mem_profiler_chan.clone() &self.mem_profiler_chan
} }
pub fn devtools_chan(&self) -> Option<IpcSender<ScriptToDevtoolsControlMsg>> { pub fn devtools_chan(&self) -> Option<IpcSender<ScriptToDevtoolsControlMsg>> {
@ -142,12 +142,12 @@ impl WorkerGlobalScope {
&self.from_devtools_receiver &self.from_devtools_receiver
} }
pub fn constellation_chan(&self) -> ConstellationChan<ConstellationMsg> { pub fn constellation_chan(&self) -> &ConstellationChan<ConstellationMsg> {
self.constellation_chan.clone() &self.constellation_chan
} }
pub fn scheduler_chan(&self) -> IpcSender<TimerEventRequest> { pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
self.scheduler_chan.clone() &self.scheduler_chan
} }
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle { pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {

View file

@ -275,14 +275,6 @@ impl ScriptChan for SendableMainThreadScriptChan {
} }
} }
impl SendableMainThreadScriptChan {
/// Creates a new script chan.
pub fn new() -> (Receiver<CommonScriptMsg>, Box<SendableMainThreadScriptChan>) {
let (chan, port) = channel();
(port, box SendableMainThreadScriptChan(chan))
}
}
/// Encapsulates internal communication of main thread messages within the script thread. /// Encapsulates internal communication of main thread messages within the script thread.
#[derive(JSTraceable)] #[derive(JSTraceable)]
pub struct MainThreadScriptChan(pub Sender<MainThreadScriptMsg>); pub struct MainThreadScriptChan(pub Sender<MainThreadScriptMsg>);
@ -297,11 +289,9 @@ impl ScriptChan for MainThreadScriptChan {
} }
} }
impl MainThreadScriptChan { impl OpaqueSender<CommonScriptMsg> for Sender<MainThreadScriptMsg> {
/// Creates a new script chan. fn send(&self, msg: CommonScriptMsg) {
pub fn new() -> (Receiver<MainThreadScriptMsg>, Box<MainThreadScriptChan>) { self.send(MainThreadScriptMsg::Common(msg)).unwrap()
let (chan, port) = channel();
(port, box MainThreadScriptChan(chan))
} }
} }
@ -453,15 +443,13 @@ impl ScriptThreadFactory for ScriptThread {
PipelineNamespace::install(state.pipeline_namespace_id); PipelineNamespace::install(state.pipeline_namespace_id);
let roots = RootCollection::new(); let roots = RootCollection::new();
let _stack_roots_tls = StackRootTLS::new(&roots); let _stack_roots_tls = StackRootTLS::new(&roots);
let chan = MainThreadScriptChan(script_chan.clone());
let channel_for_reporter = chan.clone();
let id = state.id; let id = state.id;
let parent_info = state.parent_info; let parent_info = state.parent_info;
let mem_profiler_chan = state.mem_profiler_chan.clone(); let mem_profiler_chan = state.mem_profiler_chan.clone();
let window_size = state.window_size; let window_size = state.window_size;
let script_thread = ScriptThread::new(state, let script_thread = ScriptThread::new(state,
script_port, script_port,
script_chan); script_chan.clone());
SCRIPT_THREAD_ROOT.with(|root| { SCRIPT_THREAD_ROOT.with(|root| {
*root.borrow_mut() = Some(&script_thread as *const _); *root.borrow_mut() = Some(&script_thread as *const _);
@ -478,7 +466,7 @@ impl ScriptThreadFactory for ScriptThread {
script_thread.start(); script_thread.start();
let _ = script_thread.compositor.borrow_mut().send(ScriptToCompositorMsg::Exited); let _ = script_thread.compositor.borrow_mut().send(ScriptToCompositorMsg::Exited);
let _ = script_thread.content_process_shutdown_chan.send(()); let _ = script_thread.content_process_shutdown_chan.send(());
}, reporter_name, channel_for_reporter, CommonScriptMsg::CollectReports); }, reporter_name, script_chan, CommonScriptMsg::CollectReports);
// This must always be the very last operation performed before the thread completes // This must always be the very last operation performed before the thread completes
failsafe.neuter(); failsafe.neuter();
@ -493,7 +481,7 @@ pub unsafe extern "C" fn shadow_check_callback(_cx: *mut JSContext,
} }
impl ScriptThread { impl ScriptThread {
pub fn page_fetch_complete(id: PipelineId, subpage: Option<SubpageId>, metadata: Option<Metadata>) pub fn page_fetch_complete(id: &PipelineId, subpage: Option<&SubpageId>, metadata: Option<Metadata>)
-> Option<ParserRoot> { -> Option<ParserRoot> {
SCRIPT_THREAD_ROOT.with(|root| { SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.borrow().unwrap() }; let script_thread = unsafe { &*root.borrow().unwrap() };
@ -1122,8 +1110,7 @@ impl ScriptThread {
doc.mut_loader().inhibit_events(); doc.mut_loader().inhibit_events();
// https://html.spec.whatwg.org/multipage/#the-end step 7 // https://html.spec.whatwg.org/multipage/#the-end step 7
let addr: Trusted<Document> = Trusted::new(doc); let handler = box DocumentProgressHandler::new(Trusted::new(doc));
let handler = box DocumentProgressHandler::new(addr.clone());
self.dom_manipulation_task_source.queue(DOMManipulationTask::DocumentProgress(handler)).unwrap(); self.dom_manipulation_task_source.queue(DOMManipulationTask::DocumentProgress(handler)).unwrap();
let ConstellationChan(ref chan) = self.constellation_chan; let ConstellationChan(ref chan) = self.constellation_chan;
@ -1285,10 +1272,10 @@ impl ScriptThread {
/// We have received notification that the response associated with a load has completed. /// We have received notification that the response associated with a load has completed.
/// Kick off the document and frame tree creation process using the result. /// Kick off the document and frame tree creation process using the result.
fn handle_page_fetch_complete(&self, id: PipelineId, subpage: Option<SubpageId>, fn handle_page_fetch_complete(&self, id: &PipelineId, subpage: Option<&SubpageId>,
metadata: Option<Metadata>) -> Option<ParserRoot> { metadata: Option<Metadata>) -> Option<ParserRoot> {
let idx = self.incomplete_loads.borrow().iter().position(|load| { let idx = self.incomplete_loads.borrow().iter().position(|load| {
load.pipeline_id == id && load.parent_info.map(|info| info.1) == subpage load.pipeline_id == *id && load.parent_info.as_ref().map(|info| &info.1) == subpage
}); });
// The matching in progress load structure may not exist if // The matching in progress load structure may not exist if
// the pipeline exited before the page load completed. // the pipeline exited before the page load completed.
@ -1298,7 +1285,7 @@ impl ScriptThread {
metadata.map(|meta| self.load(meta, load)) metadata.map(|meta| self.load(meta, load))
} }
None => { None => {
assert!(self.closed_pipelines.borrow().contains(&id)); assert!(self.closed_pipelines.borrow().contains(id));
None None
} }
} }
@ -1868,14 +1855,11 @@ impl ScriptThread {
let id = incomplete.pipeline_id.clone(); let id = incomplete.pipeline_id.clone();
let subpage = incomplete.parent_info.clone().map(|p| p.1); let subpage = incomplete.parent_info.clone().map(|p| p.1);
let script_chan = self.chan.clone();
let resource_thread = self.resource_thread.clone();
let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, load_data.url.clone()))); let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, load_data.url.clone())));
let (action_sender, action_receiver) = ipc::channel().unwrap(); let (action_sender, action_receiver) = ipc::channel().unwrap();
let listener = NetworkListener { let listener = NetworkListener {
context: context, context: context,
script_chan: script_chan.clone(), script_chan: self.chan.clone(),
}; };
ROUTER.add_route(action_receiver.to_opaque(), box move |message| { ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
listener.notify(message.to().unwrap()); listener.notify(message.to().unwrap());
@ -1888,7 +1872,7 @@ impl ScriptThread {
load_data.url = Url::parse("about:blank").unwrap(); load_data.url = Url::parse("about:blank").unwrap();
} }
resource_thread.send(ControlMsg::Load(NetLoadData { self.resource_thread.send(ControlMsg::Load(NetLoadData {
context: LoadContext::Browsing, context: LoadContext::Browsing,
url: load_data.url, url: load_data.url,
method: load_data.method, method: load_data.method,
@ -1982,7 +1966,7 @@ fn shut_down_layout(page_tree: &Rc<Page>) {
// processed this message. // processed this message.
let (response_chan, response_port) = channel(); let (response_chan, response_port) = channel();
let window = page.window(); let window = page.window();
let LayoutChan(chan) = window.layout_chan(); let LayoutChan(chan) = window.layout_chan().clone();
if chan.send(layout_interface::Msg::PrepareToExit(response_chan)).is_ok() { if chan.send(layout_interface::Msg::PrepareToExit(response_chan)).is_ok() {
channels.push(chan); channels.push(chan);
response_port.recv().unwrap(); response_port.recv().unwrap();