Skip to main content

cdp_driver/protocol/
extensions.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 browser extensions.
5//!
6//! Types, command parameters and event payloads for the `Extensions`
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/// Storage areas.
15#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
16pub enum StorageArea {
17    /// `session`
18    #[serde(rename = "session")]
19    Session,
20    /// `local`
21    #[serde(rename = "local")]
22    Local,
23    /// `sync`
24    #[serde(rename = "sync")]
25    Sync,
26    /// `managed`
27    #[serde(rename = "managed")]
28    Managed,
29    /// A value this vendored schema does not list. Chrome adds values ahead of
30    /// the published protocol, so an unrecognised one is kept as it arrived
31    /// rather than failing the payload it came in.
32    #[serde(untagged)]
33    Unrecognized(String),
34}
35
36/// Detailed information about an extension.
37#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
38pub struct ExtensionInfo {
39    /// Extension id.
40    pub id: String,
41    /// Extension name.
42    pub name: String,
43    /// Extension version.
44    pub version: String,
45    /// The path from which the extension was loaded.
46    pub path: String,
47    /// Extension enabled status.
48    pub enabled: bool,
49}
50
51/// Runs an extension default action.
52///
53/// Parameters of `Extensions.triggerAction`.
54#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
55pub struct TriggerActionParams {
56    /// Extension id.
57    pub id: String,
58    /// A tab target ID to trigger the default extension action on.
59    #[serde(rename = "targetId")]
60    pub target_id: String,
61}
62
63impl crate::typed::Command for TriggerActionParams {
64    const METHOD: &'static str = "Extensions.triggerAction";
65    type Returns = crate::typed::NoReturns;
66}
67
68/// Installs an unpacked extension from the filesystem similar to
69/// --load-extension CLI flags. Returns extension ID once the extension has
70/// been installed.
71///
72/// Parameters of `Extensions.loadUnpacked`.
73#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
74pub struct LoadUnpackedParams {
75    /// Absolute file path.
76    pub path: String,
77    /// Enable the extension in incognito
78    #[serde(
79        rename = "enableInIncognito",
80        default,
81        skip_serializing_if = "Option::is_none"
82    )]
83    pub enable_in_incognito: Option<bool>,
84}
85
86/// What `Extensions.loadUnpacked` answers with.
87#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
88pub struct LoadUnpackedReturns {
89    /// Extension id.
90    pub id: String,
91}
92
93impl crate::typed::Command for LoadUnpackedParams {
94    const METHOD: &'static str = "Extensions.loadUnpacked";
95    type Returns = LoadUnpackedReturns;
96}
97
98/// Gets a list of all unpacked extensions.
99///
100/// Parameters of `Extensions.getExtensions`.
101#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
102pub struct GetExtensionsParams {}
103
104/// What `Extensions.getExtensions` answers with.
105#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
106pub struct GetExtensionsReturns {
107    pub extensions: Vec<ExtensionInfo>,
108}
109
110impl crate::typed::Command for GetExtensionsParams {
111    const METHOD: &'static str = "Extensions.getExtensions";
112    type Returns = GetExtensionsReturns;
113}
114
115/// Uninstalls an unpacked extension (others not supported) from the profile.
116///
117/// Parameters of `Extensions.uninstall`.
118#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
119pub struct UninstallParams {
120    /// Extension id.
121    pub id: String,
122}
123
124impl crate::typed::Command for UninstallParams {
125    const METHOD: &'static str = "Extensions.uninstall";
126    type Returns = crate::typed::NoReturns;
127}
128
129/// Gets data from extension storage in the given `storageArea`. If `keys` is
130/// specified, these are used to filter the result.
131///
132/// Parameters of `Extensions.getStorageItems`.
133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
134pub struct GetStorageItemsParams {
135    /// ID of extension.
136    pub id: String,
137    /// StorageArea to retrieve data from.
138    #[serde(rename = "storageArea")]
139    pub storage_area: StorageArea,
140    /// Keys to retrieve.
141    #[serde(default, skip_serializing_if = "Option::is_none")]
142    pub keys: Option<Vec<String>>,
143}
144
145/// What `Extensions.getStorageItems` answers with.
146#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
147pub struct GetStorageItemsReturns {
148    pub data: serde_json::Value,
149}
150
151impl crate::typed::Command for GetStorageItemsParams {
152    const METHOD: &'static str = "Extensions.getStorageItems";
153    type Returns = GetStorageItemsReturns;
154}
155
156/// Removes `keys` from extension storage in the given `storageArea`.
157///
158/// Parameters of `Extensions.removeStorageItems`.
159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
160pub struct RemoveStorageItemsParams {
161    /// ID of extension.
162    pub id: String,
163    /// StorageArea to remove data from.
164    #[serde(rename = "storageArea")]
165    pub storage_area: StorageArea,
166    /// Keys to remove.
167    pub keys: Vec<String>,
168}
169
170impl crate::typed::Command for RemoveStorageItemsParams {
171    const METHOD: &'static str = "Extensions.removeStorageItems";
172    type Returns = crate::typed::NoReturns;
173}
174
175/// Clears extension storage in the given `storageArea`.
176///
177/// Parameters of `Extensions.clearStorageItems`.
178#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
179pub struct ClearStorageItemsParams {
180    /// ID of extension.
181    pub id: String,
182    /// StorageArea to remove data from.
183    #[serde(rename = "storageArea")]
184    pub storage_area: StorageArea,
185}
186
187impl crate::typed::Command for ClearStorageItemsParams {
188    const METHOD: &'static str = "Extensions.clearStorageItems";
189    type Returns = crate::typed::NoReturns;
190}
191
192/// Sets `values` in extension storage in the given `storageArea`. The
193/// provided `values` will be merged with existing values in the storage area.
194///
195/// Parameters of `Extensions.setStorageItems`.
196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
197pub struct SetStorageItemsParams {
198    /// ID of extension.
199    pub id: String,
200    /// StorageArea to set data in.
201    #[serde(rename = "storageArea")]
202    pub storage_area: StorageArea,
203    /// Values to set.
204    pub values: serde_json::Value,
205}
206
207impl crate::typed::Command for SetStorageItemsParams {
208    const METHOD: &'static str = "Extensions.setStorageItems";
209    type Returns = crate::typed::NoReturns;
210}