diff options
author | David Rajchenbach-Teller <D.O.Teller@gmail.com> | 2015-09-30 12:22:00 +0200 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-12-31 07:45:03 -0500 |
commit | 1e81b8c13322deed21bdfea83b8a4f8c78b50e04 (patch) | |
tree | c994a88564692926b3e2dd07affd37b360b37738 /components | |
parent | 66c8aa8cdac24ad956be5e99be3b7bc07c5f798c (diff) | |
download | servo-1e81b8c13322deed21bdfea83b8a4f8c78b50e04.tar.gz servo-1e81b8c13322deed21bdfea83b8a4f8c78b50e04.zip |
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 .
Diffstat (limited to 'components')
-rw-r--r-- | components/gfx/font_cache_task.rs | 5 | ||||
-rw-r--r-- | components/net/about_loader.rs | 6 | ||||
-rw-r--r-- | components/net/data_loader.rs | 6 | ||||
-rw-r--r-- | components/net/file_loader.rs | 8 | ||||
-rw-r--r-- | components/net/http_loader.rs | 12 | ||||
-rw-r--r-- | components/net/image_cache_task.rs | 5 | ||||
-rw-r--r-- | components/net/mime_classifier.rs | 127 | ||||
-rw-r--r-- | components/net/resource_task.rs | 14 | ||||
-rw-r--r-- | components/net_traits/lib.rs | 32 | ||||
-rw-r--r-- | components/script/document_loader.rs | 15 | ||||
-rw-r--r-- | components/script/dom/dedicatedworkerglobalscope.rs | 4 | ||||
-rw-r--r-- | components/script/dom/workerglobalscope.rs | 4 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 7 | ||||
-rw-r--r-- | components/script/script_task.rs | 3 |
14 files changed, 189 insertions, 59 deletions
diff --git a/components/gfx/font_cache_task.rs b/components/gfx/font_cache_task.rs index 1056da7e730..5b6edcd51b6 100644 --- a/components/gfx/font_cache_task.rs +++ b/components/gfx/font_cache_task.rs @@ -5,7 +5,7 @@ use font_template::{FontTemplate, FontTemplateDescriptor}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use ipc_channel::router::ROUTER; -use net_traits::{AsyncResponseTarget, PendingAsyncLoad, ResourceTask, ResponseAction}; +use net_traits::{AsyncResponseTarget, LoadContext, PendingAsyncLoad, ResourceTask, ResponseAction}; use platform::font_context::FontContextHandle; use platform::font_list::for_each_available_family; use platform::font_list::for_each_variation; @@ -156,7 +156,8 @@ impl FontCache { match src { Source::Url(ref url_source) => { let url = &url_source.url; - let load = PendingAsyncLoad::new(self.resource_task.clone(), + let load = PendingAsyncLoad::new(LoadContext::Font, + self.resource_task.clone(), url.clone(), None); let (data_sender, data_receiver) = ipc::channel().unwrap(); diff --git a/components/net/about_loader.rs b/components/net/about_loader.rs index c81ecc49b87..af9b43bb6ce 100644 --- a/components/net/about_loader.rs +++ b/components/net/about_loader.rs @@ -29,7 +29,11 @@ pub fn factory(mut load_data: LoadData, headers: None, status: Some(RawStatus(200, "OK".into())), }; - if let Ok(chan) = start_sending_sniffed_opt(start_chan, metadata, classifier, &[]) { + if let Ok(chan) = start_sending_sniffed_opt(start_chan, + metadata, + classifier, + &[], + load_data.context) { let _ = chan.send(Done(Ok(()))); } return diff --git a/components/net/data_loader.rs b/components/net/data_loader.rs index b7fb25c124d..3c3bcaa10c5 100644 --- a/components/net/data_loader.rs +++ b/components/net/data_loader.rs @@ -88,7 +88,11 @@ pub fn load(load_data: LoadData, let mut metadata = Metadata::default(url); metadata.set_content_type(content_type.as_ref()); - if let Ok(chan) = start_sending_sniffed_opt(start_chan, metadata, classifier, &bytes) { + if let Ok(chan) = start_sending_sniffed_opt(start_chan, + metadata, + classifier, + &bytes, + load_data.context) { let _ = chan.send(Payload(bytes)); let _ = chan.send(Done(Ok(()))); } diff --git a/components/net/file_loader.rs b/components/net/file_loader.rs index 8b0a287c4a1..c2ab9cce9c7 100644 --- a/components/net/file_loader.rs +++ b/components/net/file_loader.rs @@ -61,6 +61,7 @@ pub fn factory(load_data: LoadData, classifier: Arc<MIMEClassifier>, cancel_listener: CancellationListener) { let url = load_data.url; + let context = load_data.context; assert!(&*url.scheme == "file"); spawn_named("file_loader".to_owned(), move || { let file_path: Result<PathBuf, ()> = url.to_file_path(); @@ -77,7 +78,7 @@ pub fn factory(load_data: LoadData, let mime_type = guess_mime_type(file_path.as_path()); metadata.set_content_type(Some(&mime_type)); let progress_chan = start_sending_sniffed(senders, metadata, - classifier, &buf); + classifier, &buf, context); progress_chan.send(Payload(buf)).unwrap(); let read_result = read_all(reader, &progress_chan, &cancel_listener); if let Ok(load_result) = read_result { @@ -94,7 +95,8 @@ pub fn factory(load_data: LoadData, if let Ok(chan) = start_sending_sniffed_opt(senders, metadata, classifier, - &[]) { + &[], + context) { let _ = chan.send(Done(Ok(()))); } } @@ -108,7 +110,7 @@ pub fn factory(load_data: LoadData, // http://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.open // but, we'll go for a "file not found!" let url = Url::parse("about:not-found").unwrap(); - let load_data_404 = LoadData::new(url, None); + let load_data_404 = LoadData::new(context, url, None); about_loader::factory(load_data_404, senders, classifier, cancel_listener) } } diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 3a64c959570..4c3ab2f8ccf 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -26,7 +26,7 @@ use mime_classifier::MIMEClassifier; use msg::constellation_msg::{PipelineId}; use net_traits::ProgressMsg::{Done, Payload}; use net_traits::hosts::replace_hosts; -use net_traits::{CookieSource, IncludeSubdomains, LoadConsumer, LoadData, Metadata}; +use net_traits::{CookieSource, IncludeSubdomains, LoadConsumer, LoadContext, LoadData, Metadata}; use openssl::ssl::error::{SslError, OpensslError}; use openssl::ssl::{SSL_OP_NO_SSLV2, SSL_OP_NO_SSLV3, SSL_VERIFY_PEER, SslContext, SslMethod}; use resource_task::{CancellationListener, send_error, start_sending_sniffed_opt}; @@ -135,6 +135,7 @@ fn load_for_consumer(load_data: LoadData, let factory = NetworkHttpRequestFactory { connector: connector, }; + let context = load_data.context.clone(); match load::<WrappedHttpRequest>(load_data, hsts_list, cookie_jar, devtools_chan, &factory, user_agent, @@ -160,14 +161,14 @@ fn load_for_consumer(load_data: LoadData, let mut image = resources_dir_path(); image.push("badcert.html"); - let load_data = LoadData::new(Url::from_file_path(&*image).unwrap(), None); + let load_data = LoadData::new(context, Url::from_file_path(&*image).unwrap(), None); file_loader::factory(load_data, start_chan, classifier, cancel_listener) } Err(LoadError::ConnectionAborted(_)) => unreachable!(), Ok(mut load_response) => { let metadata = load_response.metadata.clone(); - send_data(&mut load_response, start_chan, metadata, classifier, &cancel_listener) + send_data(context, &mut load_response, start_chan, metadata, classifier, &cancel_listener) } } } @@ -765,7 +766,8 @@ pub fn load<A>(load_data: LoadData, } } -fn send_data<R: Read>(reader: &mut R, +fn send_data<R: Read>(context: LoadContext, + reader: &mut R, start_chan: LoadConsumer, metadata: Metadata, classifier: Arc<MIMEClassifier>, @@ -775,7 +777,7 @@ fn send_data<R: Read>(reader: &mut R, Ok(ReadResult::Payload(buf)) => buf, _ => vec!(), }; - let p = match start_sending_sniffed_opt(start_chan, metadata, classifier, &buf) { + let p = match start_sending_sniffed_opt(start_chan, metadata, classifier, &buf, context) { Ok(p) => p, _ => return }; diff --git a/components/net/image_cache_task.rs b/components/net/image_cache_task.rs index b2acbcd7494..90ade430128 100644 --- a/components/net/image_cache_task.rs +++ b/components/net/image_cache_task.rs @@ -8,7 +8,8 @@ use net_traits::image::base::{Image, load_from_memory}; use net_traits::image_cache_task::ImageResponder; use net_traits::image_cache_task::{ImageCacheChan, ImageCacheCommand, ImageCacheTask, ImageState}; use net_traits::image_cache_task::{ImageCacheResult, ImageResponse, UsePlaceholder}; -use net_traits::{AsyncResponseTarget, ControlMsg, LoadConsumer, LoadData, ResourceTask, ResponseAction}; +use net_traits::{AsyncResponseTarget, ControlMsg, LoadConsumer, LoadData, ResourceTask}; +use net_traits::{ResponseAction, LoadContext}; use std::borrow::ToOwned; use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; @@ -423,7 +424,7 @@ impl ImageCache { CacheResult::Miss => { // A new load request! Request the load from // the resource task. - let load_data = LoadData::new((*ref_url).clone(), None); + let load_data = LoadData::new(LoadContext::Image, (*ref_url).clone(), None); let (action_sender, action_receiver) = ipc::channel().unwrap(); let response_target = AsyncResponseTarget { sender: action_sender, diff --git a/components/net/mime_classifier.rs b/components/net/mime_classifier.rs index 29f559a4738..019ee75eaea 100644 --- a/components/net/mime_classifier.rs +++ b/components/net/mime_classifier.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use net_traits::LoadContext; use std::borrow::ToOwned; pub struct MIMEClassifier { @@ -11,7 +12,8 @@ pub struct MIMEClassifier { plaintext_classifier: GroupedClassifier, archive_classifier: GroupedClassifier, binary_or_plaintext: BinaryOrPlaintextClassifier, - feeds_classifier: FeedsClassifier + feeds_classifier: FeedsClassifier, + font_classifier: GroupedClassifier, } pub enum MediaType { @@ -33,35 +35,105 @@ pub enum NoSniffFlag { } impl MIMEClassifier { - //Performs MIME Type Sniffing Algorithm (section 7) + //Performs MIME Type Sniffing Algorithm (sections 7 and 8) pub fn classify(&self, + context: LoadContext, no_sniff_flag: NoSniffFlag, apache_bug_flag: ApacheBugFlag, supplied_type: &Option<(String, String)>, data: &[u8]) -> (String, String) { - match *supplied_type { - None => self.sniff_unknown_type(no_sniff_flag, data), - Some(ref supplied_type) => { - let &(ref media_type, ref media_subtype) = supplied_type; - if MIMEClassifier::is_explicit_unknown(media_type, media_subtype) { - self.sniff_unknown_type(no_sniff_flag, data) - } else { - match no_sniff_flag { - NoSniffFlag::ON => supplied_type.clone(), - NoSniffFlag::OFF => match apache_bug_flag { - ApacheBugFlag::ON => self.sniff_text_or_data(data), - ApacheBugFlag::OFF => match MIMEClassifier::get_media_type(media_type, - media_subtype) { - Some(MediaType::Xml) => None, - Some(MediaType::Html) => self.feeds_classifier.classify(data), - Some(MediaType::Image) => self.image_classifier.classify(data), - Some(MediaType::AudioVideo) => self.audio_video_classifier.classify(data), - None => None - }.unwrap_or(supplied_type.clone()) + let supplied_type_or_octet_stream = supplied_type.clone() + .unwrap_or(("application".to_owned(), + "octet-stream".to_owned())); + match context { + LoadContext::Browsing => match *supplied_type { + None => self.sniff_unknown_type(no_sniff_flag, data), + Some(ref supplied_type) => { + let &(ref media_type, ref media_subtype) = supplied_type; + if MIMEClassifier::is_explicit_unknown(media_type, media_subtype) { + self.sniff_unknown_type(no_sniff_flag, data) + } else { + match no_sniff_flag { + NoSniffFlag::ON => supplied_type.clone(), + NoSniffFlag::OFF => match apache_bug_flag { + ApacheBugFlag::ON => self.sniff_text_or_data(data), + ApacheBugFlag::OFF => match MIMEClassifier::get_media_type(media_type, + media_subtype) { + Some(MediaType::Html) => self.feeds_classifier.classify(data), + Some(MediaType::Image) => self.image_classifier.classify(data), + Some(MediaType::AudioVideo) => self.audio_video_classifier.classify(data), + Some(MediaType::Xml) | None => None, + }.unwrap_or(supplied_type.clone()) + } } } } - } + }, + LoadContext::Image => { + // Section 8.2 Sniffing an image context + match MIMEClassifier::maybe_get_media_type(supplied_type) { + Some(MediaType::Xml) => None, + _ => self.image_classifier.classify(data), + }.unwrap_or(supplied_type_or_octet_stream) + }, + LoadContext::AudioVideo => { + // Section 8.3 Sniffing an image context + match MIMEClassifier::maybe_get_media_type(supplied_type) { + Some(MediaType::Xml) => None, + _ => self.audio_video_classifier.classify(data), + }.unwrap_or(supplied_type_or_octet_stream) + }, + LoadContext::Plugin => { + // 8.4 Sniffing in a plugin context + // + // This section was *not* finalized in the specs at the time + // of this implementation. + match *supplied_type { + None => ("application".to_owned(), "octet-stream".to_owned()), + _ => supplied_type_or_octet_stream, + } + }, + LoadContext::Style => { + // 8.5 Sniffing in a style context + // + // This section was *not* finalized in the specs at the time + // of this implementation. + match *supplied_type { + None => ("text".to_owned(), "css".to_owned()), + _ => supplied_type_or_octet_stream, + } + }, + LoadContext::Script => { + // 8.6 Sniffing in a script context + // + // This section was *not* finalized in the specs at the time + // of this implementation. + match *supplied_type { + None => ("text".to_owned(), "javascript".to_owned()), + _ => supplied_type_or_octet_stream, + } + }, + LoadContext::Font => { + // 8.7 Sniffing in a font context + match MIMEClassifier::maybe_get_media_type(supplied_type) { + Some(MediaType::Xml) => None, + _ => self.font_classifier.classify(data), + }.unwrap_or(supplied_type_or_octet_stream) + }, + LoadContext::TextTrack => { + // 8.8 Sniffing in a text track context + // + // This section was *not* finalized in the specs at the time + // of this implementation. + ("text".to_owned(), "vtt".to_owned()) + }, + LoadContext::CacheManifest => { + // 8.9 Sniffing in a cache manifest context + // + // This section was *not* finalized in the specs at the time + // of this implementation. + ("text".to_owned(), "cache-manifest".to_owned()) + }, } } @@ -73,7 +145,8 @@ impl MIMEClassifier { plaintext_classifier: GroupedClassifier::plaintext_classifier(), archive_classifier: GroupedClassifier::archive_classifier(), binary_or_plaintext: BinaryOrPlaintextClassifier, - feeds_classifier: FeedsClassifier + feeds_classifier: FeedsClassifier, + font_classifier: GroupedClassifier::font_classifier() } } @@ -143,6 +216,12 @@ impl MIMEClassifier { None } } + + fn maybe_get_media_type(supplied_type: &Option<(String, String)>) -> Option<MediaType> { + supplied_type.as_ref().and_then(|&(ref media_type, ref media_subtype)| { + MIMEClassifier::get_media_type(media_type, media_subtype) + }) + } } pub fn as_string_option(tup: Option<(&'static str, &'static str)>) -> Option<(String, String)> { @@ -375,8 +454,6 @@ impl GroupedClassifier { } } - // TODO: Use this in font context classifier - #[allow(dead_code)] fn font_classifier() -> GroupedClassifier { GroupedClassifier { byte_matchers: vec![ diff --git a/components/net/resource_task.rs b/components/net/resource_task.rs index 4599e8dd1d5..b80f47255b9 100644 --- a/components/net/resource_task.rs +++ b/components/net/resource_task.rs @@ -17,6 +17,7 @@ use hyper::header::{ContentType, Header, SetCookie}; use hyper::mime::{Mime, SubLevel, TopLevel}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use mime_classifier::{ApacheBugFlag, MIMEClassifier, NoSniffFlag}; +use net_traits::LoadContext; use net_traits::ProgressMsg::Done; use net_traits::{AsyncResponseTarget, Metadata, ProgressMsg, ResourceTask, ResponseAction}; use net_traits::{ControlMsg, CookieSource, LoadConsumer, LoadData, LoadResponse, ResourceId}; @@ -65,14 +66,16 @@ pub fn send_error(url: Url, err: String, start_chan: LoadConsumer) { /// For use by loaders in responding to a Load message that allows content sniffing. pub fn start_sending_sniffed(start_chan: LoadConsumer, metadata: Metadata, - classifier: Arc<MIMEClassifier>, partial_body: &[u8]) + classifier: Arc<MIMEClassifier>, partial_body: &[u8], + context: LoadContext) -> ProgressSender { - start_sending_sniffed_opt(start_chan, metadata, classifier, partial_body).ok().unwrap() + start_sending_sniffed_opt(start_chan, metadata, classifier, partial_body, context).ok().unwrap() } /// For use by loaders in responding to a Load message that allows content sniffing. pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadata, - classifier: Arc<MIMEClassifier>, partial_body: &[u8]) + classifier: Arc<MIMEClassifier>, partial_body: &[u8], + context: LoadContext) -> Result<ProgressSender, ()> { if opts::get().sniff_mime_types { // TODO: should be calculated in the resource loader, from pull requeset #4094 @@ -94,10 +97,11 @@ pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadat } let supplied_type = - metadata.content_type.map(|ContentType(Mime(toplevel, sublevel, _))| { + metadata.content_type.as_ref().map(|&ContentType(Mime(ref toplevel, ref sublevel, _))| { (format!("{}", toplevel), format!("{}", sublevel)) }); - let (toplevel, sublevel) = classifier.classify(no_sniff, + let (toplevel, sublevel) = classifier.classify(context, + no_sniff, check_for_apache_bug, &supplied_type, &partial_body); diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 6240a4ac208..14402b4ede5 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -136,6 +136,21 @@ pub mod image { pub mod base; } +/// A loading context, for context-specific sniffing, as defined in +/// https://mimesniff.spec.whatwg.org/#context-specific-sniffing +#[derive(Clone, Deserialize, Serialize, HeapSizeOf)] +pub enum LoadContext { + Browsing, + Image, + AudioVideo, + Plugin, + Style, + Script, + Font, + TextTrack, + CacheManifest, +} + #[derive(Clone, Deserialize, Serialize, HeapSizeOf)] pub struct LoadData { pub url: Url, @@ -151,10 +166,11 @@ pub struct LoadData { pub pipeline_id: Option<PipelineId>, // https://fetch.spec.whatwg.org/#concept-http-fetch step 4.3 pub credentials_flag: bool, + pub context: LoadContext, } impl LoadData { - pub fn new(url: Url, id: Option<PipelineId>) -> LoadData { + pub fn new(context: LoadContext, url: Url, id: Option<PipelineId>) -> LoadData { LoadData { url: url, method: Method::Get, @@ -164,6 +180,7 @@ impl LoadData { cors: None, pipeline_id: id, credentials_flag: true, + context: context } } } @@ -295,6 +312,7 @@ pub struct PendingAsyncLoad { url: Url, pipeline: Option<PipelineId>, guard: PendingLoadGuard, + context: LoadContext, } struct PendingLoadGuard { @@ -316,20 +334,21 @@ impl Drop for PendingLoadGuard { } impl PendingAsyncLoad { - pub fn new(resource_task: ResourceTask, url: Url, pipeline: Option<PipelineId>) + pub fn new(context: LoadContext, resource_task: ResourceTask, url: Url, pipeline: Option<PipelineId>) -> PendingAsyncLoad { PendingAsyncLoad { resource_task: resource_task, url: url, pipeline: pipeline, guard: PendingLoadGuard { loaded: false, }, + context: context } } /// Initiate the network request associated with this pending load, using the provided target. pub fn load_async(mut self, listener: AsyncResponseTarget) { self.guard.neuter(); - let load_data = LoadData::new(self.url, self.pipeline); + let load_data = LoadData::new(self.context, self.url, self.pipeline); let consumer = LoadConsumer::Listener(listener); self.resource_task.send(ControlMsg::Load(load_data, consumer, None)).unwrap(); } @@ -425,10 +444,13 @@ pub enum ProgressMsg { } /// Convenience function for synchronously loading a whole resource. -pub fn load_whole_resource(resource_task: &ResourceTask, url: Url, pipeline_id: Option<PipelineId>) +pub fn load_whole_resource(context: LoadContext, + resource_task: &ResourceTask, + url: Url, + pipeline_id: Option<PipelineId>) -> Result<(Metadata, Vec<u8>), String> { let (start_chan, start_port) = ipc::channel().unwrap(); - resource_task.send(ControlMsg::Load(LoadData::new(url, pipeline_id), + resource_task.send(ControlMsg::Load(LoadData::new(context, url, pipeline_id), LoadConsumer::Channel(start_chan), None)).unwrap(); let response = start_port.recv().unwrap(); diff --git a/components/script/document_loader.rs b/components/script/document_loader.rs index 00906af0c05..f5e49c46785 100644 --- a/components/script/document_loader.rs +++ b/components/script/document_loader.rs @@ -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); diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 3a879d4b617..07bef0cd348 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -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, diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index dba4c7882ed..3224c04d57f 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -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()) diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 4118bf7fa2b..1ef5e361bf8 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -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(); } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index b07b5086f45..0a3bc1355c1 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -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(), |