mirror of
https://github.com/servo/servo.git
synced 2025-08-14 18:05:36 +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
|
@ -99,7 +99,11 @@ euclid = { workspace = true }
|
|||
gilrs = { git = "https://gitlab.com/gilrs-project/gilrs", rev = "eafb7f2ef488874188c5d75adce9aef486be9d4e" }
|
||||
gleam = { workspace = true }
|
||||
glow = "0.13.1"
|
||||
headers = { workspace = true }
|
||||
http = { workspace = true }
|
||||
keyboard-types = { workspace = true }
|
||||
net = { path = "../../components/net" }
|
||||
net_traits = { workspace = true }
|
||||
raw-window-handle = "0.6"
|
||||
shellwords = "1.0.0"
|
||||
surfman = { workspace = true, features = ["sm-x11", "sm-raw-window-handle-06"] }
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
//! Implements the global methods required by Servo (not window/gl/compositor related).
|
||||
|
||||
use net::protocols::ProtocolRegistry;
|
||||
use servo::compositing::windowing::EmbedderMethods;
|
||||
use servo::embedder_traits::{EmbedderProxy, EventLoopWaker};
|
||||
use servo::servo_config::pref;
|
||||
|
@ -11,6 +12,8 @@ use webxr::glwindow::GlWindowDiscovery;
|
|||
#[cfg(target_os = "windows")]
|
||||
use webxr::openxr::OpenXrDiscovery;
|
||||
|
||||
use crate::desktop::protocols::urlinfo;
|
||||
|
||||
pub enum XrDiscovery {
|
||||
GlWindow(GlWindowDiscovery),
|
||||
#[cfg(target_os = "windows")]
|
||||
|
@ -54,4 +57,10 @@ impl EmbedderMethods for EmbedderCallbacks {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_protocol_handlers(&self) -> ProtocolRegistry {
|
||||
let mut registry = ProtocolRegistry::default();
|
||||
registry.register("urlinfo", urlinfo::UrlInfoProtocolHander::default());
|
||||
registry
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ mod headed_window;
|
|||
mod headless_window;
|
||||
mod keyutils;
|
||||
mod minibrowser;
|
||||
mod protocols;
|
||||
mod tracing;
|
||||
mod webview;
|
||||
mod window_trait;
|
||||
|
|
5
ports/servoshell/desktop/protocols/mod.rs
Normal file
5
ports/servoshell/desktop/protocols/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
pub(crate) mod urlinfo;
|
46
ports/servoshell/desktop/protocols/urlinfo.rs
Normal file
46
ports/servoshell/desktop/protocols/urlinfo.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
use headers::{ContentType, HeaderMapExt};
|
||||
use http::StatusCode;
|
||||
use net::fetch::methods::{DoneChannel, FetchContext};
|
||||
use net::protocols::ProtocolHandler;
|
||||
use net_traits::request::Request;
|
||||
use net_traits::response::{Response, ResponseBody};
|
||||
use net_traits::ResourceFetchTiming;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UrlInfoProtocolHander {}
|
||||
|
||||
// A simple protocol handler that displays information about the url itself.
|
||||
impl ProtocolHandler for UrlInfoProtocolHander {
|
||||
fn load(
|
||||
&self,
|
||||
request: &mut Request,
|
||||
_done_chan: &mut DoneChannel,
|
||||
_context: &FetchContext,
|
||||
) -> Pin<Box<dyn Future<Output = Response> + Send>> {
|
||||
let url = request.current_url();
|
||||
|
||||
let content = format!(
|
||||
r#"Full url: {url}
|
||||
scheme: {}
|
||||
path: {}
|
||||
query: {:?}"#,
|
||||
url.scheme(),
|
||||
url.path(),
|
||||
url.query()
|
||||
);
|
||||
let mut response = Response::new(url, ResourceFetchTiming::new(request.timing_type()));
|
||||
*response.body.lock().unwrap() = ResponseBody::Done(content.as_bytes().to_vec());
|
||||
response.headers.typed_insert(ContentType::text());
|
||||
response.status = Some((StatusCode::OK, "OK".to_string()));
|
||||
response.raw_status = Some((StatusCode::OK.as_u16(), b"OK".to_vec()));
|
||||
|
||||
Box::pin(std::future::ready(response))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue