Index: ash/system/web_notification/message_center.h |
diff --git a/ash/system/web_notification/message_center.h b/ash/system/web_notification/message_center.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1ac3de05ca504e6fb66e2b0bf00d54a33adc37de |
--- /dev/null |
+++ b/ash/system/web_notification/message_center.h |
@@ -0,0 +1,124 @@ |
+// Copyright (c) 2012 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 ASH_SYSTEM_WEB_NOTIFICATION_MESSAGE_CENTER_H_ |
+#define ASH_SYSTEM_WEB_NOTIFICATION_MESSAGE_CENTER_H_ |
+ |
+#include "ash/ash_export.h" |
+#include "ash/system/web_notification/web_notification_list.h" |
+#include "base/memory/scoped_ptr.h" |
+ |
+// Class for managing the WebNotificationList. The client (e.g. Chrome) calls |
+// [Add|Remove|Update]Notification to create and update notifications in the |
+// list. It can also implement Delegate to receive callbacks when a |
+// notification is removed (closed), or clicked on. |
+// If a Host is provided, it will be informed when the notification list |
+// changes, and is expected to handle creating, showing, and hiding of any |
+// bubbles. |
+ |
+namespace message_center { |
+ |
+class ASH_EXPORT MessageCenter : public WebNotificationList::Delegate { |
+ public: |
+ // Class that hosts the message center. |
+ class ASH_EXPORT Host { |
+ public: |
+ // Called when the notification list has changed. |new_notification| will |
+ // be true if a notification was added or updated. |
+ virtual void MessageCenterChanged(bool new_notification) = 0; |
+ |
+ protected: |
+ virtual ~Host() {} |
+ }; |
+ |
+ class ASH_EXPORT Delegate { |
+ public: |
+ // Called when the notification associated with |notification_id| is |
+ // removed (i.e. closed by the user). |
+ virtual void NotificationRemoved(const std::string& notifcation_id) = 0; |
+ |
+ // Request to disable the extension associated with |notification_id|. |
+ virtual void DisableExtension(const std::string& notifcation_id) = 0; |
+ |
+ // Request to disable notifications from the source of |notification_id|. |
+ virtual void DisableNotificationsFromSource( |
+ const std::string& notifcation_id) = 0; |
+ |
+ // Request to show the notification settings (|notification_id| is used |
+ // to identify the requesting browser context). |
+ virtual void ShowSettings(const std::string& notifcation_id) = 0; |
+ |
+ // Called when the notification body is clicked on. |
+ virtual void OnClicked(const std::string& notifcation_id) = 0; |
+ |
+ protected: |
+ virtual ~Delegate() {} |
+ }; |
+ |
+ // |host| is expected to manage any notification bubbles. It may be NULL. |
+ explicit MessageCenter(Host* host); |
+ |
+ virtual ~MessageCenter(); |
+ |
+ // Called once to set the delegate. |
+ void SetDelegate(Delegate* delegate); |
+ |
+ // Informs the notification list whether the message center is visible. |
+ // This affects whether or not a message has been "read". |
+ void SetMessageCenterVisible(bool visible); |
+ |
+ // Accessors to notification_list_ |
+ size_t NotificationCount() const; |
+ size_t UnreadNotificationCount() const; |
+ bool HasPopupNotifications() const; |
+ |
+ // Adds a new notification. |id| is a unique identifier, used to update or |
+ // remove notifications. |title| and |meesage| describe the notification text. |
+ // Use SetNotificationImage to set the icon image. If |extension_id| is |
+ // provided then 'Disable extension' will appear in a dropdown menu and the |
+ // id will be used to disable notifications from the extension. Otherwise if |
+ // |display_source| is provided, a menu item showing the source and allowing |
+ // notifications from that source to be disabled will be shown. All actual |
+ // disabling is handled by the Delegate. |
+ void AddNotification(const std::string& id, |
+ const string16& title, |
+ const string16& message, |
+ const string16& display_source, |
+ const std::string& extension_id); |
+ |
+ // Updates an existing notification with id = old_id and set its id to new_id. |
+ void UpdateNotification(const std::string& old_id, |
+ const std::string& new_id, |
+ const string16& title, |
+ const string16& message); |
+ |
+ // Removes an existing notification. |
+ void RemoveNotification(const std::string& id); |
+ |
+ // Sets the notification image. |
+ void SetNotificationImage(const std::string& id, |
+ const gfx::ImageSkia& image); |
+ |
+ WebNotificationList* notification_list() { return notification_list_.get(); } |
+ |
+ // Overridden from WebNotificationList::Delegate. |
+ virtual void SendRemoveNotification(const std::string& id) OVERRIDE; |
+ virtual void SendRemoveAllNotifications() OVERRIDE; |
+ virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE; |
+ virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE; |
+ virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; |
+ virtual void OnNotificationClicked(const std::string& id) OVERRIDE; |
+ virtual message_center::WebNotificationList* GetNotificationList() OVERRIDE; |
+ |
+ private: |
+ scoped_ptr<WebNotificationList> notification_list_; |
+ Host* host_; |
+ Delegate* delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MessageCenter); |
+}; |
+ |
+} // namespace message_center |
+ |
+#endif // ASH_SYSTEM_WEB_NOTIFICATION_MESSAGE_CENTER_H_ |