blob: a0559ef17fd77674e3f3aab9eb620bb6708978ec [file] [log] [blame]
Alexey Baskakovd05bb012019-03-27 07:06:171// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Song Fangzhencda4af62021-09-09 05:24:025#ifndef CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_
6#define CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_
Alexey Baskakovd05bb012019-03-27 07:06:177
Giovanni Ortuño Urquidi88971892020-04-17 06:51:298#include <string>
9#include <vector>
Alexey Baskakovd05bb012019-03-27 07:06:1710
Alan Cutter919b4592021-07-08 05:50:4411#include "base/values.h"
Alexey Baskakov4e0e92c2022-05-17 00:42:3212#include "chrome/browser/ash/system_web_apps/types/system_web_app_type.h"
Dmitrii Kuraginfb3929f2022-04-22 14:06:1913#include "chrome/browser/web_applications/user_display_mode.h"
Song Fangzhencda4af62021-09-09 05:24:0214#include "chrome/browser/web_applications/web_app_constants.h"
15#include "chrome/browser/web_applications/web_app_id.h"
Anosua Roy38b833b2022-01-18 15:39:0316#include "chrome/browser/web_applications/web_app_install_info.h"
Song Fangzhenafaf6922021-08-12 05:18:0217#include "chrome/browser/web_applications/web_app_install_params.h"
Anton Bikineev46bbb972021-05-15 17:53:5318#include "third_party/abseil-cpp/absl/types/optional.h"
Alexey Baskakovd05bb012019-03-27 07:06:1719#include "url/gurl.h"
20
21namespace web_app {
22
Anosua Roy18be3752022-01-10 07:16:4523using WebAppInstallInfoFactory =
24 base::RepeatingCallback<std::unique_ptr<WebAppInstallInfo>()>;
Dominic Schulz38238af2020-07-22 02:06:4725
Alexey Baskakov031895272019-07-18 08:19:3326enum class ExternalInstallSource;
Alexey Baskakovd05bb012019-03-27 07:06:1727
Alexey Baskakov0b9a2ee2019-07-22 01:21:2428struct ExternalInstallOptions {
Alan Cutter0cc83732020-09-02 02:26:3629 ExternalInstallOptions(const GURL& install_url,
Dmitrii Kuraginfb3929f2022-04-22 14:06:1930 absl::optional<UserDisplayMode> user_display_mode,
Alexey Baskakov0b9a2ee2019-07-22 01:21:2431 ExternalInstallSource install_source);
Dmitrii Kuraginfb3929f2022-04-22 14:06:1932
Alexey Baskakov0b9a2ee2019-07-22 01:21:2433 ~ExternalInstallOptions();
34 ExternalInstallOptions(const ExternalInstallOptions& other);
35 ExternalInstallOptions(ExternalInstallOptions&& other);
36 ExternalInstallOptions& operator=(const ExternalInstallOptions& other);
Alexey Baskakovd05bb012019-03-27 07:06:1737
Alexey Baskakov0b9a2ee2019-07-22 01:21:2438 bool operator==(const ExternalInstallOptions& other) const;
Alexey Baskakovd05bb012019-03-27 07:06:1739
Alan Cutter919b4592021-07-08 05:50:4440 base::Value AsDebugValue() const;
41
Alan Cutter0cc83732020-09-02 02:26:3642 GURL install_url;
Dmitrii Kuraginfb3929f2022-04-22 14:06:1943
44 absl::optional<UserDisplayMode> user_display_mode;
45
Alexey Baskakov031895272019-07-18 08:19:3346 ExternalInstallSource install_source;
Alexey Baskakovd05bb012019-03-27 07:06:1747
Howard Woloskydeaf4d5f2021-02-11 01:20:5948 // App name to use for placeholder apps or web apps that have no name in
49 // their manifest.
Anton Bikineev46bbb972021-05-15 17:53:5350 absl::optional<std::string> fallback_app_name;
Howard Woloskydeaf4d5f2021-02-11 01:20:5951
phweiss5f191ed2022-01-17 10:27:5352 // App name that replaces the app's real name.
53 // override_name takes precedent over fallback_app_name in case both are
phweissade1f322021-09-30 19:18:3454 // present.
phweiss5f191ed2022-01-17 10:27:5355 absl::optional<std::string> override_name;
56
57 // URL of an icon that replaces the app's real icons.
58 absl::optional<GURL> override_icon_url;
phweissade1f322021-09-30 19:18:3459
Giovanni Ortuño Urquidie22f2e12019-04-01 02:43:5160 // If true, a shortcut is added to the Applications folder on macOS, and Start
Giovanni Ortuño Urquidi88971892020-04-17 06:51:2961 // Menu on Linux and Windows and launcher on Chrome OS. If false, we skip
Giovanni Ortuño Urquidie22f2e12019-04-01 02:43:5162 // adding a shortcut to desktop as well, regardless of the value of
63 // |add_to_desktop|.
64 // TODO(ortuno): Make adding a shortcut to the applications menu independent
65 // from adding a shortcut to desktop.
66 bool add_to_applications_menu = true;
67
68 // If true, a shortcut is added to the desktop on Linux and Windows. Has no
69 // effect on macOS and Chrome OS.
70 bool add_to_desktop = true;
71
72 // If true, a shortcut is added to the "quick launch bar" of the OS: the Shelf
73 // for Chrome OS, the Dock for macOS, and the Quick Launch Bar or Taskbar on
74 // Windows. Currently this only works on Chrome OS.
75 bool add_to_quick_launch_bar = true;
Alexey Baskakovd05bb012019-03-27 07:06:1776
Giovanni Ortuño Urquidi88971892020-04-17 06:51:2977 // If true, the app can be searched for on Chrome OS. Has no effect on other
78 // platforms.
79 bool add_to_search = true;
80
81 // If true, the app is shown in App Management on Chrome OS. Has no effect on
82 // other platforms.
83 bool add_to_management = true;
84
Aya ElAttar14d72a252020-04-21 10:59:1985 // If true, the app icon is displayed on Chrome OS with a blocked logo on
86 // top, and the user cannot launch the app. Has no effect on other platforms.
87 bool is_disabled = false;
88
Alexey Baskakovd05bb012019-03-27 07:06:1789 // Whether the app should be reinstalled even if the user has previously
Dibyajyoti Palb07becd42022-05-16 21:24:3190 // uninstalled it. Only applies to preinstalled apps and/or apps that can be
91 // uninstalled by the user.
Alexey Baskakovd05bb012019-03-27 07:06:1792 bool override_previous_user_uninstall = false;
93
Alan Cutterf30aa0ef2020-11-03 09:24:4094 // Whether the app should only be installed if the user is using Chrome for
95 // the first time.
96 bool only_for_new_users = false;
97
Alexey Baskakovdc0abf1e2021-05-20 04:06:3798 // Whether the app should be omitted for new preinstalls. This is the opposite
99 // of |only_for_new_users| option. It can be used for partial deprecation of
100 // a preinstalled app: do not preinstall the app for new users but leave
101 // existing users unaffected.
102 bool only_if_previously_preinstalled = false;
103
Alan Cutter167ca8042020-11-09 06:27:07104 // Which user types this app should be installed for.
105 // See apps::DetermineUserType() for relevant string constants.
106 std::vector<std::string> user_type_allowlist;
107
Tim Sergeant4c71ee52022-02-01 00:14:25108 // Which feature flag should be enabled to install this app. If the feature
109 // is disabled, existing external installs will be removed.
110 // See chrome/browser/web_applications/preinstalled_app_install_features.h
Alan Cutter167ca8042020-11-09 06:27:07111 // for available features to gate on.
Anton Bikineev46bbb972021-05-15 17:53:53112 absl::optional<std::string> gate_on_feature;
Alan Cutter167ca8042020-11-09 06:27:07113
Tim Sergeant4c71ee52022-02-01 00:14:25114 // Which feature flag should be enabled to install this app. If the feature is
115 // disabled, existing external installs will not be removed.
116 // See chrome/browser/web_applications/preinstalled_app_install_features.h
117 // for available features to gate on.
118 absl::optional<std::string> gate_on_feature_or_installed;
119
Alan Cutter167ca8042020-11-09 06:27:07120 // Whether this should not be installed for devices that support ARC.
121 bool disable_if_arc_supported = false;
122
123 // Whether this should not be installed for tablet devices.
124 bool disable_if_tablet_form_factor = false;
125
Alexey Baskakovd05bb012019-03-27 07:06:17126 // This must only be used by pre-installed default or system apps that are
127 // valid PWAs if loading the real service worker is too costly to verify
128 // programmatically.
129 bool bypass_service_worker_check = false;
130
Alan Cuttera8f043e2021-05-07 07:52:37131 // When set to true this will fail installation with
132 // |kNotValidManifestForWebApp| if the |install_url| doesn't have a manifest
133 // that passes basic validity checks. This is ignored when |app_info_factory|
134 // is used.
Alexey Baskakovd05bb012019-03-27 07:06:17135 bool require_manifest = false;
136
Daniel d'Andrada5df2b582022-08-31 09:08:46137 // The web app should be installed as a shortcut, as if done via the
138 // "Create Shortcut..." option in desktop browser GUI.
139 bool install_as_shortcut = false;
140
Alexey Baskakovd05bb012019-03-27 07:06:17141 // Whether the app should be reinstalled even if it is already installed.
Christopher Lama04e05922019-06-27 06:06:11142 bool force_reinstall = false;
Giovanni Ortuño Urquidic7e719b2019-04-03 01:33:30143
Alexey Baskakovef2601fc2021-01-12 07:05:41144 // Whether we should update the app if the browser's binary milestone number
145 // goes from less the milestone specified to greater or equal than the
146 // milestone specified. For example, if this value is 89 then we update the
147 // app on all browser upgrades from <89 to >=89. The update happens only once.
Anton Bikineev46bbb972021-05-15 17:53:53148 absl::optional<int> force_reinstall_for_milestone;
Alexey Baskakovef2601fc2021-01-12 07:05:41149
Giovanni Ortuño Urquidi68bd2a52019-04-18 12:15:24150 // Whether we should wait for all app windows being closed before reinstalling
151 // the placeholder.
152 bool wait_for_windows_closed = false;
Giovanni Ortuño Urquidib6f4c5e02019-04-16 04:57:56153
Giovanni Ortuño Urquidic7e719b2019-04-03 01:33:30154 // Whether a placeholder app should be installed if we fail to retrieve the
155 // metadata for the app. A placeholder app uses:
156 // - The default Chrome App icon for the icon
157 // - |url| as the start_url
Howard Woloskydeaf4d5f2021-02-11 01:20:59158 // - |url| as the app name (unless fallback_app_name has been specified)
Giovanni Ortuño Urquidic7e719b2019-04-03 01:33:30159 bool install_placeholder = false;
Giovanni Ortuño Urquidib6f4c5e02019-04-16 04:57:56160
161 // Whether we should try to reinstall the app if there is a placeholder for
162 // it.
163 bool reinstall_placeholder = false;
Christopher Lam8cd21342019-08-20 03:57:34164
Alan Cutter35be21052020-09-29 11:37:05165 // Optional query parameters to add to the start_url when launching the app.
Anton Bikineev46bbb972021-05-15 17:53:53166 absl::optional<std::string> launch_query_params;
Alan Cutter35be21052020-09-29 11:37:05167
Alan Cutter464b32c62020-09-16 06:41:37168 // Whether we should load |service_worker_registration_url| after successful
169 // installation to allow the site to install its service worker and set up
170 // offline caching.
171 bool load_and_await_service_worker_registration = true;
172
173 // The URL to use for service worker registration. This is
174 // configurable by sites that wish to be able to track install metrics of the
175 // install_url separate from the service worker registration step. Defaults to
176 // install_url if unset.
Anton Bikineev46bbb972021-05-15 17:53:53177 absl::optional<GURL> service_worker_registration_url;
Alan Cutter464b32c62020-09-16 06:41:37178
Christopher Lam8cd21342019-08-20 03:57:34179 // A list of app_ids that the Web App System should attempt to uninstall and
180 // replace with this app (e.g maintain shelf pins, app list positions).
181 std::vector<AppId> uninstall_and_replace;
Giovanni Ortuño Urquidib73eb2c502020-03-26 23:05:11182
183 // Additional keywords that will be used by the OS when searching for the app.
184 // Only affects Chrome OS.
185 std::vector<std::string> additional_search_terms;
Dominic Schulz38238af2020-07-22 02:06:47186
Alan Cutter2c70a7f2020-09-18 06:50:13187 // Determines whether |app_info_factory| is used as a fallback or the primary
188 // source of app metadata. If true the |install_url| and
189 // |service_worker_registration_url| will not be loaded.
190 bool only_use_app_info_factory = false;
191
Anosua Roy18be3752022-01-10 07:16:45192 // A factory callback that returns a unique_ptr<WebAppInstallInfo> to be used
Alan Cutter2c70a7f2020-09-18 06:50:13193 // as the app's installation metadata.
Anosua Roy18be3752022-01-10 07:16:45194 WebAppInstallInfoFactory app_info_factory;
Dom Schulz7b4bd512021-01-06 23:39:22195
196 // The type of SystemWebApp, if this app is a System Web App.
Alexey Baskakov4e0e92c2022-05-17 00:42:32197 absl::optional<ash::SystemWebAppType> system_app_type = absl::nullopt;
Tim Sergeant47b94312021-03-17 03:59:50198
199 // Whether the app was installed by an OEM and should be placed in a special
200 // OEM folder in the app launcher. Only used on Chrome OS.
201 bool oem_installed = false;
Jeevan Shikaramab50d8392021-06-01 23:55:10202
203 // Whether this should be installed on devices without a touch screen with
204 // stylus support.
205 bool disable_if_touchscreen_with_stylus_not_supported = false;
jungoog@a30047c2022-01-07 07:46:31206
207 // Whether the app should show up in file-open intent and picking surfaces.
208 bool handles_file_open_intents = false;
Alan Cutter0154fa22022-01-28 05:10:33209
210 // The app id that's expected to be installed from `install_url`.
211 // Does not block installation if the actual app id doesn't match the
212 // expectation.
213 // Intended to be used for post-install activities like metrics and migration.
214 absl::optional<AppId> expected_app_id;
Alexey Baskakovd05bb012019-03-27 07:06:17215};
216
Song Fangzhenafaf6922021-08-12 05:18:02217WebAppInstallParams ConvertExternalInstallOptionsToParams(
Alexey Baskakovc3fa6382019-08-01 01:47:08218 const ExternalInstallOptions& install_options);
219
Alexey Baskakovd05bb012019-03-27 07:06:17220} // namespace web_app
221
Song Fangzhencda4af62021-09-09 05:24:02222#endif // CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_