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
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/api/management/chrome_management_api_delegate.h"
#include <memory>
#include <string>
#include <utility>
#include "chrome/browser/extensions/chrome_extension_function_details.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "extensions/browser/api/management/management_api.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/mojom/context_type.mojom.h"
namespace extensions {
namespace {
class ManagementUninstallFunctionUninstallDialogDelegate
: public ExtensionUninstallDialog::Delegate,
public UninstallDialogDelegate {
public:
ManagementUninstallFunctionUninstallDialogDelegate(
ManagementUninstallFunctionBase* function,
const Extension* target_extension,
bool show_programmatic_uninstall_ui)
: function_(function) {
ChromeExtensionFunctionDetails details(function);
extension_uninstall_dialog_ = ExtensionUninstallDialog::Create(
Profile::FromBrowserContext(function->browser_context()),
details.GetNativeWindowForUI(), this);
bool uninstall_from_webstore =
(function->extension() &&
function->extension()->id() == kWebStoreAppId) ||
function->source_url().DomainIs(
extension_urls::GetNewWebstoreLaunchURL().host());
UninstallSource source;
UninstallReason reason;
if (uninstall_from_webstore) {
source = UNINSTALL_SOURCE_CHROME_WEBSTORE;
reason = UNINSTALL_REASON_CHROME_WEBSTORE;
} else if (function->source_context_type() == mojom::ContextType::kWebUi) {
source = UNINSTALL_SOURCE_CHROME_EXTENSIONS_PAGE;
// TODO: Update this to a new reason; it shouldn't be lumped in with
// other uninstalls if it's from the chrome://extensions page.
reason = UNINSTALL_REASON_MANAGEMENT_API;
} else {
source = UNINSTALL_SOURCE_EXTENSION;
reason = UNINSTALL_REASON_MANAGEMENT_API;
}
if (show_programmatic_uninstall_ui) {
extension_uninstall_dialog_->ConfirmUninstallByExtension(
target_extension, function->extension(), reason, source);
} else {
extension_uninstall_dialog_->ConfirmUninstall(target_extension, reason,
source);
}
}
ManagementUninstallFunctionUninstallDialogDelegate(
const ManagementUninstallFunctionUninstallDialogDelegate&) = delete;
ManagementUninstallFunctionUninstallDialogDelegate& operator=(
const ManagementUninstallFunctionUninstallDialogDelegate&) = delete;
~ManagementUninstallFunctionUninstallDialogDelegate() override = default;
// ExtensionUninstallDialog::Delegate implementation.
void OnExtensionUninstallDialogClosed(bool did_start_uninstall,
const std::u16string& error) override {
function_->OnExtensionUninstallDialogClosed(did_start_uninstall, error);
}
private:
raw_ptr<ManagementUninstallFunctionBase> function_;
std::unique_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_;
};
} // namespace
std::unique_ptr<UninstallDialogDelegate>
ChromeManagementAPIDelegate::UninstallFunctionDelegate(
ManagementUninstallFunctionBase* function,
const Extension* target_extension,
bool show_programmatic_uninstall_ui) const {
return std::make_unique<ManagementUninstallFunctionUninstallDialogDelegate>(
function, target_extension, show_programmatic_uninstall_ui);
}
} // namespace extensions
|