mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
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.
This commit is contained in:
parent
cff0f01c70
commit
44c80d5b18
7 changed files with 3 additions and 43 deletions
|
@ -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"
|
||||
|
|
|
@ -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!("<Network Error>")));
|
||||
*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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -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)",
|
||||
|
|
1
ports/cef/Cargo.lock
generated
1
ports/cef/Cargo.lock
generated
|
@ -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)",
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
[mime_sniffing_font_context.html]
|
||||
type: testharness
|
||||
prefs: [network.mime.sniff:true]
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue