blob: 94d0b112216c8634a2f81f74fd4942e075ad5f3d [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"
Dom Schulz5cecec022021-03-25 01:13:1312#include "chrome/browser/web_applications/system_web_apps/system_web_app_types.h"
Song Fangzhencda4af62021-09-09 05:24:0213#include "chrome/browser/web_applications/web_app_constants.h"
14#include "chrome/browser/web_applications/web_app_id.h"
Anosua Roy38b833b2022-01-18 15:39:0315#include "chrome/browser/web_applications/web_app_install_info.h"
Song Fangzhenafaf6922021-08-12 05:18:0216#include "chrome/browser/web_applications/web_app_install_params.h"
Anton Bikineev46bbb972021-05-15 17:53:5317#include "third_party/abseil-cpp/absl/types/optional.h"
Alexey Baskakovd05bb012019-03-27 07:06:1718#include "url/gurl.h"
19
20namespace web_app {
21
Anosua Roy18be3752022-01-10 07:16:4522using WebAppInstallInfoFactory =
23 base::RepeatingCallback<std::unique_ptr<WebAppInstallInfo>()>;
Dominic Schulz38238af2020-07-22 02:06:4724
Alexey Baskakov031895272019-07-18 08:19:3325enum class ExternalInstallSource;
Alexey Baskakovd05bb012019-03-27 07:06:1726
Alexey Baskakov0b9a2ee2019-07-22 01:21:2427struct ExternalInstallOptions {
Alan Cutter0cc83732020-09-02 02:26:3628 ExternalInstallOptions(const GURL& install_url,
Eric Willigersd32986ad2019-11-04 00:40:0429 DisplayMode user_display_mode,
Alexey Baskakov0b9a2ee2019-07-22 01:21:2430 ExternalInstallSource install_source);
31 ~ExternalInstallOptions();
32 ExternalInstallOptions(const ExternalInstallOptions& other);
33 ExternalInstallOptions(ExternalInstallOptions&& other);
34 ExternalInstallOptions& operator=(const ExternalInstallOptions& other);
Alexey Baskakovd05bb012019-03-27 07:06:1735
Alexey Baskakov0b9a2ee2019-07-22 01:21:2436 bool operator==(const ExternalInstallOptions& other) const;
Alexey Baskakovd05bb012019-03-27 07:06:1737
Alan Cutter919b4592021-07-08 05:50:4438 base::Value AsDebugValue() const;
39
Alan Cutter0cc83732020-09-02 02:26:3640 GURL install_url;
Eric Willigersd32986ad2019-11-04 00:40:0441 DisplayMode user_display_mode;
Alexey Baskakov031895272019-07-18 08:19:3342 ExternalInstallSource install_source;
Alexey Baskakovd05bb012019-03-27 07:06:1743
Howard Woloskydeaf4d5f2021-02-11 01:20:5944 // App name to use for placeholder apps or web apps that have no name in
45 // their manifest.
Anton Bikineev46bbb972021-05-15 17:53:5346 absl::optional<std::string> fallback_app_name;
Howard Woloskydeaf4d5f2021-02-11 01:20:5947
phweiss5f191ed2022-01-17 10:27:5348 // App name that replaces the app's real name.
49 // override_name takes precedent over fallback_app_name in case both are
phweissade1f322021-09-30 19:18:3450 // present.
phweiss5f191ed2022-01-17 10:27:5351 absl::optional<std::string> override_name;
52
53 // URL of an icon that replaces the app's real icons.
54 absl::optional<GURL> override_icon_url;
phweissade1f322021-09-30 19:18:3455
Giovanni Ortuño Urquidie22f2e12019-04-01 02:43:5156 // If true, a shortcut is added to the Applications folder on macOS, and Start
Giovanni Ortuño Urquidi88971892020-04-17 06:51:2957 // Menu on Linux and Windows and launcher on Chrome OS. If false, we skip
Giovanni Ortuño Urquidie22f2e12019-04-01 02:43:5158 // adding a shortcut to desktop as well, regardless of the value of
59 // |add_to_desktop|.
60 // TODO(ortuno): Make adding a shortcut to the applications menu independent
61 // from adding a shortcut to desktop.
62 bool add_to_applications_menu = true;
63
64 // If true, a shortcut is added to the desktop on Linux and Windows. Has no
65 // effect on macOS and Chrome OS.
66 bool add_to_desktop = true;
67
68 // If true, a shortcut is added to the "quick launch bar" of the OS: the Shelf
69 // for Chrome OS, the Dock for macOS, and the Quick Launch Bar or Taskbar on
70 // Windows. Currently this only works on Chrome OS.
71 bool add_to_quick_launch_bar = true;
Alexey Baskakovd05bb012019-03-27 07:06:1772
Giovanni Ortuño Urquidi88971892020-04-17 06:51:2973 // If true, the app can be searched for on Chrome OS. Has no effect on other
74 // platforms.
75 bool add_to_search = true;
76
77 // If true, the app is shown in App Management on Chrome OS. Has no effect on
78 // other platforms.
79 bool add_to_management = true;
80
Carlos Frias5ddded62020-05-27 23:38:1881 // Whether the app should be registered to run on OS login.
82 // Currently this only works on Windows by adding a shortcut to the
83 // Startup Folder.
84 // TODO(crbug.com/897302): Enable for other platforms.
85 bool run_on_os_login = false;
86
Aya ElAttar14d72a252020-04-21 10:59:1987 // If true, the app icon is displayed on Chrome OS with a blocked logo on
88 // top, and the user cannot launch the app. Has no effect on other platforms.
89 bool is_disabled = false;
90
Alexey Baskakovd05bb012019-03-27 07:06:1791 // Whether the app should be reinstalled even if the user has previously
92 // uninstalled it.
93 bool override_previous_user_uninstall = false;
94
Alan Cutterf30aa0ef2020-11-03 09:24:4095 // Whether the app should only be installed if the user is using Chrome for
96 // the first time.
97 bool only_for_new_users = false;
98
Alexey Baskakovdc0abf1e2021-05-20 04:06:3799 // Whether the app should be omitted for new preinstalls. This is the opposite
100 // of |only_for_new_users| option. It can be used for partial deprecation of
101 // a preinstalled app: do not preinstall the app for new users but leave
102 // existing users unaffected.
103 bool only_if_previously_preinstalled = false;
104
Alan Cutter167ca8042020-11-09 06:27:07105 // Which user types this app should be installed for.
106 // See apps::DetermineUserType() for relevant string constants.
107 std::vector<std::string> user_type_allowlist;
108
109 // Which feature flag should be enabled to install this app. See
Song Fangzhencda4af62021-09-09 05:24:02110 // 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
114 // Whether this should not be installed for devices that support ARC.
115 bool disable_if_arc_supported = false;
116
117 // Whether this should not be installed for tablet devices.
118 bool disable_if_tablet_form_factor = false;
119
Alexey Baskakovd05bb012019-03-27 07:06:17120 // This must only be used by pre-installed default or system apps that are
121 // valid PWAs if loading the real service worker is too costly to verify
122 // programmatically.
123 bool bypass_service_worker_check = false;
124
Alan Cuttera8f043e2021-05-07 07:52:37125 // When set to true this will fail installation with
126 // |kNotValidManifestForWebApp| if the |install_url| doesn't have a manifest
127 // that passes basic validity checks. This is ignored when |app_info_factory|
128 // is used.
Alexey Baskakovd05bb012019-03-27 07:06:17129 bool require_manifest = false;
130
131 // Whether the app should be reinstalled even if it is already installed.
Christopher Lama04e05922019-06-27 06:06:11132 bool force_reinstall = false;
Giovanni Ortuño Urquidic7e719b2019-04-03 01:33:30133
Alexey Baskakovef2601fc2021-01-12 07:05:41134 // Whether we should update the app if the browser's binary milestone number
135 // goes from less the milestone specified to greater or equal than the
136 // milestone specified. For example, if this value is 89 then we update the
137 // app on all browser upgrades from <89 to >=89. The update happens only once.
Anton Bikineev46bbb972021-05-15 17:53:53138 absl::optional<int> force_reinstall_for_milestone;
Alexey Baskakovef2601fc2021-01-12 07:05:41139
Giovanni Ortuño Urquidi68bd2a52019-04-18 12:15:24140 // Whether we should wait for all app windows being closed before reinstalling
141 // the placeholder.
142 bool wait_for_windows_closed = false;
Giovanni Ortuño Urquidib6f4c5e02019-04-16 04:57:56143
Giovanni Ortuño Urquidic7e719b2019-04-03 01:33:30144 // Whether a placeholder app should be installed if we fail to retrieve the
145 // metadata for the app. A placeholder app uses:
146 // - The default Chrome App icon for the icon
147 // - |url| as the start_url
Howard Woloskydeaf4d5f2021-02-11 01:20:59148 // - |url| as the app name (unless fallback_app_name has been specified)
Giovanni Ortuño Urquidic7e719b2019-04-03 01:33:30149 bool install_placeholder = false;
Giovanni Ortuño Urquidib6f4c5e02019-04-16 04:57:56150
151 // Whether we should try to reinstall the app if there is a placeholder for
152 // it.
153 bool reinstall_placeholder = false;
Christopher Lam8cd21342019-08-20 03:57:34154
Alan Cutter35be21052020-09-29 11:37:05155 // Optional query parameters to add to the start_url when launching the app.
Anton Bikineev46bbb972021-05-15 17:53:53156 absl::optional<std::string> launch_query_params;
Alan Cutter35be21052020-09-29 11:37:05157
Alan Cutter464b32c62020-09-16 06:41:37158 // Whether we should load |service_worker_registration_url| after successful
159 // installation to allow the site to install its service worker and set up
160 // offline caching.
161 bool load_and_await_service_worker_registration = true;
162
163 // The URL to use for service worker registration. This is
164 // configurable by sites that wish to be able to track install metrics of the
165 // install_url separate from the service worker registration step. Defaults to
166 // install_url if unset.
Anton Bikineev46bbb972021-05-15 17:53:53167 absl::optional<GURL> service_worker_registration_url;
Alan Cutter464b32c62020-09-16 06:41:37168
Christopher Lam8cd21342019-08-20 03:57:34169 // A list of app_ids that the Web App System should attempt to uninstall and
170 // replace with this app (e.g maintain shelf pins, app list positions).
171 std::vector<AppId> uninstall_and_replace;
Giovanni Ortuño Urquidib73eb2c502020-03-26 23:05:11172
173 // Additional keywords that will be used by the OS when searching for the app.
174 // Only affects Chrome OS.
175 std::vector<std::string> additional_search_terms;
Dominic Schulz38238af2020-07-22 02:06:47176
Alan Cutter2c70a7f2020-09-18 06:50:13177 // Determines whether |app_info_factory| is used as a fallback or the primary
178 // source of app metadata. If true the |install_url| and
179 // |service_worker_registration_url| will not be loaded.
180 bool only_use_app_info_factory = false;
181
Anosua Roy18be3752022-01-10 07:16:45182 // A factory callback that returns a unique_ptr<WebAppInstallInfo> to be used
Alan Cutter2c70a7f2020-09-18 06:50:13183 // as the app's installation metadata.
Anosua Roy18be3752022-01-10 07:16:45184 WebAppInstallInfoFactory app_info_factory;
Dom Schulz7b4bd512021-01-06 23:39:22185
186 // The type of SystemWebApp, if this app is a System Web App.
Anton Bikineev46bbb972021-05-15 17:53:53187 absl::optional<SystemAppType> system_app_type = absl::nullopt;
Tim Sergeant47b94312021-03-17 03:59:50188
189 // Whether the app was installed by an OEM and should be placed in a special
190 // OEM folder in the app launcher. Only used on Chrome OS.
191 bool oem_installed = false;
Jeevan Shikaramab50d8392021-06-01 23:55:10192
193 // Whether this should be installed on devices without a touch screen with
194 // stylus support.
195 bool disable_if_touchscreen_with_stylus_not_supported = false;
jungoog@a30047c2022-01-07 07:46:31196
197 // Whether the app should show up in file-open intent and picking surfaces.
198 bool handles_file_open_intents = false;
Alan Cutter0154fa22022-01-28 05:10:33199
200 // The app id that's expected to be installed from `install_url`.
201 // Does not block installation if the actual app id doesn't match the
202 // expectation.
203 // Intended to be used for post-install activities like metrics and migration.
204 absl::optional<AppId> expected_app_id;
Alexey Baskakovd05bb012019-03-27 07:06:17205};
206
Song Fangzhenafaf6922021-08-12 05:18:02207WebAppInstallParams ConvertExternalInstallOptionsToParams(
Alexey Baskakovc3fa6382019-08-01 01:47:08208 const ExternalInstallOptions& install_options);
209
Alexey Baskakovd05bb012019-03-27 07:06:17210} // namespace web_app
211
Song Fangzhencda4af62021-09-09 05:24:02212#endif // CHROME_BROWSER_WEB_APPLICATIONS_EXTERNAL_INSTALL_OPTIONS_H_