Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_SYSTEM_WEB_NOTIFICATION_MESSAGE_CENTER_H_ | |
| 6 #define ASH_SYSTEM_WEB_NOTIFICATION_MESSAGE_CENTER_H_ | |
| 7 | |
| 8 #include "ash/ash_export.h" | |
| 9 #include "ash/system/web_notification/web_notification_list.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 | |
| 12 // Class for managing the WebNotificationList. The client (e.g. Chrome) calls | |
| 13 // [Add|Remove|Update]Notification to create and update notifications in the | |
| 14 // list. It can also implement Delegate to receive callbacks when a | |
| 15 // notification is removed (closed), or clicked on. | |
| 16 // If a Host is provided, it will be informed when the notification list | |
| 17 // changes, and is expected to handle creating, showing, and hiding of any | |
| 18 // bubbles. | |
| 19 | |
| 20 namespace message_center { | |
| 21 | |
| 22 class ASH_EXPORT MessageCenter : public WebNotificationList::Delegate { | |
| 23 public: | |
| 24 // Class that hosts the message center. | |
| 25 class ASH_EXPORT Host { | |
| 26 public: | |
| 27 // Called when the notification list has changed. |new_notification| will | |
| 28 // be true if a notification was added or updated. | |
| 29 virtual void MessageCenterChanged(bool new_notification) = 0; | |
| 30 | |
| 31 protected: | |
| 32 virtual ~Host() {} | |
| 33 }; | |
| 34 | |
| 35 class ASH_EXPORT Delegate { | |
| 36 public: | |
| 37 // Called when the notification associated with |notification_id| is | |
| 38 // removed (i.e. closed by the user). | |
| 39 virtual void NotificationRemoved(const std::string& notifcation_id) = 0; | |
| 40 | |
| 41 // Request to disable the extension associated with |notification_id|. | |
| 42 virtual void DisableExtension(const std::string& notifcation_id) = 0; | |
| 43 | |
| 44 // Request to disable notifications from the source of |notification_id|. | |
| 45 virtual void DisableNotificationsFromSource( | |
| 46 const std::string& notifcation_id) = 0; | |
| 47 | |
| 48 // Request to show the notification settings (|notification_id| is used | |
| 49 // to identify the requesting browser context). | |
| 50 virtual void ShowSettings(const std::string& notifcation_id) = 0; | |
| 51 | |
| 52 // Called when the notification body is clicked on. | |
| 53 virtual void OnClicked(const std::string& notifcation_id) = 0; | |
| 54 | |
| 55 protected: | |
| 56 virtual ~Delegate() {} | |
| 57 }; | |
| 58 | |
| 59 // |host| is expected to manage any notification bubbles. It may be NULL. | |
| 60 explicit MessageCenter(Host* host); | |
| 61 | |
| 62 virtual ~MessageCenter(); | |
| 63 | |
| 64 // Called once to set the delegate. | |
| 65 void SetDelegate(Delegate* delegate); | |
| 66 | |
| 67 // Informs the notification list whether the message center is visible. | |
| 68 // This affects whether or not a message has been "read". | |
| 69 void SetMessageCenterVisible(bool visible); | |
| 70 | |
| 71 // Accessors to notification_list_ | |
| 72 size_t NotificationCount() const; | |
| 73 size_t UnreadNotificationCount() const; | |
| 74 bool HasPopupNotifications() const; | |
| 75 | |
| 76 // Add a new notification. |id| is a unique identifier, used to update or | |
|
miket_OOO
2012/10/19 20:45:26
I think these should be 3d-person singular ("Adds.
stevenjb
2012/10/19 21:47:54
Yep. Done.
| |
| 77 // remove notifications. |title| and |meesage| describe the notification text. | |
| 78 // Use SetNotificationImage to set the icon image. If |extension_id| is | |
| 79 // provided then 'Disable extension' will appear in a dropdown menu and the | |
| 80 // id will be used to disable notifications from the extension. Otherwise if | |
| 81 // |display_source| is provided, a menu item showing the source and allowing | |
| 82 // notifications from that source to be disabled will be shown. All actual | |
| 83 // disabling is handled by the Delegate. | |
| 84 void AddNotification(const std::string& id, | |
| 85 const string16& title, | |
| 86 const string16& message, | |
| 87 const string16& display_source, | |
| 88 const std::string& extension_id); | |
| 89 | |
| 90 // Update an existing notification with id = old_id and set its id to new_id. | |
| 91 void UpdateNotification(const std::string& old_id, | |
| 92 const std::string& new_id, | |
| 93 const string16& title, | |
| 94 const string16& message); | |
| 95 | |
| 96 // Remove an existing notification. | |
| 97 void RemoveNotification(const std::string& id); | |
| 98 | |
| 99 // Set the notification image. | |
| 100 void SetNotificationImage(const std::string& id, | |
| 101 const gfx::ImageSkia& image); | |
| 102 | |
| 103 WebNotificationList* notification_list() { return notification_list_.get(); } | |
| 104 | |
| 105 // Overridden from WebNotificationList::Delegate. | |
| 106 virtual void SendRemoveNotification(const std::string& id) OVERRIDE; | |
| 107 virtual void SendRemoveAllNotifications() OVERRIDE; | |
| 108 virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE; | |
| 109 virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE; | |
| 110 virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; | |
| 111 virtual void OnNotificationClicked(const std::string& id) OVERRIDE; | |
| 112 virtual message_center::WebNotificationList* GetNotificationList() OVERRIDE; | |
| 113 | |
| 114 private: | |
| 115 scoped_ptr<WebNotificationList> notification_list_; | |
| 116 Host* host_; | |
| 117 Delegate* delegate_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(MessageCenter); | |
| 120 }; | |
| 121 | |
| 122 } // namespace message_center | |
| 123 | |
| 124 #endif // ASH_SYSTEM_WEB_NOTIFICATION_MESSAGE_CENTER_H_ | |
| OLD | NEW |