servo/ports/servoshell/desktop/embedder.rs
Martin Robinson 0e616e0c5d
api: Flatten and simplify Servo preferences (#34966)
Flatten and simplify Servo's preferences code. In addition, have both
preferences and options passed in as arguments to `Servo::new()` and
make sure not to use the globally set preferences in `servoshell` (as
much as possible now).

Instead of a complex procedural macro to generate preferences, just
expose a very simple derive macro that adds string based getters and
setters.

- All command-line parsing is moved to servoshell.
- There is no longer the concept of a missing preference.
- Preferences no longer have to be part of the resources bundle because
  they now have reasonable default values.
- servoshell specific preferences are no longer part of the preferences
  exposed by the Servo API.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-01-14 13:54:06 +00:00

73 lines
2.4 KiB
Rust

/* 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/. */
//! 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;
use webxr::glwindow::GlWindowDiscovery;
#[cfg(target_os = "windows")]
use webxr::openxr::OpenXrDiscovery;
use crate::desktop::protocols::{resource, servo as servo_handler, urlinfo};
pub enum XrDiscovery {
GlWindow(GlWindowDiscovery),
#[cfg(target_os = "windows")]
OpenXr(OpenXrDiscovery),
}
pub struct EmbedderCallbacks {
event_loop_waker: Box<dyn EventLoopWaker>,
xr_discovery: Option<XrDiscovery>,
}
impl EmbedderCallbacks {
pub fn new(
event_loop_waker: Box<dyn EventLoopWaker>,
xr_discovery: Option<XrDiscovery>,
) -> EmbedderCallbacks {
EmbedderCallbacks {
event_loop_waker,
xr_discovery,
}
}
}
impl EmbedderMethods for EmbedderCallbacks {
fn create_event_loop_waker(&mut self) -> Box<dyn EventLoopWaker> {
self.event_loop_waker.clone()
}
#[cfg(feature = "webxr")]
fn register_webxr(
&mut self,
xr: &mut webxr::MainThreadRegistry,
_embedder_proxy: EmbedderProxy,
) {
if pref!(dom_webxr_test) {
xr.register_mock(webxr::headless::HeadlessMockDiscovery::new());
} else if let Some(xr_discovery) = self.xr_discovery.take() {
match xr_discovery {
XrDiscovery::GlWindow(discovery) => xr.register(discovery),
#[cfg(target_os = "windows")]
XrDiscovery::OpenXr(discovery) => xr.register(discovery),
}
}
}
fn get_protocol_handlers(&self) -> ProtocolRegistry {
let mut registry = ProtocolRegistry::default();
registry.register("urlinfo", urlinfo::UrlInfoProtocolHander::default());
registry.register("servo", servo_handler::ServoProtocolHandler::default());
registry.register("resource", resource::ResourceProtocolHandler::default());
registry
}
fn get_version_string(&self) -> Option<String> {
crate::servo_version().into()
}
}