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::RasterImage;
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)]
267pub enum ContextMenuResult {
268 Dismissed,
269 Ignored,
270 Selected(usize),
271}
272
273#[derive(Deserialize, Serialize)]
277pub enum SimpleDialog {
278 Alert {
281 id: EmbedderControlId,
282 message: String,
283 response_sender: GenericSender<AlertResponse>,
284 },
285 Confirm {
288 id: EmbedderControlId,
289 message: String,
290 response_sender: GenericSender<ConfirmResponse>,
291 },
292 Prompt {
295 id: EmbedderControlId,
296 message: String,
297 default: String,
298 response_sender: GenericSender<PromptResponse>,
299 },
300}
301
302impl SimpleDialog {
303 pub fn message(&self) -> &str {
305 match self {
306 SimpleDialog::Alert { message, .. } => message,
307 SimpleDialog::Confirm { message, .. } => message,
308 SimpleDialog::Prompt { message, .. } => message,
309 }
310 }
311
312 pub fn set_message(&mut self, text: String) {
313 match self {
314 SimpleDialog::Alert { message, .. } => *message = text,
315 SimpleDialog::Confirm { message, .. } => *message = text,
316 SimpleDialog::Prompt { message, .. } => *message = text,
317 }
318 }
319
320 pub fn dismiss(&self) {
321 match self {
322 SimpleDialog::Alert {
323 response_sender, ..
324 } => {
325 let _ = response_sender.send(AlertResponse::Ok);
326 },
327 SimpleDialog::Confirm {
328 response_sender, ..
329 } => {
330 let _ = response_sender.send(ConfirmResponse::Cancel);
331 },
332 SimpleDialog::Prompt {
333 response_sender, ..
334 } => {
335 let _ = response_sender.send(PromptResponse::Cancel);
336 },
337 }
338 }
339
340 pub fn accept(&self) {
341 match self {
342 SimpleDialog::Alert {
343 response_sender, ..
344 } => {
345 let _ = response_sender.send(AlertResponse::Ok);
346 },
347 SimpleDialog::Confirm {
348 response_sender, ..
349 } => {
350 let _ = response_sender.send(ConfirmResponse::Ok);
351 },
352 SimpleDialog::Prompt {
353 default,
354 response_sender,
355 ..
356 } => {
357 let _ = response_sender.send(PromptResponse::Ok(default.clone()));
358 },
359 }
360 }
361
362 pub fn id(&self) -> EmbedderControlId {
363 match self {
364 SimpleDialog::Alert { id, .. } |
365 SimpleDialog::Confirm { id, .. } |
366 SimpleDialog::Prompt { id, .. } => *id,
367 }
368 }
369}
370
371#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
372pub struct AuthenticationResponse {
373 pub username: String,
375 pub password: String,
377}
378
379#[derive(Default, Deserialize, PartialEq, Serialize)]
380pub enum AlertResponse {
381 #[default]
385 Ok,
387}
388
389#[derive(Default, Deserialize, PartialEq, Serialize)]
390pub enum ConfirmResponse {
391 Ok,
393 #[default]
397 Cancel,
399}
400
401#[derive(Default, Deserialize, PartialEq, Serialize)]
402pub enum PromptResponse {
403 Ok(String),
405 #[default]
409 Cancel,
411}
412
413#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
415pub enum AllowOrDeny {
416 Allow,
417 Deny,
418}
419
420#[derive(Clone, Debug, Deserialize, Serialize)]
421pub struct SelectElementOption {
422 pub id: usize,
424 pub label: String,
426 pub is_disabled: bool,
428}
429
430#[derive(Clone, Debug, Deserialize, Serialize)]
432pub enum SelectElementOptionOrOptgroup {
433 Option(SelectElementOption),
434 Optgroup {
435 label: String,
436 options: Vec<SelectElementOption>,
437 },
438}
439
440#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize)]
443pub struct ViewportDetails {
444 pub size: Size2D<f32, CSSPixel>,
446
447 pub hidpi_scale_factor: Scale<f32, CSSPixel, DevicePixel>,
450}
451
452impl ViewportDetails {
453 pub fn layout_size(&self) -> LayoutSize {
456 Size2D::from_untyped(self.size.to_untyped())
457 }
458}
459
460#[derive(Default, Deserialize, Serialize)]
463pub struct ScreenMetrics {
464 pub screen_size: DeviceIndependentIntSize,
465 pub available_size: DeviceIndependentIntSize,
466}
467
468#[derive(Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
470pub struct TraversalId(String);
471
472impl TraversalId {
473 #[allow(clippy::new_without_default)]
474 pub fn new() -> Self {
475 Self(Uuid::new_v4().to_string())
476 }
477}
478
479#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
480pub enum PixelFormat {
481 K8,
483 KA8,
485 RGB8,
487 RGBA8,
489 BGRA8,
491}
492
493#[derive(Clone, Deserialize, Serialize)]
495pub struct Image {
496 pub width: u32,
497 pub height: u32,
498 pub format: PixelFormat,
499 data: Arc<IpcSharedMemory>,
501 range: Range<usize>,
502}
503
504impl Image {
505 pub fn new(
506 width: u32,
507 height: u32,
508 data: Arc<IpcSharedMemory>,
509 range: Range<usize>,
510 format: PixelFormat,
511 ) -> Self {
512 Self {
513 width,
514 height,
515 format,
516 data,
517 range,
518 }
519 }
520
521 pub fn data(&self) -> &[u8] {
523 &self.data[self.range.clone()]
524 }
525}
526
527#[derive(Deserialize, IntoStaticStr, Serialize)]
528pub enum EmbedderMsg {
529 Status(WebViewId, Option<String>),
531 ChangePageTitle(WebViewId, Option<String>),
533 MoveTo(WebViewId, DeviceIntPoint),
535 ResizeTo(WebViewId, DeviceIntSize),
537 ShowSimpleDialog(WebViewId, SimpleDialog),
541 RequestAuthentication(
543 WebViewId,
544 ServoUrl,
545 bool, GenericSender<Option<AuthenticationResponse>>,
547 ),
548 ShowContextMenu(
550 WebViewId,
551 GenericSender<ContextMenuResult>,
552 Option<String>,
553 Vec<String>,
554 ),
555 AllowNavigationRequest(WebViewId, PipelineId, ServoUrl),
557 AllowOpeningWebView(
559 WebViewId,
560 GenericSender<Option<(WebViewId, ViewportDetails)>>,
561 ),
562 WebViewClosed(WebViewId),
564 WebViewFocused(WebViewId, bool),
567 WebViewBlurred,
569 AllowUnload(WebViewId, GenericSender<AllowOrDeny>),
571 ClearClipboard(WebViewId),
573 GetClipboardText(WebViewId, IpcSender<Result<String, String>>),
575 SetClipboardText(WebViewId, String),
577 SetCursor(WebViewId, Cursor),
579 NewFavicon(WebViewId, Image),
581 HistoryChanged(WebViewId, Vec<ServoUrl>, usize),
583 HistoryTraversalComplete(WebViewId, TraversalId),
585 GetWindowRect(WebViewId, GenericSender<DeviceIndependentIntRect>),
587 GetScreenMetrics(WebViewId, GenericSender<ScreenMetrics>),
589 NotifyFullscreenStateChanged(WebViewId, bool),
591 NotifyLoadStatusChanged(WebViewId, LoadStatus),
593 WebResourceRequested(
594 Option<WebViewId>,
595 WebResourceRequest,
596 GenericSender<WebResourceResponseMsg>,
597 ),
598 Panic(WebViewId, String, Option<String>),
600 GetSelectedBluetoothDevice(WebViewId, Vec<String>, GenericSender<Option<String>>),
602 SelectFiles(
604 EmbedderControlId,
605 FilePickerRequest,
606 GenericSender<Option<Vec<PathBuf>>>,
607 ),
608 PromptPermission(WebViewId, PermissionFeature, GenericSender<AllowOrDeny>),
610 ReportProfile(Vec<u8>),
612 MediaSessionEvent(WebViewId, MediaSessionEvent),
615 OnDevtoolsStarted(Result<u16, ()>, String),
617 RequestDevtoolsConnection(GenericSender<AllowOrDeny>),
619 PlayGamepadHapticEffect(WebViewId, usize, GamepadHapticEffectType, IpcSender<bool>),
621 StopGamepadHapticEffect(WebViewId, usize, IpcSender<bool>),
623 ShutdownComplete,
627 ShowNotification(Option<WebViewId>, Notification),
629 ShowEmbedderControl(EmbedderControlId, DeviceIntRect, EmbedderControlRequest),
631 HideEmbedderControl(EmbedderControlId),
633 FinishJavaScriptEvaluation(
636 JavaScriptEvaluationId,
637 Result<JSValue, JavaScriptEvaluationError>,
638 ),
639 InputEventHandled(WebViewId, InputEventId, InputEventResult),
642}
643
644impl Debug for EmbedderMsg {
645 fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
646 let string: &'static str = self.into();
647 write!(formatter, "{string}")
648 }
649}
650
651#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
652pub struct EmbedderControlId {
653 pub webview_id: WebViewId,
654 pub pipeline_id: PipelineId,
655 pub index: Epoch,
656}
657
658#[derive(Debug, Deserialize, Serialize)]
659pub enum EmbedderControlRequest {
660 SelectElement(Vec<SelectElementOptionOrOptgroup>, Option<usize>),
662 ColorPicker(RgbColor),
664 FilePicker(FilePickerRequest),
666 InputMethod(InputMethodRequest),
669}
670
671#[derive(Debug, Deserialize, Serialize)]
675pub struct InputMethodRequest {
676 pub input_method_type: InputMethodType,
677 pub text: String,
678 pub insertion_point: Option<u32>,
679 pub multiline: bool,
680}
681
682#[derive(Debug, Deserialize, Serialize)]
683pub struct FilePickerRequest {
684 pub origin: String,
685 pub current_paths: Vec<PathBuf>,
686 pub filter_patterns: Vec<FilterPattern>,
687 pub allow_select_multiple: bool,
688 pub accept_current_paths_for_testing: bool,
689}
690
691#[derive(Debug, Deserialize, Serialize)]
692pub enum EmbedderControlResponse {
693 SelectElement(Option<usize>),
694 ColorPicker(Option<RgbColor>),
695 FilePicker(Option<Vec<SelectedFile>>),
696}
697
698#[derive(Debug, Deserialize, Serialize)]
700pub struct SelectedFile {
701 pub id: Uuid,
702 pub filename: PathBuf,
703 pub modified: SystemTime,
704 pub size: u64,
705 pub type_string: String,
707}
708
709#[derive(Clone, Debug, Deserialize, Serialize)]
712pub struct FilterPattern(pub String);
713
714#[derive(Clone, Debug, Deserialize, Serialize)]
716pub struct MediaMetadata {
717 pub title: String,
719 pub artist: String,
721 pub album: String,
723}
724
725impl MediaMetadata {
726 pub fn new(title: String) -> Self {
727 Self {
728 title,
729 artist: "".to_owned(),
730 album: "".to_owned(),
731 }
732 }
733}
734
735#[repr(i32)]
737#[derive(Clone, Debug, Deserialize, Serialize)]
738pub enum MediaSessionPlaybackState {
739 None_ = 1,
741 Playing,
743 Paused,
745}
746
747#[derive(Clone, Debug, Deserialize, Serialize)]
749pub struct MediaPositionState {
750 pub duration: f64,
751 pub playback_rate: f64,
752 pub position: f64,
753}
754
755impl MediaPositionState {
756 pub fn new(duration: f64, playback_rate: f64, position: f64) -> Self {
757 Self {
758 duration,
759 playback_rate,
760 position,
761 }
762 }
763}
764
765#[derive(Clone, Debug, Deserialize, Serialize)]
767pub enum MediaSessionEvent {
768 SetMetadata(MediaMetadata),
770 PlaybackStateChange(MediaSessionPlaybackState),
772 SetPositionState(MediaPositionState),
774}
775
776#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
778pub enum PermissionFeature {
779 Geolocation,
780 Notifications,
781 Push,
782 Midi,
783 Camera,
784 Microphone,
785 Speaker,
786 DeviceInfo,
787 BackgroundSync,
788 Bluetooth,
789 PersistentStorage,
790}
791
792#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
796pub enum InputMethodType {
797 Color,
798 Date,
799 DatetimeLocal,
800 Email,
801 Month,
802 Number,
803 Password,
804 Search,
805 Tel,
806 Text,
807 Time,
808 Url,
809 Week,
810}
811
812#[derive(Clone, Debug, Deserialize, Serialize)]
813pub struct DualRumbleEffectParams {
815 pub duration: f64,
816 pub start_delay: f64,
817 pub strong_magnitude: f64,
818 pub weak_magnitude: f64,
819}
820
821#[derive(Clone, Debug, Deserialize, Serialize)]
822pub enum GamepadHapticEffectType {
824 DualRumble(DualRumbleEffectParams),
825}
826
827#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
828pub struct WebResourceRequest {
829 #[serde(
830 deserialize_with = "::hyper_serde::deserialize",
831 serialize_with = "::hyper_serde::serialize"
832 )]
833 #[ignore_malloc_size_of = "Defined in hyper"]
834 pub method: Method,
835 #[serde(
836 deserialize_with = "::hyper_serde::deserialize",
837 serialize_with = "::hyper_serde::serialize"
838 )]
839 #[ignore_malloc_size_of = "Defined in hyper"]
840 pub headers: HeaderMap,
841 pub url: Url,
842 pub is_for_main_frame: bool,
843 pub is_redirect: bool,
844}
845
846#[derive(Clone, Deserialize, Serialize)]
847pub enum WebResourceResponseMsg {
848 Start(WebResourceResponse),
852 SendBodyData(Vec<u8>),
854 FinishLoad,
856 CancelLoad,
858 DoNotIntercept,
860}
861
862#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
863pub struct WebResourceResponse {
864 pub url: Url,
865 #[serde(
866 deserialize_with = "::hyper_serde::deserialize",
867 serialize_with = "::hyper_serde::serialize"
868 )]
869 #[ignore_malloc_size_of = "Defined in hyper"]
870 pub headers: HeaderMap,
871 #[serde(
872 deserialize_with = "::hyper_serde::deserialize",
873 serialize_with = "::hyper_serde::serialize"
874 )]
875 #[ignore_malloc_size_of = "Defined in hyper"]
876 pub status_code: StatusCode,
877 pub status_message: Vec<u8>,
878}
879
880impl WebResourceResponse {
881 pub fn new(url: Url) -> WebResourceResponse {
882 WebResourceResponse {
883 url,
884 headers: HeaderMap::new(),
885 status_code: StatusCode::OK,
886 status_message: b"OK".to_vec(),
887 }
888 }
889
890 pub fn headers(mut self, headers: HeaderMap) -> WebResourceResponse {
891 self.headers = headers;
892 self
893 }
894
895 pub fn status_code(mut self, status_code: StatusCode) -> WebResourceResponse {
896 self.status_code = status_code;
897 self
898 }
899
900 pub fn status_message(mut self, status_message: Vec<u8>) -> WebResourceResponse {
901 self.status_message = status_message;
902 self
903 }
904}
905
906#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
908pub enum Theme {
909 Light,
911 Dark,
913}
914
915impl From<Theme> for PrefersColorScheme {
916 fn from(value: Theme) -> Self {
917 match value {
918 Theme::Light => PrefersColorScheme::Light,
919 Theme::Dark => PrefersColorScheme::Dark,
920 }
921 }
922}
923
924#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
927pub enum MediaSessionActionType {
928 Play,
930 Pause,
932 SeekBackward,
935 SeekForward,
938 PreviousTrack,
942 NextTrack,
945 SkipAd,
947 Stop,
949 SeekTo,
951}
952
953#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
955pub enum LoadStatus {
956 Started,
958 HeadParsed,
961 Complete,
965}
966
967#[derive(Clone, Debug, Deserialize, Serialize)]
970pub struct Notification {
971 pub title: String,
973 pub body: String,
975 pub tag: String,
978 pub language: String,
980 pub require_interaction: bool,
983 pub silent: Option<bool>,
986 pub icon_url: Option<ServoUrl>,
988 pub icon_resource: Option<Arc<RasterImage>>,
990 pub badge_url: Option<ServoUrl>,
993 pub badge_resource: Option<Arc<RasterImage>>,
995 pub image_url: Option<ServoUrl>,
997 pub image_resource: Option<Arc<RasterImage>>,
999 pub actions: Vec<NotificationAction>,
1001}
1002
1003#[derive(Clone, Debug, Deserialize, Serialize)]
1005pub struct NotificationAction {
1006 pub name: String,
1008 pub title: String,
1010 pub icon_url: Option<ServoUrl>,
1012 pub icon_resource: Option<Arc<RasterImage>>,
1014}
1015
1016#[derive(Clone, Copy, Debug, Default)]
1022pub struct ScreenGeometry {
1023 pub size: DeviceIntSize,
1026 pub available_size: DeviceIntSize,
1032 pub window_rect: DeviceIntRect,
1037}
1038
1039impl From<SelectElementOption> for SelectElementOptionOrOptgroup {
1040 fn from(value: SelectElementOption) -> Self {
1041 Self::Option(value)
1042 }
1043}
1044
1045#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
1048pub struct UntrustedNodeAddress(pub *const c_void);
1049
1050malloc_size_of_is_0!(UntrustedNodeAddress);
1051
1052#[allow(unsafe_code)]
1053unsafe impl Send for UntrustedNodeAddress {}
1054
1055impl From<style_traits::dom::OpaqueNode> for UntrustedNodeAddress {
1056 fn from(o: style_traits::dom::OpaqueNode) -> Self {
1057 UntrustedNodeAddress(o.0 as *const c_void)
1058 }
1059}
1060
1061impl Serialize for UntrustedNodeAddress {
1062 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
1063 (self.0 as usize).serialize(s)
1064 }
1065}
1066
1067impl<'de> Deserialize<'de> for UntrustedNodeAddress {
1068 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<UntrustedNodeAddress, D::Error> {
1069 let value: usize = Deserialize::deserialize(d)?;
1070 Ok(UntrustedNodeAddress::from_id(value))
1071 }
1072}
1073
1074impl UntrustedNodeAddress {
1075 #[inline]
1077 pub fn from_id(id: usize) -> UntrustedNodeAddress {
1078 UntrustedNodeAddress(id as *const c_void)
1079 }
1080}
1081
1082#[derive(Clone, Debug, Deserialize, Serialize)]
1084pub struct CompositorHitTestResult {
1085 pub pipeline_id: PipelineId,
1087
1088 pub point_in_viewport: Point2D<f32, CSSPixel>,
1090
1091 pub external_scroll_id: ExternalScrollId,
1093}
1094
1095#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
1098pub enum AnimationState {
1099 AnimationsPresent,
1101 AnimationCallbacksPresent,
1103 NoAnimationsPresent,
1105 NoAnimationCallbacksPresent,
1107}
1108
1109#[derive(
1162 Clone,
1163 Copy,
1164 Debug,
1165 Default,
1166 Deserialize,
1167 Eq,
1168 Hash,
1169 MallocSizeOf,
1170 PartialEq,
1171 Serialize,
1172 PartialOrd,
1173)]
1174pub struct FocusSequenceNumber(pub u64);
1175
1176impl Display for FocusSequenceNumber {
1177 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
1178 Display::fmt(&self.0, f)
1179 }
1180}
1181
1182#[derive(Clone, Copy, Deserialize, Eq, Hash, PartialEq, Serialize)]
1185pub struct JavaScriptEvaluationId(pub usize);
1186
1187#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1188pub enum JSValue {
1189 Undefined,
1190 Null,
1191 Boolean(bool),
1192 Number(f64),
1193 String(String),
1194 Element(String),
1195 ShadowRoot(String),
1196 Frame(String),
1197 Window(String),
1198 Array(Vec<JSValue>),
1199 Object(HashMap<String, JSValue>),
1200}
1201
1202#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1203pub struct JavaScriptErrorInfo {
1204 pub message: String,
1205 pub filename: String,
1206 pub stack: Option<String>,
1207 pub line_number: u64,
1208 pub column: u64,
1209}
1210
1211#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1214pub enum JavaScriptEvaluationResultSerializationError {
1215 DetachedShadowRoot,
1218 StaleElementReference,
1221 UnknownType,
1224 OtherJavaScriptError,
1228}
1229
1230#[derive(Clone, Debug, Deserialize, EnumMessage, PartialEq, Serialize)]
1232pub enum JavaScriptEvaluationError {
1233 DocumentNotFound,
1235 CompilationFailure,
1237 EvaluationFailure(Option<JavaScriptErrorInfo>),
1239 InternalError,
1242 WebViewNotReady,
1245 SerializationError(JavaScriptEvaluationResultSerializationError),
1248}
1249
1250#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1251pub enum ScreenshotCaptureError {
1252 CouldNotReadImage,
1255 WebViewDoesNotExist,
1257}
1258
1259#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
1260pub struct RgbColor {
1261 pub red: u8,
1262 pub green: u8,
1263 pub blue: u8,
1264}
1265
1266#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
1268pub struct ScriptToEmbedderChan(GenericCallback<EmbedderMsg>);
1269
1270impl ScriptToEmbedderChan {
1271 pub fn new(
1273 embedder_chan: Sender<EmbedderMsg>,
1274 waker: Box<dyn EventLoopWaker>,
1275 ) -> ScriptToEmbedderChan {
1276 let embedder_callback = GenericCallback::new(move |embedder_msg| {
1277 let msg = match embedder_msg {
1278 Ok(embedder_msg) => embedder_msg,
1279 Err(err) => {
1280 log::warn!("Script to Embedder message error: {err}");
1281 return;
1282 },
1283 };
1284 let _ = embedder_chan.send(msg);
1285 waker.wake();
1286 })
1287 .expect("Failed to create channel");
1288 ScriptToEmbedderChan(embedder_callback)
1289 }
1290
1291 pub fn send(&self, msg: EmbedderMsg) -> SendResult {
1293 self.0.send(msg)
1294 }
1295}