diff options
author | David Rajchenbach-Teller <D.O.Teller@gmail.com> | 2015-09-30 12:22:00 +0200 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-12-31 07:45:03 -0500 |
commit | 1e81b8c13322deed21bdfea83b8a4f8c78b50e04 (patch) | |
tree | c994a88564692926b3e2dd07affd37b360b37738 /components/script/document_loader.rs | |
parent | 66c8aa8cdac24ad956be5e99be3b7bc07c5f798c (diff) | |
download | servo-1e81b8c13322deed21bdfea83b8a4f8c78b50e04.tar.gz servo-1e81b8c13322deed21bdfea83b8a4f8c78b50e04.zip |
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 .
Diffstat (limited to 'components/script/document_loader.rs')
-rw-r--r-- | components/script/document_loader.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/components/script/document_loader.rs b/components/script/document_loader.rs index 00906af0c05..f5e49c46785 100644 --- a/components/script/document_loader.rs +++ b/components/script/document_loader.rs @@ -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); |