Skip to main content

rustenium_bidi_definitions/browsing_context/
commands.rs

1use serde::{Deserialize, Serialize};
2#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3pub struct ActivateParams {
4    #[serde(rename = "context")]
5    pub context: super::types::BrowsingContext,
6}
7impl ActivateParams {
8    pub fn new(context: impl Into<super::types::BrowsingContext>) -> Self {
9        Self {
10            context: context.into(),
11        }
12    }
13}
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub enum ActivateMethod {
16    #[serde(rename = "browsingContext.activate")]
17    Activate,
18}
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
20pub struct Activate {
21    pub method: ActivateMethod,
22    pub params: ActivateParams,
23}
24impl Activate {
25    pub const IDENTIFIER: &'static str = "browsingContext.activate";
26    pub const DOMAIN_DIRECTION: &'static str = "remote";
27    pub fn identifier(&self) -> &'static str {
28        Self::IDENTIFIER
29    }
30}
31impl crate::CommandResult for Activate {
32    type Result = super::results::ActivateResult;
33}
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35pub struct CaptureScreenshotParams {
36    #[serde(rename = "context")]
37    pub context: super::types::BrowsingContext,
38    #[serde(rename = "origin")]
39    #[serde(skip_serializing_if = "Option::is_none")]
40    #[serde(default)]
41    pub origin: Option<CaptureScreenshotOrigin>,
42    #[serde(rename = "format")]
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[serde(default)]
45    pub format: Option<super::types::ImageFormat>,
46    #[serde(rename = "clip")]
47    #[serde(skip_serializing_if = "Option::is_none")]
48    #[serde(default)]
49    pub clip: Option<super::types::ClipRectangle>,
50}
51#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
52pub enum CaptureScreenshotOrigin {
53    #[serde(rename = "viewport")]
54    Viewport,
55    #[serde(rename = "document")]
56    Document,
57}
58impl CaptureScreenshotParams {
59    pub fn new(context: impl Into<super::types::BrowsingContext>) -> Self {
60        Self {
61            context: context.into(),
62            origin: None,
63            format: None,
64            clip: None,
65        }
66    }
67}
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
69pub enum CaptureScreenshotMethod {
70    #[serde(rename = "browsingContext.captureScreenshot")]
71    CaptureScreenshot,
72}
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
74pub struct CaptureScreenshot {
75    pub method: CaptureScreenshotMethod,
76    pub params: CaptureScreenshotParams,
77}
78impl CaptureScreenshot {
79    pub const IDENTIFIER: &'static str = "browsingContext.captureScreenshot";
80    pub const DOMAIN_DIRECTION: &'static str = "remote";
81    pub fn identifier(&self) -> &'static str {
82        Self::IDENTIFIER
83    }
84}
85impl crate::CommandResult for CaptureScreenshot {
86    type Result = super::results::CaptureScreenshotResult;
87}
88#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
89pub struct CloseParams {
90    #[serde(rename = "context")]
91    pub context: super::types::BrowsingContext,
92    #[serde(rename = "promptUnload")]
93    #[serde(skip_serializing_if = "Option::is_none")]
94    #[serde(default = "default_close_params_prompt_unload")]
95    pub prompt_unload: Option<bool>,
96}
97fn default_close_params_prompt_unload() -> Option<bool> {
98    Some(false)
99}
100impl CloseParams {
101    pub fn new(context: impl Into<super::types::BrowsingContext>) -> Self {
102        Self {
103            context: context.into(),
104            prompt_unload: None,
105        }
106    }
107}
108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
109pub enum CloseMethod {
110    #[serde(rename = "browsingContext.close")]
111    Close,
112}
113#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
114pub struct Close {
115    pub method: CloseMethod,
116    pub params: CloseParams,
117}
118impl Close {
119    pub const IDENTIFIER: &'static str = "browsingContext.close";
120    pub const DOMAIN_DIRECTION: &'static str = "remote";
121    pub fn identifier(&self) -> &'static str {
122        Self::IDENTIFIER
123    }
124}
125impl crate::CommandResult for Close {
126    type Result = super::results::CloseResult;
127}
128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
129pub struct CreateParams {
130    #[serde(rename = "type")]
131    pub r#type: super::types::CreateType,
132    #[serde(rename = "referenceContext")]
133    #[serde(skip_serializing_if = "Option::is_none")]
134    #[serde(default)]
135    pub reference_context: Option<super::types::BrowsingContext>,
136    #[serde(rename = "background")]
137    #[serde(skip_serializing_if = "Option::is_none")]
138    #[serde(default = "default_create_params_background")]
139    pub background: Option<bool>,
140    #[serde(rename = "userContext")]
141    #[serde(skip_serializing_if = "Option::is_none")]
142    #[serde(default)]
143    pub user_context: Option<crate::browser::types::UserContext>,
144}
145fn default_create_params_background() -> Option<bool> {
146    Some(false)
147}
148impl CreateParams {
149    pub fn new(r#type: impl Into<super::types::CreateType>) -> Self {
150        Self {
151            r#type: r#type.into(),
152            reference_context: None,
153            background: None,
154            user_context: None,
155        }
156    }
157}
158#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
159pub enum CreateMethod {
160    #[serde(rename = "browsingContext.create")]
161    Create,
162}
163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
164pub struct Create {
165    pub method: CreateMethod,
166    pub params: CreateParams,
167}
168impl Create {
169    pub const IDENTIFIER: &'static str = "browsingContext.create";
170    pub const DOMAIN_DIRECTION: &'static str = "remote";
171    pub fn identifier(&self) -> &'static str {
172        Self::IDENTIFIER
173    }
174}
175impl crate::CommandResult for Create {
176    type Result = super::results::CreateResult;
177}
178#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
179pub struct GetTreeParams {
180    #[serde(rename = "maxDepth")]
181    #[serde(skip_serializing_if = "Option::is_none")]
182    #[serde(default)]
183    pub max_depth: Option<u64>,
184    #[serde(rename = "root")]
185    #[serde(skip_serializing_if = "Option::is_none")]
186    #[serde(default)]
187    pub root: Option<super::types::BrowsingContext>,
188}
189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
190pub enum GetTreeMethod {
191    #[serde(rename = "browsingContext.getTree")]
192    GetTree,
193}
194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
195pub struct GetTree {
196    pub method: GetTreeMethod,
197    pub params: GetTreeParams,
198}
199impl GetTree {
200    pub const IDENTIFIER: &'static str = "browsingContext.getTree";
201    pub const DOMAIN_DIRECTION: &'static str = "remote";
202    pub fn identifier(&self) -> &'static str {
203        Self::IDENTIFIER
204    }
205}
206impl crate::CommandResult for GetTree {
207    type Result = super::results::GetTreeResult;
208}
209#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
210pub struct HandleUserPromptParams {
211    #[serde(rename = "context")]
212    pub context: super::types::BrowsingContext,
213    #[serde(rename = "accept")]
214    #[serde(skip_serializing_if = "Option::is_none")]
215    #[serde(default)]
216    pub accept: Option<bool>,
217    #[serde(rename = "userText")]
218    #[serde(skip_serializing_if = "Option::is_none")]
219    #[serde(default)]
220    pub user_text: Option<String>,
221}
222impl HandleUserPromptParams {
223    pub fn new(context: impl Into<super::types::BrowsingContext>) -> Self {
224        Self {
225            context: context.into(),
226            accept: None,
227            user_text: None,
228        }
229    }
230}
231#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
232pub enum HandleUserPromptMethod {
233    #[serde(rename = "browsingContext.handleUserPrompt")]
234    HandleUserPrompt,
235}
236#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
237pub struct HandleUserPrompt {
238    pub method: HandleUserPromptMethod,
239    pub params: HandleUserPromptParams,
240}
241impl HandleUserPrompt {
242    pub const IDENTIFIER: &'static str = "browsingContext.handleUserPrompt";
243    pub const DOMAIN_DIRECTION: &'static str = "remote";
244    pub fn identifier(&self) -> &'static str {
245        Self::IDENTIFIER
246    }
247}
248impl crate::CommandResult for HandleUserPrompt {
249    type Result = super::results::HandleUserPromptResult;
250}
251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, serde_valid :: Validate)]
252pub struct LocateNodesParams {
253    #[serde(rename = "context")]
254    pub context: super::types::BrowsingContext,
255    #[serde(rename = "locator")]
256    pub locator: super::types::Locator,
257    #[serde(rename = "maxNodeCount")]
258    #[serde(skip_serializing_if = "Option::is_none")]
259    #[serde(default)]
260    #[validate(minimum = 1u64)]
261    pub max_node_count: Option<u64>,
262    #[serde(rename = "serializationOptions")]
263    #[serde(skip_serializing_if = "Option::is_none")]
264    #[serde(default)]
265    pub serialization_options: Option<crate::script::types::SerializationOptions>,
266    #[serde(rename = "startNodes")]
267    #[serde(skip_serializing_if = "Option::is_none")]
268    #[serde(default)]
269    pub start_nodes: Option<Vec<crate::script::types::SharedReference>>,
270}
271impl LocateNodesParams {
272    pub fn new(
273        context: impl Into<super::types::BrowsingContext>,
274        locator: impl Into<super::types::Locator>,
275    ) -> Self {
276        Self {
277            context: context.into(),
278            locator: locator.into(),
279            max_node_count: None,
280            serialization_options: None,
281            start_nodes: None,
282        }
283    }
284}
285#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
286pub enum LocateNodesMethod {
287    #[serde(rename = "browsingContext.locateNodes")]
288    LocateNodes,
289}
290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
291pub struct LocateNodes {
292    pub method: LocateNodesMethod,
293    pub params: LocateNodesParams,
294}
295impl LocateNodes {
296    pub const IDENTIFIER: &'static str = "browsingContext.locateNodes";
297    pub const DOMAIN_DIRECTION: &'static str = "remote";
298    pub fn identifier(&self) -> &'static str {
299        Self::IDENTIFIER
300    }
301}
302impl crate::CommandResult for LocateNodes {
303    type Result = super::results::LocateNodesResult;
304}
305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
306pub struct NavigateParams {
307    #[serde(rename = "context")]
308    pub context: super::types::BrowsingContext,
309    #[serde(rename = "url")]
310    pub url: String,
311    #[serde(rename = "wait")]
312    #[serde(skip_serializing_if = "Option::is_none")]
313    #[serde(default)]
314    pub wait: Option<super::types::ReadinessState>,
315}
316impl NavigateParams {
317    pub fn new(context: impl Into<super::types::BrowsingContext>, url: impl Into<String>) -> Self {
318        Self {
319            context: context.into(),
320            url: url.into(),
321            wait: None,
322        }
323    }
324}
325#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
326pub enum NavigateMethod {
327    #[serde(rename = "browsingContext.navigate")]
328    Navigate,
329}
330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
331pub struct Navigate {
332    pub method: NavigateMethod,
333    pub params: NavigateParams,
334}
335impl Navigate {
336    pub const IDENTIFIER: &'static str = "browsingContext.navigate";
337    pub const DOMAIN_DIRECTION: &'static str = "remote";
338    pub fn identifier(&self) -> &'static str {
339        Self::IDENTIFIER
340    }
341}
342impl crate::CommandResult for Navigate {
343    type Result = super::results::NavigateResult;
344}
345#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
346pub struct PrintParams {
347    #[serde(rename = "context")]
348    pub context: super::types::BrowsingContext,
349    #[serde(rename = "background")]
350    #[serde(skip_serializing_if = "Option::is_none")]
351    #[serde(default = "default_print_params_background")]
352    pub background: Option<bool>,
353    #[serde(rename = "margin")]
354    #[serde(skip_serializing_if = "Option::is_none")]
355    #[serde(default)]
356    pub margin: Option<super::types::PrintMarginParameters>,
357    #[serde(rename = "orientation")]
358    #[serde(skip_serializing_if = "Option::is_none")]
359    #[serde(default)]
360    pub orientation: Option<PrintOrientation>,
361    #[serde(rename = "page")]
362    #[serde(skip_serializing_if = "Option::is_none")]
363    #[serde(default)]
364    pub page: Option<super::types::PrintPageParameters>,
365    #[serde(rename = "pageRanges")]
366    #[serde(skip_serializing_if = "Option::is_none")]
367    #[serde(default)]
368    pub page_ranges: Option<Vec<serde_json::Value>>,
369    #[serde(rename = "scale")]
370    #[serde(skip_serializing_if = "Option::is_none")]
371    #[serde(default = "default_print_params_scale")]
372    pub scale: Option<f64>,
373    #[serde(rename = "shrinkToFit")]
374    #[serde(skip_serializing_if = "Option::is_none")]
375    #[serde(default = "default_print_params_shrink_to_fit")]
376    pub shrink_to_fit: Option<bool>,
377}
378fn default_print_params_background() -> Option<bool> {
379    Some(false)
380}
381fn default_print_params_scale() -> Option<f64> {
382    Some(1f64)
383}
384fn default_print_params_shrink_to_fit() -> Option<bool> {
385    Some(true)
386}
387#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
388pub enum PrintOrientation {
389    #[serde(rename = "portrait")]
390    Portrait,
391    #[serde(rename = "landscape")]
392    Landscape,
393}
394impl PrintParams {
395    pub fn new(context: impl Into<super::types::BrowsingContext>) -> Self {
396        Self {
397            context: context.into(),
398            background: None,
399            margin: None,
400            orientation: None,
401            page: None,
402            page_ranges: None,
403            scale: None,
404            shrink_to_fit: None,
405        }
406    }
407}
408#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
409pub enum PrintMethod {
410    #[serde(rename = "browsingContext.print")]
411    Print,
412}
413#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
414pub struct Print {
415    pub method: PrintMethod,
416    pub params: PrintParams,
417}
418impl Print {
419    pub const IDENTIFIER: &'static str = "browsingContext.print";
420    pub const DOMAIN_DIRECTION: &'static str = "remote";
421    pub fn identifier(&self) -> &'static str {
422        Self::IDENTIFIER
423    }
424}
425impl crate::CommandResult for Print {
426    type Result = super::results::PrintResult;
427}
428#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
429pub struct ReloadParams {
430    #[serde(rename = "context")]
431    pub context: super::types::BrowsingContext,
432    #[serde(rename = "ignoreCache")]
433    #[serde(skip_serializing_if = "Option::is_none")]
434    #[serde(default)]
435    pub ignore_cache: Option<bool>,
436    #[serde(rename = "wait")]
437    #[serde(skip_serializing_if = "Option::is_none")]
438    #[serde(default)]
439    pub wait: Option<super::types::ReadinessState>,
440}
441impl ReloadParams {
442    pub fn new(context: impl Into<super::types::BrowsingContext>) -> Self {
443        Self {
444            context: context.into(),
445            ignore_cache: None,
446            wait: None,
447        }
448    }
449}
450#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
451pub enum ReloadMethod {
452    #[serde(rename = "browsingContext.reload")]
453    Reload,
454}
455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
456pub struct Reload {
457    pub method: ReloadMethod,
458    pub params: ReloadParams,
459}
460impl Reload {
461    pub const IDENTIFIER: &'static str = "browsingContext.reload";
462    pub const DOMAIN_DIRECTION: &'static str = "remote";
463    pub fn identifier(&self) -> &'static str {
464        Self::IDENTIFIER
465    }
466}
467impl crate::CommandResult for Reload {
468    type Result = super::results::ReloadResult;
469}
470#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, serde_valid :: Validate)]
471pub struct SetViewportParams {
472    #[serde(rename = "context")]
473    #[serde(skip_serializing_if = "Option::is_none")]
474    #[serde(default)]
475    pub context: Option<super::types::BrowsingContext>,
476    #[serde(rename = "viewport")]
477    #[serde(skip_serializing_if = "Option::is_none")]
478    #[serde(default)]
479    pub viewport: Option<super::types::Viewport>,
480    #[serde(rename = "devicePixelRatio")]
481    #[serde(skip_serializing_if = "Option::is_none")]
482    #[serde(default)]
483    #[validate(exclusive_minimum = 0f64)]
484    pub device_pixel_ratio: Option<f64>,
485    #[serde(rename = "userContexts")]
486    #[serde(skip_serializing_if = "Option::is_none")]
487    #[serde(default)]
488    pub user_contexts: Option<Vec<crate::browser::types::UserContext>>,
489}
490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
491pub enum SetViewportMethod {
492    #[serde(rename = "browsingContext.setViewport")]
493    SetViewport,
494}
495#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
496pub struct SetViewport {
497    pub method: SetViewportMethod,
498    pub params: SetViewportParams,
499}
500impl SetViewport {
501    pub const IDENTIFIER: &'static str = "browsingContext.setViewport";
502    pub const DOMAIN_DIRECTION: &'static str = "remote";
503    pub fn identifier(&self) -> &'static str {
504        Self::IDENTIFIER
505    }
506}
507impl crate::CommandResult for SetViewport {
508    type Result = super::results::SetViewportResult;
509}
510#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
511pub struct TraverseHistoryParams {
512    #[serde(rename = "context")]
513    pub context: super::types::BrowsingContext,
514    #[serde(rename = "delta")]
515    pub delta: i64,
516}
517impl TraverseHistoryParams {
518    pub fn new(context: impl Into<super::types::BrowsingContext>, delta: impl Into<i64>) -> Self {
519        Self {
520            context: context.into(),
521            delta: delta.into(),
522        }
523    }
524}
525#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
526pub enum TraverseHistoryMethod {
527    #[serde(rename = "browsingContext.traverseHistory")]
528    TraverseHistory,
529}
530#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
531pub struct TraverseHistory {
532    pub method: TraverseHistoryMethod,
533    pub params: TraverseHistoryParams,
534}
535impl TraverseHistory {
536    pub const IDENTIFIER: &'static str = "browsingContext.traverseHistory";
537    pub const DOMAIN_DIRECTION: &'static str = "remote";
538    pub fn identifier(&self) -> &'static str {
539        Self::IDENTIFIER
540    }
541}
542impl crate::CommandResult for TraverseHistory {
543    type Result = super::results::TraverseHistoryResult;
544}
545group_enum ! (BrowsingContextCommand { Activate (Activate) , CaptureScreenshot (CaptureScreenshot) , Close (Close) , Create (Create) , GetTree (GetTree) , HandleUserPrompt (HandleUserPrompt) , LocateNodes (LocateNodes) , Navigate (Navigate) , Print (Print) , Reload (Reload) , SetViewport (SetViewport) , TraverseHistory (TraverseHistory) } + identifiable);