mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #11225 - izgzhen:patch-input-element-file, r=Manishearth
Implement file related functionalities in htmlinputelement and related - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy --faster` does not report any errors - [x] These changes is related to #11131 - [x] These changes do not require tests because it is a partial implementation 1. Improve the `filemanager_thread` by adding type string and create `SelectedFile` 2. Fill several gaps in `htmlinputelement` implementation related to file type 3. Improve the `File` interface to accommodate the above changes 4. Integrate changes introduced by PR #11189 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11225) <!-- Reviewable:end -->
This commit is contained in:
commit
7cea4eb01c
10 changed files with 155 additions and 30 deletions
|
@ -3,7 +3,9 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerResult, FileManagerThreadError};
|
||||
use mime_guess::guess_mime_type_opt;
|
||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerResult};
|
||||
use net_traits::filemanager_thread::{SelectedFile, FileManagerThreadError};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
|
@ -17,15 +19,13 @@ pub struct FileManager {
|
|||
idmap: RefCell<HashMap<Uuid, PathBuf>>,
|
||||
}
|
||||
|
||||
impl FileManager {
|
||||
fn new(recv: IpcReceiver<FileManagerThreadMsg>) -> FileManager {
|
||||
FileManager {
|
||||
receiver: recv,
|
||||
idmap: RefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
pub trait FileManagerThreadFactory {
|
||||
fn new() -> Self;
|
||||
}
|
||||
|
||||
pub fn new_thread() -> IpcSender<FileManagerThreadMsg> {
|
||||
impl FileManagerThreadFactory for IpcSender<FileManagerThreadMsg> {
|
||||
/// Create a FileManagerThread
|
||||
fn new() -> IpcSender<FileManagerThreadMsg> {
|
||||
let (chan, recv) = ipc::channel().unwrap();
|
||||
|
||||
spawn_named("FileManager".to_owned(), move || {
|
||||
|
@ -34,6 +34,16 @@ impl FileManager {
|
|||
|
||||
chan
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl FileManager {
|
||||
fn new(recv: IpcReceiver<FileManagerThreadMsg>) -> FileManager {
|
||||
FileManager {
|
||||
receiver: recv,
|
||||
idmap: RefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Start the file manager event loop
|
||||
fn start(&mut self) {
|
||||
|
@ -49,7 +59,7 @@ impl FileManager {
|
|||
}
|
||||
|
||||
impl FileManager {
|
||||
fn select_file(&mut self, sender: IpcSender<FileManagerResult<(Uuid, PathBuf, u64)>>) {
|
||||
fn select_file(&mut self, sender: IpcSender<FileManagerResult<SelectedFile>>) {
|
||||
// TODO: Pull the dialog UI in and get selected
|
||||
let selected_path = Path::new("");
|
||||
|
||||
|
@ -63,7 +73,7 @@ impl FileManager {
|
|||
}
|
||||
}
|
||||
|
||||
fn select_files(&mut self, sender: IpcSender<FileManagerResult<Vec<(Uuid, PathBuf, u64)>>>) {
|
||||
fn select_files(&mut self, sender: IpcSender<FileManagerResult<Vec<SelectedFile>>>) {
|
||||
let selected_paths = vec![Path::new("")];
|
||||
|
||||
let mut replies = vec![];
|
||||
|
@ -81,7 +91,7 @@ impl FileManager {
|
|||
let _ = sender.send(Ok(replies));
|
||||
}
|
||||
|
||||
fn create_entry(&mut self, file_path: &Path) -> Option<(Uuid, PathBuf, u64)> {
|
||||
fn create_entry(&mut self, file_path: &Path) -> Option<SelectedFile> {
|
||||
match File::open(file_path) {
|
||||
Ok(handler) => {
|
||||
let id = Uuid::new_v4();
|
||||
|
@ -100,7 +110,19 @@ impl FileManager {
|
|||
let filename = file_path.file_name();
|
||||
|
||||
match (epoch, filename) {
|
||||
(Ok(epoch), Some(filename)) => Some((id, Path::new(filename).to_path_buf(), epoch)),
|
||||
(Ok(epoch), Some(filename)) => {
|
||||
let filename_path = Path::new(filename);
|
||||
let mime = guess_mime_type_opt(filename_path);
|
||||
Some(SelectedFile {
|
||||
id: id,
|
||||
filename: filename_path.to_path_buf(),
|
||||
modified: epoch,
|
||||
type_string: match mime {
|
||||
Some(x) => format!("{}", x),
|
||||
None => "".to_string(),
|
||||
},
|
||||
})
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
},
|
||||
|
|
|
@ -11,6 +11,7 @@ use cookie_storage::CookieStorage;
|
|||
use data_loader;
|
||||
use devtools_traits::{DevtoolsControlMsg};
|
||||
use file_loader;
|
||||
use filemanager_thread::FileManagerThreadFactory;
|
||||
use hsts::HstsList;
|
||||
use http_loader::{self, HttpState};
|
||||
use hyper::client::pool::Pool;
|
||||
|
@ -154,7 +155,8 @@ pub fn new_resource_threads(user_agent: String,
|
|||
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||
profiler_chan: ProfilerChan) -> ResourceThreads {
|
||||
ResourceThreads::new(new_core_resource_thread(user_agent, devtools_chan, profiler_chan),
|
||||
StorageThreadFactory::new())
|
||||
StorageThreadFactory::new(),
|
||||
FileManagerThreadFactory::new())
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue