Skip to main content

cdp_driver/protocol/
autofill.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! Defines commands and events for Autofill.
5//!
6//! Types, command parameters and event payloads for the `Autofill`
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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct CreditCard {
16    /// 16-digit credit card number.
17    pub number: String,
18    /// Name of the credit card owner.
19    pub name: String,
20    /// 2-digit expiry month.
21    #[serde(rename = "expiryMonth")]
22    pub expiry_month: String,
23    /// 4-digit expiry year.
24    #[serde(rename = "expiryYear")]
25    pub expiry_year: String,
26    /// 3-digit card verification code.
27    pub cvc: String,
28}
29
30#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
31pub struct AddressField {
32    /// address field name, for example GIVEN_NAME. The full list of supported
33    /// field names:
34    /// <https://source.chromium.org/chromium/chromium/src/+/main:components/autofill/core/browser/field_types.cc;l=38>
35    pub name: String,
36    /// address field value, for example Jon Doe.
37    pub value: String,
38}
39
40/// A list of address fields.
41#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
42pub struct AddressFields {
43    pub fields: Vec<AddressField>,
44}
45
46#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
47pub struct Address {
48    /// fields and values defining an address.
49    pub fields: Vec<AddressField>,
50}
51
52/// Defines how an address can be displayed like in
53/// chrome://settings/addresses. Address UI is a two dimensional array, each
54/// inner array is an "address information line", and when rendered in a UI
55/// surface should be displayed as such. The following address UI for
56/// instance: \[\[{name: "GIVE_NAME", value: "Jon"}, {name: "FAMILY_NAME",
57/// value: "Doe"}\], \[{name: "CITY", value: "Munich"}, {name: "ZIP", value:
58/// "81456"}\]\] should allow the receiver to render: Jon Doe Munich 81456
59#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
60pub struct AddressUi {
61    /// A two dimension array containing the representation of values from an
62    /// address profile.
63    #[serde(rename = "addressFields")]
64    pub address_fields: Vec<AddressFields>,
65}
66
67/// Specified whether a filled field was done so by using the html
68/// autocomplete attribute or autofill heuristics.
69#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
70pub enum FillingStrategy {
71    /// `autocompleteAttribute`
72    #[serde(rename = "autocompleteAttribute")]
73    AutocompleteAttribute,
74    /// `autofillInferred`
75    #[serde(rename = "autofillInferred")]
76    AutofillInferred,
77    /// A value this vendored schema does not list. Chrome adds values ahead of
78    /// the published protocol, so an unrecognised one is kept as it arrived
79    /// rather than failing the payload it came in.
80    #[serde(untagged)]
81    Unrecognized(String),
82}
83
84#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
85pub struct FilledField {
86    /// The type of the field, e.g text, password etc.
87    #[serde(rename = "htmlType")]
88    pub html_type: String,
89    /// the html id
90    pub id: String,
91    /// the html name
92    pub name: String,
93    /// the field value
94    pub value: String,
95    /// The actual field type, e.g FAMILY_NAME
96    #[serde(rename = "autofillType")]
97    pub autofill_type: String,
98    /// The filling strategy
99    #[serde(rename = "fillingStrategy")]
100    pub filling_strategy: FillingStrategy,
101    /// The frame the field belongs to
102    #[serde(rename = "frameId")]
103    pub frame_id: crate::protocol::page::FrameId,
104    /// The form field's DOM node
105    #[serde(rename = "fieldId")]
106    pub field_id: crate::protocol::dom::BackendNodeId,
107}
108
109/// Trigger autofill on a form identified by the fieldId. If the field and
110/// related form cannot be autofilled, returns an error. Returns once the
111/// values have been applied to the form fields.
112///
113/// Parameters of `Autofill.trigger`.
114#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
115pub struct TriggerParams {
116    /// Identifies a field that serves as an anchor for autofill.
117    #[serde(rename = "fieldId")]
118    pub field_id: crate::protocol::dom::BackendNodeId,
119    /// Identifies the frame that field belongs to.
120    #[serde(rename = "frameId", default, skip_serializing_if = "Option::is_none")]
121    pub frame_id: Option<crate::protocol::page::FrameId>,
122    /// Credit card information to fill out the form. Credit card data is not
123    /// saved. Mutually exclusive with `address`.
124    #[serde(default, skip_serializing_if = "Option::is_none")]
125    pub card: Option<CreditCard>,
126    /// Address to fill out the form. Address data is not saved. Mutually
127    /// exclusive with `card`.
128    #[serde(default, skip_serializing_if = "Option::is_none")]
129    pub address: Option<Address>,
130}
131
132impl crate::typed::Command for TriggerParams {
133    const METHOD: &'static str = "Autofill.trigger";
134    type Returns = crate::typed::NoReturns;
135}
136
137/// Set addresses so that developers can verify their forms implementation.
138///
139/// Parameters of `Autofill.setAddresses`.
140#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
141pub struct SetAddressesParams {
142    pub addresses: Vec<Address>,
143}
144
145impl crate::typed::Command for SetAddressesParams {
146    const METHOD: &'static str = "Autofill.setAddresses";
147    type Returns = crate::typed::NoReturns;
148}
149
150/// Disables autofill domain notifications.
151///
152/// Parameters of `Autofill.disable`.
153#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
154pub struct DisableParams {}
155
156impl crate::typed::Command for DisableParams {
157    const METHOD: &'static str = "Autofill.disable";
158    type Returns = crate::typed::NoReturns;
159}
160
161/// Enables autofill domain notifications.
162///
163/// Parameters of `Autofill.enable`.
164#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
165pub struct EnableParams {}
166
167impl crate::typed::Command for EnableParams {
168    const METHOD: &'static str = "Autofill.enable";
169    type Returns = crate::typed::NoReturns;
170}
171
172/// Emitted when an address form is filled.
173///
174/// Payload of the `Autofill.addressFormFilled` event.
175#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
176pub struct AddressFormFilledEvent {
177    /// Information about the fields that were filled
178    #[serde(rename = "filledFields")]
179    pub filled_fields: Vec<FilledField>,
180    /// An UI representation of the address used to fill the form. Consists of a
181    /// 2D array where each child represents an address/profile line.
182    #[serde(rename = "addressUi")]
183    pub address_ui: AddressUi,
184}
185
186impl crate::typed::Event for AddressFormFilledEvent {
187    const METHOD: &'static str = "Autofill.addressFormFilled";
188}