From 52b9e4f0abf145ceb695d0b8f6addcef71b4bbac Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Tue, 3 Apr 2018 09:57:46 -0700 Subject: [PATCH] refactor(constellation): replace constellationmsg to filemanagermsg --- components/compositing/compositor_thread.rs | 2 +- components/constellation/constellation.rs | 46 ++++++++++++++------- components/script_traits/lib.rs | 5 +-- components/script_traits/script_msg.rs | 8 ++++ 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/components/compositing/compositor_thread.rs b/components/compositing/compositor_thread.rs index f4aa96c20b9..d4d177c29e1 100644 --- a/components/compositing/compositor_thread.rs +++ b/components/compositing/compositor_thread.rs @@ -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"), diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 048e0c7b740..0f1e6a37393 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -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}; @@ -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; @@ -175,6 +174,10 @@ pub struct Constellation { /// This is the constellation's view of `script_sender`. script_receiver: Receiver>, + /// A channel for the constellation to receive messages from filemanager threads. + /// This is the constellation's view of `filemanager_sender`. + filemanager_receiver: Receiver>, + /// An IPC channel for layout threads to send messages to the constellation. /// This is the layout threads' view of `layout_receiver`. layout_sender: IpcSender, @@ -547,17 +550,22 @@ impl Constellation STF: ScriptThreadFactory { /// Create a new constellation thread. - pub fn start(state: InitialConstellationState) -> (Sender, IpcSender) { + pub fn start(state: InitialConstellationState) + -> (Sender, IpcSender, IpcSender) { 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); @@ -571,6 +579,7 @@ impl Constellation 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, @@ -637,7 +646,7 @@ impl Constellation constellation.run(); }).expect("Thread spawning failed"); - (compositor_sender, swmanager_sender) + (compositor_sender, swmanager_sender, filemanager_sender) } /// The main event loop for the constellation. @@ -831,6 +840,7 @@ impl Constellation Layout(FromLayoutMsg), NetworkListener((PipelineId, FetchResponseMsg)), FromSWManager(SWManagerMsg), + FromFileManager(FileManagerMsg), } // Get one incoming request. @@ -850,6 +860,7 @@ impl Constellation 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), @@ -862,7 +873,9 @@ impl Constellation 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) } }; @@ -886,6 +899,9 @@ impl Constellation }, Request::FromSWManager(message) => { self.handle_request_from_swmanager(message); + }, + Request::FromFileManager(message) => { + self.handle_request_from_filemanager(message); } } } @@ -915,6 +931,15 @@ impl Constellation } } + 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 => { @@ -1013,9 +1038,6 @@ impl Constellation 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); - } } } @@ -1742,14 +1764,6 @@ impl Constellation self.embedder_proxy.send(EmbedderMsg::SetCursor(cursor)) } - fn handle_open_file_select_dialog_msg(&mut self, - patterns: Vec, - multiple_files: bool, - sender: IpcSender>>) { - 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) { diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 584798caf0e..b2cf6a97e43 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -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; @@ -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. @@ -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, bool, IpcSender>>), } /// Resources required by workerglobalscopes diff --git a/components/script_traits/script_msg.rs b/components/script_traits/script_msg.rs index d263753c7de..9df1e7ee077 100644 --- a/components/script_traits/script_msg.rs +++ b/components/script_traits/script_msg.rs @@ -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; @@ -217,3 +218,10 @@ pub enum SWManagerMsg { /// Provide the constellation with a means of communicating with the Service Worker Manager OwnSender(IpcSender), } + +/// Messages outgoing from the File Manager thread to constellation +#[derive(Deserialize, Serialize)] +pub enum FileManagerMsg { + /// Requesting to open file select dialog + OpenFileSelectDialog(Vec, bool, IpcSender>>) +}