Commit b60b2638 authored by nancy's avatar nancy Committed by Commit Bot

Add Crostini uninstall dialog view.

BUG=1009248

Change-Id: I15e467a7efdaf88967f9d40ef48033a6605c6d86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862870
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706845}
parent 9e33cf41
......@@ -8,6 +8,7 @@
#include "chrome/browser/apps/app_service/dip_px_util.h"
#include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/crostini/crostini_package_service.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_registry_service_factory.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
......@@ -159,7 +160,8 @@ void CrostiniApps::PromptUninstall(const std::string& app_id) {
void CrostiniApps::Uninstall(const std::string& app_id,
bool clear_site_data,
bool report_abuse) {
NOTIMPLEMENTED();
crostini::CrostiniPackageService::GetForProfile(profile_)
->QueueUninstallApplication(app_id);
}
void CrostiniApps::OpenNativeSettings(const std::string& app_id) {
......
......@@ -19,18 +19,21 @@ namespace apps {
UninstallDialog::UninstallDialog(Profile* profile,
apps::mojom::AppType app_type,
const std::string& app_id,
const std::string& app_name,
apps::mojom::IconKeyPtr icon_key,
apps::IconLoader* icon_loader,
UninstallCallback uninstall_callback)
: profile_(profile),
app_type_(app_type),
app_id_(app_id),
app_name_(app_name),
uninstall_callback_(std::move(uninstall_callback)) {
int32_t size_hint_in_dip;
switch (app_type) {
case apps::mojom::AppType::kCrostini:
// Crostini uninstall dialog doesn't show the icon.
UiBase::Create(profile_, app_type_, app_id_, gfx::ImageSkia(), this);
UiBase::Create(profile_, app_type_, app_id_, app_name, gfx::ImageSkia(),
this);
return;
case apps::mojom::AppType::kArc:
// Currently ARC apps only support 48*48 native icon.
......@@ -68,7 +71,8 @@ void UninstallDialog::OnLoadIcon(apps::mojom::IconValuePtr icon_value) {
return;
}
UiBase::Create(profile_, app_type_, app_id_, icon_value->uncompressed, this);
UiBase::Create(profile_, app_type_, app_id_, app_name_,
icon_value->uncompressed, this);
}
} // namespace apps
......@@ -55,6 +55,7 @@ class UninstallDialog {
static void Create(Profile* profile,
apps::mojom::AppType app_type,
const std::string& app_id,
const std::string& app_name,
gfx::ImageSkia image,
UninstallDialog* uninstall_dialog);
......@@ -82,6 +83,7 @@ class UninstallDialog {
UninstallDialog(Profile* profile,
apps::mojom::AppType app_type,
const std::string& app_id,
const std::string& app_name,
apps::mojom::IconKeyPtr icon_key,
IconLoader* icon_loader,
UninstallCallback uninstall_callback);
......@@ -98,6 +100,7 @@ class UninstallDialog {
Profile* profile_;
apps::mojom::AppType app_type_;
const std::string app_id_;
const std::string app_name_;
UninstallCallback uninstall_callback_;
base::WeakPtrFactory<UninstallDialog> weak_ptr_factory_{this};
......
......@@ -33,9 +33,10 @@ void apps::UninstallDialog::UiBase::Create(
Profile* profile,
apps::mojom::AppType app_type,
const std::string& app_id,
const std::string& app_name,
gfx::ImageSkia image,
apps::UninstallDialog* uninstall_dialog) {
new AppUninstallDialogView(profile, app_type, app_id, image,
new AppUninstallDialogView(profile, app_type, app_id, app_name, image,
uninstall_dialog);
}
......@@ -43,11 +44,13 @@ AppUninstallDialogView::AppUninstallDialogView(
Profile* profile,
apps::mojom::AppType app_type,
const std::string& app_id,
const std::string& app_name,
gfx::ImageSkia image,
apps::UninstallDialog* uninstall_dialog)
: apps::UninstallDialog::UiBase(image, uninstall_dialog),
BubbleDialogDelegateView(nullptr, views::BubbleBorder::NONE),
app_type_(app_type) {
app_type_(app_type),
app_name_(app_name) {
InitializeView(profile, app_id);
constrained_window::CreateBrowserModalDialogViews(this, nullptr)->Show();
}
......@@ -89,7 +92,28 @@ gfx::ImageSkia AppUninstallDialogView::GetWindowIcon() {
}
base::string16 AppUninstallDialogView::GetWindowTitle() const {
return window_title_;
switch (app_type_) {
case apps::mojom::AppType::kUnknown:
case apps::mojom::AppType::kBuiltIn:
NOTREACHED();
return base::string16();
case apps::mojom::AppType::kArc:
return l10n_util::GetStringUTF16(
shortcut_ ? IDS_EXTENSION_UNINSTALL_PROMPT_TITLE
: IDS_APP_UNINSTALL_PROMPT_TITLE);
case apps::mojom::AppType::kCrostini:
#if defined(OS_CHROMEOS)
return l10n_util::GetStringUTF16(
IDS_CROSTINI_APPLICATION_UNINSTALL_CONFIRM_TITLE);
#else
NOTREACHED();
return base::string16();
#endif
case apps::mojom::AppType::kExtension:
case apps::mojom::AppType::kWeb:
return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_TITLE,
base::UTF8ToUTF16(app_name_));
}
}
bool AppUninstallDialogView::ShouldShowCloseButton() const {
......@@ -114,6 +138,10 @@ void AppUninstallDialogView::AddMultiLineLabel(
void AppUninstallDialogView::InitializeViewForExtension(
Profile* profile,
const std::string& app_id) {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, gfx::Insets(),
......@@ -129,10 +157,6 @@ void AppUninstallDialogView::InitializeViewForExtension(
app_id);
DCHECK(extension);
window_title_ =
l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_TITLE,
base::UTF8ToUTF16(extension->name()));
if (extensions::ManifestURL::UpdatesFromGallery(extension)) {
auto report_abuse_checkbox = std::make_unique<views::Checkbox>(
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_REPORT_ABUSE));
......@@ -168,16 +192,14 @@ void AppUninstallDialogView::InitializeViewForArcApp(
arc_prefs->GetApp(app_id);
DCHECK(arc_prefs);
window_title_ = l10n_util::GetStringUTF16(
app_info->shortcut ? IDS_EXTENSION_UNINSTALL_PROMPT_TITLE
: IDS_APP_UNINSTALL_PROMPT_TITLE);
shortcut_ = app_info->shortcut;
base::string16 heading_text = l10n_util::GetStringFUTF16(
app_info->shortcut ? IDS_EXTENSION_UNINSTALL_PROMPT_HEADING
: IDS_NON_PLATFORM_APP_UNINSTALL_PROMPT_HEADING,
base::UTF8ToUTF16(app_info->name));
shortcut_ ? IDS_EXTENSION_UNINSTALL_PROMPT_HEADING
: IDS_NON_PLATFORM_APP_UNINSTALL_PROMPT_HEADING,
base::UTF8ToUTF16(app_name_));
base::string16 subheading_text;
if (!app_info->shortcut) {
if (!shortcut_) {
subheading_text = l10n_util::GetStringUTF16(
IDS_ARC_APP_UNINSTALL_PROMPT_DATA_REMOVAL_WARNING);
}
......@@ -186,6 +208,10 @@ void AppUninstallDialogView::InitializeViewForArcApp(
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_APP_BUTTON));
} else {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
}
auto* icon_view = AddChildView(std::make_unique<views::ImageView>());
......@@ -207,6 +233,27 @@ void AppUninstallDialogView::InitializeViewForArcApp(
if (!subheading_text.empty())
AddMultiLineLabel(text_container, subheading_text);
}
void AppUninstallDialogView::InitializeViewForCrostiniApp(
Profile* profile,
const std::string& app_id) {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_APP_BUTTON));
views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
provider->GetDialogInsetsForContentType(views::TEXT, views::TEXT),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
base::string16 message = l10n_util::GetStringFUTF16(
IDS_CROSTINI_APPLICATION_UNINSTALL_CONFIRM_BODY,
base::UTF8ToUTF16(app_name_));
auto* message_label = AddChildView(std::make_unique<views::Label>(message));
message_label->SetMultiLine(true);
message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
}
#endif
void AppUninstallDialogView::InitializeView(Profile* profile,
......@@ -219,10 +266,16 @@ void AppUninstallDialogView::InitializeView(Profile* profile,
case apps::mojom::AppType::kArc:
#if defined(OS_CHROMEOS)
InitializeViewForArcApp(profile, app_id);
#else
NOTREACHED();
#endif
break;
case apps::mojom::AppType::kCrostini:
#if defined(OS_CHROMEOS)
InitializeViewForCrostiniApp(profile, app_id);
#else
NOTREACHED();
#endif
break;
case apps::mojom::AppType::kExtension:
case apps::mojom::AppType::kWeb:
......
......@@ -39,8 +39,7 @@ class ImageSkia;
// AppService, which transfers control to the publisher to uninstall the app.
//
// TODO(crbug.com/1009248):
// 1. Add Crostini uninstall function.
// 2. Add an interface to the uninstall, like what is done by
// 1. Add an interface to the uninstall, like what is done by
// extension_uninstall_dialog_->ConfirmUninstallByExtension.
class AppUninstallDialogView : public apps::UninstallDialog::UiBase,
views::BubbleDialogDelegateView {
......@@ -48,6 +47,7 @@ class AppUninstallDialogView : public apps::UninstallDialog::UiBase,
AppUninstallDialogView(Profile* profile,
apps::mojom::AppType app_type,
const std::string& app_id,
const std::string& app_name,
gfx::ImageSkia image,
apps::UninstallDialog* uninstall_dialog);
~AppUninstallDialogView() override = default;
......@@ -68,19 +68,25 @@ class AppUninstallDialogView : public apps::UninstallDialog::UiBase,
void InitializeViewForExtension(Profile* profile, const std::string& app_id);
#if defined(OS_CHROMEOS)
void InitializeViewForArcApp(Profile* profile, const std::string& app_id);
void InitializeViewForCrostiniApp(Profile* profile,
const std::string& app_id);
#endif
void InitializeView(Profile* profile,
const std::string& app_id);
// The type of apps, e.g. Extension-backed app, Android app.
apps::mojom::AppType app_type_;
// The name of apps, e.g. Camera.
const std::string app_name_;
// Whether app represents a shortcut. |shortcut_| is available for the ARC
// apps only.
bool shortcut_ = false;
views::Checkbox* report_abuse_checkbox_ = nullptr;
views::Checkbox* clear_site_data_checkbox_ = nullptr;
// TODO(crbug.com/1009248): Remove these fields to use the consistent title
// and button.
base::string16 window_title_;
DISALLOW_COPY_AND_ASSIGN(AppUninstallDialogView);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment