/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! Types used by the embedding layer and/or exposed to the API. This crate is responsible for //! defining types that cross the process boundary from the embedding/rendering layer all the way //! to script, thus it should have very minimal dependencies on other parts of Servo. If a type //! is not exposed in the API or doesn't involve messages sent to the embedding/libservo layer, it //! is probably a better fit for the `constellation_traits` crate. pub mod input_events; pub mod resources; pub mod user_content_manager; mod webdriver; use std::ffi::c_void; use std::fmt::{Debug, Error, Formatter}; use std::path::PathBuf; use std::sync::Arc; use base::id::{PipelineId, ScrollTreeNodeId, WebViewId}; use crossbeam_channel::Sender; use euclid::{Scale, Size2D}; use http::{HeaderMap, Method, StatusCode}; use ipc_channel::ipc::IpcSender; pub use keyboard_types::{KeyboardEvent, Modifiers}; use log::warn; use malloc_size_of::malloc_size_of_is_0; use malloc_size_of_derive::MallocSizeOf; use num_derive::FromPrimitive; use pixels::Image; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use servo_url::ServoUrl; use strum_macros::IntoStaticStr; use style_traits::CSSPixel; use url::Url; use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel}; pub use crate::input_events::*; pub use crate::webdriver::*; /// Tracks whether Servo isn't shutting down, is in the process of shutting down, /// or has finished shutting down. #[derive(Clone, Copy, Debug, PartialEq)] pub enum ShutdownState { NotShuttingDown, ShuttingDown, FinishedShuttingDown, } /// A cursor for the window. This is different from a CSS cursor (see /// `CursorKind`) in that it has no `Auto` value. #[repr(u8)] #[derive(Clone, Copy, Debug, Deserialize, Eq, FromPrimitive, PartialEq, Serialize)] pub enum Cursor { None, Default, Pointer, ContextMenu, Help, Progress, Wait, Cell, Crosshair, Text, VerticalText, Alias, Copy, Move, NoDrop, NotAllowed, Grab, Grabbing, EResize, NResize, NeResize, NwResize, SResize, SeResize, SwResize, WResize, EwResize, NsResize, NeswResize, NwseResize, ColResize, RowResize, AllScroll, ZoomIn, ZoomOut, } pub trait EventLoopWaker: 'static + Send { fn clone_box(&self) -> Box; fn wake(&self) {} } impl Clone for Box { fn clone(&self) -> Self { self.clone_box() } } /// Sends messages to the embedder. pub struct EmbedderProxy { pub sender: Sender, pub event_loop_waker: Box, } impl EmbedderProxy { pub fn send(&self, message: EmbedderMsg) { // Send a message and kick the OS event loop awake. if let Err(err) = self.sender.send(message) { warn!("Failed to send response ({:?}).", err); } self.event_loop_waker.wake(); } } impl Clone for EmbedderProxy { fn clone(&self) -> EmbedderProxy { EmbedderProxy { sender: self.sender.clone(), event_loop_waker: self.event_loop_waker.clone(), } } } #[derive(Deserialize, Serialize)] pub enum ContextMenuResult { Dismissed, Ignored, Selected(usize), } /// [Simple dialogs](https://html.spec.whatwg.org/multipage/#simple-dialogs) are synchronous dialogs /// that can be opened by web content. Since their messages are controlled by web content, they /// should be presented to the user in a way that makes them impossible to mistake for browser UI. #[derive(Deserialize, Serialize)] pub enum SimpleDialog { /// [`alert()`](https://html.spec.whatwg.org/multipage/#dom-alert). /// TODO: Include details about the document origin. Alert { message: String, response_sender: IpcSender, }, /// [`confirm()`](https://html.spec.whatwg.org/multipage/#dom-confirm). /// TODO: Include details about the document origin. Confirm { message: String, response_sender: IpcSender, }, /// [`prompt()`](https://html.spec.whatwg.org/multipage/#dom-prompt). /// TODO: Include details about the document origin. Prompt { message: String, default: String, response_sender: IpcSender, }, } #[derive(Debug, Default, Deserialize, PartialEq, Serialize)] pub struct AuthenticationResponse { /// Username for http request authentication pub username: String, /// Password for http request authentication pub password: String, } #[derive(Deserialize, PartialEq, Serialize)] pub enum AlertResponse { /// The user chose Ok, or the dialog was otherwise dismissed or ignored. Ok, } impl Default for AlertResponse { fn default() -> Self { // Per , // if we **cannot show simple dialogs**, including cases where the user or user agent decides to ignore // all modal dialogs, we need to return (which represents Ok). Self::Ok } } #[derive(Deserialize, PartialEq, Serialize)] pub enum ConfirmResponse { /// The user chose Ok. Ok, /// The user chose Cancel, or the dialog was otherwise dismissed or ignored. Cancel, } impl Default for ConfirmResponse { fn default() -> Self { // Per , // if we **cannot show simple dialogs**, including cases where the user or user agent decides to ignore // all modal dialogs, we need to return false (which represents Cancel), not true (Ok). Self::Cancel } } #[derive(Deserialize, PartialEq, Serialize)] pub enum PromptResponse { /// The user chose Ok, with the given input. Ok(String), /// The user chose Cancel, or the dialog was otherwise dismissed or ignored. Cancel, } impl Default for PromptResponse { fn default() -> Self { // Per , // if we **cannot show simple dialogs**, including cases where the user or user agent decides to ignore // all modal dialogs, we need to return null (which represents Cancel), not the default input. Self::Cancel } } /// A response to a request to allow or deny an action. #[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] pub enum AllowOrDeny { Allow, Deny, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SelectElementOption { /// A unique identifier for the option that can be used to select it. pub id: usize, /// The label that should be used to display the option to the user. pub label: String, /// Whether or not the option is selectable pub is_disabled: bool, } /// Represents the contents of either an `` element #[derive(Clone, Debug, Deserialize, Serialize)] pub enum SelectElementOptionOrOptgroup { Option(SelectElementOption), Optgroup { label: String, options: Vec, }, } /// Data about a `WebView` or `