Skip to main content

cdp_driver/protocol/
background_service.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! Defines events for background web platform features.
5//!
6//! Types, command parameters and event payloads for the `BackgroundService`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9//!
10//! This domain is experimental and may change without notice.
11
12use serde::{Deserialize, Serialize};
13
14/// The Background Service that will be associated with the commands/events.
15/// Every Background Service operates independently, but they share the same
16/// API.
17#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
18pub enum ServiceName {
19    /// `backgroundFetch`
20    #[serde(rename = "backgroundFetch")]
21    BackgroundFetch,
22    /// `backgroundSync`
23    #[serde(rename = "backgroundSync")]
24    BackgroundSync,
25    /// `pushMessaging`
26    #[serde(rename = "pushMessaging")]
27    PushMessaging,
28    /// `notifications`
29    #[serde(rename = "notifications")]
30    Notifications,
31    /// `paymentHandler`
32    #[serde(rename = "paymentHandler")]
33    PaymentHandler,
34    /// `periodicBackgroundSync`
35    #[serde(rename = "periodicBackgroundSync")]
36    PeriodicBackgroundSync,
37    /// A value this vendored schema does not list. Chrome adds values ahead of
38    /// the published protocol, so an unrecognised one is kept as it arrived
39    /// rather than failing the payload it came in.
40    #[serde(untagged)]
41    Unrecognized(String),
42}
43
44/// A key-value pair for additional event information to pass along.
45#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
46pub struct EventMetadata {
47    pub key: String,
48    pub value: String,
49}
50
51#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
52pub struct BackgroundServiceEvent {
53    /// Timestamp of the event (in seconds).
54    pub timestamp: crate::protocol::network::TimeSinceEpoch,
55    /// The origin this event belongs to.
56    pub origin: String,
57    /// The Service Worker ID that initiated the event.
58    #[serde(rename = "serviceWorkerRegistrationId")]
59    pub service_worker_registration_id: crate::protocol::service_worker::RegistrationId,
60    /// The Background Service this event belongs to.
61    pub service: ServiceName,
62    /// A description of the event.
63    #[serde(rename = "eventName")]
64    pub event_name: String,
65    /// An identifier that groups related events together.
66    #[serde(rename = "instanceId")]
67    pub instance_id: String,
68    /// A list of event-specific information.
69    #[serde(rename = "eventMetadata")]
70    pub event_metadata: Vec<EventMetadata>,
71    /// Storage key this event belongs to.
72    #[serde(rename = "storageKey")]
73    pub storage_key: String,
74}
75
76/// Enables event updates for the service.
77///
78/// Parameters of `BackgroundService.startObserving`.
79#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
80pub struct StartObservingParams {
81    pub service: ServiceName,
82}
83
84impl crate::typed::Command for StartObservingParams {
85    const METHOD: &'static str = "BackgroundService.startObserving";
86    type Returns = crate::typed::NoReturns;
87}
88
89/// Disables event updates for the service.
90///
91/// Parameters of `BackgroundService.stopObserving`.
92#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
93pub struct StopObservingParams {
94    pub service: ServiceName,
95}
96
97impl crate::typed::Command for StopObservingParams {
98    const METHOD: &'static str = "BackgroundService.stopObserving";
99    type Returns = crate::typed::NoReturns;
100}
101
102/// Set the recording state for the service.
103///
104/// Parameters of `BackgroundService.setRecording`.
105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
106pub struct SetRecordingParams {
107    #[serde(rename = "shouldRecord")]
108    pub should_record: bool,
109    pub service: ServiceName,
110}
111
112impl crate::typed::Command for SetRecordingParams {
113    const METHOD: &'static str = "BackgroundService.setRecording";
114    type Returns = crate::typed::NoReturns;
115}
116
117/// Clears all stored data for the service.
118///
119/// Parameters of `BackgroundService.clearEvents`.
120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
121pub struct ClearEventsParams {
122    pub service: ServiceName,
123}
124
125impl crate::typed::Command for ClearEventsParams {
126    const METHOD: &'static str = "BackgroundService.clearEvents";
127    type Returns = crate::typed::NoReturns;
128}
129
130/// Called when the recording state for the service has been updated.
131///
132/// Payload of the `BackgroundService.recordingStateChanged` event.
133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
134pub struct RecordingStateChangedEvent {
135    #[serde(rename = "isRecording")]
136    pub is_recording: bool,
137    pub service: ServiceName,
138}
139
140impl crate::typed::Event for RecordingStateChangedEvent {
141    const METHOD: &'static str = "BackgroundService.recordingStateChanged";
142}
143
144/// Called with all existing backgroundServiceEvents when enabled, and all new
145/// events afterwards if enabled and recording.
146///
147/// Payload of the `BackgroundService.backgroundServiceEventReceived` event.
148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
149pub struct BackgroundServiceEventReceivedEvent {
150    #[serde(rename = "backgroundServiceEvent")]
151    pub background_service_event: BackgroundServiceEvent,
152}
153
154impl crate::typed::Event for BackgroundServiceEventReceivedEvent {
155    const METHOD: &'static str = "BackgroundService.backgroundServiceEventReceived";
156}