File: web_app_dialogs.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (220 lines) | stat: -rw-r--r-- 9,161 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_DIALOGS_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_DIALOGS_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/auto_reset.h"
#include "base/functional/callback.h"
#include "build/build_config.h"
#include "chrome/browser/web_applications/web_app_callback_app_identity.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_uninstall_dialog_user_options.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/gfx/native_widget_types.h"

static_assert(BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) ||
              BUILDFLAG(IS_CHROMEOS));

class GURL;
class Profile;
class Browser;

namespace base {
class FilePath;
}

namespace content {
class WebContents;
}

namespace webapps {
class MlInstallOperationTracker;
enum class WebappUninstallSource;
}  // namespace webapps

namespace web_app {

class IsolatedWebAppInstallerCoordinator;
class WebAppScreenshotFetcher;
struct WebAppInstallInfo;

// Callback used to indicate whether a user has accepted the installation of a
// web app. The boolean parameter is true when the user accepts the dialog. The
// WebAppInstallInfo parameter contains the information about the app,
// possibly modified by the user.
using AppInstallationAcceptanceCallback =
    base::OnceCallback<void(bool, std::unique_ptr<WebAppInstallInfo>)>;

// Shows the Create Shortcut confirmation dialog.
//
// |web_app_info| is the WebAppInstallInfo being converted into an app.
void ShowCreateShortcutDialog(
    content::WebContents* web_contents,
    std::unique_ptr<WebAppInstallInfo> web_app_info,
    std::unique_ptr<webapps::MlInstallOperationTracker> install_tracker,
    AppInstallationAcceptanceCallback callback);

// When an app changes its icon or name, that is considered an app identity
// change which (for some types of apps) needs confirmation from the user.
// This function shows that confirmation dialog. |app_id| is the unique id of
// the app that is updating and |title_change| and |icon_change| specify which
// piece of information is changing. Can be one or the other, or both (but
// both cannot be |false|). |old_title| and |new_title|, as well as |old_icon|
// and |new_icon| show the 'before' and 'after' values. A response is sent
// back via the |callback|.
void ShowWebAppIdentityUpdateDialog(const std::string& app_id,
                                    bool title_change,
                                    bool icon_change,
                                    const std::u16string& old_title,
                                    const std::u16string& new_title,
                                    const SkBitmap& old_icon,
                                    const SkBitmap& new_icon,
                                    content::WebContents* web_contents,
                                    AppIdentityDialogCallback callback);

// Shows the web app uninstallation dialog on a page whenever user has decided
// to uninstall an installed dPWA from a variety of OS surfaces and chrome.
void ShowWebAppUninstallDialog(
    Profile* profile,
    const webapps::AppId& app_id,
    webapps::WebappUninstallSource uninstall_source,
    gfx::NativeWindow parent,
    std::map<SquareSizePx, SkBitmap> icon_bitmaps,
    UninstallDialogCallback uninstall_dialog_result_callback);

// Callback used to indicate whether a user has accepted the launch of a
// web app. The |allowed| is true when the user allows the app to launch.
// |remember_user_choice| is true if the user wants to persist the decision.
using WebAppLaunchAcceptanceCallback =
    base::OnceCallback<void(bool allowed, bool remember_user_choice)>;

// Shows the pre-launch dialog for protocol handling PWA launch. The user can
// allow or block the launch.
void ShowWebAppProtocolLaunchDialog(
    const GURL& url,
    Profile* profile,
    const webapps::AppId& app_id,
    WebAppLaunchAcceptanceCallback close_callback);

// Shows the pre-launch dialog for a file handling PWA launch. The user can
// allow or block the launch.
void ShowWebAppFileLaunchDialog(const std::vector<base::FilePath>& file_paths,
                                Profile* profile,
                                const webapps::AppId& app_id,
                                WebAppLaunchAcceptanceCallback close_callback);
// Sets whether |ShowWebAppDialog| should accept immediately without any
// user interaction. |auto_open_in_window| sets whether the open in window
// checkbox is checked.
void SetAutoAcceptWebAppDialogForTesting(bool auto_accept,
                                         bool auto_open_in_window);

// Sets an override title for the Create Shortcut confirmation view.
void SetOverrideTitleForTesting(const char* title_to_use);

// Describes the state of in-product-help being shown to the user.
enum class PwaInProductHelpState {
  // The in-product-help bubble was shown.
  kShown,
  // The in-product-help bubble was not shown.
  kNotShown
};

DECLARE_ELEMENT_IDENTIFIER_VALUE(kSimpleInstallDialogAppTitle);
DECLARE_ELEMENT_IDENTIFIER_VALUE(kSimpleInstallDialogIconView);
DECLARE_ELEMENT_IDENTIFIER_VALUE(kSimpleInstallDialogOriginLabel);

// Shows the PWA installation confirmation bubble anchored off the PWA install
// icon in the omnibox.
//
// |web_app_info| is the WebAppInstallInfo to be installed.
// |callback| is called when install bubble closed.
// |iph_state| records whether PWA install iph is shown before Install bubble is
// shown.
void ShowSimpleInstallDialogForWebApps(
    content::WebContents* web_contents,
    std::unique_ptr<WebAppInstallInfo> web_app_info,
    std::unique_ptr<webapps::MlInstallOperationTracker> install_tracker,
    AppInstallationAcceptanceCallback callback,
    PwaInProductHelpState iph_state = PwaInProductHelpState::kNotShown);

// Shows the PWA install dialog for apps that are not installable, AKA, DIY
// apps.
void ShowDiyAppInstallDialog(
    content::WebContents* web_contents,
    std::unique_ptr<WebAppInstallInfo> web_app_info,
    std::unique_ptr<webapps::MlInstallOperationTracker> install_tracker,
    AppInstallationAcceptanceCallback callback,
    PwaInProductHelpState iph_state = PwaInProductHelpState::kNotShown);

DECLARE_ELEMENT_IDENTIFIER_VALUE(kDetailedInstallDialogImageContainer);

// Shows the Web App detailed install dialog.
// The dialog shows app's detailed information including screenshots. Users then
// confirm or cancel install in this dialog.
void ShowWebAppDetailedInstallDialog(
    content::WebContents* web_contents,
    std::unique_ptr<WebAppInstallInfo> web_app_info,
    std::unique_ptr<webapps::MlInstallOperationTracker> install_tracker,
    AppInstallationAcceptanceCallback callback,
    base::WeakPtr<WebAppScreenshotFetcher> screenshot_fetcher,
    PwaInProductHelpState iph_state = PwaInProductHelpState::kNotShown);

// Sets whether |ShowSimpleInstallDialogForWebApps| should accept immediately
// without any user interaction.
base::AutoReset<bool> SetAutoAcceptPWAInstallConfirmationForTesting();

// Sets whether |ShowDiyInstallDialogForWebApps| should accept immediately
// without any user interaction.
void SetAutoAcceptDiyAppsInstallDialogForTesting(bool auto_accept);

// Sets whether the bubble should close when it is not in an active window
// during testing.
base::AutoReset<bool> SetDontCloseOnDeactivateForTesting();

// Shows the Isolated Web App manual install wizard.
IsolatedWebAppInstallerCoordinator* LaunchIsolatedWebAppInstaller(
    Profile* profile,
    const base::FilePath& bundle_path,
    base::OnceClosure on_closed_callback);

void FocusIsolatedWebAppInstaller(
    IsolatedWebAppInstallerCoordinator* coordinator);

void PostCallbackOnBrowserActivation(
    const Browser* browser,
    ui::ElementIdentifier id,
    base::OnceCallback<void(bool)> view_and_element_activated_callback);

// Callback used by the Web Install API to indicate whether the user has
// accepted the launch of a web app.
using WebInstallAppLaunchAcceptanceCallback =
    base::OnceCallback<void(bool accepted)>;

DECLARE_ELEMENT_IDENTIFIER_VALUE(kWebInstallLaunchDialogAppName);

// Shows a web app launch dialog for `app_id`. Used by the Web Install API. The
// dialog contains the app short name and icon, just like the intent picker. The
// user can accept or cancel the launch. A response is sent via `callback` so
// the service implementation can resolve itself based on the user
// interaction.
void ShowWebInstallAppLaunchDialog(
    content::WebContents* web_contents,
    const webapps::AppId& app_id,
    Profile* profile,
    std::string app_name,
    WebInstallAppLaunchAcceptanceCallback callback);

// Sets whether |ShowWebInstallAppLaunchDialog| should accept immediately.
base::AutoReset<bool> SetAutoAcceptWebInstallLaunchDialogForTesting();

}  // namespace web_app

#endif  // CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_DIALOGS_H_