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::generic_channel::{
34 GenericCallback, GenericSender, GenericSharedMemory, SendResult,
35};
36use servo_base::id::{PipelineId, WebViewId};
37use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize};
38use servo_url::ServoUrl;
39use strum::{EnumMessage, IntoStaticStr};
40use style::queries::values::PrefersColorScheme;
41use style_traits::CSSPixel;
42use url::Url;
43use uuid::Uuid;
44use webrender_api::ExternalScrollId;
45use webrender_api::units::{
46 DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel, DevicePoint, DeviceRect,
47 DeviceVector2D, LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D,
48};
49
50pub use crate::embedder_controls::*;
51pub use crate::input_events::*;
52use crate::user_contents::UserContentManagerId;
53pub use crate::webdriver::*;
54
55#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
59pub enum WebViewPoint {
60 Device(DevicePoint),
61 Page(Point2D<f32, CSSPixel>),
62}
63
64impl WebViewPoint {
65 pub fn as_device_point(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DevicePoint {
66 match self {
67 Self::Device(point) => *point,
68 Self::Page(point) => *point * scale,
69 }
70 }
71}
72
73impl From<DevicePoint> for WebViewPoint {
74 fn from(point: DevicePoint) -> Self {
75 Self::Device(point)
76 }
77}
78
79impl From<LayoutPoint> for WebViewPoint {
80 fn from(point: LayoutPoint) -> Self {
81 Self::Page(Point2D::new(point.x, point.y))
82 }
83}
84
85impl From<Point2D<f32, CSSPixel>> for WebViewPoint {
86 fn from(point: Point2D<f32, CSSPixel>) -> Self {
87 Self::Page(point)
88 }
89}
90
91#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
95pub enum WebViewRect {
96 Device(DeviceRect),
97 Page(Box2D<f32, CSSPixel>),
98}
99
100impl WebViewRect {
101 pub fn as_device_rect(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceRect {
102 match self {
103 Self::Device(rect) => *rect,
104 Self::Page(rect) => *rect * scale,
105 }
106 }
107}
108
109impl From<DeviceRect> for WebViewRect {
110 fn from(rect: DeviceRect) -> Self {
111 Self::Device(rect)
112 }
113}
114
115impl From<LayoutRect> for WebViewRect {
116 fn from(rect: LayoutRect) -> Self {
117 Self::Page(Box2D::new(
118 Point2D::new(rect.min.x, rect.min.y),
119 Point2D::new(rect.max.x, rect.max.y),
120 ))
121 }
122}
123
124impl From<Box2D<f32, CSSPixel>> for WebViewRect {
125 fn from(rect: Box2D<f32, CSSPixel>) -> Self {
126 Self::Page(rect)
127 }
128}
129
130#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
131pub enum WebViewVector {
132 Device(DeviceVector2D),
133 Page(Vector2D<f32, CSSPixel>),
134}
135
136impl WebViewVector {
137 pub fn as_device_vector(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceVector2D {
138 match self {
139 Self::Device(vector) => *vector,
140 Self::Page(vector) => *vector * scale,
141 }
142 }
143}
144
145impl From<DeviceVector2D> for WebViewVector {
146 fn from(vector: DeviceVector2D) -> Self {
147 Self::Device(vector)
148 }
149}
150
151impl From<LayoutVector2D> for WebViewVector {
152 fn from(vector: LayoutVector2D) -> Self {
153 Self::Page(Vector2D::new(vector.x, vector.y))
154 }
155}
156
157impl From<Vector2D<f32, CSSPixel>> for WebViewVector {
158 fn from(vector: Vector2D<f32, CSSPixel>) -> Self {
159 Self::Page(vector)
160 }
161}
162
163#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
164pub enum Scroll {
165 Delta(WebViewVector),
166 Start,
167 End,
168}
169
170#[derive(Clone, Copy, Debug, PartialEq)]
173pub enum ShutdownState {
174 NotShuttingDown,
175 ShuttingDown,
176 FinishedShuttingDown,
177}
178
179#[repr(u8)]
182#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
183pub enum Cursor {
184 None,
185 #[default]
186 Default,
187 Pointer,
188 ContextMenu,
189 Help,
190 Progress,
191 Wait,
192 Cell,
193 Crosshair,
194 Text,
195 VerticalText,
196 Alias,
197 Copy,
198 Move,
199 NoDrop,
200 NotAllowed,
201 Grab,
202 Grabbing,
203 EResize,
204 NResize,
205 NeResize,
206 NwResize,
207 SResize,
208 SeResize,
209 SwResize,
210 WResize,
211 EwResize,
212 NsResize,
213 NeswResize,
214 NwseResize,
215 ColResize,
216 RowResize,
217 AllScroll,
218 ZoomIn,
219 ZoomOut,
220}
221
222pub trait EventLoopWaker: 'static + Send + Sync {
227 fn clone_box(&self) -> Box<dyn EventLoopWaker>;
228
229 fn wake(&self);
235}
236
237impl Clone for Box<dyn EventLoopWaker> {
238 fn clone(&self) -> Self {
239 self.clone_box()
240 }
241}
242
243pub struct GenericEmbedderProxy<T> {
245 pub sender: Sender<T>,
246 pub event_loop_waker: Box<dyn EventLoopWaker>,
247}
248
249impl<T> GenericEmbedderProxy<T> {
250 pub fn send(&self, message: T) {
251 if let Err(err) = self.sender.send(message) {
253 warn!("Failed to send response ({:?}).", err);
254 }
255 self.event_loop_waker.wake();
256 }
257}
258
259impl<T> Clone for GenericEmbedderProxy<T> {
260 fn clone(&self) -> Self {
261 Self {
262 sender: self.sender.clone(),
263 event_loop_waker: self.event_loop_waker.clone(),
264 }
265 }
266}
267
268pub type EmbedderProxy = GenericEmbedderProxy<EmbedderMsg>;
269
270pub trait RefreshDriver {
275 fn observe_next_frame(&self, start_frame_callback: Box<dyn Fn() + Send + 'static>);
282}
283
284#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
285pub struct AuthenticationResponse {
286 pub username: String,
288 pub password: String,
290}
291
292#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
294pub enum AllowOrDeny {
295 Allow,
296 Deny,
297}
298
299#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
300pub enum RegisterOrUnregister {
302 Register,
303 Unregister,
304}
305
306#[derive(Clone, Debug, Deserialize, Serialize)]
307pub struct ProtocolHandlerUpdateRegistration {
308 pub scheme: String,
310 pub url: ServoUrl,
312 pub register_or_unregister: RegisterOrUnregister,
314}
315
316#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
319pub struct ViewportDetails {
320 pub size: Size2D<f32, CSSPixel>,
322
323 pub hidpi_scale_factor: Scale<f32, CSSPixel, DevicePixel>,
326}
327
328impl ViewportDetails {
329 pub fn layout_size(&self) -> LayoutSize {
332 Size2D::from_untyped(self.size.to_untyped())
333 }
334}
335
336#[derive(Default, Deserialize, Serialize)]
339pub struct ScreenMetrics {
340 pub screen_size: DeviceIndependentIntSize,
341 pub available_size: DeviceIndependentIntSize,
342}
343
344#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
346pub struct TraversalId(String);
347
348impl TraversalId {
349 #[expect(clippy::new_without_default)]
350 pub fn new() -> Self {
351 Self(Uuid::new_v4().to_string())
352 }
353}
354
355#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, MallocSizeOf)]
356pub enum PixelFormat {
357 K8,
359 KA8,
361 RGB8,
363 RGBA8,
365 BGRA8,
367}
368
369#[derive(Clone, Deserialize, Serialize, MallocSizeOf)]
371pub struct Image {
372 pub width: u32,
373 pub height: u32,
374 pub format: PixelFormat,
375 #[conditional_malloc_size_of]
377 data: Arc<GenericSharedMemory>,
378 range: Range<usize>,
379}
380
381impl Image {
382 pub fn new(
383 width: u32,
384 height: u32,
385 data: Arc<GenericSharedMemory>,
386 range: Range<usize>,
387 format: PixelFormat,
388 ) -> Self {
389 Self {
390 width,
391 height,
392 format,
393 data,
394 range,
395 }
396 }
397
398 pub fn data(&self) -> &[u8] {
400 &self.data[self.range.clone()]
401 }
402}
403
404#[derive(Clone, Debug, Deserialize, Serialize, MallocSizeOf)]
405#[serde(rename_all = "lowercase")]
406pub enum ConsoleLogLevel {
407 Log,
408 Debug,
409 Info,
410 Warn,
411 Error,
412 Trace,
413}
414
415impl From<ConsoleLogLevel> for log::Level {
416 fn from(value: ConsoleLogLevel) -> Self {
417 match value {
418 ConsoleLogLevel::Log => log::Level::Info,
419 ConsoleLogLevel::Debug => log::Level::Debug,
420 ConsoleLogLevel::Info => log::Level::Info,
421 ConsoleLogLevel::Warn => log::Level::Warn,
422 ConsoleLogLevel::Error => log::Level::Error,
423 ConsoleLogLevel::Trace => log::Level::Trace,
424 }
425 }
426}
427
428#[derive(Clone, Deserialize, Serialize)]
429pub struct BluetoothDeviceDescription {
430 pub address: String,
431 pub name: String,
432}
433
434#[derive(Deserialize, IntoStaticStr, Serialize)]
436pub enum EmbedderMsg {
437 Status(WebViewId, Option<String>),
439 ChangePageTitle(WebViewId, Option<String>),
441 MoveTo(WebViewId, DeviceIntPoint),
443 ResizeTo(WebViewId, DeviceIntSize),
445 ShowSimpleDialog(WebViewId, SimpleDialogRequest),
449 AllowProtocolHandlerRequest(
451 WebViewId,
452 ProtocolHandlerUpdateRegistration,
453 GenericSender<AllowOrDeny>,
454 ),
455 AllowUnload(WebViewId, GenericSender<AllowOrDeny>),
457 ClearClipboard(WebViewId),
459 GetClipboardText(WebViewId, GenericCallback<Result<String, String>>),
461 SetClipboardText(WebViewId, String),
463 SetCursor(WebViewId, Cursor),
465 NewFavicon(WebViewId, Image),
467 GetWindowRect(WebViewId, GenericSender<DeviceIndependentIntRect>),
469 GetScreenMetrics(WebViewId, GenericSender<ScreenMetrics>),
471 NotifyFullscreenStateChanged(WebViewId, bool),
473 NotifyLoadStatusChanged(WebViewId, LoadStatus),
475 GetSelectedBluetoothDevice(
477 WebViewId,
478 Vec<BluetoothDeviceDescription>,
479 GenericSender<Option<String>>,
480 ),
481 PromptPermission(WebViewId, PermissionFeature, GenericSender<AllowOrDeny>),
483 OnDevtoolsStarted(Result<u16, ()>, String),
485 RequestDevtoolsConnection(GenericSender<AllowOrDeny>),
487 #[cfg(feature = "gamepad")]
489 PlayGamepadHapticEffect(
490 WebViewId,
491 usize,
492 GamepadHapticEffectType,
493 GenericCallback<bool>,
494 ),
495 #[cfg(feature = "gamepad")]
497 StopGamepadHapticEffect(WebViewId, usize, GenericCallback<bool>),
498 ShowNotification(Option<WebViewId>, Notification),
500 ShowConsoleApiMessage(Option<WebViewId>, ConsoleLogLevel, String),
503 ShowEmbedderControl(EmbedderControlId, DeviceIntRect, EmbedderControlRequest),
505 HideEmbedderControl(EmbedderControlId),
507 InputEventsHandled(WebViewId, Vec<InputEventOutcome>),
510 AccessibilityTreeUpdate(WebViewId, TreeUpdate),
512}
513
514impl Debug for EmbedderMsg {
515 fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
516 let string: &'static str = self.into();
517 write!(formatter, "{string}")
518 }
519}
520
521#[derive(Clone, Debug, Deserialize, Serialize)]
523pub struct MediaMetadata {
524 pub title: String,
526 pub artist: String,
528 pub album: String,
530}
531
532impl MediaMetadata {
533 pub fn new(title: String) -> Self {
534 Self {
535 title,
536 artist: "".to_owned(),
537 album: "".to_owned(),
538 }
539 }
540}
541
542#[repr(i32)]
544#[derive(Clone, Debug, Deserialize, Serialize)]
545pub enum MediaSessionPlaybackState {
546 None_ = 1,
548 Playing,
550 Paused,
552}
553
554#[derive(Clone, Debug, Deserialize, Serialize)]
556pub struct MediaPositionState {
557 pub duration: f64,
558 pub playback_rate: f64,
559 pub position: f64,
560}
561
562impl MediaPositionState {
563 pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
564 Self {
565 duration,
566 playback_rate,
567 position,
568 }
569 }
570}
571
572#[derive(Clone, Debug, Deserialize, Serialize)]
574pub enum MediaSessionEvent {
575 SetMetadata(MediaMetadata),
577 PlaybackStateChange(MediaSessionPlaybackState),
579 SetPositionState(MediaPositionState),
581}
582
583#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
585pub enum PermissionFeature {
586 Geolocation,
587 Notifications,
588 Push,
589 Midi,
590 Camera,
591 Microphone,
592 Speaker,
593 DeviceInfo,
594 BackgroundSync,
595 Bluetooth,
596 PersistentStorage,
597}
598
599#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
603pub enum InputMethodType {
604 Color,
605 Date,
606 DatetimeLocal,
607 Email,
608 Month,
609 Number,
610 Password,
611 Search,
612 Tel,
613 Text,
614 Time,
615 Url,
616 Week,
617}
618
619#[cfg(feature = "gamepad")]
620#[derive(Clone, Debug, Deserialize, Serialize)]
621pub struct DualRumbleEffectParams {
623 pub duration: f64,
624 pub start_delay: f64,
625 pub strong_magnitude: f64,
626 pub weak_magnitude: f64,
627}
628
629#[cfg(feature = "gamepad")]
630#[derive(Clone, Debug, Deserialize, Serialize)]
631pub enum GamepadHapticEffectType {
633 DualRumble(DualRumbleEffectParams),
634}
635
636#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
637pub struct WebResourceRequest {
638 #[serde(
639 deserialize_with = "::hyper_serde::deserialize",
640 serialize_with = "::hyper_serde::serialize"
641 )]
642 #[ignore_malloc_size_of = "Defined in hyper"]
643 pub method: Method,
644 #[serde(
645 deserialize_with = "::hyper_serde::deserialize",
646 serialize_with = "::hyper_serde::serialize"
647 )]
648 #[ignore_malloc_size_of = "Defined in hyper"]
649 pub headers: HeaderMap,
650 pub url: Url,
651 pub is_for_main_frame: bool,
652 pub is_redirect: bool,
653}
654
655#[derive(Clone, Deserialize, Serialize)]
656pub enum WebResourceResponseMsg {
657 Start(WebResourceResponse),
661 SendBodyData(Vec<u8>),
663 FinishLoad,
665 CancelLoad,
667 DoNotIntercept,
669}
670
671#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
672pub struct WebResourceResponse {
673 pub url: Url,
674 #[serde(
675 deserialize_with = "::hyper_serde::deserialize",
676 serialize_with = "::hyper_serde::serialize"
677 )]
678 #[ignore_malloc_size_of = "Defined in hyper"]
679 pub headers: HeaderMap,
680 #[serde(
681 deserialize_with = "::hyper_serde::deserialize",
682 serialize_with = "::hyper_serde::serialize"
683 )]
684 #[ignore_malloc_size_of = "Defined in hyper"]
685 pub status_code: StatusCode,
686 pub status_message: Vec<u8>,
687}
688
689impl WebResourceResponse {
690 pub fn new(url: Url) -> WebResourceResponse {
691 WebResourceResponse {
692 url,
693 headers: HeaderMap::new(),
694 status_code: StatusCode::OK,
695 status_message: b"OK".to_vec(),
696 }
697 }
698
699 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
700 self.headers = headers;
701 self
702 }
703
704 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
705 self.status_code = status_code;
706 self
707 }
708
709 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
710 self.status_message = status_message;
711 self
712 }
713}
714
715#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
717pub enum Theme {
718 Light,
720 Dark,
722}
723
724impl From<Theme> for PrefersColorScheme {
725 fn from(value: Theme) -> Self {
726 match value {
727 Theme::Light => PrefersColorScheme::Light,
728 Theme::Dark => PrefersColorScheme::Dark,
729 }
730 }
731}
732
733#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
736pub enum MediaSessionActionType {
737 Play,
739 Pause,
741 SeekBackward,
744 SeekForward,
747 PreviousTrack,
751 NextTrack,
754 SkipAd,
756 Stop,
758 SeekTo,
760}
761
762#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
764pub enum LoadStatus {
765 Started,
767 HeadParsed,
770 Complete,
774}
775
776#[derive(Clone, Debug, Deserialize, Serialize)]
779pub struct Notification {
780 pub title: String,
782 pub body: String,
784 pub tag: String,
787 pub language: String,
789 pub require_interaction: bool,
792 pub silent: Option<bool>,
795 pub icon_url: Option<ServoUrl>,
797 pub icon_resource: Option<Arc<SharedRasterImage>>,
799 pub badge_url: Option<ServoUrl>,
802 pub badge_resource: Option<Arc<SharedRasterImage>>,
804 pub image_url: Option<ServoUrl>,
806 pub image_resource: Option<Arc<SharedRasterImage>>,
808 pub actions: Vec<NotificationAction>,
810}
811
812#[derive(Clone, Debug, Deserialize, Serialize)]
814pub struct NotificationAction {
815 pub name: String,
817 pub title: String,
819 pub icon_url: Option<ServoUrl>,
821 pub icon_resource: Option<Arc<SharedRasterImage>>,
823}
824
825#[derive(Clone, Copy, Debug, Default)]
831pub struct ScreenGeometry {
832 pub size: DeviceIntSize,
835 pub available_size: DeviceIntSize,
841 pub window_rect: DeviceIntRect,
846}
847
848impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
849 fn from(value: SelectElementOption) -> Self {
850 Self::Option(value)
851 }
852}
853
854#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
857pub struct UntrustedNodeAddress(pub *const c_void);
858
859malloc_size_of_is_0!(UntrustedNodeAddress);
860
861#[expect(unsafe_code)]
862unsafe impl Send for UntrustedNodeAddress {}
863
864impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
865 fn from(o: style_traits::dom::OpaqueNode) -> Self {
866 UntrustedNodeAddress(o.0 as *const c_void)
867 }
868}
869
870impl Serialize for UntrustedNodeAddress {
871 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
872 (self.0 as usize).serialize(s)
873 }
874}
875
876impl<'de> Deserialize<'de> for UntrustedNodeAddress {
877 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
878 let value: usize = Deserialize::deserialize(d)?;
879 Ok(UntrustedNodeAddress::from_id(value))
880 }
881}
882
883impl UntrustedNodeAddress {
884 #[inline]
886 pub fn from_id(id: usize) -> UntrustedNodeAddress {
887 UntrustedNodeAddress(id as *const c_void)
888 }
889}
890
891#[derive(Clone, Debug, Deserialize, Serialize)]
893pub struct PaintHitTestResult {
894 pub pipeline_id: PipelineId,
896
897 pub point_in_viewport: Point2D<f32, CSSPixel>,
899
900 pub external_scroll_id: ExternalScrollId,
902}
903
904#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
907pub enum AnimationState {
908 AnimationsPresent,
910 AnimationCallbacksPresent,
912 NoAnimationsPresent,
914 NoAnimationCallbacksPresent,
916}
917
918#[derive(
971 Clone,
972 Copy,
973 Debug,
974 Default,
975 Deserialize,
976 Eq,
977 Hash,
978 MallocSizeOf,
979 PartialEq,
980 Serialize,
981 PartialOrd,
982)]
983pub struct FocusSequenceNumber(pub u64);
984
985impl Display for FocusSequenceNumber {
986 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
987 Display::fmt(&self.0, f)
988 }
989}
990
991#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
994pub struct JavaScriptEvaluationId(pub usize);
995
996#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
997pub enum JSValue {
998 Undefined,
999 Null,
1000 Boolean(bool),
1001 Number(f64),
1002 String(String),
1003 Element(String),
1004 ShadowRoot(String),
1005 Frame(String),
1006 Window(String),
1007 Array(Vec<JSValue>),
1008 Object(HashMap<String, JSValue>),
1009}
1010
1011#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1012pub struct JavaScriptErrorInfo {
1013 pub message: String,
1014 pub filename: String,
1015 pub stack: Option<String>,
1016 pub line_number: u64,
1017 pub column: u64,
1018}
1019
1020#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1023pub enum JavaScriptEvaluationResultSerializationError {
1024 DetachedShadowRoot,
1027 StaleElementReference,
1030 UnknownType,
1033 OtherJavaScriptError,
1037}
1038
1039#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1041pub enum JavaScriptEvaluationError {
1042 DocumentNotFound,
1044 CompilationFailure,
1046 EvaluationFailure(Option<JavaScriptErrorInfo>),
1048 InternalError,
1051 WebViewNotReady,
1054 SerializationError(JavaScriptEvaluationResultSerializationError),
1057}
1058
1059#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1060pub enum ScreenshotCaptureError {
1061 CouldNotReadImage,
1064 WebViewDoesNotExist,
1066}
1067
1068#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1069pub struct RgbColor {
1070 pub red: u8,
1071 pub green: u8,
1072 pub blue: u8,
1073}
1074
1075#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1077pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1078
1079impl ScriptToEmbedderChan {
1080 pub fn new(
1082 embedder_chan: Sender<EmbedderMsg>,
1083 waker: Box<dyn EventLoopWaker>,
1084 ) -> ScriptToEmbedderChan {
1085 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1086 let msg = match embedder_msg {
1087 Ok(embedder_msg) => embedder_msg,
1088 Err(err) => {
1089 log::warn!("Script to Embedder message error: {err}");
1090 return;
1091 },
1092 };
1093 let _ = embedder_chan.send(msg);
1094 waker.wake();
1095 })
1096 .expect("Failed to create channel");
1097 ScriptToEmbedderChan(embedder_callback)
1098 }
1099
1100 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1102 self.0.send(msg)
1103 }
1104}
1105
1106#[derive(Deserialize, Serialize)]
1109pub struct NewWebViewDetails {
1110 pub webview_id: WebViewId,
1111 pub viewport_details: ViewportDetails,
1112 pub user_content_manager_id: Option<UserContentManagerId>,
1113}