Ability to create new TopLevelBrowsingContext

This commit is contained in:
Paul Rouget 2017-07-15 07:35:59 +02:00
parent 899aa0c371
commit bb3ac8f266
5 changed files with 24 additions and 12 deletions

View file

@ -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);
}
}
}
}

View file

@ -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 {
@ -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"),
}
}
}

View file

@ -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) => {
@ -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;
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,

View file

@ -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.
@ -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

View file

@ -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<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(),
@ -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,
@ -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,