Skip to main content

browser_protocol/pwa/
mod.rs

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