viewpoint_cdp/protocol/browser/
mod.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub enum PermissionType {
11 AccessibilityEvents,
13 AudioCapture,
15 BackgroundSync,
17 BackgroundFetch,
19 CapturedSurfaceControl,
21 ClipboardReadWrite,
23 ClipboardSanitizedWrite,
25 DisplayCapture,
27 DurableStorage,
29 Flash,
31 Geolocation,
33 IdleDetection,
35 LocalFonts,
37 Midi,
39 MidiSysex,
41 Nfc,
43 Notifications,
45 PaymentHandler,
47 PeriodicBackgroundSync,
49 ProtectedMediaIdentifier,
51 Sensors,
53 SpeakerSelection,
55 StorageAccess,
57 TopLevelStorageAccess,
59 VideoCapture,
61 VideoCaptureGenericPanTiltZoom,
63 WakeLockScreen,
65 WakeLockSystem,
67 WebAppInstallation,
69 WindowManagement,
71}
72
73impl PermissionType {
74 pub fn as_str(&self) -> &'static str {
76 match self {
77 Self::AccessibilityEvents => "accessibilityEvents",
78 Self::AudioCapture => "audioCapture",
79 Self::BackgroundSync => "backgroundSync",
80 Self::BackgroundFetch => "backgroundFetch",
81 Self::CapturedSurfaceControl => "capturedSurfaceControl",
82 Self::ClipboardReadWrite => "clipboardReadWrite",
83 Self::ClipboardSanitizedWrite => "clipboardSanitizedWrite",
84 Self::DisplayCapture => "displayCapture",
85 Self::DurableStorage => "durableStorage",
86 Self::Flash => "flash",
87 Self::Geolocation => "geolocation",
88 Self::IdleDetection => "idleDetection",
89 Self::LocalFonts => "localFonts",
90 Self::Midi => "midi",
91 Self::MidiSysex => "midiSysex",
92 Self::Nfc => "nfc",
93 Self::Notifications => "notifications",
94 Self::PaymentHandler => "paymentHandler",
95 Self::PeriodicBackgroundSync => "periodicBackgroundSync",
96 Self::ProtectedMediaIdentifier => "protectedMediaIdentifier",
97 Self::Sensors => "sensors",
98 Self::SpeakerSelection => "speakerSelection",
99 Self::StorageAccess => "storageAccess",
100 Self::TopLevelStorageAccess => "topLevelStorageAccess",
101 Self::VideoCapture => "videoCapture",
102 Self::VideoCaptureGenericPanTiltZoom => "videoCaptureGenericPanTiltZoom",
103 Self::WakeLockScreen => "wakeLockScreen",
104 Self::WakeLockSystem => "wakeLockSystem",
105 Self::WebAppInstallation => "webAppInstallation",
106 Self::WindowManagement => "windowManagement",
107 }
108 }
109}
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
113#[serde(rename_all = "camelCase")]
114#[derive(Default)]
115pub enum PermissionSetting {
116 #[default]
118 Granted,
119 Denied,
121 Prompt,
123}
124
125#[derive(Debug, Clone, Serialize)]
127#[serde(rename_all = "camelCase")]
128pub struct PermissionDescriptor {
129 pub name: String,
131 #[serde(skip_serializing_if = "Option::is_none")]
133 pub sysex: Option<bool>,
134 #[serde(skip_serializing_if = "Option::is_none")]
136 pub user_visible_only: Option<bool>,
137 #[serde(skip_serializing_if = "Option::is_none")]
139 pub allow_without_gesture: Option<bool>,
140 #[serde(skip_serializing_if = "Option::is_none")]
142 pub pan_tilt_zoom: Option<bool>,
143}
144
145impl PermissionDescriptor {
146 pub fn new(name: impl Into<String>) -> Self {
148 Self {
149 name: name.into(),
150 sysex: None,
151 user_visible_only: None,
152 allow_without_gesture: None,
153 pan_tilt_zoom: None,
154 }
155 }
156}
157
158#[derive(Debug, Clone, Serialize)]
160#[serde(rename_all = "camelCase")]
161pub struct GrantPermissionsParams {
162 pub permissions: Vec<PermissionType>,
164 #[serde(skip_serializing_if = "Option::is_none")]
166 pub origin: Option<String>,
167 #[serde(skip_serializing_if = "Option::is_none")]
169 pub browser_context_id: Option<String>,
170}
171
172impl GrantPermissionsParams {
173 pub fn new(permissions: Vec<PermissionType>) -> Self {
175 Self {
176 permissions,
177 origin: None,
178 browser_context_id: None,
179 }
180 }
181
182 #[must_use]
184 pub fn origin(mut self, origin: impl Into<String>) -> Self {
185 self.origin = Some(origin.into());
186 self
187 }
188
189 #[must_use]
191 pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
192 self.browser_context_id = Some(id.into());
193 self
194 }
195}
196
197#[derive(Debug, Clone, Serialize, Default)]
199#[serde(rename_all = "camelCase")]
200pub struct ResetPermissionsParams {
201 #[serde(skip_serializing_if = "Option::is_none")]
203 pub browser_context_id: Option<String>,
204}
205
206impl ResetPermissionsParams {
207 pub fn new() -> Self {
209 Self::default()
210 }
211
212 #[must_use]
214 pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
215 self.browser_context_id = Some(id.into());
216 self
217 }
218}
219
220#[derive(Debug, Clone, Serialize)]
222#[serde(rename_all = "camelCase")]
223pub struct SetPermissionParams {
224 pub permission: PermissionDescriptor,
226 pub setting: PermissionSetting,
228 #[serde(skip_serializing_if = "Option::is_none")]
230 pub origin: Option<String>,
231 #[serde(skip_serializing_if = "Option::is_none")]
233 pub browser_context_id: Option<String>,
234}
235
236impl SetPermissionParams {
237 pub fn new(permission: PermissionDescriptor, setting: PermissionSetting) -> Self {
239 Self {
240 permission,
241 setting,
242 origin: None,
243 browser_context_id: None,
244 }
245 }
246
247 #[must_use]
249 pub fn origin(mut self, origin: impl Into<String>) -> Self {
250 self.origin = Some(origin.into());
251 self
252 }
253
254 #[must_use]
256 pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
257 self.browser_context_id = Some(id.into());
258 self
259 }
260}
261
262#[derive(Debug, Clone, Serialize, Default)]
264pub struct CloseParams {}
265
266#[derive(Debug, Clone, Serialize, Default)]
268pub struct GetVersionParams {}
269
270#[derive(Debug, Clone, Deserialize)]
272#[serde(rename_all = "camelCase")]
273pub struct GetVersionResult {
274 pub protocol_version: String,
276 pub product: String,
278 pub revision: String,
280 pub user_agent: String,
282 pub js_version: String,
284}
285
286#[cfg(test)]
287mod tests;