Chromium Code Reviews| Index: ash/display/display_util.cc |
| diff --git a/ash/display/display_util.cc b/ash/display/display_util.cc |
| index afa67d2a91aa5538ad6b34201cce16c3e5179755..18d8a439b817ede432b50e31e4e1bb05bb6aebb5 100644 |
| --- a/ash/display/display_util.cc |
| +++ b/ash/display/display_util.cc |
| @@ -9,14 +9,23 @@ |
| #include "ash/display/display_info.h" |
| #include "ash/display/display_manager.h" |
| #include "ash/host/ash_window_tree_host.h" |
| +#include "ash/new_window_delegate.h" |
| #include "ash/shell.h" |
| +#include "ash/system/system_notifier.h" |
| #include "base/strings/string_number_conversions.h" |
| +#include "grit/ash_resources.h" |
| #include "ui/aura/env.h" |
| #include "ui/aura/window_tree_host.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| #include "ui/display/display.h" |
| #include "ui/gfx/geometry/point.h" |
| #include "ui/gfx/geometry/rect.h" |
| #include "ui/gfx/geometry/size_conversions.h" |
| +#include "ui/message_center/message_center.h" |
| +#include "ui/message_center/notification.h" |
| +#include "ui/message_center/notification_delegate.h" |
| +#include "ui/message_center/notification_list.h" |
| #include "ui/wm/core/coordinate_conversion.h" |
| #if defined(OS_CHROMEOS) |
| @@ -26,6 +35,29 @@ |
| namespace ash { |
| namespace { |
| +const char kDisplayErrorNotificationId[] = "chrome://settings/display/error"; |
| + |
| +// A notification delegate that will start the feedback app when the notication |
| +// is clicked. |
| +class DisplayErrorNotificationDelegate |
| + : public message_center::NotificationDelegate { |
| + public: |
| + DisplayErrorNotificationDelegate() = default; |
| + |
| + // message_center::NotificationDelegate: |
| + bool HasClickedListener() override { return true; } |
| + |
| + void Click() override { |
| + ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); |
| + } |
| + |
| + private: |
| + // Private destructor since NotificationDelegate is ref-counted. |
| + ~DisplayErrorNotificationDelegate() override = default; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate); |
| +}; |
| + |
| // List of value UI Scale values. Scales for 2x are equivalent to 640, |
| // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on |
| // 2560 pixel width 2x density display. Please see crbug.com/233375 |
| @@ -407,4 +439,39 @@ bool CompareDisplayIds(int64_t id1, int64_t id2) { |
| (index_1 < index_2 && !display::Display::IsInternalDisplayId(id2)); |
| } |
| +void ShowDisplayErrorNotification(int message_id) { |
| + // Always remove the notification to make sure the notification appears |
| + // as a popup in any situation. |
| + message_center::MessageCenter::Get()->RemoveNotification( |
| + kDisplayErrorNotificationId, false /* by_user */); |
| + |
| + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| + std::unique_ptr<message_center::Notification> notification( |
| + new message_center::Notification( |
| + message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, |
| + base::string16(), // title |
| + l10n_util::GetStringUTF16(message_id), |
| + bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), |
| + base::string16(), // display_source |
| + GURL(), message_center::NotifierId( |
| + message_center::NotifierId::SYSTEM_COMPONENT, |
| + system_notifier::kNotifierDisplayError), |
| + message_center::RichNotificationData(), |
| + new DisplayErrorNotificationDelegate)); |
| + message_center::MessageCenter::Get()->AddNotification( |
| + std::move(notification)); |
| +} |
| + |
| +base::string16 GetDisplayErrorNotificationMessageForTest() { |
| + message_center::NotificationList::Notifications notifications = |
| + message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| + for (message_center::NotificationList::Notifications::const_iterator iter = |
|
stevenjb
2016/05/06 16:03:51
nit: for (const auto iter : notifications)
oshima
2016/05/06 18:47:04
Done.
|
| + notifications.begin(); |
| + iter != notifications.end(); ++iter) { |
| + if ((*iter)->id() == kDisplayErrorNotificationId) |
| + return (*iter)->message(); |
| + } |
| + return base::string16(); |
| +} |
| + |
| } // namespace ash |