Skip to main content

cdp_driver/protocol/
pwa.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 browser to control PWAs.
5//!
6//! Types, command parameters and event payloads for the `PWA`
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/// The following types are the replica of
15/// <https://crsrc.org/c/chrome/browser/web_applications/proto/web_app_os_integration_state.proto;drc=9910d3be894c8f142c977ba1023f30a656bc13fc;l=67>
16#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
17pub struct FileHandlerAccept {
18    /// New name of the mimetype according to
19    /// <https://www.iana.org/assignments/media-types/media-types.xhtml>
20    #[serde(rename = "mediaType")]
21    pub media_type: String,
22    #[serde(rename = "fileExtensions")]
23    pub file_extensions: Vec<String>,
24}
25
26#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
27pub struct FileHandler {
28    pub action: String,
29    pub accepts: Vec<FileHandlerAccept>,
30    #[serde(rename = "displayName")]
31    pub display_name: String,
32}
33
34/// If user prefers opening the app in browser or an app window.
35#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
36pub enum DisplayMode {
37    /// `standalone`
38    #[serde(rename = "standalone")]
39    Standalone,
40    /// `browser`
41    #[serde(rename = "browser")]
42    Browser,
43    /// A value this vendored schema does not list. Chrome adds values ahead of
44    /// the published protocol, so an unrecognised one is kept as it arrived
45    /// rather than failing the payload it came in.
46    #[serde(untagged)]
47    Unrecognized(String),
48}
49
50/// Returns the following OS state for the given manifest id.
51///
52/// Parameters of `PWA.getOsAppState`.
53#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
54pub struct GetOsAppStateParams {
55    /// The id from the webapp's manifest file, commonly it's the url of the site
56    /// installing the webapp. See <https://web.dev/learn/pwa/web-app-manifest>.
57    #[serde(rename = "manifestId")]
58    pub manifest_id: String,
59}
60
61/// What `PWA.getOsAppState` answers with.
62#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
63pub struct GetOsAppStateReturns {
64    #[serde(rename = "badgeCount")]
65    pub badge_count: i64,
66    #[serde(rename = "fileHandlers")]
67    pub file_handlers: Vec<FileHandler>,
68}
69
70impl crate::typed::Command for GetOsAppStateParams {
71    const METHOD: &'static str = "PWA.getOsAppState";
72    type Returns = GetOsAppStateReturns;
73}
74
75/// Installs the given manifest identity, optionally using the given
76/// installUrlOrBundleUrl IWA-specific install description: manifestId
77/// corresponds to isolated-app:// + web_package::SignedWebBundleId File
78/// installation mode: The installUrlOrBundleUrl can be either file:// or
79/// http(s):// pointing to a signed web bundle (.swbn). In this case
80/// SignedWebBundleId must correspond to The .swbn file's signing key. Dev
81/// proxy installation mode: installUrlOrBundleUrl must be http(s):// that
82/// serves dev mode IWA. web_package::SignedWebBundleId must be of type dev
83/// proxy. The advantage of dev proxy mode is that all changes to IWA
84/// automatically will be reflected in the running app without reinstallation.
85/// To generate bundle id for proxy mode: 1. Generate 32 random bytes. 2. Add
86/// a specific suffix at the end following the documentation
87/// <https://github.com/WICG/isolated-web-apps/blob/main/Scheme.md#suffix> 3.
88/// Encode the entire sequence using Base32 without padding. If Chrome is not
89/// in IWA dev mode, the installation will fail, regardless of the state of
90/// the allowlist.
91///
92/// Parameters of `PWA.install`.
93#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
94pub struct InstallParams {
95    #[serde(rename = "manifestId")]
96    pub manifest_id: String,
97    /// The location of the app or bundle overriding the one derived from the
98    /// manifestId.
99    #[serde(
100        rename = "installUrlOrBundleUrl",
101        default,
102        skip_serializing_if = "Option::is_none"
103    )]
104    pub install_url_or_bundle_url: Option<String>,
105}
106
107impl crate::typed::Command for InstallParams {
108    const METHOD: &'static str = "PWA.install";
109    type Returns = crate::typed::NoReturns;
110}
111
112/// Uninstalls the given manifest_id and closes any opened app windows.
113///
114/// Parameters of `PWA.uninstall`.
115#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
116pub struct UninstallParams {
117    #[serde(rename = "manifestId")]
118    pub manifest_id: String,
119}
120
121impl crate::typed::Command for UninstallParams {
122    const METHOD: &'static str = "PWA.uninstall";
123    type Returns = crate::typed::NoReturns;
124}
125
126/// Launches the installed web app, or an url in the same web app instead of
127/// the default start url if it is provided. Returns a page Target.TargetID
128/// which can be used to attach to via Target.attachToTarget or similar APIs.
129///
130/// Parameters of `PWA.launch`.
131#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
132pub struct LaunchParams {
133    #[serde(rename = "manifestId")]
134    pub manifest_id: String,
135    #[serde(default, skip_serializing_if = "Option::is_none")]
136    pub url: Option<String>,
137}
138
139/// What `PWA.launch` answers with.
140#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
141pub struct LaunchReturns {
142    /// ID of the tab target created as a result.
143    #[serde(rename = "targetId")]
144    pub target_id: crate::protocol::target::TargetId,
145}
146
147impl crate::typed::Command for LaunchParams {
148    const METHOD: &'static str = "PWA.launch";
149    type Returns = LaunchReturns;
150}
151
152/// Opens one or more local files from an installed web app identified by its
153/// manifestId. The web app needs to have file handlers registered to process
154/// the files. The API returns one or more page Target.TargetIDs which can be
155/// used to attach to via Target.attachToTarget or similar APIs. If some files
156/// in the parameters cannot be handled by the web app, they will be ignored.
157/// If none of the files can be handled, this API returns an error. If no
158/// files are provided as the parameter, this API also returns an error.
159/// According to the definition of the file handlers in the manifest file, one
160/// Target.TargetID may represent a page handling one or more files. The order
161/// of the returned Target.TargetIDs is not guaranteed.
162/// TODO(crbug.com/339454034): Check the existences of the input files.
163///
164/// Parameters of `PWA.launchFilesInApp`.
165#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
166pub struct LaunchFilesInAppParams {
167    #[serde(rename = "manifestId")]
168    pub manifest_id: String,
169    pub files: Vec<String>,
170}
171
172/// What `PWA.launchFilesInApp` answers with.
173#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
174pub struct LaunchFilesInAppReturns {
175    /// IDs of the tab targets created as the result.
176    #[serde(rename = "targetIds")]
177    pub target_ids: Vec<crate::protocol::target::TargetId>,
178}
179
180impl crate::typed::Command for LaunchFilesInAppParams {
181    const METHOD: &'static str = "PWA.launchFilesInApp";
182    type Returns = LaunchFilesInAppReturns;
183}
184
185/// Opens the current page in its web app identified by the manifest id, needs
186/// to be called on a page target. This function returns immediately without
187/// waiting for the app to finish loading.
188///
189/// Parameters of `PWA.openCurrentPageInApp`.
190#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
191pub struct OpenCurrentPageInAppParams {
192    #[serde(rename = "manifestId")]
193    pub manifest_id: String,
194}
195
196impl crate::typed::Command for OpenCurrentPageInAppParams {
197    const METHOD: &'static str = "PWA.openCurrentPageInApp";
198    type Returns = crate::typed::NoReturns;
199}
200
201/// Changes user settings of the web app identified by its manifestId. If the
202/// app was not installed, this command returns an error. Unset parameters
203/// will be ignored; unrecognized values will cause an error. Unlike the ones
204/// defined in the manifest files of the web apps, these settings are provided
205/// by the browser and controlled by the users, they impact the way the
206/// browser handling the web apps. See the comment of each parameter.
207///
208/// Parameters of `PWA.changeAppUserSettings`.
209#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
210pub struct ChangeAppUserSettingsParams {
211    #[serde(rename = "manifestId")]
212    pub manifest_id: String,
213    /// If user allows the links clicked on by the user in the app's scope, or
214    /// extended scope if the manifest has scope extensions and the flags
215    /// `DesktopPWAsLinkCapturingWithScopeExtensions` and
216    /// `WebAppEnableScopeExtensions` are enabled. Note, the API does not support
217    /// resetting the linkCapturing to the initial value, uninstalling and
218    /// installing the web app again will reset it. TODO(crbug.com/339453269):
219    /// Setting this value on ChromeOS is not supported yet.
220    #[serde(
221        rename = "linkCapturing",
222        default,
223        skip_serializing_if = "Option::is_none"
224    )]
225    pub link_capturing: Option<bool>,
226    #[serde(
227        rename = "displayMode",
228        default,
229        skip_serializing_if = "Option::is_none"
230    )]
231    pub display_mode: Option<DisplayMode>,
232}
233
234impl crate::typed::Command for ChangeAppUserSettingsParams {
235    const METHOD: &'static str = "PWA.changeAppUserSettings";
236    type Returns = crate::typed::NoReturns;
237}