constellation_traits/from_script_message.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Messages send from the ScriptThread to the Constellation.
6
7use std::fmt;
8
9use base::Epoch;
10use base::generic_channel::{GenericCallback, GenericReceiver, GenericSender, SendResult};
11use base::id::{
12 BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId,
13 MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId, WebViewId,
14};
15use canvas_traits::canvas::{CanvasId, CanvasMsg};
16use compositing_traits::CrossProcessCompositorApi;
17use content_security_policy::sandboxing_directive::SandboxingFlagSet;
18use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
19use embedder_traits::{
20 AnimationState, FocusSequenceNumber, JSValue, JavaScriptEvaluationError,
21 JavaScriptEvaluationId, MediaSessionEvent, ScriptToEmbedderChan, Theme, TouchEventResult,
22 ViewportDetails,
23};
24use euclid::default::Size2D as UntypedSize2D;
25use fonts_traits::SystemFontServiceProxySender;
26use http::{HeaderMap, Method};
27use ipc_channel::ipc::IpcSender;
28use malloc_size_of_derive::MallocSizeOf;
29use net_traits::policy_container::PolicyContainer;
30use net_traits::request::{Destination, InsecureRequestsPolicy, Referrer, RequestBody};
31use net_traits::{ReferrerPolicy, ResourceThreads};
32use profile_traits::mem::MemoryReportResult;
33use profile_traits::{mem, time as profile_time};
34use rustc_hash::FxHashMap;
35use serde::{Deserialize, Serialize};
36use servo_url::{ImmutableOrigin, ServoUrl};
37use storage_traits::StorageThreads;
38use storage_traits::webstorage_thread::StorageType;
39use strum_macros::IntoStaticStr;
40#[cfg(feature = "webgpu")]
41use webgpu_traits::{WebGPU, WebGPUAdapterResponse};
42use webrender_api::ImageKey;
43
44use crate::structured_data::{BroadcastChannelMsg, StructuredSerializedData};
45use crate::{
46 LogEntry, MessagePortMsg, PortMessageTask, PortTransferInfo, TraversalDirection, WindowSizeType,
47};
48
49/// A Script to Constellation channel.
50#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
51pub struct ScriptToConstellationChan {
52 /// Sender for communicating with constellation thread.
53 pub sender: GenericSender<(PipelineId, ScriptToConstellationMessage)>,
54 /// Used to identify the origin of the message.
55 pub pipeline_id: PipelineId,
56}
57
58impl ScriptToConstellationChan {
59 /// Send ScriptMsg and attach the pipeline_id to the message.
60 pub fn send(&self, msg: ScriptToConstellationMessage) -> SendResult {
61 self.sender.send((self.pipeline_id, msg))
62 }
63}
64
65/// The origin where a given load was initiated.
66/// Useful for origin checks, for example before evaluation a JS URL.
67#[derive(Clone, Debug, Deserialize, Serialize)]
68pub enum LoadOrigin {
69 /// A load originating in the constellation.
70 Constellation,
71 /// A load originating in webdriver.
72 WebDriver,
73 /// A load originating in script.
74 Script(ImmutableOrigin),
75}
76
77/// can be passed to `LoadUrl` to load a page with GET/POST
78/// parameters or headers
79#[derive(Clone, Debug, Deserialize, Serialize)]
80pub struct LoadData {
81 /// The origin where the load started.
82 pub load_origin: LoadOrigin,
83 /// The URL.
84 pub url: ServoUrl,
85 /// The creator pipeline id if this is an about:blank load.
86 pub creator_pipeline_id: Option<PipelineId>,
87 /// The method.
88 #[serde(
89 deserialize_with = "::hyper_serde::deserialize",
90 serialize_with = "::hyper_serde::serialize"
91 )]
92 pub method: Method,
93 /// The headers.
94 #[serde(
95 deserialize_with = "::hyper_serde::deserialize",
96 serialize_with = "::hyper_serde::serialize"
97 )]
98 pub headers: HeaderMap,
99 /// The data that will be used as the body of the request.
100 pub data: Option<RequestBody>,
101 /// The result of evaluating a javascript scheme url.
102 pub js_eval_result: Option<JsEvalResult>,
103 /// The referrer.
104 pub referrer: Referrer,
105 /// The referrer policy.
106 pub referrer_policy: ReferrerPolicy,
107 /// The policy container.
108 pub policy_container: Option<PolicyContainer>,
109
110 /// The source to use instead of a network response for a srcdoc document.
111 pub srcdoc: String,
112 /// The inherited context is Secure, None if not inherited
113 pub inherited_secure_context: Option<bool>,
114 /// The inherited policy for upgrading insecure requests; None if not inherited.
115 pub inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>,
116 /// Whether the page's ancestors have potentially trustworthy origin
117 pub has_trustworthy_ancestor_origin: bool,
118 /// Servo internal: if crash details are present, trigger a crash error page with these details.
119 pub crash: Option<String>,
120 /// Destination, used for CSP checks
121 pub destination: Destination,
122 /// The "creation sandboxing flag set" that this Pipeline should use when it is created.
123 /// See <https://html.spec.whatwg.org/multipage/#determining-the-creation-sandboxing-flags>.
124 pub creation_sandboxing_flag_set: SandboxingFlagSet,
125}
126
127/// The result of evaluating a javascript scheme url.
128#[derive(Clone, Debug, Deserialize, Serialize)]
129pub enum JsEvalResult {
130 /// The js evaluation had a non-string result, 204 status code.
131 /// <https://html.spec.whatwg.org/multipage/#navigate> 12.11
132 NoContent,
133 /// The js evaluation had a string result.
134 Ok(Vec<u8>),
135}
136
137impl LoadData {
138 /// Create a new `LoadData` object.
139 #[allow(clippy::too_many_arguments)]
140 pub fn new(
141 load_origin: LoadOrigin,
142 url: ServoUrl,
143 creator_pipeline_id: Option<PipelineId>,
144 referrer: Referrer,
145 referrer_policy: ReferrerPolicy,
146 inherited_secure_context: Option<bool>,
147 inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>,
148 has_trustworthy_ancestor_origin: bool,
149 creation_sandboxing_flag_set: SandboxingFlagSet,
150 ) -> LoadData {
151 LoadData {
152 load_origin,
153 url,
154 creator_pipeline_id,
155 method: Method::GET,
156 headers: HeaderMap::new(),
157 data: None,
158 js_eval_result: None,
159 referrer,
160 referrer_policy,
161 policy_container: None,
162 srcdoc: "".to_string(),
163 inherited_secure_context,
164 crash: None,
165 inherited_insecure_requests_policy,
166 has_trustworthy_ancestor_origin,
167 destination: Destination::Document,
168 creation_sandboxing_flag_set,
169 }
170 }
171}
172
173/// <https://html.spec.whatwg.org/multipage/#navigation-supporting-concepts:navigationhistorybehavior>
174#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
175pub enum NavigationHistoryBehavior {
176 /// The default value, which will be converted very early in the navigate algorithm into "push"
177 /// or "replace". Usually it becomes "push", but under certain circumstances it becomes
178 /// "replace" instead.
179 #[default]
180 Auto,
181 /// A regular navigation which adds a new session history entry, and will clear the forward
182 /// session history.
183 Push,
184 /// A navigation that will replace the active session history entry.
185 Replace,
186}
187
188/// Entities required to spawn service workers
189#[derive(Clone, Debug, Deserialize, Serialize)]
190pub struct ScopeThings {
191 /// script resource url
192 pub script_url: ServoUrl,
193 /// network load origin of the resource
194 pub worker_load_origin: WorkerScriptLoadOrigin,
195 /// base resources required to create worker global scopes
196 pub init: WorkerGlobalScopeInit,
197 /// the port to receive devtools message from
198 pub devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
199 /// service worker id
200 pub worker_id: WorkerId,
201}
202
203/// Message that gets passed to service worker scope on postMessage
204#[derive(Debug, Deserialize, Serialize)]
205pub struct DOMMessage {
206 /// The origin of the message
207 pub origin: ImmutableOrigin,
208 /// The payload of the message
209 pub data: StructuredSerializedData,
210}
211
212/// Channels to allow service worker manager to communicate with constellation and resource thread
213#[derive(Deserialize, Serialize)]
214pub struct SWManagerSenders {
215 /// Sender of messages to the constellation.
216 pub swmanager_sender: GenericSender<SWManagerMsg>,
217 /// [`ResourceThreads`] for initating fetches or using i/o.
218 pub resource_threads: ResourceThreads,
219 /// [`CrossProcessCompositorApi`] for communicating with the compositor.
220 pub compositor_api: CrossProcessCompositorApi,
221 /// The [`SystemFontServiceProxy`] used to communicate with the `SystemFontService`.
222 pub system_font_service_sender: SystemFontServiceProxySender,
223 /// Sender of messages to the manager.
224 pub own_sender: GenericSender<ServiceWorkerMsg>,
225 /// Receiver of messages from the constellation.
226 pub receiver: GenericReceiver<ServiceWorkerMsg>,
227}
228
229/// Messages sent to Service Worker Manager thread
230#[derive(Debug, Deserialize, Serialize)]
231#[allow(clippy::large_enum_variant)]
232pub enum ServiceWorkerMsg {
233 /// Timeout message sent by active service workers
234 Timeout(ServoUrl),
235 /// Message sent by constellation to forward to a running service worker
236 ForwardDOMMessage(DOMMessage, ServoUrl),
237 /// <https://w3c.github.io/ServiceWorker/#schedule-job-algorithm>
238 ScheduleJob(Job),
239 /// Exit the service worker manager
240 Exit,
241}
242
243#[derive(Debug, Deserialize, PartialEq, Serialize)]
244/// <https://w3c.github.io/ServiceWorker/#dfn-job-type>
245pub enum JobType {
246 /// <https://w3c.github.io/ServiceWorker/#register>
247 Register,
248 /// <https://w3c.github.io/ServiceWorker/#unregister-algorithm>
249 Unregister,
250 /// <https://w3c.github.io/ServiceWorker/#update-algorithm>
251 Update,
252}
253
254#[derive(Debug, Deserialize, Serialize)]
255/// The kind of error the job promise should be rejected with.
256pub enum JobError {
257 /// <https://w3c.github.io/ServiceWorker/#reject-job-promise>
258 TypeError,
259 /// <https://w3c.github.io/ServiceWorker/#reject-job-promise>
260 SecurityError,
261}
262
263#[derive(Debug, Deserialize, Serialize)]
264#[allow(clippy::large_enum_variant)]
265/// Messages sent from Job algorithms steps running in the SW manager,
266/// in order to resolve or reject the job promise.
267pub enum JobResult {
268 /// <https://w3c.github.io/ServiceWorker/#reject-job-promise>
269 RejectPromise(JobError),
270 /// <https://w3c.github.io/ServiceWorker/#resolve-job-promise>
271 ResolvePromise(Job, JobResultValue),
272}
273
274#[derive(Debug, Deserialize, Serialize)]
275/// Jobs are resolved with the help of various values.
276pub enum JobResultValue {
277 /// Data representing a serviceworker registration.
278 Registration {
279 /// The Id of the registration.
280 id: ServiceWorkerRegistrationId,
281 /// The installing worker, if any.
282 installing_worker: Option<ServiceWorkerId>,
283 /// The waiting worker, if any.
284 waiting_worker: Option<ServiceWorkerId>,
285 /// The active worker, if any.
286 active_worker: Option<ServiceWorkerId>,
287 },
288}
289
290#[derive(Debug, Deserialize, Serialize)]
291/// <https://w3c.github.io/ServiceWorker/#dfn-job>
292pub struct Job {
293 /// <https://w3c.github.io/ServiceWorker/#dfn-job-type>
294 pub job_type: JobType,
295 /// <https://w3c.github.io/ServiceWorker/#dfn-job-scope-url>
296 pub scope_url: ServoUrl,
297 /// <https://w3c.github.io/ServiceWorker/#dfn-job-script-url>
298 pub script_url: ServoUrl,
299 /// <https://w3c.github.io/ServiceWorker/#dfn-job-client>
300 pub client: GenericCallback<JobResult>,
301 /// <https://w3c.github.io/ServiceWorker/#job-referrer>
302 pub referrer: ServoUrl,
303 /// Various data needed to process job.
304 pub scope_things: Option<ScopeThings>,
305}
306
307impl Job {
308 /// <https://w3c.github.io/ServiceWorker/#create-job-algorithm>
309 pub fn create_job(
310 job_type: JobType,
311 scope_url: ServoUrl,
312 script_url: ServoUrl,
313 client: GenericCallback<JobResult>,
314 referrer: ServoUrl,
315 scope_things: Option<ScopeThings>,
316 ) -> Job {
317 Job {
318 job_type,
319 scope_url,
320 script_url,
321 client,
322 referrer,
323 scope_things,
324 }
325 }
326}
327
328impl PartialEq for Job {
329 /// Equality criteria as described in <https://w3c.github.io/ServiceWorker/#dfn-job-equivalent>
330 fn eq(&self, other: &Self) -> bool {
331 // TODO: match on job type, take worker type and `update_via_cache_mode` into account.
332 let same_job = self.job_type == other.job_type;
333 if same_job {
334 match self.job_type {
335 JobType::Register | JobType::Update => {
336 self.scope_url == other.scope_url && self.script_url == other.script_url
337 },
338 JobType::Unregister => self.scope_url == other.scope_url,
339 }
340 } else {
341 false
342 }
343 }
344}
345
346/// Messages outgoing from the Service Worker Manager thread to constellation
347#[derive(Debug, Deserialize, Serialize)]
348pub enum SWManagerMsg {
349 /// Placeholder to keep the enum,
350 /// as it will be needed when implementing
351 /// <https://github.com/servo/servo/issues/24660>
352 PostMessageToClient,
353}
354
355/// Used to determine if a script has any pending asynchronous activity.
356#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
357pub enum DocumentState {
358 /// The document has been loaded and is idle.
359 Idle,
360 /// The document is either loading or waiting on an event.
361 Pending,
362}
363
364/// This trait allows creating a `ServiceWorkerManager` without depending on the `script`
365/// crate.
366pub trait ServiceWorkerManagerFactory {
367 /// Create a `ServiceWorkerManager`.
368 fn create(sw_senders: SWManagerSenders, origin: ImmutableOrigin);
369}
370
371/// Specifies the information required to load an auxiliary browsing context.
372#[derive(Debug, Deserialize, Serialize)]
373pub struct AuxiliaryWebViewCreationRequest {
374 /// Load data containing the url to load
375 pub load_data: LoadData,
376 /// The webview that caused this request.
377 pub opener_webview_id: WebViewId,
378 /// The pipeline opener browsing context.
379 pub opener_pipeline_id: PipelineId,
380 /// Sender for the constellation’s response to our request.
381 pub response_sender: IpcSender<Option<AuxiliaryWebViewCreationResponse>>,
382}
383
384/// Constellation’s response to auxiliary browsing context creation requests.
385#[derive(Debug, Deserialize, Serialize)]
386pub struct AuxiliaryWebViewCreationResponse {
387 /// The new webview ID.
388 pub new_webview_id: WebViewId,
389 /// The new pipeline ID.
390 pub new_pipeline_id: PipelineId,
391}
392
393/// Specifies the information required to load an iframe.
394#[derive(Debug, Deserialize, Serialize)]
395pub struct IFrameLoadInfo {
396 /// Pipeline ID of the parent of this iframe
397 pub parent_pipeline_id: PipelineId,
398 /// The ID for this iframe's nested browsing context.
399 pub browsing_context_id: BrowsingContextId,
400 /// The ID for the top-level ancestor browsing context of this iframe's nested browsing context.
401 pub webview_id: WebViewId,
402 /// The new pipeline ID that the iframe has generated.
403 pub new_pipeline_id: PipelineId,
404 /// Whether this iframe should be considered private
405 pub is_private: bool,
406 /// Whether this iframe should be considered secure
407 pub inherited_secure_context: Option<bool>,
408 /// Whether this load should replace the current entry (reload). If true, the current
409 /// entry will be replaced instead of a new entry being added.
410 pub history_handling: NavigationHistoryBehavior,
411}
412
413/// Specifies the information required to load a URL in an iframe.
414#[derive(Debug, Deserialize, Serialize)]
415pub struct IFrameLoadInfoWithData {
416 /// The information required to load an iframe.
417 pub info: IFrameLoadInfo,
418 /// Load data containing the url to load
419 pub load_data: LoadData,
420 /// The old pipeline ID for this iframe, if a page was previously loaded.
421 pub old_pipeline_id: Option<PipelineId>,
422 /// The initial viewport size for this iframe.
423 pub viewport_details: ViewportDetails,
424 /// The [`Theme`] to use within this iframe.
425 pub theme: Theme,
426}
427
428/// Resources required by workerglobalscopes
429#[derive(Clone, Debug, Deserialize, Serialize)]
430pub struct WorkerGlobalScopeInit {
431 /// Chan to a resource thread
432 pub resource_threads: ResourceThreads,
433 /// Chan to a storage thread
434 pub storage_threads: StorageThreads,
435 /// Chan to the memory profiler
436 pub mem_profiler_chan: mem::ProfilerChan,
437 /// Chan to the time profiler
438 pub time_profiler_chan: profile_time::ProfilerChan,
439 /// To devtools sender
440 pub to_devtools_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
441 /// From devtools sender
442 pub from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
443 /// Messages to send to constellation
444 pub script_to_constellation_chan: ScriptToConstellationChan,
445 /// Messages to send to the Embedder
446 pub script_to_embedder_chan: ScriptToEmbedderChan,
447 /// The worker id
448 pub worker_id: WorkerId,
449 /// The pipeline id
450 pub pipeline_id: PipelineId,
451 /// The origin
452 pub origin: ImmutableOrigin,
453 /// The creation URL
454 pub creation_url: ServoUrl,
455 /// True if secure context
456 pub inherited_secure_context: Option<bool>,
457}
458
459/// Common entities representing a network load origin
460#[derive(Clone, Debug, Deserialize, Serialize)]
461pub struct WorkerScriptLoadOrigin {
462 /// referrer url
463 pub referrer_url: Option<ServoUrl>,
464 /// the referrer policy which is used
465 pub referrer_policy: ReferrerPolicy,
466 /// the pipeline id of the entity requesting the load
467 pub pipeline_id: PipelineId,
468}
469
470/// An iframe sizing operation.
471#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
472pub struct IFrameSizeMsg {
473 /// The child browsing context for this iframe.
474 pub browsing_context_id: BrowsingContextId,
475 /// The size and scale factor of the iframe.
476 pub size: ViewportDetails,
477 /// The kind of sizing operation.
478 pub type_: WindowSizeType,
479}
480
481/// An enum that describe a type of keyboard scroll.
482#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
483pub enum KeyboardScroll {
484 /// Scroll the container one line up.
485 Up,
486 /// Scroll the container one line down.
487 Down,
488 /// Scroll the container one "line" left.
489 Left,
490 /// Scroll the container one "line" right.
491 Right,
492 /// Scroll the container one page up.
493 PageUp,
494 /// Scroll the container one page down.
495 PageDown,
496 /// Scroll the container to the vertical start.
497 Home,
498 /// Scroll the container to the vertical end.
499 End,
500}
501
502#[derive(Debug, Deserialize, Serialize)]
503pub enum ScreenshotReadinessResponse {
504 /// The Pipeline associated with this response, is ready for a screenshot at the
505 /// provided [`Epoch`].
506 Ready(Epoch),
507 /// The Pipeline associated with this response is no longer active and should be
508 /// ignored for the purposes of the screenshot.
509 NoLongerActive,
510}
511
512/// Messages from the script to the constellation.
513#[derive(Deserialize, IntoStaticStr, Serialize)]
514pub enum ScriptToConstellationMessage {
515 /// Request to complete the transfer of a set of ports to a router.
516 CompleteMessagePortTransfer(MessagePortRouterId, Vec<MessagePortId>),
517 /// The results of attempting to complete the transfer of a batch of ports.
518 MessagePortTransferResult(
519 /* The router whose transfer of ports succeeded, if any */
520 Option<MessagePortRouterId>,
521 /* The ids of ports transferred successfully */
522 Vec<MessagePortId>,
523 /* The ids, and buffers, of ports whose transfer failed */
524 FxHashMap<MessagePortId, PortTransferInfo>,
525 ),
526 /// A new message-port was created or transferred, with corresponding control-sender.
527 NewMessagePort(MessagePortRouterId, MessagePortId),
528 /// A global has started managing message-ports
529 NewMessagePortRouter(MessagePortRouterId, IpcSender<MessagePortMsg>),
530 /// A global has stopped managing message-ports
531 RemoveMessagePortRouter(MessagePortRouterId),
532 /// A task requires re-routing to an already shipped message-port.
533 RerouteMessagePort(MessagePortId, PortMessageTask),
534 /// A message-port was shipped, let the entangled port know.
535 MessagePortShipped(MessagePortId),
536 /// Entangle two message-ports.
537 EntanglePorts(MessagePortId, MessagePortId),
538 /// Disentangle two message-ports.
539 /// The first is the initiator, the second the other port,
540 /// unless the message is sent to complete a disentanglement,
541 /// in which case the first one is the other port,
542 /// and the second is none.
543 DisentanglePorts(MessagePortId, Option<MessagePortId>),
544 /// A global has started managing broadcast-channels.
545 NewBroadcastChannelRouter(
546 BroadcastChannelRouterId,
547 IpcSender<BroadcastChannelMsg>,
548 ImmutableOrigin,
549 ),
550 /// A global has stopped managing broadcast-channels.
551 RemoveBroadcastChannelRouter(BroadcastChannelRouterId, ImmutableOrigin),
552 /// A global started managing broadcast channels for a given channel-name.
553 NewBroadcastChannelNameInRouter(BroadcastChannelRouterId, String, ImmutableOrigin),
554 /// A global stopped managing broadcast channels for a given channel-name.
555 RemoveBroadcastChannelNameInRouter(BroadcastChannelRouterId, String, ImmutableOrigin),
556 /// Broadcast a message to all same-origin broadcast channels,
557 /// excluding the source of the broadcast.
558 ScheduleBroadcast(BroadcastChannelRouterId, BroadcastChannelMsg),
559 /// Broadcast a storage event to every same-origin pipeline.
560 /// The strings are key, old value and new value.
561 BroadcastStorageEvent(
562 StorageType,
563 ServoUrl,
564 Option<String>,
565 Option<String>,
566 Option<String>,
567 ),
568 /// Indicates whether this pipeline is currently running animations.
569 ChangeRunningAnimationsState(AnimationState),
570 /// Requests that a new 2D canvas thread be created. (This is done in the constellation because
571 /// 2D canvases may use the GPU and we don't want to give untrusted content access to the GPU.)
572 CreateCanvasPaintThread(
573 UntypedSize2D<u64>,
574 IpcSender<Option<(GenericSender<CanvasMsg>, CanvasId, ImageKey)>>,
575 ),
576 /// Notifies the constellation that this pipeline is requesting focus.
577 ///
578 /// When this message is sent, the sender pipeline has already its local
579 /// focus state updated. The constellation, after receiving this message,
580 /// will broadcast messages to other pipelines that are affected by this
581 /// focus operation.
582 ///
583 /// The first field contains the browsing context ID of the container
584 /// element if one was focused.
585 ///
586 /// The second field is a sequence number that the constellation should use
587 /// when sending a focus-related message to the sender pipeline next time.
588 Focus(Option<BrowsingContextId>, FocusSequenceNumber),
589 /// Requests the constellation to focus the specified browsing context.
590 FocusRemoteDocument(BrowsingContextId),
591 /// Get the top-level browsing context info for a given browsing context.
592 GetTopForBrowsingContext(BrowsingContextId, IpcSender<Option<WebViewId>>),
593 /// Get the browsing context id of the browsing context in which pipeline is
594 /// embedded and the parent pipeline id of that browsing context.
595 GetBrowsingContextInfo(
596 PipelineId,
597 IpcSender<Option<(BrowsingContextId, Option<PipelineId>)>>,
598 ),
599 /// Get the nth child browsing context ID for a given browsing context, sorted in tree order.
600 GetChildBrowsingContextId(
601 BrowsingContextId,
602 usize,
603 IpcSender<Option<BrowsingContextId>>,
604 ),
605 /// All pending loads are complete, and the `load` event for this pipeline
606 /// has been dispatched.
607 LoadComplete,
608 /// A new load has been requested, with an option to replace the current entry once loaded
609 /// instead of adding a new entry.
610 LoadUrl(LoadData, NavigationHistoryBehavior),
611 /// Abort loading after sending a LoadUrl message.
612 AbortLoadUrl,
613 /// Post a message to the currently active window of a given browsing context.
614 PostMessage {
615 /// The target of the posted message.
616 target: BrowsingContextId,
617 /// The source of the posted message.
618 source: PipelineId,
619 /// The expected origin of the target.
620 target_origin: Option<ImmutableOrigin>,
621 /// The source origin of the message.
622 /// <https://html.spec.whatwg.org/multipage/#dom-messageevent-origin>
623 source_origin: ImmutableOrigin,
624 /// The data to be posted.
625 data: StructuredSerializedData,
626 },
627 /// Inform the constellation that a fragment was navigated to and whether or not it was a replacement navigation.
628 NavigatedToFragment(ServoUrl, NavigationHistoryBehavior),
629 /// HTMLIFrameElement Forward or Back traversal.
630 TraverseHistory(TraversalDirection),
631 /// Inform the constellation of a pushed history state.
632 PushHistoryState(HistoryStateId, ServoUrl),
633 /// Inform the constellation of a replaced history state.
634 ReplaceHistoryState(HistoryStateId, ServoUrl),
635 /// Gets the length of the joint session history from the constellation.
636 JointSessionHistoryLength(IpcSender<u32>),
637 /// Notification that this iframe should be removed.
638 /// Returns a list of pipelines which were closed.
639 RemoveIFrame(BrowsingContextId, IpcSender<Vec<PipelineId>>),
640 /// Successful response to [crate::ConstellationControlMsg::SetThrottled].
641 SetThrottledComplete(bool),
642 /// A load has been requested in an IFrame.
643 ScriptLoadedURLInIFrame(IFrameLoadInfoWithData),
644 /// A load of the initial `about:blank` has been completed in an IFrame.
645 ScriptNewIFrame(IFrameLoadInfoWithData),
646 /// Script has opened a new auxiliary browsing context.
647 CreateAuxiliaryWebView(AuxiliaryWebViewCreationRequest),
648 /// Mark a new document as active
649 ActivateDocument,
650 /// Set the document state for a pipeline (used by screenshot / reftests)
651 SetDocumentState(DocumentState),
652 /// Update the pipeline Url, which can change after redirections.
653 SetFinalUrl(ServoUrl),
654 /// Script has handled a touch event, and either prevented or allowed default actions.
655 TouchEventProcessed(TouchEventResult),
656 /// A log entry, with the top-level browsing context id and thread name
657 LogEntry(Option<String>, LogEntry),
658 /// Discard the document.
659 DiscardDocument,
660 /// Discard the browsing context.
661 DiscardTopLevelBrowsingContext,
662 /// Notifies the constellation that this pipeline has exited.
663 PipelineExited,
664 /// Send messages from postMessage calls from serviceworker
665 /// to constellation for storing in service worker manager
666 ForwardDOMMessage(DOMMessage, ServoUrl),
667 /// <https://w3c.github.io/ServiceWorker/#schedule-job-algorithm>
668 ScheduleJob(Job),
669 /// Notifies the constellation about media session events
670 /// (i.e. when there is metadata for the active media session, playback state changes...).
671 MediaSessionEvent(PipelineId, MediaSessionEvent),
672 #[cfg(feature = "webgpu")]
673 /// Create a WebGPU Adapter instance
674 RequestAdapter(
675 IpcSender<WebGPUAdapterResponse>,
676 wgpu_core::instance::RequestAdapterOptions,
677 wgpu_core::id::AdapterId,
678 ),
679 #[cfg(feature = "webgpu")]
680 /// Get WebGPU channel
681 GetWebGPUChan(IpcSender<Option<WebGPU>>),
682 /// Notify the constellation of a pipeline's document's title.
683 TitleChanged(PipelineId, String),
684 /// Notify the constellation that the size of some `<iframe>`s has changed.
685 IFrameSizes(Vec<IFrameSizeMsg>),
686 /// Request results from the memory reporter.
687 ReportMemory(IpcSender<MemoryReportResult>),
688 /// Return the result of the evaluated JavaScript with the given [`JavaScriptEvaluationId`].
689 FinishJavaScriptEvaluation(
690 JavaScriptEvaluationId,
691 Result<JSValue, JavaScriptEvaluationError>,
692 ),
693 /// Forward a keyboard scroll operation from an `<iframe>` to a parent pipeline.
694 ForwardKeyboardScroll(PipelineId, KeyboardScroll),
695 /// Notify the Constellation of the screenshot readiness of a given pipeline.
696 RespondToScreenshotReadinessRequest(ScreenshotReadinessResponse),
697}
698
699impl fmt::Debug for ScriptToConstellationMessage {
700 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
701 let variant_string: &'static str = self.into();
702 write!(formatter, "ScriptMsg::{variant_string}")
703 }
704}