message_center.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/message_center_export.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/notification_list.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/notifications/notification_types.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Class for managing the NotificationList. The client (e.g. Chrome) calls 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// [Add|Remove|Update]Notification to create and update notifications in the 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// list. It can also implement Delegate to receive callbacks when a 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// notification is removed (closed), or clicked on. 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If a Host is provided, it will be informed when the notification list 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// changes, and is expected to handle creating, showing, and hiding of any 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// bubbles. 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace message_center { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Class that hosts the message center. 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class MESSAGE_CENTER_EXPORT Host { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the notification list has changed. |new_notification| will 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be true if a notification was added or updated. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void MessageCenterChanged(bool new_notification) = 0; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Host() {} 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class MESSAGE_CENTER_EXPORT Delegate { 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the notification associated with |notification_id| is 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // removed (i.e. closed by the user). 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void NotificationRemoved(const std::string& notifcation_id) = 0; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request to disable the extension associated with |notification_id|. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DisableExtension(const std::string& notifcation_id) = 0; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request to disable notifications from the source of |notification_id|. 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DisableNotificationsFromSource( 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& notifcation_id) = 0; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request to show the notification settings (|notification_id| is used 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to identify the requesting browser context). 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ShowSettings(const std::string& notifcation_id) = 0; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the notification body is clicked on. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnClicked(const std::string& notifcation_id) = 0; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Delegate() {} 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |host| is expected to manage any notification bubbles. It may be NULL. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit MessageCenter(Host* host); 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~MessageCenter(); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called once to set the delegate. 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetDelegate(Delegate* delegate); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Informs the notification list whether the message center is visible. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This affects whether or not a message has been "read". 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetMessageCenterVisible(bool visible); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Accessors to notification_list_ 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t NotificationCount() const; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t UnreadNotificationCount() const; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasPopupNotifications() const; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds a new notification. |id| is a unique identifier, used to update or 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // remove notifications. |title| and |meesage| describe the notification text. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use SetNotificationImage to set the icon image. If |extension_id| is 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // provided then 'Disable extension' will appear in a dropdown menu and the 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // id will be used to disable notifications from the extension. Otherwise if 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |display_source| is provided, a menu item showing the source and allowing 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // notifications from that source to be disabled will be shown. All actual 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // disabling is handled by the Delegate. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddNotification(ui::notifications::NotificationType type, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& id, 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& title, 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& message, 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& display_source, 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& extension_id, 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::DictionaryValue* optional_fields); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates an existing notification with id = old_id and set its id to new_id. 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateNotification(const std::string& old_id, 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& new_id, 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& title, 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& message); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes an existing notification. 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveNotification(const std::string& id); 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the notification image. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetNotificationImage(const std::string& id, 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::ImageSkia& image); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NotificationList* notification_list() { return notification_list_.get(); } 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from NotificationList::Delegate. 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SendRemoveNotification(const std::string& id) OVERRIDE; 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SendRemoveAllNotifications() OVERRIDE; 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE; 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnNotificationClicked(const std::string& id) OVERRIDE; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual NotificationList* GetNotificationList() OVERRIDE; 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<NotificationList> notification_list_; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Host* host_; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate_; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MessageCenter); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace message_center 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 132