Skip to main content

browser_commander/playwright/protocol/
binding_call.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `BindingCall`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct BindingCallInitializer {
16    #[serde(rename = "frame")]
17    pub frame: Ref<Frame>,
18    #[serde(rename = "name")]
19    pub name: String,
20    #[serde(rename = "args")]
21    pub args: Vec<SerializedValue>,
22}
23
24/// Parameters of `BindingCall.reject`.
25#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26pub struct BindingCallRejectParams {
27    #[serde(rename = "error")]
28    pub error: SerializedError,
29}
30
31/// Parameters of `BindingCall.resolve`.
32#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
33pub struct BindingCallResolveParams {
34    #[serde(rename = "result")]
35    pub result: SerializedArgument,
36}
37
38/// Events a `BindingCall` channel can emit.
39#[derive(Debug, Clone, PartialEq)]
40pub enum BindingCallEvent {
41    /// An event this binding does not know (a newer driver).
42    Unknown {
43        /// Event name.
44        method: String,
45        /// Raw event parameters.
46        params: serde_json::Value,
47    },
48}
49
50impl ProtocolEvent for BindingCallEvent {
51    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
52        match method {
53            _ => Ok(Self::Unknown { method: method.to_string(), params }),
54        }
55    }
56}
57
58/// Channel for the `BindingCall` interface (`playwright.yml`).
59#[derive(Debug, Clone)]
60pub struct BindingCall {
61    channel: Channel,
62}
63
64impl ChannelType for BindingCall {
65    const INTERFACE: &'static str = "BindingCall";
66    type Initializer = BindingCallInitializer;
67    type Event = BindingCallEvent;
68
69    fn accepts(interface: &str) -> bool {
70        matches!(interface, "BindingCall")
71    }
72
73    fn from_channel(channel: Channel) -> Self {
74        Self { channel }
75    }
76
77    fn channel(&self) -> &Channel {
78        &self.channel
79    }
80}
81
82impl BindingCall {
83    /// `BindingCall.reject` (internal).
84    pub async fn reject(&self, params: BindingCallRejectParams) -> Result<(), ProtocolError> {
85        self.channel.send_no_result("reject", &params).await
86    }
87
88    /// `BindingCall.resolve` (internal).
89    pub async fn resolve(&self, params: BindingCallResolveParams) -> Result<(), ProtocolError> {
90        self.channel.send_no_result("resolve", &params).await
91    }
92}