browser_commander/playwright/protocol/
binding_call.rs1#![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#[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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26pub struct BindingCallRejectParams {
27 #[serde(rename = "error")]
28 pub error: SerializedError,
29}
30
31#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
33pub struct BindingCallResolveParams {
34 #[serde(rename = "result")]
35 pub result: SerializedArgument,
36}
37
38#[derive(Debug, Clone, PartialEq)]
40pub enum BindingCallEvent {
41 Unknown {
43 method: String,
45 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#[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 pub async fn reject(&self, params: BindingCallRejectParams) -> Result<(), ProtocolError> {
85 self.channel.send_no_result("reject", ¶ms).await
86 }
87
88 pub async fn resolve(&self, params: BindingCallResolveParams) -> Result<(), ProtocolError> {
90 self.channel.send_no_result("resolve", ¶ms).await
91 }
92}