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 crossbeam_channel::Sender;
26use euclid::{Box2D, Point2D, Scale, Size2D, Vector2D};
27use http::{HeaderMap, Method, StatusCode};
28use log::warn;
29use malloc_size_of::malloc_size_of_is_0;
30use malloc_size_of_derive::MallocSizeOf;
31use pixels::SharedRasterImage;
32use serde::{Deserialize, Deserializer, Serialize, Serializer};
33use servo_base::Epoch;
34use servo_base::generic_channel::{
35 GenericCallback, GenericSender, GenericSharedMemory, SendResult,
36};
37use servo_base::id::{PipelineId, WebViewId};
38use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize};
39use servo_url::ServoUrl;
40use strum::{EnumMessage, IntoStaticStr};
41use style::queries::values::PrefersColorScheme;
42use style_traits::CSSPixel;
43use url::Url;
44use uuid::Uuid;
45use webrender_api::ExternalScrollId;
46use webrender_api::units::{
47 DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel, DevicePoint, DeviceRect,
48 DeviceVector2D, LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D,
49};
50
51pub use crate::embedder_controls::*;
52pub use crate::input_events::*;
53use crate::user_contents::UserContentManagerId;
54pub use crate::webdriver::*;
55
56#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
60pub enum WebViewPoint {
61 Device(DevicePoint),
62 Page(Point2D<f32, CSSPixel>),
63}
64
65impl WebViewPoint {
66 pub fn as_device_point(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DevicePoint {
67 match self {
68 Self::Device(point) => *point,
69 Self::Page(point) => *point * scale,
70 }
71 }
72}
73
74impl From<DevicePoint> for WebViewPoint {
75 fn from(point: DevicePoint) -> Self {
76 Self::Device(point)
77 }
78}
79
80impl From<LayoutPoint> for WebViewPoint {
81 fn from(point: LayoutPoint) -> Self {
82 Self::Page(Point2D::new(point.x, point.y))
83 }
84}
85
86impl From<Point2D<f32, CSSPixel>> for WebViewPoint {
87 fn from(point: Point2D<f32, CSSPixel>) -> Self {
88 Self::Page(point)
89 }
90}
91
92#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
96pub enum WebViewRect {
97 Device(DeviceRect),
98 Page(Box2D<f32, CSSPixel>),
99}
100
101impl WebViewRect {
102 pub fn as_device_rect(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceRect {
103 match self {
104 Self::Device(rect) => *rect,
105 Self::Page(rect) => *rect * scale,
106 }
107 }
108}
109
110impl From<DeviceRect> for WebViewRect {
111 fn from(rect: DeviceRect) -> Self {
112 Self::Device(rect)
113 }
114}
115
116impl From<LayoutRect> for WebViewRect {
117 fn from(rect: LayoutRect) -> Self {
118 Self::Page(Box2D::new(
119 Point2D::new(rect.min.x, rect.min.y),
120 Point2D::new(rect.max.x, rect.max.y),
121 ))
122 }
123}
124
125impl From<Box2D<f32, CSSPixel>> for WebViewRect {
126 fn from(rect: Box2D<f32, CSSPixel>) -> Self {
127 Self::Page(rect)
128 }
129}
130
131#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
132pub enum WebViewVector {
133 Device(DeviceVector2D),
134 Page(Vector2D<f32, CSSPixel>),
135}
136
137impl WebViewVector {
138 pub fn as_device_vector(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceVector2D {
139 match self {
140 Self::Device(vector) => *vector,
141 Self::Page(vector) => *vector * scale,
142 }
143 }
144}
145
146impl From<DeviceVector2D> for WebViewVector {
147 fn from(vector: DeviceVector2D) -> Self {
148 Self::Device(vector)
149 }
150}
151
152impl From<LayoutVector2D> for WebViewVector {
153 fn from(vector: LayoutVector2D) -> Self {
154 Self::Page(Vector2D::new(vector.x, vector.y))
155 }
156}
157
158impl From<Vector2D<f32, CSSPixel>> for WebViewVector {
159 fn from(vector: Vector2D<f32, CSSPixel>) -> Self {
160 Self::Page(vector)
161 }
162}
163
164#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
165pub enum Scroll {
166 Delta(WebViewVector),
167 Start,
168 End,
169}
170
171#[derive(Clone, Copy, Debug, PartialEq)]
174pub enum ShutdownState {
175 NotShuttingDown,
176 ShuttingDown,
177 FinishedShuttingDown,
178}
179
180#[repr(u8)]
183#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
184pub enum Cursor {
185 None,
186 #[default]
187 Default,
188 Pointer,
189 ContextMenu,
190 Help,
191 Progress,
192 Wait,
193 Cell,
194 Crosshair,
195 Text,
196 VerticalText,
197 Alias,
198 Copy,
199 Move,
200 NoDrop,
201 NotAllowed,
202 Grab,
203 Grabbing,
204 EResize,
205 NResize,
206 NeResize,
207 NwResize,
208 SResize,
209 SeResize,
210 SwResize,
211 WResize,
212 EwResize,
213 NsResize,
214 NeswResize,
215 NwseResize,
216 ColResize,
217 RowResize,
218 AllScroll,
219 ZoomIn,
220 ZoomOut,
221}
222
223pub trait EventLoopWaker: 'static + Send + Sync {
228 fn clone_box(&self) -> Box<dyn EventLoopWaker>;
229
230 fn wake(&self);
236}
237
238impl Clone for Box<dyn EventLoopWaker> {
239 fn clone(&self) -> Self {
240 self.clone_box()
241 }
242}
243
244pub struct GenericEmbedderProxy<T> {
246 pub sender: Sender<T>,
247 pub event_loop_waker: Box<dyn EventLoopWaker>,
248}
249
250impl<T> GenericEmbedderProxy<T> {
251 pub fn send(&self, message: T) {
252 if let Err(err) = self.sender.send(message) {
254 warn!("Failed to send response ({:?}).", err);
255 }
256 self.event_loop_waker.wake();
257 }
258}
259
260impl<T> Clone for GenericEmbedderProxy<T> {
261 fn clone(&self) -> Self {
262 Self {
263 sender: self.sender.clone(),
264 event_loop_waker: self.event_loop_waker.clone(),
265 }
266 }
267}
268
269pub type EmbedderProxy = GenericEmbedderProxy<EmbedderMsg>;
270
271pub trait RefreshDriver {
276 fn observe_next_frame(&self, start_frame_callback: Box<dyn Fn() + Send + 'static>);
283}
284
285#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
286pub struct AuthenticationResponse {
287 pub username: String,
289 pub password: String,
291}
292
293#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
295pub enum AllowOrDeny {
296 Allow,
297 Deny,
298}
299
300#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
301pub enum RegisterOrUnregister {
303 Register,
304 Unregister,
305}
306
307#[derive(Clone, Debug, Deserialize, Serialize)]
308pub struct ProtocolHandlerUpdateRegistration {
309 pub scheme: String,
311 pub url: ServoUrl,
313 pub register_or_unregister: RegisterOrUnregister,
315}
316
317#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
320pub struct ViewportDetails {
321 pub size: Size2D<f32, CSSPixel>,
323
324 pub hidpi_scale_factor: Scale<f32, CSSPixel, DevicePixel>,
327}
328
329impl ViewportDetails {
330 pub fn layout_size(&self) -> LayoutSize {
333 Size2D::from_untyped(self.size.to_untyped())
334 }
335}
336
337#[derive(Default, Deserialize, Serialize)]
340pub struct ScreenMetrics {
341 pub screen_size: DeviceIndependentIntSize,
342 pub available_size: DeviceIndependentIntSize,
343}
344
345#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
347pub struct TraversalId(String);
348
349impl TraversalId {
350 #[expect(clippy::new_without_default)]
351 pub fn new() -> Self {
352 Self(Uuid::new_v4().to_string())
353 }
354}
355
356#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, MallocSizeOf)]
357pub enum PixelFormat {
358 K8,
360 KA8,
362 RGB8,
364 RGBA8,
366 BGRA8,
368}
369
370#[derive(Clone, Deserialize, Serialize, MallocSizeOf)]
372pub struct Image {
373 pub width: u32,
374 pub height: u32,
375 pub format: PixelFormat,
376 #[conditional_malloc_size_of]
378 data: Arc<GenericSharedMemory>,
379 range: Range<usize>,
380}
381
382impl Image {
383 pub fn new(
384 width: u32,
385 height: u32,
386 data: Arc<GenericSharedMemory>,
387 range: Range<usize>,
388 format: PixelFormat,
389 ) -> Self {
390 Self {
391 width,
392 height,
393 format,
394 data,
395 range,
396 }
397 }
398
399 pub fn data(&self) -> &[u8] {
401 &self.data[self.range.clone()]
402 }
403}
404
405#[derive(Clone, Debug, Deserialize, Serialize, MallocSizeOf)]
406#[serde(rename_all = "lowercase")]
407pub enum ConsoleLogLevel {
408 Log,
409 Debug,
410 Info,
411 Warn,
412 Error,
413 Trace,
414}
415
416impl From<ConsoleLogLevel> for log::Level {
417 fn from(value: ConsoleLogLevel) -> Self {
418 match value {
419 ConsoleLogLevel::Log => log::Level::Info,
420 ConsoleLogLevel::Debug => log::Level::Debug,
421 ConsoleLogLevel::Info => log::Level::Info,
422 ConsoleLogLevel::Warn => log::Level::Warn,
423 ConsoleLogLevel::Error => log::Level::Error,
424 ConsoleLogLevel::Trace => log::Level::Trace,
425 }
426 }
427}
428
429#[derive(Clone, Deserialize, Serialize)]
430pub struct BluetoothDeviceDescription {
431 pub address: String,
432 pub name: String,
433}
434
435#[derive(Deserialize, IntoStaticStr, Serialize)]
437pub enum EmbedderMsg {
438 Status(WebViewId, Option<String>),
440 ChangePageTitle(WebViewId, Option<String>),
442 MoveTo(WebViewId, DeviceIntPoint),
444 ResizeTo(WebViewId, DeviceIntSize),
446 ShowSimpleDialog(WebViewId, SimpleDialogRequest),
450 AllowProtocolHandlerRequest(
452 WebViewId,
453 ProtocolHandlerUpdateRegistration,
454 GenericSender<AllowOrDeny>,
455 ),
456 AllowUnload(WebViewId, GenericSender<AllowOrDeny>),
458 ClearClipboard(WebViewId),
460 GetClipboardText(WebViewId, GenericCallback<Result<String, String>>),
462 SetClipboardText(WebViewId, String),
464 SetCursor(WebViewId, Cursor),
466 NewFavicon(WebViewId, Image),
468 GetWindowRect(WebViewId, GenericSender<DeviceIndependentIntRect>),
470 GetScreenMetrics(WebViewId, GenericSender<ScreenMetrics>),
472 NotifyFullscreenStateChanged(WebViewId, bool),
474 NotifyLoadStatusChanged(WebViewId, LoadStatus),
476 GetSelectedBluetoothDevice(
478 WebViewId,
479 Vec<BluetoothDeviceDescription>,
480 GenericSender<Option<String>>,
481 ),
482 PromptPermission(WebViewId, PermissionFeature, GenericSender<AllowOrDeny>),
484 RequestWakeLockPermission(WebViewId, GenericCallback<AllowOrDeny>),
488 OnDevtoolsStarted(Result<u16, ()>, String),
490 RequestDevtoolsConnection(GenericSender<AllowOrDeny>),
492 #[cfg(feature = "gamepad")]
494 PlayGamepadHapticEffect(
495 WebViewId,
496 usize,
497 GamepadHapticEffectType,
498 GenericCallback<bool>,
499 ),
500 #[cfg(feature = "gamepad")]
502 StopGamepadHapticEffect(WebViewId, usize, GenericCallback<bool>),
503 ShowNotification(Option<WebViewId>, Notification),
505 ShowConsoleApiMessage(Option<WebViewId>, ConsoleLogLevel, String),
508 ShowEmbedderControl(EmbedderControlId, DeviceIntRect, EmbedderControlRequest),
510 HideEmbedderControl(EmbedderControlId),
512 InputEventsHandled(WebViewId, Vec<InputEventOutcome>),
515 AccessibilityTreeUpdate(WebViewId, TreeUpdate, Epoch),
517}
518
519impl Debug for EmbedderMsg {
520 fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
521 let string: &'static str = self.into();
522 write!(formatter, "{string}")
523 }
524}
525
526#[derive(Clone, Debug, Deserialize, Serialize)]
528pub struct MediaMetadata {
529 pub title: String,
531 pub artist: String,
533 pub album: String,
535}
536
537impl MediaMetadata {
538 pub fn new(title: String) -> Self {
539 Self {
540 title,
541 artist: "".to_owned(),
542 album: "".to_owned(),
543 }
544 }
545}
546
547#[repr(i32)]
549#[derive(Clone, Debug, Deserialize, Serialize)]
550pub enum MediaSessionPlaybackState {
551 None_ = 1,
553 Playing,
555 Paused,
557}
558
559#[derive(Clone, Debug, Deserialize, Serialize)]
561pub struct MediaPositionState {
562 pub duration: f64,
563 pub playback_rate: f64,
564 pub position: f64,
565}
566
567impl MediaPositionState {
568 pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
569 Self {
570 duration,
571 playback_rate,
572 position,
573 }
574 }
575}
576
577#[derive(Clone, Debug, Deserialize, Serialize)]
579pub enum MediaSessionEvent {
580 SetMetadata(MediaMetadata),
582 PlaybackStateChange(MediaSessionPlaybackState),
584 SetPositionState(MediaPositionState),
586}
587
588#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
590pub enum PermissionFeature {
591 Geolocation,
592 Notifications,
593 Push,
594 Midi,
595 Camera,
596 Microphone,
597 Speaker,
598 DeviceInfo,
599 BackgroundSync,
600 Bluetooth,
601 PersistentStorage,
602 ScreenWakeLock,
603}
604
605#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
609pub enum InputMethodType {
610 Color,
611 Date,
612 DatetimeLocal,
613 Email,
614 Month,
615 Number,
616 Password,
617 Search,
618 Tel,
619 Text,
620 Time,
621 Url,
622 Week,
623}
624
625#[cfg(feature = "gamepad")]
626#[derive(Clone, Debug, Deserialize, Serialize)]
627pub struct DualRumbleEffectParams {
629 pub duration: f64,
630 pub start_delay: f64,
631 pub strong_magnitude: f64,
632 pub weak_magnitude: f64,
633}
634
635#[cfg(feature = "gamepad")]
636#[derive(Clone, Debug, Deserialize, Serialize)]
637pub enum GamepadHapticEffectType {
639 DualRumble(DualRumbleEffectParams),
640}
641
642#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
643pub struct WebResourceRequest {
644 #[serde(
645 deserialize_with = "::hyper_serde::deserialize",
646 serialize_with = "::hyper_serde::serialize"
647 )]
648 pub method: Method,
649 #[serde(
650 deserialize_with = "::hyper_serde::deserialize",
651 serialize_with = "::hyper_serde::serialize"
652 )]
653 pub headers: HeaderMap,
654 pub url: Url,
655 pub is_for_main_frame: bool,
656 pub is_redirect: bool,
657}
658
659#[derive(Clone, Deserialize, Serialize)]
660pub enum WebResourceResponseMsg {
661 Start(WebResourceResponse),
665 SendBodyData(Vec<u8>),
667 FinishLoad,
669 CancelLoad,
671 DoNotIntercept,
673}
674
675#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
676pub struct WebResourceResponse {
677 pub url: Url,
678 #[serde(
679 deserialize_with = "::hyper_serde::deserialize",
680 serialize_with = "::hyper_serde::serialize"
681 )]
682 #[ignore_malloc_size_of = "Defined in hyper"]
683 pub headers: HeaderMap,
684 #[serde(
685 deserialize_with = "::hyper_serde::deserialize",
686 serialize_with = "::hyper_serde::serialize"
687 )]
688 #[ignore_malloc_size_of = "Defined in hyper"]
689 pub status_code: StatusCode,
690 pub status_message: Vec<u8>,
691}
692
693impl WebResourceResponse {
694 pub fn new(url: Url) -> WebResourceResponse {
695 WebResourceResponse {
696 url,
697 headers: HeaderMap::new(),
698 status_code: StatusCode::OK,
699 status_message: b"OK".to_vec(),
700 }
701 }
702
703 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
704 self.headers = headers;
705 self
706 }
707
708 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
709 self.status_code = status_code;
710 self
711 }
712
713 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
714 self.status_message = status_message;
715 self
716 }
717}
718
719#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
721pub enum Theme {
722 Light,
724 Dark,
726}
727
728impl From<Theme> for PrefersColorScheme {
729 fn from(value: Theme) -> Self {
730 match value {
731 Theme::Light => PrefersColorScheme::Light,
732 Theme::Dark => PrefersColorScheme::Dark,
733 }
734 }
735}
736
737#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
740pub enum MediaSessionActionType {
741 Play,
743 Pause,
745 SeekBackward,
748 SeekForward,
751 PreviousTrack,
755 NextTrack,
758 SkipAd,
760 Stop,
762 SeekTo,
764}
765
766#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
768pub enum LoadStatus {
769 Started,
771 HeadParsed,
774 Complete,
778}
779
780#[derive(Clone, Debug, Deserialize, Serialize)]
783pub struct Notification {
784 pub title: String,
786 pub body: String,
788 pub tag: String,
791 pub language: String,
793 pub require_interaction: bool,
796 pub silent: Option<bool>,
799 pub icon_url: Option<ServoUrl>,
801 pub icon_resource: Option<Arc<SharedRasterImage>>,
803 pub badge_url: Option<ServoUrl>,
806 pub badge_resource: Option<Arc<SharedRasterImage>>,
808 pub image_url: Option<ServoUrl>,
810 pub image_resource: Option<Arc<SharedRasterImage>>,
812 pub actions: Vec<NotificationAction>,
814}
815
816#[derive(Clone, Debug, Deserialize, Serialize)]
818pub struct NotificationAction {
819 pub name: String,
821 pub title: String,
823 pub icon_url: Option<ServoUrl>,
825 pub icon_resource: Option<Arc<SharedRasterImage>>,
827}
828
829#[derive(Clone, Copy, Debug, Default)]
835pub struct ScreenGeometry {
836 pub size: DeviceIntSize,
839 pub available_size: DeviceIntSize,
845 pub window_rect: DeviceIntRect,
850}
851
852impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
853 fn from(value: SelectElementOption) -> Self {
854 Self::Option(value)
855 }
856}
857
858#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
861pub struct UntrustedNodeAddress(pub *const c_void);
862
863malloc_size_of_is_0!(UntrustedNodeAddress);
864
865#[expect(unsafe_code)]
866unsafe impl Send for UntrustedNodeAddress {}
867
868impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
869 fn from(o: style_traits::dom::OpaqueNode) -> Self {
870 UntrustedNodeAddress(o.0 as *const c_void)
871 }
872}
873
874impl Serialize for UntrustedNodeAddress {
875 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
876 (self.0 as usize).serialize(s)
877 }
878}
879
880impl<'de> Deserialize<'de> for UntrustedNodeAddress {
881 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
882 let value: usize = Deserialize::deserialize(d)?;
883 Ok(UntrustedNodeAddress::from_id(value))
884 }
885}
886
887impl UntrustedNodeAddress {
888 #[inline]
890 pub fn from_id(id: usize) -> UntrustedNodeAddress {
891 UntrustedNodeAddress(id as *const c_void)
892 }
893}
894
895#[derive(Clone, Debug, Deserialize, Serialize)]
897pub struct PaintHitTestResult {
898 pub pipeline_id: PipelineId,
900
901 pub point_in_viewport: Point2D<f32, CSSPixel>,
903
904 pub external_scroll_id: ExternalScrollId,
906}
907
908#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
911pub enum AnimationState {
912 AnimationsPresent,
914 AnimationCallbacksPresent,
916 NoAnimationsPresent,
918 NoAnimationCallbacksPresent,
920}
921
922#[derive(
975 Clone,
976 Copy,
977 Debug,
978 Default,
979 Deserialize,
980 Eq,
981 Hash,
982 MallocSizeOf,
983 PartialEq,
984 Serialize,
985 PartialOrd,
986)]
987pub struct FocusSequenceNumber(pub u64);
988
989impl Display for FocusSequenceNumber {
990 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
991 Display::fmt(&self.0, f)
992 }
993}
994
995#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
998pub struct JavaScriptEvaluationId(pub usize);
999
1000#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1001pub enum JSValue {
1002 Undefined,
1003 Null,
1004 Boolean(bool),
1005 Number(f64),
1006 String(String),
1007 Element(String),
1008 ShadowRoot(String),
1009 Frame(String),
1010 Window(String),
1011 Array(Vec<JSValue>),
1012 Object(HashMap<String, JSValue>),
1013}
1014
1015#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1016pub struct JavaScriptErrorInfo {
1017 pub message: String,
1018 pub filename: String,
1019 pub stack: Option<String>,
1020 pub line_number: u64,
1021 pub column: u64,
1022}
1023
1024#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1027pub enum JavaScriptEvaluationResultSerializationError {
1028 DetachedShadowRoot,
1031 StaleElementReference,
1034 UnknownType,
1037 OtherJavaScriptError,
1041}
1042
1043#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1045pub enum JavaScriptEvaluationError {
1046 DocumentNotFound,
1048 CompilationFailure,
1050 EvaluationFailure(Option<JavaScriptErrorInfo>),
1052 InternalError,
1055 WebViewNotReady,
1058 SerializationError(JavaScriptEvaluationResultSerializationError),
1061}
1062
1063#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1064pub enum ScreenshotCaptureError {
1065 CouldNotReadImage,
1068 WebViewDoesNotExist,
1070}
1071
1072#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1073pub struct RgbColor {
1074 pub red: u8,
1075 pub green: u8,
1076 pub blue: u8,
1077}
1078
1079#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1081pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1082
1083impl ScriptToEmbedderChan {
1084 pub fn new(
1086 embedder_chan: Sender<EmbedderMsg>,
1087 waker: Box<dyn EventLoopWaker>,
1088 ) -> ScriptToEmbedderChan {
1089 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1090 let msg = match embedder_msg {
1091 Ok(embedder_msg) => embedder_msg,
1092 Err(err) => {
1093 log::warn!("Script to Embedder message error: {err}");
1094 return;
1095 },
1096 };
1097 let _ = embedder_chan.send(msg);
1098 waker.wake();
1099 })
1100 .expect("Failed to create channel");
1101 ScriptToEmbedderChan(embedder_callback)
1102 }
1103
1104 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1106 self.0.send(msg)
1107 }
1108}
1109
1110#[derive(Deserialize, Serialize)]
1113pub struct NewWebViewDetails {
1114 pub webview_id: WebViewId,
1115 pub viewport_details: ViewportDetails,
1116 pub user_content_manager_id: Option<UserContentManagerId>,
1117}
1118
1119#[derive(Serialize, Deserialize, Debug)]
1120pub struct UrlRequest {
1129 pub url: ServoUrl,
1130 #[serde(
1131 deserialize_with = "hyper_serde::deserialize",
1132 serialize_with = "hyper_serde::serialize"
1133 )]
1134 pub headers: HeaderMap,
1135}
1136
1137impl UrlRequest {
1138 pub fn new(url: Url) -> Self {
1139 UrlRequest {
1140 url: url.into(),
1141 headers: HeaderMap::new(),
1142 }
1143 }
1144
1145 pub fn headers(mut self, headers: HeaderMap) -> Self {
1147 self.headers = headers;
1148 self
1149 }
1150}