mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Resolves #4183 - Implemementing context-based MIME type sniffing
The version of the standard is not finalized at the time of this writing. Specifications may be found here: https://mimesniff.spec.whatwg.org/#context-specific-sniffing .
This commit is contained in:
parent
66c8aa8cda
commit
1e81b8c133
18 changed files with 226 additions and 93 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::AsyncResponseTarget;
|
||||
use net_traits::{PendingAsyncLoad, ResourceTask};
|
||||
use net_traits::{PendingAsyncLoad, ResourceTask, LoadContext};
|
||||
use std::sync::Arc;
|
||||
use url::Url;
|
||||
|
||||
|
@ -30,6 +30,15 @@ impl LoadType {
|
|||
LoadType::PageSource(ref url) => url,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_load_context(&self) -> LoadContext {
|
||||
match *self {
|
||||
LoadType::Image(_) => LoadContext::Image,
|
||||
LoadType::Script(_) => LoadContext::Script,
|
||||
LoadType::Subframe(_) | LoadType::PageSource(_) => LoadContext::Browsing,
|
||||
LoadType::Stylesheet(_) => LoadContext::Style
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
|
@ -67,9 +76,10 @@ impl DocumentLoader {
|
|||
/// Create a new pending network request, which can be initiated at some point in
|
||||
/// the future.
|
||||
pub fn prepare_async_load(&mut self, load: LoadType) -> PendingAsyncLoad {
|
||||
let context = load.to_load_context();
|
||||
let url = load.url().clone();
|
||||
self.blocking_loads.push(load);
|
||||
PendingAsyncLoad::new((*self.resource_task).clone(), url, self.pipeline)
|
||||
PendingAsyncLoad::new(context, (*self.resource_task).clone(), url, self.pipeline)
|
||||
}
|
||||
|
||||
/// Create and initiate a new network request.
|
||||
|
@ -78,7 +88,6 @@ impl DocumentLoader {
|
|||
pending.load_async(listener)
|
||||
}
|
||||
|
||||
|
||||
/// Mark an in-progress network request complete.
|
||||
pub fn finish_load(&mut self, load: LoadType) {
|
||||
let idx = self.blocking_loads.iter().position(|unfinished| *unfinished == load);
|
||||
|
|
|
@ -26,7 +26,7 @@ use js::jsapi::{JSAutoCompartment, JSAutoRequest};
|
|||
use js::jsval::UndefinedValue;
|
||||
use js::rust::Runtime;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::load_whole_resource;
|
||||
use net_traits::{LoadContext, load_whole_resource};
|
||||
use rand::random;
|
||||
use script_task::ScriptTaskEventCategory::WorkerEvent;
|
||||
use script_task::{ScriptTask, ScriptChan, ScriptPort, StackRootTLS, CommonScriptMsg};
|
||||
|
@ -220,7 +220,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
let roots = RootCollection::new();
|
||||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
|
||||
let (url, source) = match load_whole_resource(&init.resource_task, worker_url, None) {
|
||||
let (url, source) = match load_whole_resource(LoadContext::Script, &init.resource_task, worker_url, None) {
|
||||
Err(_) => {
|
||||
println!("error loading script {}", serialized_worker_url);
|
||||
parent_sender.send(CommonScriptMsg::RunnableMsg(WorkerEvent,
|
||||
|
|
|
@ -21,7 +21,7 @@ use ipc_channel::ipc::IpcSender;
|
|||
use js::jsapi::{HandleValue, JSAutoRequest, JSContext};
|
||||
use js::rust::Runtime;
|
||||
use msg::constellation_msg::{ConstellationChan, PipelineId};
|
||||
use net_traits::{ResourceTask, load_whole_resource};
|
||||
use net_traits::{LoadContext, ResourceTask, load_whole_resource};
|
||||
use profile_traits::mem;
|
||||
use script_task::{CommonScriptMsg, ScriptChan, ScriptPort};
|
||||
use script_traits::ScriptMsg as ConstellationMsg;
|
||||
|
@ -203,7 +203,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
|||
}
|
||||
|
||||
for url in urls {
|
||||
let (url, source) = match load_whole_resource(&self.resource_task, url, None) {
|
||||
let (url, source) = match load_whole_resource(LoadContext::Script, &self.resource_task, url, None) {
|
||||
Err(_) => return Err(Error::Network),
|
||||
Ok((metadata, bytes)) => {
|
||||
(metadata.final_url, String::from_utf8(bytes).unwrap())
|
||||
|
|
|
@ -46,7 +46,7 @@ use js::jsapi::{JSContext, JS_ParseJSON, RootedValue};
|
|||
use js::jsval::{JSVal, NullValue, UndefinedValue};
|
||||
use net_traits::ControlMsg::Load;
|
||||
use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata};
|
||||
use net_traits::{LoadConsumer, LoadData, ResourceCORSData, ResourceTask};
|
||||
use net_traits::{LoadConsumer, LoadContext, LoadData, ResourceCORSData, ResourceTask};
|
||||
use network_listener::{NetworkListener, PreInvoke};
|
||||
use parse::html::{ParseContext, parse_html};
|
||||
use parse::xml::{self, parse_xml};
|
||||
|
@ -521,7 +521,10 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
|
||||
let global = self.global.root();
|
||||
let pipeline_id = global.r().pipeline();
|
||||
let mut load_data = LoadData::new(self.request_url.borrow().clone().unwrap(), Some(pipeline_id));
|
||||
let mut load_data =
|
||||
LoadData::new(LoadContext::Browsing,
|
||||
self.request_url.borrow().clone().unwrap(),
|
||||
Some(pipeline_id));
|
||||
if load_data.url.origin().ne(&global.r().get_url().origin()) {
|
||||
load_data.credentials_flag = self.WithCredentials();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ use msg::webdriver_msg::WebDriverScriptCommand;
|
|||
use net_traits::LoadData as NetLoadData;
|
||||
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheResult, ImageCacheTask};
|
||||
use net_traits::storage_task::StorageTask;
|
||||
use net_traits::{AsyncResponseTarget, ControlMsg, LoadConsumer, Metadata, ResourceTask};
|
||||
use net_traits::{AsyncResponseTarget, ControlMsg, LoadConsumer, LoadContext, Metadata, ResourceTask};
|
||||
use network_listener::NetworkListener;
|
||||
use page::{Frame, IterablePage, Page};
|
||||
use parse::html::{ParseContext, parse_html};
|
||||
|
@ -2003,6 +2003,7 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
resource_task.send(ControlMsg::Load(NetLoadData {
|
||||
context: LoadContext::Browsing,
|
||||
url: load_data.url,
|
||||
method: load_data.method,
|
||||
headers: Headers::new(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue