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", rename = "securityOrigin")]
18 security_origin: Option<Cow<'a, str>>,
19 #[serde(skip_serializing_if = "Option::is_none", rename = "storageKey")]
21 storage_key: Option<SerializedStorageKey<'a>>,
22 #[serde(rename = "isLocalStorage")]
24 is_local_storage: bool,
25}
26
27impl<'a> StorageId<'a> {
28 pub fn builder(is_local_storage: bool) -> StorageIdBuilder<'a> {
31 StorageIdBuilder {
32 security_origin: None,
33 storage_key: None,
34 is_local_storage: is_local_storage,
35 }
36 }
37 pub fn security_origin(&self) -> Option<&str> { self.security_origin.as_deref() }
39 pub fn storage_key(&self) -> Option<&SerializedStorageKey<'a>> { self.storage_key.as_ref() }
41 pub fn is_local_storage(&self) -> bool { self.is_local_storage }
43}
44
45
46pub struct StorageIdBuilder<'a> {
47 security_origin: Option<Cow<'a, str>>,
48 storage_key: Option<SerializedStorageKey<'a>>,
49 is_local_storage: bool,
50}
51
52impl<'a> StorageIdBuilder<'a> {
53 pub fn security_origin(mut self, security_origin: impl Into<Cow<'a, str>>) -> Self { self.security_origin = Some(security_origin.into()); self }
55 pub fn storage_key(mut self, storage_key: impl Into<SerializedStorageKey<'a>>) -> Self { self.storage_key = Some(storage_key.into()); self }
57 pub fn build(self) -> StorageId<'a> {
58 StorageId {
59 security_origin: self.security_origin,
60 storage_key: self.storage_key,
61 is_local_storage: self.is_local_storage,
62 }
63 }
64}
65
66pub type Item<'a> = Vec<Cow<'a, str>>;
69
70
71#[derive(Debug, Clone, Serialize, Deserialize, Default)]
72#[serde(rename_all = "camelCase")]
73pub struct ClearParams<'a> {
74 #[serde(rename = "storageId")]
75 storage_id: StorageId<'a>,
76}
77
78impl<'a> ClearParams<'a> {
79 pub fn builder(storage_id: StorageId<'a>) -> ClearParamsBuilder<'a> {
82 ClearParamsBuilder {
83 storage_id: storage_id,
84 }
85 }
86 pub fn storage_id(&self) -> &StorageId<'a> { &self.storage_id }
87}
88
89
90pub struct ClearParamsBuilder<'a> {
91 storage_id: StorageId<'a>,
92}
93
94impl<'a> ClearParamsBuilder<'a> {
95 pub fn build(self) -> ClearParams<'a> {
96 ClearParams {
97 storage_id: self.storage_id,
98 }
99 }
100}
101
102impl<'a> ClearParams<'a> { pub const METHOD: &'static str = "DOMStorage.clear"; }
103
104impl<'a> crate::CdpCommand<'a> for ClearParams<'a> {
105 const METHOD: &'static str = "DOMStorage.clear";
106 type Response = crate::EmptyReturns;
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize, Default)]
110pub struct DisableParams {}
111
112impl DisableParams { pub const METHOD: &'static str = "DOMStorage.disable"; }
113
114impl<'a> crate::CdpCommand<'a> for DisableParams {
115 const METHOD: &'static str = "DOMStorage.disable";
116 type Response = crate::EmptyReturns;
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize, Default)]
120pub struct EnableParams {}
121
122impl EnableParams { pub const METHOD: &'static str = "DOMStorage.enable"; }
123
124impl<'a> crate::CdpCommand<'a> for EnableParams {
125 const METHOD: &'static str = "DOMStorage.enable";
126 type Response = crate::EmptyReturns;
127}
128
129
130#[derive(Debug, Clone, Serialize, Deserialize, Default)]
131#[serde(rename_all = "camelCase")]
132pub struct GetDOMStorageItemsParams<'a> {
133 #[serde(rename = "storageId")]
134 storage_id: StorageId<'a>,
135}
136
137impl<'a> GetDOMStorageItemsParams<'a> {
138 pub fn builder(storage_id: StorageId<'a>) -> GetDOMStorageItemsParamsBuilder<'a> {
141 GetDOMStorageItemsParamsBuilder {
142 storage_id: storage_id,
143 }
144 }
145 pub fn storage_id(&self) -> &StorageId<'a> { &self.storage_id }
146}
147
148
149pub struct GetDOMStorageItemsParamsBuilder<'a> {
150 storage_id: StorageId<'a>,
151}
152
153impl<'a> GetDOMStorageItemsParamsBuilder<'a> {
154 pub fn build(self) -> GetDOMStorageItemsParams<'a> {
155 GetDOMStorageItemsParams {
156 storage_id: self.storage_id,
157 }
158 }
159}
160
161
162#[derive(Debug, Clone, Serialize, Deserialize, Default)]
163#[serde(rename_all = "camelCase")]
164pub struct GetDOMStorageItemsReturns<'a> {
165 entries: Vec<Item<'a>>,
166}
167
168impl<'a> GetDOMStorageItemsReturns<'a> {
169 pub fn builder(entries: Vec<Item<'a>>) -> GetDOMStorageItemsReturnsBuilder<'a> {
172 GetDOMStorageItemsReturnsBuilder {
173 entries: entries,
174 }
175 }
176 pub fn entries(&self) -> &[Item<'a>] { &self.entries }
177}
178
179
180pub struct GetDOMStorageItemsReturnsBuilder<'a> {
181 entries: Vec<Item<'a>>,
182}
183
184impl<'a> GetDOMStorageItemsReturnsBuilder<'a> {
185 pub fn build(self) -> GetDOMStorageItemsReturns<'a> {
186 GetDOMStorageItemsReturns {
187 entries: self.entries,
188 }
189 }
190}
191
192impl<'a> GetDOMStorageItemsParams<'a> { pub const METHOD: &'static str = "DOMStorage.getDOMStorageItems"; }
193
194impl<'a> crate::CdpCommand<'a> for GetDOMStorageItemsParams<'a> {
195 const METHOD: &'static str = "DOMStorage.getDOMStorageItems";
196 type Response = GetDOMStorageItemsReturns<'a>;
197}
198
199
200#[derive(Debug, Clone, Serialize, Deserialize, Default)]
201#[serde(rename_all = "camelCase")]
202pub struct RemoveDOMStorageItemParams<'a> {
203 #[serde(rename = "storageId")]
204 storage_id: StorageId<'a>,
205 key: Cow<'a, str>,
206}
207
208impl<'a> RemoveDOMStorageItemParams<'a> {
209 pub fn builder(storage_id: StorageId<'a>, key: impl Into<Cow<'a, str>>) -> RemoveDOMStorageItemParamsBuilder<'a> {
213 RemoveDOMStorageItemParamsBuilder {
214 storage_id: storage_id,
215 key: key.into(),
216 }
217 }
218 pub fn storage_id(&self) -> &StorageId<'a> { &self.storage_id }
219 pub fn key(&self) -> &str { self.key.as_ref() }
220}
221
222
223pub struct RemoveDOMStorageItemParamsBuilder<'a> {
224 storage_id: StorageId<'a>,
225 key: Cow<'a, str>,
226}
227
228impl<'a> RemoveDOMStorageItemParamsBuilder<'a> {
229 pub fn build(self) -> RemoveDOMStorageItemParams<'a> {
230 RemoveDOMStorageItemParams {
231 storage_id: self.storage_id,
232 key: self.key,
233 }
234 }
235}
236
237impl<'a> RemoveDOMStorageItemParams<'a> { pub const METHOD: &'static str = "DOMStorage.removeDOMStorageItem"; }
238
239impl<'a> crate::CdpCommand<'a> for RemoveDOMStorageItemParams<'a> {
240 const METHOD: &'static str = "DOMStorage.removeDOMStorageItem";
241 type Response = crate::EmptyReturns;
242}
243
244
245#[derive(Debug, Clone, Serialize, Deserialize, Default)]
246#[serde(rename_all = "camelCase")]
247pub struct SetDOMStorageItemParams<'a> {
248 #[serde(rename = "storageId")]
249 storage_id: StorageId<'a>,
250 key: Cow<'a, str>,
251 value: Cow<'a, str>,
252}
253
254impl<'a> SetDOMStorageItemParams<'a> {
255 pub fn builder(storage_id: StorageId<'a>, key: impl Into<Cow<'a, str>>, value: impl Into<Cow<'a, str>>) -> SetDOMStorageItemParamsBuilder<'a> {
260 SetDOMStorageItemParamsBuilder {
261 storage_id: storage_id,
262 key: key.into(),
263 value: value.into(),
264 }
265 }
266 pub fn storage_id(&self) -> &StorageId<'a> { &self.storage_id }
267 pub fn key(&self) -> &str { self.key.as_ref() }
268 pub fn value(&self) -> &str { self.value.as_ref() }
269}
270
271
272pub struct SetDOMStorageItemParamsBuilder<'a> {
273 storage_id: StorageId<'a>,
274 key: Cow<'a, str>,
275 value: Cow<'a, str>,
276}
277
278impl<'a> SetDOMStorageItemParamsBuilder<'a> {
279 pub fn build(self) -> SetDOMStorageItemParams<'a> {
280 SetDOMStorageItemParams {
281 storage_id: self.storage_id,
282 key: self.key,
283 value: self.value,
284 }
285 }
286}
287
288impl<'a> SetDOMStorageItemParams<'a> { pub const METHOD: &'static str = "DOMStorage.setDOMStorageItem"; }
289
290impl<'a> crate::CdpCommand<'a> for SetDOMStorageItemParams<'a> {
291 const METHOD: &'static str = "DOMStorage.setDOMStorageItem";
292 type Response = crate::EmptyReturns;
293}