Skip to main content

browser_protocol/deviceaccess/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5/// Device request id.
6
7pub type RequestId<'a> = Cow<'a, str>;
8
9/// A device id.
10
11pub type DeviceId<'a> = Cow<'a, str>;
12
13/// Device information displayed in a user prompt to select a device.
14
15#[derive(Debug, Clone, Serialize, Deserialize, Default)]
16#[serde(rename_all = "camelCase")]
17pub struct PromptDevice<'a> {
18    id: DeviceId<'a>,
19    /// Display name as it appears in a device request user prompt.
20    name: Cow<'a, str>,
21}
22
23impl<'a> PromptDevice<'a> {
24    pub fn builder(id: DeviceId<'a>, name: impl Into<Cow<'a, str>>) -> PromptDeviceBuilder<'a> {
25        PromptDeviceBuilder {
26            id: id,
27            name: name.into(),
28        }
29    }
30    pub fn id(&self) -> &DeviceId<'a> { &self.id }
31    pub fn name(&self) -> &str { self.name.as_ref() }
32}
33
34
35pub struct PromptDeviceBuilder<'a> {
36    id: DeviceId<'a>,
37    name: Cow<'a, str>,
38}
39
40impl<'a> PromptDeviceBuilder<'a> {
41    pub fn build(self) -> PromptDevice<'a> {
42        PromptDevice {
43            id: self.id,
44            name: self.name,
45        }
46    }
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize, Default)]
50pub struct EnableParams {}
51
52impl EnableParams { pub const METHOD: &'static str = "DeviceAccess.enable"; }
53
54impl<'a> crate::CdpCommand<'a> for EnableParams {
55    const METHOD: &'static str = "DeviceAccess.enable";
56    type Response = crate::EmptyReturns;
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize, Default)]
60pub struct DisableParams {}
61
62impl DisableParams { pub const METHOD: &'static str = "DeviceAccess.disable"; }
63
64impl<'a> crate::CdpCommand<'a> for DisableParams {
65    const METHOD: &'static str = "DeviceAccess.disable";
66    type Response = crate::EmptyReturns;
67}
68
69/// Select a device in response to a DeviceAccess.deviceRequestPrompted event.
70
71#[derive(Debug, Clone, Serialize, Deserialize, Default)]
72#[serde(rename_all = "camelCase")]
73pub struct SelectPromptParams<'a> {
74    id: RequestId<'a>,
75    deviceId: DeviceId<'a>,
76}
77
78impl<'a> SelectPromptParams<'a> {
79    pub fn builder(id: RequestId<'a>, deviceId: DeviceId<'a>) -> SelectPromptParamsBuilder<'a> {
80        SelectPromptParamsBuilder {
81            id: id,
82            deviceId: deviceId,
83        }
84    }
85    pub fn id(&self) -> &RequestId<'a> { &self.id }
86    pub fn deviceId(&self) -> &DeviceId<'a> { &self.deviceId }
87}
88
89
90pub struct SelectPromptParamsBuilder<'a> {
91    id: RequestId<'a>,
92    deviceId: DeviceId<'a>,
93}
94
95impl<'a> SelectPromptParamsBuilder<'a> {
96    pub fn build(self) -> SelectPromptParams<'a> {
97        SelectPromptParams {
98            id: self.id,
99            deviceId: self.deviceId,
100        }
101    }
102}
103
104impl<'a> SelectPromptParams<'a> { pub const METHOD: &'static str = "DeviceAccess.selectPrompt"; }
105
106impl<'a> crate::CdpCommand<'a> for SelectPromptParams<'a> {
107    const METHOD: &'static str = "DeviceAccess.selectPrompt";
108    type Response = crate::EmptyReturns;
109}
110
111/// Cancel a prompt in response to a DeviceAccess.deviceRequestPrompted event.
112
113#[derive(Debug, Clone, Serialize, Deserialize, Default)]
114#[serde(rename_all = "camelCase")]
115pub struct CancelPromptParams<'a> {
116    id: RequestId<'a>,
117}
118
119impl<'a> CancelPromptParams<'a> {
120    pub fn builder(id: RequestId<'a>) -> CancelPromptParamsBuilder<'a> {
121        CancelPromptParamsBuilder {
122            id: id,
123        }
124    }
125    pub fn id(&self) -> &RequestId<'a> { &self.id }
126}
127
128
129pub struct CancelPromptParamsBuilder<'a> {
130    id: RequestId<'a>,
131}
132
133impl<'a> CancelPromptParamsBuilder<'a> {
134    pub fn build(self) -> CancelPromptParams<'a> {
135        CancelPromptParams {
136            id: self.id,
137        }
138    }
139}
140
141impl<'a> CancelPromptParams<'a> { pub const METHOD: &'static str = "DeviceAccess.cancelPrompt"; }
142
143impl<'a> crate::CdpCommand<'a> for CancelPromptParams<'a> {
144    const METHOD: &'static str = "DeviceAccess.cancelPrompt";
145    type Response = crate::EmptyReturns;
146}