Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 1 | // 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 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 | |
Giovanni Ortuño Urquidi | 8897189 | 2020-04-17 06:51:29 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 10 | |
Alan Cutter | 919b459 | 2021-07-08 05:50:44 | [diff] [blame] | 11 | #include "base/values.h" |
Dom Schulz | 5cecec02 | 2021-03-25 01:13:13 | [diff] [blame] | 12 | #include "chrome/browser/web_applications/system_web_apps/system_web_app_types.h" |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame^] | 13 | #include "chrome/browser/web_applications/web_app_constants.h" |
| 14 | #include "chrome/browser/web_applications/web_app_id.h" |
Song Fangzhen | afaf692 | 2021-08-12 05:18:02 | [diff] [blame] | 15 | #include "chrome/browser/web_applications/web_app_install_params.h" |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame^] | 16 | #include "chrome/browser/web_applications/web_application_info.h" |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 17 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 18 | #include "url/gurl.h" |
| 19 | |
| 20 | namespace web_app { |
| 21 | |
Dominic Schulz | 38238af | 2020-07-22 02:06:47 | [diff] [blame] | 22 | using WebApplicationInfoFactory = |
| 23 | base::RepeatingCallback<std::unique_ptr<WebApplicationInfo>()>; |
| 24 | |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 25 | enum class ExternalInstallSource; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 26 | |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 27 | struct ExternalInstallOptions { |
Alan Cutter | 0cc8373 | 2020-09-02 02:26:36 | [diff] [blame] | 28 | ExternalInstallOptions(const GURL& install_url, |
Eric Willigers | d32986ad | 2019-11-04 00:40:04 | [diff] [blame] | 29 | DisplayMode user_display_mode, |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 30 | ExternalInstallSource install_source); |
| 31 | ~ExternalInstallOptions(); |
| 32 | ExternalInstallOptions(const ExternalInstallOptions& other); |
| 33 | ExternalInstallOptions(ExternalInstallOptions&& other); |
| 34 | ExternalInstallOptions& operator=(const ExternalInstallOptions& other); |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 35 | |
Alexey Baskakov | 0b9a2ee | 2019-07-22 01:21:24 | [diff] [blame] | 36 | bool operator==(const ExternalInstallOptions& other) const; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 37 | |
Alan Cutter | 919b459 | 2021-07-08 05:50:44 | [diff] [blame] | 38 | base::Value AsDebugValue() const; |
| 39 | |
Alan Cutter | 0cc8373 | 2020-09-02 02:26:36 | [diff] [blame] | 40 | GURL install_url; |
Eric Willigers | d32986ad | 2019-11-04 00:40:04 | [diff] [blame] | 41 | DisplayMode user_display_mode; |
Alexey Baskakov | 03189527 | 2019-07-18 08:19:33 | [diff] [blame] | 42 | ExternalInstallSource install_source; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 43 | |
Howard Wolosky | deaf4d5f | 2021-02-11 01:20:59 | [diff] [blame] | 44 | // App name to use for placeholder apps or web apps that have no name in |
| 45 | // their manifest. |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 46 | absl::optional<std::string> fallback_app_name; |
Howard Wolosky | deaf4d5f | 2021-02-11 01:20:59 | [diff] [blame] | 47 | |
Giovanni Ortuño Urquidi | e22f2e1 | 2019-04-01 02:43:51 | [diff] [blame] | 48 | // 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] | 49 | // 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] | 50 | // adding a shortcut to desktop as well, regardless of the value of |
| 51 | // |add_to_desktop|. |
| 52 | // TODO(ortuno): Make adding a shortcut to the applications menu independent |
| 53 | // from adding a shortcut to desktop. |
| 54 | bool add_to_applications_menu = true; |
| 55 | |
| 56 | // If true, a shortcut is added to the desktop on Linux and Windows. Has no |
| 57 | // effect on macOS and Chrome OS. |
| 58 | bool add_to_desktop = true; |
| 59 | |
| 60 | // If true, a shortcut is added to the "quick launch bar" of the OS: the Shelf |
| 61 | // for Chrome OS, the Dock for macOS, and the Quick Launch Bar or Taskbar on |
| 62 | // Windows. Currently this only works on Chrome OS. |
| 63 | bool add_to_quick_launch_bar = true; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 64 | |
Giovanni Ortuño Urquidi | 8897189 | 2020-04-17 06:51:29 | [diff] [blame] | 65 | // If true, the app can be searched for on Chrome OS. Has no effect on other |
| 66 | // platforms. |
| 67 | bool add_to_search = true; |
| 68 | |
| 69 | // If true, the app is shown in App Management on Chrome OS. Has no effect on |
| 70 | // other platforms. |
| 71 | bool add_to_management = true; |
| 72 | |
Carlos Frias | 5ddded6 | 2020-05-27 23:38:18 | [diff] [blame] | 73 | // Whether the app should be registered to run on OS login. |
| 74 | // Currently this only works on Windows by adding a shortcut to the |
| 75 | // Startup Folder. |
| 76 | // TODO(crbug.com/897302): Enable for other platforms. |
| 77 | bool run_on_os_login = false; |
| 78 | |
Aya ElAttar | 14d72a25 | 2020-04-21 10:59:19 | [diff] [blame] | 79 | // If true, the app icon is displayed on Chrome OS with a blocked logo on |
| 80 | // top, and the user cannot launch the app. Has no effect on other platforms. |
| 81 | bool is_disabled = false; |
| 82 | |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 83 | // Whether the app should be reinstalled even if the user has previously |
| 84 | // uninstalled it. |
| 85 | bool override_previous_user_uninstall = false; |
| 86 | |
Alan Cutter | f30aa0ef | 2020-11-03 09:24:40 | [diff] [blame] | 87 | // Whether the app should only be installed if the user is using Chrome for |
| 88 | // the first time. |
| 89 | bool only_for_new_users = false; |
| 90 | |
Alexey Baskakov | dc0abf1e | 2021-05-20 04:06:37 | [diff] [blame] | 91 | // Whether the app should be omitted for new preinstalls. This is the opposite |
| 92 | // of |only_for_new_users| option. It can be used for partial deprecation of |
| 93 | // a preinstalled app: do not preinstall the app for new users but leave |
| 94 | // existing users unaffected. |
| 95 | bool only_if_previously_preinstalled = false; |
| 96 | |
Alan Cutter | 167ca804 | 2020-11-09 06:27:07 | [diff] [blame] | 97 | // Which user types this app should be installed for. |
| 98 | // See apps::DetermineUserType() for relevant string constants. |
| 99 | std::vector<std::string> user_type_allowlist; |
| 100 | |
| 101 | // Which feature flag should be enabled to install this app. See |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame^] | 102 | // chrome/browser/web_applications/preinstalled_app_install_features.h |
Alan Cutter | 167ca804 | 2020-11-09 06:27:07 | [diff] [blame] | 103 | // for available features to gate on. |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 104 | absl::optional<std::string> gate_on_feature; |
Alan Cutter | 167ca804 | 2020-11-09 06:27:07 | [diff] [blame] | 105 | |
| 106 | // Whether this should not be installed for devices that support ARC. |
| 107 | bool disable_if_arc_supported = false; |
| 108 | |
| 109 | // Whether this should not be installed for tablet devices. |
| 110 | bool disable_if_tablet_form_factor = false; |
| 111 | |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 112 | // This must only be used by pre-installed default or system apps that are |
| 113 | // valid PWAs if loading the real service worker is too costly to verify |
| 114 | // programmatically. |
| 115 | bool bypass_service_worker_check = false; |
| 116 | |
Alan Cutter | a8f043e | 2021-05-07 07:52:37 | [diff] [blame] | 117 | // When set to true this will fail installation with |
| 118 | // |kNotValidManifestForWebApp| if the |install_url| doesn't have a manifest |
| 119 | // that passes basic validity checks. This is ignored when |app_info_factory| |
| 120 | // is used. |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 121 | bool require_manifest = false; |
| 122 | |
| 123 | // Whether the app should be reinstalled even if it is already installed. |
Christopher Lam | a04e0592 | 2019-06-27 06:06:11 | [diff] [blame] | 124 | bool force_reinstall = false; |
Giovanni Ortuño Urquidi | c7e719b | 2019-04-03 01:33:30 | [diff] [blame] | 125 | |
Alexey Baskakov | ef2601fc | 2021-01-12 07:05:41 | [diff] [blame] | 126 | // Whether we should update the app if the browser's binary milestone number |
| 127 | // goes from less the milestone specified to greater or equal than the |
| 128 | // milestone specified. For example, if this value is 89 then we update the |
| 129 | // app on all browser upgrades from <89 to >=89. The update happens only once. |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 130 | absl::optional<int> force_reinstall_for_milestone; |
Alexey Baskakov | ef2601fc | 2021-01-12 07:05:41 | [diff] [blame] | 131 | |
Giovanni Ortuño Urquidi | 68bd2a5 | 2019-04-18 12:15:24 | [diff] [blame] | 132 | // Whether we should wait for all app windows being closed before reinstalling |
| 133 | // the placeholder. |
| 134 | bool wait_for_windows_closed = false; |
Giovanni Ortuño Urquidi | b6f4c5e0 | 2019-04-16 04:57:56 | [diff] [blame] | 135 | |
Giovanni Ortuño Urquidi | c7e719b | 2019-04-03 01:33:30 | [diff] [blame] | 136 | // Whether a placeholder app should be installed if we fail to retrieve the |
| 137 | // metadata for the app. A placeholder app uses: |
| 138 | // - The default Chrome App icon for the icon |
| 139 | // - |url| as the start_url |
Howard Wolosky | deaf4d5f | 2021-02-11 01:20:59 | [diff] [blame] | 140 | // - |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] | 141 | bool install_placeholder = false; |
Giovanni Ortuño Urquidi | b6f4c5e0 | 2019-04-16 04:57:56 | [diff] [blame] | 142 | |
| 143 | // Whether we should try to reinstall the app if there is a placeholder for |
| 144 | // it. |
| 145 | bool reinstall_placeholder = false; |
Christopher Lam | 8cd2134 | 2019-08-20 03:57:34 | [diff] [blame] | 146 | |
Alan Cutter | 35be2105 | 2020-09-29 11:37:05 | [diff] [blame] | 147 | // Optional query parameters to add to the start_url when launching the app. |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 148 | absl::optional<std::string> launch_query_params; |
Alan Cutter | 35be2105 | 2020-09-29 11:37:05 | [diff] [blame] | 149 | |
Alan Cutter | 464b32c6 | 2020-09-16 06:41:37 | [diff] [blame] | 150 | // Whether we should load |service_worker_registration_url| after successful |
| 151 | // installation to allow the site to install its service worker and set up |
| 152 | // offline caching. |
| 153 | bool load_and_await_service_worker_registration = true; |
| 154 | |
| 155 | // The URL to use for service worker registration. This is |
| 156 | // configurable by sites that wish to be able to track install metrics of the |
| 157 | // install_url separate from the service worker registration step. Defaults to |
| 158 | // install_url if unset. |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 159 | absl::optional<GURL> service_worker_registration_url; |
Alan Cutter | 464b32c6 | 2020-09-16 06:41:37 | [diff] [blame] | 160 | |
Christopher Lam | 8cd2134 | 2019-08-20 03:57:34 | [diff] [blame] | 161 | // A list of app_ids that the Web App System should attempt to uninstall and |
| 162 | // replace with this app (e.g maintain shelf pins, app list positions). |
| 163 | std::vector<AppId> uninstall_and_replace; |
Giovanni Ortuño Urquidi | b73eb2c50 | 2020-03-26 23:05:11 | [diff] [blame] | 164 | |
| 165 | // Additional keywords that will be used by the OS when searching for the app. |
| 166 | // Only affects Chrome OS. |
| 167 | std::vector<std::string> additional_search_terms; |
Dominic Schulz | 38238af | 2020-07-22 02:06:47 | [diff] [blame] | 168 | |
Alan Cutter | 2c70a7f | 2020-09-18 06:50:13 | [diff] [blame] | 169 | // Determines whether |app_info_factory| is used as a fallback or the primary |
| 170 | // source of app metadata. If true the |install_url| and |
| 171 | // |service_worker_registration_url| will not be loaded. |
| 172 | bool only_use_app_info_factory = false; |
| 173 | |
| 174 | // A factory callback that returns a unique_ptr<WebApplicationInfo> to be used |
| 175 | // as the app's installation metadata. |
Dominic Schulz | 38238af | 2020-07-22 02:06:47 | [diff] [blame] | 176 | WebApplicationInfoFactory app_info_factory; |
Dom Schulz | 7b4bd51 | 2021-01-06 23:39:22 | [diff] [blame] | 177 | |
| 178 | // The type of SystemWebApp, if this app is a System Web App. |
Anton Bikineev | 46bbb97 | 2021-05-15 17:53:53 | [diff] [blame] | 179 | absl::optional<SystemAppType> system_app_type = absl::nullopt; |
Tim Sergeant | 47b9431 | 2021-03-17 03:59:50 | [diff] [blame] | 180 | |
| 181 | // Whether the app was installed by an OEM and should be placed in a special |
| 182 | // OEM folder in the app launcher. Only used on Chrome OS. |
| 183 | bool oem_installed = false; |
Jeevan Shikaram | ab50d839 | 2021-06-01 23:55:10 | [diff] [blame] | 184 | |
| 185 | // Whether this should be installed on devices without a touch screen with |
| 186 | // stylus support. |
| 187 | bool disable_if_touchscreen_with_stylus_not_supported = false; |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 188 | }; |
| 189 | |
Song Fangzhen | afaf692 | 2021-08-12 05:18:02 | [diff] [blame] | 190 | WebAppInstallParams ConvertExternalInstallOptionsToParams( |
Alexey Baskakov | c3fa638 | 2019-08-01 01:47:08 | [diff] [blame] | 191 | const ExternalInstallOptions& install_options); |
| 192 | |
Alexey Baskakov | d05bb01 | 2019-03-27 07:06:17 | [diff] [blame] | 193 | } // namespace web_app |
| 194 | |
Song Fangzhen | cda4af6 | 2021-09-09 05:24:02 | [diff] [blame^] | 195 | #endif // CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_ |