mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Implement file-type functionalities in htmlinputelement and related
Changes include: - Implement file selection and other DOM behaviours in htmlinputelement - Integrate IpcSender<FileManagerThreadMsg> into ResourceThreads - Improve filemanager_thread, including adding type_string field to SelectedFile - Improve interfaces in FileList/File/Blob to accommodate the above changes
This commit is contained in:
parent
983612751b
commit
dd590d088b
10 changed files with 155 additions and 30 deletions
|
@ -6,13 +6,22 @@ use ipc_channel::ipc::IpcSender;
|
|||
use std::path::PathBuf;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct SelectedFile {
|
||||
pub id: Uuid,
|
||||
pub filename: PathBuf,
|
||||
pub modified: u64,
|
||||
// https://w3c.github.io/FileAPI/#dfn-type
|
||||
pub type_string: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum FileManagerThreadMsg {
|
||||
/// Select a single file, return triple (FileID, FileName, lastModified)
|
||||
SelectFile(IpcSender<FileManagerResult<(Uuid, PathBuf, u64)>>),
|
||||
SelectFile(IpcSender<FileManagerResult<SelectedFile>>),
|
||||
|
||||
/// Select multiple files, return a vector of triples
|
||||
SelectFiles(IpcSender<FileManagerResult<Vec<(Uuid, PathBuf, u64)>>>),
|
||||
SelectFiles(IpcSender<FileManagerResult<Vec<SelectedFile>>>),
|
||||
|
||||
/// Read file, return the bytes
|
||||
ReadFile(IpcSender<FileManagerResult<Vec<u8>>>, Uuid),
|
||||
|
@ -23,7 +32,7 @@ pub enum FileManagerThreadMsg {
|
|||
|
||||
pub type FileManagerResult<T> = Result<T, FileManagerThreadError>;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum FileManagerThreadError {
|
||||
/// The selection action is invalid, nothing is selected
|
||||
InvalidSelection,
|
||||
|
|
|
@ -28,6 +28,7 @@ extern crate util;
|
|||
extern crate uuid;
|
||||
extern crate websocket;
|
||||
|
||||
use filemanager_thread::FileManagerThreadMsg;
|
||||
use heapsize::HeapSizeOf;
|
||||
use hyper::header::{ContentType, Headers};
|
||||
use hyper::http::RawStatus;
|
||||
|
@ -186,8 +187,13 @@ pub type CoreResourceThread = IpcSender<CoreResourceMsg>;
|
|||
|
||||
pub type IpcSendResult = Result<(), IOError>;
|
||||
|
||||
/// Abstraction of the ability to send a particular type of message,
|
||||
/// used by net_traits::ResourceThreads to ease the use its IpcSender sub-fields
|
||||
/// XXX: If this trait will be used more in future, some auto derive might be appealing
|
||||
pub trait IpcSend<T> where T: serde::Serialize + serde::Deserialize {
|
||||
/// send message T
|
||||
fn send(&self, T) -> IpcSendResult;
|
||||
/// get underlying sender
|
||||
fn sender(&self) -> IpcSender<T>;
|
||||
}
|
||||
|
||||
|
@ -200,13 +206,17 @@ pub trait IpcSend<T> where T: serde::Serialize + serde::Deserialize {
|
|||
pub struct ResourceThreads {
|
||||
core_thread: CoreResourceThread,
|
||||
storage_thread: IpcSender<StorageThreadMsg>,
|
||||
filemanager_thread: IpcSender<FileManagerThreadMsg>,
|
||||
}
|
||||
|
||||
impl ResourceThreads {
|
||||
pub fn new(c: CoreResourceThread, s: IpcSender<StorageThreadMsg>) -> ResourceThreads {
|
||||
pub fn new(c: CoreResourceThread,
|
||||
s: IpcSender<StorageThreadMsg>,
|
||||
f: IpcSender<FileManagerThreadMsg>) -> ResourceThreads {
|
||||
ResourceThreads {
|
||||
core_thread: c,
|
||||
storage_thread: s,
|
||||
filemanager_thread: f,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,6 +241,16 @@ impl IpcSend<StorageThreadMsg> for ResourceThreads {
|
|||
}
|
||||
}
|
||||
|
||||
impl IpcSend<FileManagerThreadMsg> for ResourceThreads {
|
||||
fn send(&self, msg: FileManagerThreadMsg) -> IpcSendResult {
|
||||
self.filemanager_thread.send(msg)
|
||||
}
|
||||
|
||||
fn sender(&self) -> IpcSender<FileManagerThreadMsg> {
|
||||
self.filemanager_thread.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore the sub-fields
|
||||
impl HeapSizeOf for ResourceThreads {
|
||||
fn heap_size_of_children(&self) -> usize { 0 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue