browser_protocol/domstorage/
mod.rs1use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8
9pub type SerializedStorageKey<'a> = Cow<'a, str>;
10
11#[derive(Debug, Clone, Serialize, Deserialize, Default)]
14#[serde(rename_all = "camelCase")]
15pub struct StorageId<'a> {
16 #[serde(skip_serializing_if = "Option::is_none")]
18 securityOrigin: Option<Cow<'a, str>>,
19 #[serde(skip_serializing_if = "Option::is_none")]
21 storageKey: Option<SerializedStorageKey<'a>>,
22 isLocalStorage: bool,
24}
25
26impl<'a> StorageId<'a> {
27 pub fn builder(isLocalStorage: bool) -> StorageIdBuilder<'a> {
28 StorageIdBuilder {
29 securityOrigin: None,
30 storageKey: None,
31 isLocalStorage: isLocalStorage,
32 }
33 }
34 pub fn securityOrigin(&self) -> Option<&str> { self.securityOrigin.as_deref() }
35 pub fn storageKey(&self) -> Option<&SerializedStorageKey<'a>> { self.storageKey.as_ref() }
36 pub fn isLocalStorage(&self) -> bool { self.isLocalStorage }
37}
38
39
40pub struct StorageIdBuilder<'a> {
41 securityOrigin: Option<Cow<'a, str>>,
42 storageKey: Option<SerializedStorageKey<'a>>,
43 isLocalStorage: bool,
44}
45
46impl<'a> StorageIdBuilder<'a> {
47 pub fn securityOrigin(mut self, securityOrigin: impl Into<Cow<'a, str>>) -> Self { self.securityOrigin = Some(securityOrigin.into()); self }
49 pub fn storageKey(mut self, storageKey: SerializedStorageKey<'a>) -> Self { self.storageKey = Some(storageKey); self }
51 pub fn build(self) -> StorageId<'a> {
52 StorageId {
53 securityOrigin: self.securityOrigin,
54 storageKey: self.storageKey,
55 isLocalStorage: self.isLocalStorage,
56 }
57 }
58}
59
60pub type Item<'a> = Vec<Cow<'a, str>>;
63
64
65#[derive(Debug, Clone, Serialize, Deserialize, Default)]
66#[serde(rename_all = "camelCase")]
67pub struct ClearParams<'a> {
68 storageId: StorageId<'a>,
69}
70
71impl<'a> ClearParams<'a> {
72 pub fn builder(storageId: StorageId<'a>) -> ClearParamsBuilder<'a> {
73 ClearParamsBuilder {
74 storageId: storageId,
75 }
76 }
77 pub fn storageId(&self) -> &StorageId<'a> { &self.storageId }
78}
79
80
81pub struct ClearParamsBuilder<'a> {
82 storageId: StorageId<'a>,
83}
84
85impl<'a> ClearParamsBuilder<'a> {
86 pub fn build(self) -> ClearParams<'a> {
87 ClearParams {
88 storageId: self.storageId,
89 }
90 }
91}
92
93impl<'a> ClearParams<'a> { pub const METHOD: &'static str = "DOMStorage.clear"; }
94
95impl<'a> crate::CdpCommand<'a> for ClearParams<'a> {
96 const METHOD: &'static str = "DOMStorage.clear";
97 type Response = crate::EmptyReturns;
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, Default)]
101pub struct DisableParams {}
102
103impl DisableParams { pub const METHOD: &'static str = "DOMStorage.disable"; }
104
105impl<'a> crate::CdpCommand<'a> for DisableParams {
106 const METHOD: &'static str = "DOMStorage.disable";
107 type Response = crate::EmptyReturns;
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize, Default)]
111pub struct EnableParams {}
112
113impl EnableParams { pub const METHOD: &'static str = "DOMStorage.enable"; }
114
115impl<'a> crate::CdpCommand<'a> for EnableParams {
116 const METHOD: &'static str = "DOMStorage.enable";
117 type Response = crate::EmptyReturns;
118}
119
120
121#[derive(Debug, Clone, Serialize, Deserialize, Default)]
122#[serde(rename_all = "camelCase")]
123pub struct GetDOMStorageItemsParams<'a> {
124 storageId: StorageId<'a>,
125}
126
127impl<'a> GetDOMStorageItemsParams<'a> {
128 pub fn builder(storageId: StorageId<'a>) -> GetDOMStorageItemsParamsBuilder<'a> {
129 GetDOMStorageItemsParamsBuilder {
130 storageId: storageId,
131 }
132 }
133 pub fn storageId(&self) -> &StorageId<'a> { &self.storageId }
134}
135
136
137pub struct GetDOMStorageItemsParamsBuilder<'a> {
138 storageId: StorageId<'a>,
139}
140
141impl<'a> GetDOMStorageItemsParamsBuilder<'a> {
142 pub fn build(self) -> GetDOMStorageItemsParams<'a> {
143 GetDOMStorageItemsParams {
144 storageId: self.storageId,
145 }
146 }
147}
148
149
150#[derive(Debug, Clone, Serialize, Deserialize, Default)]
151#[serde(rename_all = "camelCase")]
152pub struct GetDOMStorageItemsReturns<'a> {
153 entries: Vec<Item<'a>>,
154}
155
156impl<'a> GetDOMStorageItemsReturns<'a> {
157 pub fn builder(entries: Vec<Item<'a>>) -> GetDOMStorageItemsReturnsBuilder<'a> {
158 GetDOMStorageItemsReturnsBuilder {
159 entries: entries,
160 }
161 }
162 pub fn entries(&self) -> &[Item<'a>] { &self.entries }
163}
164
165
166pub struct GetDOMStorageItemsReturnsBuilder<'a> {
167 entries: Vec<Item<'a>>,
168}
169
170impl<'a> GetDOMStorageItemsReturnsBuilder<'a> {
171 pub fn build(self) -> GetDOMStorageItemsReturns<'a> {
172 GetDOMStorageItemsReturns {
173 entries: self.entries,
174 }
175 }
176}
177
178impl<'a> GetDOMStorageItemsParams<'a> { pub const METHOD: &'static str = "DOMStorage.getDOMStorageItems"; }
179
180impl<'a> crate::CdpCommand<'a> for GetDOMStorageItemsParams<'a> {
181 const METHOD: &'static str = "DOMStorage.getDOMStorageItems";
182 type Response = GetDOMStorageItemsReturns<'a>;
183}
184
185
186#[derive(Debug, Clone, Serialize, Deserialize, Default)]
187#[serde(rename_all = "camelCase")]
188pub struct RemoveDOMStorageItemParams<'a> {
189 storageId: StorageId<'a>,
190 key: Cow<'a, str>,
191}
192
193impl<'a> RemoveDOMStorageItemParams<'a> {
194 pub fn builder(storageId: StorageId<'a>, key: impl Into<Cow<'a, str>>) -> RemoveDOMStorageItemParamsBuilder<'a> {
195 RemoveDOMStorageItemParamsBuilder {
196 storageId: storageId,
197 key: key.into(),
198 }
199 }
200 pub fn storageId(&self) -> &StorageId<'a> { &self.storageId }
201 pub fn key(&self) -> &str { self.key.as_ref() }
202}
203
204
205pub struct RemoveDOMStorageItemParamsBuilder<'a> {
206 storageId: StorageId<'a>,
207 key: Cow<'a, str>,
208}
209
210impl<'a> RemoveDOMStorageItemParamsBuilder<'a> {
211 pub fn build(self) -> RemoveDOMStorageItemParams<'a> {
212 RemoveDOMStorageItemParams {
213 storageId: self.storageId,
214 key: self.key,
215 }
216 }
217}
218
219impl<'a> RemoveDOMStorageItemParams<'a> { pub const METHOD: &'static str = "DOMStorage.removeDOMStorageItem"; }
220
221impl<'a> crate::CdpCommand<'a> for RemoveDOMStorageItemParams<'a> {
222 const METHOD: &'static str = "DOMStorage.removeDOMStorageItem";
223 type Response = crate::EmptyReturns;
224}
225
226
227#[derive(Debug, Clone, Serialize, Deserialize, Default)]
228#[serde(rename_all = "camelCase")]
229pub struct SetDOMStorageItemParams<'a> {
230 storageId: StorageId<'a>,
231 key: Cow<'a, str>,
232 value: Cow<'a, str>,
233}
234
235impl<'a> SetDOMStorageItemParams<'a> {
236 pub fn builder(storageId: StorageId<'a>, key: impl Into<Cow<'a, str>>, value: impl Into<Cow<'a, str>>) -> SetDOMStorageItemParamsBuilder<'a> {
237 SetDOMStorageItemParamsBuilder {
238 storageId: storageId,
239 key: key.into(),
240 value: value.into(),
241 }
242 }
243 pub fn storageId(&self) -> &StorageId<'a> { &self.storageId }
244 pub fn key(&self) -> &str { self.key.as_ref() }
245 pub fn value(&self) -> &str { self.value.as_ref() }
246}
247
248
249pub struct SetDOMStorageItemParamsBuilder<'a> {
250 storageId: StorageId<'a>,
251 key: Cow<'a, str>,
252 value: Cow<'a, str>,
253}
254
255impl<'a> SetDOMStorageItemParamsBuilder<'a> {
256 pub fn build(self) -> SetDOMStorageItemParams<'a> {
257 SetDOMStorageItemParams {
258 storageId: self.storageId,
259 key: self.key,
260 value: self.value,
261 }
262 }
263}
264
265impl<'a> SetDOMStorageItemParams<'a> { pub const METHOD: &'static str = "DOMStorage.setDOMStorageItem"; }
266
267impl<'a> crate::CdpCommand<'a> for SetDOMStorageItemParams<'a> {
268 const METHOD: &'static str = "DOMStorage.setDOMStorageItem";
269 type Response = crate::EmptyReturns;
270}