Skip to main content

cdp_driver/protocol/
fed_cm.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! This domain allows interacting with the FedCM dialog.
5//!
6//! Types, command parameters and event payloads for the `FedCm`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9//!
10//! This domain is experimental and may change without notice.
11
12use serde::{Deserialize, Serialize};
13
14/// Whether this is a sign-up or sign-in action for this account, i.e. whether
15/// this account has ever been used to sign in to this RP before.
16#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
17pub enum LoginState {
18    /// `SignIn`
19    SignIn,
20    /// `SignUp`
21    SignUp,
22    /// A value this vendored schema does not list. Chrome adds values ahead of
23    /// the published protocol, so an unrecognised one is kept as it arrived
24    /// rather than failing the payload it came in.
25    #[serde(untagged)]
26    Unrecognized(String),
27}
28
29/// The types of FedCM dialogs.
30#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
31pub enum DialogType {
32    /// `AccountChooser`
33    AccountChooser,
34    /// `AutoReauthn`
35    AutoReauthn,
36    /// `ConfirmIdpLogin`
37    ConfirmIdpLogin,
38    /// `Error`
39    Error,
40    /// A value this vendored schema does not list. Chrome adds values ahead of
41    /// the published protocol, so an unrecognised one is kept as it arrived
42    /// rather than failing the payload it came in.
43    #[serde(untagged)]
44    Unrecognized(String),
45}
46
47/// The buttons on the FedCM dialog.
48#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
49pub enum DialogButton {
50    /// `ConfirmIdpLoginContinue`
51    ConfirmIdpLoginContinue,
52    /// `ErrorGotIt`
53    ErrorGotIt,
54    /// `ErrorMoreDetails`
55    ErrorMoreDetails,
56    /// A value this vendored schema does not list. Chrome adds values ahead of
57    /// the published protocol, so an unrecognised one is kept as it arrived
58    /// rather than failing the payload it came in.
59    #[serde(untagged)]
60    Unrecognized(String),
61}
62
63/// The URLs that each account has
64#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
65pub enum AccountUrlType {
66    /// `TermsOfService`
67    TermsOfService,
68    /// `PrivacyPolicy`
69    PrivacyPolicy,
70    /// A value this vendored schema does not list. Chrome adds values ahead of
71    /// the published protocol, so an unrecognised one is kept as it arrived
72    /// rather than failing the payload it came in.
73    #[serde(untagged)]
74    Unrecognized(String),
75}
76
77/// Corresponds to IdentityRequestAccount
78#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
79pub struct Account {
80    #[serde(rename = "accountId")]
81    pub account_id: String,
82    pub email: String,
83    pub name: String,
84    #[serde(rename = "givenName")]
85    pub given_name: String,
86    #[serde(rename = "pictureUrl")]
87    pub picture_url: String,
88    #[serde(rename = "idpConfigUrl")]
89    pub idp_config_url: String,
90    #[serde(rename = "idpLoginUrl")]
91    pub idp_login_url: String,
92    #[serde(rename = "loginState")]
93    pub login_state: LoginState,
94    /// These two are only set if the loginState is signUp
95    #[serde(
96        rename = "termsOfServiceUrl",
97        default,
98        skip_serializing_if = "Option::is_none"
99    )]
100    pub terms_of_service_url: Option<String>,
101    #[serde(
102        rename = "privacyPolicyUrl",
103        default,
104        skip_serializing_if = "Option::is_none"
105    )]
106    pub privacy_policy_url: Option<String>,
107}
108
109/// Parameters of `FedCm.enable`.
110#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
111pub struct EnableParams {
112    /// Allows callers to disable the promise rejection delay that would normally
113    /// happen, if this is unimportant to what's being tested. (step 4 of
114    /// <https://fedidcg.github.io/FedCM/#browser-api-rp-sign-in>)
115    #[serde(
116        rename = "disableRejectionDelay",
117        default,
118        skip_serializing_if = "Option::is_none"
119    )]
120    pub disable_rejection_delay: Option<bool>,
121}
122
123impl crate::typed::Command for EnableParams {
124    const METHOD: &'static str = "FedCm.enable";
125    type Returns = crate::typed::NoReturns;
126}
127
128/// Parameters of `FedCm.disable`.
129#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
130pub struct DisableParams {}
131
132impl crate::typed::Command for DisableParams {
133    const METHOD: &'static str = "FedCm.disable";
134    type Returns = crate::typed::NoReturns;
135}
136
137/// Parameters of `FedCm.selectAccount`.
138#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
139pub struct SelectAccountParams {
140    #[serde(rename = "dialogId")]
141    pub dialog_id: String,
142    #[serde(rename = "accountIndex")]
143    pub account_index: i64,
144}
145
146impl crate::typed::Command for SelectAccountParams {
147    const METHOD: &'static str = "FedCm.selectAccount";
148    type Returns = crate::typed::NoReturns;
149}
150
151/// Parameters of `FedCm.clickDialogButton`.
152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
153pub struct ClickDialogButtonParams {
154    #[serde(rename = "dialogId")]
155    pub dialog_id: String,
156    #[serde(rename = "dialogButton")]
157    pub dialog_button: DialogButton,
158}
159
160impl crate::typed::Command for ClickDialogButtonParams {
161    const METHOD: &'static str = "FedCm.clickDialogButton";
162    type Returns = crate::typed::NoReturns;
163}
164
165/// Parameters of `FedCm.openUrl`.
166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
167pub struct OpenUrlParams {
168    #[serde(rename = "dialogId")]
169    pub dialog_id: String,
170    #[serde(rename = "accountIndex")]
171    pub account_index: i64,
172    #[serde(rename = "accountUrlType")]
173    pub account_url_type: AccountUrlType,
174}
175
176impl crate::typed::Command for OpenUrlParams {
177    const METHOD: &'static str = "FedCm.openUrl";
178    type Returns = crate::typed::NoReturns;
179}
180
181/// Parameters of `FedCm.dismissDialog`.
182#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
183pub struct DismissDialogParams {
184    #[serde(rename = "dialogId")]
185    pub dialog_id: String,
186    #[serde(
187        rename = "triggerCooldown",
188        default,
189        skip_serializing_if = "Option::is_none"
190    )]
191    pub trigger_cooldown: Option<bool>,
192}
193
194impl crate::typed::Command for DismissDialogParams {
195    const METHOD: &'static str = "FedCm.dismissDialog";
196    type Returns = crate::typed::NoReturns;
197}
198
199/// Resets the cooldown time, if any, to allow the next FedCM call to show a
200/// dialog even if one was recently dismissed by the user.
201///
202/// Parameters of `FedCm.resetCooldown`.
203#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
204pub struct ResetCooldownParams {}
205
206impl crate::typed::Command for ResetCooldownParams {
207    const METHOD: &'static str = "FedCm.resetCooldown";
208    type Returns = crate::typed::NoReturns;
209}
210
211/// Payload of the `FedCm.dialogShown` event.
212#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
213pub struct DialogShownEvent {
214    #[serde(rename = "dialogId")]
215    pub dialog_id: String,
216    #[serde(rename = "dialogType")]
217    pub dialog_type: DialogType,
218    pub accounts: Vec<Account>,
219    /// These exist primarily so that the caller can verify the RP context was
220    /// used appropriately.
221    pub title: String,
222    #[serde(default, skip_serializing_if = "Option::is_none")]
223    pub subtitle: Option<String>,
224}
225
226impl crate::typed::Event for DialogShownEvent {
227    const METHOD: &'static str = "FedCm.dialogShown";
228}
229
230/// Triggered when a dialog is closed, either by user action, JS abort, or a
231/// command below.
232///
233/// Payload of the `FedCm.dialogClosed` event.
234#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
235pub struct DialogClosedEvent {
236    #[serde(rename = "dialogId")]
237    pub dialog_id: String,
238}
239
240impl crate::typed::Event for DialogClosedEvent {
241    const METHOD: &'static str = "FedCm.dialogClosed";
242}