Commit de2e1bae authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cbuiv apps: use new widget/dialog setters

This change:
* Migrates AppBlockDialogView to use SetTitle
* Migrates AppDialogView to use SetIcon, SetShowCloseButton, and
  SetShowIcon
* Migrates AppPauseDialogView to use SetTitle and SetAcceptCallback
* Migrates AppUninstallDialogView to use SetTitle
* Removes many now-unneeded member variables from these classes

Bug: 1075649
Change-Id: Ifd8df11b87f77a3b337394c20a7c2b6dd638f7dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250508
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779905}
parent 0f02ee54
...@@ -33,7 +33,10 @@ void AppServiceProxy::CreateBlockDialog(const std::string& app_name, ...@@ -33,7 +33,10 @@ void AppServiceProxy::CreateBlockDialog(const std::string& app_name,
AppBlockDialogView::AppBlockDialogView(const std::string& app_name, AppBlockDialogView::AppBlockDialogView(const std::string& app_name,
const gfx::ImageSkia& image, const gfx::ImageSkia& image,
Profile* profile) Profile* profile)
: AppDialogView(app_name, image) { : AppDialogView(image) {
SetTitle(l10n_util::GetStringFUTF16(IDS_APP_BLOCK_PROMPT_TITLE,
base::UTF8ToUTF16(app_name)));
base::string16 heading_text = l10n_util::GetStringFUTF16( base::string16 heading_text = l10n_util::GetStringFUTF16(
profile->IsChild() ? IDS_APP_BLOCK_HEADING_FOR_CHILD profile->IsChild() ? IDS_APP_BLOCK_HEADING_FOR_CHILD
: IDS_APP_BLOCK_HEADING, : IDS_APP_BLOCK_HEADING,
...@@ -52,8 +55,3 @@ AppBlockDialogView::~AppBlockDialogView() { ...@@ -52,8 +55,3 @@ AppBlockDialogView::~AppBlockDialogView() {
AppBlockDialogView* AppBlockDialogView::GetActiveViewForTesting() { AppBlockDialogView* AppBlockDialogView::GetActiveViewForTesting() {
return g_app_block_dialog_view; return g_app_block_dialog_view;
} }
base::string16 AppBlockDialogView::GetWindowTitle() const {
return l10n_util::GetStringFUTF16(IDS_APP_BLOCK_PROMPT_TITLE,
base::UTF8ToUTF16(app_name()));
}
...@@ -26,9 +26,6 @@ class AppBlockDialogView : public AppDialogView { ...@@ -26,9 +26,6 @@ class AppBlockDialogView : public AppDialogView {
~AppBlockDialogView() override; ~AppBlockDialogView() override;
static AppBlockDialogView* GetActiveViewForTesting(); static AppBlockDialogView* GetActiveViewForTesting();
// AppDialogView:
base::string16 GetWindowTitle() const override;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_APP_BLOCK_DIALOG_VIEW_H_ #endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_APP_BLOCK_DIALOG_VIEW_H_
...@@ -12,11 +12,12 @@ ...@@ -12,11 +12,12 @@
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
AppDialogView::AppDialogView(const std::string& app_name, AppDialogView::AppDialogView(const gfx::ImageSkia& image)
const gfx::ImageSkia& image) : BubbleDialogDelegateView(nullptr, views::BubbleBorder::NONE) {
: BubbleDialogDelegateView(nullptr, views::BubbleBorder::NONE), SetIcon(image);
app_name_(app_name), SetShowCloseButton(false);
image_(image) {} SetShowIcon(true);
}
AppDialogView::~AppDialogView() = default; AppDialogView::~AppDialogView() = default;
...@@ -31,18 +32,6 @@ ui::ModalType AppDialogView::GetModalType() const { ...@@ -31,18 +32,6 @@ ui::ModalType AppDialogView::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM; return ui::MODAL_TYPE_SYSTEM;
} }
gfx::ImageSkia AppDialogView::GetWindowIcon() {
return image_;
}
bool AppDialogView::ShouldShowCloseButton() const {
return false;
}
bool AppDialogView::ShouldShowWindowIcon() const {
return true;
}
void AppDialogView::InitializeView(const base::string16& heading_text) { void AppDialogView::InitializeView(const base::string16& heading_text) {
SetButtons(ui::DIALOG_BUTTON_OK); SetButtons(ui::DIALOG_BUTTON_OK);
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
......
...@@ -16,25 +16,15 @@ class ImageSkia; ...@@ -16,25 +16,15 @@ class ImageSkia;
// for app related dialog classes, e.g AppBlockDialogView, AppPauseDialogView. // for app related dialog classes, e.g AppBlockDialogView, AppPauseDialogView.
class AppDialogView : public views::BubbleDialogDelegateView { class AppDialogView : public views::BubbleDialogDelegateView {
public: public:
explicit AppDialogView(const std::string& app_name, explicit AppDialogView(const gfx::ImageSkia& image);
const gfx::ImageSkia& image);
~AppDialogView() override; ~AppDialogView() override;
// views::BubbleDialogDelegateView: // views::BubbleDialogDelegateView:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
gfx::ImageSkia GetWindowIcon() override;
bool ShouldShowCloseButton() const override;
bool ShouldShowWindowIcon() const override;
std::string app_name() const { return app_name_; }
protected: protected:
void InitializeView(const base::string16& heading_text); void InitializeView(const base::string16& heading_text);
private:
const std::string app_name_;
gfx::ImageSkia image_;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_APP_DIALOG_VIEW_H_ #endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_APP_DIALOG_VIEW_H_
...@@ -38,8 +38,12 @@ AppPauseDialogView::AppPauseDialogView( ...@@ -38,8 +38,12 @@ AppPauseDialogView::AppPauseDialogView(
const gfx::ImageSkia& image, const gfx::ImageSkia& image,
const apps::PauseData& pause_data, const apps::PauseData& pause_data,
apps::AppServiceProxy::OnPauseDialogClosedCallback closed_callback) apps::AppServiceProxy::OnPauseDialogClosedCallback closed_callback)
: AppDialogView(app_name, image), : AppDialogView(image) {
closed_callback_(std::move(closed_callback)) { SetTitle(l10n_util::GetStringFUTF16(IDS_APP_PAUSE_PROMPT_TITLE,
base::UTF8ToUTF16(app_name)));
SetAcceptCallback(std::move(closed_callback));
const int cutoff = pause_data.minutes == 0 || pause_data.hours == 0 ? 0 : -1; const int cutoff = pause_data.minutes == 0 || pause_data.hours == 0 ? 0 : -1;
base::string16 heading_text = l10n_util::GetStringFUTF16( base::string16 heading_text = l10n_util::GetStringFUTF16(
(app_type == apps::mojom::AppType::kWeb) (app_type == apps::mojom::AppType::kWeb)
...@@ -65,13 +69,3 @@ AppPauseDialogView::~AppPauseDialogView() { ...@@ -65,13 +69,3 @@ AppPauseDialogView::~AppPauseDialogView() {
AppPauseDialogView* AppPauseDialogView::GetActiveViewForTesting() { AppPauseDialogView* AppPauseDialogView::GetActiveViewForTesting() {
return g_app_pause_dialog_view; return g_app_pause_dialog_view;
} }
bool AppPauseDialogView::Accept() {
std::move(closed_callback_).Run();
return true;
}
base::string16 AppPauseDialogView::GetWindowTitle() const {
return l10n_util::GetStringFUTF16(IDS_APP_PAUSE_PROMPT_TITLE,
base::UTF8ToUTF16(app_name()));
}
...@@ -25,14 +25,6 @@ class AppPauseDialogView : public AppDialogView { ...@@ -25,14 +25,6 @@ class AppPauseDialogView : public AppDialogView {
~AppPauseDialogView() override; ~AppPauseDialogView() override;
static AppPauseDialogView* GetActiveViewForTesting(); static AppPauseDialogView* GetActiveViewForTesting();
// views::BubbleDialogDelegateView:
bool Accept() override;
base::string16 GetWindowTitle() const override;
private:
// Callback when the dialog closes after the user has clicked the OK.
apps::AppServiceProxy::OnPauseDialogClosedCallback closed_callback_;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_APP_PAUSE_DIALOG_VIEW_H_ #endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_APP_PAUSE_DIALOG_VIEW_H_
...@@ -43,6 +43,36 @@ namespace { ...@@ -43,6 +43,36 @@ namespace {
AppUninstallDialogView* g_app_uninstall_dialog_view = nullptr; AppUninstallDialogView* g_app_uninstall_dialog_view = nullptr;
#if defined(OS_CHROMEOS)
bool IsArcShortcutApp(Profile* profile, const std::string& app_id) {
ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile);
DCHECK(arc_prefs);
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
arc_prefs->GetApp(app_id);
DCHECK(app_info);
return app_info->shortcut;
}
#endif
base::string16 GetWindowTitleForApp(Profile* profile,
apps::mojom::AppType app_type,
const std::string& app_id,
const std::string& app_name) {
using apps::mojom::AppType;
#if defined(OS_CHROMEOS)
// On ChromeOS, all app types exist, but Arc shortcut apps get the regular
// extension uninstall title.
if (app_type == AppType::kArc && IsArcShortcutApp(profile, app_id))
return l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE);
#else
// On non-ChromeOS, only extension and web app types meaningfully exist.
DCHECK(app_type != AppType::kExtension && app_type != AppType::kWeb);
#endif
return l10n_util::GetStringFUTF16(IDS_PROMPT_APP_UNINSTALL_TITLE,
base::UTF8ToUTF16(app_name));
}
} // namespace } // namespace
// static // static
...@@ -69,9 +99,10 @@ AppUninstallDialogView::AppUninstallDialogView( ...@@ -69,9 +99,10 @@ AppUninstallDialogView::AppUninstallDialogView(
gfx::ImageSkia image, gfx::ImageSkia image,
apps::UninstallDialog* uninstall_dialog) apps::UninstallDialog* uninstall_dialog)
: apps::UninstallDialog::UiBase(uninstall_dialog), : apps::UninstallDialog::UiBase(uninstall_dialog),
AppDialogView(app_name, image), AppDialogView(image),
profile_(profile), profile_(profile) {
app_type_(app_type) { SetTitle(GetWindowTitleForApp(profile, app_type, app_id, app_name));
SetCloseCallback(base::BindOnce(&AppUninstallDialogView::OnDialogCancelled, SetCloseCallback(base::BindOnce(&AppUninstallDialogView::OnDialogCancelled,
base::Unretained(this))); base::Unretained(this)));
SetCancelCallback(base::BindOnce(&AppUninstallDialogView::OnDialogCancelled, SetCancelCallback(base::BindOnce(&AppUninstallDialogView::OnDialogCancelled,
...@@ -79,7 +110,7 @@ AppUninstallDialogView::AppUninstallDialogView( ...@@ -79,7 +110,7 @@ AppUninstallDialogView::AppUninstallDialogView(
SetAcceptCallback(base::BindOnce(&AppUninstallDialogView::OnDialogAccepted, SetAcceptCallback(base::BindOnce(&AppUninstallDialogView::OnDialogAccepted,
base::Unretained(this))); base::Unretained(this)));
InitializeView(profile, app_type, app_id); InitializeView(profile, app_type, app_id, app_name);
chrome::RecordDialogCreation(chrome::DialogIdentifier::APP_UNINSTALL); chrome::RecordDialogCreation(chrome::DialogIdentifier::APP_UNINSTALL);
...@@ -99,43 +130,10 @@ ui::ModalType AppUninstallDialogView::GetModalType() const { ...@@ -99,43 +130,10 @@ ui::ModalType AppUninstallDialogView::GetModalType() const {
return ui::MODAL_TYPE_WINDOW; return ui::MODAL_TYPE_WINDOW;
} }
base::string16 AppUninstallDialogView::GetWindowTitle() const {
switch (app_type_) {
case apps::mojom::AppType::kUnknown:
case apps::mojom::AppType::kBuiltIn:
case apps::mojom::AppType::kMacNative:
case apps::mojom::AppType::kLacros:
NOTREACHED();
return base::string16();
case apps::mojom::AppType::kArc:
#if defined(OS_CHROMEOS)
if (shortcut_)
return l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE);
// Otherwise fallback to Uninstall + app name.
FALLTHROUGH;
#else
NOTREACHED();
return base::string16();
#endif
case apps::mojom::AppType::kCrostini:
case apps::mojom::AppType::kPluginVm:
#if defined(OS_CHROMEOS)
FALLTHROUGH;
#else
NOTREACHED();
return base::string16();
#endif
case apps::mojom::AppType::kExtension:
case apps::mojom::AppType::kWeb:
return l10n_util::GetStringFUTF16(IDS_PROMPT_APP_UNINSTALL_TITLE,
base::UTF8ToUTF16(app_name()));
}
}
void AppUninstallDialogView::InitializeView(Profile* profile, void AppUninstallDialogView::InitializeView(Profile* profile,
apps::mojom::AppType app_type, apps::mojom::AppType app_type,
const std::string& app_id) { const std::string& app_id,
const std::string& app_name) {
SetButtonLabel( SetButtonLabel(
ui::DIALOG_BUTTON_OK, ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_APP_BUTTON)); l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_APP_BUTTON));
...@@ -145,7 +143,7 @@ void AppUninstallDialogView::InitializeView(Profile* profile, ...@@ -145,7 +143,7 @@ void AppUninstallDialogView::InitializeView(Profile* profile,
views::BoxLayout::Orientation::kVertical, gfx::Insets(), views::BoxLayout::Orientation::kVertical, gfx::Insets(),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL))); provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
switch (app_type_) { switch (app_type) {
case apps::mojom::AppType::kUnknown: case apps::mojom::AppType::kUnknown:
case apps::mojom::AppType::kBuiltIn: case apps::mojom::AppType::kBuiltIn:
case apps::mojom::AppType::kMacNative: case apps::mojom::AppType::kMacNative:
...@@ -162,7 +160,7 @@ void AppUninstallDialogView::InitializeView(Profile* profile, ...@@ -162,7 +160,7 @@ void AppUninstallDialogView::InitializeView(Profile* profile,
case apps::mojom::AppType::kPluginVm: case apps::mojom::AppType::kPluginVm:
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
InitializeViewWithMessage(l10n_util::GetStringFUTF16( InitializeViewWithMessage(l10n_util::GetStringFUTF16(
IDS_PLUGIN_VM_UNINSTALL_PROMPT_BODY, base::UTF8ToUTF16(app_name()))); IDS_PLUGIN_VM_UNINSTALL_PROMPT_BODY, base::UTF8ToUTF16(app_name)));
#else #else
NOTREACHED(); NOTREACHED();
#endif #endif
...@@ -304,16 +302,7 @@ void AppUninstallDialogView::InitializeViewForWebApp( ...@@ -304,16 +302,7 @@ void AppUninstallDialogView::InitializeViewForWebApp(
void AppUninstallDialogView::InitializeViewForArcApp( void AppUninstallDialogView::InitializeViewForArcApp(
Profile* profile, Profile* profile,
const std::string& app_id) { const std::string& app_id) {
ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile); if (IsArcShortcutApp(profile, app_id)) {
DCHECK(arc_prefs);
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
arc_prefs->GetApp(app_id);
DCHECK(app_info);
shortcut_ = app_info->shortcut;
if (shortcut_) {
SetButtonLabel( SetButtonLabel(
ui::DIALOG_BUTTON_OK, ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)); l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
......
...@@ -44,12 +44,12 @@ class AppUninstallDialogView : public apps::UninstallDialog::UiBase, ...@@ -44,12 +44,12 @@ class AppUninstallDialogView : public apps::UninstallDialog::UiBase,
// views::BubbleDialogDelegateView: // views::BubbleDialogDelegateView:
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
private: private:
void InitializeView(Profile* profile, void InitializeView(Profile* profile,
apps::mojom::AppType app_type, apps::mojom::AppType app_type,
const std::string& app_id); const std::string& app_id,
const std::string& app_name);
void InitializeCheckbox(const GURL& app_launch_url); void InitializeCheckbox(const GURL& app_launch_url);
...@@ -70,15 +70,6 @@ class AppUninstallDialogView : public apps::UninstallDialog::UiBase, ...@@ -70,15 +70,6 @@ class AppUninstallDialogView : public apps::UninstallDialog::UiBase,
Profile* profile_; Profile* profile_;
// The type of apps, e.g. Extension-backed app, Android app.
apps::mojom::AppType app_type_;
// Whether app represents a shortcut. |shortcut_| is available for the ARC
// apps only.
#if defined(OS_CHROMEOS)
bool shortcut_ = false;
#endif
views::Checkbox* report_abuse_checkbox_ = nullptr; views::Checkbox* report_abuse_checkbox_ = nullptr;
views::Checkbox* clear_site_data_checkbox_ = nullptr; views::Checkbox* clear_site_data_checkbox_ = nullptr;
......
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