Auto merge of #14588 - servo:log-font-face, r=jdm

Add logging to font-face loading.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14588)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-12-14 21:29:10 -08:00 committed by GitHub
commit d03039757c

View file

@ -18,6 +18,7 @@ use servo_atoms::Atom;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt;
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -222,31 +223,36 @@ impl FontCache {
let channel_to_self = self.channel_to_self.clone(); let channel_to_self = self.channel_to_self.clone();
let bytes = Mutex::new(Vec::new()); let bytes = Mutex::new(Vec::new());
let response_valid = Mutex::new(false); let response_valid = Mutex::new(false);
debug!("Loading @font-face {} from {}", family_name, url);
fetch_async(request, &self.core_resource_thread, move |response| { fetch_async(request, &self.core_resource_thread, move |response| {
match response { match response {
FetchResponseMsg::ProcessRequestBody | FetchResponseMsg::ProcessRequestBody |
FetchResponseMsg::ProcessRequestEOF => (), FetchResponseMsg::ProcessRequestEOF => (),
FetchResponseMsg::ProcessResponse(meta_result) => { FetchResponseMsg::ProcessResponse(meta_result) => {
trace!("@font-face {} metadata ok={:?}", family_name, meta_result.is_ok());
*response_valid.lock().unwrap() = meta_result.is_ok(); *response_valid.lock().unwrap() = meta_result.is_ok();
} }
FetchResponseMsg::ProcessResponseChunk(new_bytes) => { FetchResponseMsg::ProcessResponseChunk(new_bytes) => {
trace!("@font-face {} chunk={:?}", family_name, new_bytes);
if *response_valid.lock().unwrap() { if *response_valid.lock().unwrap() {
bytes.lock().unwrap().extend(new_bytes.into_iter()) bytes.lock().unwrap().extend(new_bytes.into_iter())
} }
} }
FetchResponseMsg::ProcessResponseEOF(response) => { FetchResponseMsg::ProcessResponseEOF(response) => {
trace!("@font-face {} EOF={:?}", family_name, response);
if response.is_err() || !*response_valid.lock().unwrap() { if response.is_err() || !*response_valid.lock().unwrap() {
let msg = Command::AddWebFont(family_name.clone(), sources.clone(), sender.clone()); let msg = Command::AddWebFont(family_name.clone(), sources.clone(), sender.clone());
channel_to_self.send(msg).unwrap(); channel_to_self.send(msg).unwrap();
return; return;
} }
let bytes = mem::replace(&mut *bytes.lock().unwrap(), vec![]); let bytes = mem::replace(&mut *bytes.lock().unwrap(), vec![]);
trace!("@font-face {} data={:?}", family_name, bytes);
let bytes = match fontsan::process(&bytes) { let bytes = match fontsan::process(&bytes) {
Ok(san) => san, Ok(san) => san,
Err(_) => { Err(_) => {
// FIXME(servo/fontsan#1): get an error message // FIXME(servo/fontsan#1): get an error message
debug!("Sanitiser rejected web font: \ debug!("Sanitiser rejected web font: \
family={:?} url={:?}", family_name, url); family={} url={:?}", family_name, url);
let msg = Command::AddWebFont(family_name.clone(), sources.clone(), sender.clone()); let msg = Command::AddWebFont(family_name.clone(), sources.clone(), sender.clone());
channel_to_self.send(msg).unwrap(); channel_to_self.send(msg).unwrap();
return; return;
@ -488,3 +494,9 @@ impl Deref for LowercaseString {
&*self.inner &*self.inner
} }
} }
impl fmt::Display for LowercaseString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.fmt(f)
}
}