Index: ui/arc/notification/arc_notification_item.cc |
diff --git a/ui/arc/notification/arc_notification_item.cc b/ui/arc/notification/arc_notification_item.cc |
index 5d936ad3cc3776773adc00553ab7324865bd6bcd..2b3722efba9fd49bb7f74e52155e2fe12ca7ec64 100644 |
--- a/ui/arc/notification/arc_notification_item.cc |
+++ b/ui/arc/notification/arc_notification_item.cc |
@@ -5,8 +5,10 @@ |
#include "ui/arc/notification/arc_notification_item.h" |
#include <algorithm> |
+#include <memory> |
#include <vector> |
+#include "base/memory/ptr_util.h" |
#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/task_runner.h" |
@@ -15,6 +17,7 @@ |
#include "components/arc/bitmap/bitmap_type_converters.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
#include "third_party/skia/include/core/SkPaint.h" |
+#include "ui/arc/notification/arc_custom_notification_view.h" |
#include "ui/gfx/codec/png_codec.h" |
#include "ui/gfx/geometry/size.h" |
#include "ui/gfx/image/image.h" |
@@ -28,9 +31,11 @@ namespace arc { |
namespace { |
-static const char kNotifierId[] = "ARC_NOTIFICATION"; |
+constexpr char kNotifierId[] = "ARC_NOTIFICATION"; |
+constexpr char kNotificationIdPrefix[] = "ARC_NOTIFICATION_"; |
-static const char kNotificationIdPrefix[] = "ARC_NOTIFICATION_"; |
+// Whether to use notification surface. |
+constexpr bool use_notification_surface = true; |
SkBitmap DecodeImage(const std::vector<uint8_t>& data) { |
DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); |
@@ -134,11 +139,23 @@ class ArcNotificationDelegate : public message_center::NotificationDelegate { |
item_->ButtonClick(button_index); |
} |
+ std::unique_ptr<views::View> CreateCustomContent() override { |
+ if (!item_ || !surface_) |
+ return std::unique_ptr<views::View>(); |
+ |
+ return base::WrapUnique(new ArcCustomNotificationView(surface_)); |
+ } |
+ |
+ void set_notification_surface(exo::NotificationSurface* surface) { |
+ surface_ = surface; |
+ } |
+ |
private: |
// The destructor is private since this class is ref-counted. |
~ArcNotificationDelegate() override {} |
base::WeakPtr<ArcNotificationItem> item_; |
+ exo::NotificationSurface* surface_ = nullptr; |
DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); |
}; |
@@ -244,6 +261,9 @@ void ArcNotificationItem::UpdateWithArcNotificationData( |
message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
notifier_id.profile_id = profile_id_.GetUserEmail(); |
+ if (use_notification_surface) |
+ type = message_center::NOTIFICATION_TYPE_CUSTOM; |
+ |
DCHECK(!data.title.is_null()); |
DCHECK(!data.message.is_null()); |
notification_.reset(new message_center::Notification( |
@@ -255,6 +275,18 @@ void ArcNotificationItem::UpdateWithArcNotificationData( |
notifier_id, rich_data, |
new ArcNotificationDelegate(weak_ptr_factory_.GetWeakPtr()))); |
+ if (use_notification_surface) { |
+ ArcNotificationSurfaceCollection* surface_collection = |
+ manager_->notification_surface_collection(); |
+ exo::NotificationSurface* surface = |
+ surface_collection->GetSurface(notification_id_); |
+ if (surface) |
+ OnNotificationSurfaceAdded(surface); |
+ else |
+ surface_collection->AddObserver(this); |
+ return; |
yoshiki
2016/06/15 11:47:20
Please call AddToMessageCenter(). At least, we nee
xiyuan
2016/06/15 19:32:44
AddToMessageCenter() is called once the surface is
yoshiki
2016/06/16 02:44:50
I got it. Thank you for explanation.
|
+ } |
+ |
DCHECK(!data.icon_data.is_null()); |
if (data.icon_data.size() == 0) { |
OnImageDecoded(SkBitmap()); // Pass an empty bitmap. |
@@ -269,7 +301,9 @@ void ArcNotificationItem::UpdateWithArcNotificationData( |
weak_ptr_factory_.GetWeakPtr())); |
} |
-ArcNotificationItem::~ArcNotificationItem() {} |
+ArcNotificationItem::~ArcNotificationItem() { |
+ manager_->notification_surface_collection()->RemoveObserver(this); |
+} |
void ArcNotificationItem::OnClosedFromAndroid(bool by_user) { |
being_removed_by_manager_ = true; // Closing is initiated by the manager. |
@@ -297,12 +331,25 @@ void ArcNotificationItem::ButtonClick(int button_index) { |
notification_key_, button_index); |
} |
+void ArcNotificationItem::OnNotificationSurfaceAdded( |
+ exo::NotificationSurface* surface) { |
+ if (!notification_ || surface->notification_id() != notification_key_) |
+ return; |
yoshiki
2016/06/15 11:47:20
Ditto for calling AddTestMessageCenter().
xiyuan
2016/06/15 19:32:44
AddToMessageCenter() is called at the end. The con
|
+ |
+ static_cast<ArcNotificationDelegate*>(notification_->delegate()) |
+ ->set_notification_surface(surface); |
+ AddToMessageCenter(); |
+} |
+ |
void ArcNotificationItem::OnImageDecoded(const SkBitmap& bitmap) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap); |
notification_->set_icon(image); |
+ AddToMessageCenter(); |
+} |
+void ArcNotificationItem::AddToMessageCenter() { |
DCHECK(notification_); |
message_center_->AddNotification(std::move(notification_)); |