1pub mod input_events;
12pub mod resources;
13pub mod user_content_manager;
14pub mod webdriver;
15
16use std::collections::HashMap;
17use std::ffi::c_void;
18use std::fmt::{Debug, Display, Error, Formatter};
19use std::hash::Hash;
20use std::ops::Range;
21use std::path::PathBuf;
22use std::sync::Arc;
23use std::time::SystemTime;
24
25use base::Epoch;
26use base::generic_channel::{GenericCallback, GenericSender, SendResult};
27use base::id::{PipelineId, WebViewId};
28use crossbeam_channel::Sender;
29use euclid::{Box2D, Point2D, Scale, Size2D, Vector2D};
30use http::{HeaderMap, Method, StatusCode};
31use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
32use log::warn;
33use malloc_size_of::malloc_size_of_is_0;
34use malloc_size_of_derive::MallocSizeOf;
35use pixels::SharedRasterImage;
36use serde::{Deserialize, Deserializer, Serialize, Serializer};
37use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize};
38use servo_url::ServoUrl;
39use strum_macros::{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::input_events::*;
51pub use crate::webdriver::*;
52
53#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
57pub enum WebViewPoint {
58 Device(DevicePoint),
59 Page(Point2D<f32, CSSPixel>),
60}
61
62impl WebViewPoint {
63 pub fn as_device_point(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DevicePoint {
64 match self {
65 Self::Device(point) => *point,
66 Self::Page(point) => *point * scale,
67 }
68 }
69}
70
71impl From<DevicePoint> for WebViewPoint {
72 fn from(point: DevicePoint) -> Self {
73 Self::Device(point)
74 }
75}
76
77impl From<LayoutPoint> for WebViewPoint {
78 fn from(point: LayoutPoint) -> Self {
79 Self::Page(Point2D::new(point.x, point.y))
80 }
81}
82
83impl From<Point2D<f32, CSSPixel>> for WebViewPoint {
84 fn from(point: Point2D<f32, CSSPixel>) -> Self {
85 Self::Page(point)
86 }
87}
88
89#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
93pub enum WebViewRect {
94 Device(DeviceRect),
95 Page(Box2D<f32, CSSPixel>),
96}
97
98impl WebViewRect {
99 pub fn as_device_rect(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceRect {
100 match self {
101 Self::Device(rect) => *rect,
102 Self::Page(rect) => *rect * scale,
103 }
104 }
105}
106
107impl From<DeviceRect> for WebViewRect {
108 fn from(rect: DeviceRect) -> Self {
109 Self::Device(rect)
110 }
111}
112
113impl From<LayoutRect> for WebViewRect {
114 fn from(rect: LayoutRect) -> Self {
115 Self::Page(Box2D::new(
116 Point2D::new(rect.min.x, rect.min.y),
117 Point2D::new(rect.max.x, rect.max.y),
118 ))
119 }
120}
121
122impl From<Box2D<f32, CSSPixel>> for WebViewRect {
123 fn from(rect: Box2D<f32, CSSPixel>) -> Self {
124 Self::Page(rect)
125 }
126}
127
128#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
129pub enum WebViewVector {
130 Device(DeviceVector2D),
131 Page(Vector2D<f32, CSSPixel>),
132}
133
134impl WebViewVector {
135 pub fn as_device_vector(&self, scale: Scale<f32, CSSPixel, DevicePixel>) -> DeviceVector2D {
136 match self {
137 Self::Device(vector) => *vector,
138 Self::Page(vector) => *vector * scale,
139 }
140 }
141}
142
143impl From<DeviceVector2D> for WebViewVector {
144 fn from(vector: DeviceVector2D) -> Self {
145 Self::Device(vector)
146 }
147}
148
149impl From<LayoutVector2D> for WebViewVector {
150 fn from(vector: LayoutVector2D) -> Self {
151 Self::Page(Vector2D::new(vector.x, vector.y))
152 }
153}
154
155impl From<Vector2D<f32, CSSPixel>> for WebViewVector {
156 fn from(vector: Vector2D<f32, CSSPixel>) -> Self {
157 Self::Page(vector)
158 }
159}
160
161#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
162pub enum Scroll {
163 Delta(WebViewVector),
164 Start,
165 End,
166}
167
168#[derive(Clone, Copy, Debug, PartialEq)]
171pub enum ShutdownState {
172 NotShuttingDown,
173 ShuttingDown,
174 FinishedShuttingDown,
175}
176
177#[repr(u8)]
180#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
181pub enum Cursor {
182 None,
183 #[default]
184 Default,
185 Pointer,
186 ContextMenu,
187 Help,
188 Progress,
189 Wait,
190 Cell,
191 Crosshair,
192 Text,
193 VerticalText,
194 Alias,
195 Copy,
196 Move,
197 NoDrop,
198 NotAllowed,
199 Grab,
200 Grabbing,
201 EResize,
202 NResize,
203 NeResize,
204 NwResize,
205 SResize,
206 SeResize,
207 SwResize,
208 WResize,
209 EwResize,
210 NsResize,
211 NeswResize,
212 NwseResize,
213 ColResize,
214 RowResize,
215 AllScroll,
216 ZoomIn,
217 ZoomOut,
218}
219
220pub trait EventLoopWaker: 'static + Send {
221 fn clone_box(&self) -> Box<dyn EventLoopWaker>;
222 fn wake(&self) {}
223}
224
225impl Clone for Box<dyn EventLoopWaker> {
226 fn clone(&self) -> Self {
227 self.clone_box()
228 }
229}
230pub struct EmbedderProxy {
232 pub sender: Sender<EmbedderMsg>,
233 pub event_loop_waker: Box<dyn EventLoopWaker>,
234}
235
236impl EmbedderProxy {
237 pub fn send(&self, message: EmbedderMsg) {
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 Clone for EmbedderProxy {
247 fn clone(&self) -> EmbedderProxy {
248 EmbedderProxy {
249 sender: self.sender.clone(),
250 event_loop_waker: self.event_loop_waker.clone(),
251 }
252 }
253}
254
255pub trait RefreshDriver {
260 fn observe_next_frame(&self, start_frame_callback: Box<dyn Fn() + Send + 'static>);
264}
265
266#[derive(Deserialize, Serialize)]
270pub enum SimpleDialog {
271 Alert {
274 id: EmbedderControlId,
275 message: String,
276 response_sender: GenericSender<AlertResponse>,
277 },
278 Confirm {
281 id: EmbedderControlId,
282 message: String,
283 response_sender: GenericSender<ConfirmResponse>,
284 },
285 Prompt {
288 id: EmbedderControlId,
289 message: String,
290 default: String,
291 response_sender: GenericSender<PromptResponse>,
292 },
293}
294
295impl SimpleDialog {
296 pub fn message(&self) -> &str {
298 match self {
299 SimpleDialog::Alert { message, .. } => message,
300 SimpleDialog::Confirm { message, .. } => message,
301 SimpleDialog::Prompt { message, .. } => message,
302 }
303 }
304
305 pub fn set_message(&mut self, text: String) {
306 match self {
307 SimpleDialog::Alert { message, .. } => *message = text,
308 SimpleDialog::Confirm { message, .. } => *message = text,
309 SimpleDialog::Prompt { message, .. } => *message = text,
310 }
311 }
312
313 pub fn dismiss(&self) {
314 match self {
315 SimpleDialog::Alert {
316 response_sender, ..
317 } => {
318 let _ = response_sender.send(AlertResponse::Ok);
319 },
320 SimpleDialog::Confirm {
321 response_sender, ..
322 } => {
323 let _ = response_sender.send(ConfirmResponse::Cancel);
324 },
325 SimpleDialog::Prompt {
326 response_sender, ..
327 } => {
328 let _ = response_sender.send(PromptResponse::Cancel);
329 },
330 }
331 }
332
333 pub fn accept(&self) {
334 match self {
335 SimpleDialog::Alert {
336 response_sender, ..
337 } => {
338 let _ = response_sender.send(AlertResponse::Ok);
339 },
340 SimpleDialog::Confirm {
341 response_sender, ..
342 } => {
343 let _ = response_sender.send(ConfirmResponse::Ok);
344 },
345 SimpleDialog::Prompt {
346 default,
347 response_sender,
348 ..
349 } => {
350 let _ = response_sender.send(PromptResponse::Ok(default.clone()));
351 },
352 }
353 }
354
355 pub fn id(&self) -> EmbedderControlId {
356 match self {
357 SimpleDialog::Alert { id, .. } |
358 SimpleDialog::Confirm { id, .. } |
359 SimpleDialog::Prompt { id, .. } => *id,
360 }
361 }
362}
363
364#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
365pub struct AuthenticationResponse {
366 pub username: String,
368 pub password: String,
370}
371
372#[derive(Default, Deserialize, PartialEq, Serialize)]
373pub enum AlertResponse {
374 #[default]
378 Ok,
380}
381
382#[derive(Default, Deserialize, PartialEq, Serialize)]
383pub enum ConfirmResponse {
384 Ok,
386 #[default]
390 Cancel,
392}
393
394#[derive(Default, Deserialize, PartialEq, Serialize)]
395pub enum PromptResponse {
396 Ok(String),
398 #[default]
402 Cancel,
404}
405
406#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
408pub enum AllowOrDeny {
409 Allow,
410 Deny,
411}
412
413#[derive(Clone, Debug, Deserialize, Serialize)]
414pub struct SelectElementOption {
415 pub id: usize,
417 pub label: String,
419 pub is_disabled: bool,
421}
422
423#[derive(Clone, Debug, Deserialize, Serialize)]
425pub enum SelectElementOptionOrOptgroup {
426 Option(SelectElementOption),
427 Optgroup {
428 label: String,
429 options: Vec<SelectElementOption>,
430 },
431}
432
433#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
436pub struct ViewportDetails {
437 pub size: Size2D<f32, CSSPixel>,
439
440 pub hidpi_scale_factor: Scale<f32, CSSPixel, DevicePixel>,
443}
444
445impl ViewportDetails {
446 pub fn layout_size(&self) -> LayoutSize {
449 Size2D::from_untyped(self.size.to_untyped())
450 }
451}
452
453#[derive(Default, Deserialize, Serialize)]
456pub struct ScreenMetrics {
457 pub screen_size: DeviceIndependentIntSize,
458 pub available_size: DeviceIndependentIntSize,
459}
460
461#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
463pub struct TraversalId(String);
464
465impl TraversalId {
466 #[allow(clippy::new_without_default)]
467 pub fn new() -> Self {
468 Self(Uuid::new_v4().to_string())
469 }
470}
471
472#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
473pub enum PixelFormat {
474 K8,
476 KA8,
478 RGB8,
480 RGBA8,
482 BGRA8,
484}
485
486#[derive(Clone, Deserialize, Serialize)]
488pub struct Image {
489 pub width: u32,
490 pub height: u32,
491 pub format: PixelFormat,
492 data: Arc<IpcSharedMemory>,
494 range: Range<usize>,
495}
496
497impl Image {
498 pub fn new(
499 width: u32,
500 height: u32,
501 data: Arc<IpcSharedMemory>,
502 range: Range<usize>,
503 format: PixelFormat,
504 ) -> Self {
505 Self {
506 width,
507 height,
508 format,
509 data,
510 range,
511 }
512 }
513
514 pub fn data(&self) -> &[u8] {
516 &self.data[self.range.clone()]
517 }
518}
519
520#[derive(Deserialize, IntoStaticStr, Serialize)]
521pub enum EmbedderMsg {
522 Status(WebViewId, Option<String>),
524 ChangePageTitle(WebViewId, Option<String>),
526 MoveTo(WebViewId, DeviceIntPoint),
528 ResizeTo(WebViewId, DeviceIntSize),
530 ShowSimpleDialog(WebViewId, SimpleDialog),
534 RequestAuthentication(
536 WebViewId,
537 ServoUrl,
538 bool, GenericSender<Option<AuthenticationResponse>>,
540 ),
541 AllowNavigationRequest(WebViewId, PipelineId, ServoUrl),
543 AllowOpeningWebView(
545 WebViewId,
546 GenericSender<Option<(WebViewId, ViewportDetails)>>,
547 ),
548 WebViewClosed(WebViewId),
550 WebViewFocused(WebViewId, bool),
553 WebViewBlurred,
555 AllowUnload(WebViewId, GenericSender<AllowOrDeny>),
557 ClearClipboard(WebViewId),
559 GetClipboardText(WebViewId, IpcSender<Result<String, String>>),
561 SetClipboardText(WebViewId, String),
563 SetCursor(WebViewId, Cursor),
565 NewFavicon(WebViewId, Image),
567 HistoryChanged(WebViewId, Vec<ServoUrl>, usize),
569 HistoryTraversalComplete(WebViewId, TraversalId),
571 GetWindowRect(WebViewId, GenericSender<DeviceIndependentIntRect>),
573 GetScreenMetrics(WebViewId, GenericSender<ScreenMetrics>),
575 NotifyFullscreenStateChanged(WebViewId, bool),
577 NotifyLoadStatusChanged(WebViewId, LoadStatus),
579 WebResourceRequested(
580 Option<WebViewId>,
581 WebResourceRequest,
582 GenericSender<WebResourceResponseMsg>,
583 ),
584 Panic(WebViewId, String, Option<String>),
586 GetSelectedBluetoothDevice(WebViewId, Vec<String>, GenericSender<Option<String>>),
588 SelectFiles(
590 EmbedderControlId,
591 FilePickerRequest,
592 GenericSender<Option<Vec<PathBuf>>>,
593 ),
594 PromptPermission(WebViewId, PermissionFeature, GenericSender<AllowOrDeny>),
596 ReportProfile(Vec<u8>),
598 MediaSessionEvent(WebViewId, MediaSessionEvent),
601 OnDevtoolsStarted(Result<u16, ()>, String),
603 RequestDevtoolsConnection(GenericSender<AllowOrDeny>),
605 PlayGamepadHapticEffect(WebViewId, usize, GamepadHapticEffectType, IpcSender<bool>),
607 StopGamepadHapticEffect(WebViewId, usize, IpcSender<bool>),
609 ShutdownComplete,
613 ShowNotification(Option<WebViewId>, Notification),
615 ShowEmbedderControl(EmbedderControlId, DeviceIntRect, EmbedderControlRequest),
617 HideEmbedderControl(EmbedderControlId),
619 FinishJavaScriptEvaluation(
622 JavaScriptEvaluationId,
623 Result<JSValue, JavaScriptEvaluationError>,
624 ),
625 InputEventHandled(WebViewId, InputEventId, InputEventResult),
628}
629
630impl Debug for EmbedderMsg {
631 fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
632 let string: &'static str = self.into();
633 write!(formatter, "{string}")
634 }
635}
636
637#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
638pub struct EmbedderControlId {
639 pub webview_id: WebViewId,
640 pub pipeline_id: PipelineId,
641 pub index: Epoch,
642}
643
644#[derive(Debug, Deserialize, Serialize)]
645pub enum EmbedderControlRequest {
646 SelectElement(Vec<SelectElementOptionOrOptgroup>, Option<usize>),
648 ColorPicker(RgbColor),
650 FilePicker(FilePickerRequest),
652 InputMethod(InputMethodRequest),
655 ContextMenu(ContextMenuRequest),
657}
658
659#[derive(Debug, Deserialize, Serialize)]
662pub struct ContextMenuRequest {
663 pub items: Vec<ContextMenuItem>,
664}
665
666#[derive(Clone, Debug, Deserialize, Serialize)]
668pub enum ContextMenuItem {
669 Item {
670 label: String,
671 action: ContextMenuAction,
672 enabled: bool,
673 },
674 Separator,
675}
676
677#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)]
681pub enum ContextMenuAction {
682 GoBack,
683 GoForward,
684 Reload,
685
686 CopyLink,
687 OpenLinkInNewWebView,
688
689 CopyImageLink,
690 OpenImageInNewView,
691
692 Cut,
693 Copy,
694 Paste,
695 SelectAll,
696}
697
698#[derive(Debug, Deserialize, Serialize)]
702pub struct InputMethodRequest {
703 pub input_method_type: InputMethodType,
704 pub text: String,
705 pub insertion_point: Option<u32>,
706 pub multiline: bool,
707}
708
709#[derive(Debug, Deserialize, Serialize)]
710pub struct FilePickerRequest {
711 pub origin: String,
712 pub current_paths: Vec<PathBuf>,
713 pub filter_patterns: Vec<FilterPattern>,
714 pub allow_select_multiple: bool,
715 pub accept_current_paths_for_testing: bool,
716}
717
718#[derive(Debug, Deserialize, Serialize)]
719pub enum EmbedderControlResponse {
720 SelectElement(Option<usize>),
721 ColorPicker(Option<RgbColor>),
722 FilePicker(Option<Vec<SelectedFile>>),
723 ContextMenu(Option<ContextMenuAction>),
724}
725
726#[derive(Debug, Deserialize, Serialize)]
728pub struct SelectedFile {
729 pub id: Uuid,
730 pub filename: PathBuf,
731 pub modified: SystemTime,
732 pub size: u64,
733 pub type_string: String,
735}
736
737#[derive(Clone, Debug, Deserialize, Serialize)]
740pub struct FilterPattern(pub String);
741
742#[derive(Clone, Debug, Deserialize, Serialize)]
744pub struct MediaMetadata {
745 pub title: String,
747 pub artist: String,
749 pub album: String,
751}
752
753impl MediaMetadata {
754 pub fn new(title: String) -> Self {
755 Self {
756 title,
757 artist: "".to_owned(),
758 album: "".to_owned(),
759 }
760 }
761}
762
763#[repr(i32)]
765#[derive(Clone, Debug, Deserialize, Serialize)]
766pub enum MediaSessionPlaybackState {
767 None_ = 1,
769 Playing,
771 Paused,
773}
774
775#[derive(Clone, Debug, Deserialize, Serialize)]
777pub struct MediaPositionState {
778 pub duration: f64,
779 pub playback_rate: f64,
780 pub position: f64,
781}
782
783impl MediaPositionState {
784 pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
785 Self {
786 duration,
787 playback_rate,
788 position,
789 }
790 }
791}
792
793#[derive(Clone, Debug, Deserialize, Serialize)]
795pub enum MediaSessionEvent {
796 SetMetadata(MediaMetadata),
798 PlaybackStateChange(MediaSessionPlaybackState),
800 SetPositionState(MediaPositionState),
802}
803
804#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
806pub enum PermissionFeature {
807 Geolocation,
808 Notifications,
809 Push,
810 Midi,
811 Camera,
812 Microphone,
813 Speaker,
814 DeviceInfo,
815 BackgroundSync,
816 Bluetooth,
817 PersistentStorage,
818}
819
820#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
824pub enum InputMethodType {
825 Color,
826 Date,
827 DatetimeLocal,
828 Email,
829 Month,
830 Number,
831 Password,
832 Search,
833 Tel,
834 Text,
835 Time,
836 Url,
837 Week,
838}
839
840#[derive(Clone, Debug, Deserialize, Serialize)]
841pub struct DualRumbleEffectParams {
843 pub duration: f64,
844 pub start_delay: f64,
845 pub strong_magnitude: f64,
846 pub weak_magnitude: f64,
847}
848
849#[derive(Clone, Debug, Deserialize, Serialize)]
850pub enum GamepadHapticEffectType {
852 DualRumble(DualRumbleEffectParams),
853}
854
855#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
856pub struct WebResourceRequest {
857 #[serde(
858 deserialize_with = "::hyper_serde::deserialize",
859 serialize_with = "::hyper_serde::serialize"
860 )]
861 #[ignore_malloc_size_of = "Defined in hyper"]
862 pub method: Method,
863 #[serde(
864 deserialize_with = "::hyper_serde::deserialize",
865 serialize_with = "::hyper_serde::serialize"
866 )]
867 #[ignore_malloc_size_of = "Defined in hyper"]
868 pub headers: HeaderMap,
869 pub url: Url,
870 pub is_for_main_frame: bool,
871 pub is_redirect: bool,
872}
873
874#[derive(Clone, Deserialize, Serialize)]
875pub enum WebResourceResponseMsg {
876 Start(WebResourceResponse),
880 SendBodyData(Vec<u8>),
882 FinishLoad,
884 CancelLoad,
886 DoNotIntercept,
888}
889
890#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
891pub struct WebResourceResponse {
892 pub url: Url,
893 #[serde(
894 deserialize_with = "::hyper_serde::deserialize",
895 serialize_with = "::hyper_serde::serialize"
896 )]
897 #[ignore_malloc_size_of = "Defined in hyper"]
898 pub headers: HeaderMap,
899 #[serde(
900 deserialize_with = "::hyper_serde::deserialize",
901 serialize_with = "::hyper_serde::serialize"
902 )]
903 #[ignore_malloc_size_of = "Defined in hyper"]
904 pub status_code: StatusCode,
905 pub status_message: Vec<u8>,
906}
907
908impl WebResourceResponse {
909 pub fn new(url: Url) -> WebResourceResponse {
910 WebResourceResponse {
911 url,
912 headers: HeaderMap::new(),
913 status_code: StatusCode::OK,
914 status_message: b"OK".to_vec(),
915 }
916 }
917
918 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
919 self.headers = headers;
920 self
921 }
922
923 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
924 self.status_code = status_code;
925 self
926 }
927
928 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
929 self.status_message = status_message;
930 self
931 }
932}
933
934#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
936pub enum Theme {
937 Light,
939 Dark,
941}
942
943impl From<Theme> for PrefersColorScheme {
944 fn from(value: Theme) -> Self {
945 match value {
946 Theme::Light => PrefersColorScheme::Light,
947 Theme::Dark => PrefersColorScheme::Dark,
948 }
949 }
950}
951
952#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
955pub enum MediaSessionActionType {
956 Play,
958 Pause,
960 SeekBackward,
963 SeekForward,
966 PreviousTrack,
970 NextTrack,
973 SkipAd,
975 Stop,
977 SeekTo,
979}
980
981#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
983pub enum LoadStatus {
984 Started,
986 HeadParsed,
989 Complete,
993}
994
995#[derive(Clone, Debug, Deserialize, Serialize)]
998pub struct Notification {
999 pub title: String,
1001 pub body: String,
1003 pub tag: String,
1006 pub language: String,
1008 pub require_interaction: bool,
1011 pub silent: Option<bool>,
1014 pub icon_url: Option<ServoUrl>,
1016 pub icon_resource: Option<Arc<SharedRasterImage>>,
1018 pub badge_url: Option<ServoUrl>,
1021 pub badge_resource: Option<Arc<SharedRasterImage>>,
1023 pub image_url: Option<ServoUrl>,
1025 pub image_resource: Option<Arc<SharedRasterImage>>,
1027 pub actions: Vec<NotificationAction>,
1029}
1030
1031#[derive(Clone, Debug, Deserialize, Serialize)]
1033pub struct NotificationAction {
1034 pub name: String,
1036 pub title: String,
1038 pub icon_url: Option<ServoUrl>,
1040 pub icon_resource: Option<Arc<SharedRasterImage>>,
1042}
1043
1044#[derive(Clone, Copy, Debug, Default)]
1050pub struct ScreenGeometry {
1051 pub size: DeviceIntSize,
1054 pub available_size: DeviceIntSize,
1060 pub window_rect: DeviceIntRect,
1065}
1066
1067impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
1068 fn from(value: SelectElementOption) -> Self {
1069 Self::Option(value)
1070 }
1071}
1072
1073#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
1076pub struct UntrustedNodeAddress(pub *const c_void);
1077
1078malloc_size_of_is_0!(UntrustedNodeAddress);
1079
1080#[expect(unsafe_code)]
1081unsafe impl Send for UntrustedNodeAddress {}
1082
1083impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
1084 fn from(o: style_traits::dom::OpaqueNode) -> Self {
1085 UntrustedNodeAddress(o.0 as *const c_void)
1086 }
1087}
1088
1089impl Serialize for UntrustedNodeAddress {
1090 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
1091 (self.0 as usize).serialize(s)
1092 }
1093}
1094
1095impl<'de> Deserialize<'de> for UntrustedNodeAddress {
1096 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
1097 let value: usize = Deserialize::deserialize(d)?;
1098 Ok(UntrustedNodeAddress::from_id(value))
1099 }
1100}
1101
1102impl UntrustedNodeAddress {
1103 #[inline]
1105 pub fn from_id(id: usize) -> UntrustedNodeAddress {
1106 UntrustedNodeAddress(id as *const c_void)
1107 }
1108}
1109
1110#[derive(Clone, Debug, Deserialize, Serialize)]
1112pub struct CompositorHitTestResult {
1113 pub pipeline_id: PipelineId,
1115
1116 pub point_in_viewport: Point2D<f32, CSSPixel>,
1118
1119 pub external_scroll_id: ExternalScrollId,
1121}
1122
1123#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1126pub enum AnimationState {
1127 AnimationsPresent,
1129 AnimationCallbacksPresent,
1131 NoAnimationsPresent,
1133 NoAnimationCallbacksPresent,
1135}
1136
1137#[derive(
1190 Clone,
1191 Copy,
1192 Debug,
1193 Default,
1194 Deserialize,
1195 Eq,
1196 Hash,
1197 MallocSizeOf,
1198 PartialEq,
1199 Serialize,
1200 PartialOrd,
1201)]
1202pub struct FocusSequenceNumber(pub u64);
1203
1204impl Display for FocusSequenceNumber {
1205 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
1206 Display::fmt(&self.0, f)
1207 }
1208}
1209
1210#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
1213pub struct JavaScriptEvaluationId(pub usize);
1214
1215#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1216pub enum JSValue {
1217 Undefined,
1218 Null,
1219 Boolean(bool),
1220 Number(f64),
1221 String(String),
1222 Element(String),
1223 ShadowRoot(String),
1224 Frame(String),
1225 Window(String),
1226 Array(Vec<JSValue>),
1227 Object(HashMap<String, JSValue>),
1228}
1229
1230#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1231pub struct JavaScriptErrorInfo {
1232 pub message: String,
1233 pub filename: String,
1234 pub stack: Option<String>,
1235 pub line_number: u64,
1236 pub column: u64,
1237}
1238
1239#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1242pub enum JavaScriptEvaluationResultSerializationError {
1243 DetachedShadowRoot,
1246 StaleElementReference,
1249 UnknownType,
1252 OtherJavaScriptError,
1256}
1257
1258#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1260pub enum JavaScriptEvaluationError {
1261 DocumentNotFound,
1263 CompilationFailure,
1265 EvaluationFailure(Option<JavaScriptErrorInfo>),
1267 InternalError,
1270 WebViewNotReady,
1273 SerializationError(JavaScriptEvaluationResultSerializationError),
1276}
1277
1278#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1279pub enum ScreenshotCaptureError {
1280 CouldNotReadImage,
1283 WebViewDoesNotExist,
1285}
1286
1287#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1288pub struct RgbColor {
1289 pub red: u8,
1290 pub green: u8,
1291 pub blue: u8,
1292}
1293
1294#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1296pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1297
1298impl ScriptToEmbedderChan {
1299 pub fn new(
1301 embedder_chan: Sender<EmbedderMsg>,
1302 waker: Box<dyn EventLoopWaker>,
1303 ) -> ScriptToEmbedderChan {
1304 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1305 let msg = match embedder_msg {
1306 Ok(embedder_msg) => embedder_msg,
1307 Err(err) => {
1308 log::warn!("Script to Embedder message error: {err}");
1309 return;
1310 },
1311 };
1312 let _ = embedder_chan.send(msg);
1313 waker.wake();
1314 })
1315 .expect("Failed to create channel");
1316 ScriptToEmbedderChan(embedder_callback)
1317 }
1318
1319 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1321 self.0.send(msg)
1322 }
1323}