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
126#[derive(Debug, Clone, Serialize)]
128#[serde(rename_all = "camelCase")]
129pub struct PermissionDescriptor {
130 pub name: String,
132 #[serde(skip_serializing_if = "Option::is_none")]
134 pub sysex: Option<bool>,
135 #[serde(skip_serializing_if = "Option::is_none")]
137 pub user_visible_only: Option<bool>,
138 #[serde(skip_serializing_if = "Option::is_none")]
140 pub allow_without_gesture: Option<bool>,
141 #[serde(skip_serializing_if = "Option::is_none")]
143 pub pan_tilt_zoom: Option<bool>,
144}
145
146impl PermissionDescriptor {
147 pub fn new(name: impl Into<String>) -> Self {
149 Self {
150 name: name.into(),
151 sysex: None,
152 user_visible_only: None,
153 allow_without_gesture: None,
154 pan_tilt_zoom: None,
155 }
156 }
157}
158
159#[derive(Debug, Clone, Serialize)]
161#[serde(rename_all = "camelCase")]
162pub struct GrantPermissionsParams {
163 pub permissions: Vec<PermissionType>,
165 #[serde(skip_serializing_if = "Option::is_none")]
167 pub origin: Option<String>,
168 #[serde(skip_serializing_if = "Option::is_none")]
170 pub browser_context_id: Option<String>,
171}
172
173impl GrantPermissionsParams {
174 pub fn new(permissions: Vec<PermissionType>) -> Self {
176 Self {
177 permissions,
178 origin: None,
179 browser_context_id: None,
180 }
181 }
182
183 #[must_use]
185 pub fn origin(mut self, origin: impl Into<String>) -> Self {
186 self.origin = Some(origin.into());
187 self
188 }
189
190 #[must_use]
192 pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
193 self.browser_context_id = Some(id.into());
194 self
195 }
196}
197
198#[derive(Debug, Clone, Serialize, Default)]
200#[serde(rename_all = "camelCase")]
201pub struct ResetPermissionsParams {
202 #[serde(skip_serializing_if = "Option::is_none")]
204 pub browser_context_id: Option<String>,
205}
206
207impl ResetPermissionsParams {
208 pub fn new() -> Self {
210 Self::default()
211 }
212
213 #[must_use]
215 pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
216 self.browser_context_id = Some(id.into());
217 self
218 }
219}
220
221#[derive(Debug, Clone, Serialize)]
223#[serde(rename_all = "camelCase")]
224pub struct SetPermissionParams {
225 pub permission: PermissionDescriptor,
227 pub setting: PermissionSetting,
229 #[serde(skip_serializing_if = "Option::is_none")]
231 pub origin: Option<String>,
232 #[serde(skip_serializing_if = "Option::is_none")]
234 pub browser_context_id: Option<String>,
235}
236
237impl SetPermissionParams {
238 pub fn new(permission: PermissionDescriptor, setting: PermissionSetting) -> Self {
240 Self {
241 permission,
242 setting,
243 origin: None,
244 browser_context_id: None,
245 }
246 }
247
248 #[must_use]
250 pub fn origin(mut self, origin: impl Into<String>) -> Self {
251 self.origin = Some(origin.into());
252 self
253 }
254
255 #[must_use]
257 pub fn browser_context_id(mut self, id: impl Into<String>) -> Self {
258 self.browser_context_id = Some(id.into());
259 self
260 }
261}
262
263#[derive(Debug, Clone, Serialize, Default)]
265pub struct CloseParams {}
266
267#[derive(Debug, Clone, Serialize, Default)]
269pub struct GetVersionParams {}
270
271#[derive(Debug, Clone, Deserialize)]
273#[serde(rename_all = "camelCase")]
274pub struct GetVersionResult {
275 pub protocol_version: String,
277 pub product: String,
279 pub revision: String,
281 pub user_agent: String,
283 pub js_version: String,
285}
286
287#[cfg(test)]
288mod tests;