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 base::generic_channel::{GenericCallback, GenericSender, GenericSharedMemory, SendResult};
25use base::id::{PipelineId, WebViewId};
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_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize};
35use servo_url::ServoUrl;
36use strum::{EnumMessage, IntoStaticStr};
37use style::queries::values::PrefersColorScheme;
38use style_traits::CSSPixel;
39use url::Url;
40use uuid::Uuid;
41use webrender_api::ExternalScrollId;
42use webrender_api::units::{
43 DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel, DevicePoint, DeviceRect,
44 DeviceVector2D, LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D,
45};
46
47pub use crate::embedder_controls::*;
48pub use crate::input_events::*;
49use crate::user_contents::UserContentManagerId;
50pub use crate::webdriver::*;
51
52#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
56pub enum WebViewPoint {
57 Device(DevicePoint),
58 Page(Point2D<f32, CSSPixel>),
59}
60
61impl WebViewPoint {
62 pub fn as_device_point(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DevicePoint {
63 match self {
64 Self::Device(point) => *point,
65 Self::Page(point) => *point * scale,
66 }
67 }
68}
69
70impl From<DevicePoint> for WebViewPoint {
71 fn from(point: DevicePoint) -> Self {
72 Self::Device(point)
73 }
74}
75
76impl From<LayoutPoint> for WebViewPoint {
77 fn from(point: LayoutPoint) -> Self {
78 Self::Page(Point2D::new(point.x, point.y))
79 }
80}
81
82impl From<Point2D<f32, CSSPixel>> for WebViewPoint {
83 fn from(point: Point2D<f32, CSSPixel>) -> Self {
84 Self::Page(point)
85 }
86}
87
88#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
92pub enum WebViewRect {
93 Device(DeviceRect),
94 Page(Box2D<f32, CSSPixel>),
95}
96
97impl WebViewRect {
98 pub fn as_device_rect(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceRect {
99 match self {
100 Self::Device(rect) => *rect,
101 Self::Page(rect) => *rect * scale,
102 }
103 }
104}
105
106impl From<DeviceRect> for WebViewRect {
107 fn from(rect: DeviceRect) -> Self {
108 Self::Device(rect)
109 }
110}
111
112impl From<LayoutRect> for WebViewRect {
113 fn from(rect: LayoutRect) -> Self {
114 Self::Page(Box2D::new(
115 Point2D::new(rect.min.x, rect.min.y),
116 Point2D::new(rect.max.x, rect.max.y),
117 ))
118 }
119}
120
121impl From<Box2D<f32, CSSPixel>> for WebViewRect {
122 fn from(rect: Box2D<f32, CSSPixel>) -> Self {
123 Self::Page(rect)
124 }
125}
126
127#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
128pub enum WebViewVector {
129 Device(DeviceVector2D),
130 Page(Vector2D<f32, CSSPixel>),
131}
132
133impl WebViewVector {
134 pub fn as_device_vector(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceVector2D {
135 match self {
136 Self::Device(vector) => *vector,
137 Self::Page(vector) => *vector * scale,
138 }
139 }
140}
141
142impl From<DeviceVector2D> for WebViewVector {
143 fn from(vector: DeviceVector2D) -> Self {
144 Self::Device(vector)
145 }
146}
147
148impl From<LayoutVector2D> for WebViewVector {
149 fn from(vector: LayoutVector2D) -> Self {
150 Self::Page(Vector2D::new(vector.x, vector.y))
151 }
152}
153
154impl From<Vector2D<f32, CSSPixel>> for WebViewVector {
155 fn from(vector: Vector2D<f32, CSSPixel>) -> Self {
156 Self::Page(vector)
157 }
158}
159
160#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
161pub enum Scroll {
162 Delta(WebViewVector),
163 Start,
164 End,
165}
166
167#[derive(Clone, Copy, Debug, PartialEq)]
170pub enum ShutdownState {
171 NotShuttingDown,
172 ShuttingDown,
173 FinishedShuttingDown,
174}
175
176#[repr(u8)]
179#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
180pub enum Cursor {
181 None,
182 #[default]
183 Default,
184 Pointer,
185 ContextMenu,
186 Help,
187 Progress,
188 Wait,
189 Cell,
190 Crosshair,
191 Text,
192 VerticalText,
193 Alias,
194 Copy,
195 Move,
196 NoDrop,
197 NotAllowed,
198 Grab,
199 Grabbing,
200 EResize,
201 NResize,
202 NeResize,
203 NwResize,
204 SResize,
205 SeResize,
206 SwResize,
207 WResize,
208 EwResize,
209 NsResize,
210 NeswResize,
211 NwseResize,
212 ColResize,
213 RowResize,
214 AllScroll,
215 ZoomIn,
216 ZoomOut,
217}
218
219pub trait EventLoopWaker: 'static + Send + Sync {
220 fn clone_box(&self) -> Box<dyn EventLoopWaker>;
221 fn wake(&self) {}
222}
223
224impl Clone for Box<dyn EventLoopWaker> {
225 fn clone(&self) -> Self {
226 self.clone_box()
227 }
228}
229
230pub struct GenericEmbedderProxy<T> {
232 pub sender: Sender<T>,
233 pub event_loop_waker: Box<dyn EventLoopWaker>,
234}
235
236impl<T> GenericEmbedderProxy<T> {
237 pub fn send(&self, message: T) {
238 if let Err(err) = self.sender.send(message) {
240 warn!("Failed to send response ({:?}).", err);
241 }
242 self.event_loop_waker.wake();
243 }
244}
245
246impl<T> Clone for GenericEmbedderProxy<T> {
247 fn clone(&self) -> Self {
248 Self {
249 sender: self.sender.clone(),
250 event_loop_waker: self.event_loop_waker.clone(),
251 }
252 }
253}
254
255pub type EmbedderProxy = GenericEmbedderProxy<EmbedderMsg>;
256
257pub trait RefreshDriver {
262 fn observe_next_frame(&self, start_frame_callback: Box<dyn Fn() + Send + 'static>);
269}
270
271#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
272pub struct AuthenticationResponse {
273 pub username: String,
275 pub password: String,
277}
278
279#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
281pub enum AllowOrDeny {
282 Allow,
283 Deny,
284}
285
286#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
287pub enum RegisterOrUnregister {
289 Register,
290 Unregister,
291}
292
293#[derive(Clone, Debug, Deserialize, Serialize)]
294pub struct ProtocolHandlerUpdateRegistration {
295 pub scheme: String,
297 pub url: ServoUrl,
299 pub register_or_unregister: RegisterOrUnregister,
301}
302
303#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
306pub struct ViewportDetails {
307 pub size: Size2D<f32, CSSPixel>,
309
310 pub hidpi_scale_factor: Scale<f32, CSSPixel, DevicePixel>,
313}
314
315impl ViewportDetails {
316 pub fn layout_size(&self) -> LayoutSize {
319 Size2D::from_untyped(self.size.to_untyped())
320 }
321}
322
323#[derive(Default, Deserialize, Serialize)]
326pub struct ScreenMetrics {
327 pub screen_size: DeviceIndependentIntSize,
328 pub available_size: DeviceIndependentIntSize,
329}
330
331#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
333pub struct TraversalId(String);
334
335impl TraversalId {
336 #[expect(clippy::new_without_default)]
337 pub fn new() -> Self {
338 Self(Uuid::new_v4().to_string())
339 }
340}
341
342#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize, MallocSizeOf)]
343pub enum PixelFormat {
344 K8,
346 KA8,
348 RGB8,
350 RGBA8,
352 BGRA8,
354}
355
356#[derive(Clone, Deserialize, Serialize, MallocSizeOf)]
358pub struct Image {
359 pub width: u32,
360 pub height: u32,
361 pub format: PixelFormat,
362 #[conditional_malloc_size_of]
364 data: Arc<GenericSharedMemory>,
365 range: Range<usize>,
366}
367
368impl Image {
369 pub fn new(
370 width: u32,
371 height: u32,
372 data: Arc<GenericSharedMemory>,
373 range: Range<usize>,
374 format: PixelFormat,
375 ) -> Self {
376 Self {
377 width,
378 height,
379 format,
380 data,
381 range,
382 }
383 }
384
385 pub fn data(&self) -> &[u8] {
387 &self.data[self.range.clone()]
388 }
389}
390
391#[derive(Clone, Debug, Deserialize, Serialize, MallocSizeOf)]
392#[serde(rename_all = "lowercase")]
393pub enum ConsoleLogLevel {
394 Log,
395 Debug,
396 Info,
397 Warn,
398 Error,
399 Trace,
400}
401
402impl From<ConsoleLogLevel> for log::Level {
403 fn from(value: ConsoleLogLevel) -> Self {
404 match value {
405 ConsoleLogLevel::Log => log::Level::Info,
406 ConsoleLogLevel::Debug => log::Level::Debug,
407 ConsoleLogLevel::Info => log::Level::Info,
408 ConsoleLogLevel::Warn => log::Level::Warn,
409 ConsoleLogLevel::Error => log::Level::Error,
410 ConsoleLogLevel::Trace => log::Level::Trace,
411 }
412 }
413}
414
415#[derive(Deserialize, IntoStaticStr, Serialize)]
417pub enum EmbedderMsg {
418 Status(WebViewId, Option<String>),
420 ChangePageTitle(WebViewId, Option<String>),
422 MoveTo(WebViewId, DeviceIntPoint),
424 ResizeTo(WebViewId, DeviceIntSize),
426 ShowSimpleDialog(WebViewId, SimpleDialogRequest),
430 AllowNavigationRequest(WebViewId, PipelineId, ServoUrl),
432 AllowProtocolHandlerRequest(
434 WebViewId,
435 ProtocolHandlerUpdateRegistration,
436 GenericSender<AllowOrDeny>,
437 ),
438 AllowOpeningWebView(WebViewId, GenericSender<Option<NewWebViewDetails>>),
440 WebViewClosed(WebViewId),
442 WebViewFocused(WebViewId, bool),
445 WebViewBlurred,
447 AllowUnload(WebViewId, GenericSender<AllowOrDeny>),
449 ClearClipboard(WebViewId),
451 GetClipboardText(WebViewId, GenericCallback<Result<String, String>>),
453 SetClipboardText(WebViewId, String),
455 SetCursor(WebViewId, Cursor),
457 NewFavicon(WebViewId, Image),
459 HistoryChanged(WebViewId, Vec<ServoUrl>, usize),
461 HistoryTraversalComplete(WebViewId, TraversalId),
463 GetWindowRect(WebViewId, GenericSender<DeviceIndependentIntRect>),
465 GetScreenMetrics(WebViewId, GenericSender<ScreenMetrics>),
467 NotifyFullscreenStateChanged(WebViewId, bool),
469 NotifyLoadStatusChanged(WebViewId, LoadStatus),
471 Panic(WebViewId, String, Option<String>),
473 GetSelectedBluetoothDevice(WebViewId, Vec<String>, GenericSender<Option<String>>),
475 PromptPermission(WebViewId, PermissionFeature, GenericSender<AllowOrDeny>),
477 ReportProfile(Vec<u8>),
479 MediaSessionEvent(WebViewId, MediaSessionEvent),
482 OnDevtoolsStarted(Result<u16, ()>, String),
484 RequestDevtoolsConnection(GenericSender<AllowOrDeny>),
486 #[cfg(feature = "gamepad")]
488 PlayGamepadHapticEffect(
489 WebViewId,
490 usize,
491 GamepadHapticEffectType,
492 GenericCallback<bool>,
493 ),
494 #[cfg(feature = "gamepad")]
496 StopGamepadHapticEffect(WebViewId, usize, GenericCallback<bool>),
497 ShutdownComplete,
501 ShowNotification(Option<WebViewId>, Notification),
503 ShowConsoleApiMessage(Option<WebViewId>, ConsoleLogLevel, String),
506 ShowEmbedderControl(EmbedderControlId, DeviceIntRect, EmbedderControlRequest),
508 HideEmbedderControl(EmbedderControlId),
510 FinishJavaScriptEvaluation(
513 JavaScriptEvaluationId,
514 Result<JSValue, JavaScriptEvaluationError>,
515 ),
516 InputEventHandled(WebViewId, InputEventId, InputEventResult),
519 AccessibilityTreeUpdate(WebViewId, accesskit::TreeUpdate),
521}
522
523impl Debug for EmbedderMsg {
524 fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
525 let string: &'static str = self.into();
526 write!(formatter, "{string}")
527 }
528}
529
530#[derive(Clone, Debug, Deserialize, Serialize)]
532pub struct MediaMetadata {
533 pub title: String,
535 pub artist: String,
537 pub album: String,
539}
540
541impl MediaMetadata {
542 pub fn new(title: String) -> Self {
543 Self {
544 title,
545 artist: "".to_owned(),
546 album: "".to_owned(),
547 }
548 }
549}
550
551#[repr(i32)]
553#[derive(Clone, Debug, Deserialize, Serialize)]
554pub enum MediaSessionPlaybackState {
555 None_ = 1,
557 Playing,
559 Paused,
561}
562
563#[derive(Clone, Debug, Deserialize, Serialize)]
565pub struct MediaPositionState {
566 pub duration: f64,
567 pub playback_rate: f64,
568 pub position: f64,
569}
570
571impl MediaPositionState {
572 pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
573 Self {
574 duration,
575 playback_rate,
576 position,
577 }
578 }
579}
580
581#[derive(Clone, Debug, Deserialize, Serialize)]
583pub enum MediaSessionEvent {
584 SetMetadata(MediaMetadata),
586 PlaybackStateChange(MediaSessionPlaybackState),
588 SetPositionState(MediaPositionState),
590}
591
592#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
594pub enum PermissionFeature {
595 Geolocation,
596 Notifications,
597 Push,
598 Midi,
599 Camera,
600 Microphone,
601 Speaker,
602 DeviceInfo,
603 BackgroundSync,
604 Bluetooth,
605 PersistentStorage,
606}
607
608#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
612pub enum InputMethodType {
613 Color,
614 Date,
615 DatetimeLocal,
616 Email,
617 Month,
618 Number,
619 Password,
620 Search,
621 Tel,
622 Text,
623 Time,
624 Url,
625 Week,
626}
627
628#[cfg(feature = "gamepad")]
629#[derive(Clone, Debug, Deserialize, Serialize)]
630pub struct DualRumbleEffectParams {
632 pub duration: f64,
633 pub start_delay: f64,
634 pub strong_magnitude: f64,
635 pub weak_magnitude: f64,
636}
637
638#[cfg(feature = "gamepad")]
639#[derive(Clone, Debug, Deserialize, Serialize)]
640pub enum GamepadHapticEffectType {
642 DualRumble(DualRumbleEffectParams),
643}
644
645#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
646pub struct WebResourceRequest {
647 #[serde(
648 deserialize_with = "::hyper_serde::deserialize",
649 serialize_with = "::hyper_serde::serialize"
650 )]
651 #[ignore_malloc_size_of = "Defined in hyper"]
652 pub method: Method,
653 #[serde(
654 deserialize_with = "::hyper_serde::deserialize",
655 serialize_with = "::hyper_serde::serialize"
656 )]
657 #[ignore_malloc_size_of = "Defined in hyper"]
658 pub headers: HeaderMap,
659 pub url: Url,
660 pub is_for_main_frame: bool,
661 pub is_redirect: bool,
662}
663
664#[derive(Clone, Deserialize, Serialize)]
665pub enum WebResourceResponseMsg {
666 Start(WebResourceResponse),
670 SendBodyData(Vec<u8>),
672 FinishLoad,
674 CancelLoad,
676 DoNotIntercept,
678}
679
680#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
681pub struct WebResourceResponse {
682 pub url: Url,
683 #[serde(
684 deserialize_with = "::hyper_serde::deserialize",
685 serialize_with = "::hyper_serde::serialize"
686 )]
687 #[ignore_malloc_size_of = "Defined in hyper"]
688 pub headers: HeaderMap,
689 #[serde(
690 deserialize_with = "::hyper_serde::deserialize",
691 serialize_with = "::hyper_serde::serialize"
692 )]
693 #[ignore_malloc_size_of = "Defined in hyper"]
694 pub status_code: StatusCode,
695 pub status_message: Vec<u8>,
696}
697
698impl WebResourceResponse {
699 pub fn new(url: Url) -> WebResourceResponse {
700 WebResourceResponse {
701 url,
702 headers: HeaderMap::new(),
703 status_code: StatusCode::OK,
704 status_message: b"OK".to_vec(),
705 }
706 }
707
708 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
709 self.headers = headers;
710 self
711 }
712
713 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
714 self.status_code = status_code;
715 self
716 }
717
718 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
719 self.status_message = status_message;
720 self
721 }
722}
723
724#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
726pub enum Theme {
727 Light,
729 Dark,
731}
732
733impl From<Theme> for PrefersColorScheme {
734 fn from(value: Theme) -> Self {
735 match value {
736 Theme::Light => PrefersColorScheme::Light,
737 Theme::Dark => PrefersColorScheme::Dark,
738 }
739 }
740}
741
742#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
745pub enum MediaSessionActionType {
746 Play,
748 Pause,
750 SeekBackward,
753 SeekForward,
756 PreviousTrack,
760 NextTrack,
763 SkipAd,
765 Stop,
767 SeekTo,
769}
770
771#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
773pub enum LoadStatus {
774 Started,
776 HeadParsed,
779 Complete,
783}
784
785#[derive(Clone, Debug, Deserialize, Serialize)]
788pub struct Notification {
789 pub title: String,
791 pub body: String,
793 pub tag: String,
796 pub language: String,
798 pub require_interaction: bool,
801 pub silent: Option<bool>,
804 pub icon_url: Option<ServoUrl>,
806 pub icon_resource: Option<Arc<SharedRasterImage>>,
808 pub badge_url: Option<ServoUrl>,
811 pub badge_resource: Option<Arc<SharedRasterImage>>,
813 pub image_url: Option<ServoUrl>,
815 pub image_resource: Option<Arc<SharedRasterImage>>,
817 pub actions: Vec<NotificationAction>,
819}
820
821#[derive(Clone, Debug, Deserialize, Serialize)]
823pub struct NotificationAction {
824 pub name: String,
826 pub title: String,
828 pub icon_url: Option<ServoUrl>,
830 pub icon_resource: Option<Arc<SharedRasterImage>>,
832}
833
834#[derive(Clone, Copy, Debug, Default)]
840pub struct ScreenGeometry {
841 pub size: DeviceIntSize,
844 pub available_size: DeviceIntSize,
850 pub window_rect: DeviceIntRect,
855}
856
857impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
858 fn from(value: SelectElementOption) -> Self {
859 Self::Option(value)
860 }
861}
862
863#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
866pub struct UntrustedNodeAddress(pub *const c_void);
867
868malloc_size_of_is_0!(UntrustedNodeAddress);
869
870#[expect(unsafe_code)]
871unsafe impl Send for UntrustedNodeAddress {}
872
873impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
874 fn from(o: style_traits::dom::OpaqueNode) -> Self {
875 UntrustedNodeAddress(o.0 as *const c_void)
876 }
877}
878
879impl Serialize for UntrustedNodeAddress {
880 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
881 (self.0 as usize).serialize(s)
882 }
883}
884
885impl<'de> Deserialize<'de> for UntrustedNodeAddress {
886 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
887 let value: usize = Deserialize::deserialize(d)?;
888 Ok(UntrustedNodeAddress::from_id(value))
889 }
890}
891
892impl UntrustedNodeAddress {
893 #[inline]
895 pub fn from_id(id: usize) -> UntrustedNodeAddress {
896 UntrustedNodeAddress(id as *const c_void)
897 }
898}
899
900#[derive(Clone, Debug, Deserialize, Serialize)]
902pub struct PaintHitTestResult {
903 pub pipeline_id: PipelineId,
905
906 pub point_in_viewport: Point2D<f32, CSSPixel>,
908
909 pub external_scroll_id: ExternalScrollId,
911}
912
913#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
916pub enum AnimationState {
917 AnimationsPresent,
919 AnimationCallbacksPresent,
921 NoAnimationsPresent,
923 NoAnimationCallbacksPresent,
925}
926
927#[derive(
980 Clone,
981 Copy,
982 Debug,
983 Default,
984 Deserialize,
985 Eq,
986 Hash,
987 MallocSizeOf,
988 PartialEq,
989 Serialize,
990 PartialOrd,
991)]
992pub struct FocusSequenceNumber(pub u64);
993
994impl Display for FocusSequenceNumber {
995 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
996 Display::fmt(&self.0, f)
997 }
998}
999
1000#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
1003pub struct JavaScriptEvaluationId(pub usize);
1004
1005#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1006pub enum JSValue {
1007 Undefined,
1008 Null,
1009 Boolean(bool),
1010 Number(f64),
1011 String(String),
1012 Element(String),
1013 ShadowRoot(String),
1014 Frame(String),
1015 Window(String),
1016 Array(Vec<JSValue>),
1017 Object(HashMap<String, JSValue>),
1018}
1019
1020#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1021pub struct JavaScriptErrorInfo {
1022 pub message: String,
1023 pub filename: String,
1024 pub stack: Option<String>,
1025 pub line_number: u64,
1026 pub column: u64,
1027}
1028
1029#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1032pub enum JavaScriptEvaluationResultSerializationError {
1033 DetachedShadowRoot,
1036 StaleElementReference,
1039 UnknownType,
1042 OtherJavaScriptError,
1046}
1047
1048#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1050pub enum JavaScriptEvaluationError {
1051 DocumentNotFound,
1053 CompilationFailure,
1055 EvaluationFailure(Option<JavaScriptErrorInfo>),
1057 InternalError,
1060 WebViewNotReady,
1063 SerializationError(JavaScriptEvaluationResultSerializationError),
1066}
1067
1068#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1069pub enum ScreenshotCaptureError {
1070 CouldNotReadImage,
1073 WebViewDoesNotExist,
1075}
1076
1077#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1078pub struct RgbColor {
1079 pub red: u8,
1080 pub green: u8,
1081 pub blue: u8,
1082}
1083
1084#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1086pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1087
1088impl ScriptToEmbedderChan {
1089 pub fn new(
1091 embedder_chan: Sender<EmbedderMsg>,
1092 waker: Box<dyn EventLoopWaker>,
1093 ) -> ScriptToEmbedderChan {
1094 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1095 let msg = match embedder_msg {
1096 Ok(embedder_msg) => embedder_msg,
1097 Err(err) => {
1098 log::warn!("Script to Embedder message error: {err}");
1099 return;
1100 },
1101 };
1102 let _ = embedder_chan.send(msg);
1103 waker.wake();
1104 })
1105 .expect("Failed to create channel");
1106 ScriptToEmbedderChan(embedder_callback)
1107 }
1108
1109 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1111 self.0.send(msg)
1112 }
1113}
1114
1115#[derive(Deserialize, Serialize)]
1118pub struct NewWebViewDetails {
1119 pub webview_id: WebViewId,
1120 pub viewport_details: ViewportDetails,
1121 pub user_content_manager_id: Option<UserContentManagerId>,
1122}