mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Refactor embedder NewBrowser flow
This commit is contained in:
parent
96f75465cf
commit
e784f5a9f7
7 changed files with 83 additions and 48 deletions
|
@ -8,7 +8,6 @@ use embedder_traits::EventLoopWaker;
|
|||
use euclid::TypedScale;
|
||||
#[cfg(feature = "gleam")]
|
||||
use gleam::gl;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, TopLevelBrowsingContextId, TraversalDirection};
|
||||
use script_traits::{MouseButton, TouchEventType, TouchId};
|
||||
use servo_geometry::{DeviceIndependentPixel, DeviceUintLength};
|
||||
|
@ -75,7 +74,7 @@ pub enum WindowEvent {
|
|||
/// Sent when Ctr+R/Apple+R is called to reload the current page.
|
||||
Reload(TopLevelBrowsingContextId),
|
||||
/// Create a new top level browsing context
|
||||
NewBrowser(ServoUrl, IpcSender<TopLevelBrowsingContextId>),
|
||||
NewBrowser(ServoUrl, TopLevelBrowsingContextId),
|
||||
/// Close a top level browsing context
|
||||
CloseBrowser(TopLevelBrowsingContextId),
|
||||
/// Panic a top level browsing context.
|
||||
|
|
|
@ -578,7 +578,8 @@ where
|
|||
let swmanager_receiver =
|
||||
route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(swmanager_receiver);
|
||||
|
||||
PipelineNamespace::install(PipelineNamespaceId(0));
|
||||
// Zero is reserved for the embedder.
|
||||
PipelineNamespace::install(PipelineNamespaceId(1));
|
||||
|
||||
let mut constellation: Constellation<Message, LTF, STF> = Constellation {
|
||||
script_sender: ipc_script_sender,
|
||||
|
@ -605,8 +606,10 @@ where
|
|||
pipelines: HashMap::new(),
|
||||
browsing_contexts: HashMap::new(),
|
||||
pending_changes: vec![],
|
||||
// We initialize the namespace at 1, since we reserved namespace 0 for the constellation
|
||||
next_pipeline_namespace_id: PipelineNamespaceId(1),
|
||||
// We initialize the namespace at 2,
|
||||
// since we reserved namespace 0 for the embedder,
|
||||
// and 0 for the constellation
|
||||
next_pipeline_namespace_id: PipelineNamespaceId(2),
|
||||
focus_pipeline_id: None,
|
||||
time_profiler_chan: state.time_profiler_chan,
|
||||
mem_profiler_chan: state.mem_profiler_chan,
|
||||
|
@ -1026,8 +1029,8 @@ where
|
|||
},
|
||||
// Create a new top level browsing context. Will use response_chan to return
|
||||
// the browsing context id.
|
||||
FromCompositorMsg::NewBrowser(url, response_chan) => {
|
||||
self.handle_new_top_level_browsing_context(url, response_chan);
|
||||
FromCompositorMsg::NewBrowser(url, top_level_browsing_context_id) => {
|
||||
self.handle_new_top_level_browsing_context(url, top_level_browsing_context_id);
|
||||
},
|
||||
// Close a top level browsing context.
|
||||
FromCompositorMsg::CloseBrowser(top_level_browsing_context_id) => {
|
||||
|
@ -1651,17 +1654,12 @@ where
|
|||
fn handle_new_top_level_browsing_context(
|
||||
&mut self,
|
||||
url: ServoUrl,
|
||||
reply: IpcSender<TopLevelBrowsingContextId>,
|
||||
top_level_browsing_context_id: 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 msg = (Some(top_level_browsing_context_id), EmbedderMsg::BrowserCreated(top_level_browsing_context_id));
|
||||
self.embedder_proxy.send(msg);
|
||||
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;
|
||||
|
|
|
@ -717,7 +717,7 @@ pub enum ConstellationMsg {
|
|||
/// Dispatch WebVR events to the subscribed script threads.
|
||||
WebVREvents(Vec<PipelineId>, Vec<WebVREvent>),
|
||||
/// Create a new top level browsing context.
|
||||
NewBrowser(ServoUrl, IpcSender<TopLevelBrowsingContextId>),
|
||||
NewBrowser(ServoUrl, TopLevelBrowsingContextId),
|
||||
/// Close a top level browsing context.
|
||||
CloseBrowser(TopLevelBrowsingContextId),
|
||||
/// Panic a top level browsing context.
|
||||
|
|
|
@ -87,6 +87,7 @@ use gaol::sandbox::{ChildSandbox, ChildSandboxMethods};
|
|||
use gfx::font_cache_thread::FontCacheThread;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use log::{Log, Metadata, Record};
|
||||
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId};
|
||||
use net::resource_thread::new_resource_threads;
|
||||
use net_traits::IpcSend;
|
||||
use profile::mem as profile_mem;
|
||||
|
@ -135,6 +136,9 @@ impl<Window> Servo<Window> where Window: WindowMethods + 'static {
|
|||
// Make sure the gl context is made current.
|
||||
window.prepare_for_composite(Length::new(0), Length::new(0));
|
||||
|
||||
// Reserving a namespace to create TopLevelBrowserContextId.
|
||||
PipelineNamespace::install(PipelineNamespaceId(0));
|
||||
|
||||
// Get both endpoints of a special channel for communication between
|
||||
// the client window and the compositor. This channel is unique because
|
||||
// messages to client may need to pump a platform-specific event loop
|
||||
|
@ -326,8 +330,8 @@ impl<Window> Servo<Window> where Window: WindowMethods + 'static {
|
|||
self.compositor.capture_webrender();
|
||||
}
|
||||
|
||||
WindowEvent::NewBrowser(url, response_chan) => {
|
||||
let msg = ConstellationMsg::NewBrowser(url, response_chan);
|
||||
WindowEvent::NewBrowser(url, browser_id) => {
|
||||
let msg = ConstellationMsg::NewBrowser(url, browser_id);
|
||||
if let Err(e) = self.constellation_chan.send(msg) {
|
||||
warn!("Sending NewBrowser message to constellation failed ({}).", e);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue