From 44c80d5b188311e61e0da06f646b688a6dcb1dbf Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 26 Oct 2016 16:42:10 +0200 Subject: [PATCH] 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. --- components/gfx/Cargo.toml | 1 - components/gfx/font_cache_thread.rs | 37 +------------------ components/gfx/lib.rs | 1 - components/servo/Cargo.lock | 1 - ports/cef/Cargo.lock | 1 - .../mime_sniffing_font_context.html.ini | 1 - .../mozilla/mime_sniffing_font_context.html | 4 +- 7 files changed, 3 insertions(+), 43 deletions(-) diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml index cc008dc6e87..035e24b37b0 100644 --- a/components/gfx/Cargo.toml +++ b/components/gfx/Cargo.toml @@ -25,7 +25,6 @@ ipc-channel = "0.5" lazy_static = "0.2" libc = "0.2" log = "0.3.5" -mime = "0.2" msg = {path = "../msg"} net_traits = {path = "../net_traits"} ordered-float = "0.2.2" diff --git a/components/gfx/font_cache_thread.rs b/components/gfx/font_cache_thread.rs index e921f41fcf9..e469cf6dfaa 100644 --- a/components/gfx/font_cache_thread.rs +++ b/components/gfx/font_cache_thread.rs @@ -6,7 +6,6 @@ use font_template::{FontTemplate, FontTemplateDescriptor}; use fontsan; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use ipc_channel::router::ROUTER; -use mime::{TopLevel, SubLevel}; use net_traits::{AsyncResponseTarget, LoadContext, CoreResourceThread, ResponseAction, load_async}; use platform::font_context::FontContextHandle; use platform::font_list::SANS_SERIF_FONT_FAMILY; @@ -25,7 +24,6 @@ use string_cache::Atom; use style::font_face::{EffectiveSources, Source}; use style::properties::longhands::font_family::computed_value::FontFamily; use url::Url; -use util::prefs::PREFS; use util::thread::spawn_named; use webrender_traits; @@ -227,21 +225,7 @@ impl FontCache { let response: ResponseAction = message.to().unwrap(); match response { 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).0, &mime.1) - }) - } - Err(_) => false, - }; - - info!("{} font with MIME type {}", - if is_response_valid { "Loading" } else { "Ignoring" }, - meta_result.map(|ref meta| format!("{:?}", meta.content_type)) - .unwrap_or(format!(""))); - *response_valid.lock().unwrap() = is_response_valid; + *response_valid.lock().unwrap() = meta_result.is_ok(); } ResponseAction::DataAvailable(new_bytes) => { if *response_valid.lock().unwrap() { @@ -480,25 +464,6 @@ impl FontCacheThread { } } -// derived from http://stackoverflow.com/a/10864297/3830 -fn is_supported_font_type(toplevel: &TopLevel, sublevel: &SubLevel) -> bool { - if !PREFS.get("network.mime.sniff").as_boolean().unwrap_or(false) { - return true; - } - - match (toplevel, sublevel) { - (&TopLevel::Application, &SubLevel::Ext(ref ext)) => { - match &ext[..] { - //FIXME: once sniffing is enabled by default, we shouldn't need nonstandard - // MIME types here. - "font-sfnt" | "x-font-ttf" | "x-font-truetype" | "x-font-opentype" => true, - _ => false, - } - } - _ => false, - } -} - #[derive(Clone, Eq, PartialEq, Hash, Debug, Deserialize, Serialize)] pub struct LowercaseString { diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index 01cb4da8689..5f831715f29 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -62,7 +62,6 @@ extern crate lazy_static; extern crate libc; #[macro_use] extern crate log; -extern crate mime; extern crate msg; extern crate net_traits; extern crate ordered_float; diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 1cb8805264c..240cd6170da 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -794,7 +794,6 @@ dependencies = [ "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", "ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index e077a916134..47af71d1852 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -710,7 +710,6 @@ dependencies = [ "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", "ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/tests/wpt/mozilla/meta/mozilla/mime_sniffing_font_context.html.ini b/tests/wpt/mozilla/meta/mozilla/mime_sniffing_font_context.html.ini index 567ecfaa9cf..f58ef7e15c7 100644 --- a/tests/wpt/mozilla/meta/mozilla/mime_sniffing_font_context.html.ini +++ b/tests/wpt/mozilla/meta/mozilla/mime_sniffing_font_context.html.ini @@ -1,3 +1,2 @@ [mime_sniffing_font_context.html] type: testharness - prefs: [network.mime.sniff:true] diff --git a/tests/wpt/mozilla/tests/mozilla/mime_sniffing_font_context.html b/tests/wpt/mozilla/tests/mozilla/mime_sniffing_font_context.html index 8112a99f431..2182b7fcbd8 100644 --- a/tests/wpt/mozilla/tests/mozilla/mime_sniffing_font_context.html +++ b/tests/wpt/mozilla/tests/mozilla/mime_sniffing_font_context.html @@ -51,8 +51,8 @@ async_test(function() { var xhr = new XMLHttpRequest(); xhr.open('GET', 'resources/no_mime_type.py?Content-Type=application/xhtml%2Bxml', true); xhr.onload = this.step_func_done(function() { - t4.step_timeout(checkFontNotLoaded.bind(t4, 'fifth', 'sixth'), 500); assert_equals(xhr.getResponseHeader('Content-Type'), 'application/xhtml+xml'); + t4.step_timeout(checkFontLoaded, 500); }); xhr.send(); }, "XHR Content-Type has xhtml+xml"); @@ -61,8 +61,8 @@ async_test(function() { var xhr = new XMLHttpRequest(); xhr.open('GET', 'resources/no_mime_type.py?Content-Type=application/xml', true); xhr.onload = this.step_func_done(function() { - t3.step_timeout(checkFontNotLoaded.bind(t3, 'third', 'fourth'), 500); assert_equals(xhr.getResponseHeader('Content-Type'), 'application/xml'); + t3.step_timeout(checkFontLoaded, 500); }); xhr.send(); }, "XHR Content-Type has xml");