Skip to main content

browser_protocol/systeminfo/
mod.rs

1//! The SystemInfo domain defines methods and events for querying low-level system information.
2
3
4use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8/// Describes a single graphics processor (GPU).
9
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct GPUDevice<'a> {
13    /// PCI ID of the GPU vendor, if available; 0 otherwise.
14    vendorId: f64,
15    /// PCI ID of the GPU device, if available; 0 otherwise.
16    deviceId: f64,
17    /// Sub sys ID of the GPU, only available on Windows.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    subSysId: Option<f64>,
20    /// Revision of the GPU, only available on Windows.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    revision: Option<f64>,
23    /// String description of the GPU vendor, if the PCI ID is not available.
24    vendorString: Cow<'a, str>,
25    /// String description of the GPU device, if the PCI ID is not available.
26    deviceString: Cow<'a, str>,
27    /// String description of the GPU driver vendor.
28    driverVendor: Cow<'a, str>,
29    /// String description of the GPU driver version.
30    driverVersion: Cow<'a, str>,
31}
32
33impl<'a> GPUDevice<'a> {
34    pub fn builder(vendorId: f64, deviceId: f64, vendorString: impl Into<Cow<'a, str>>, deviceString: impl Into<Cow<'a, str>>, driverVendor: impl Into<Cow<'a, str>>, driverVersion: impl Into<Cow<'a, str>>) -> GPUDeviceBuilder<'a> {
35        GPUDeviceBuilder {
36            vendorId: vendorId,
37            deviceId: deviceId,
38            subSysId: None,
39            revision: None,
40            vendorString: vendorString.into(),
41            deviceString: deviceString.into(),
42            driverVendor: driverVendor.into(),
43            driverVersion: driverVersion.into(),
44        }
45    }
46    pub fn vendorId(&self) -> f64 { self.vendorId }
47    pub fn deviceId(&self) -> f64 { self.deviceId }
48    pub fn subSysId(&self) -> Option<f64> { self.subSysId }
49    pub fn revision(&self) -> Option<f64> { self.revision }
50    pub fn vendorString(&self) -> &str { self.vendorString.as_ref() }
51    pub fn deviceString(&self) -> &str { self.deviceString.as_ref() }
52    pub fn driverVendor(&self) -> &str { self.driverVendor.as_ref() }
53    pub fn driverVersion(&self) -> &str { self.driverVersion.as_ref() }
54}
55
56
57pub struct GPUDeviceBuilder<'a> {
58    vendorId: f64,
59    deviceId: f64,
60    subSysId: Option<f64>,
61    revision: Option<f64>,
62    vendorString: Cow<'a, str>,
63    deviceString: Cow<'a, str>,
64    driverVendor: Cow<'a, str>,
65    driverVersion: Cow<'a, str>,
66}
67
68impl<'a> GPUDeviceBuilder<'a> {
69    /// Sub sys ID of the GPU, only available on Windows.
70    pub fn subSysId(mut self, subSysId: f64) -> Self { self.subSysId = Some(subSysId); self }
71    /// Revision of the GPU, only available on Windows.
72    pub fn revision(mut self, revision: f64) -> Self { self.revision = Some(revision); self }
73    pub fn build(self) -> GPUDevice<'a> {
74        GPUDevice {
75            vendorId: self.vendorId,
76            deviceId: self.deviceId,
77            subSysId: self.subSysId,
78            revision: self.revision,
79            vendorString: self.vendorString,
80            deviceString: self.deviceString,
81            driverVendor: self.driverVendor,
82            driverVersion: self.driverVersion,
83        }
84    }
85}
86
87/// Describes the width and height dimensions of an entity.
88
89#[derive(Debug, Clone, Serialize, Deserialize, Default)]
90#[serde(rename_all = "camelCase")]
91pub struct Size {
92    /// Width in pixels.
93    width: u64,
94    /// Height in pixels.
95    height: i64,
96}
97
98impl Size {
99    pub fn builder(width: u64, height: i64) -> SizeBuilder {
100        SizeBuilder {
101            width: width,
102            height: height,
103        }
104    }
105    pub fn width(&self) -> u64 { self.width }
106    pub fn height(&self) -> i64 { self.height }
107}
108
109
110pub struct SizeBuilder {
111    width: u64,
112    height: i64,
113}
114
115impl SizeBuilder {
116    pub fn build(self) -> Size {
117        Size {
118            width: self.width,
119            height: self.height,
120        }
121    }
122}
123
124/// Describes a supported video decoding profile with its associated minimum and
125/// maximum resolutions.
126
127#[derive(Debug, Clone, Serialize, Deserialize, Default)]
128#[serde(rename_all = "camelCase")]
129pub struct VideoDecodeAcceleratorCapability<'a> {
130    /// Video codec profile that is supported, e.g. VP9 Profile 2.
131    profile: Cow<'a, str>,
132    /// Maximum video dimensions in pixels supported for this |profile|.
133    maxResolution: Size,
134    /// Minimum video dimensions in pixels supported for this |profile|.
135    minResolution: Size,
136}
137
138impl<'a> VideoDecodeAcceleratorCapability<'a> {
139    pub fn builder(profile: impl Into<Cow<'a, str>>, maxResolution: Size, minResolution: Size) -> VideoDecodeAcceleratorCapabilityBuilder<'a> {
140        VideoDecodeAcceleratorCapabilityBuilder {
141            profile: profile.into(),
142            maxResolution: maxResolution,
143            minResolution: minResolution,
144        }
145    }
146    pub fn profile(&self) -> &str { self.profile.as_ref() }
147    pub fn maxResolution(&self) -> &Size { &self.maxResolution }
148    pub fn minResolution(&self) -> &Size { &self.minResolution }
149}
150
151
152pub struct VideoDecodeAcceleratorCapabilityBuilder<'a> {
153    profile: Cow<'a, str>,
154    maxResolution: Size,
155    minResolution: Size,
156}
157
158impl<'a> VideoDecodeAcceleratorCapabilityBuilder<'a> {
159    pub fn build(self) -> VideoDecodeAcceleratorCapability<'a> {
160        VideoDecodeAcceleratorCapability {
161            profile: self.profile,
162            maxResolution: self.maxResolution,
163            minResolution: self.minResolution,
164        }
165    }
166}
167
168/// Describes a supported video encoding profile with its associated maximum
169/// resolution and maximum framerate.
170
171#[derive(Debug, Clone, Serialize, Deserialize, Default)]
172#[serde(rename_all = "camelCase")]
173pub struct VideoEncodeAcceleratorCapability<'a> {
174    /// Video codec profile that is supported, e.g H264 Main.
175    profile: Cow<'a, str>,
176    /// Maximum video dimensions in pixels supported for this |profile|.
177    maxResolution: Size,
178    /// Maximum encoding framerate in frames per second supported for this
179    /// |profile|, as fraction's numerator and denominator, e.g. 24/1 fps,
180    /// 24000/1001 fps, etc.
181    maxFramerateNumerator: i64,
182    maxFramerateDenominator: i64,
183}
184
185impl<'a> VideoEncodeAcceleratorCapability<'a> {
186    pub fn builder(profile: impl Into<Cow<'a, str>>, maxResolution: Size, maxFramerateNumerator: i64, maxFramerateDenominator: i64) -> VideoEncodeAcceleratorCapabilityBuilder<'a> {
187        VideoEncodeAcceleratorCapabilityBuilder {
188            profile: profile.into(),
189            maxResolution: maxResolution,
190            maxFramerateNumerator: maxFramerateNumerator,
191            maxFramerateDenominator: maxFramerateDenominator,
192        }
193    }
194    pub fn profile(&self) -> &str { self.profile.as_ref() }
195    pub fn maxResolution(&self) -> &Size { &self.maxResolution }
196    pub fn maxFramerateNumerator(&self) -> i64 { self.maxFramerateNumerator }
197    pub fn maxFramerateDenominator(&self) -> i64 { self.maxFramerateDenominator }
198}
199
200
201pub struct VideoEncodeAcceleratorCapabilityBuilder<'a> {
202    profile: Cow<'a, str>,
203    maxResolution: Size,
204    maxFramerateNumerator: i64,
205    maxFramerateDenominator: i64,
206}
207
208impl<'a> VideoEncodeAcceleratorCapabilityBuilder<'a> {
209    pub fn build(self) -> VideoEncodeAcceleratorCapability<'a> {
210        VideoEncodeAcceleratorCapability {
211            profile: self.profile,
212            maxResolution: self.maxResolution,
213            maxFramerateNumerator: self.maxFramerateNumerator,
214            maxFramerateDenominator: self.maxFramerateDenominator,
215        }
216    }
217}
218
219/// YUV subsampling type of the pixels of a given image.
220
221#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
222pub enum SubsamplingFormat {
223    #[default]
224    #[serde(rename = "yuv420")]
225    Yuv420,
226    #[serde(rename = "yuv422")]
227    Yuv422,
228    #[serde(rename = "yuv444")]
229    Yuv444,
230}
231
232/// Image format of a given image.
233
234#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
235pub enum ImageType {
236    #[default]
237    #[serde(rename = "jpeg")]
238    Jpeg,
239    #[serde(rename = "webp")]
240    Webp,
241    #[serde(rename = "unknown")]
242    Unknown,
243}
244
245/// Provides information about the GPU(s) on the system.
246
247#[derive(Debug, Clone, Serialize, Deserialize, Default)]
248#[serde(rename_all = "camelCase")]
249pub struct GPUInfo<'a> {
250    /// The graphics devices on the system. Element 0 is the primary GPU.
251    devices: Vec<GPUDevice<'a>>,
252    /// An optional dictionary of additional GPU related attributes.
253    #[serde(skip_serializing_if = "Option::is_none")]
254    auxAttributes: Option<serde_json::Map<String, JsonValue>>,
255    /// An optional dictionary of graphics features and their status.
256    #[serde(skip_serializing_if = "Option::is_none")]
257    featureStatus: Option<serde_json::Map<String, JsonValue>>,
258    /// An optional array of GPU driver bug workarounds.
259    driverBugWorkarounds: Vec<Cow<'a, str>>,
260    /// Supported accelerated video decoding capabilities.
261    videoDecoding: Vec<VideoDecodeAcceleratorCapability<'a>>,
262    /// Supported accelerated video encoding capabilities.
263    videoEncoding: Vec<VideoEncodeAcceleratorCapability<'a>>,
264}
265
266impl<'a> GPUInfo<'a> {
267    pub fn builder(devices: Vec<GPUDevice<'a>>, driverBugWorkarounds: Vec<Cow<'a, str>>, videoDecoding: Vec<VideoDecodeAcceleratorCapability<'a>>, videoEncoding: Vec<VideoEncodeAcceleratorCapability<'a>>) -> GPUInfoBuilder<'a> {
268        GPUInfoBuilder {
269            devices: devices,
270            auxAttributes: None,
271            featureStatus: None,
272            driverBugWorkarounds: driverBugWorkarounds,
273            videoDecoding: videoDecoding,
274            videoEncoding: videoEncoding,
275        }
276    }
277    pub fn devices(&self) -> &[GPUDevice<'a>] { &self.devices }
278    pub fn auxAttributes(&self) -> Option<&serde_json::Map<String, JsonValue>> { self.auxAttributes.as_ref() }
279    pub fn featureStatus(&self) -> Option<&serde_json::Map<String, JsonValue>> { self.featureStatus.as_ref() }
280    pub fn driverBugWorkarounds(&self) -> &[Cow<'a, str>] { &self.driverBugWorkarounds }
281    pub fn videoDecoding(&self) -> &[VideoDecodeAcceleratorCapability<'a>] { &self.videoDecoding }
282    pub fn videoEncoding(&self) -> &[VideoEncodeAcceleratorCapability<'a>] { &self.videoEncoding }
283}
284
285
286pub struct GPUInfoBuilder<'a> {
287    devices: Vec<GPUDevice<'a>>,
288    auxAttributes: Option<serde_json::Map<String, JsonValue>>,
289    featureStatus: Option<serde_json::Map<String, JsonValue>>,
290    driverBugWorkarounds: Vec<Cow<'a, str>>,
291    videoDecoding: Vec<VideoDecodeAcceleratorCapability<'a>>,
292    videoEncoding: Vec<VideoEncodeAcceleratorCapability<'a>>,
293}
294
295impl<'a> GPUInfoBuilder<'a> {
296    /// An optional dictionary of additional GPU related attributes.
297    pub fn auxAttributes(mut self, auxAttributes: serde_json::Map<String, JsonValue>) -> Self { self.auxAttributes = Some(auxAttributes); self }
298    /// An optional dictionary of graphics features and their status.
299    pub fn featureStatus(mut self, featureStatus: serde_json::Map<String, JsonValue>) -> Self { self.featureStatus = Some(featureStatus); self }
300    pub fn build(self) -> GPUInfo<'a> {
301        GPUInfo {
302            devices: self.devices,
303            auxAttributes: self.auxAttributes,
304            featureStatus: self.featureStatus,
305            driverBugWorkarounds: self.driverBugWorkarounds,
306            videoDecoding: self.videoDecoding,
307            videoEncoding: self.videoEncoding,
308        }
309    }
310}
311
312/// Represents process info.
313
314#[derive(Debug, Clone, Serialize, Deserialize, Default)]
315#[serde(rename_all = "camelCase")]
316pub struct ProcessInfo<'a> {
317    /// Specifies process type.
318    #[serde(rename = "type")]
319    type_: Cow<'a, str>,
320    /// Specifies process id.
321    id: u64,
322    /// Specifies cumulative CPU usage in seconds across all threads of the
323    /// process since the process start.
324    cpuTime: f64,
325}
326
327impl<'a> ProcessInfo<'a> {
328    pub fn builder(type_: impl Into<Cow<'a, str>>, id: u64, cpuTime: f64) -> ProcessInfoBuilder<'a> {
329        ProcessInfoBuilder {
330            type_: type_.into(),
331            id: id,
332            cpuTime: cpuTime,
333        }
334    }
335    pub fn type_(&self) -> &str { self.type_.as_ref() }
336    pub fn id(&self) -> u64 { self.id }
337    pub fn cpuTime(&self) -> f64 { self.cpuTime }
338}
339
340
341pub struct ProcessInfoBuilder<'a> {
342    type_: Cow<'a, str>,
343    id: u64,
344    cpuTime: f64,
345}
346
347impl<'a> ProcessInfoBuilder<'a> {
348    pub fn build(self) -> ProcessInfo<'a> {
349        ProcessInfo {
350            type_: self.type_,
351            id: self.id,
352            cpuTime: self.cpuTime,
353        }
354    }
355}
356
357/// Returns information about the system.
358
359#[derive(Debug, Clone, Serialize, Deserialize, Default)]
360#[serde(rename_all = "camelCase")]
361pub struct GetInfoReturns<'a> {
362    /// Information about the GPUs on the system.
363    gpu: GPUInfo<'a>,
364    /// A platform-dependent description of the model of the machine. On Mac OS, this is, for
365    /// example, 'MacBookPro'. Will be the empty string if not supported.
366    modelName: Cow<'a, str>,
367    /// A platform-dependent description of the version of the machine. On Mac OS, this is, for
368    /// example, '10.1'. Will be the empty string if not supported.
369    modelVersion: Cow<'a, str>,
370    /// The command line string used to launch the browser. Will be the empty string if not
371    /// supported.
372    commandLine: Cow<'a, str>,
373}
374
375impl<'a> GetInfoReturns<'a> {
376    pub fn builder(gpu: GPUInfo<'a>, modelName: impl Into<Cow<'a, str>>, modelVersion: impl Into<Cow<'a, str>>, commandLine: impl Into<Cow<'a, str>>) -> GetInfoReturnsBuilder<'a> {
377        GetInfoReturnsBuilder {
378            gpu: gpu,
379            modelName: modelName.into(),
380            modelVersion: modelVersion.into(),
381            commandLine: commandLine.into(),
382        }
383    }
384    pub fn gpu(&self) -> &GPUInfo<'a> { &self.gpu }
385    pub fn modelName(&self) -> &str { self.modelName.as_ref() }
386    pub fn modelVersion(&self) -> &str { self.modelVersion.as_ref() }
387    pub fn commandLine(&self) -> &str { self.commandLine.as_ref() }
388}
389
390
391pub struct GetInfoReturnsBuilder<'a> {
392    gpu: GPUInfo<'a>,
393    modelName: Cow<'a, str>,
394    modelVersion: Cow<'a, str>,
395    commandLine: Cow<'a, str>,
396}
397
398impl<'a> GetInfoReturnsBuilder<'a> {
399    pub fn build(self) -> GetInfoReturns<'a> {
400        GetInfoReturns {
401            gpu: self.gpu,
402            modelName: self.modelName,
403            modelVersion: self.modelVersion,
404            commandLine: self.commandLine,
405        }
406    }
407}
408
409#[derive(Debug, Clone, Serialize, Deserialize, Default)]
410pub struct GetInfoParams {}
411
412impl GetInfoParams { pub const METHOD: &'static str = "SystemInfo.getInfo"; }
413
414impl<'a> crate::CdpCommand<'a> for GetInfoParams {
415    const METHOD: &'static str = "SystemInfo.getInfo";
416    type Response = GetInfoReturns<'a>;
417}
418
419/// Returns information about the feature state.
420
421#[derive(Debug, Clone, Serialize, Deserialize, Default)]
422#[serde(rename_all = "camelCase")]
423pub struct GetFeatureStateParams<'a> {
424    featureState: Cow<'a, str>,
425}
426
427impl<'a> GetFeatureStateParams<'a> {
428    pub fn builder(featureState: impl Into<Cow<'a, str>>) -> GetFeatureStateParamsBuilder<'a> {
429        GetFeatureStateParamsBuilder {
430            featureState: featureState.into(),
431        }
432    }
433    pub fn featureState(&self) -> &str { self.featureState.as_ref() }
434}
435
436
437pub struct GetFeatureStateParamsBuilder<'a> {
438    featureState: Cow<'a, str>,
439}
440
441impl<'a> GetFeatureStateParamsBuilder<'a> {
442    pub fn build(self) -> GetFeatureStateParams<'a> {
443        GetFeatureStateParams {
444            featureState: self.featureState,
445        }
446    }
447}
448
449/// Returns information about the feature state.
450
451#[derive(Debug, Clone, Serialize, Deserialize, Default)]
452#[serde(rename_all = "camelCase")]
453pub struct GetFeatureStateReturns {
454    featureEnabled: bool,
455}
456
457impl GetFeatureStateReturns {
458    pub fn builder(featureEnabled: bool) -> GetFeatureStateReturnsBuilder {
459        GetFeatureStateReturnsBuilder {
460            featureEnabled: featureEnabled,
461        }
462    }
463    pub fn featureEnabled(&self) -> bool { self.featureEnabled }
464}
465
466
467pub struct GetFeatureStateReturnsBuilder {
468    featureEnabled: bool,
469}
470
471impl GetFeatureStateReturnsBuilder {
472    pub fn build(self) -> GetFeatureStateReturns {
473        GetFeatureStateReturns {
474            featureEnabled: self.featureEnabled,
475        }
476    }
477}
478
479impl<'a> GetFeatureStateParams<'a> { pub const METHOD: &'static str = "SystemInfo.getFeatureState"; }
480
481impl<'a> crate::CdpCommand<'a> for GetFeatureStateParams<'a> {
482    const METHOD: &'static str = "SystemInfo.getFeatureState";
483    type Response = GetFeatureStateReturns;
484}
485
486/// Returns information about all running processes.
487
488#[derive(Debug, Clone, Serialize, Deserialize, Default)]
489#[serde(rename_all = "camelCase")]
490pub struct GetProcessInfoReturns<'a> {
491    /// An array of process info blocks.
492    processInfo: Vec<ProcessInfo<'a>>,
493}
494
495impl<'a> GetProcessInfoReturns<'a> {
496    pub fn builder(processInfo: Vec<ProcessInfo<'a>>) -> GetProcessInfoReturnsBuilder<'a> {
497        GetProcessInfoReturnsBuilder {
498            processInfo: processInfo,
499        }
500    }
501    pub fn processInfo(&self) -> &[ProcessInfo<'a>] { &self.processInfo }
502}
503
504
505pub struct GetProcessInfoReturnsBuilder<'a> {
506    processInfo: Vec<ProcessInfo<'a>>,
507}
508
509impl<'a> GetProcessInfoReturnsBuilder<'a> {
510    pub fn build(self) -> GetProcessInfoReturns<'a> {
511        GetProcessInfoReturns {
512            processInfo: self.processInfo,
513        }
514    }
515}
516
517#[derive(Debug, Clone, Serialize, Deserialize, Default)]
518pub struct GetProcessInfoParams {}
519
520impl GetProcessInfoParams { pub const METHOD: &'static str = "SystemInfo.getProcessInfo"; }
521
522impl<'a> crate::CdpCommand<'a> for GetProcessInfoParams {
523    const METHOD: &'static str = "SystemInfo.getProcessInfo";
524    type Response = GetProcessInfoReturns<'a>;
525}