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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
// Copyright 2019 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_UI_MANAGER_IMPL_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_UI_MANAGER_IMPL_H_
#include <stddef.h>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_multi_source_observation.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.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_ui_manager.h"
#include "chrome/browser/web_applications/web_app_uninstall_dialog_user_options.h"
#include "components/user_education/common/feature_promo/feature_promo_result.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/native_widget_types.h"
class Browser;
class BrowserWindow;
class Profile;
class SkBitmap;
namespace apps {
struct AppLaunchParams;
}
namespace base {
class FilePath;
}
namespace views {
class NativeWindowTracker;
} // namespace views
namespace webapps {
enum class WebappUninstallSource;
}
namespace web_app {
class IsolatedWebAppInstallerCoordinator;
class WithAppResources;
// Implementation of WebAppUiManager that depends upon //c/b/ui.
// Allows //c/b/web_applications code to call into //c/b/ui without directly
// depending on UI.
class WebAppUiManagerImpl : public BrowserListObserver,
public WebAppUiManager,
public TabStripModelObserver {
public:
explicit WebAppUiManagerImpl(Profile* profile);
WebAppUiManagerImpl(const WebAppUiManagerImpl&) = delete;
WebAppUiManagerImpl& operator=(const WebAppUiManagerImpl&) = delete;
~WebAppUiManagerImpl() override;
void Start() override;
void Shutdown() override;
// WebAppUiManager:
WebAppUiManagerImpl* AsImpl() override;
size_t GetNumWindowsForApp(const webapps::AppId& app_id) override;
void CloseAppWindows(const webapps::AppId& app_id) override;
void NotifyOnAllAppWindowsClosed(const webapps::AppId& app_id,
base::OnceClosure callback) override;
bool CanAddAppToQuickLaunchBar() const override;
void AddAppToQuickLaunchBar(const webapps::AppId& app_id) override;
bool IsAppInQuickLaunchBar(const webapps::AppId& app_id) const override;
bool CanReparentAppTabToWindow(
const webapps::AppId& app_id,
bool shortcut_created,
content::WebContents* web_contents) const override;
Browser* ReparentAppTabToWindow(content::WebContents* contents,
const webapps::AppId& app_id,
bool shortcut_created) override;
Browser* ReparentAppTabToWindow(
content::WebContents* contents,
const webapps::AppId& app_id,
base::OnceCallback<void(content::WebContents*)> completion_callback)
override;
void ShowWebAppFileLaunchDialog(
const std::vector<base::FilePath>& file_paths,
const webapps::AppId& app_id,
WebAppLaunchAcceptanceCallback launch_callback) override;
void ShowWebAppProtocolLaunchDialog(
const GURL& protocol_url,
const webapps::AppId& app_id,
WebAppLaunchAcceptanceCallback launch_callback) override;
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,
web_app::AppIdentityDialogCallback callback) override;
void ShowWebAppSettings(const webapps::AppId& app_id) override;
void LaunchWebApp(apps::AppLaunchParams params,
LaunchWebAppWindowSetting launch_setting,
Profile& profile,
LaunchWebAppDebugValueCallback callback,
WithAppResources& lock) override;
void WaitForFirstRunService(
Profile& profile,
FirstRunServiceCompletedCallback callback) override;
#if BUILDFLAG(IS_CHROMEOS)
void MigrateLauncherState(const webapps::AppId& from_app_id,
const webapps::AppId& to_app_id,
base::OnceClosure callback) override;
void DisplayRunOnOsLoginNotification(
const base::flat_map<webapps::AppId, RoolNotificationBehavior>& apps,
base::WeakPtr<Profile> profile) override;
#endif // BUILDFLAG(IS_CHROMEOS)
void NotifyAppRelaunchState(const webapps::AppId& placeholder_app_id,
const webapps::AppId& final_app_id,
const std::u16string& final_app_name,
base::WeakPtr<Profile> profile,
AppRelaunchState relaunch_state) override;
content::WebContents* CreateNewTab() override;
bool IsWebContentsActiveTabInBrowser(
content::WebContents* web_contents) override;
void TriggerInstallDialog(content::WebContents* web_contents,
webapps::WebappInstallSource source,
InstallCallback callback) override;
void TriggerInstallDialogForBackgroundInstall(
content::WebContents* initiating_web_contents,
std::unique_ptr<webapps::MlInstallOperationTracker> tracker,
const GURL& install_url,
const std::optional<GURL>& manifest_id,
InstallCallback callback) override;
void TriggerLaunchDialogForBackgroundInstall(
content::WebContents* initiating_web_contents,
const webapps::AppId& app_id,
Profile* profile,
const std::string& app_name,
WebInstallAppLaunchAcceptanceCallback callback) override;
void PresentUserUninstallDialog(
const webapps::AppId& app_id,
webapps::WebappUninstallSource uninstall_source,
BrowserWindow* parent_window,
UninstallCompleteCallback callback) override;
void PresentUserUninstallDialog(
const webapps::AppId& app_id,
webapps::WebappUninstallSource uninstall_source,
gfx::NativeWindow parent_window,
UninstallCompleteCallback callback) override;
void PresentUserUninstallDialog(
const webapps::AppId& app_id,
webapps::WebappUninstallSource uninstall_source,
gfx::NativeWindow parent_window,
UninstallCompleteCallback callback,
UninstallScheduledCallback scheduled_callback) override;
void ShowIntentPicker(const GURL& url,
content::WebContents* web_contents,
ShowIntentPickerBubbleCallback callback) override;
void LaunchOrFocusIsolatedWebAppInstaller(
const base::FilePath& bundle_path) override;
void MaybeCreateEnableSupportedLinksInfobar(
content::WebContents* web_contents,
const std::string& launch_name) override;
void MaybeShowIPHPromoForAppsLaunchedViaLinkCapturing(
Browser* browser,
Profile* profile,
const std::string& app_id) override;
// BrowserListObserver:
void OnBrowserAdded(Browser* browser) override;
#if BUILDFLAG(IS_CHROMEOS)
void OnBrowserCloseCancelled(Browser* browser,
BrowserClosingStatus reason) override;
#endif // BUILDFLAG(IS_CHROMEOS)
void OnBrowserRemoved(Browser* browser) override;
#if BUILDFLAG(IS_CHROMEOS)
// TabStripModelObserver:
void TabCloseCancelled(const content::WebContents* contents) override;
#endif // BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_WIN)
// Attempts to uninstall the given web app id. Meant to be used with OS-level
// uninstallation support/hooks.
void UninstallWebAppFromStartupSwitch(const webapps::AppId& app_id);
#endif
private:
// Returns true if Browser is for an installed App.
bool IsBrowserForInstalledApp(Browser* browser);
// Returns webapps::AppId of the Browser's installed App,
// |IsBrowserForInstalledApp| must be true.
webapps::AppId GetAppIdForBrowser(Browser* browser);
void OnExtensionSystemReady();
void OnIconsReadForUninstall(
const webapps::AppId& app_id,
webapps::WebappUninstallSource uninstall_source,
gfx::NativeWindow parent_window,
std::unique_ptr<views::NativeWindowTracker> parent_window_tracker,
UninstallCompleteCallback complete_callback,
UninstallScheduledCallback uninstall_scheduled_callback,
std::map<SquareSizePx, SkBitmap> icon_bitmaps);
void OnIsolatedWebAppInstallerClosed(base::FilePath bundle_path);
void ScheduleUninstallIfUserRequested(
const webapps::AppId& app_id,
webapps::WebappUninstallSource uninstall_source,
UninstallCompleteCallback complete_callback,
UninstallScheduledCallback uninstall_scheduled_callback,
web_app::UninstallUserOptions uninstall_options);
void OnUninstallCancelled(
UninstallCompleteCallback complete_callback,
UninstallScheduledCallback uninstall_scheduled_callback);
void ClearWebAppSiteDataIfNeeded(
const GURL app_start_url,
UninstallCompleteCallback uninstall_complete_callback,
webapps::UninstallResultCode uninstall_code);
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
void ShowIPHPromoForAppsLaunchedViaLinkCapturing(const Browser* browser,
const webapps::AppId& app_id,
bool is_activated);
void OnIPHPromoResponseForLinkCapturing(const Browser* browser,
const webapps::AppId& app_id);
void OnTabChangedDuringIph(const Browser* browser);
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
const raw_ptr<Profile> profile_;
std::map<webapps::AppId, std::vector<base::OnceClosure>>
windows_closed_requests_map_;
std::map<webapps::AppId, size_t> num_windows_for_apps_map_;
std::map<base::FilePath, raw_ptr<IsolatedWebAppInstallerCoordinator>>
active_installers_;
bool started_ = false;
base::WeakPtrFactory<WebAppUiManagerImpl> weak_ptr_factory_{this};
};
} // namespace web_app
#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_UI_MANAGER_IMPL_H_
|