Skip to content

Commit

Permalink
Ability to create new TopLevelBrowsingContext
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Aug 12, 2017
1 parent 899aa0c commit bb3ac8f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
7 changes: 7 additions & 0 deletions components/compositing/compositor.rs
Expand Up @@ -818,6 +818,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {
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);
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions components/compositing/windowing.rs
Expand Up @@ -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<TopLevelBrowsingContextId>),
}

impl Debug for WindowEvent {
Expand All @@ -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"),
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions components/constellation/constellation.rs
Expand Up @@ -955,10 +955,11 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
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) => {
Expand Down Expand Up @@ -1473,14 +1474,19 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}

fn handle_init_load(&mut self, url: ServoUrl) {
fn handle_new_top_level_browsing_context(&mut self, url: ServoUrl, reply: IpcSender<TopLevelBrowsingContextId>) {
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,
Expand Down
4 changes: 2 additions & 2 deletions components/script_traits/lib.rs
Expand Up @@ -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<Option<TopLevelBrowsingContextId>>),
/// Request to load the initial page.
InitLoadUrl(ServoUrl),
/// Query the constellation to see if the current compositor output is stable
IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
/// Inform the constellation of a key event.
Expand All @@ -764,6 +762,8 @@ pub enum ConstellationMsg {
SetWebVRThread(IpcSender<WebVRMsg>),
/// Dispatch WebVR events to the subscribed script threads.
WebVREvents(Vec<PipelineId>, Vec<WebVREvent>),
/// Create a new top level browsing context.
NewBrowser(ServoUrl, IpcSender<TopLevelBrowsingContextId>),
}

/// Resources required by workerglobalscopes
Expand Down
6 changes: 1 addition & 5 deletions components/servo/lib.rs
Expand Up @@ -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;
Expand All @@ -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.
///
Expand Down Expand Up @@ -202,7 +202,6 @@ impl<Window> Browser<Window> 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(),
Expand Down Expand Up @@ -280,7 +279,6 @@ fn create_compositor_channel(event_loop_waker: Box<compositor_thread::EventLoopW

fn create_constellation(user_agent: Cow<'static, str>,
config_dir: Option<PathBuf>,
url: ServoUrl,
compositor_proxy: CompositorProxy,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bb3ac8f

Please sign in to comment.