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 pub method: Method,
643 #[serde(
644 deserialize_with = "::hyper_serde::deserialize",
645 serialize_with = "::hyper_serde::serialize"
646 )]
647 pub headers: HeaderMap,
648 pub url: Url,
649 pub is_for_main_frame: bool,
650 pub is_redirect: bool,
651}
652
653#[derive(Clone, Deserialize, Serialize)]
654pub enum WebResourceResponseMsg {
655 Start(WebResourceResponse),
659 SendBodyData(Vec<u8>),
661 FinishLoad,
663 CancelLoad,
665 DoNotIntercept,
667}
668
669#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
670pub struct WebResourceResponse {
671 pub url: Url,
672 #[serde(
673 deserialize_with = "::hyper_serde::deserialize",
674 serialize_with = "::hyper_serde::serialize"
675 )]
676 #[ignore_malloc_size_of = "Defined in hyper"]
677 pub headers: HeaderMap,
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 status_code: StatusCode,
684 pub status_message: Vec<u8>,
685}
686
687impl WebResourceResponse {
688 pub fn new(url: Url) -> WebResourceResponse {
689 WebResourceResponse {
690 url,
691 headers: HeaderMap::new(),
692 status_code: StatusCode::OK,
693 status_message: b"OK".to_vec(),
694 }
695 }
696
697 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
698 self.headers = headers;
699 self
700 }
701
702 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
703 self.status_code = status_code;
704 self
705 }
706
707 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
708 self.status_message = status_message;
709 self
710 }
711}
712
713#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
715pub enum Theme {
716 Light,
718 Dark,
720}
721
722impl From<Theme> for PrefersColorScheme {
723 fn from(value: Theme) -> Self {
724 match value {
725 Theme::Light => PrefersColorScheme::Light,
726 Theme::Dark => PrefersColorScheme::Dark,
727 }
728 }
729}
730
731#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
734pub enum MediaSessionActionType {
735 Play,
737 Pause,
739 SeekBackward,
742 SeekForward,
745 PreviousTrack,
749 NextTrack,
752 SkipAd,
754 Stop,
756 SeekTo,
758}
759
760#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
762pub enum LoadStatus {
763 Started,
765 HeadParsed,
768 Complete,
772}
773
774#[derive(Clone, Debug, Deserialize, Serialize)]
777pub struct Notification {
778 pub title: String,
780 pub body: String,
782 pub tag: String,
785 pub language: String,
787 pub require_interaction: bool,
790 pub silent: Option<bool>,
793 pub icon_url: Option<ServoUrl>,
795 pub icon_resource: Option<Arc<SharedRasterImage>>,
797 pub badge_url: Option<ServoUrl>,
800 pub badge_resource: Option<Arc<SharedRasterImage>>,
802 pub image_url: Option<ServoUrl>,
804 pub image_resource: Option<Arc<SharedRasterImage>>,
806 pub actions: Vec<NotificationAction>,
808}
809
810#[derive(Clone, Debug, Deserialize, Serialize)]
812pub struct NotificationAction {
813 pub name: String,
815 pub title: String,
817 pub icon_url: Option<ServoUrl>,
819 pub icon_resource: Option<Arc<SharedRasterImage>>,
821}
822
823#[derive(Clone, Copy, Debug, Default)]
829pub struct ScreenGeometry {
830 pub size: DeviceIntSize,
833 pub available_size: DeviceIntSize,
839 pub window_rect: DeviceIntRect,
844}
845
846impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
847 fn from(value: SelectElementOption) -> Self {
848 Self::Option(value)
849 }
850}
851
852#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
855pub struct UntrustedNodeAddress(pub *const c_void);
856
857malloc_size_of_is_0!(UntrustedNodeAddress);
858
859#[expect(unsafe_code)]
860unsafe impl Send for UntrustedNodeAddress {}
861
862impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
863 fn from(o: style_traits::dom::OpaqueNode) -> Self {
864 UntrustedNodeAddress(o.0 as *const c_void)
865 }
866}
867
868impl Serialize for UntrustedNodeAddress {
869 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
870 (self.0 as usize).serialize(s)
871 }
872}
873
874impl<'de> Deserialize<'de> for UntrustedNodeAddress {
875 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
876 let value: usize = Deserialize::deserialize(d)?;
877 Ok(UntrustedNodeAddress::from_id(value))
878 }
879}
880
881impl UntrustedNodeAddress {
882 #[inline]
884 pub fn from_id(id: usize) -> UntrustedNodeAddress {
885 UntrustedNodeAddress(id as *const c_void)
886 }
887}
888
889#[derive(Clone, Debug, Deserialize, Serialize)]
891pub struct PaintHitTestResult {
892 pub pipeline_id: PipelineId,
894
895 pub point_in_viewport: Point2D<f32, CSSPixel>,
897
898 pub external_scroll_id: ExternalScrollId,
900}
901
902#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
905pub enum AnimationState {
906 AnimationsPresent,
908 AnimationCallbacksPresent,
910 NoAnimationsPresent,
912 NoAnimationCallbacksPresent,
914}
915
916#[derive(
969 Clone,
970 Copy,
971 Debug,
972 Default,
973 Deserialize,
974 Eq,
975 Hash,
976 MallocSizeOf,
977 PartialEq,
978 Serialize,
979 PartialOrd,
980)]
981pub struct FocusSequenceNumber(pub u64);
982
983impl Display for FocusSequenceNumber {
984 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
985 Display::fmt(&self.0, f)
986 }
987}
988
989#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
992pub struct JavaScriptEvaluationId(pub usize);
993
994#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
995pub enum JSValue {
996 Undefined,
997 Null,
998 Boolean(bool),
999 Number(f64),
1000 String(String),
1001 Element(String),
1002 ShadowRoot(String),
1003 Frame(String),
1004 Window(String),
1005 Array(Vec<JSValue>),
1006 Object(HashMap<String, JSValue>),
1007}
1008
1009#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1010pub struct JavaScriptErrorInfo {
1011 pub message: String,
1012 pub filename: String,
1013 pub stack: Option<String>,
1014 pub line_number: u64,
1015 pub column: u64,
1016}
1017
1018#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1021pub enum JavaScriptEvaluationResultSerializationError {
1022 DetachedShadowRoot,
1025 StaleElementReference,
1028 UnknownType,
1031 OtherJavaScriptError,
1035}
1036
1037#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1039pub enum JavaScriptEvaluationError {
1040 DocumentNotFound,
1042 CompilationFailure,
1044 EvaluationFailure(Option<JavaScriptErrorInfo>),
1046 InternalError,
1049 WebViewNotReady,
1052 SerializationError(JavaScriptEvaluationResultSerializationError),
1055}
1056
1057#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1058pub enum ScreenshotCaptureError {
1059 CouldNotReadImage,
1062 WebViewDoesNotExist,
1064}
1065
1066#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1067pub struct RgbColor {
1068 pub red: u8,
1069 pub green: u8,
1070 pub blue: u8,
1071}
1072
1073#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1075pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1076
1077impl ScriptToEmbedderChan {
1078 pub fn new(
1080 embedder_chan: Sender<EmbedderMsg>,
1081 waker: Box<dyn EventLoopWaker>,
1082 ) -> ScriptToEmbedderChan {
1083 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1084 let msg = match embedder_msg {
1085 Ok(embedder_msg) => embedder_msg,
1086 Err(err) => {
1087 log::warn!("Script to Embedder message error: {err}");
1088 return;
1089 },
1090 };
1091 let _ = embedder_chan.send(msg);
1092 waker.wake();
1093 })
1094 .expect("Failed to create channel");
1095 ScriptToEmbedderChan(embedder_callback)
1096 }
1097
1098 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1100 self.0.send(msg)
1101 }
1102}
1103
1104#[derive(Deserialize, Serialize)]
1107pub struct NewWebViewDetails {
1108 pub webview_id: WebViewId,
1109 pub viewport_details: ViewportDetails,
1110 pub user_content_manager_id: Option<UserContentManagerId>,
1111}