diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 145b57ef5d7..f5ef97f9f43 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -825,6 +825,13 @@ impl IOCompositor { warn!("Sending NewBrowser message to constellation failed ({}).", e); } } + + WindowEvent::SelectBrowser(ctx) => { + let msg = ConstellationMsg::SelectBrowser(ctx); + if let Err(e) = self.constellation_chan.send(msg) { + warn!("Sending SelectBrowser message to constellation failed ({}).", e); + } + } } } diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 7e044dfeb6c..cceaaf9fce8 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -73,6 +73,9 @@ pub enum WindowEvent { Reload(TopLevelBrowsingContextId), /// Create a new top level browsing context NewBrowser(ServoUrl, IpcSender), + /// Make a top level browsing context visible, hiding the previous + /// visible one. + SelectBrowser(TopLevelBrowsingContextId), } impl Debug for WindowEvent { @@ -96,6 +99,7 @@ impl Debug for WindowEvent { WindowEvent::ToggleWebRenderProfiler => write!(f, "ToggleWebRenderProfiler"), WindowEvent::Reload(..) => write!(f, "Reload"), WindowEvent::NewBrowser(..) => write!(f, "NewBrowser"), + WindowEvent::SelectBrowser(..) => write!(f, "SelectBrowser"), } } } diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 5c849352c67..1685a32d8d2 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -174,6 +174,9 @@ pub struct Constellation { /// constellation to send messages to the compositor thread. compositor_proxy: CompositorProxy, + /// The last frame tree sent to WebRender. + active_browser_id: Option, + /// Channels for the constellation to send messages to the public /// resource-related threads. There are two groups of resource /// threads: one for public browsing, and one for private @@ -527,6 +530,7 @@ impl Constellation network_listener_sender: network_listener_sender, network_listener_receiver: network_listener_receiver, compositor_proxy: state.compositor_proxy, + active_browser_id: None, debugger_chan: state.debugger_chan, devtools_chan: state.devtools_chan, bluetooth_thread: state.bluetooth_thread, @@ -963,6 +967,10 @@ impl Constellation debug!("constellation got init load URL message"); self.handle_new_top_level_browsing_context(url, response_chan); } + // Send frame tree to WebRender. Make it visible. + FromCompositorMsg::SelectBrowser(top_level_browsing_context_id) => { + self.send_frame_tree(top_level_browsing_context_id); + } // Handle a forward or back request FromCompositorMsg::TraverseHistory(top_level_browsing_context_id, direction) => { debug!("constellation got traverse history message from compositor"); @@ -2306,7 +2314,11 @@ impl Constellation self.notify_history_changed(top_level_id); // Set paint permissions correctly for the compositor layers. - self.send_frame_tree(top_level_id); + if let Some(id) = self.active_browser_id { + if id == top_level_id { + self.send_frame_tree(top_level_id); + } + } // Update the owning iframe to point to the new pipeline id. // This makes things like contentDocument work correctly. @@ -2465,7 +2477,11 @@ impl Constellation } // Build frame tree - self.send_frame_tree(change.top_level_browsing_context_id); + if let Some(id) = self.active_browser_id { + if id == change.top_level_browsing_context_id { + self.send_frame_tree(change.top_level_browsing_context_id ); + } + } } fn handle_activate_document_msg(&mut self, pipeline_id: PipelineId) { @@ -2902,6 +2918,7 @@ impl Constellation fn send_frame_tree(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId) { // This might be a mozbrowser iframe, so we need to climb the parent hierarchy, // even though it's a top-level browsing context. + self.active_browser_id = Some(top_level_browsing_context_id); let mut browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); let mut pipeline_id = match self.browsing_contexts.get(&browsing_context_id) { Some(browsing_context) => browsing_context.pipeline_id, diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index ec08b205c31..85122d35c3c 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -765,6 +765,8 @@ pub enum ConstellationMsg { WebVREvents(Vec, Vec), /// Create a new top level browsing context. NewBrowser(ServoUrl, IpcSender), + /// Make browser visible. + SelectBrowser(TopLevelBrowsingContextId), } /// Resources required by workerglobalscopes