Skip to content

Commit

Permalink
refactor(constellation): replace constellationmsg to filemanagermsg
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Apr 27, 2018
1 parent c4c0d26 commit 52b9e4f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion components/compositing/compositor_thread.rs
Expand Up @@ -251,7 +251,7 @@ impl Debug for EmbedderMsg {
EmbedderMsg::LoadComplete(..) => write!(f, "LoadComplete"),
EmbedderMsg::Panic(..) => write!(f, "Panic"),
EmbedderMsg::GetSelectedBluetoothDevice(..) => write!(f, "GetSelectedBluetoothDevice"),
EmbedderMsg::GetSelectedFiles(..) => write!(f, "SelectFileDialog"),
EmbedderMsg::GetSelectedFiles(..) => write!(f, "GetSelectedFiles"),
EmbedderMsg::ShowIME(..) => write!(f, "ShowIME"),
EmbedderMsg::HideIME(..) => write!(f, "HideIME"),
EmbedderMsg::Shutdown => write!(f, "Shutdown"),
Expand Down
46 changes: 30 additions & 16 deletions components/constellation/constellation.rs
Expand Up @@ -115,7 +115,6 @@ use msg::constellation_msg::{BrowsingContextId, PipelineId, HistoryStateId, TopL
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId, TraversalDirection};
use net_traits::{self, IpcSend, FetchResponseMsg, ResourceThreads};
use net_traits::filemanager_thread::FilterPattern;
use net_traits::pub_domains::reg_host;
use net_traits::request::RequestInit;
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
Expand All @@ -126,10 +125,10 @@ use profile_traits::time;
use script_traits::{AnimationState, AnimationTickType, CompositorEvent};
use script_traits::{ConstellationControlMsg, ConstellationMsg as FromCompositorMsg, DiscardBrowsingContext};
use script_traits::{DocumentActivity, DocumentState, LayoutControlMsg, LoadData};
use script_traits::{FileManagerMsg, SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use script_traits::{IFrameLoadInfo, IFrameLoadInfoWithData, IFrameSandboxState, TimerSchedulerMsg};
use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, ScriptThreadFactory};
use script_traits::{LogEntry, ScriptToConstellationChan, ServiceWorkerMsg, webdriver_msg};
use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use script_traits::{WindowSizeData, WindowSizeType};
use serde::{Deserialize, Serialize};
use servo_config::opts;
Expand Down Expand Up @@ -175,6 +174,10 @@ pub struct Constellation<Message, LTF, STF> {
/// This is the constellation's view of `script_sender`.
script_receiver: Receiver<Result<(PipelineId, FromScriptMsg), IpcError>>,

/// A channel for the constellation to receive messages from filemanager threads.
/// This is the constellation's view of `filemanager_sender`.
filemanager_receiver: Receiver<Result<FileManagerMsg, IpcError>>,

/// An IPC channel for layout threads to send messages to the constellation.
/// This is the layout threads' view of `layout_receiver`.
layout_sender: IpcSender<FromLayoutMsg>,
Expand Down Expand Up @@ -547,17 +550,22 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
STF: ScriptThreadFactory<Message=Message>
{
/// Create a new constellation thread.
pub fn start(state: InitialConstellationState) -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>) {
pub fn start(state: InitialConstellationState)
-> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>, IpcSender<FileManagerMsg>) {
let (compositor_sender, compositor_receiver) = channel();

// service worker manager to communicate with constellation
let (swmanager_sender, swmanager_receiver) = ipc::channel().expect("ipc channel failure");
let sw_mgr_clone = swmanager_sender.clone();

let (filemanager_sender, filemanager_receiver) = ipc::channel().expect("ipc channel failure");

thread::Builder::new().name("Constellation".to_owned()).spawn(move || {
let (ipc_script_sender, ipc_script_receiver) = ipc::channel().expect("ipc channel failure");
let script_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(ipc_script_receiver);

let filemanager_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(filemanager_receiver);

let (ipc_layout_sender, ipc_layout_receiver) = ipc::channel().expect("ipc channel failure");
let layout_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(ipc_layout_receiver);

Expand All @@ -571,6 +579,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
script_sender: ipc_script_sender,
layout_sender: ipc_layout_sender,
script_receiver: script_receiver,
filemanager_receiver: filemanager_receiver,
compositor_receiver: compositor_receiver,
layout_receiver: layout_receiver,
network_listener_sender: network_listener_sender,
Expand Down Expand Up @@ -637,7 +646,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
constellation.run();
}).expect("Thread spawning failed");

(compositor_sender, swmanager_sender)
(compositor_sender, swmanager_sender, filemanager_sender)
}

/// The main event loop for the constellation.
Expand Down Expand Up @@ -831,6 +840,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
Layout(FromLayoutMsg),
NetworkListener((PipelineId, FetchResponseMsg)),
FromSWManager(SWManagerMsg),
FromFileManager(FileManagerMsg),
}

// Get one incoming request.
Expand All @@ -850,6 +860,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
let receiver_from_layout = &self.layout_receiver;
let receiver_from_network_listener = &self.network_listener_receiver;
let receiver_from_swmanager = &self.swmanager_receiver;
let receiver_from_filemanager = &self.filemanager_receiver;
select! {
msg = receiver_from_script.recv() =>
msg.expect("Unexpected script channel panic in constellation").map(Request::Script),
Expand All @@ -862,7 +873,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
msg.expect("Unexpected network listener channel panic in constellation")
)),
msg = receiver_from_swmanager.recv() =>
msg.expect("Unexpected panic channel panic in constellation").map(Request::FromSWManager)
msg.expect("Unexpected panic channel panic in constellation").map(Request::FromSWManager),
msg = receiver_from_filemanager.recv() =>
msg.expect("Unexpected file manager channel panic in constellation").map(Request::FromFileManager)
}
};

Expand All @@ -886,6 +899,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
},
Request::FromSWManager(message) => {
self.handle_request_from_swmanager(message);
},
Request::FromFileManager(message) => {
self.handle_request_from_filemanager(message);
}
}
}
Expand Down Expand Up @@ -915,6 +931,15 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}

fn handle_request_from_filemanager(&mut self, message: FileManagerMsg) {
match message {
FileManagerMsg::OpenFileSelectDialog(patterns, multiple_files, sender) => {
let msg = EmbedderMsg::GetSelectedFiles(patterns, multiple_files, sender);
self.embedder_proxy.send(msg);
}
}
}

fn handle_request_from_compositor(&mut self, message: FromCompositorMsg) {
match message {
FromCompositorMsg::Exit => {
Expand Down Expand Up @@ -1013,9 +1038,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
FromCompositorMsg::SetCursor(cursor) => {
self.handle_set_cursor_msg(cursor)
}
FromCompositorMsg::OpenFileSelectDialog(patterns, multiple_files, sender) => {
self.handle_open_file_select_dialog_msg(patterns, multiple_files, sender);
}
}
}

Expand Down Expand Up @@ -1742,14 +1764,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
self.embedder_proxy.send(EmbedderMsg::SetCursor(cursor))
}

fn handle_open_file_select_dialog_msg(&mut self,
patterns: Vec<FilterPattern>,
multiple_files: bool,
sender: IpcSender<Option<Vec<String>>>) {
let msg = EmbedderMsg::GetSelectedFiles(patterns, multiple_files, sender);
self.embedder_proxy.send(msg);
}

fn handle_change_running_animations_state(&mut self,
pipeline_id: PipelineId,
animation_state: AnimationState) {
Expand Down
5 changes: 1 addition & 4 deletions components/script_traits/lib.rs
Expand Up @@ -51,7 +51,6 @@ use libc::c_void;
use msg::constellation_msg::{BrowsingContextId, HistoryStateId, Key, KeyModifiers, KeyState, PipelineId};
use msg::constellation_msg::{PipelineNamespaceId, TraversalDirection, TopLevelBrowsingContextId};
use net_traits::{FetchResponseMsg, ReferrerPolicy, ResourceThreads};
use net_traits::filemanager_thread::FilterPattern;
use net_traits::image::base::Image;
use net_traits::image::base::PixelFormat;
use net_traits::image_cache::ImageCache;
Expand All @@ -74,7 +73,7 @@ use webrender_api::{ExternalScrollId, DevicePixel, DeviceUintSize, DocumentId, I
use webvr_traits::{WebVREvent, WebVRMsg};

pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry};
pub use script_msg::{ServiceWorkerMsg, ScopeThings, SWManagerMsg, SWManagerSenders, DOMMessage};
pub use script_msg::{FileManagerMsg, ServiceWorkerMsg, ScopeThings, SWManagerMsg, SWManagerSenders, DOMMessage};

/// The address of a node. Layout sends these back. They must be validated via
/// `from_untrusted_node_address` before they can be used, because we do not trust layout.
Expand Down Expand Up @@ -706,8 +705,6 @@ pub enum ConstellationMsg {
ForwardEvent(PipelineId, CompositorEvent),
/// Requesting a change to the onscreen cursor.
SetCursor(CursorKind),
/// Requesting to open file select dialog
OpenFileSelectDialog(Vec<FilterPattern>, bool, IpcSender<Option<Vec<String>>>),
}

/// Resources required by workerglobalscopes
Expand Down
8 changes: 8 additions & 0 deletions components/script_traits/script_msg.rs
Expand Up @@ -19,6 +19,7 @@ use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::constellation_msg::{BrowsingContextId, HistoryStateId, PipelineId, TraversalDirection};
use msg::constellation_msg::{InputMethodType, Key, KeyModifiers, KeyState};
use net_traits::CoreResourceMsg;
use net_traits::filemanager_thread::FilterPattern;
use net_traits::request::RequestInit;
use net_traits::storage_thread::StorageType;
use servo_url::ImmutableOrigin;
Expand Down Expand Up @@ -217,3 +218,10 @@ pub enum SWManagerMsg {
/// Provide the constellation with a means of communicating with the Service Worker Manager
OwnSender(IpcSender<ServiceWorkerMsg>),
}

/// Messages outgoing from the File Manager thread to constellation
#[derive(Deserialize, Serialize)]
pub enum FileManagerMsg {
/// Requesting to open file select dialog
OpenFileSelectDialog(Vec<FilterPattern>, bool, IpcSender<Option<Vec<String>>>)
}

0 comments on commit 52b9e4f

Please sign in to comment.