aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/resource_thread.rs
diff options
context:
space:
mode:
authorwebbeef <me@webbeef.org>2024-08-21 21:11:16 -0700
committerGitHub <noreply@github.com>2024-08-22 04:11:16 +0000
commit663a92a5df39f5daef091624b6e29c228dcecbc3 (patch)
treedbcf67d033768d91ed585623c816410f0267d34d /components/net/resource_thread.rs
parent562d32c0519d58052cea681a696546fd4818bd3a (diff)
downloadservo-663a92a5df39f5daef091624b6e29c228dcecbc3.tar.gz
servo-663a92a5df39f5daef091624b6e29c228dcecbc3.zip
make protocol handlers registrable (#33104)
Signed-off-by: webbeef <me@webbeef.org>
Diffstat (limited to 'components/net/resource_thread.rs')
-rw-r--r--components/net/resource_thread.rs62
1 files changed, 48 insertions, 14 deletions
diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs
index b885b35226a..df3f5160915 100644
--- a/components/net/resource_thread.rs
+++ b/components/net/resource_thread.rs
@@ -52,6 +52,7 @@ use crate::filemanager_thread::FileManager;
use crate::hsts::HstsList;
use crate::http_cache::HttpCache;
use crate::http_loader::{http_redirect_fetch, HttpState};
+use crate::protocols::ProtocolRegistry;
use crate::storage_thread::StorageThreadFactory;
use crate::websocket_loader;
@@ -76,6 +77,7 @@ pub fn new_resource_threads(
config_dir: Option<PathBuf>,
certificate_path: Option<String>,
ignore_certificate_errors: bool,
+ protocols: Arc<ProtocolRegistry>,
) -> (ResourceThreads, ResourceThreads) {
let ca_certificates = match certificate_path {
Some(path) => match load_root_cert_store_from_file(path) {
@@ -97,6 +99,7 @@ pub fn new_resource_threads(
config_dir.clone(),
ca_certificates,
ignore_certificate_errors,
+ protocols,
);
let storage: IpcSender<StorageThreadMsg> = StorageThreadFactory::new(config_dir);
(
@@ -116,6 +119,7 @@ pub fn new_core_resource_thread(
config_dir: Option<PathBuf>,
ca_certificates: CACertificates,
ignore_certificate_errors: bool,
+ protocols: Arc<ProtocolRegistry>,
) -> (CoreResourceThread, CoreResourceThread) {
let (public_setup_chan, public_setup_port) = ipc::channel().unwrap();
let (private_setup_chan, private_setup_port) = ipc::channel().unwrap();
@@ -141,7 +145,14 @@ pub fn new_core_resource_thread(
};
mem_profiler_chan.run_with_memory_reporting(
- || (channel_manager.start(public_setup_port, private_setup_port, report_port)),
+ || {
+ channel_manager.start(
+ public_setup_port,
+ private_setup_port,
+ report_port,
+ protocols,
+ )
+ },
String::from("network-cache-reporter"),
report_chan,
|report_chan| report_chan,
@@ -215,6 +226,7 @@ impl ResourceChannelManager {
public_receiver: IpcReceiver<CoreResourceMsg>,
private_receiver: IpcReceiver<CoreResourceMsg>,
memory_reporter: IpcReceiver<ReportsChan>,
+ protocols: Arc<ProtocolRegistry>,
) {
let (public_http_state, private_http_state) = create_http_states(
self.config_dir.as_deref(),
@@ -248,7 +260,7 @@ impl ResourceChannelManager {
&public_http_state
};
if let Ok(msg) = data.to() {
- if !self.process_msg(msg, group) {
+ if !self.process_msg(msg, group, Arc::clone(&protocols)) {
return;
}
}
@@ -283,13 +295,22 @@ impl ResourceChannelManager {
}
/// Returns false if the thread should exit.
- fn process_msg(&mut self, msg: CoreResourceMsg, http_state: &Arc<HttpState>) -> bool {
+ fn process_msg(
+ &mut self,
+ msg: CoreResourceMsg,
+ http_state: &Arc<HttpState>,
+ protocols: Arc<ProtocolRegistry>,
+ ) -> bool {
match msg {
CoreResourceMsg::Fetch(req_init, channels) => match channels {
- FetchChannels::ResponseMsg(sender, cancel_chan) => {
- self.resource_manager
- .fetch(req_init, None, sender, http_state, cancel_chan)
- },
+ FetchChannels::ResponseMsg(sender, cancel_chan) => self.resource_manager.fetch(
+ req_init,
+ None,
+ sender,
+ http_state,
+ cancel_chan,
+ protocols,
+ ),
FetchChannels::WebSocket {
event_sender,
action_receiver,
@@ -299,10 +320,14 @@ impl ResourceChannelManager {
action_receiver,
http_state,
),
- FetchChannels::Prefetch => {
- self.resource_manager
- .fetch(req_init, None, DiscardFetch, http_state, None)
- },
+ FetchChannels::Prefetch => self.resource_manager.fetch(
+ req_init,
+ None,
+ DiscardFetch,
+ http_state,
+ None,
+ protocols,
+ ),
},
CoreResourceMsg::DeleteCookies(request) => {
http_state
@@ -312,9 +337,16 @@ impl ResourceChannelManager {
.clear_storage(&request);
return true;
},
- CoreResourceMsg::FetchRedirect(req_init, res_init, sender, cancel_chan) => self
- .resource_manager
- .fetch(req_init, Some(res_init), sender, http_state, cancel_chan),
+ CoreResourceMsg::FetchRedirect(req_init, res_init, sender, cancel_chan) => {
+ self.resource_manager.fetch(
+ req_init,
+ Some(res_init),
+ sender,
+ http_state,
+ cancel_chan,
+ protocols,
+ )
+ },
CoreResourceMsg::SetCookieForUrl(request, cookie, source) => self
.resource_manager
.set_cookie_for_url(&request, cookie.into_inner().to_owned(), source, http_state),
@@ -656,6 +688,7 @@ impl CoreResourceManager {
mut sender: Target,
http_state: &Arc<HttpState>,
cancel_chan: Option<IpcReceiver<()>>,
+ protocols: Arc<ProtocolRegistry>,
) {
let http_state = http_state.clone();
let ua = self.user_agent.clone();
@@ -704,6 +737,7 @@ impl CoreResourceManager {
file_token,
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(cancel_chan))),
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(request.timing_type()))),
+ protocols,
};
match res_init_ {