refactor(constellation): replace constellationmsg to filemanagermsg

This commit is contained in:
OJ Kwon 2018-04-03 09:57:46 -07:00
parent c4c0d263e9
commit 52b9e4f0ab
No known key found for this signature in database
GPG key ID: 6C23A45602A44DA6
4 changed files with 40 additions and 21 deletions

View file

@ -251,7 +251,7 @@ impl Debug for EmbedderMsg {
EmbedderMsg::LoadComplete(..) => write!(f, "LoadComplete"), EmbedderMsg::LoadComplete(..) => write!(f, "LoadComplete"),
EmbedderMsg::Panic(..) => write!(f, "Panic"), EmbedderMsg::Panic(..) => write!(f, "Panic"),
EmbedderMsg::GetSelectedBluetoothDevice(..) => write!(f, "GetSelectedBluetoothDevice"), EmbedderMsg::GetSelectedBluetoothDevice(..) => write!(f, "GetSelectedBluetoothDevice"),
EmbedderMsg::GetSelectedFiles(..) => write!(f, "SelectFileDialog"), EmbedderMsg::GetSelectedFiles(..) => write!(f, "GetSelectedFiles"),
EmbedderMsg::ShowIME(..) => write!(f, "ShowIME"), EmbedderMsg::ShowIME(..) => write!(f, "ShowIME"),
EmbedderMsg::HideIME(..) => write!(f, "HideIME"), EmbedderMsg::HideIME(..) => write!(f, "HideIME"),
EmbedderMsg::Shutdown => write!(f, "Shutdown"), EmbedderMsg::Shutdown => write!(f, "Shutdown"),

View file

@ -115,7 +115,6 @@ use msg::constellation_msg::{BrowsingContextId, PipelineId, HistoryStateId, TopL
use msg::constellation_msg::{Key, KeyModifiers, KeyState}; use msg::constellation_msg::{Key, KeyModifiers, KeyState};
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId, TraversalDirection}; use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId, TraversalDirection};
use net_traits::{self, IpcSend, FetchResponseMsg, ResourceThreads}; use net_traits::{self, IpcSend, FetchResponseMsg, ResourceThreads};
use net_traits::filemanager_thread::FilterPattern;
use net_traits::pub_domains::reg_host; use net_traits::pub_domains::reg_host;
use net_traits::request::RequestInit; use net_traits::request::RequestInit;
use net_traits::storage_thread::{StorageThreadMsg, StorageType}; use net_traits::storage_thread::{StorageThreadMsg, StorageType};
@ -126,10 +125,10 @@ use profile_traits::time;
use script_traits::{AnimationState, AnimationTickType, CompositorEvent}; use script_traits::{AnimationState, AnimationTickType, CompositorEvent};
use script_traits::{ConstellationControlMsg, ConstellationMsg as FromCompositorMsg, DiscardBrowsingContext}; use script_traits::{ConstellationControlMsg, ConstellationMsg as FromCompositorMsg, DiscardBrowsingContext};
use script_traits::{DocumentActivity, DocumentState, LayoutControlMsg, LoadData}; 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::{IFrameLoadInfo, IFrameLoadInfoWithData, IFrameSandboxState, TimerSchedulerMsg};
use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, ScriptThreadFactory}; use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, ScriptThreadFactory};
use script_traits::{LogEntry, ScriptToConstellationChan, ServiceWorkerMsg, webdriver_msg}; use script_traits::{LogEntry, ScriptToConstellationChan, ServiceWorkerMsg, webdriver_msg};
use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use script_traits::{WindowSizeData, WindowSizeType}; use script_traits::{WindowSizeData, WindowSizeType};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use servo_config::opts; use servo_config::opts;
@ -175,6 +174,10 @@ pub struct Constellation<Message, LTF, STF> {
/// This is the constellation's view of `script_sender`. /// This is the constellation's view of `script_sender`.
script_receiver: Receiver<Result<(PipelineId, FromScriptMsg), IpcError>>, 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. /// An IPC channel for layout threads to send messages to the constellation.
/// This is the layout threads' view of `layout_receiver`. /// This is the layout threads' view of `layout_receiver`.
layout_sender: IpcSender<FromLayoutMsg>, layout_sender: IpcSender<FromLayoutMsg>,
@ -547,17 +550,22 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
STF: ScriptThreadFactory<Message=Message> STF: ScriptThreadFactory<Message=Message>
{ {
/// Create a new constellation thread. /// 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(); let (compositor_sender, compositor_receiver) = channel();
// service worker manager to communicate with constellation // service worker manager to communicate with constellation
let (swmanager_sender, swmanager_receiver) = ipc::channel().expect("ipc channel failure"); let (swmanager_sender, swmanager_receiver) = ipc::channel().expect("ipc channel failure");
let sw_mgr_clone = swmanager_sender.clone(); 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 || { thread::Builder::new().name("Constellation".to_owned()).spawn(move || {
let (ipc_script_sender, ipc_script_receiver) = ipc::channel().expect("ipc channel failure"); 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 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 (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); let layout_receiver = route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(ipc_layout_receiver);
@ -571,6 +579,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
script_sender: ipc_script_sender, script_sender: ipc_script_sender,
layout_sender: ipc_layout_sender, layout_sender: ipc_layout_sender,
script_receiver: script_receiver, script_receiver: script_receiver,
filemanager_receiver: filemanager_receiver,
compositor_receiver: compositor_receiver, compositor_receiver: compositor_receiver,
layout_receiver: layout_receiver, layout_receiver: layout_receiver,
network_listener_sender: network_listener_sender, network_listener_sender: network_listener_sender,
@ -637,7 +646,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
constellation.run(); constellation.run();
}).expect("Thread spawning failed"); }).expect("Thread spawning failed");
(compositor_sender, swmanager_sender) (compositor_sender, swmanager_sender, filemanager_sender)
} }
/// The main event loop for the constellation. /// The main event loop for the constellation.
@ -831,6 +840,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
Layout(FromLayoutMsg), Layout(FromLayoutMsg),
NetworkListener((PipelineId, FetchResponseMsg)), NetworkListener((PipelineId, FetchResponseMsg)),
FromSWManager(SWManagerMsg), FromSWManager(SWManagerMsg),
FromFileManager(FileManagerMsg),
} }
// Get one incoming request. // Get one incoming request.
@ -850,6 +860,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
let receiver_from_layout = &self.layout_receiver; let receiver_from_layout = &self.layout_receiver;
let receiver_from_network_listener = &self.network_listener_receiver; let receiver_from_network_listener = &self.network_listener_receiver;
let receiver_from_swmanager = &self.swmanager_receiver; let receiver_from_swmanager = &self.swmanager_receiver;
let receiver_from_filemanager = &self.filemanager_receiver;
select! { select! {
msg = receiver_from_script.recv() => msg = receiver_from_script.recv() =>
msg.expect("Unexpected script channel panic in constellation").map(Request::Script), msg.expect("Unexpected script channel panic in constellation").map(Request::Script),
@ -862,7 +873,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
msg.expect("Unexpected network listener channel panic in constellation") msg.expect("Unexpected network listener channel panic in constellation")
)), )),
msg = receiver_from_swmanager.recv() => 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)
} }
}; };
@ -886,6 +899,9 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}, },
Request::FromSWManager(message) => { Request::FromSWManager(message) => {
self.handle_request_from_swmanager(message); self.handle_request_from_swmanager(message);
},
Request::FromFileManager(message) => {
self.handle_request_from_filemanager(message);
} }
} }
} }
@ -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) { fn handle_request_from_compositor(&mut self, message: FromCompositorMsg) {
match message { match message {
FromCompositorMsg::Exit => { FromCompositorMsg::Exit => {
@ -1013,9 +1038,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
FromCompositorMsg::SetCursor(cursor) => { FromCompositorMsg::SetCursor(cursor) => {
self.handle_set_cursor_msg(cursor) self.handle_set_cursor_msg(cursor)
} }
FromCompositorMsg::OpenFileSelectDialog(patterns, multiple_files, sender) => {
self.handle_open_file_select_dialog_msg(patterns, multiple_files, sender);
}
} }
} }
@ -1742,14 +1764,6 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
self.embedder_proxy.send(EmbedderMsg::SetCursor(cursor)) 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, fn handle_change_running_animations_state(&mut self,
pipeline_id: PipelineId, pipeline_id: PipelineId,
animation_state: AnimationState) { animation_state: AnimationState) {

View file

@ -51,7 +51,6 @@ use libc::c_void;
use msg::constellation_msg::{BrowsingContextId, HistoryStateId, Key, KeyModifiers, KeyState, PipelineId}; use msg::constellation_msg::{BrowsingContextId, HistoryStateId, Key, KeyModifiers, KeyState, PipelineId};
use msg::constellation_msg::{PipelineNamespaceId, TraversalDirection, TopLevelBrowsingContextId}; use msg::constellation_msg::{PipelineNamespaceId, TraversalDirection, TopLevelBrowsingContextId};
use net_traits::{FetchResponseMsg, ReferrerPolicy, ResourceThreads}; use net_traits::{FetchResponseMsg, ReferrerPolicy, ResourceThreads};
use net_traits::filemanager_thread::FilterPattern;
use net_traits::image::base::Image; use net_traits::image::base::Image;
use net_traits::image::base::PixelFormat; use net_traits::image::base::PixelFormat;
use net_traits::image_cache::ImageCache; use net_traits::image_cache::ImageCache;
@ -74,7 +73,7 @@ use webrender_api::{ExternalScrollId, DevicePixel, DeviceUintSize, DocumentId, I
use webvr_traits::{WebVREvent, WebVRMsg}; use webvr_traits::{WebVREvent, WebVRMsg};
pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry}; 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 /// 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. /// `from_untrusted_node_address` before they can be used, because we do not trust layout.
@ -706,8 +705,6 @@ pub enum ConstellationMsg {
ForwardEvent(PipelineId, CompositorEvent), ForwardEvent(PipelineId, CompositorEvent),
/// Requesting a change to the onscreen cursor. /// Requesting a change to the onscreen cursor.
SetCursor(CursorKind), SetCursor(CursorKind),
/// Requesting to open file select dialog
OpenFileSelectDialog(Vec<FilterPattern>, bool, IpcSender<Option<Vec<String>>>),
} }
/// Resources required by workerglobalscopes /// Resources required by workerglobalscopes

View file

@ -19,6 +19,7 @@ use ipc_channel::ipc::{IpcReceiver, IpcSender};
use msg::constellation_msg::{BrowsingContextId, HistoryStateId, PipelineId, TraversalDirection}; use msg::constellation_msg::{BrowsingContextId, HistoryStateId, PipelineId, TraversalDirection};
use msg::constellation_msg::{InputMethodType, Key, KeyModifiers, KeyState}; use msg::constellation_msg::{InputMethodType, Key, KeyModifiers, KeyState};
use net_traits::CoreResourceMsg; use net_traits::CoreResourceMsg;
use net_traits::filemanager_thread::FilterPattern;
use net_traits::request::RequestInit; use net_traits::request::RequestInit;
use net_traits::storage_thread::StorageType; use net_traits::storage_thread::StorageType;
use servo_url::ImmutableOrigin; use servo_url::ImmutableOrigin;
@ -217,3 +218,10 @@ pub enum SWManagerMsg {
/// Provide the constellation with a means of communicating with the Service Worker Manager /// Provide the constellation with a means of communicating with the Service Worker Manager
OwnSender(IpcSender<ServiceWorkerMsg>), 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>>>)
}