diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index cdbaa747edd..7c9611f65d4 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -34,7 +34,6 @@ use profile_traits::mem::ProfilerChan as MemProfilerChan; use profile_traits::mem::{Report, ReportKind, ReportsChan}; use profile_traits::time::ProfilerChan; use serde::{Deserialize, Serialize}; -use servo_config::opts; use servo_url::ServoUrl; use std::borrow::{Cow, ToOwned}; use std::collections::HashMap; @@ -54,6 +53,7 @@ pub fn new_resource_threads( mem_profiler_chan: MemProfilerChan, embedder_proxy: EmbedderProxy, config_dir: Option, + certificate_path: Option, ) -> (ResourceThreads, ResourceThreads) { let (public_core, private_core) = new_core_resource_thread( user_agent, @@ -62,6 +62,7 @@ pub fn new_resource_threads( mem_profiler_chan, embedder_proxy, config_dir.clone(), + certificate_path, ); let storage: IpcSender = StorageThreadFactory::new(config_dir); ( @@ -78,6 +79,7 @@ pub fn new_core_resource_thread( mem_profiler_chan: MemProfilerChan, embedder_proxy: EmbedderProxy, config_dir: Option, + certificate_path: Option, ) -> (CoreResourceThread, CoreResourceThread) { let (public_setup_chan, public_setup_port) = ipc::channel().unwrap(); let (private_setup_chan, private_setup_port) = ipc::channel().unwrap(); @@ -91,11 +93,13 @@ pub fn new_core_resource_thread( devtools_chan, time_profiler_chan, embedder_proxy, + certificate_path.clone(), ); let mut channel_manager = ResourceChannelManager { - resource_manager: resource_manager, - config_dir: config_dir, + resource_manager, + config_dir, + certificate_path, }; mem_profiler_chan.run_with_memory_reporting( @@ -112,9 +116,13 @@ pub fn new_core_resource_thread( struct ResourceChannelManager { resource_manager: CoreResourceManager, config_dir: Option, + certificate_path: Option, } -fn create_http_states(config_dir: Option<&Path>) -> (Arc, Arc) { +fn create_http_states( + config_dir: Option<&Path>, + certificate_path: Option, +) -> (Arc, Arc) { let mut hsts_list = HstsList::from_servo_preload(); let mut auth_cache = AuthCache::new(); let http_cache = HttpCache::new(); @@ -125,7 +133,7 @@ fn create_http_states(config_dir: Option<&Path>) -> (Arc, Arc fs::read_to_string(path).expect("Couldn't not find certificate file"), None => resources::read_string(Resource::SSLCertificates), }; @@ -154,8 +162,10 @@ impl ResourceChannelManager { private_receiver: IpcReceiver, memory_reporter: IpcReceiver, ) { - let (public_http_state, private_http_state) = - create_http_states(self.config_dir.as_ref().map(Deref::deref)); + let (public_http_state, private_http_state) = create_http_states( + self.config_dir.as_ref().map(Deref::deref), + self.certificate_path.clone(), + ); let mut rx_set = IpcReceiverSet::new().unwrap(); let private_id = rx_set.add(private_receiver).unwrap(); @@ -407,6 +417,7 @@ pub struct CoreResourceManager { swmanager_chan: Option>, filemanager: FileManager, fetch_pool: rayon::ThreadPool, + certificate_path: Option, } impl CoreResourceManager { @@ -415,6 +426,7 @@ impl CoreResourceManager { devtools_channel: Option>, _profiler_chan: ProfilerChan, embedder_proxy: EmbedderProxy, + certificate_path: Option, ) -> CoreResourceManager { let pool = rayon::ThreadPoolBuilder::new() .num_threads(16) @@ -426,6 +438,7 @@ impl CoreResourceManager { swmanager_chan: None, filemanager: FileManager::new(embedder_proxy), fetch_pool: pool, + certificate_path, } } @@ -500,6 +513,12 @@ impl CoreResourceManager { action_receiver: IpcReceiver, http_state: &Arc, ) { - websocket_loader::init(request, event_sender, action_receiver, http_state.clone()); + websocket_loader::init( + request, + event_sender, + action_receiver, + http_state.clone(), + self.certificate_path.clone(), + ); } } diff --git a/components/net/tests/resource_thread.rs b/components/net/tests/resource_thread.rs index 8c42b7f773a..7951e7e10da 100644 --- a/components/net/tests/resource_thread.rs +++ b/components/net/tests/resource_thread.rs @@ -27,6 +27,7 @@ fn test_exit() { MemProfilerChan(mtx), create_embedder_proxy(), None, + None, ); resource_thread.send(CoreResourceMsg::Exit(sender)).unwrap(); receiver.recv().unwrap(); diff --git a/components/net/websocket_loader.rs b/components/net/websocket_loader.rs index e98b22a70f7..67e6e256274 100644 --- a/components/net/websocket_loader.rs +++ b/components/net/websocket_loader.rs @@ -16,7 +16,6 @@ use net_traits::request::{RequestBuilder, RequestMode}; use net_traits::{CookieSource, MessageData}; use net_traits::{WebSocketDomAction, WebSocketNetworkEvent}; use openssl::ssl::SslStream; -use servo_config::opts; use servo_url::ServoUrl; use std::fs; use std::sync::atomic::{AtomicBool, Ordering}; @@ -40,6 +39,7 @@ struct Client<'a> { resource_url: &'a ServoUrl, event_sender: &'a IpcSender, protocol_in_use: Option, + certificate_path: Option, } impl<'a> Factory for Client<'a> { @@ -153,7 +153,7 @@ impl<'a> Handler for Client<'a> { stream: TcpStream, url: &Url, ) -> WebSocketResult> { - let certs = match opts::get().certificate_path { + let certs = match self.certificate_path { Some(ref path) => fs::read_to_string(path).expect("Couldn't not find certificate file"), None => resources::read_string(Resource::SSLCertificates), }; @@ -178,6 +178,7 @@ pub fn init( resource_event_sender: IpcSender, dom_action_receiver: IpcReceiver, http_state: Arc, + certificate_path: Option, ) { thread::Builder::new() .name(format!("WebSocket connection to {}", req_builder.url)) @@ -229,6 +230,7 @@ pub fn init( resource_url: &req_builder.url, event_sender: &resource_event_sender, protocol_in_use: None, + certificate_path, }; let mut ws = WebSocket::new(client).unwrap(); diff --git a/components/servo/lib.rs b/components/servo/lib.rs index c9f9bf5c5e5..78f09faf5c5 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -630,6 +630,7 @@ fn create_constellation( mem_profiler_chan.clone(), embedder_proxy.clone(), config_dir, + opts.certificate_path.clone(), ); let font_cache_thread = FontCacheThread::new( public_resource_threads.sender(),