1pub mod embedder_controls;
12pub mod input_events;
13pub mod resources;
14pub mod user_contents;
15pub mod webdriver;
16
17use std::collections::HashMap;
18use std::ffi::c_void;
19use std::fmt::{Debug, Display, Error, Formatter};
20use std::hash::Hash;
21use std::ops::Range;
22use std::sync::Arc;
23
24use accesskit::TreeUpdate;
25use content_security_policy::Destination;
26use crossbeam_channel::Sender;
27use euclid::{Box2D, Point2D, Scale, Size2D, Vector2D};
28use http::{HeaderMap, Method, StatusCode};
29use log::warn;
30use malloc_size_of::malloc_size_of_is_0;
31use malloc_size_of_derive::MallocSizeOf;
32use pixels::SharedRasterImage;
33use serde::{Deserialize, Deserializer, Serialize, Serializer};
34use servo_base::Epoch;
35use servo_base::generic_channel::{
36 GenericCallback, GenericSender, GenericSharedMemory, SendResult,
37};
38use servo_base::id::{PipelineId, WebViewId};
39use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize};
40use servo_url::ServoUrl;
41use strum::{EnumMessage, IntoStaticStr};
42use style::queries::values::PrefersColorScheme;
43use style_traits::CSSPixel;
44use url::Url;
45use uuid::Uuid;
46use webrender_api::ExternalScrollId;
47use webrender_api::units::{
48 DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel, DevicePoint, DeviceRect,
49 DeviceVector2D, LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D,
50};
51
52pub use crate::embedder_controls::*;
53pub use crate::input_events::*;
54use crate::user_contents::UserContentManagerId;
55pub use crate::webdriver::*;
56
57#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
61pub enum WebViewPoint {
62 Device(DevicePoint),
63 Page(Point2D<f32, CSSPixel>),
64}
65
66impl WebViewPoint {
67 pub fn as_device_point(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DevicePoint {
68 match self {
69 Self::Device(point) => *point,
70 Self::Page(point) => *point * scale,
71 }
72 }
73}
74
75impl From<DevicePoint> for WebViewPoint {
76 fn from(point: DevicePoint) -> Self {
77 Self::Device(point)
78 }
79}
80
81impl From<LayoutPoint> for WebViewPoint {
82 fn from(point: LayoutPoint) -> Self {
83 Self::Page(Point2D::new(point.x, point.y))
84 }
85}
86
87impl From<Point2D<f32, CSSPixel>> for WebViewPoint {
88 fn from(point: Point2D<f32, CSSPixel>) -> Self {
89 Self::Page(point)
90 }
91}
92
93#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
97pub enum WebViewRect {
98 Device(DeviceRect),
99 Page(Box2D<f32, CSSPixel>),
100}
101
102impl WebViewRect {
103 pub fn as_device_rect(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceRect {
104 match self {
105 Self::Device(rect) => *rect,
106 Self::Page(rect) => *rect * scale,
107 }
108 }
109}
110
111impl From<DeviceRect> for WebViewRect {
112 fn from(rect: DeviceRect) -> Self {
113 Self::Device(rect)
114 }
115}
116
117impl From<LayoutRect> for WebViewRect {
118 fn from(rect: LayoutRect) -> Self {
119 Self::Page(Box2D::new(
120 Point2D::new(rect.min.x, rect.min.y),
121 Point2D::new(rect.max.x, rect.max.y),
122 ))
123 }
124}
125
126impl From<Box2D<f32, CSSPixel>> for WebViewRect {
127 fn from(rect: Box2D<f32, CSSPixel>) -> Self {
128 Self::Page(rect)
129 }
130}
131
132#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
133pub enum WebViewVector {
134 Device(DeviceVector2D),
135 Page(Vector2D<f32, CSSPixel>),
136}
137
138impl WebViewVector {
139 pub fn as_device_vector(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceVector2D {
140 match self {
141 Self::Device(vector) => *vector,
142 Self::Page(vector) => *vector * scale,
143 }
144 }
145}
146
147impl From<DeviceVector2D> for WebViewVector {
148 fn from(vector: DeviceVector2D) -> Self {
149 Self::Device(vector)
150 }
151}
152
153impl From<LayoutVector2D> for WebViewVector {
154 fn from(vector: LayoutVector2D) -> Self {
155 Self::Page(Vector2D::new(vector.x, vector.y))
156 }
157}
158
159impl From<Vector2D<f32, CSSPixel>> for WebViewVector {
160 fn from(vector: Vector2D<f32, CSSPixel>) -> Self {
161 Self::Page(vector)
162 }
163}
164
165#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
166pub enum Scroll {
167 Delta(WebViewVector),
168 Start,
169 End,
170}
171
172#[derive(Clone, Copy, Debug, PartialEq)]
175pub enum ShutdownState {
176 NotShuttingDown,
177 ShuttingDown,
178 FinishedShuttingDown,
179}
180
181#[repr(u8)]
184#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
185pub enum Cursor {
186 None,
187 #[default]
188 Default,
189 Pointer,
190 ContextMenu,
191 Help,
192 Progress,
193 Wait,
194 Cell,
195 Crosshair,
196 Text,
197 VerticalText,
198 Alias,
199 Copy,
200 Move,
201 NoDrop,
202 NotAllowed,
203 Grab,
204 Grabbing,
205 EResize,
206 NResize,
207 NeResize,
208 NwResize,
209 SResize,
210 SeResize,
211 SwResize,
212 WResize,
213 EwResize,
214 NsResize,
215 NeswResize,
216 NwseResize,
217 ColResize,
218 RowResize,
219 AllScroll,
220 ZoomIn,
221 ZoomOut,
222}
223
224pub trait EventLoopWaker: 'static + Send + Sync {
229 fn clone_box(&self) -> Box<dyn EventLoopWaker>;
230
231 fn wake(&self);
237}
238
239impl Clone for Box<dyn EventLoopWaker> {
240 fn clone(&self) -> Self {
241 self.clone_box()
242 }
243}
244
245pub struct GenericEmbedderProxy<T> {
247 pub sender: Sender<T>,
248 pub event_loop_waker: Box<dyn EventLoopWaker>,
249}
250
251impl<T> GenericEmbedderProxy<T> {
252 pub fn send(&self, message: T) {
253 if let Err(err) = self.sender.send(message) {
255 warn!("Failed to send response ({:?}).", err);
256 }
257 self.event_loop_waker.wake();
258 }
259}
260
261impl<T> Clone for GenericEmbedderProxy<T> {
262 fn clone(&self) -> Self {
263 Self {
264 sender: self.sender.clone(),
265 event_loop_waker: self.event_loop_waker.clone(),
266 }
267 }
268}
269
270pub type EmbedderProxy = GenericEmbedderProxy<EmbedderMsg>;
271
272pub trait RefreshDriver {
277 fn observe_next_frame(&self, start_frame_callback: Box<dyn Fn() + Send + 'static>);
284}
285
286#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
287pub struct AuthenticationResponse {
288 pub username: String,
290 pub password: String,
292}
293
294#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
296pub enum AllowOrDeny {
297 Allow,
298 Deny,
299}
300
301#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
302pub enum RegisterOrUnregister {
304 Register,
305 Unregister,
306}
307
308#[derive(Clone, Debug, Deserialize, Serialize)]
309pub struct ProtocolHandlerUpdateRegistration {
310 pub scheme: String,
312 pub url: ServoUrl,
314 pub register_or_unregister: RegisterOrUnregister,
316}
317
318#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
321pub struct ViewportDetails {
322 pub size: Size2D<f32, CSSPixel>,
324
325 pub hidpi_scale_factor: Scale<f32, CSSPixel, DevicePixel>,
328}
329
330impl ViewportDetails {
331 pub fn layout_size(&self) -> LayoutSize {
334 Size2D::from_untyped(self.size.to_untyped())
335 }
336}
337
338#[derive(Default, Deserialize, Serialize)]
341pub struct ScreenMetrics {
342 pub screen_size: DeviceIndependentIntSize,
343 pub available_size: DeviceIndependentIntSize,
344}
345
346#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
348pub struct TraversalId(String);
349
350impl TraversalId {
351 #[expect(clippy::new_without_default)]
352 pub fn new() -> Self {
353 Self(Uuid::new_v4().to_string())
354 }
355}
356
357#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, MallocSizeOf)]
358pub enum PixelFormat {
359 K8,
361 KA8,
363 RGB8,
365 RGBA8,
367 BGRA8,
369}
370
371#[derive(Clone, Deserialize, Serialize, MallocSizeOf)]
373pub struct Image {
374 pub width: u32,
375 pub height: u32,
376 pub format: PixelFormat,
377 #[conditional_malloc_size_of]
379 data: Arc<GenericSharedMemory>,
380 range: Range<usize>,
381}
382
383impl Image {
384 pub fn new(
385 width: u32,
386 height: u32,
387 data: Arc<GenericSharedMemory>,
388 range: Range<usize>,
389 format: PixelFormat,
390 ) -> Self {
391 Self {
392 width,
393 height,
394 format,
395 data,
396 range,
397 }
398 }
399
400 pub fn data(&self) -> &[u8] {
402 &self.data[self.range.clone()]
403 }
404}
405
406#[derive(Clone, Debug, Deserialize, Serialize, MallocSizeOf)]
407#[serde(rename_all = "lowercase")]
408pub enum ConsoleLogLevel {
409 Log,
410 Debug,
411 Info,
412 Warn,
413 Error,
414 Trace,
415}
416
417impl From<ConsoleLogLevel> for log::Level {
418 fn from(value: ConsoleLogLevel) -> Self {
419 match value {
420 ConsoleLogLevel::Log => log::Level::Info,
421 ConsoleLogLevel::Debug => log::Level::Debug,
422 ConsoleLogLevel::Info => log::Level::Info,
423 ConsoleLogLevel::Warn => log::Level::Warn,
424 ConsoleLogLevel::Error => log::Level::Error,
425 ConsoleLogLevel::Trace => log::Level::Trace,
426 }
427 }
428}
429
430#[derive(Clone, Deserialize, Serialize)]
431pub struct BluetoothDeviceDescription {
432 pub address: String,
433 pub name: String,
434}
435
436#[derive(Deserialize, IntoStaticStr, Serialize)]
438pub enum EmbedderMsg {
439 Status(WebViewId, Option<String>),
441 ChangePageTitle(WebViewId, Option<String>),
443 MoveTo(WebViewId, DeviceIntPoint),
445 ResizeTo(WebViewId, DeviceIntSize),
447 ShowSimpleDialog(WebViewId, SimpleDialogRequest),
451 AllowProtocolHandlerRequest(
453 WebViewId,
454 ProtocolHandlerUpdateRegistration,
455 GenericSender<AllowOrDeny>,
456 ),
457 AllowUnload(WebViewId, GenericSender<AllowOrDeny>),
459 ClearClipboard(WebViewId),
461 GetClipboardText(WebViewId, GenericCallback<Result<String, String>>),
463 SetClipboardText(WebViewId, String),
465 SetCursor(WebViewId, Cursor),
467 NewFavicon(WebViewId, Image),
469 GetWindowRect(WebViewId, GenericSender<DeviceIndependentIntRect>),
471 GetScreenMetrics(WebViewId, GenericSender<ScreenMetrics>),
473 NotifyFullscreenStateChanged(WebViewId, bool),
475 NotifyLoadStatusChanged(WebViewId, LoadStatus),
477 GetSelectedBluetoothDevice(
479 WebViewId,
480 Vec<BluetoothDeviceDescription>,
481 GenericSender<Option<String>>,
482 ),
483 PromptPermission(WebViewId, PermissionFeature, GenericSender<AllowOrDeny>),
485 RequestWakeLockPermission(WebViewId, GenericCallback<AllowOrDeny>),
489 OnDevtoolsStarted(Result<u16, ()>, String),
491 RequestDevtoolsConnection(GenericSender<AllowOrDeny>),
493 #[cfg(feature = "gamepad")]
495 PlayGamepadHapticEffect(
496 WebViewId,
497 usize,
498 GamepadHapticEffectType,
499 GenericCallback<bool>,
500 ),
501 #[cfg(feature = "gamepad")]
503 StopGamepadHapticEffect(WebViewId, usize, GenericCallback<bool>),
504 ShowNotification(Option<WebViewId>, Notification),
506 ShowConsoleApiMessage(Option<WebViewId>, ConsoleLogLevel, String),
509 ShowEmbedderControl(EmbedderControlId, DeviceIntRect, EmbedderControlRequest),
511 HideEmbedderControl(EmbedderControlId),
513 InputEventsHandled(WebViewId, Vec<InputEventOutcome>),
516 AccessibilityTreeUpdate(WebViewId, TreeUpdate, Epoch),
518}
519
520impl Debug for EmbedderMsg {
521 fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
522 let string: &'static str = self.into();
523 write!(formatter, "{string}")
524 }
525}
526
527#[derive(Clone, Debug, Deserialize, Serialize)]
529pub struct MediaMetadata {
530 pub title: String,
532 pub artist: String,
534 pub album: String,
536}
537
538impl MediaMetadata {
539 pub fn new(title: String) -> Self {
540 Self {
541 title,
542 artist: "".to_owned(),
543 album: "".to_owned(),
544 }
545 }
546}
547
548#[repr(i32)]
550#[derive(Clone, Debug, Deserialize, Serialize)]
551pub enum MediaSessionPlaybackState {
552 None_ = 1,
554 Playing,
556 Paused,
558}
559
560#[derive(Clone, Debug, Deserialize, Serialize)]
562pub struct MediaPositionState {
563 pub duration: f64,
564 pub playback_rate: f64,
565 pub position: f64,
566}
567
568impl MediaPositionState {
569 pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
570 Self {
571 duration,
572 playback_rate,
573 position,
574 }
575 }
576}
577
578#[derive(Clone, Debug, Deserialize, Serialize)]
580pub enum MediaSessionEvent {
581 SetMetadata(MediaMetadata),
583 PlaybackStateChange(MediaSessionPlaybackState),
585 SetPositionState(MediaPositionState),
587}
588
589#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
591pub enum PermissionFeature {
592 Geolocation,
593 Notifications,
594 Push,
595 Midi,
596 Camera,
597 Microphone,
598 Speaker,
599 DeviceInfo,
600 BackgroundSync,
601 Bluetooth,
602 PersistentStorage,
603 ScreenWakeLock,
604}
605
606#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
610pub enum InputMethodType {
611 Color,
612 Date,
613 DatetimeLocal,
614 Email,
615 Month,
616 Number,
617 Password,
618 Search,
619 Tel,
620 Text,
621 Time,
622 Url,
623 Week,
624}
625
626#[cfg(feature = "gamepad")]
627#[derive(Clone, Debug, Deserialize, Serialize)]
628pub struct DualRumbleEffectParams {
630 pub duration: f64,
631 pub start_delay: f64,
632 pub strong_magnitude: f64,
633 pub weak_magnitude: f64,
634}
635
636#[cfg(feature = "gamepad")]
637#[derive(Clone, Debug, Deserialize, Serialize)]
638pub enum GamepadHapticEffectType {
640 DualRumble(DualRumbleEffectParams),
641}
642
643#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
644pub struct WebResourceRequest {
645 #[serde(
646 deserialize_with = "::hyper_serde::deserialize",
647 serialize_with = "::hyper_serde::serialize"
648 )]
649 pub method: Method,
650 #[serde(
651 deserialize_with = "::hyper_serde::deserialize",
652 serialize_with = "::hyper_serde::serialize"
653 )]
654 pub headers: HeaderMap,
655 pub url: Url,
656 pub destination: Destination,
657 pub referrer_url: Option<Url>,
658 pub is_for_main_frame: bool,
659 pub is_redirect: bool,
660}
661
662#[derive(Clone, Deserialize, Serialize)]
663pub enum WebResourceResponseMsg {
664 Start(WebResourceResponse),
668 SendBodyData(Vec<u8>),
670 FinishLoad,
672 CancelLoad,
674 DoNotIntercept,
676}
677
678#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
679pub struct WebResourceResponse {
680 pub url: Url,
681 #[serde(
682 deserialize_with = "::hyper_serde::deserialize",
683 serialize_with = "::hyper_serde::serialize"
684 )]
685 #[ignore_malloc_size_of = "Defined in hyper"]
686 pub headers: HeaderMap,
687 #[serde(
688 deserialize_with = "::hyper_serde::deserialize",
689 serialize_with = "::hyper_serde::serialize"
690 )]
691 #[ignore_malloc_size_of = "Defined in hyper"]
692 pub status_code: StatusCode,
693 pub status_message: Vec<u8>,
694}
695
696impl WebResourceResponse {
697 pub fn new(url: Url) -> WebResourceResponse {
698 WebResourceResponse {
699 url,
700 headers: HeaderMap::new(),
701 status_code: StatusCode::OK,
702 status_message: b"OK".to_vec(),
703 }
704 }
705
706 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
707 self.headers = headers;
708 self
709 }
710
711 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
712 self.status_code = status_code;
713 self
714 }
715
716 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
717 self.status_message = status_message;
718 self
719 }
720}
721
722#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
724pub enum Theme {
725 Light,
727 Dark,
729}
730
731impl From<Theme> for PrefersColorScheme {
732 fn from(value: Theme) -> Self {
733 match value {
734 Theme::Light => PrefersColorScheme::Light,
735 Theme::Dark => PrefersColorScheme::Dark,
736 }
737 }
738}
739
740#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
743pub enum MediaSessionActionType {
744 Play,
746 Pause,
748 SeekBackward,
751 SeekForward,
754 PreviousTrack,
758 NextTrack,
761 SkipAd,
763 Stop,
765 SeekTo,
767}
768
769#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
771pub enum LoadStatus {
772 Started,
774 HeadParsed,
777 Complete,
781}
782
783#[derive(Clone, Debug, Deserialize, Serialize)]
786pub struct Notification {
787 pub title: String,
789 pub body: String,
791 pub tag: String,
794 pub language: String,
796 pub require_interaction: bool,
799 pub silent: Option<bool>,
802 pub icon_url: Option<ServoUrl>,
804 pub icon_resource: Option<Arc<SharedRasterImage>>,
806 pub badge_url: Option<ServoUrl>,
809 pub badge_resource: Option<Arc<SharedRasterImage>>,
811 pub image_url: Option<ServoUrl>,
813 pub image_resource: Option<Arc<SharedRasterImage>>,
815 pub actions: Vec<NotificationAction>,
817}
818
819#[derive(Clone, Debug, Deserialize, Serialize)]
821pub struct NotificationAction {
822 pub name: String,
824 pub title: String,
826 pub icon_url: Option<ServoUrl>,
828 pub icon_resource: Option<Arc<SharedRasterImage>>,
830}
831
832#[derive(Clone, Copy, Debug, Default)]
838pub struct ScreenGeometry {
839 pub size: DeviceIntSize,
842 pub available_size: DeviceIntSize,
848 pub window_rect: DeviceIntRect,
853}
854
855impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
856 fn from(value: SelectElementOption) -> Self {
857 Self::Option(value)
858 }
859}
860
861#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
864pub struct UntrustedNodeAddress(pub *const c_void);
865
866malloc_size_of_is_0!(UntrustedNodeAddress);
867
868#[expect(unsafe_code)]
869unsafe impl Send for UntrustedNodeAddress {}
870
871impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
872 fn from(o: style_traits::dom::OpaqueNode) -> Self {
873 UntrustedNodeAddress(o.0 as *const c_void)
874 }
875}
876
877impl Serialize for UntrustedNodeAddress {
878 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
879 (self.0 as usize).serialize(s)
880 }
881}
882
883impl<'de> Deserialize<'de> for UntrustedNodeAddress {
884 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
885 let value: usize = Deserialize::deserialize(d)?;
886 Ok(UntrustedNodeAddress::from_id(value))
887 }
888}
889
890impl UntrustedNodeAddress {
891 #[inline]
893 pub fn from_id(id: usize) -> UntrustedNodeAddress {
894 UntrustedNodeAddress(id as *const c_void)
895 }
896}
897
898#[derive(Clone, Debug, Deserialize, Serialize)]
900pub struct PaintHitTestResult {
901 pub pipeline_id: PipelineId,
903
904 pub point_in_viewport: Point2D<f32, CSSPixel>,
906
907 pub external_scroll_id: ExternalScrollId,
909}
910
911#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
914pub enum AnimationState {
915 AnimationsPresent,
917 AnimationCallbacksPresent,
919 NoAnimationsPresent,
921 NoAnimationCallbacksPresent,
923}
924
925#[derive(
978 Clone,
979 Copy,
980 Debug,
981 Default,
982 Deserialize,
983 Eq,
984 Hash,
985 MallocSizeOf,
986 PartialEq,
987 Serialize,
988 PartialOrd,
989)]
990pub struct FocusSequenceNumber(pub u64);
991
992impl Display for FocusSequenceNumber {
993 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
994 Display::fmt(&self.0, f)
995 }
996}
997
998#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
1001pub struct JavaScriptEvaluationId(pub usize);
1002
1003#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1004pub enum JSValue {
1005 Undefined,
1006 Null,
1007 Boolean(bool),
1008 Number(f64),
1009 String(String),
1010 Element(String),
1011 ShadowRoot(String),
1012 Frame(String),
1013 Window(String),
1014 Array(Vec<JSValue>),
1015 Object(HashMap<String, JSValue>),
1016}
1017
1018#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1019pub struct JavaScriptErrorInfo {
1020 pub message: String,
1021 pub filename: String,
1022 pub stack: Option<String>,
1023 pub line_number: u64,
1024 pub column: u64,
1025}
1026
1027#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1030pub enum JavaScriptEvaluationResultSerializationError {
1031 DetachedShadowRoot,
1034 StaleElementReference,
1037 UnknownType,
1040 OtherJavaScriptError,
1044}
1045
1046#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1048pub enum JavaScriptEvaluationError {
1049 DocumentNotFound,
1051 CompilationFailure,
1053 EvaluationFailure(Option<JavaScriptErrorInfo>),
1055 InternalError,
1058 WebViewNotReady,
1061 SerializationError(JavaScriptEvaluationResultSerializationError),
1064}
1065
1066#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1067pub enum ScreenshotCaptureError {
1068 CouldNotReadImage,
1071 WebViewDoesNotExist,
1073}
1074
1075#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1076pub struct RgbColor {
1077 pub red: u8,
1078 pub green: u8,
1079 pub blue: u8,
1080}
1081
1082#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1084pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1085
1086impl ScriptToEmbedderChan {
1087 pub fn new(
1089 embedder_chan: Sender<EmbedderMsg>,
1090 waker: Box<dyn EventLoopWaker>,
1091 ) -> ScriptToEmbedderChan {
1092 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1093 let msg = match embedder_msg {
1094 Ok(embedder_msg) => embedder_msg,
1095 Err(err) => {
1096 log::warn!("Script to Embedder message error: {err}");
1097 return;
1098 },
1099 };
1100 let _ = embedder_chan.send(msg);
1101 waker.wake();
1102 })
1103 .expect("Failed to create channel");
1104 ScriptToEmbedderChan(embedder_callback)
1105 }
1106
1107 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1109 self.0.send(msg)
1110 }
1111}
1112
1113#[derive(Deserialize, Serialize)]
1116pub struct NewWebViewDetails {
1117 pub webview_id: WebViewId,
1118 pub viewport_details: ViewportDetails,
1119 pub user_content_manager_id: Option<UserContentManagerId>,
1120}
1121
1122#[derive(Serialize, Deserialize, Debug)]
1123pub struct UrlRequest {
1132 pub url: ServoUrl,
1133 #[serde(
1134 deserialize_with = "hyper_serde::deserialize",
1135 serialize_with = "hyper_serde::serialize"
1136 )]
1137 pub headers: HeaderMap,
1138}
1139
1140impl UrlRequest {
1141 pub fn new(url: Url) -> Self {
1142 UrlRequest {
1143 url: url.into(),
1144 headers: HeaderMap::new(),
1145 }
1146 }
1147
1148 pub fn headers(mut self, headers: HeaderMap) -> Self {
1150 self.headers = headers;
1151 self
1152 }
1153}
1154
1155#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1157pub enum WakeLockType {
1158 Screen,
1159}
1160
1161pub trait WakeLockDelegate: Send + Sync {
1166 fn acquire(&self, type_: WakeLockType) -> Result<(), Box<dyn std::error::Error>>;
1170
1171 fn release(&self, type_: WakeLockType) -> Result<(), Box<dyn std::error::Error>>;
1175}