message_center.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/observer_list.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/native_widget_types.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/message_center_export.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/notification_list.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_types.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue; 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Interface to manage the NotificationList. The client (e.g. Chrome) calls 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// [Add|Remove|Update]Notification to create and update notifications in the 23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// list. It also sends those changes to its observers when a notification 24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// is shown, closed, or clicked on. 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// It can also implement Delegate to ask platform-dependent features like 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// disabling extensions or opening settings. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace message_center { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MessageCenterObserver; 31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class NotificationList; 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MESSAGE_CENTER_EXPORT MessageCenter { 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creates the global message center object. 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static void Initialize(); 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the global message center object. Initialize must be called first. 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static MessageCenter* Get(); 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Destroys the global message_center object. 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static void Shutdown(); 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class MESSAGE_CENTER_EXPORT Delegate { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~Delegate(); 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request to disable the extension associated with |notification_id|. 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DisableExtension(const std::string& notification_id) = 0; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request to disable notifications from the source of |notification_id|. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DisableNotificationsFromSource( 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& notification_id) = 0; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request to show the notification settings (|notification_id| is used 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to identify the requesting browser context). 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void ShowSettings(const std::string& notification_id) = 0; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Request to show the notification settings dialog. |context| is necessary 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to create a new window. 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void ShowSettingsDialog(gfx::NativeView context) = 0; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called to set the delegate. Generally called only once, except in tests. 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Changing the delegate does not affect notifications in its 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // NotificationList. 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetDelegate(Delegate* delegate) = 0; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Management of the observer list. 70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void AddObserver(MessageCenterObserver* observer) = 0; 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RemoveObserver(MessageCenterObserver* observer) = 0; 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Queries of current notification list status. 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual size_t NotificationCount() const = 0; 75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual size_t UnreadNotificationCount() const = 0; 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool HasPopupNotifications() const = 0; 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool HasNotification(const std::string& id) = 0; 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool IsQuietMode() const = 0; 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool HasClickedListener(const std::string& id) = 0; 80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Getters of the current notifications. 82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual const NotificationList::Notifications& GetNotifications() = 0; 83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual NotificationList::PopupNotifications GetPopupNotifications() = 0; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Basic operations of notification: add/remove/update. 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds a new notification. |id| is a unique identifier, used to update or 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // remove notifications. |title| and |meesage| describe the notification text. 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Use SetNotificationIcon, SetNotificationImage, or SetNotificationButtonIcon 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to set images. If |extension_id| is provided then 'Disable extension' will 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // appear in a dropdown menu and the id will be used to disable notifications 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // from the extension. Otherwise if |display_source| is provided, a menu item 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // showing the source and allowing notifications from that source to be 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // disabled will be shown. All actual disabling is handled by the Delegate. 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void AddNotification(NotificationType type, 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& id, 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const string16& title, 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const string16& message, 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const string16& display_source, 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& extension_id, 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const base::DictionaryValue* optional_fields, 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NotificationDelegate* delegate) = 0; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates an existing notification with id = old_id and set its id to new_id. 10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // |delegate| and |optional_fields| can be NULL in case of no updates on 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // those fields. 10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void UpdateNotification(const std::string& old_id, 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& new_id, 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const string16& title, 11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const string16& message, 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const base::DictionaryValue* optional_fields, 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NotificationDelegate* delegate) = 0; 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes an existing notification. 115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RemoveNotification(const std::string& id, bool by_user) = 0; 116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RemoveAllNotifications(bool by_user) = 0; 117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Sets the icon image. Icon appears at the top-left of the notification. 119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetNotificationIcon(const std::string& notification_id, 120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Image& image) = 0; 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Sets the large image for the notifications of type == TYPE_IMAGE. Specified 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // image will appear below of the notification. 124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetNotificationImage(const std::string& notification_id, 125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Image& image) = 0; 126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 127a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Sets the image for the icon of the specific action button. 128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetNotificationButtonIcon(const std::string& notification_id, 129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int button_index, 130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Image& image) = 0; 131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Operations happening especially from GUIs: click, expand, disable, 133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // and settings. 134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // TODO(mukai): settings can be in another class? 135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void DisableNotificationsByExtension(const std::string& id) = 0; 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void DisableNotificationsByUrl(const std::string& id) = 0; 137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ShowNotificationSettings(const std::string& id) = 0; 138c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ShowNotificationSettingsDialog(gfx::NativeView context) = 0; 139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ExpandNotification(const std::string& id) = 0; 140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ClickOnNotification(const std::string& id) = 0; 141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ClickOnNotificationButton(const std::string& id, 142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int button_index) = 0; 143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void MarkSinglePopupAsShown(const std::string& id, 144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool mark_notification_as_read) = 0; 145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void DisplayedNotification(const std::string& id) = 0; 146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetQuietMode(bool in_quiet_mode) = 0; 147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0; 148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Informs the notification list whether the message center is visible. 149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // This affects whether or not a message has been "read". 150c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetMessageCenterVisible(bool visible) = 0; 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MessageCenter(); 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~MessageCenter(); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MessageCenter); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace message_center 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 163