Auto merge of #17425 - paulrouget:attach-pipeline-2, r=asajeffrey

cleanup embedder/compositor/constellation/script messages

Fix: #17226 #17200 #17201

This is work in progress. Some tests still fail.
I'd like to get early feedback as it's a pretty large PR.

There is nothing fundamentally new. Basically, I added TopLevelBrowsingContrextId to the relevant messages between the embedder, the compositor and the constellation, and enforced the PipelineId to be attached to each ScriptMsg (see #17201).

I unaliased all the ScriptMsg. It was getting difficult to understand the nature of the message as ScriptMsg was used aliased CompositorMsg sometimes (CompositorMsg is an actually type of message already). I renamed constellation_chan to script_to_constellation_chan, again, for clarification.

This cleanup code is necessary for #15934 and for tabs support.

/cc @asajeffrey can I ask you to look at this? No need for a formal review, I need feedback at this stage.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17425)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-15 02:20:10 -05:00 committed by GitHub
commit 74558990b2
33 changed files with 625 additions and 517 deletions

View file

@ -11,19 +11,17 @@ use gfx_traits::Epoch;
use gleam::gl;
use image::{DynamicImage, ImageFormat, RgbImage};
use ipc_channel::ipc::{self, IpcSharedMemory};
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId, TraversalDirection};
use msg::constellation_msg::{KeyState, PipelineId, PipelineIndex, PipelineNamespaceId};
use net_traits::image::base::{Image, PixelFormat};
use profile_traits::time::{self, ProfilerCategory, profile};
use script_traits::{AnimationState, AnimationTickType, ConstellationControlMsg};
use script_traits::{ConstellationMsg, LayoutControlMsg, LoadData, MouseButton};
use script_traits::{ConstellationMsg, LayoutControlMsg, MouseButton};
use script_traits::{MouseEventType, ScrollState};
use script_traits::{TouchpadPressurePhase, TouchEventType, TouchId, WindowSizeData, WindowSizeType};
use script_traits::CompositorEvent::{self, MouseMoveEvent, MouseButtonEvent, TouchEvent, TouchpadPressureEvent};
use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
use std::collections::HashMap;
use std::fs::File;
use std::rc::Rc;
@ -460,8 +458,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.change_running_animations_state(pipeline_id, animation_state);
}
(Msg::ChangePageTitle(pipeline_id, title), ShutdownState::NotShuttingDown) => {
self.change_page_title(pipeline_id, title);
(Msg::ChangePageTitle(top_level_browsing_context, title), ShutdownState::NotShuttingDown) => {
self.window.set_page_title(top_level_browsing_context, title);
}
(Msg::SetFrameTree(frame_tree),
@ -475,55 +473,56 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.scroll_fragment_to_point(scroll_root_id, point);
}
(Msg::MoveTo(point),
(Msg::MoveTo(top_level_browsing_context_id, point),
ShutdownState::NotShuttingDown) => {
self.window.set_position(point);
self.window.set_position(top_level_browsing_context_id, point);
}
(Msg::ResizeTo(size),
(Msg::ResizeTo(top_level_browsing_context_id, size),
ShutdownState::NotShuttingDown) => {
self.window.set_inner_size(size);
self.window.set_inner_size(top_level_browsing_context_id, size);
}
(Msg::GetClientWindow(send),
(Msg::GetClientWindow(top_level_browsing_context_id, send),
ShutdownState::NotShuttingDown) => {
let rect = self.window.client_window();
let rect = self.window.client_window(top_level_browsing_context_id);
if let Err(e) = send.send(rect) {
warn!("Sending response to get client window failed ({}).", e);
}
}
(Msg::Status(message), ShutdownState::NotShuttingDown) => {
self.window.status(message);
(Msg::Status(top_level_browsing_context_id, message),
ShutdownState::NotShuttingDown) => {
self.window.status(top_level_browsing_context_id, message);
}
(Msg::LoadStart, ShutdownState::NotShuttingDown) => {
self.window.load_start();
(Msg::LoadStart(top_level_browsing_context_id), ShutdownState::NotShuttingDown) => {
self.window.load_start(top_level_browsing_context_id);
}
(Msg::LoadComplete, ShutdownState::NotShuttingDown) => {
(Msg::LoadComplete(top_level_browsing_context_id), ShutdownState::NotShuttingDown) => {
// If we're painting in headless mode, schedule a recomposite.
if opts::get().output_file.is_some() || opts::get().exit_after_load {
self.composite_if_necessary(CompositingReason::Headless);
}
// Inform the embedder that the load has finished.
//
// TODO(pcwalton): Specify which frame's load completed.
self.window.load_end();
self.window.load_end(top_level_browsing_context_id);
}
(Msg::AllowNavigation(url, response_chan), ShutdownState::NotShuttingDown) => {
self.window.allow_navigation(url, response_chan);
(Msg::AllowNavigation(top_level_browsing_context_id, url, response_chan),
ShutdownState::NotShuttingDown) => {
self.window.allow_navigation(top_level_browsing_context_id, url, response_chan);
}
(Msg::Recomposite(reason), ShutdownState::NotShuttingDown) => {
self.composition_request = CompositionRequest::CompositeNow(reason)
}
(Msg::KeyEvent(ch, key, state, modified), ShutdownState::NotShuttingDown) => {
(Msg::KeyEvent(top_level_browsing_context_id, ch, key, state, modified),
ShutdownState::NotShuttingDown) => {
if state == KeyState::Pressed {
self.window.handle_key(ch, key, modified);
self.window.handle_key(top_level_browsing_context_id, ch, key, modified);
}
}
@ -567,16 +566,16 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.composite_if_necessary(CompositingReason::Headless);
}
(Msg::NewFavicon(url), ShutdownState::NotShuttingDown) => {
self.window.set_favicon(url);
(Msg::NewFavicon(top_level_browsing_context_id, url), ShutdownState::NotShuttingDown) => {
self.window.set_favicon(top_level_browsing_context_id, url);
}
(Msg::HeadParsed, ShutdownState::NotShuttingDown) => {
self.window.head_parsed();
(Msg::HeadParsed(top_level_browsing_context_id), ShutdownState::NotShuttingDown) => {
self.window.head_parsed(top_level_browsing_context_id);
}
(Msg::HistoryChanged(entries, current), ShutdownState::NotShuttingDown) => {
self.window.history_changed(entries, current);
(Msg::HistoryChanged(top_level_browsing_context_id, entries, current), ShutdownState::NotShuttingDown) => {
self.window.history_changed(top_level_browsing_context_id, entries, current);
}
(Msg::PipelineVisibilityChanged(pipeline_id, visible), ShutdownState::NotShuttingDown) => {
@ -606,8 +605,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
func();
}
(Msg::SetFullscreenState(state), ShutdownState::NotShuttingDown) => {
self.window.set_fullscreen_state(state);
(Msg::SetFullscreenState(top_level_browsing_context_id, state), ShutdownState::NotShuttingDown) => {
self.window.set_fullscreen_state(top_level_browsing_context_id, state);
}
// When we are shutting_down, we need to avoid performing operations
@ -665,15 +664,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}
fn change_page_title(&mut self, pipeline_id: PipelineId, title: Option<String>) {
let set_title = self.root_pipeline.as_ref().map_or(false, |root_pipeline| {
root_pipeline.id == pipeline_id
});
if set_title {
self.window.set_page_title(title);
}
}
fn set_frame_tree(&mut self, frame_tree: &SendableFrameTree) {
debug!("Setting the frame tree for pipeline {}", frame_tree.pipeline.id);
@ -743,8 +733,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.on_resize_window_event(size);
}
WindowEvent::LoadUrl(url_string) => {
self.on_load_url_window_event(url_string);
WindowEvent::LoadUrl(top_level_browsing_context_id, url) => {
let msg = ConstellationMsg::LoadUrl(top_level_browsing_context_id, url);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending load url to constellation failed ({}).", e);
}
}
WindowEvent::MouseWindowEventClass(mouse_window_event) => {
@ -788,8 +781,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.on_pinch_zoom_window_event(magnification);
}
WindowEvent::Navigation(direction) => {
self.on_navigation_window_event(direction);
WindowEvent::Navigation(top_level_browsing_context_id, direction) => {
let msg = ConstellationMsg::TraverseHistory(top_level_browsing_context_id, direction);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending navigation to constellation failed ({}).", e);
}
}
WindowEvent::TouchpadPressure(cursor, pressure, stage) => {
@ -797,7 +793,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
WindowEvent::KeyEvent(ch, key, state, modifiers) => {
self.on_key_event(ch, key, state, modifiers);
let msg = ConstellationMsg::KeyEvent(ch, key, state, modifiers);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending key event to constellation failed ({}).", e);
}
}
WindowEvent::Quit => {
@ -807,11 +806,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}
WindowEvent::Reload => {
let top_level_browsing_context_id = match self.root_pipeline {
Some(ref pipeline) => pipeline.top_level_browsing_context_id,
None => return warn!("Window reload without root pipeline."),
};
WindowEvent::Reload(top_level_browsing_context_id) => {
let msg = ConstellationMsg::Reload(top_level_browsing_context_id);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending reload to constellation failed ({}).", e);
@ -824,6 +819,20 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.webrender.set_debug_flags(flags);
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);
}
}
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);
}
}
}
}
@ -851,23 +860,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.send_window_size(WindowSizeType::Resize);
}
fn on_load_url_window_event(&mut self, url_string: String) {
debug!("osmain: loading URL `{}`", url_string);
match ServoUrl::parse(&url_string) {
Ok(url) => {
let msg = match self.root_pipeline {
Some(ref pipeline) =>
ConstellationMsg::LoadUrl(pipeline.id, LoadData::new(url, Some(pipeline.id), None, None)),
None => ConstellationMsg::InitLoadUrl(url)
};
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending load url to constellation failed ({}).", e);
}
},
Err(e) => warn!("Parsing URL {} failed ({}).", url_string, e),
}
}
fn on_mouse_window_event_class(&mut self, mouse_window_event: MouseWindowEvent) {
if opts::get().convert_mouse_to_touch {
match mouse_window_event {
@ -1292,28 +1284,6 @@ impl<Window: WindowMethods> IOCompositor<Window> {
});
}
fn on_navigation_window_event(&self, direction: TraversalDirection) {
let top_level_browsing_context_id = match self.root_pipeline {
Some(ref pipeline) => pipeline.top_level_browsing_context_id,
None => return warn!("Sending navigation to constellation with no root pipeline."),
};
let msg = ConstellationMsg::TraverseHistory(top_level_browsing_context_id, direction);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending navigation to constellation failed ({}).", e);
}
}
fn on_key_event(&mut self,
ch: Option<char>,
key: Key,
state: KeyState,
modifiers: KeyModifiers) {
let msg = ConstellationMsg::KeyEvent(ch, key, state, modifiers);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending key event to constellation failed ({}).", e);
}
}
fn send_viewport_rects(&self) {
let mut scroll_states_per_pipeline = HashMap::new();
for scroll_layer_state in self.webrender_api.get_scroll_node_state(self.webrender_document) {