Skip to content

Commit 4f02413

Browse files
committed
Ignore the Content-Type header completely for @font-face.
This matches the previous default (network.mime.sniff off) behaviour in all but one case: we will now accept a font without a `Content-Type` header, which would previously have been ignored.
1 parent ba2fb4e commit 4f02413

File tree

3 files changed

+3
-39
lines changed

3 files changed

+3
-39
lines changed

components/gfx/font_cache_thread.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use font_template::{FontTemplate, FontTemplateDescriptor};
66
use fontsan;
77
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
88
use ipc_channel::router::ROUTER;
9-
use mime::{TopLevel, SubLevel};
109
use net_traits::{AsyncResponseTarget, LoadContext, CoreResourceThread, ResponseAction, load_async};
1110
use platform::font_context::FontContextHandle;
1211
use platform::font_list::SANS_SERIF_FONT_FAMILY;
@@ -25,7 +24,6 @@ use string_cache::Atom;
2524
use style::font_face::{EffectiveSources, Source};
2625
use style::properties::longhands::font_family::computed_value::FontFamily;
2726
use url::Url;
28-
use util::prefs::PREFS;
2927
use util::thread::spawn_named;
3028
use webrender_traits;
3129

@@ -227,21 +225,7 @@ impl FontCache {
227225
let response: ResponseAction = message.to().unwrap();
228226
match response {
229227
ResponseAction::HeadersAvailable(meta_result) => {
230-
let is_response_valid = match meta_result {
231-
Ok(ref metadata) => {
232-
metadata.content_type.as_ref().map_or(false, |content_type| {
233-
let mime = &content_type.0;
234-
is_supported_font_type(&(mime.0).0, &mime.1)
235-
})
236-
}
237-
Err(_) => false,
238-
};
239-
240-
info!("{} font with MIME type {}",
241-
if is_response_valid { "Loading" } else { "Ignoring" },
242-
meta_result.map(|ref meta| format!("{:?}", meta.content_type))
243-
.unwrap_or(format!("<Network Error>")));
244-
*response_valid.lock().unwrap() = is_response_valid;
228+
*response_valid.lock().unwrap() = meta_result.is_ok();
245229
}
246230
ResponseAction::DataAvailable(new_bytes) => {
247231
if *response_valid.lock().unwrap() {
@@ -480,25 +464,6 @@ impl FontCacheThread {
480464
}
481465
}
482466

483-
// derived from http://stackoverflow.com/a/10864297/3830
484-
fn is_supported_font_type(toplevel: &TopLevel, sublevel: &SubLevel) -> bool {
485-
if !PREFS.get("network.mime.sniff").as_boolean().unwrap_or(false) {
486-
return true;
487-
}
488-
489-
match (toplevel, sublevel) {
490-
(&TopLevel::Application, &SubLevel::Ext(ref ext)) => {
491-
match &ext[..] {
492-
//FIXME: once sniffing is enabled by default, we shouldn't need nonstandard
493-
// MIME types here.
494-
"font-sfnt" | "x-font-ttf" | "x-font-truetype" | "x-font-opentype" => true,
495-
_ => false,
496-
}
497-
}
498-
_ => false,
499-
}
500-
}
501-
502467

503468
#[derive(Clone, Eq, PartialEq, Hash, Debug, Deserialize, Serialize)]
504469
pub struct LowercaseString {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[mime_sniffing_font_context.html]
22
type: testharness
3-
prefs: [network.mime.sniff:true]

tests/wpt/mozilla/tests/mozilla/mime_sniffing_font_context.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
var xhr = new XMLHttpRequest();
5252
xhr.open('GET', 'resources/no_mime_type.py?Content-Type=application/xhtml%2Bxml', true);
5353
xhr.onload = this.step_func_done(function() {
54-
t4.step_timeout(checkFontNotLoaded.bind(t4, 'fifth', 'sixth'), 500);
5554
assert_equals(xhr.getResponseHeader('Content-Type'), 'application/xhtml+xml');
55+
t4.step_timeout(checkFontLoaded, 500);
5656
});
5757
xhr.send();
5858
}, "XHR Content-Type has xhtml+xml");
@@ -61,8 +61,8 @@
6161
var xhr = new XMLHttpRequest();
6262
xhr.open('GET', 'resources/no_mime_type.py?Content-Type=application/xml', true);
6363
xhr.onload = this.step_func_done(function() {
64-
t3.step_timeout(checkFontNotLoaded.bind(t3, 'third', 'fourth'), 500);
6564
assert_equals(xhr.getResponseHeader('Content-Type'), 'application/xml');
65+
t3.step_timeout(checkFontLoaded, 500);
6666
});
6767
xhr.send();
6868
}, "XHR Content-Type has xml");

0 commit comments

Comments
 (0)