Skip to main content

browser_protocol/fedcm/
mod.rs

1//! This domain allows interacting with the FedCM dialog.
2use serde::{Serialize, Deserialize};
3use serde_json::Value as JsonValue;
4
5/// Whether this is a sign-up or sign-in action for this account, i.e.
6/// whether this account has ever been used to sign in to this RP before.
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
9pub enum LoginState {
10    #[default]
11    SignIn,
12    SignUp,
13}
14
15/// The types of FedCM dialogs.
16
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
18pub enum DialogType {
19    #[default]
20    AccountChooser,
21    AutoReauthn,
22    ConfirmIdpLogin,
23    Error,
24}
25
26/// The buttons on the FedCM dialog.
27
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
29pub enum DialogButton {
30    #[default]
31    ConfirmIdpLoginContinue,
32    ErrorGotIt,
33    ErrorMoreDetails,
34}
35
36/// The URLs that each account has
37
38#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
39pub enum AccountUrlType {
40    #[default]
41    TermsOfService,
42    PrivacyPolicy,
43}
44
45/// Corresponds to IdentityRequestAccount
46
47#[derive(Debug, Clone, Serialize, Deserialize, Default)]
48#[serde(rename_all = "camelCase")]
49pub struct Account {
50
51    pub accountId: String,
52
53    pub email: String,
54
55    pub name: String,
56
57    pub givenName: String,
58
59    pub pictureUrl: String,
60
61    pub idpConfigUrl: String,
62
63    pub idpLoginUrl: String,
64
65    pub loginState: LoginState,
66    /// These two are only set if the loginState is signUp
67
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub termsOfServiceUrl: Option<String>,
70
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub privacyPolicyUrl: Option<String>,
73}
74
75
76#[derive(Debug, Clone, Serialize, Deserialize, Default)]
77#[serde(rename_all = "camelCase")]
78pub struct EnableParams {
79    /// Allows callers to disable the promise rejection delay that would
80    /// normally happen, if this is unimportant to what's being tested.
81    /// (step 4 of https://fedidcg.github.io/FedCM/#browser-api-rp-sign-in)
82
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub disableRejectionDelay: Option<bool>,
85}
86
87impl EnableParams { pub const METHOD: &'static str = "FedCm.enable"; }
88
89impl crate::CdpCommand for EnableParams {
90    const METHOD: &'static str = "FedCm.enable";
91    type Response = crate::EmptyReturns;
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize, Default)]
95pub struct DisableParams {}
96
97impl DisableParams { pub const METHOD: &'static str = "FedCm.disable"; }
98
99impl crate::CdpCommand for DisableParams {
100    const METHOD: &'static str = "FedCm.disable";
101    type Response = crate::EmptyReturns;
102}
103
104
105#[derive(Debug, Clone, Serialize, Deserialize, Default)]
106#[serde(rename_all = "camelCase")]
107pub struct SelectAccountParams {
108
109    pub dialogId: String,
110
111    pub accountIndex: u64,
112}
113
114impl SelectAccountParams { pub const METHOD: &'static str = "FedCm.selectAccount"; }
115
116impl crate::CdpCommand for SelectAccountParams {
117    const METHOD: &'static str = "FedCm.selectAccount";
118    type Response = crate::EmptyReturns;
119}
120
121
122#[derive(Debug, Clone, Serialize, Deserialize, Default)]
123#[serde(rename_all = "camelCase")]
124pub struct ClickDialogButtonParams {
125
126    pub dialogId: String,
127
128    pub dialogButton: DialogButton,
129}
130
131impl ClickDialogButtonParams { pub const METHOD: &'static str = "FedCm.clickDialogButton"; }
132
133impl crate::CdpCommand for ClickDialogButtonParams {
134    const METHOD: &'static str = "FedCm.clickDialogButton";
135    type Response = crate::EmptyReturns;
136}
137
138
139#[derive(Debug, Clone, Serialize, Deserialize, Default)]
140#[serde(rename_all = "camelCase")]
141pub struct OpenUrlParams {
142
143    pub dialogId: String,
144
145    pub accountIndex: u64,
146
147    pub accountUrlType: AccountUrlType,
148}
149
150impl OpenUrlParams { pub const METHOD: &'static str = "FedCm.openUrl"; }
151
152impl crate::CdpCommand for OpenUrlParams {
153    const METHOD: &'static str = "FedCm.openUrl";
154    type Response = crate::EmptyReturns;
155}
156
157
158#[derive(Debug, Clone, Serialize, Deserialize, Default)]
159#[serde(rename_all = "camelCase")]
160pub struct DismissDialogParams {
161
162    pub dialogId: String,
163
164    #[serde(skip_serializing_if = "Option::is_none")]
165    pub triggerCooldown: Option<bool>,
166}
167
168impl DismissDialogParams { pub const METHOD: &'static str = "FedCm.dismissDialog"; }
169
170impl crate::CdpCommand for DismissDialogParams {
171    const METHOD: &'static str = "FedCm.dismissDialog";
172    type Response = crate::EmptyReturns;
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize, Default)]
176pub struct ResetCooldownParams {}
177
178impl ResetCooldownParams { pub const METHOD: &'static str = "FedCm.resetCooldown"; }
179
180impl crate::CdpCommand for ResetCooldownParams {
181    const METHOD: &'static str = "FedCm.resetCooldown";
182    type Response = crate::EmptyReturns;
183}