mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Resolves #4183 - Implemementing context-based MIME type sniffing
The version of the standard is not finalized at the time of this writing. Specifications may be found here: https://mimesniff.spec.whatwg.org/#context-specific-sniffing .
This commit is contained in:
parent
66c8aa8cda
commit
1e81b8c133
18 changed files with 226 additions and 93 deletions
|
@ -136,6 +136,21 @@ pub mod image {
|
|||
pub mod base;
|
||||
}
|
||||
|
||||
/// A loading context, for context-specific sniffing, as defined in
|
||||
/// https://mimesniff.spec.whatwg.org/#context-specific-sniffing
|
||||
#[derive(Clone, Deserialize, Serialize, HeapSizeOf)]
|
||||
pub enum LoadContext {
|
||||
Browsing,
|
||||
Image,
|
||||
AudioVideo,
|
||||
Plugin,
|
||||
Style,
|
||||
Script,
|
||||
Font,
|
||||
TextTrack,
|
||||
CacheManifest,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize, HeapSizeOf)]
|
||||
pub struct LoadData {
|
||||
pub url: Url,
|
||||
|
@ -151,10 +166,11 @@ pub struct LoadData {
|
|||
pub pipeline_id: Option<PipelineId>,
|
||||
// https://fetch.spec.whatwg.org/#concept-http-fetch step 4.3
|
||||
pub credentials_flag: bool,
|
||||
pub context: LoadContext,
|
||||
}
|
||||
|
||||
impl LoadData {
|
||||
pub fn new(url: Url, id: Option<PipelineId>) -> LoadData {
|
||||
pub fn new(context: LoadContext, url: Url, id: Option<PipelineId>) -> LoadData {
|
||||
LoadData {
|
||||
url: url,
|
||||
method: Method::Get,
|
||||
|
@ -164,6 +180,7 @@ impl LoadData {
|
|||
cors: None,
|
||||
pipeline_id: id,
|
||||
credentials_flag: true,
|
||||
context: context
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -295,6 +312,7 @@ pub struct PendingAsyncLoad {
|
|||
url: Url,
|
||||
pipeline: Option<PipelineId>,
|
||||
guard: PendingLoadGuard,
|
||||
context: LoadContext,
|
||||
}
|
||||
|
||||
struct PendingLoadGuard {
|
||||
|
@ -316,20 +334,21 @@ impl Drop for PendingLoadGuard {
|
|||
}
|
||||
|
||||
impl PendingAsyncLoad {
|
||||
pub fn new(resource_task: ResourceTask, url: Url, pipeline: Option<PipelineId>)
|
||||
pub fn new(context: LoadContext, resource_task: ResourceTask, url: Url, pipeline: Option<PipelineId>)
|
||||
-> PendingAsyncLoad {
|
||||
PendingAsyncLoad {
|
||||
resource_task: resource_task,
|
||||
url: url,
|
||||
pipeline: pipeline,
|
||||
guard: PendingLoadGuard { loaded: false, },
|
||||
context: context
|
||||
}
|
||||
}
|
||||
|
||||
/// Initiate the network request associated with this pending load, using the provided target.
|
||||
pub fn load_async(mut self, listener: AsyncResponseTarget) {
|
||||
self.guard.neuter();
|
||||
let load_data = LoadData::new(self.url, self.pipeline);
|
||||
let load_data = LoadData::new(self.context, self.url, self.pipeline);
|
||||
let consumer = LoadConsumer::Listener(listener);
|
||||
self.resource_task.send(ControlMsg::Load(load_data, consumer, None)).unwrap();
|
||||
}
|
||||
|
@ -425,10 +444,13 @@ pub enum ProgressMsg {
|
|||
}
|
||||
|
||||
/// Convenience function for synchronously loading a whole resource.
|
||||
pub fn load_whole_resource(resource_task: &ResourceTask, url: Url, pipeline_id: Option<PipelineId>)
|
||||
pub fn load_whole_resource(context: LoadContext,
|
||||
resource_task: &ResourceTask,
|
||||
url: Url,
|
||||
pipeline_id: Option<PipelineId>)
|
||||
-> Result<(Metadata, Vec<u8>), String> {
|
||||
let (start_chan, start_port) = ipc::channel().unwrap();
|
||||
resource_task.send(ControlMsg::Load(LoadData::new(url, pipeline_id),
|
||||
resource_task.send(ControlMsg::Load(LoadData::new(context, url, pipeline_id),
|
||||
LoadConsumer::Channel(start_chan), None)).unwrap();
|
||||
let response = start_port.recv().unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue