Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_ |
| 6 | #define CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_ |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 7 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 8 | #include <optional> |
Giovanni Ortuño Urquidi | 8897189 | 2020-04-17 06:51:29 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 11 | |
Ben Reich | 50d16cd5 | 2023-07-12 01:46:12 | [diff] [blame] | 12 | #include "base/time/time.h" |
Alan Cutter | 919b459 | 2021-07-08 05:50:44 | [diff] [blame] | 13 | #include "base/values.h" |
Georg Neis | 251cf6f | 2025-02-19 05:23:19 | [diff] [blame] | 14 | #include "build/build_config.h" |
liqining.keiling | 5a8e27f2 | 2023-01-01 17:55:47 | [diff] [blame] | 15 | #include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h" |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame] | 16 | #include "chrome/browser/web_applications/web_app_constants.h" |
Anosua Roy | 38b833b | 2022-01-18 15:39:03 | [diff] [blame] | 17 | #include "chrome/browser/web_applications/web_app_install_info.h" |
Song Fangzhen | afaf692 | 2021-08-12 05:18:02 | [diff] [blame] | 18 | #include "chrome/browser/web_applications/web_app_install_params.h" |
Glenn Hartmann | 5f992ed | 2023-09-25 18:05:36 | [diff] [blame] | 19 | #include "components/webapps/common/web_app_id.h" |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 20 | #include "url/gurl.h" |
| 21 | |
Georg Neis | 251cf6f | 2025-02-19 05:23:19 | [diff] [blame] | 22 | #if BUILDFLAG(IS_CHROMEOS) |
Lei Zhang | 52db54f | 2023-02-13 20:27:36 | [diff] [blame] | 23 | #include "ash/webui/system_apps/public/system_web_app_type.h" |
| 24 | #endif |
| 25 | |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 26 | namespace web_app { |
| 27 | |
Anosua Roy | 18be375 | 2022-01-10 07:16:45 | [diff] [blame] | 28 | using WebAppInstallInfoFactory = |
Alan Cutter | d95afd9 | 2023-06-26 04:21:40 | [diff] [blame] | 29 | base::RepeatingCallback<std::unique_ptr<WebAppInstallInfo>()>; |
Dominic Schulz | 38238af | 2020-07-22 02:06:47 | [diff] [blame] | 30 | |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 31 | enum class ExternalInstallSource; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 32 | |
Simon Hangl | 4f7fcae6 | 2023-11-21 16:00:53 | [diff] [blame] | 33 | enum class PlaceholderResolutionBehavior { |
| 34 | // Waits for all running app instances being closed before the placeholder is |
| 35 | // resolved. |
| 36 | kWaitForAppWindowsClosed, |
| 37 | // Closes all running app instances, resolves the placeholder and relaunches |
| 38 | // the app in a separate window. |
| 39 | kCloseAndRelaunch, |
| 40 | // Closes all running app instances and resolves the placeholder. After the |
| 41 | // placeholder is resolved, the app is not relaunched. |
| 42 | kClose |
| 43 | }; |
| 44 | |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 45 | struct ExternalInstallOptions { |
liqining.keiling | 5a8e27f2 | 2023-01-01 17:55:47 | [diff] [blame] | 46 | ExternalInstallOptions( |
| 47 | const GURL& install_url, |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 48 | std::optional<mojom::UserDisplayMode> user_display_mode, |
liqining.keiling | 5a8e27f2 | 2023-01-01 17:55:47 | [diff] [blame] | 49 | ExternalInstallSource install_source); |
Dmitrii Kuragin | fb3929f | 2022-04-22 14:06:19 | [diff] [blame] | 50 | |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 51 | ~ExternalInstallOptions(); |
| 52 | ExternalInstallOptions(const ExternalInstallOptions& other); |
| 53 | ExternalInstallOptions(ExternalInstallOptions&& other); |
| 54 | ExternalInstallOptions& operator=(const ExternalInstallOptions& other); |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 55 | |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 56 | bool operator==(const ExternalInstallOptions& other) const; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 57 | |
Alan Cutter | 919b459 | 2021-07-08 05:50:44 | [diff] [blame] | 58 | base::Value AsDebugValue() const; |
| 59 | |
Alan Cutter | 0cc8373 | 2020-09-02 02:26:36 | [diff] [blame] | 60 | GURL install_url; |
Dmitrii Kuragin | fb3929f | 2022-04-22 14:06:19 | [diff] [blame] | 61 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 62 | std::optional<mojom::UserDisplayMode> user_display_mode; |
Dmitrii Kuragin | fb3929f | 2022-04-22 14:06:19 | [diff] [blame] | 63 | |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 64 | ExternalInstallSource install_source; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 65 | |
Howard Wolosky | deaf4d5f | 2021-02-11 01:20:59 | [diff] [blame] | 66 | // App name to use for placeholder apps or web apps that have no name in |
| 67 | // their manifest. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 68 | std::optional<std::string> fallback_app_name; |
Howard Wolosky | deaf4d5f | 2021-02-11 01:20:59 | [diff] [blame] | 69 | |
phweiss | 5f191ed | 2022-01-17 10:27:53 | [diff] [blame] | 70 | // App name that replaces the app's real name. |
| 71 | // override_name takes precedent over fallback_app_name in case both are |
phweiss | ade1f32 | 2021-09-30 19:18:34 | [diff] [blame] | 72 | // present. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 73 | std::optional<std::string> override_name; |
phweiss | 5f191ed | 2022-01-17 10:27:53 | [diff] [blame] | 74 | |
| 75 | // URL of an icon that replaces the app's real icons. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 76 | std::optional<GURL> override_icon_url; |
phweiss | ade1f32 | 2021-09-30 19:18:34 | [diff] [blame] | 77 | |
Giovanni Ortuño Urquidi | e22f2e1 | 2019-04-01 02:43:51 | [diff] [blame] | 78 | // If true, a shortcut is added to the Applications folder on macOS, and Start |
Giovanni Ortuño Urquidi | 8897189 | 2020-04-17 06:51:29 | [diff] [blame] | 79 | // Menu on Linux and Windows and launcher on Chrome OS. If false, we skip |
Giovanni Ortuño Urquidi | e22f2e1 | 2019-04-01 02:43:51 | [diff] [blame] | 80 | // adding a shortcut to desktop as well, regardless of the value of |
| 81 | // |add_to_desktop|. |
| 82 | // TODO(ortuno): Make adding a shortcut to the applications menu independent |
| 83 | // from adding a shortcut to desktop. |
| 84 | bool add_to_applications_menu = true; |
| 85 | |
| 86 | // If true, a shortcut is added to the desktop on Linux and Windows. Has no |
| 87 | // effect on macOS and Chrome OS. |
| 88 | bool add_to_desktop = true; |
| 89 | |
| 90 | // If true, a shortcut is added to the "quick launch bar" of the OS: the Shelf |
| 91 | // for Chrome OS, the Dock for macOS, and the Quick Launch Bar or Taskbar on |
| 92 | // Windows. Currently this only works on Chrome OS. |
| 93 | bool add_to_quick_launch_bar = true; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 94 | |
Giovanni Ortuño Urquidi | 8897189 | 2020-04-17 06:51:29 | [diff] [blame] | 95 | // If true, the app can be searched for on Chrome OS. Has no effect on other |
| 96 | // platforms. |
| 97 | bool add_to_search = true; |
| 98 | |
| 99 | // If true, the app is shown in App Management on Chrome OS. Has no effect on |
| 100 | // other platforms. |
| 101 | bool add_to_management = true; |
| 102 | |
Aya ElAttar | 14d72a25 | 2020-04-21 10:59:19 | [diff] [blame] | 103 | // If true, the app icon is displayed on Chrome OS with a blocked logo on |
| 104 | // top, and the user cannot launch the app. Has no effect on other platforms. |
| 105 | bool is_disabled = false; |
| 106 | |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 107 | // Whether the app should be reinstalled even if the user has previously |
Dibyajyoti Pal | b07becd4 | 2022-05-16 21:24:31 | [diff] [blame] | 108 | // uninstalled it. Only applies to preinstalled apps and/or apps that can be |
| 109 | // uninstalled by the user. |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 110 | bool override_previous_user_uninstall = false; |
| 111 | |
Alan Cutter | f30aa0ef | 2020-11-03 09:24:40 | [diff] [blame] | 112 | // Whether the app should only be installed if the user is using Chrome for |
| 113 | // the first time. |
| 114 | bool only_for_new_users = false; |
| 115 | |
Alexey Baskakov | dc0abf1e | 2021-05-20 04:06:37 | [diff] [blame] | 116 | // Whether the app should be omitted for new preinstalls. This is the opposite |
| 117 | // of |only_for_new_users| option. It can be used for partial deprecation of |
| 118 | // a preinstalled app: do not preinstall the app for new users but leave |
| 119 | // existing users unaffected. |
| 120 | bool only_if_previously_preinstalled = false; |
| 121 | |
Alan Cutter | 167ca804 | 2020-11-09 06:27:07 | [diff] [blame] | 122 | // Which user types this app should be installed for. |
| 123 | // See apps::DetermineUserType() for relevant string constants. |
| 124 | std::vector<std::string> user_type_allowlist; |
| 125 | |
Tim Sergeant | 4c71ee5 | 2022-02-01 00:14:25 | [diff] [blame] | 126 | // Which feature flag should be enabled to install this app. If the feature |
| 127 | // is disabled, existing external installs will be removed. |
| 128 | // See chrome/browser/web_applications/preinstalled_app_install_features.h |
Alan Cutter | 167ca804 | 2020-11-09 06:27:07 | [diff] [blame] | 129 | // for available features to gate on. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 130 | std::optional<std::string> gate_on_feature; |
Alan Cutter | 167ca804 | 2020-11-09 06:27:07 | [diff] [blame] | 131 | |
Tim Sergeant | 4c71ee5 | 2022-02-01 00:14:25 | [diff] [blame] | 132 | // Which feature flag should be enabled to install this app. If the feature is |
| 133 | // disabled, existing external installs will not be removed. |
| 134 | // See chrome/browser/web_applications/preinstalled_app_install_features.h |
| 135 | // for available features to gate on. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 136 | std::optional<std::string> gate_on_feature_or_installed; |
Tim Sergeant | 4c71ee5 | 2022-02-01 00:14:25 | [diff] [blame] | 137 | |
Alan Cutter | 167ca804 | 2020-11-09 06:27:07 | [diff] [blame] | 138 | // Whether this should not be installed for devices that support ARC. |
| 139 | bool disable_if_arc_supported = false; |
| 140 | |
| 141 | // Whether this should not be installed for tablet devices. |
| 142 | bool disable_if_tablet_form_factor = false; |
| 143 | |
Alan Cutter | a8f043e | 2021-05-07 07:52:37 | [diff] [blame] | 144 | // When set to true this will fail installation with |
| 145 | // |kNotValidManifestForWebApp| if the |install_url| doesn't have a manifest |
| 146 | // that passes basic validity checks. This is ignored when |app_info_factory| |
| 147 | // is used. |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 148 | bool require_manifest = false; |
| 149 | |
msiem | 12b8863 | 2025-01-24 18:51:34 | [diff] [blame] | 150 | // The web app should be installed as a DIY, where only limited |
Daniel d'Andrada | e070761 | 2022-09-27 16:53:55 | [diff] [blame] | 151 | // values from the manifest are used (like theme color) and all extra |
| 152 | // capabilities are not used (like file handlers). |
msiem | 12b8863 | 2025-01-24 18:51:34 | [diff] [blame] | 153 | bool install_as_diy = false; |
Daniel d'Andrada | 5df2b58 | 2022-08-31 09:08:46 | [diff] [blame] | 154 | |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 155 | // Whether the app should be reinstalled even if it is already installed. |
Christopher Lam | a04e0592 | 2019-06-27 06:06:11 | [diff] [blame] | 156 | bool force_reinstall = false; |
Giovanni Ortuño Urquidi | c7e719b | 2019-04-03 01:33:30 | [diff] [blame] | 157 | |
Alexey Baskakov | ef2601fc | 2021-01-12 07:05:41 | [diff] [blame] | 158 | // Whether we should update the app if the browser's binary milestone number |
| 159 | // goes from less the milestone specified to greater or equal than the |
| 160 | // milestone specified. For example, if this value is 89 then we update the |
| 161 | // app on all browser upgrades from <89 to >=89. The update happens only once. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 162 | std::optional<int> force_reinstall_for_milestone; |
Alexey Baskakov | ef2601fc | 2021-01-12 07:05:41 | [diff] [blame] | 163 | |
Simon Hangl | 4f7fcae6 | 2023-11-21 16:00:53 | [diff] [blame] | 164 | // Defines how to handle running app instances of a placeholder app when a |
| 165 | // placeholder can be resolved. See `PlaceholderResolutionBehavior` |
| 166 | // documentation for details. |
| 167 | PlaceholderResolutionBehavior placeholder_resolution_behavior = |
| 168 | PlaceholderResolutionBehavior::kClose; |
Giovanni Ortuño Urquidi | b6f4c5e0 | 2019-04-16 04:57:56 | [diff] [blame] | 169 | |
Giovanni Ortuño Urquidi | c7e719b | 2019-04-03 01:33:30 | [diff] [blame] | 170 | // Whether a placeholder app should be installed if we fail to retrieve the |
| 171 | // metadata for the app. A placeholder app uses: |
| 172 | // - The default Chrome App icon for the icon |
| 173 | // - |url| as the start_url |
Howard Wolosky | deaf4d5f | 2021-02-11 01:20:59 | [diff] [blame] | 174 | // - |url| as the app name (unless fallback_app_name has been specified) |
Giovanni Ortuño Urquidi | c7e719b | 2019-04-03 01:33:30 | [diff] [blame] | 175 | bool install_placeholder = false; |
Giovanni Ortuño Urquidi | b6f4c5e0 | 2019-04-16 04:57:56 | [diff] [blame] | 176 | |
Alan Cutter | 35be2105 | 2020-09-29 11:37:05 | [diff] [blame] | 177 | // Optional query parameters to add to the start_url when launching the app. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 178 | std::optional<std::string> launch_query_params; |
Alan Cutter | 35be2105 | 2020-09-29 11:37:05 | [diff] [blame] | 179 | |
Alan Cutter | 464b32c6 | 2020-09-16 06:41:37 | [diff] [blame] | 180 | // Whether we should load |service_worker_registration_url| after successful |
| 181 | // installation to allow the site to install its service worker and set up |
| 182 | // offline caching. |
| 183 | bool load_and_await_service_worker_registration = true; |
| 184 | |
| 185 | // The URL to use for service worker registration. This is |
| 186 | // configurable by sites that wish to be able to track install metrics of the |
| 187 | // install_url separate from the service worker registration step. Defaults to |
| 188 | // install_url if unset. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 189 | std::optional<GURL> service_worker_registration_url; |
Alan Cutter | 464b32c6 | 2020-09-16 06:41:37 | [diff] [blame] | 190 | |
Ben Reich | 50d16cd5 | 2023-07-12 01:46:12 | [diff] [blame] | 191 | // The time to wait for the service worker registration before it times out. |
| 192 | // This is currently default at 40 seconds, override this value if more or |
| 193 | // less time is required. |
| 194 | base::TimeDelta service_worker_registration_timeout = base::Seconds(40); |
| 195 | |
Christopher Lam | 8cd2134 | 2019-08-20 03:57:34 | [diff] [blame] | 196 | // A list of app_ids that the Web App System should attempt to uninstall and |
| 197 | // replace with this app (e.g maintain shelf pins, app list positions). |
Glenn Hartmann | 5f992ed | 2023-09-25 18:05:36 | [diff] [blame] | 198 | std::vector<webapps::AppId> uninstall_and_replace; |
Giovanni Ortuño Urquidi | b73eb2c50 | 2020-03-26 23:05:11 | [diff] [blame] | 199 | |
| 200 | // Additional keywords that will be used by the OS when searching for the app. |
| 201 | // Only affects Chrome OS. |
| 202 | std::vector<std::string> additional_search_terms; |
Dominic Schulz | 38238af | 2020-07-22 02:06:47 | [diff] [blame] | 203 | |
Alan Cutter | 2c70a7f | 2020-09-18 06:50:13 | [diff] [blame] | 204 | // Determines whether |app_info_factory| is used as a fallback or the primary |
| 205 | // source of app metadata. If true the |install_url| and |
| 206 | // |service_worker_registration_url| will not be loaded. |
| 207 | bool only_use_app_info_factory = false; |
| 208 | |
Alan Cutter | d95afd9 | 2023-06-26 04:21:40 | [diff] [blame] | 209 | // A factory callback that returns a unique_ptr<WebAppInstallInfo> to be used |
| 210 | // as the app's installation metadata. |
Anosua Roy | 18be375 | 2022-01-10 07:16:45 | [diff] [blame] | 211 | WebAppInstallInfoFactory app_info_factory; |
Dom Schulz | 7b4bd51 | 2021-01-06 23:39:22 | [diff] [blame] | 212 | |
Georg Neis | 251cf6f | 2025-02-19 05:23:19 | [diff] [blame] | 213 | #if BUILDFLAG(IS_CHROMEOS) |
Dom Schulz | 7b4bd51 | 2021-01-06 23:39:22 | [diff] [blame] | 214 | // The type of SystemWebApp, if this app is a System Web App. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 215 | std::optional<ash::SystemWebAppType> system_app_type = std::nullopt; |
Lei Zhang | 52db54f | 2023-02-13 20:27:36 | [diff] [blame] | 216 | #endif |
Tim Sergeant | 47b9431 | 2021-03-17 03:59:50 | [diff] [blame] | 217 | |
| 218 | // Whether the app was installed by an OEM and should be placed in a special |
| 219 | // OEM folder in the app launcher. Only used on Chrome OS. |
| 220 | bool oem_installed = false; |
Jeevan Shikaram | ab50d839 | 2021-06-01 23:55:10 | [diff] [blame] | 221 | |
| 222 | // Whether this should be installed on devices without a touch screen with |
| 223 | // stylus support. |
| 224 | bool disable_if_touchscreen_with_stylus_not_supported = false; |
jungoog@ | a30047c | 2022-01-07 07:46:31 | [diff] [blame] | 225 | |
| 226 | // Whether the app should show up in file-open intent and picking surfaces. |
| 227 | bool handles_file_open_intents = false; |
Alan Cutter | 0154fa2 | 2022-01-28 05:10:33 | [diff] [blame] | 228 | |
| 229 | // The app id that's expected to be installed from `install_url`. |
| 230 | // Does not block installation if the actual app id doesn't match the |
| 231 | // expectation. |
| 232 | // Intended to be used for post-install activities like metrics and migration. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 233 | std::optional<webapps::AppId> expected_app_id; |
David Black | 05833c9c | 2024-03-26 08:29:01 | [diff] [blame] | 234 | |
| 235 | // Whether the app should be set as the preferred app for its supported links |
| 236 | // after installation. Note that this has no effect if the app is already |
| 237 | // installed as the user may have already updated their preference. |
| 238 | bool is_preferred_app_for_supported_links = false; |
Daniel Murphy | 6672a8d | 2024-06-26 16:39:52 | [diff] [blame] | 239 | |
| 240 | // Whether the app should not be fully installed with os integration |
| 241 | // (shortcuts in application menu, etc), and instead only installed within |
| 242 | // Chromium. This sets the installation status to |
| 243 | // `InstallState::INSTALLED_WITHOUT_OS_INTEGRATION`. This will not |
| 244 | // downgrade an existing install. |
| 245 | bool install_without_os_integration = false; |
| 246 | |
| 247 | // Note: All new fields must be added to AsDebugValue() and the == operator. |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 248 | }; |
| 249 | |
Song Fangzhen | afaf692 | 2021-08-12 05:18:02 | [diff] [blame] | 250 | WebAppInstallParams ConvertExternalInstallOptionsToParams( |
Alexey Baskakov | c3fa638 | 2019-08-01 01:47:08 | [diff] [blame] | 251 | const ExternalInstallOptions& install_options); |
| 252 | |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 253 | } // namespace web_app |
| 254 | |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame] | 255 | #endif // CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_ |