mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
refactor(filemanager): use filemanagermsg to request embedder
This commit is contained in:
parent
52b9e4f0ab
commit
7cec47b3fa
4 changed files with 22 additions and 18 deletions
|
@ -7,7 +7,7 @@ use mime_guess::guess_mime_type_opt;
|
|||
use net_traits::blob_url_store::{BlobBuf, BlobURLStoreError};
|
||||
use net_traits::filemanager_thread::{FileManagerResult, FileManagerThreadMsg, FileOrigin, FilterPattern};
|
||||
use net_traits::filemanager_thread::{FileManagerThreadError, ReadFileProgress, RelativePos, SelectedFile};
|
||||
use script_traits::ConstellationMsg;
|
||||
use script_traits::FileManagerMsg;
|
||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
||||
use servo_config::opts;
|
||||
use servo_config::prefs::PREFS;
|
||||
|
@ -18,7 +18,6 @@ use std::ops::Index;
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::atomic::{self, AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thread;
|
||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
||||
use url::Url;
|
||||
|
@ -63,12 +62,12 @@ enum FileImpl {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct FileManager {
|
||||
constellation_chan: Sender<ConstellationMsg>,
|
||||
constellation_chan: IpcSender<FileManagerMsg>,
|
||||
store: Arc<FileManagerStore>,
|
||||
}
|
||||
|
||||
impl FileManager {
|
||||
pub fn new(constellation_chan: Sender<ConstellationMsg>) -> FileManager {
|
||||
pub fn new(constellation_chan: IpcSender<FileManagerMsg>) -> FileManager {
|
||||
FileManager {
|
||||
constellation_chan: constellation_chan,
|
||||
store: Arc::new(FileManagerStore::new()),
|
||||
|
@ -222,13 +221,13 @@ impl FileManagerStore {
|
|||
fn get_selected_files(&self,
|
||||
patterns: Vec<FilterPattern>,
|
||||
multiple_files: bool,
|
||||
constellation_chan: Sender<ConstellationMsg>) -> Option<Vec<String>> {
|
||||
constellation_chan: IpcSender<FileManagerMsg>) -> Option<Vec<String>> {
|
||||
if opts::get().headless {
|
||||
return None;
|
||||
}
|
||||
|
||||
let (ipc_sender, ipc_receiver) = ipc::channel().expect("Failed to create IPC channel!");
|
||||
let msg = ConstellationMsg::OpenFileSelectDialog(patterns, multiple_files, ipc_sender);
|
||||
let msg = FileManagerMsg::OpenFileSelectDialog(patterns, multiple_files, ipc_sender);
|
||||
|
||||
constellation_chan.send(msg).map(|_| ipc_receiver.recv().unwrap()).unwrap_or_default()
|
||||
}
|
||||
|
@ -238,7 +237,7 @@ impl FileManagerStore {
|
|||
sender: IpcSender<FileManagerResult<SelectedFile>>,
|
||||
origin: FileOrigin,
|
||||
opt_test_path: Option<String>,
|
||||
constellation_chan: Sender<ConstellationMsg>) {
|
||||
constellation_chan: IpcSender<FileManagerMsg>) {
|
||||
// Check if the select_files preference is enabled
|
||||
// to ensure process-level security against compromised script;
|
||||
// Then try applying opt_test_path directly for testing convenience
|
||||
|
@ -266,7 +265,7 @@ impl FileManagerStore {
|
|||
sender: IpcSender<FileManagerResult<Vec<SelectedFile>>>,
|
||||
origin: FileOrigin,
|
||||
opt_test_paths: Option<Vec<String>>,
|
||||
constellation_chan: Sender<ConstellationMsg>) {
|
||||
constellation_chan: IpcSender<FileManagerMsg>) {
|
||||
// Check if the select_files preference is enabled
|
||||
// to ensure process-level security against compromised script;
|
||||
// Then try applying opt_test_paths directly for testing convenience
|
||||
|
|
|
@ -28,7 +28,7 @@ use net_traits::storage_thread::StorageThreadMsg;
|
|||
use profile_traits::mem::{Report, ReportsChan, ReportKind};
|
||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||
use profile_traits::time::ProfilerChan;
|
||||
use script_traits::ConstellationMsg;
|
||||
use script_traits::FileManagerMsg;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use servo_allocator;
|
||||
|
@ -42,7 +42,7 @@ use std::io::prelude::*;
|
|||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::sync::mpsc::{self, Sender};
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thread;
|
||||
use storage_thread::StorageThreadFactory;
|
||||
use websocket_loader;
|
||||
|
@ -53,7 +53,7 @@ pub fn new_resource_threads(user_agent: Cow<'static, str>,
|
|||
time_profiler_chan: ProfilerChan,
|
||||
mem_profiler_chan: MemProfilerChan,
|
||||
config_dir: Option<PathBuf>)
|
||||
-> (ResourceThreads, ResourceThreads, Sender<Sender<ConstellationMsg>>) {
|
||||
-> (ResourceThreads, ResourceThreads, IpcSender<IpcSender<FileManagerMsg>>) {
|
||||
let (public_core, private_core, constellation_sender) = new_core_resource_thread(
|
||||
user_agent,
|
||||
devtools_chan,
|
||||
|
@ -73,11 +73,11 @@ pub fn new_core_resource_thread(user_agent: Cow<'static, str>,
|
|||
time_profiler_chan: ProfilerChan,
|
||||
mem_profiler_chan: MemProfilerChan,
|
||||
config_dir: Option<PathBuf>)
|
||||
-> (CoreResourceThread, CoreResourceThread, Sender<Sender<ConstellationMsg>>) {
|
||||
-> (CoreResourceThread, CoreResourceThread, IpcSender<IpcSender<FileManagerMsg>>) {
|
||||
let (public_setup_chan, public_setup_port) = ipc::channel().unwrap();
|
||||
let (private_setup_chan, private_setup_port) = ipc::channel().unwrap();
|
||||
let (report_chan, report_port) = ipc::channel().unwrap();
|
||||
let (constellation_sender, constellation_receiver) = mpsc::channel();
|
||||
let (constellation_sender, constellation_receiver) = ipc::channel().unwrap();
|
||||
|
||||
thread::Builder::new().name("ResourceManager".to_owned()).spawn(move || {
|
||||
let constellation_chan = constellation_receiver.recv().unwrap();
|
||||
|
@ -377,7 +377,7 @@ impl CoreResourceManager {
|
|||
pub fn new(user_agent: Cow<'static, str>,
|
||||
devtools_channel: Option<Sender<DevtoolsControlMsg>>,
|
||||
_profiler_chan: ProfilerChan,
|
||||
constellation_chan: Sender<ConstellationMsg>) -> CoreResourceManager {
|
||||
constellation_chan: IpcSender<FileManagerMsg>) -> CoreResourceManager {
|
||||
CoreResourceManager {
|
||||
user_agent: user_agent,
|
||||
devtools_chan: devtools_channel,
|
||||
|
|
|
@ -523,7 +523,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
|
|||
webgl_threads,
|
||||
webvr_chan,
|
||||
};
|
||||
let (constellation_chan, from_swmanager_sender) =
|
||||
let (constellation_chan, from_swmanager_sender, from_filemanager_sender) =
|
||||
Constellation::<script_layout_interface::message::Msg,
|
||||
layout_thread::LayoutThread,
|
||||
script::script_thread::ScriptThread>::start(initial_state);
|
||||
|
@ -533,7 +533,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
|
|||
webvr_constellation_sender.send(constellation_chan.clone()).unwrap();
|
||||
}
|
||||
|
||||
resource_constellation_sender.send(constellation_chan.clone()).unwrap();
|
||||
resource_constellation_sender.send(from_filemanager_sender.clone()).unwrap();
|
||||
|
||||
// channels to communicate with Service Worker Manager
|
||||
let sw_senders = SWManagerSenders {
|
||||
|
|
|
@ -18,6 +18,7 @@ use servo::servo_url::ServoUrl;
|
|||
use servo::webrender_api::ScrollLocation;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
||||
use std::thread;
|
||||
use tinyfiledialogs;
|
||||
|
||||
|
@ -344,7 +345,9 @@ fn platform_get_selected_devices(devices: Vec<String>, sender: IpcSender<Option<
|
|||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
||||
fn platform_get_selected_files(patterns: Vec<FilterPattern>, multiple_files: bool, sender: IpcSender<Option<Vec<String>>>) {
|
||||
fn platform_get_selected_files(patterns: Vec<FilterPattern>,
|
||||
multiple_files: bool,
|
||||
sender: IpcSender<Option<Vec<String>>>) {
|
||||
let picker_name = if multiple_files { "Pick files" } else { "Pick a file" };
|
||||
|
||||
thread::Builder::new().name(picker_name.to_owned()).spawn(move || {
|
||||
|
@ -368,7 +371,9 @@ fn platform_get_selected_files(patterns: Vec<FilterPattern>, multiple_files: boo
|
|||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
|
||||
fn platform_get_selected_files(_patterns: Vec<FilterPattern>, _multiple_files: bool, sender: IpcSender<Option<Vec<String>>>) {
|
||||
fn platform_get_selected_files(_patterns: Vec<FilterPattern>,
|
||||
_multiple_files: bool,
|
||||
sender: IpcSender<Option<Vec<String>>>) {
|
||||
sender.send(None);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue