mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +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
|
@ -7,7 +7,7 @@
|
|||
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::AsyncResponseTarget;
|
||||
use net_traits::{PendingAsyncLoad, ResourceTask};
|
||||
use net_traits::{PendingAsyncLoad, ResourceTask, LoadContext};
|
||||
use std::sync::Arc;
|
||||
use url::Url;
|
||||
|
||||
|
@ -30,6 +30,15 @@ impl LoadType {
|
|||
LoadType::PageSource(ref url) => url,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_load_context(&self) -> LoadContext {
|
||||
match *self {
|
||||
LoadType::Image(_) => LoadContext::Image,
|
||||
LoadType::Script(_) => LoadContext::Script,
|
||||
LoadType::Subframe(_) | LoadType::PageSource(_) => LoadContext::Browsing,
|
||||
LoadType::Stylesheet(_) => LoadContext::Style
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
|
@ -67,9 +76,10 @@ impl DocumentLoader {
|
|||
/// Create a new pending network request, which can be initiated at some point in
|
||||
/// the future.
|
||||
pub fn prepare_async_load(&mut self, load: LoadType) -> PendingAsyncLoad {
|
||||
let context = load.to_load_context();
|
||||
let url = load.url().clone();
|
||||
self.blocking_loads.push(load);
|
||||
PendingAsyncLoad::new((*self.resource_task).clone(), url, self.pipeline)
|
||||
PendingAsyncLoad::new(context, (*self.resource_task).clone(), url, self.pipeline)
|
||||
}
|
||||
|
||||
/// Create and initiate a new network request.
|
||||
|
@ -78,7 +88,6 @@ impl DocumentLoader {
|
|||
pending.load_async(listener)
|
||||
}
|
||||
|
||||
|
||||
/// Mark an in-progress network request complete.
|
||||
pub fn finish_load(&mut self, load: LoadType) {
|
||||
let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == load);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue