From bb3ac8f266de29bd342faf4df7d69410533a9941 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Sat, 15 Jul 2017 07:35:59 +0200 Subject: [PATCH] Ability to create new TopLevelBrowsingContext --- components/compositing/compositor.rs | 7 +++++++ components/compositing/windowing.rs | 3 +++ components/constellation/constellation.rs | 16 +++++++++++----- components/script_traits/lib.rs | 4 ++-- components/servo/lib.rs | 6 +----- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index b9d536d295f4..145b57ef5d7a 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -818,6 +818,13 @@ impl IOCompositor { self.webrender.set_profiler_enabled(!profiler_enabled); self.webrender_api.generate_frame(self.webrender_document, None); } + + WindowEvent::NewBrowser(url, response_chan) => { + let msg = ConstellationMsg::NewBrowser(url, response_chan); + if let Err(e) = self.constellation_chan.send(msg) { + warn!("Sending NewBrowser message to constellation failed ({}).", e); + } + } } } diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 8831b12b1c96..7e044dfeb6c5 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -71,6 +71,8 @@ pub enum WindowEvent { /// Toggles the Web renderer profiler on and off ToggleWebRenderProfiler, Reload(TopLevelBrowsingContextId), + /// Create a new top level browsing context + NewBrowser(ServoUrl, IpcSender), } impl Debug for WindowEvent { @@ -93,6 +95,7 @@ impl Debug for WindowEvent { WindowEvent::Quit => write!(f, "Quit"), WindowEvent::ToggleWebRenderProfiler => write!(f, "ToggleWebRenderProfiler"), WindowEvent::Reload(..) => write!(f, "Reload"), + WindowEvent::NewBrowser(..) => write!(f, "NewBrowser"), } } } diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 15d7d18a87fe..e9b944d9df75 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -955,10 +955,11 @@ impl Constellation println!("sent response"); } } - // This should only be called once per constellation, and only by the browser - FromCompositorMsg::InitLoadUrl(url) => { + // Create a new top level browsing context. Will use response_chan to return + // the browsing context id. + FromCompositorMsg::NewBrowser(url, response_chan) => { debug!("constellation got init load URL message"); - self.handle_init_load(url); + self.handle_new_top_level_browsing_context(url, response_chan); } // Handle a forward or back request FromCompositorMsg::TraverseHistory(top_level_browsing_context_id, direction) => { @@ -1473,14 +1474,19 @@ impl Constellation } } - fn handle_init_load(&mut self, url: ServoUrl) { + fn handle_new_top_level_browsing_context(&mut self, url: ServoUrl, reply: IpcSender) { let window_size = self.window_size.initial_viewport; let pipeline_id = PipelineId::new(); let top_level_browsing_context_id = TopLevelBrowsingContextId::new(); + if let Err(e) = reply.send(top_level_browsing_context_id) { + warn!("Failed to send newly created top level browsing context ({}).", e); + } let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); let load_data = LoadData::new(url.clone(), None, None, None); let sandbox = IFrameSandboxState::IFrameUnsandboxed; - self.focus_pipeline_id = Some(pipeline_id); + if self.focus_pipeline_id.is_none() { + self.focus_pipeline_id = Some(pipeline_id); + } self.new_pipeline(pipeline_id, browsing_context_id, top_level_browsing_context_id, diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 34363b8f9921..5d1b555df987 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -740,8 +740,6 @@ pub enum ConstellationMsg { /// Request that the constellation send the current focused top-level browsing context id, /// over a provided channel. GetFocusTopLevelBrowsingContext(IpcSender>), - /// Request to load the initial page. - InitLoadUrl(ServoUrl), /// Query the constellation to see if the current compositor output is stable IsReadyToSaveImage(HashMap), /// Inform the constellation of a key event. @@ -764,6 +762,8 @@ pub enum ConstellationMsg { SetWebVRThread(IpcSender), /// Dispatch WebVR events to the subscribed script threads. WebVREvents(Vec, Vec), + /// Create a new top level browsing context. + NewBrowser(ServoUrl, IpcSender), } /// Resources required by workerglobalscopes diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 896887e2e349..e3034d0d08d6 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -92,7 +92,6 @@ use script_traits::{ConstellationMsg, SWManagerSenders, ScriptMsg}; use servo_config::opts; use servo_config::prefs::PREFS; use servo_config::resource_files::resources_dir_path; -use servo_url::ServoUrl; use std::borrow::Cow; use std::cmp::max; use std::path::PathBuf; @@ -104,6 +103,7 @@ use webvr::{WebVRThread, WebVRCompositorHandler}; pub use gleam::gl; pub use servo_config as config; pub use servo_url as url; +pub use msg::constellation_msg::TopLevelBrowsingContextId as BrowserId; /// The in-process interface to Servo. /// @@ -202,7 +202,6 @@ impl Browser where Window: WindowMethods + 'static { // as the navigation context. let (constellation_chan, sw_senders) = create_constellation(opts.user_agent.clone(), opts.config_dir.clone(), - target_url, compositor_proxy.clone_compositor_proxy(), time_profiler_chan.clone(), mem_profiler_chan.clone(), @@ -280,7 +279,6 @@ fn create_compositor_channel(event_loop_waker: Box, config_dir: Option, - url: ServoUrl, compositor_proxy: CompositorProxy, time_profiler_chan: time::ProfilerChan, mem_profiler_chan: mem::ProfilerChan, @@ -332,8 +330,6 @@ fn create_constellation(user_agent: Cow<'static, str>, constellation_chan.send(ConstellationMsg::SetWebVRThread(webvr_thread)).unwrap(); } - constellation_chan.send(ConstellationMsg::InitLoadUrl(url)).unwrap(); - // channels to communicate with Service Worker Manager let sw_senders = SWManagerSenders { swmanager_sender: from_swmanager_sender,