/* 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/. */ //! Messages send from the ScriptThread to the Constellation. use std::fmt; use base::Epoch; use base::generic_channel::{GenericCallback, GenericReceiver, GenericSender, SendResult}; use base::id::{ BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId, MessagePortRouterId, PipelineId, ScriptEventLoopId, ServiceWorkerId, ServiceWorkerRegistrationId, WebViewId, }; use canvas_traits::canvas::{CanvasId, CanvasMsg}; use content_security_policy::sandboxing_directive::SandboxingFlagSet; use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId}; use embedder_traits::user_contents::UserContentManagerId; use embedder_traits::{ AnimationState, FocusSequenceNumber, JSValue, JavaScriptEvaluationError, JavaScriptEvaluationId, MediaSessionEvent, ScriptToEmbedderChan, Theme, ViewportDetails, }; use encoding_rs::Encoding; use euclid::default::Size2D as UntypedSize2D; use fonts_traits::SystemFontServiceProxySender; use http::{HeaderMap, Method}; use ipc_channel::ipc::IpcSender; use malloc_size_of_derive::MallocSizeOf; use net_traits::policy_container::PolicyContainer; use net_traits::request::{Destination, InsecureRequestsPolicy, Referrer, RequestBody}; use net_traits::{ReferrerPolicy, ResourceThreads}; use paint_api::CrossProcessPaintApi; use profile_traits::mem::MemoryReportResult; use profile_traits::{mem, time as profile_time}; use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use servo_url::{ImmutableOrigin, OriginSnapshot, ServoUrl}; use storage_traits::StorageThreads; use storage_traits::webstorage_thread::WebStorageType; use strum::IntoStaticStr; #[cfg(feature = "webgpu")] use webgpu_traits::{WebGPU, WebGPUAdapterResponse}; use crate::structured_data::{BroadcastChannelMsg, StructuredSerializedData}; use crate::{ LogEntry, MessagePortMsg, PortMessageTask, PortTransferInfo, TraversalDirection, WindowSizeType, }; pub type ScriptToConstellationSender = GenericSender<(WebViewId, PipelineId, ScriptToConstellationMessage)>; /// A Script to Constellation channel. #[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] pub struct ScriptToConstellationChan { /// Sender for communicating with constellation thread. pub sender: ScriptToConstellationSender, /// Used to identify the origin `WebView` of the message. pub webview_id: WebViewId, /// Used to identify the origin `Pipeline` of the message. pub pipeline_id: PipelineId, } impl ScriptToConstellationChan { /// Send ScriptMsg and attach the pipeline_id to the message. pub fn send(&self, msg: ScriptToConstellationMessage) -> SendResult { self.sender.send((self.webview_id, self.pipeline_id, msg)) } } /// The origin where a given load was initiated. /// Useful for origin checks, for example before evaluation a JS URL. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum LoadOrigin { /// A load originating in the constellation. Constellation, /// A load originating in webdriver. WebDriver, /// A load originating in script. Script(OriginSnapshot), } /// can be passed to `LoadUrl` to load a page with GET/POST /// parameters or headers #[derive(Clone, Debug, Deserialize, Serialize)] pub struct LoadData { /// The origin where the load started. pub load_origin: LoadOrigin, /// The URL. pub url: ServoUrl, /// pub about_base_url: Option, /// The creator pipeline id if this is an about:blank load. pub creator_pipeline_id: Option, /// The method. #[serde( deserialize_with = "::hyper_serde::deserialize", serialize_with = "::hyper_serde::serialize" )] pub method: Method, /// The headers. #[serde( deserialize_with = "::hyper_serde::deserialize", serialize_with = "::hyper_serde::serialize" )] pub headers: HeaderMap, /// The data that will be used as the body of the request. pub data: Option, /// The result of evaluating a javascript scheme url. pub js_eval_result: Option, /// The referrer. pub referrer: Referrer, /// The referrer policy. pub referrer_policy: ReferrerPolicy, /// The policy container. pub policy_container: Option, /// The source to use instead of a network response for a srcdoc document. pub srcdoc: String, /// The inherited context is Secure, None if not inherited pub inherited_secure_context: Option, /// The inherited policy for upgrading insecure requests; None if not inherited. pub inherited_insecure_requests_policy: Option, /// Whether the page's ancestors have potentially trustworthy origin pub has_trustworthy_ancestor_origin: bool, /// Servo internal: if crash details are present, trigger a crash error page with these details. pub crash: Option, /// Destination, used for CSP checks pub destination: Destination, /// The "creation sandboxing flag set" that this Pipeline should use when it is created. /// See . pub creation_sandboxing_flag_set: SandboxingFlagSet, /// If this is a load operation for an `