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)]
343pub enum PixelFormat {
344 K8,
346 KA8,
348 RGB8,
350 RGBA8,
352 BGRA8,
354}
355
356#[derive(Clone, Deserialize, Serialize)]
358pub struct Image {
359 pub width: u32,
360 pub height: u32,
361 pub format: PixelFormat,
362 data: Arc<GenericSharedMemory>,
364 range: Range<usize>,
365}
366
367impl Image {
368 pub fn new(
369 width: u32,
370 height: u32,
371 data: Arc<GenericSharedMemory>,
372 range: Range<usize>,
373 format: PixelFormat,
374 ) -> Self {
375 Self {
376 width,
377 height,
378 format,
379 data,
380 range,
381 }
382 }
383
384 pub fn data(&self) -> &[u8] {
386 &self.data[self.range.clone()]
387 }
388}
389
390#[derive(Clone, Debug, Deserialize, Serialize)]
391#[serde(rename_all = "lowercase")]
392pub enum ConsoleLogLevel {
393 Log,
394 Debug,
395 Info,
396 Warn,
397 Error,
398 Trace,
399}
400
401impl From<ConsoleLogLevel> for log::Level {
402 fn from(value: ConsoleLogLevel) -> Self {
403 match value {
404 ConsoleLogLevel::Log => log::Level::Info,
405 ConsoleLogLevel::Debug => log::Level::Debug,
406 ConsoleLogLevel::Info => log::Level::Info,
407 ConsoleLogLevel::Warn => log::Level::Warn,
408 ConsoleLogLevel::Error => log::Level::Error,
409 ConsoleLogLevel::Trace => log::Level::Trace,
410 }
411 }
412}
413
414#[derive(Deserialize, IntoStaticStr, Serialize)]
416pub enum EmbedderMsg {
417 Status(WebViewId, Option<String>),
419 ChangePageTitle(WebViewId, Option<String>),
421 MoveTo(WebViewId, DeviceIntPoint),
423 ResizeTo(WebViewId, DeviceIntSize),
425 ShowSimpleDialog(WebViewId, SimpleDialogRequest),
429 AllowNavigationRequest(WebViewId, PipelineId, ServoUrl),
431 AllowProtocolHandlerRequest(
433 WebViewId,
434 ProtocolHandlerUpdateRegistration,
435 GenericSender<AllowOrDeny>,
436 ),
437 AllowOpeningWebView(WebViewId, GenericSender<Option<NewWebViewDetails>>),
439 WebViewClosed(WebViewId),
441 WebViewFocused(WebViewId, bool),
444 WebViewBlurred,
446 AllowUnload(WebViewId, GenericSender<AllowOrDeny>),
448 ClearClipboard(WebViewId),
450 GetClipboardText(WebViewId, GenericCallback<Result<String, String>>),
452 SetClipboardText(WebViewId, String),
454 SetCursor(WebViewId, Cursor),
456 NewFavicon(WebViewId, Image),
458 HistoryChanged(WebViewId, Vec<ServoUrl>, usize),
460 HistoryTraversalComplete(WebViewId, TraversalId),
462 GetWindowRect(WebViewId, GenericSender<DeviceIndependentIntRect>),
464 GetScreenMetrics(WebViewId, GenericSender<ScreenMetrics>),
466 NotifyFullscreenStateChanged(WebViewId, bool),
468 NotifyLoadStatusChanged(WebViewId, LoadStatus),
470 Panic(WebViewId, String, Option<String>),
472 GetSelectedBluetoothDevice(WebViewId, Vec<String>, GenericSender<Option<String>>),
474 PromptPermission(WebViewId, PermissionFeature, GenericSender<AllowOrDeny>),
476 ReportProfile(Vec<u8>),
478 MediaSessionEvent(WebViewId, MediaSessionEvent),
481 OnDevtoolsStarted(Result<u16, ()>, String),
483 RequestDevtoolsConnection(GenericSender<AllowOrDeny>),
485 #[cfg(feature = "gamepad")]
487 PlayGamepadHapticEffect(
488 WebViewId,
489 usize,
490 GamepadHapticEffectType,
491 GenericCallback<bool>,
492 ),
493 #[cfg(feature = "gamepad")]
495 StopGamepadHapticEffect(WebViewId, usize, GenericCallback<bool>),
496 ShutdownComplete,
500 ShowNotification(Option<WebViewId>, Notification),
502 ShowConsoleApiMessage(Option<WebViewId>, ConsoleLogLevel, String),
505 ShowEmbedderControl(EmbedderControlId, DeviceIntRect, EmbedderControlRequest),
507 HideEmbedderControl(EmbedderControlId),
509 FinishJavaScriptEvaluation(
512 JavaScriptEvaluationId,
513 Result<JSValue, JavaScriptEvaluationError>,
514 ),
515 InputEventHandled(WebViewId, InputEventId, InputEventResult),
518 AccessibilityTreeUpdate(WebViewId, accesskit::TreeUpdate),
520}
521
522impl Debug for EmbedderMsg {
523 fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
524 let string: &'static str = self.into();
525 write!(formatter, "{string}")
526 }
527}
528
529#[derive(Clone, Debug, Deserialize, Serialize)]
531pub struct MediaMetadata {
532 pub title: String,
534 pub artist: String,
536 pub album: String,
538}
539
540impl MediaMetadata {
541 pub fn new(title: String) -> Self {
542 Self {
543 title,
544 artist: "".to_owned(),
545 album: "".to_owned(),
546 }
547 }
548}
549
550#[repr(i32)]
552#[derive(Clone, Debug, Deserialize, Serialize)]
553pub enum MediaSessionPlaybackState {
554 None_ = 1,
556 Playing,
558 Paused,
560}
561
562#[derive(Clone, Debug, Deserialize, Serialize)]
564pub struct MediaPositionState {
565 pub duration: f64,
566 pub playback_rate: f64,
567 pub position: f64,
568}
569
570impl MediaPositionState {
571 pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
572 Self {
573 duration,
574 playback_rate,
575 position,
576 }
577 }
578}
579
580#[derive(Clone, Debug, Deserialize, Serialize)]
582pub enum MediaSessionEvent {
583 SetMetadata(MediaMetadata),
585 PlaybackStateChange(MediaSessionPlaybackState),
587 SetPositionState(MediaPositionState),
589}
590
591#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
593pub enum PermissionFeature {
594 Geolocation,
595 Notifications,
596 Push,
597 Midi,
598 Camera,
599 Microphone,
600 Speaker,
601 DeviceInfo,
602 BackgroundSync,
603 Bluetooth,
604 PersistentStorage,
605}
606
607#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
611pub enum InputMethodType {
612 Color,
613 Date,
614 DatetimeLocal,
615 Email,
616 Month,
617 Number,
618 Password,
619 Search,
620 Tel,
621 Text,
622 Time,
623 Url,
624 Week,
625}
626
627#[cfg(feature = "gamepad")]
628#[derive(Clone, Debug, Deserialize, Serialize)]
629pub struct DualRumbleEffectParams {
631 pub duration: f64,
632 pub start_delay: f64,
633 pub strong_magnitude: f64,
634 pub weak_magnitude: f64,
635}
636
637#[cfg(feature = "gamepad")]
638#[derive(Clone, Debug, Deserialize, Serialize)]
639pub enum GamepadHapticEffectType {
641 DualRumble(DualRumbleEffectParams),
642}
643
644#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
645pub struct WebResourceRequest {
646 #[serde(
647 deserialize_with = "::hyper_serde::deserialize",
648 serialize_with = "::hyper_serde::serialize"
649 )]
650 #[ignore_malloc_size_of = "Defined in hyper"]
651 pub method: Method,
652 #[serde(
653 deserialize_with = "::hyper_serde::deserialize",
654 serialize_with = "::hyper_serde::serialize"
655 )]
656 #[ignore_malloc_size_of = "Defined in hyper"]
657 pub headers: HeaderMap,
658 pub url: Url,
659 pub is_for_main_frame: bool,
660 pub is_redirect: bool,
661}
662
663#[derive(Clone, Deserialize, Serialize)]
664pub enum WebResourceResponseMsg {
665 Start(WebResourceResponse),
669 SendBodyData(Vec<u8>),
671 FinishLoad,
673 CancelLoad,
675 DoNotIntercept,
677}
678
679#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
680pub struct WebResourceResponse {
681 pub url: Url,
682 #[serde(
683 deserialize_with = "::hyper_serde::deserialize",
684 serialize_with = "::hyper_serde::serialize"
685 )]
686 #[ignore_malloc_size_of = "Defined in hyper"]
687 pub headers: HeaderMap,
688 #[serde(
689 deserialize_with = "::hyper_serde::deserialize",
690 serialize_with = "::hyper_serde::serialize"
691 )]
692 #[ignore_malloc_size_of = "Defined in hyper"]
693 pub status_code: StatusCode,
694 pub status_message: Vec<u8>,
695}
696
697impl WebResourceResponse {
698 pub fn new(url: Url) -> WebResourceResponse {
699 WebResourceResponse {
700 url,
701 headers: HeaderMap::new(),
702 status_code: StatusCode::OK,
703 status_message: b"OK".to_vec(),
704 }
705 }
706
707 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
708 self.headers = headers;
709 self
710 }
711
712 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
713 self.status_code = status_code;
714 self
715 }
716
717 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
718 self.status_message = status_message;
719 self
720 }
721}
722
723#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
725pub enum Theme {
726 Light,
728 Dark,
730}
731
732impl From<Theme> for PrefersColorScheme {
733 fn from(value: Theme) -> Self {
734 match value {
735 Theme::Light => PrefersColorScheme::Light,
736 Theme::Dark => PrefersColorScheme::Dark,
737 }
738 }
739}
740
741#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
744pub enum MediaSessionActionType {
745 Play,
747 Pause,
749 SeekBackward,
752 SeekForward,
755 PreviousTrack,
759 NextTrack,
762 SkipAd,
764 Stop,
766 SeekTo,
768}
769
770#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
772pub enum LoadStatus {
773 Started,
775 HeadParsed,
778 Complete,
782}
783
784#[derive(Clone, Debug, Deserialize, Serialize)]
787pub struct Notification {
788 pub title: String,
790 pub body: String,
792 pub tag: String,
795 pub language: String,
797 pub require_interaction: bool,
800 pub silent: Option<bool>,
803 pub icon_url: Option<ServoUrl>,
805 pub icon_resource: Option<Arc<SharedRasterImage>>,
807 pub badge_url: Option<ServoUrl>,
810 pub badge_resource: Option<Arc<SharedRasterImage>>,
812 pub image_url: Option<ServoUrl>,
814 pub image_resource: Option<Arc<SharedRasterImage>>,
816 pub actions: Vec<NotificationAction>,
818}
819
820#[derive(Clone, Debug, Deserialize, Serialize)]
822pub struct NotificationAction {
823 pub name: String,
825 pub title: String,
827 pub icon_url: Option<ServoUrl>,
829 pub icon_resource: Option<Arc<SharedRasterImage>>,
831}
832
833#[derive(Clone, Copy, Debug, Default)]
839pub struct ScreenGeometry {
840 pub size: DeviceIntSize,
843 pub available_size: DeviceIntSize,
849 pub window_rect: DeviceIntRect,
854}
855
856impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
857 fn from(value: SelectElementOption) -> Self {
858 Self::Option(value)
859 }
860}
861
862#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
865pub struct UntrustedNodeAddress(pub *const c_void);
866
867malloc_size_of_is_0!(UntrustedNodeAddress);
868
869#[expect(unsafe_code)]
870unsafe impl Send for UntrustedNodeAddress {}
871
872impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
873 fn from(o: style_traits::dom::OpaqueNode) -> Self {
874 UntrustedNodeAddress(o.0 as *const c_void)
875 }
876}
877
878impl Serialize for UntrustedNodeAddress {
879 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
880 (self.0 as usize).serialize(s)
881 }
882}
883
884impl<'de> Deserialize<'de> for UntrustedNodeAddress {
885 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
886 let value: usize = Deserialize::deserialize(d)?;
887 Ok(UntrustedNodeAddress::from_id(value))
888 }
889}
890
891impl UntrustedNodeAddress {
892 #[inline]
894 pub fn from_id(id: usize) -> UntrustedNodeAddress {
895 UntrustedNodeAddress(id as *const c_void)
896 }
897}
898
899#[derive(Clone, Debug, Deserialize, Serialize)]
901pub struct PaintHitTestResult {
902 pub pipeline_id: PipelineId,
904
905 pub point_in_viewport: Point2D<f32, CSSPixel>,
907
908 pub external_scroll_id: ExternalScrollId,
910}
911
912#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
915pub enum AnimationState {
916 AnimationsPresent,
918 AnimationCallbacksPresent,
920 NoAnimationsPresent,
922 NoAnimationCallbacksPresent,
924}
925
926#[derive(
979 Clone,
980 Copy,
981 Debug,
982 Default,
983 Deserialize,
984 Eq,
985 Hash,
986 MallocSizeOf,
987 PartialEq,
988 Serialize,
989 PartialOrd,
990)]
991pub struct FocusSequenceNumber(pub u64);
992
993impl Display for FocusSequenceNumber {
994 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
995 Display::fmt(&self.0, f)
996 }
997}
998
999#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
1002pub struct JavaScriptEvaluationId(pub usize);
1003
1004#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1005pub enum JSValue {
1006 Undefined,
1007 Null,
1008 Boolean(bool),
1009 Number(f64),
1010 String(String),
1011 Element(String),
1012 ShadowRoot(String),
1013 Frame(String),
1014 Window(String),
1015 Array(Vec<JSValue>),
1016 Object(HashMap<String, JSValue>),
1017}
1018
1019#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1020pub struct JavaScriptErrorInfo {
1021 pub message: String,
1022 pub filename: String,
1023 pub stack: Option<String>,
1024 pub line_number: u64,
1025 pub column: u64,
1026}
1027
1028#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1031pub enum JavaScriptEvaluationResultSerializationError {
1032 DetachedShadowRoot,
1035 StaleElementReference,
1038 UnknownType,
1041 OtherJavaScriptError,
1045}
1046
1047#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1049pub enum JavaScriptEvaluationError {
1050 DocumentNotFound,
1052 CompilationFailure,
1054 EvaluationFailure(Option<JavaScriptErrorInfo>),
1056 InternalError,
1059 WebViewNotReady,
1062 SerializationError(JavaScriptEvaluationResultSerializationError),
1065}
1066
1067#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1068pub enum ScreenshotCaptureError {
1069 CouldNotReadImage,
1072 WebViewDoesNotExist,
1074}
1075
1076#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1077pub struct RgbColor {
1078 pub red: u8,
1079 pub green: u8,
1080 pub blue: u8,
1081}
1082
1083#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1085pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1086
1087impl ScriptToEmbedderChan {
1088 pub fn new(
1090 embedder_chan: Sender<EmbedderMsg>,
1091 waker: Box<dyn EventLoopWaker>,
1092 ) -> ScriptToEmbedderChan {
1093 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1094 let msg = match embedder_msg {
1095 Ok(embedder_msg) => embedder_msg,
1096 Err(err) => {
1097 log::warn!("Script to Embedder message error: {err}");
1098 return;
1099 },
1100 };
1101 let _ = embedder_chan.send(msg);
1102 waker.wake();
1103 })
1104 .expect("Failed to create channel");
1105 ScriptToEmbedderChan(embedder_callback)
1106 }
1107
1108 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1110 self.0.send(msg)
1111 }
1112}
1113
1114#[derive(Deserialize, Serialize)]
1117pub struct NewWebViewDetails {
1118 pub webview_id: WebViewId,
1119 pub viewport_details: ViewportDetails,
1120 pub user_content_manager_id: Option<UserContentManagerId>,
1121}