#include "chrome/browser/extensions/api/management/chrome_management_api_delegate.h"
#include <memory>
#include <utility>
#include "base/check_is_test.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/browser_app_launcher.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/extensions/manifest_v2_experiment_manager.h"
#include "chrome/browser/extensions/mv2_experiment_stage.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/extensions_dialogs.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/tab_helpers.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/web_applications/extension_status_utils.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_install_manager.h"
#include "chrome/browser/web_applications/web_app_install_params.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/extension_metrics.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "components/favicon/core/favicon_service.h"
#include "components/security_state/content/security_state_tab_helper.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/browser/installable/installable_manager.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/api/management/management_api.h"
#include "extensions/browser/api/management/management_api_constants.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/supervised_user_extensions_delegate.h"
#include "extensions/common/api/management.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
#include "third_party/blink/public/mojom/window_features/window_features.mojom.h"
namespace {
InstallOrLaunchWebAppCallback;
InstallOrLaunchWebAppResult;
InstallableCheckResult;
class ManagementSetEnabledFunctionInstallPromptDelegate
: public extensions::InstallPromptDelegate { … };
class ManagementUninstallFunctionUninstallDialogDelegate
: public extensions::ExtensionUninstallDialog::Delegate,
public extensions::UninstallDialogDelegate { … };
void OnGenerateAppForLinkCompleted(
extensions::ManagementGenerateAppForLinkFunction* function,
const webapps::AppId& app_id,
webapps::InstallResultCode code) { … }
class ChromeAppForLinkDelegate : public extensions::AppForLinkDelegate { … };
void LaunchWebApp(const webapps::AppId& app_id, Profile* profile) { … }
void OnWebAppInstallCompleted(InstallOrLaunchWebAppCallback callback,
const webapps::AppId& app_id,
webapps::InstallResultCode code) { … }
void OnWebAppInstallabilityChecked(
base::WeakPtr<Profile> profile,
InstallOrLaunchWebAppCallback callback,
std::unique_ptr<content::WebContents> web_contents,
InstallableCheckResult result,
std::optional<webapps::AppId> app_id) { … }
extensions::SupervisedUserExtensionsDelegate*
GetSupervisedUserExtensionsDelegateFromContext(
content::BrowserContext* context) { … }
}
ChromeManagementAPIDelegate::ChromeManagementAPIDelegate() = default;
ChromeManagementAPIDelegate::~ChromeManagementAPIDelegate() = default;
bool ChromeManagementAPIDelegate::LaunchAppFunctionDelegate(
const extensions::Extension* extension,
content::BrowserContext* context) const { … }
GURL ChromeManagementAPIDelegate::GetFullLaunchURL(
const extensions::Extension* extension) const { … }
extensions::LaunchType ChromeManagementAPIDelegate::GetLaunchType(
const extensions::ExtensionPrefs* prefs,
const extensions::Extension* extension) const { … }
std::unique_ptr<extensions::InstallPromptDelegate>
ChromeManagementAPIDelegate::SetEnabledFunctionDelegate(
content::WebContents* web_contents,
content::BrowserContext* browser_context,
const extensions::Extension* extension,
base::OnceCallback<void(bool)> callback) const { … }
std::unique_ptr<extensions::UninstallDialogDelegate>
ChromeManagementAPIDelegate::UninstallFunctionDelegate(
extensions::ManagementUninstallFunctionBase* function,
const extensions::Extension* target_extension,
bool show_programmatic_uninstall_ui) const { … }
bool ChromeManagementAPIDelegate::CreateAppShortcutFunctionDelegate(
extensions::ManagementCreateAppShortcutFunction* function,
const extensions::Extension* extension,
std::string* error) const { … }
std::unique_ptr<extensions::AppForLinkDelegate>
ChromeManagementAPIDelegate::GenerateAppForLinkFunctionDelegate(
extensions::ManagementGenerateAppForLinkFunction* function,
content::BrowserContext* context,
const std::string& title,
const GURL& launch_url) const { … }
bool ChromeManagementAPIDelegate::CanContextInstallWebApps(
content::BrowserContext* context) const { … }
void ChromeManagementAPIDelegate::InstallOrLaunchReplacementWebApp(
content::BrowserContext* context,
const GURL& web_app_url,
InstallOrLaunchWebAppCallback callback) const { … }
void ChromeManagementAPIDelegate::EnableExtension(
content::BrowserContext* context,
const extensions::ExtensionId& extension_id) const { … }
void ChromeManagementAPIDelegate::DisableExtension(
content::BrowserContext* context,
const extensions::Extension* source_extension,
const extensions::ExtensionId& extension_id,
extensions::disable_reason::DisableReason disable_reason) const { … }
bool ChromeManagementAPIDelegate::UninstallExtension(
content::BrowserContext* context,
const extensions::ExtensionId& transient_extension_id,
extensions::UninstallReason reason,
std::u16string* error) const { … }
void ChromeManagementAPIDelegate::SetLaunchType(
content::BrowserContext* context,
const extensions::ExtensionId& extension_id,
extensions::LaunchType launch_type) const { … }
GURL ChromeManagementAPIDelegate::GetIconURL(
const extensions::Extension* extension,
int icon_size,
ExtensionIconSet::Match match,
bool grayscale) const { … }
GURL ChromeManagementAPIDelegate::GetEffectiveUpdateURL(
const extensions::Extension& extension,
content::BrowserContext* context) const { … }
void ChromeManagementAPIDelegate::ShowMv2DeprecationReEnableDialog(
content::BrowserContext* context,
content::WebContents* web_contents,
const extensions::Extension& extension,
base::OnceCallback<void(bool)> done_callback) const { … }