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

Add the block app dialog.

Refactor the current app pause dialog view, to add a base class app
dialog, to keep consistency for the app pause dialog and the app block
dialog. The app uninstall dialog might be changed to inherit from app
dialog as well, when the decision has been made for
https://bugs.chromium.org/p/chromium/issues/detail?id=1010303

BUG=1035136

Change-Id: I2e5a17f75bce8f343d15ffa1b7e7b542ea433b8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2060433Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743393}
parent 58d10a96
......@@ -10519,6 +10519,19 @@ Please help our engineers fix this problem. Tell us what happened right before y
The limit on "<ph name="APP_NAME">$1<ex>Google Photos</ex></ph>" that your parent set ran out. You can use it for <ph name="TIME_LIMIT">$2<ex>2 hours and 30 minutes</ex></ph> tomorrow.
</message>
<!-- App block prompt -->
<message name="IDS_APP_BLOCK_PROMPT_TITLE" desc="Titlebar of the app block prompt window">
App blocked
</message>
<message name="IDS_APP_BLOCK_HEADING_FOR_CHILD" desc="Tells the child the app is blocked.">
"<ph name="APP_NAME">$1<ex>Google Photos</ex></ph>" is blocked by your parent. Ask your parent for permission to use this app.
</message>
<message name="IDS_APP_BLOCK_HEADING" desc="Tells the user the app is blocked.">
"<ph name="APP_NAME">$1<ex>Google Photos</ex></ph>" is blocked by admin. Ask admin for permission to use this app.
</message>
<!-- Extension request -->
<if expr="not is_android">
<message name="IDS_ENTERPRISE_EXTENSION_REQUEST_APPROVED_TITLE" desc="The notification title when there are some extension requests approved.">
......
9cba8feaf00659d841e96d7cce2945a2130286c5
\ No newline at end of file
e01582a77561339d6b9797143a9bf776b30f2611
\ No newline at end of file
e01582a77561339d6b9797143a9bf776b30f2611
\ No newline at end of file
......@@ -260,6 +260,7 @@ void AppServiceProxy::Uninstall(const std::string& app_id,
void AppServiceProxy::PauseApps(
const std::map<std::string, PauseData>& pause_data) {
#if defined(OS_CHROMEOS)
if (!app_service_.is_connected()) {
return;
}
......@@ -278,9 +279,11 @@ void AppServiceProxy::PauseApps(
this->LoadIconForPauseDialog(update, data.second);
});
}
#endif // OS_CHROMEOS
}
void AppServiceProxy::UnpauseApps(const std::set<std::string>& app_ids) {
#if defined(OS_CHROMEOS)
if (!app_service_.is_connected()) {
return;
}
......@@ -292,6 +295,7 @@ void AppServiceProxy::UnpauseApps(const std::set<std::string>& app_ids) {
app_service_->UnpauseApps(app_type, app_id);
}
#endif // OS_CHROMEOS
}
void AppServiceProxy::GetMenuModel(
......@@ -476,6 +480,7 @@ void AppServiceProxy::OnUninstallDialogClosed(
void AppServiceProxy::LoadIconForPauseDialog(const apps::AppUpdate& update,
const PauseData& pause_data) {
#if defined(OS_CHROMEOS)
apps::mojom::IconKeyPtr icon_key = update.IconKey();
constexpr bool kAllowPlaceholderIcon = false;
constexpr int32_t kPauseIconSize = 48;
......@@ -486,6 +491,7 @@ void AppServiceProxy::LoadIconForPauseDialog(const apps::AppUpdate& update,
base::BindOnce(&AppServiceProxy::OnLoadIconForPauseDialog,
weak_ptr_factory_.GetWeakPtr(), update.AppType(),
update.AppId(), update.Name(), pause_data));
#endif // OS_CHROMEOS
}
void AppServiceProxy::OnLoadIconForPauseDialog(
......@@ -494,6 +500,7 @@ void AppServiceProxy::OnLoadIconForPauseDialog(
const std::string& app_name,
const PauseData& pause_data,
apps::mojom::IconValuePtr icon_value) {
#if defined(OS_CHROMEOS)
if (icon_value->icon_compression !=
apps::mojom::IconCompression::kUncompressed) {
OnPauseDialogClosed(app_type, app_id);
......@@ -504,11 +511,13 @@ void AppServiceProxy::OnLoadIconForPauseDialog(
app_name, icon_value->uncompressed, pause_data,
base::BindOnce(&AppServiceProxy::OnPauseDialogClosed,
weak_ptr_factory_.GetWeakPtr(), app_type, app_id));
#endif // OS_CHROMEOS
}
void AppServiceProxy::UpdatePausedStatus(apps::mojom::AppType app_type,
const std::string& app_id,
bool paused) {
#if defined(OS_CHROMEOS)
std::vector<apps::mojom::AppPtr> apps;
apps::mojom::AppPtr app = apps::mojom::App::New();
app->app_type = app_type;
......@@ -517,11 +526,14 @@ void AppServiceProxy::UpdatePausedStatus(apps::mojom::AppType app_type,
: apps::mojom::OptionalBool::kFalse;
apps.push_back(std::move(app));
cache_.OnApps(std::move(apps));
#endif // OS_CHROMEOS
}
void AppServiceProxy::OnPauseDialogClosed(apps::mojom::AppType app_type,
const std::string& app_id) {
#if defined(OS_CHROMEOS)
app_service_->PauseApp(app_type, app_id);
#endif // OS_CHROMEOS
}
void AppServiceProxy::OnAppUpdate(const apps::AppUpdate& update) {
......
......@@ -229,7 +229,7 @@ class AppServiceProxy : public KeyedService,
};
static void CreatePauseDialog(const std::string& app_name,
gfx::ImageSkia image,
const gfx::ImageSkia& image,
const PauseData& pause_data,
OnPauseDialogClosedCallback pause_callback);
......
......@@ -55,6 +55,10 @@ class ArcApps : public KeyedService,
using AppIdToTaskIds = std::map<std::string, std::set<int>>;
using TaskIdToAppId = std::map<int, std::string>;
static void CreateBlockDialog(const std::string& app_name,
const gfx::ImageSkia& image,
Profile* profile);
ArcApps(Profile* profile, apps::AppServiceProxy* proxy);
// KeyedService overrides.
......
......@@ -2730,6 +2730,8 @@ jumbo_static_library("ui") {
"views/accessibility/invert_bubble_view.h",
"views/accessibility/non_accessible_image_view.cc",
"views/accessibility/non_accessible_image_view.h",
"views/apps/app_dialog_view.cc",
"views/apps/app_dialog_view.h",
"views/apps/app_info_dialog/app_info_dialog_container.cc",
"views/apps/app_info_dialog/app_info_dialog_container.h",
"views/apps/app_info_dialog/app_info_dialog_views.cc",
......@@ -2746,8 +2748,6 @@ jumbo_static_library("ui") {
"views/apps/app_info_dialog/app_info_permissions_panel.h",
"views/apps/app_info_dialog/app_info_summary_panel.cc",
"views/apps/app_info_dialog/app_info_summary_panel.h",
"views/apps/app_pause_dialog_view.cc",
"views/apps/app_pause_dialog_view.h",
"views/apps/app_uninstall_dialog_view.cc",
"views/apps/app_uninstall_dialog_view.h",
"views/apps/chrome_native_app_window_views.cc",
......@@ -3906,6 +3906,10 @@ jumbo_static_library("ui") {
"ash/launcher/shelf_spinner_controller.h",
"ash/launcher/shelf_spinner_item_controller.cc",
"ash/launcher/shelf_spinner_item_controller.h",
"views/apps/app_block_dialog_view.cc",
"views/apps/app_block_dialog_view.h",
"views/apps/app_pause_dialog_view.cc",
"views/apps/app_pause_dialog_view.h",
"views/arc_app_dialog_view.cc",
"views/arc_data_removal_dialog_view.cc",
"views/crostini/crostini_ansible_software_config_view.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/apps/app_block_dialog_view.h"
#include "chrome/browser/apps/app_service/arc_apps.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/window/dialog_delegate.h"
namespace apps {
// static
void ArcApps::CreateBlockDialog(const std::string& app_name,
const gfx::ImageSkia& image,
Profile* profile) {
views::DialogDelegate::CreateDialogWidget(
new AppBlockDialogView(app_name, image, profile), nullptr, nullptr)
->Show();
}
} // namespace apps
AppBlockDialogView::AppBlockDialogView(const std::string& app_name,
const gfx::ImageSkia& image,
Profile* profile) {
base::string16 heading_text = l10n_util::GetStringFUTF16(
profile->IsChild() ? IDS_APP_BLOCK_HEADING_FOR_CHILD
: IDS_APP_BLOCK_HEADING,
base::UTF8ToUTF16(app_name));
InitializeView(image, heading_text);
}
AppBlockDialogView::~AppBlockDialogView() = default;
base::string16 AppBlockDialogView::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_APP_BLOCK_PROMPT_TITLE);
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_APPS_APP_BLOCK_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_APPS_APP_BLOCK_DIALOG_VIEW_H_
#include <string>
#include "chrome/browser/ui/views/apps/app_dialog_view.h"
class Profile;
namespace gfx {
class ImageSkia;
}
// The app block dialog that displays the app's name, icon and the block reason.
// It is shown when the app is blocked to notice the user that the app can't be
// launched.
class AppBlockDialogView : public AppDialogView {
public:
AppBlockDialogView(const std::string& app_name,
const gfx::ImageSkia& image,
Profile* profile);
~AppBlockDialogView() override;
// AppDialogView:
base::string16 GetWindowTitle() const override;
};
#endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_BLOCK_DIALOG_VIEW_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/apps/app_dialog_view.h"
#include <memory>
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
AppDialogView::AppDialogView()
: BubbleDialogDelegateView(nullptr, views::BubbleBorder::NONE) {}
AppDialogView::~AppDialogView() = default;
gfx::Size AppDialogView::CalculatePreferredSize() const {
const int default_width = views::LayoutProvider::Get()->GetDistanceMetric(
DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(default_width, GetHeightForWidth(default_width));
}
ui::ModalType AppDialogView::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
bool AppDialogView::ShouldShowCloseButton() const {
return false;
}
void AppDialogView::InitializeView(const gfx::ImageSkia& image,
const base::string16& heading_text) {
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_OK);
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
provider->GetDialogInsetsForContentType(views::TEXT, views::TEXT),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_HORIZONTAL)));
auto* icon_view = AddChildView(std::make_unique<views::ImageView>());
icon_view->SetImage(image);
auto* label = AddChildView(std::make_unique<views::Label>(heading_text));
label->SetMultiLine(true);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_VIEW_H_
#include "base/strings/string16.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
namespace gfx {
class ImageSkia;
}
// The app dialog that may display the app's name, icon. This is the base class
// for app related dialog classes, e.g AppBlockDialogView, AppPauseDialogView.
class AppDialogView : public views::BubbleDialogDelegateView {
public:
AppDialogView();
~AppDialogView() override;
// views::BubbleDialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
ui::ModalType GetModalType() const override;
bool ShouldShowCloseButton() const override;
void InitializeView(const gfx::ImageSkia& image,
const base::string16& heading_text);
};
#endif // CHROME_BROWSER_UI_VIEWS_APPS_APP_DIALOG_VIEW_H_
......@@ -4,54 +4,33 @@
#include "chrome/browser/ui/views/apps/app_pause_dialog_view.h"
#include <memory>
#include <utility>
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/window/dialog_delegate.h"
// static
void apps::AppServiceProxy::CreatePauseDialog(
const std::string& app_name,
gfx::ImageSkia image,
const gfx::ImageSkia& image,
const apps::PauseData& pause_data,
apps::AppServiceProxy::OnPauseDialogClosedCallback closed_callback) {
constrained_window::CreateBrowserModalDialogViews(
views::DialogDelegate::CreateDialogWidget(
new AppPauseDialogView(app_name, image, pause_data,
std::move(closed_callback)),
nullptr)
nullptr, nullptr)
->Show();
}
AppPauseDialogView::AppPauseDialogView(
const std::string& app_name,
gfx::ImageSkia image,
const gfx::ImageSkia& image,
const apps::PauseData& pause_data,
apps::AppServiceProxy::OnPauseDialogClosedCallback closed_callback)
: BubbleDialogDelegateView(nullptr, views::BubbleBorder::NONE),
closed_callback_(std::move(closed_callback)) {
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_OK);
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
provider->GetDialogInsetsForContentType(views::TEXT, views::TEXT),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_HORIZONTAL)));
auto* icon_view = AddChildView(std::make_unique<views::ImageView>());
icon_view->SetImage(image);
: closed_callback_(std::move(closed_callback)) {
const int cutoff = pause_data.minutes == 0 || pause_data.hours == 0 ? 0 : -1;
base::string16 heading_text = l10n_util::GetStringFUTF16(
IDS_APP_PAUSE_HEADING, base::UTF8ToUTF16(app_name),
......@@ -61,9 +40,7 @@ AppPauseDialogView::AppPauseDialogView(
base::TimeDelta::FromHours(pause_data.hours) +
base::TimeDelta::FromMinutes(pause_data.minutes)));
auto* label = AddChildView(std::make_unique<views::Label>(heading_text));
label->SetMultiLine(true);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
InitializeView(image, heading_text);
}
AppPauseDialogView::~AppPauseDialogView() = default;
......@@ -73,21 +50,6 @@ bool AppPauseDialogView::Accept() {
return true;
}
gfx::Size AppPauseDialogView::CalculatePreferredSize() const {
const int default_width = views::LayoutProvider::Get()->GetDistanceMetric(
DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(default_width, GetHeightForWidth(default_width));
}
ui::ModalType AppPauseDialogView::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
base::string16 AppPauseDialogView::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_APP_PAUSE_PROMPT_TITLE);
}
bool AppPauseDialogView::ShouldShowCloseButton() const {
return false;
}
......@@ -5,10 +5,8 @@
#ifndef CHROME_BROWSER_UI_VIEWS_APPS_APP_PAUSE_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_APPS_APP_PAUSE_DIALOG_VIEW_H_
#include "base/macros.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "chrome/browser/ui/views/apps/app_dialog_view.h"
namespace gfx {
class ImageSkia;
......@@ -16,21 +14,18 @@ class ImageSkia;
// The app pause dialog. Once the user clicks the 'OK' button, this class calls
// the callback to notify AppService, which pauses the app.
class AppPauseDialogView : public views::BubbleDialogDelegateView {
class AppPauseDialogView : public AppDialogView {
public:
AppPauseDialogView(
const std::string& app_name,
gfx::ImageSkia image,
const gfx::ImageSkia& image,
const apps::PauseData& pause_data,
apps::AppServiceProxy::OnPauseDialogClosedCallback callback);
~AppPauseDialogView() override;
// views::BubbleDialogDelegateView:
bool Accept() override;
gfx::Size CalculatePreferredSize() const override;
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
private:
// Callback when the dialog closes after the user has clicked the OK.
......
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