Auto merge of #11536 - izgzhen:add-blob-loader, r=Manishearth

Add blob loader

Add a blob loader to implement [Blob URL](https://w3c.github.io/FileAPI/#url). The related interfaces to script thread are also declared.

Progressing in parallel with PR #11534. Related to #11131.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix part of #10539

<!-- Either: -->
- [x] These changes do not require tests because not integrated yet.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/11536)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-08 06:13:39 -05:00
commit 3977128d7e
6 changed files with 191 additions and 0 deletions

View file

@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use ipc_channel::ipc::IpcSender;
use std::str::FromStr;
use url::Url;
use uuid::Uuid;
/// Errors returns to BlobURLStoreMsg::Request
#[derive(Clone, Serialize, Deserialize)]
pub enum BlobURLStoreError {
/// Invalid UUID key
InvalidKey,
/// Invalid URL origin
InvalidOrigin,
}
/// Blob URL store entry, a packaged form of Blob DOM object
#[derive(Clone, Serialize, Deserialize)]
pub struct BlobURLStoreEntry {
/// MIME type string
pub type_string: String,
/// Some filename if the backend of Blob is a file
pub filename: Option<String>,
/// Size of content in bytes
pub size: u64,
/// Content of blob
pub bytes: Vec<u8>,
}
/// Message-passing style interface between store and loader
#[derive(Serialize, Deserialize)]
pub enum BlobURLStoreMsg {
/// Request for an blob entry identified by uuid
Request(Uuid, IpcSender<Result<BlobURLStoreEntry, BlobURLStoreError>>),
}
/// Parse URL as Blob URL scheme's definition
/// https://w3c.github.io/FileAPI/#DefinitionOfScheme
pub fn parse_blob_url(url: &Url) -> Option<(Uuid, Option<&str>)> {
url.path_segments().and_then(|mut segments| {
let id_str = match (segments.next(), segments.next()) {
(Some(s), None) => s,
_ => return None,
};
Uuid::from_str(id_str).map(|id| (id, url.fragment())).ok()
})
}

View file

@ -4,6 +4,7 @@
use ipc_channel::ipc::IpcSender;
use std::path::PathBuf;
use super::{LoadConsumer, LoadData};
use uuid::Uuid;
#[derive(Debug, Deserialize, Serialize)]
@ -29,6 +30,9 @@ pub enum FileManagerThreadMsg {
/// Delete the FileID entry
DeleteFileID(Uuid),
/// Load resource by Blob URL
LoadBlob(LoadData, LoadConsumer),
/// Shut down this thread
Exit,
}

View file

@ -43,6 +43,7 @@ use storage_thread::StorageThreadMsg;
use url::Url;
use websocket::header;
pub mod blob_url_store;
pub mod bluetooth_scanfilter;
pub mod bluetooth_thread;
pub mod filemanager_thread;