mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement Blob URL's DOM interfaces
This commit is contained in:
parent
5a0c98afb2
commit
4d3379392d
17 changed files with 146 additions and 97 deletions
|
@ -6,7 +6,7 @@ use blob_loader;
|
|||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use mime_classifier::MIMEClassifier;
|
||||
use mime_guess::guess_mime_type_opt;
|
||||
use net_traits::blob_url_store::{BlobURLStoreEntry, BlobURLStoreError};
|
||||
use net_traits::blob_url_store::{BlobURLStoreEntry, BlobURLStoreError, BlobURLStoreMsg};
|
||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerResult, FilterPattern};
|
||||
use net_traits::filemanager_thread::{SelectedFile, FileManagerThreadError, SelectedFileId};
|
||||
use std::collections::HashMap;
|
||||
|
@ -16,7 +16,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::{Arc, RwLock};
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
use tinyfiledialogs;
|
||||
use url::Origin;
|
||||
use url::{Url, Origin};
|
||||
use util::thread::spawn_named;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -105,6 +105,7 @@ impl<UI: 'static + UIProvider> FileManager<UI> {
|
|||
}
|
||||
}
|
||||
FileManagerThreadMsg::DeleteFileID(id) => self.delete_fileid(id),
|
||||
FileManagerThreadMsg::BlobURLStoreMsg(msg) => self.blob_url_store.write().unwrap().process(msg),
|
||||
FileManagerThreadMsg::LoadBlob(load_data, consumer) => {
|
||||
blob_loader::load(load_data, consumer,
|
||||
self.blob_url_store.clone(),
|
||||
|
@ -232,6 +233,29 @@ impl BlobURLStore {
|
|||
}
|
||||
}
|
||||
|
||||
fn process(&mut self, msg: BlobURLStoreMsg) {
|
||||
match msg {
|
||||
BlobURLStoreMsg::AddEntry(entry, origin_str, sender) => {
|
||||
match Url::parse(&origin_str) {
|
||||
Ok(base_url) => {
|
||||
let id = Uuid::new_v4();
|
||||
self.add_entry(id, base_url.origin(), entry);
|
||||
|
||||
let _ = sender.send(Ok(id.simple().to_string()));
|
||||
}
|
||||
Err(_) => {
|
||||
let _ = sender.send(Err(BlobURLStoreError::InvalidOrigin));
|
||||
}
|
||||
}
|
||||
}
|
||||
BlobURLStoreMsg::DeleteEntry(id) => {
|
||||
if let Ok(id) = Uuid::parse_str(&id) {
|
||||
self.delete_entry(id);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request(&self, id: Uuid, origin: &Origin) -> Result<&BlobURLStoreEntry, BlobURLStoreError> {
|
||||
match self.entries.get(&id) {
|
||||
Some(ref pair) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue