Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving the error handling out of network loader... #8851

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -173,15 +173,21 @@ impl FontCache {
ROUTER.add_route(data_receiver.to_opaque(), box move |message| {
let response: ResponseAction = message.to().unwrap();
match response {
ResponseAction::HeadersAvailable(metadata) => {
let is_response_valid =
metadata.content_type.as_ref().map_or(false, |content_type| {
let mime = &content_type.0;
is_supported_font_type(&mime.0, &mime.1)
});
info!("{} font with MIME type {:?}",
ResponseAction::HeadersAvailable(meta_result) => {
let is_response_valid = match meta_result {
Ok(ref metadata) => {
metadata.content_type.as_ref().map_or(false, |content_type| {
let mime = &content_type.0;
is_supported_font_type(&mime.0, &mime.1)
})
}
Err(_) => false,
};

info!("{} font with MIME type {}",
if is_response_valid { "Loading" } else { "Ignoring" },
metadata.content_type);
meta_result.map(|ref meta| format!("{:?}", meta.content_type))
.unwrap_or(format!("<Network Error>")));
*response_valid.lock().unwrap() = is_response_valid;
}
ResponseAction::DataAvailable(new_bytes) => {
@@ -9,12 +9,19 @@ use hyper::mime::{Mime, SubLevel, TopLevel};
use mime_classifier::MIMEClassifier;
use net_traits::ProgressMsg::Done;
use net_traits::response::HttpsState;
use net_traits::{LoadConsumer, LoadData, Metadata};
use net_traits::{LoadConsumer, LoadData, Metadata, NetworkError};
use resource_thread::{CancellationListener, send_error, start_sending_sniffed_opt};
use std::sync::Arc;
use url::Url;
use util::resource_files::resources_dir_path;

fn url_from_non_relative_scheme(load_data: &mut LoadData, filename: &str) {
let mut path = resources_dir_path();
path.push(filename);
assert!(path.exists());
load_data.url = Url::from_file_path(&*path).unwrap();
}

pub fn factory(mut load_data: LoadData,
start_chan: LoadConsumer,
classifier: Arc<MIMEClassifier>,
@@ -41,15 +48,11 @@ pub fn factory(mut load_data: LoadData,
return
}
"crash" => panic!("Loading the about:crash URL."),
"failure" | "not-found" => {
let mut path = resources_dir_path();
let file_name = non_relative_scheme_data.to_owned() + ".html";
path.push(&file_name);
assert!(path.exists());
load_data.url = Url::from_file_path(&*path).unwrap();
}
"failure" | "not-found" =>
url_from_non_relative_scheme(&mut load_data, &(non_relative_scheme_data.to_owned() + ".html")),
"sslfail" => url_from_non_relative_scheme(&mut load_data, "badcert.html"),
_ => {
send_error(load_data.url, "Unknown about: URL.".to_owned(), start_chan);
send_error(load_data.url, NetworkError::Internal("Unknown about: URL.".to_owned()), start_chan);
return
}
};
@@ -5,7 +5,7 @@
use hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
use mime_classifier::MIMEClassifier;
use net_traits::ProgressMsg::{Done, Payload};
use net_traits::{LoadConsumer, LoadData, Metadata};
use net_traits::{LoadConsumer, LoadData, Metadata, NetworkError};
use resource_thread::{CancellationListener, send_error, start_sending_sniffed_opt};
use rustc_serialize::base64::FromBase64;
use std::sync::Arc;
@@ -44,7 +44,7 @@ pub fn load(load_data: LoadData,
}
let parts: Vec<&str> = scheme_data.splitn(2, ',').collect();
if parts.len() != 2 {
send_error(url, "invalid data uri".to_owned(), start_chan);
send_error(url, NetworkError::Internal("Invalid Data URI".to_owned()), start_chan);
return;
}

@@ -79,7 +79,7 @@ pub fn load(load_data: LoadData,
// but Acid 3 apparently depends on spaces being ignored.
let bytes = bytes.into_iter().filter(|&b| b != ' ' as u8).collect::<Vec<u8>>();
match bytes.from_base64() {
Err(..) => return send_error(url, "non-base64 data uri".to_owned(), start_chan),
Err(..) => return send_error(url, NetworkError::Internal("Non-Base64 Data URI".to_owned()), start_chan),
Ok(data) => data,
}
} else {
@@ -6,7 +6,7 @@ use about_loader;
use mime_classifier::MIMEClassifier;
use mime_guess::guess_mime_type;
use net_traits::ProgressMsg::{Done, Payload};
use net_traits::{LoadConsumer, LoadData, Metadata};
use net_traits::{LoadConsumer, LoadData, Metadata, NetworkError};
use resource_thread::{CancellationListener, ProgressSender};
use resource_thread::{send_error, start_sending_sniffed_opt};
use std::borrow::ToOwned;
@@ -46,7 +46,7 @@ fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener:
-> Result<LoadResult, String> {
loop {
if cancel_listener.is_cancelled() {
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
let _ = progress_chan.send(Done(Err(NetworkError::Internal("load cancelled".to_owned()))));
return Ok(LoadResult::Cancelled);
}

@@ -80,7 +80,9 @@ pub fn factory(load_data: LoadData,
if cancel_listener.is_cancelled() {
if let Ok(progress_chan) = get_progress_chan(load_data, file_path,
senders, classifier, &[]) {
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
let _ = progress_chan.send(
Done(Err(NetworkError::Internal("load cancelled".to_owned())))
);
}
return;
}
@@ -104,7 +106,7 @@ pub fn factory(load_data: LoadData,
}
}
Err(e) => {
send_error(load_data.url, e, senders);
send_error(load_data.url, NetworkError::Internal(e), senders);
}
};
}
@@ -119,7 +121,7 @@ pub fn factory(load_data: LoadData,
}
}
Err(_) => {
send_error(load_data.url, "Could not parse path".to_owned(), senders);
send_error(load_data.url, NetworkError::Internal("Could not parse path".to_owned()), senders);
}
}
});
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.