mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Rename MIMEClassifier
to match Rust acronym naming conventions.
e.g. `std::net::TcpStream`
This commit is contained in:
parent
749fe986aa
commit
6c02a576cf
11 changed files with 46 additions and 46 deletions
|
@ -6,7 +6,7 @@ use file_loader;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
use hyper::http::RawStatus;
|
use hyper::http::RawStatus;
|
||||||
use hyper::mime::{Mime, SubLevel, TopLevel};
|
use hyper::mime::{Mime, SubLevel, TopLevel};
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MimeClassifier;
|
||||||
use net_traits::ProgressMsg::Done;
|
use net_traits::ProgressMsg::Done;
|
||||||
use net_traits::response::HttpsState;
|
use net_traits::response::HttpsState;
|
||||||
use net_traits::{LoadConsumer, LoadData, Metadata, NetworkError};
|
use net_traits::{LoadConsumer, LoadData, Metadata, NetworkError};
|
||||||
|
@ -24,7 +24,7 @@ fn url_from_non_relative_scheme(load_data: &mut LoadData, filename: &str) {
|
||||||
|
|
||||||
pub fn factory(mut load_data: LoadData,
|
pub fn factory(mut load_data: LoadData,
|
||||||
start_chan: LoadConsumer,
|
start_chan: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
cancel_listener: CancellationListener) {
|
cancel_listener: CancellationListener) {
|
||||||
let url = load_data.url.clone();
|
let url = load_data.url.clone();
|
||||||
match url.path() {
|
match url.path() {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use hyper::header::{DispositionType, ContentDisposition, DispositionParam};
|
||||||
use hyper::header::{Headers, ContentType, ContentLength, Charset};
|
use hyper::header::{Headers, ContentType, ContentLength, Charset};
|
||||||
use hyper::http::RawStatus;
|
use hyper::http::RawStatus;
|
||||||
use mime::{Mime, Attr};
|
use mime::{Mime, Attr};
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MimeClassifier;
|
||||||
use net_traits::ProgressMsg::Done;
|
use net_traits::ProgressMsg::Done;
|
||||||
use net_traits::blob_url_store::{parse_blob_url, BlobURLStoreEntry, BlobURLStoreError};
|
use net_traits::blob_url_store::{parse_blob_url, BlobURLStoreEntry, BlobURLStoreError};
|
||||||
use net_traits::response::HttpsState;
|
use net_traits::response::HttpsState;
|
||||||
|
@ -22,7 +22,7 @@ use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
pub fn load(load_data: LoadData, consumer: LoadConsumer,
|
pub fn load(load_data: LoadData, consumer: LoadConsumer,
|
||||||
blob_url_store: Arc<RwLock<BlobURLStore>>,
|
blob_url_store: Arc<RwLock<BlobURLStore>>,
|
||||||
classifier: Arc<MIMEClassifier>) { // XXX: Move it into net process later
|
classifier: Arc<MimeClassifier>) { // XXX: Move it into net process later
|
||||||
|
|
||||||
match parse_blob_url(&load_data.url) {
|
match parse_blob_url(&load_data.url) {
|
||||||
None => {
|
None => {
|
||||||
|
@ -48,7 +48,7 @@ pub fn load(load_data: LoadData, consumer: LoadConsumer,
|
||||||
|
|
||||||
fn load_blob(load_data: &LoadData,
|
fn load_blob(load_data: &LoadData,
|
||||||
start_chan: LoadConsumer,
|
start_chan: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
entry: &BlobURLStoreEntry) {
|
entry: &BlobURLStoreEntry) {
|
||||||
let content_type: Mime = entry.type_string.parse().unwrap_or(mime!(Text / Plain));
|
let content_type: Mime = entry.type_string.parse().unwrap_or(mime!(Text / Plain));
|
||||||
let charset = content_type.get_param(Attr::Charset);
|
let charset = content_type.get_param(Attr::Charset);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use file_loader;
|
use file_loader;
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MimeClassifier;
|
||||||
use net_traits::{LoadConsumer, LoadData, NetworkError};
|
use net_traits::{LoadConsumer, LoadData, NetworkError};
|
||||||
use resource_thread::{CancellationListener, send_error};
|
use resource_thread::{CancellationListener, send_error};
|
||||||
use std::fs::canonicalize;
|
use std::fs::canonicalize;
|
||||||
|
@ -37,7 +37,7 @@ pub fn resolve_chrome_url(url: &Url) -> Result<Url, ()> {
|
||||||
|
|
||||||
pub fn factory(mut load_data: LoadData,
|
pub fn factory(mut load_data: LoadData,
|
||||||
start_chan: LoadConsumer,
|
start_chan: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
cancel_listener: CancellationListener) {
|
cancel_listener: CancellationListener) {
|
||||||
let file_url = match resolve_chrome_url(&load_data.url) {
|
let file_url = match resolve_chrome_url(&load_data.url) {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
|
use hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MimeClassifier;
|
||||||
use net_traits::LoadConsumer;
|
use net_traits::LoadConsumer;
|
||||||
use net_traits::ProgressMsg::{Payload, Done};
|
use net_traits::ProgressMsg::{Payload, Done};
|
||||||
use net_traits::{LoadData, Metadata, NetworkError};
|
use net_traits::{LoadData, Metadata, NetworkError};
|
||||||
|
@ -15,7 +15,7 @@ use url::{Position, Url};
|
||||||
|
|
||||||
pub fn factory(load_data: LoadData,
|
pub fn factory(load_data: LoadData,
|
||||||
senders: LoadConsumer,
|
senders: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
cancel_listener: CancellationListener) {
|
cancel_listener: CancellationListener) {
|
||||||
// NB: we don't spawn a new thread.
|
// NB: we don't spawn a new thread.
|
||||||
// Hypothesis: data URLs are too small for parallel base64 etc. to be worth it.
|
// Hypothesis: data URLs are too small for parallel base64 etc. to be worth it.
|
||||||
|
@ -72,7 +72,7 @@ pub fn decode(url: &Url) -> Result<DecodeData, DecodeError> {
|
||||||
|
|
||||||
pub fn load(load_data: LoadData,
|
pub fn load(load_data: LoadData,
|
||||||
start_chan: LoadConsumer,
|
start_chan: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
cancel_listener: CancellationListener) {
|
cancel_listener: CancellationListener) {
|
||||||
let url = load_data.url;
|
let url = load_data.url;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use about_loader;
|
use about_loader;
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MimeClassifier;
|
||||||
use mime_guess::guess_mime_type;
|
use mime_guess::guess_mime_type;
|
||||||
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
||||||
use net_traits::ProgressMsg::{Done, Payload};
|
use net_traits::ProgressMsg::{Done, Payload};
|
||||||
|
@ -72,7 +72,7 @@ fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_progress_chan(load_data: LoadData, file_path: PathBuf,
|
fn get_progress_chan(load_data: LoadData, file_path: PathBuf,
|
||||||
senders: LoadConsumer, classifier: Arc<MIMEClassifier>, buf: &[u8])
|
senders: LoadConsumer, classifier: Arc<MimeClassifier>, buf: &[u8])
|
||||||
-> Result<ProgressSender, ()> {
|
-> Result<ProgressSender, ()> {
|
||||||
let mut metadata = Metadata::default(load_data.url);
|
let mut metadata = Metadata::default(load_data.url);
|
||||||
let mime_type = guess_mime_type(file_path.as_path());
|
let mime_type = guess_mime_type(file_path.as_path());
|
||||||
|
@ -82,7 +82,7 @@ fn get_progress_chan(load_data: LoadData, file_path: PathBuf,
|
||||||
|
|
||||||
pub fn factory(load_data: LoadData,
|
pub fn factory(load_data: LoadData,
|
||||||
senders: LoadConsumer,
|
senders: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
cancel_listener: CancellationListener) {
|
cancel_listener: CancellationListener) {
|
||||||
assert!(load_data.url.scheme() == "file");
|
assert!(load_data.url.scheme() == "file");
|
||||||
spawn_named("file_loader".to_owned(), move || {
|
spawn_named("file_loader".to_owned(), move || {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use blob_loader;
|
use blob_loader;
|
||||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MimeClassifier;
|
||||||
use mime_guess::guess_mime_type_opt;
|
use mime_guess::guess_mime_type_opt;
|
||||||
use net_traits::blob_url_store::{BlobURLStoreEntry, BlobURLStoreError, BlobURLStoreMsg};
|
use net_traits::blob_url_store::{BlobURLStoreEntry, BlobURLStoreError, BlobURLStoreMsg};
|
||||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerResult, FilterPattern};
|
use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerResult, FilterPattern};
|
||||||
|
@ -90,7 +90,7 @@ impl<UI: 'static + UIProvider> FileManagerThreadFactory<UI> for IpcSender<FileMa
|
||||||
struct FileManager<UI: 'static + UIProvider> {
|
struct FileManager<UI: 'static + UIProvider> {
|
||||||
receiver: IpcReceiver<FileManagerThreadMsg>,
|
receiver: IpcReceiver<FileManagerThreadMsg>,
|
||||||
idmap: HashMap<Uuid, PathBuf>,
|
idmap: HashMap<Uuid, PathBuf>,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
blob_url_store: Arc<RwLock<BlobURLStore>>,
|
blob_url_store: Arc<RwLock<BlobURLStore>>,
|
||||||
ui: &'static UI,
|
ui: &'static UI,
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ impl<UI: 'static + UIProvider> FileManager<UI> {
|
||||||
FileManager {
|
FileManager {
|
||||||
receiver: recv,
|
receiver: recv,
|
||||||
idmap: HashMap::new(),
|
idmap: HashMap::new(),
|
||||||
classifier: Arc::new(MIMEClassifier::new()),
|
classifier: Arc::new(MimeClassifier::new()),
|
||||||
blob_url_store: Arc::new(RwLock::new(BlobURLStore::new())),
|
blob_url_store: Arc::new(RwLock::new(BlobURLStore::new())),
|
||||||
ui: ui
|
ui: ui
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ use hyper::net::Fresh;
|
||||||
use hyper::status::{StatusClass, StatusCode};
|
use hyper::status::{StatusClass, StatusCode};
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
use log;
|
use log;
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MimeClassifier;
|
||||||
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
||||||
use net_traits::ProgressMsg::{Done, Payload};
|
use net_traits::ProgressMsg::{Done, Payload};
|
||||||
use net_traits::hosts::replace_hosts;
|
use net_traits::hosts::replace_hosts;
|
||||||
|
@ -62,7 +62,7 @@ pub fn factory(user_agent: String,
|
||||||
connector: Arc<Pool<Connector>>)
|
connector: Arc<Pool<Connector>>)
|
||||||
-> Box<FnBox(LoadData,
|
-> Box<FnBox(LoadData,
|
||||||
LoadConsumer,
|
LoadConsumer,
|
||||||
Arc<MIMEClassifier>,
|
Arc<MimeClassifier>,
|
||||||
CancellationListener) + Send> {
|
CancellationListener) + Send> {
|
||||||
box move |load_data: LoadData, senders, classifier, cancel_listener| {
|
box move |load_data: LoadData, senders, classifier, cancel_listener| {
|
||||||
spawn_named(format!("http_loader for {}", load_data.url), move || {
|
spawn_named(format!("http_loader for {}", load_data.url), move || {
|
||||||
|
@ -127,7 +127,7 @@ fn precise_time_ms() -> u64 {
|
||||||
|
|
||||||
fn load_for_consumer(load_data: LoadData,
|
fn load_for_consumer(load_data: LoadData,
|
||||||
start_chan: LoadConsumer,
|
start_chan: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
connector: Arc<Pool<Connector>>,
|
connector: Arc<Pool<Connector>>,
|
||||||
http_state: HttpState,
|
http_state: HttpState,
|
||||||
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||||
|
@ -1093,7 +1093,7 @@ fn send_data<R: Read>(context: LoadContext,
|
||||||
reader: &mut R,
|
reader: &mut R,
|
||||||
start_chan: LoadConsumer,
|
start_chan: LoadConsumer,
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MimeClassifier>,
|
||||||
cancel_listener: &CancellationListener) {
|
cancel_listener: &CancellationListener) {
|
||||||
let (progress_chan, mut chunk) = {
|
let (progress_chan, mut chunk) = {
|
||||||
let buf = match read_block(reader) {
|
let buf = match read_block(reader) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use net_traits::LoadContext;
|
use net_traits::LoadContext;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
|
||||||
pub struct MIMEClassifier {
|
pub struct MimeClassifier {
|
||||||
image_classifier: GroupedClassifier,
|
image_classifier: GroupedClassifier,
|
||||||
audio_video_classifier: GroupedClassifier,
|
audio_video_classifier: GroupedClassifier,
|
||||||
scriptable_classifier: GroupedClassifier,
|
scriptable_classifier: GroupedClassifier,
|
||||||
|
@ -50,7 +50,7 @@ pub enum NoSniffFlag {
|
||||||
|
|
||||||
pub type MimeType = (String, String);
|
pub type MimeType = (String, String);
|
||||||
|
|
||||||
impl MIMEClassifier {
|
impl MimeClassifier {
|
||||||
//Performs MIME Type Sniffing Algorithm (sections 7 and 8)
|
//Performs MIME Type Sniffing Algorithm (sections 7 and 8)
|
||||||
pub fn classify(&self,
|
pub fn classify(&self,
|
||||||
context: LoadContext,
|
context: LoadContext,
|
||||||
|
@ -66,14 +66,14 @@ impl MIMEClassifier {
|
||||||
None => self.sniff_unknown_type(no_sniff_flag, data),
|
None => self.sniff_unknown_type(no_sniff_flag, data),
|
||||||
Some(ref supplied_type) => {
|
Some(ref supplied_type) => {
|
||||||
let &(ref media_type, ref media_subtype) = supplied_type;
|
let &(ref media_type, ref media_subtype) = supplied_type;
|
||||||
if MIMEClassifier::is_explicit_unknown(media_type, media_subtype) {
|
if MimeClassifier::is_explicit_unknown(media_type, media_subtype) {
|
||||||
self.sniff_unknown_type(no_sniff_flag, data)
|
self.sniff_unknown_type(no_sniff_flag, data)
|
||||||
} else {
|
} else {
|
||||||
match no_sniff_flag {
|
match no_sniff_flag {
|
||||||
NoSniffFlag::ON => supplied_type.clone(),
|
NoSniffFlag::ON => supplied_type.clone(),
|
||||||
NoSniffFlag::OFF => match apache_bug_flag {
|
NoSniffFlag::OFF => match apache_bug_flag {
|
||||||
ApacheBugFlag::ON => self.sniff_text_or_data(data),
|
ApacheBugFlag::ON => self.sniff_text_or_data(data),
|
||||||
ApacheBugFlag::OFF => match MIMEClassifier::get_media_type(media_type,
|
ApacheBugFlag::OFF => match MimeClassifier::get_media_type(media_type,
|
||||||
media_subtype) {
|
media_subtype) {
|
||||||
Some(MediaType::Html) => self.feeds_classifier.classify(data),
|
Some(MediaType::Html) => self.feeds_classifier.classify(data),
|
||||||
Some(MediaType::Image) => self.image_classifier.classify(data),
|
Some(MediaType::Image) => self.image_classifier.classify(data),
|
||||||
|
@ -87,14 +87,14 @@ impl MIMEClassifier {
|
||||||
},
|
},
|
||||||
LoadContext::Image => {
|
LoadContext::Image => {
|
||||||
// Section 8.2 Sniffing an image context
|
// Section 8.2 Sniffing an image context
|
||||||
match MIMEClassifier::maybe_get_media_type(supplied_type) {
|
match MimeClassifier::maybe_get_media_type(supplied_type) {
|
||||||
Some(MediaType::Xml) => None,
|
Some(MediaType::Xml) => None,
|
||||||
_ => self.image_classifier.classify(data),
|
_ => self.image_classifier.classify(data),
|
||||||
}.unwrap_or(supplied_type_or_octet_stream)
|
}.unwrap_or(supplied_type_or_octet_stream)
|
||||||
},
|
},
|
||||||
LoadContext::AudioVideo => {
|
LoadContext::AudioVideo => {
|
||||||
// Section 8.3 Sniffing an image context
|
// Section 8.3 Sniffing an image context
|
||||||
match MIMEClassifier::maybe_get_media_type(supplied_type) {
|
match MimeClassifier::maybe_get_media_type(supplied_type) {
|
||||||
Some(MediaType::Xml) => None,
|
Some(MediaType::Xml) => None,
|
||||||
_ => self.audio_video_classifier.classify(data),
|
_ => self.audio_video_classifier.classify(data),
|
||||||
}.unwrap_or(supplied_type_or_octet_stream)
|
}.unwrap_or(supplied_type_or_octet_stream)
|
||||||
|
@ -131,7 +131,7 @@ impl MIMEClassifier {
|
||||||
},
|
},
|
||||||
LoadContext::Font => {
|
LoadContext::Font => {
|
||||||
// 8.7 Sniffing in a font context
|
// 8.7 Sniffing in a font context
|
||||||
match MIMEClassifier::maybe_get_media_type(supplied_type) {
|
match MimeClassifier::maybe_get_media_type(supplied_type) {
|
||||||
Some(MediaType::Xml) => None,
|
Some(MediaType::Xml) => None,
|
||||||
_ => self.font_classifier.classify(data),
|
_ => self.font_classifier.classify(data),
|
||||||
}.unwrap_or(supplied_type_or_octet_stream)
|
}.unwrap_or(supplied_type_or_octet_stream)
|
||||||
|
@ -153,8 +153,8 @@ impl MIMEClassifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> MIMEClassifier {
|
pub fn new() -> MimeClassifier {
|
||||||
MIMEClassifier {
|
MimeClassifier {
|
||||||
image_classifier: GroupedClassifier::image_classifer(),
|
image_classifier: GroupedClassifier::image_classifer(),
|
||||||
audio_video_classifier: GroupedClassifier::audio_video_classifier(),
|
audio_video_classifier: GroupedClassifier::audio_video_classifier(),
|
||||||
scriptable_classifier: GroupedClassifier::scriptable_classifier(),
|
scriptable_classifier: GroupedClassifier::scriptable_classifier(),
|
||||||
|
@ -232,13 +232,13 @@ impl MIMEClassifier {
|
||||||
|
|
||||||
fn get_media_type(media_type: &str,
|
fn get_media_type(media_type: &str,
|
||||||
media_subtype: &str) -> Option<MediaType> {
|
media_subtype: &str) -> Option<MediaType> {
|
||||||
if MIMEClassifier::is_xml(media_type, media_subtype) {
|
if MimeClassifier::is_xml(media_type, media_subtype) {
|
||||||
Some(MediaType::Xml)
|
Some(MediaType::Xml)
|
||||||
} else if MIMEClassifier::is_html(media_type, media_subtype) {
|
} else if MimeClassifier::is_html(media_type, media_subtype) {
|
||||||
Some(MediaType::Html)
|
Some(MediaType::Html)
|
||||||
} else if MIMEClassifier::is_image(media_type) {
|
} else if MimeClassifier::is_image(media_type) {
|
||||||
Some(MediaType::Image)
|
Some(MediaType::Image)
|
||||||
} else if MIMEClassifier::is_audio_video(media_type, media_subtype) {
|
} else if MimeClassifier::is_audio_video(media_type, media_subtype) {
|
||||||
Some(MediaType::AudioVideo)
|
Some(MediaType::AudioVideo)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -247,7 +247,7 @@ impl MIMEClassifier {
|
||||||
|
|
||||||
fn maybe_get_media_type(supplied_type: &Option<MimeType>) -> Option<MediaType> {
|
fn maybe_get_media_type(supplied_type: &Option<MimeType>) -> Option<MediaType> {
|
||||||
supplied_type.as_ref().and_then(|&(ref media_type, ref media_subtype)| {
|
supplied_type.as_ref().and_then(|&(ref media_type, ref media_subtype)| {
|
||||||
MIMEClassifier::get_media_type(media_type, media_subtype)
|
MimeClassifier::get_media_type(media_type, media_subtype)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use hyper::client::pool::Pool;
|
||||||
use hyper::header::{ContentType, Header, SetCookie};
|
use hyper::header::{ContentType, Header, SetCookie};
|
||||||
use hyper::mime::{Mime, SubLevel, TopLevel};
|
use hyper::mime::{Mime, SubLevel, TopLevel};
|
||||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender, IpcReceiverSet};
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender, IpcReceiverSet};
|
||||||
use mime_classifier::{ApacheBugFlag, MIMEClassifier, NoSniffFlag};
|
use mime_classifier::{ApacheBugFlag, MimeClassifier, NoSniffFlag};
|
||||||
use net_traits::LoadContext;
|
use net_traits::LoadContext;
|
||||||
use net_traits::ProgressMsg::Done;
|
use net_traits::ProgressMsg::Done;
|
||||||
use net_traits::filemanager_thread::FileManagerThreadMsg;
|
use net_traits::filemanager_thread::FileManagerThreadMsg;
|
||||||
|
@ -95,7 +95,7 @@ pub fn send_error(url: Url, err: NetworkError, start_chan: LoadConsumer) {
|
||||||
|
|
||||||
/// For use by loaders in responding to a Load message that allows content sniffing.
|
/// For use by loaders in responding to a Load message that allows content sniffing.
|
||||||
pub fn start_sending_sniffed(start_chan: LoadConsumer, metadata: Metadata,
|
pub fn start_sending_sniffed(start_chan: LoadConsumer, metadata: Metadata,
|
||||||
classifier: Arc<MIMEClassifier>, partial_body: &[u8],
|
classifier: Arc<MimeClassifier>, partial_body: &[u8],
|
||||||
context: LoadContext)
|
context: LoadContext)
|
||||||
-> ProgressSender {
|
-> ProgressSender {
|
||||||
start_sending_sniffed_opt(start_chan, metadata, classifier, partial_body, context).ok().unwrap()
|
start_sending_sniffed_opt(start_chan, metadata, classifier, partial_body, context).ok().unwrap()
|
||||||
|
@ -103,7 +103,7 @@ pub fn start_sending_sniffed(start_chan: LoadConsumer, metadata: Metadata,
|
||||||
|
|
||||||
/// For use by loaders in responding to a Load message that allows content sniffing.
|
/// For use by loaders in responding to a Load message that allows content sniffing.
|
||||||
pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadata,
|
pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadata,
|
||||||
classifier: Arc<MIMEClassifier>, partial_body: &[u8],
|
classifier: Arc<MimeClassifier>, partial_body: &[u8],
|
||||||
context: LoadContext)
|
context: LoadContext)
|
||||||
-> Result<ProgressSender, ()> {
|
-> Result<ProgressSender, ()> {
|
||||||
if prefs::get_pref("network.mime.sniff").as_boolean().unwrap_or(false) {
|
if prefs::get_pref("network.mime.sniff").as_boolean().unwrap_or(false) {
|
||||||
|
@ -459,7 +459,7 @@ pub struct AuthCache {
|
||||||
|
|
||||||
pub struct CoreResourceManager {
|
pub struct CoreResourceManager {
|
||||||
user_agent: String,
|
user_agent: String,
|
||||||
mime_classifier: Arc<MIMEClassifier>,
|
mime_classifier: Arc<MimeClassifier>,
|
||||||
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||||
profiler_chan: ProfilerChan,
|
profiler_chan: ProfilerChan,
|
||||||
cancel_load_map: HashMap<ResourceId, Sender<()>>,
|
cancel_load_map: HashMap<ResourceId, Sender<()>>,
|
||||||
|
@ -472,7 +472,7 @@ impl CoreResourceManager {
|
||||||
profiler_chan: ProfilerChan) -> CoreResourceManager {
|
profiler_chan: ProfilerChan) -> CoreResourceManager {
|
||||||
CoreResourceManager {
|
CoreResourceManager {
|
||||||
user_agent: user_agent,
|
user_agent: user_agent,
|
||||||
mime_classifier: Arc::new(MIMEClassifier::new()),
|
mime_classifier: Arc::new(MimeClassifier::new()),
|
||||||
devtools_chan: devtools_channel,
|
devtools_chan: devtools_channel,
|
||||||
profiler_chan: profiler_chan,
|
profiler_chan: profiler_chan,
|
||||||
cancel_load_map: HashMap::new(),
|
cancel_load_map: HashMap::new(),
|
||||||
|
@ -510,10 +510,10 @@ impl CoreResourceManager {
|
||||||
id_sender: Option<IpcSender<ResourceId>>,
|
id_sender: Option<IpcSender<ResourceId>>,
|
||||||
resource_thread: CoreResourceThread,
|
resource_thread: CoreResourceThread,
|
||||||
resource_grp: &ResourceGroup) {
|
resource_grp: &ResourceGroup) {
|
||||||
fn from_factory(factory: fn(LoadData, LoadConsumer, Arc<MIMEClassifier>, CancellationListener))
|
fn from_factory(factory: fn(LoadData, LoadConsumer, Arc<MimeClassifier>, CancellationListener))
|
||||||
-> Box<FnBox(LoadData,
|
-> Box<FnBox(LoadData,
|
||||||
LoadConsumer,
|
LoadConsumer,
|
||||||
Arc<MIMEClassifier>,
|
Arc<MimeClassifier>,
|
||||||
CancellationListener) + Send> {
|
CancellationListener) + Send> {
|
||||||
box move |load_data, senders, classifier, cancel_listener| {
|
box move |load_data, senders, classifier, cancel_listener| {
|
||||||
factory(load_data, senders, classifier, cancel_listener)
|
factory(load_data, senders, classifier, cancel_listener)
|
||||||
|
|
|
@ -36,12 +36,12 @@ fn assert_parse(url: &'static str,
|
||||||
charset: Option<String>,
|
charset: Option<String>,
|
||||||
data: Option<Vec<u8>>) {
|
data: Option<Vec<u8>>) {
|
||||||
use net::data_loader::load;
|
use net::data_loader::load;
|
||||||
use net::mime_classifier::MIMEClassifier;
|
use net::mime_classifier::MimeClassifier;
|
||||||
use net::resource_thread::CancellationListener;
|
use net::resource_thread::CancellationListener;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
let (start_chan, start_port) = ipc::channel().unwrap();
|
let (start_chan, start_port) = ipc::channel().unwrap();
|
||||||
let classifier = Arc::new(MIMEClassifier::new());
|
let classifier = Arc::new(MimeClassifier::new());
|
||||||
load(LoadData::new(LoadContext::Browsing, Url::parse(url).unwrap(), &DataLoadTest),
|
load(LoadData::new(LoadContext::Browsing, Url::parse(url).unwrap(), &DataLoadTest),
|
||||||
Channel(start_chan),
|
Channel(start_chan),
|
||||||
classifier, CancellationListener::new(None));
|
classifier, CancellationListener::new(None));
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use net::mime_classifier::as_string_option;
|
use net::mime_classifier::as_string_option;
|
||||||
use net::mime_classifier::{Mp4Matcher, MIMEClassifier, ApacheBugFlag, NoSniffFlag};
|
use net::mime_classifier::{Mp4Matcher, MimeClassifier, ApacheBugFlag, NoSniffFlag};
|
||||||
use net_traits::LoadContext;
|
use net_traits::LoadContext;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -52,7 +52,7 @@ fn test_sniff_mp4_matcher_long() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_validate_classifier() {
|
fn test_validate_classifier() {
|
||||||
let classifier = MIMEClassifier::new();
|
let classifier = MimeClassifier::new();
|
||||||
classifier.validate().expect("Validation error")
|
classifier.validate().expect("Validation error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ fn test_sniff_with_flags(filename_orig: &path::Path,
|
||||||
let mut filename = PathBuf::from("parsable_mime/");
|
let mut filename = PathBuf::from("parsable_mime/");
|
||||||
filename.push(filename_orig);
|
filename.push(filename_orig);
|
||||||
|
|
||||||
let classifier = MIMEClassifier::new();
|
let classifier = MimeClassifier::new();
|
||||||
|
|
||||||
let read_result = read_file(&filename);
|
let read_result = read_file(&filename);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue