webdriverbidi/model/
browsing_context.rs

1use serde::{Deserialize, Serialize};
2
3use crate::model::browser::{ClientWindow, UserContext};
4use crate::model::common::{JsInt, JsUint};
5use crate::model::script::{NodeRemoteValue, SerializationOptions, SharedReference};
6use crate::model::session::UserPromptHandlerType;
7
8#[derive(Debug, Serialize, Deserialize)]
9#[serde(untagged)]
10pub enum BrowsingContextCommand {
11    Activate(Activate),
12    CaptureScreenshot(CaptureScreenshot),
13    Close(Close),
14    Create(Create),
15    GetTree(GetTree),
16    HandleUserPrompt(HandleUserPrompt),
17    LocateNodes(LocateNodes),
18    Navigate(Navigate),
19    Print(Print),
20    Reload(Reload),
21    SetViewport(SetViewport),
22    TraverseHistory(TraverseHistory),
23}
24
25#[derive(Serialize, Deserialize, Debug)]
26#[serde(untagged)]
27pub enum BrowsingContextResult {
28    CaptureScreenshotResult(CaptureScreenshotResult),
29    CreateResult(CreateResult),
30    GetTreeResult(GetTreeResult),
31    LocateNodesResult(LocateNodesResult),
32    NavigateResult(NavigateResult),
33    PrintResult(PrintResult),
34    TraverseHistoryResult(TraverseHistoryResult),
35}
36
37#[derive(Serialize, Deserialize, Debug)]
38#[serde(untagged)]
39pub enum BrowsingContextEvent {
40    ContextCreated(ContextCreated),
41    ContextDestroyed(ContextDestroyed),
42    DomContentLoaded(DomContentLoaded),
43    DownloadEnd(DownloadEnd),
44    DownloadWillBegin(DownloadWillBegin),
45    FragmentNavigated(FragmentNavigated),
46    HistoryUpdated(HistoryUpdated),
47    Load(Load),
48    NavigationAborted(NavigationAborted),
49    NavigationCommitted(NavigationCommitted),
50    NavigationFailed(NavigationFailed),
51    NavigationStarted(NavigationStarted),
52    UserPromptClosed(UserPromptClosed),
53    UserPromptOpened(UserPromptOpened),
54}
55
56pub type BrowsingContext = String;
57
58pub type InfoList = Vec<Info>;
59
60#[derive(Serialize, Deserialize, Debug)]
61pub struct Info {
62    pub children: Option<InfoList>,
63    #[serde(rename = "clientWindow", skip_serializing_if = "Option::is_none")]
64    pub client_window: Option<ClientWindow>,
65    pub context: BrowsingContext,
66    #[serde(rename = "originalOpener")]
67    pub original_opener: Option<BrowsingContext>,
68    pub url: String,
69    #[serde(rename = "userContext")]
70    pub user_context: UserContext,
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub parent: Option<BrowsingContext>,
73}
74
75#[derive(Debug, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum Locator {
78    AccessibilityLocator(AccessibilityLocator),
79    CssLocator(CssLocator),
80    ContextLocator(ContextLocator),
81    InnerTextLocator(InnerTextLocator),
82    XPathLocator(XPathLocator),
83}
84
85#[derive(Debug, Serialize, Deserialize)]
86pub struct AccessibilityLocator {
87    #[serde(rename = "type")]
88    pub locator_type: String,
89    pub value: AccessibilityLocatorValue,
90}
91
92impl AccessibilityLocator {
93    pub fn new(value: AccessibilityLocatorValue) -> Self {
94        Self {
95            locator_type: "accessibility".to_string(),
96            value,
97        }
98    }
99}
100
101#[derive(Debug, Serialize, Deserialize)]
102pub struct AccessibilityLocatorValue {
103    #[serde(skip_serializing_if = "Option::is_none")]
104    pub name: Option<String>,
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub role: Option<String>,
107}
108
109impl AccessibilityLocatorValue {
110    pub fn new(name: Option<String>, role: Option<String>) -> Self {
111        Self { name, role }
112    }
113}
114
115#[derive(Debug, Serialize, Deserialize)]
116pub struct CssLocator {
117    #[serde(rename = "type")]
118    pub locator_type: String,
119    pub value: String,
120}
121
122impl CssLocator {
123    pub fn new(value: String) -> Self {
124        Self {
125            locator_type: "css".to_string(),
126            value,
127        }
128    }
129}
130
131#[derive(Serialize, Deserialize, Debug)]
132pub struct ContextLocator {
133    #[serde(rename = "type")]
134    pub locator_type: String,
135    pub value: ContextValue,
136}
137
138impl ContextLocator {
139    pub fn new(value: ContextValue) -> Self {
140        Self {
141            locator_type: "context".to_string(),
142            value,
143        }
144    }
145}
146
147#[derive(Serialize, Deserialize, Debug)]
148pub struct ContextValue {
149    pub context: BrowsingContext,
150}
151
152impl ContextValue {
153    pub fn new(context: BrowsingContext) -> Self {
154        Self { context }
155    }
156}
157
158#[derive(Debug, Serialize, Deserialize)]
159pub struct InnerTextLocator {
160    #[serde(rename = "type")]
161    pub locator_type: String,
162    pub value: String,
163    #[serde(rename = "ignoreCase", skip_serializing_if = "Option::is_none")]
164    pub ignore_case: Option<bool>,
165    #[serde(rename = "matchType", skip_serializing_if = "Option::is_none")]
166    pub match_type: Option<InnerTextLocatorMatchType>,
167    #[serde(rename = "maxDepth", skip_serializing_if = "Option::is_none")]
168    pub max_depth: Option<JsUint>,
169}
170
171impl InnerTextLocator {
172    pub fn new(
173        value: String,
174        ignore_case: Option<bool>,
175        match_type: Option<InnerTextLocatorMatchType>,
176        max_depth: Option<JsUint>,
177    ) -> Self {
178        Self {
179            locator_type: "innerText".to_string(),
180            value,
181            ignore_case,
182            match_type,
183            max_depth,
184        }
185    }
186}
187
188#[derive(Debug, Serialize, Deserialize)]
189#[serde(rename_all = "lowercase")]
190pub enum InnerTextLocatorMatchType {
191    Full,
192    Partial,
193}
194
195#[derive(Debug, Serialize, Deserialize)]
196pub struct XPathLocator {
197    #[serde(rename = "type")]
198    pub locator_type: String,
199    pub value: String,
200}
201
202impl XPathLocator {
203    pub fn new(value: String) -> Self {
204        Self {
205            locator_type: "xpath".to_string(),
206            value,
207        }
208    }
209}
210
211pub type Navigation = String;
212
213#[derive(Serialize, Deserialize, Debug)]
214pub struct BaseNavigationInfo {
215    pub context: BrowsingContext,
216    pub navigation: Option<Navigation>,
217    pub timestamp: JsUint,
218    pub url: String,
219}
220
221#[derive(Debug, Serialize, Deserialize)]
222pub struct NavigationInfo {
223    #[serde(flatten)]
224    pub base: BaseNavigationInfo,
225}
226
227#[derive(Debug, Serialize, Deserialize)]
228#[serde(rename_all = "lowercase")]
229pub enum ReadinessState {
230    Complete,
231    Interactive,
232    None,
233}
234
235#[derive(Debug, Serialize, Deserialize)]
236#[serde(rename_all = "lowercase")]
237pub enum UserPromptType {
238    Alert,
239    BeforeUnload,
240    Confirm,
241    Prompt,
242}
243
244#[derive(Debug, Serialize, Deserialize)]
245pub struct Activate {
246    pub method: String,
247    pub params: ActivateParameters,
248}
249
250impl Activate {
251    pub fn new(params: ActivateParameters) -> Self {
252        Self {
253            method: "browsingContext.activate".to_string(),
254            params,
255        }
256    }
257}
258
259#[derive(Debug, Serialize, Deserialize)]
260pub struct ActivateParameters {
261    pub context: BrowsingContext,
262}
263
264impl ActivateParameters {
265    pub fn new(context: BrowsingContext) -> Self {
266        Self { context }
267    }
268}
269
270#[derive(Debug, Serialize, Deserialize)]
271pub struct CaptureScreenshot {
272    pub method: String,
273    pub params: CaptureScreenshotParameters,
274}
275
276impl CaptureScreenshot {
277    pub fn new(params: CaptureScreenshotParameters) -> Self {
278        Self {
279            method: "browsingContext.captureScreenshot".to_string(),
280            params,
281        }
282    }
283}
284
285#[derive(Debug, Serialize, Deserialize)]
286pub struct CaptureScreenshotParameters {
287    pub context: BrowsingContext,
288    #[serde(skip_serializing_if = "Option::is_none")]
289    pub origin: Option<CaptureScreenshotParametersOrigin>,
290    #[serde(skip_serializing_if = "Option::is_none")]
291    pub format: Option<ImageFormat>,
292    #[serde(skip_serializing_if = "Option::is_none")]
293    pub clip: Option<ClipRectangle>,
294}
295
296impl CaptureScreenshotParameters {
297    pub fn new(
298        context: BrowsingContext,
299        origin: Option<CaptureScreenshotParametersOrigin>,
300        format: Option<ImageFormat>,
301        clip: Option<ClipRectangle>,
302    ) -> Self {
303        Self {
304            context,
305            origin,
306            format,
307            clip,
308        }
309    }
310}
311
312#[derive(Debug, Serialize, Deserialize)]
313#[serde(rename_all = "lowercase")]
314pub enum CaptureScreenshotParametersOrigin {
315    Document,
316    Viewport,
317}
318
319#[derive(Debug, Serialize, Deserialize)]
320pub struct ImageFormat {
321    #[serde(rename = "type")]
322    pub image_format_type: String,
323    #[serde(skip_serializing_if = "Option::is_none")]
324    pub quality: Option<f32>, // 0.0..1.0
325}
326
327impl ImageFormat {
328    pub fn new(image_format_type: String, quality: Option<f32>) -> Self {
329        Self {
330            image_format_type,
331            quality,
332        }
333    }
334}
335
336#[derive(Debug, Serialize, Deserialize)]
337#[serde(untagged)]
338pub enum ClipRectangle {
339    BoxClipRectangle(BoxClipRectangle),
340    ElementClipRectangle(ElementClipRectangle),
341}
342
343#[derive(Debug, Serialize, Deserialize)]
344pub struct ElementClipRectangle {
345    #[serde(rename = "type")]
346    pub clip_rectangle_type: String,
347    pub element: SharedReference,
348}
349
350impl ElementClipRectangle {
351    pub fn new(element: SharedReference) -> Self {
352        Self {
353            clip_rectangle_type: "element".to_string(),
354            element,
355        }
356    }
357}
358
359#[derive(Debug, Serialize, Deserialize)]
360pub struct BoxClipRectangle {
361    #[serde(rename = "type")]
362    pub clip_rectangle_type: String,
363    pub x: f32,
364    pub y: f32,
365    pub width: f32,
366    pub height: f32,
367}
368
369impl BoxClipRectangle {
370    pub fn new(x: f32, y: f32, width: f32, height: f32) -> Self {
371        Self {
372            clip_rectangle_type: "box".to_string(),
373            x,
374            y,
375            width,
376            height,
377        }
378    }
379}
380
381#[derive(Serialize, Deserialize, Debug)]
382pub struct CaptureScreenshotResult {
383    pub data: String,
384}
385
386#[derive(Debug, Serialize, Deserialize)]
387pub struct Close {
388    pub method: String,
389    pub params: CloseParameters,
390}
391
392impl Close {
393    pub fn new(params: CloseParameters) -> Self {
394        Self {
395            method: "browsingContext.close".to_string(),
396            params,
397        }
398    }
399}
400
401#[derive(Debug, Serialize, Deserialize)]
402pub struct CloseParameters {
403    pub context: BrowsingContext,
404    #[serde(rename = "promptUnload", skip_serializing_if = "Option::is_none")]
405    pub prompt_unload: Option<bool>,
406}
407
408impl CloseParameters {
409    pub fn new(context: BrowsingContext, prompt_unload: Option<bool>) -> Self {
410        Self {
411            context,
412            prompt_unload,
413        }
414    }
415}
416
417#[derive(Debug, Serialize, Deserialize)]
418pub struct Create {
419    pub method: String,
420    pub params: CreateParameters,
421}
422
423impl Create {
424    pub fn new(params: CreateParameters) -> Self {
425        Self {
426            method: "browsingContext.create".to_string(),
427            params,
428        }
429    }
430}
431
432#[derive(Debug, Serialize, Deserialize)]
433#[serde(rename_all = "lowercase")]
434pub enum CreateType {
435    Tab,
436    Window,
437}
438
439#[derive(Debug, Serialize, Deserialize)]
440pub struct CreateParameters {
441    #[serde(rename = "type")]
442    pub create_type: CreateType,
443    #[serde(rename = "referenceContext", skip_serializing_if = "Option::is_none")]
444    pub reference_context: Option<BrowsingContext>,
445    #[serde(skip_serializing_if = "Option::is_none")]
446    pub background: Option<bool>,
447    #[serde(rename = "userContext", skip_serializing_if = "Option::is_none")]
448    pub user_context: Option<UserContext>,
449}
450
451impl CreateParameters {
452    pub fn new(
453        create_type: CreateType,
454        reference_context: Option<BrowsingContext>,
455        background: Option<bool>,
456        user_context: Option<UserContext>,
457    ) -> Self {
458        Self {
459            create_type,
460            reference_context,
461            background,
462            user_context,
463        }
464    }
465}
466
467#[derive(Serialize, Deserialize, Debug)]
468pub struct CreateResult {
469    pub context: BrowsingContext,
470}
471
472#[derive(Debug, Serialize, Deserialize)]
473pub struct GetTree {
474    pub method: String,
475    pub params: GetTreeParameters,
476}
477
478impl GetTree {
479    pub fn new(params: GetTreeParameters) -> Self {
480        Self {
481            method: "browsingContext.getTree".to_string(),
482            params,
483        }
484    }
485}
486
487#[derive(Debug, Serialize, Deserialize)]
488pub struct GetTreeParameters {
489    #[serde(rename = "maxDepth", skip_serializing_if = "Option::is_none")]
490    pub max_depth: Option<JsUint>,
491    #[serde(skip_serializing_if = "Option::is_none")]
492    pub root: Option<BrowsingContext>,
493}
494
495impl GetTreeParameters {
496    pub fn new(max_depth: Option<JsUint>, root: Option<BrowsingContext>) -> Self {
497        Self { max_depth, root }
498    }
499}
500
501#[derive(Serialize, Deserialize, Debug)]
502pub struct GetTreeResult {
503    pub contexts: InfoList,
504}
505
506#[derive(Debug, Serialize, Deserialize)]
507pub struct HandleUserPrompt {
508    pub method: String,
509    pub params: HandleUserPromptParameters,
510}
511
512impl HandleUserPrompt {
513    pub fn new(params: HandleUserPromptParameters) -> Self {
514        Self {
515            method: "browsingContext.handleUserPrompt".to_string(),
516            params,
517        }
518    }
519}
520
521#[derive(Debug, Serialize, Deserialize)]
522pub struct HandleUserPromptParameters {
523    pub context: BrowsingContext,
524    #[serde(skip_serializing_if = "Option::is_none")]
525    pub accept: Option<bool>,
526    #[serde(skip_serializing_if = "Option::is_none")]
527    pub user_text: Option<String>,
528}
529
530impl HandleUserPromptParameters {
531    pub fn new(context: BrowsingContext, accept: Option<bool>, user_text: Option<String>) -> Self {
532        Self {
533            context,
534            accept,
535            user_text,
536        }
537    }
538}
539
540#[derive(Debug, Serialize, Deserialize)]
541pub struct LocateNodes {
542    pub method: String,
543    pub params: LocateNodesParameters,
544}
545
546impl LocateNodes {
547    pub fn new(params: LocateNodesParameters) -> Self {
548        Self {
549            method: "browsingContext.locateNodes".to_string(),
550            params,
551        }
552    }
553}
554
555#[derive(Debug, Serialize, Deserialize)]
556pub struct LocateNodesParameters {
557    pub context: BrowsingContext,
558    pub locator: Locator,
559    #[serde(rename = "maxNodeCount", skip_serializing_if = "Option::is_none")]
560    pub max_node_count: Option<JsUint>,
561    #[serde(
562        rename = "serializationOptions",
563        skip_serializing_if = "Option::is_none"
564    )]
565    pub serialization_options: Option<SerializationOptions>,
566    #[serde(rename = "startNodes", skip_serializing_if = "Option::is_none")]
567    pub start_nodes: Option<Vec<SharedReference>>,
568}
569
570impl LocateNodesParameters {
571    pub fn new(
572        context: BrowsingContext,
573        locator: Locator,
574        max_node_count: Option<JsUint>,
575        serialization_options: Option<SerializationOptions>,
576        start_nodes: Option<Vec<SharedReference>>,
577    ) -> Self {
578        Self {
579            context,
580            locator,
581            max_node_count,
582            serialization_options,
583            start_nodes,
584        }
585    }
586}
587
588#[derive(Serialize, Deserialize, Debug)]
589pub struct LocateNodesResult {
590    pub nodes: Vec<NodeRemoteValue>,
591}
592
593#[derive(Debug, Serialize, Deserialize)]
594pub struct Navigate {
595    pub method: String, // "browsingContext.navigate"
596    pub params: NavigateParameters,
597}
598
599impl Navigate {
600    pub fn new(params: NavigateParameters) -> Self {
601        Self {
602            method: "browsingContext.navigate".to_string(),
603            params,
604        }
605    }
606}
607
608#[derive(Debug, Serialize, Deserialize)]
609pub struct NavigateParameters {
610    pub context: BrowsingContext,
611    pub url: String,
612    #[serde(skip_serializing_if = "Option::is_none")]
613    pub wait: Option<ReadinessState>,
614}
615
616impl NavigateParameters {
617    pub fn new(context: BrowsingContext, url: String, wait: Option<ReadinessState>) -> Self {
618        Self { context, url, wait }
619    }
620}
621
622#[derive(Serialize, Deserialize, Debug)]
623pub struct NavigateResult {
624    pub navigation: Option<Navigation>,
625    pub url: String,
626}
627
628#[derive(Debug, Serialize, Deserialize)]
629pub struct Print {
630    pub method: String,
631    pub params: PrintParameters,
632}
633
634impl Print {
635    pub fn new(params: PrintParameters) -> Self {
636        Self {
637            method: "browsingContext.print".to_string(),
638            params,
639        }
640    }
641}
642
643#[derive(Debug, Serialize, Deserialize)]
644pub struct PrintParameters {
645    pub context: BrowsingContext,
646    #[serde(skip_serializing_if = "Option::is_none")]
647    pub background: Option<bool>,
648    #[serde(skip_serializing_if = "Option::is_none")]
649    pub margin: Option<PrintMarginParameters>,
650    #[serde(skip_serializing_if = "Option::is_none")]
651    pub orientation: Option<PrintParametersOrientation>,
652    #[serde(skip_serializing_if = "Option::is_none")]
653    pub page: Option<PrintPageParameters>,
654    #[serde(rename = "pageRanges", skip_serializing_if = "Option::is_none")]
655    pub page_ranges: Option<Vec<JsUintOrText>>,
656    #[serde(skip_serializing_if = "Option::is_none")]
657    pub scale: Option<f32>, // 0.1..2.0
658    #[serde(rename = "shrinkToFit", skip_serializing_if = "Option::is_none")]
659    pub shrink_to_fit: Option<bool>,
660}
661
662impl PrintParameters {
663    pub fn new(
664        context: BrowsingContext,
665        background: Option<bool>,
666        margin: Option<PrintMarginParameters>,
667        orientation: Option<PrintParametersOrientation>,
668        page: Option<PrintPageParameters>,
669        page_ranges: Option<Vec<JsUintOrText>>,
670        scale: Option<f32>,
671        shrink_to_fit: Option<bool>,
672    ) -> Self {
673        Self {
674            context,
675            background,
676            margin,
677            orientation,
678            page,
679            page_ranges,
680            scale,
681            shrink_to_fit,
682        }
683    }
684}
685
686#[derive(Debug, Serialize, Deserialize)]
687#[serde(rename_all = "lowercase")]
688pub enum PrintParametersOrientation {
689    Landscape,
690    Portrait,
691}
692
693#[derive(Debug, Serialize, Deserialize)]
694#[serde(untagged)]
695pub enum JsUintOrText {
696    JsUint(JsUint),
697    Text(String),
698}
699
700#[derive(Debug, Serialize, Deserialize)]
701pub struct PrintMarginParameters {
702    #[serde(skip_serializing_if = "Option::is_none")]
703    pub bottom: Option<f32>, // 0.0..
704    #[serde(skip_serializing_if = "Option::is_none")]
705    pub left: Option<f32>, // 0.0..
706    #[serde(skip_serializing_if = "Option::is_none")]
707    pub right: Option<f32>, // 0.0..
708    #[serde(skip_serializing_if = "Option::is_none")]
709    pub top: Option<f32>, // 0.0..
710}
711
712impl PrintMarginParameters {
713    pub fn new(
714        bottom: Option<f32>,
715        left: Option<f32>,
716        right: Option<f32>,
717        top: Option<f32>,
718    ) -> Self {
719        Self {
720            bottom,
721            left,
722            right,
723            top,
724        }
725    }
726}
727
728#[derive(Debug, Serialize, Deserialize)]
729pub struct PrintPageParameters {
730    #[serde(skip_serializing_if = "Option::is_none")]
731    pub height: Option<f32>, // 0.0352..
732    #[serde(skip_serializing_if = "Option::is_none")]
733    pub width: Option<f32>, // 0.0352..
734}
735
736impl PrintPageParameters {
737    pub fn new(height: Option<f32>, width: Option<f32>) -> Self {
738        Self { height, width }
739    }
740}
741
742#[derive(Serialize, Deserialize, Debug)]
743pub struct PrintResult {
744    pub data: String,
745}
746
747#[derive(Debug, Serialize, Deserialize)]
748pub struct Reload {
749    pub method: String,
750    pub params: ReloadParameters,
751}
752
753impl Reload {
754    pub fn new(params: ReloadParameters) -> Self {
755        Self {
756            method: "browsingContext.reload".to_string(),
757            params,
758        }
759    }
760}
761
762#[derive(Debug, Serialize, Deserialize)]
763pub struct ReloadParameters {
764    pub context: BrowsingContext,
765    #[serde(rename = "ignoreCache", skip_serializing_if = "Option::is_none")]
766    pub ignore_cache: Option<bool>,
767    #[serde(skip_serializing_if = "Option::is_none")]
768    pub wait: Option<ReadinessState>,
769}
770
771impl ReloadParameters {
772    pub fn new(
773        context: BrowsingContext,
774        ignore_cache: Option<bool>,
775        wait: Option<ReadinessState>,
776    ) -> Self {
777        Self {
778            context,
779            ignore_cache,
780            wait,
781        }
782    }
783}
784
785#[derive(Debug, Serialize, Deserialize)]
786pub struct SetViewport {
787    pub method: String,
788    pub params: SetViewportParameters,
789}
790
791impl SetViewport {
792    pub fn new(params: SetViewportParameters) -> Self {
793        Self {
794            method: "browsingContext.setViewport".to_string(),
795            params,
796        }
797    }
798}
799
800#[derive(Debug, Serialize, Deserialize)]
801pub struct SetViewportParameters {
802    #[serde(skip_serializing_if = "Option::is_none")]
803    pub context: Option<BrowsingContext>,
804    #[serde(skip_serializing_if = "Option::is_none")]
805    pub viewport: Option<Viewport>,
806    #[serde(rename = "devicePixelRatio", skip_serializing_if = "Option::is_none")]
807    pub device_pixel_ratio: Option<f32>, // 0.0..
808    #[serde(rename = "userContexts", skip_serializing_if = "Option::is_none")]
809    pub user_contexts: Option<Vec<UserContext>>,
810}
811
812impl SetViewportParameters {
813    pub fn new(
814        context: Option<BrowsingContext>,
815        viewport: Option<Viewport>,
816        device_pixel_ratio: Option<f32>,
817        user_contexts: Option<Vec<UserContext>>,
818    ) -> Self {
819        Self {
820            context,
821            viewport,
822            device_pixel_ratio,
823            user_contexts,
824        }
825    }
826}
827
828#[derive(Debug, Serialize, Deserialize)]
829pub struct Viewport {
830    pub width: JsUint,
831    pub height: JsUint,
832}
833
834impl Viewport {
835    pub fn new(width: JsUint, height: JsUint) -> Self {
836        Self { width, height }
837    }
838}
839
840#[derive(Debug, Serialize, Deserialize)]
841pub struct TraverseHistory {
842    pub method: String,
843    pub params: TraverseHistoryParameters,
844}
845
846impl TraverseHistory {
847    pub fn new(params: TraverseHistoryParameters) -> Self {
848        Self {
849            method: "browsingContext.traverseHistory".into(),
850            params,
851        }
852    }
853}
854
855#[derive(Debug, Serialize, Deserialize)]
856pub struct TraverseHistoryParameters {
857    pub context: BrowsingContext,
858    pub delta: JsInt,
859}
860
861impl TraverseHistoryParameters {
862    pub fn new(context: String, delta: i64) -> Self {
863        Self { context, delta }
864    }
865}
866
867#[derive(Serialize, Deserialize, Debug)]
868pub struct TraverseHistoryResult {}
869
870#[derive(Serialize, Deserialize, Debug)]
871pub struct ContextCreated {
872    pub method: String,
873    pub params: Info,
874}
875
876#[derive(Serialize, Deserialize, Debug)]
877pub struct ContextDestroyed {
878    pub method: String,
879    pub params: Info,
880}
881
882#[derive(Serialize, Deserialize, Debug)]
883pub struct NavigationStarted {
884    pub method: String,
885    pub params: NavigationInfo,
886}
887
888#[derive(Serialize, Deserialize, Debug)]
889pub struct FragmentNavigated {
890    pub method: String,
891    pub params: NavigationInfo,
892}
893
894#[derive(Serialize, Deserialize, Debug)]
895pub struct HistoryUpdated {
896    pub method: String,
897    pub params: HistoryUpdatedParameters,
898}
899
900#[derive(Serialize, Deserialize, Debug)]
901pub struct HistoryUpdatedParameters {
902    pub context: BrowsingContext,
903    pub timestamp: JsUint,
904    pub url: String,
905}
906
907#[derive(Serialize, Deserialize, Debug)]
908pub struct DomContentLoaded {
909    pub method: String,
910    pub params: NavigationInfo,
911}
912
913#[derive(Serialize, Deserialize, Debug)]
914pub struct Load {
915    pub method: String,
916    pub params: NavigationInfo,
917}
918
919#[derive(Serialize, Deserialize, Debug)]
920pub struct DownloadWillBegin {
921    pub method: String,
922    pub params: DownloadWillBeginParams,
923}
924
925#[derive(Serialize, Deserialize, Debug)]
926pub struct DownloadWillBeginParams {
927    #[serde(rename = "suggestedFilename")]
928    pub suggested_filename: String,
929    #[serde(flatten)]
930    pub base: BaseNavigationInfo,
931}
932
933#[derive(Serialize, Deserialize, Debug)]
934pub struct DownloadEnd {
935    pub method: String,
936    pub params: DownloadEndParams,
937}
938
939#[derive(Serialize, Deserialize, Debug)]
940#[serde(untagged)]
941pub enum DownloadEndParams {
942    DownloadCanceled(DownloadCanceledParams),
943    DownloadComplete(DownloadCompleteParams),
944}
945
946#[derive(Serialize, Deserialize, Debug)]
947pub struct DownloadCanceledParams {
948    pub status: String,
949    #[serde(flatten)]
950    pub base: BaseNavigationInfo,
951}
952
953#[derive(Serialize, Deserialize, Debug)]
954pub struct DownloadCompleteParams {
955    pub status: String,
956    pub filepath: Option<String>,
957    #[serde(flatten)]
958    pub base: BaseNavigationInfo,
959}
960
961#[derive(Serialize, Deserialize, Debug)]
962pub struct NavigationAborted {
963    pub method: String,
964    pub params: NavigationInfo,
965}
966
967#[derive(Serialize, Deserialize, Debug)]
968pub struct NavigationCommitted {
969    pub method: String,
970    pub params: NavigationInfo,
971}
972
973#[derive(Serialize, Deserialize, Debug)]
974pub struct NavigationFailed {
975    pub method: String,
976    pub params: NavigationInfo,
977}
978
979#[derive(Serialize, Deserialize, Debug)]
980pub struct UserPromptClosed {
981    pub method: String,
982    pub params: UserPromptClosedParameters,
983}
984
985#[derive(Serialize, Deserialize, Debug)]
986pub struct UserPromptClosedParameters {
987    pub context: BrowsingContext,
988    pub accepted: bool,
989    #[serde(rename = "type")]
990    pub prompt_type: UserPromptType,
991    #[serde(rename = "userText", skip_serializing_if = "Option::is_none")]
992    pub user_text: Option<String>,
993}
994
995#[derive(Serialize, Deserialize, Debug)]
996pub struct UserPromptOpened {
997    pub method: String,
998    pub params: UserPromptOpenedParameters,
999}
1000
1001#[derive(Serialize, Deserialize, Debug)]
1002pub struct UserPromptOpenedParameters {
1003    pub context: BrowsingContext,
1004    pub handler: UserPromptHandlerType,
1005    pub message: String,
1006    #[serde(rename = "type")]
1007    pub prompt_type: UserPromptType,
1008    #[serde(rename = "defaultValue", skip_serializing_if = "Option::is_none")]
1009    pub default_value: Option<String>,
1010}