mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
make protocol handlers registrable (#33104)
Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
parent
562d32c051
commit
663a92a5df
19 changed files with 516 additions and 219 deletions
|
@ -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_ {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue