message_center.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 6#define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 7 8#include <string> 9 10#include "base/memory/scoped_ptr.h" 11#include "base/observer_list.h" 12#include "ui/gfx/native_widget_types.h" 13#include "ui/message_center/message_center_export.h" 14#include "ui/message_center/notification_list.h" 15#include "ui/message_center/notification_types.h" 16 17namespace base { 18class DictionaryValue; 19} 20 21// Interface to manage the NotificationList. The client (e.g. Chrome) calls 22// [Add|Remove|Update]Notification to create and update notifications in the 23// list. It also sends those changes to its observers when a notification 24// is shown, closed, or clicked on. 25// It can also implement Delegate to ask platform-dependent features like 26// disabling extensions or opening settings. 27 28namespace message_center { 29 30class MessageCenterObserver; 31class NotificationList; 32 33class MESSAGE_CENTER_EXPORT MessageCenter { 34 public: 35 // Creates the global message center object. 36 static void Initialize(); 37 38 // Returns the global message center object. Initialize must be called first. 39 static MessageCenter* Get(); 40 41 // Destroys the global message_center object. 42 static void Shutdown(); 43 44 class MESSAGE_CENTER_EXPORT Delegate { 45 public: 46 virtual ~Delegate(); 47 48 // Request to disable the extension associated with |notification_id|. 49 virtual void DisableExtension(const std::string& notification_id) = 0; 50 51 // Request to disable notifications from the source of |notification_id|. 52 virtual void DisableNotificationsFromSource( 53 const std::string& notification_id) = 0; 54 55 // Request to show the notification settings (|notification_id| is used 56 // to identify the requesting browser context). 57 virtual void ShowSettings(const std::string& notification_id) = 0; 58 59 // Request to show the notification settings dialog. |context| is necessary 60 // to create a new window. 61 virtual void ShowSettingsDialog(gfx::NativeView context) = 0; 62 }; 63 64 // Called to set the delegate. Generally called only once, except in tests. 65 // Changing the delegate does not affect notifications in its 66 // NotificationList. 67 virtual void SetDelegate(Delegate* delegate) = 0; 68 69 // Management of the observer list. 70 virtual void AddObserver(MessageCenterObserver* observer) = 0; 71 virtual void RemoveObserver(MessageCenterObserver* observer) = 0; 72 73 // Queries of current notification list status. 74 virtual size_t NotificationCount() const = 0; 75 virtual size_t UnreadNotificationCount() const = 0; 76 virtual bool HasPopupNotifications() const = 0; 77 virtual bool HasNotification(const std::string& id) = 0; 78 virtual bool IsQuietMode() const = 0; 79 virtual bool HasClickedListener(const std::string& id) = 0; 80 81 // Getters of the current notifications. 82 virtual const NotificationList::Notifications& GetNotifications() = 0; 83 virtual NotificationList::PopupNotifications GetPopupNotifications() = 0; 84 85 // Basic operations of notification: add/remove/update. 86 87 // Adds a new notification. |id| is a unique identifier, used to update or 88 // remove notifications. |title| and |meesage| describe the notification text. 89 // Use SetNotificationIcon, SetNotificationImage, or SetNotificationButtonIcon 90 // to set images. If |extension_id| is provided then 'Disable extension' will 91 // appear in a dropdown menu and the id will be used to disable notifications 92 // from the extension. Otherwise if |display_source| is provided, a menu item 93 // showing the source and allowing notifications from that source to be 94 // disabled will be shown. All actual disabling is handled by the Delegate. 95 virtual void AddNotification(NotificationType type, 96 const std::string& id, 97 const string16& title, 98 const string16& message, 99 const string16& display_source, 100 const std::string& extension_id, 101 const base::DictionaryValue* optional_fields, 102 NotificationDelegate* delegate) = 0; 103 104 // Updates an existing notification with id = old_id and set its id to new_id. 105 // |delegate| and |optional_fields| can be NULL in case of no updates on 106 // those fields. 107 virtual void UpdateNotification(const std::string& old_id, 108 const std::string& new_id, 109 const string16& title, 110 const string16& message, 111 const base::DictionaryValue* optional_fields, 112 NotificationDelegate* delegate) = 0; 113 114 // Removes an existing notification. 115 virtual void RemoveNotification(const std::string& id, bool by_user) = 0; 116 virtual void RemoveAllNotifications(bool by_user) = 0; 117 118 // Sets the icon image. Icon appears at the top-left of the notification. 119 virtual void SetNotificationIcon(const std::string& notification_id, 120 const gfx::Image& image) = 0; 121 122 // Sets the large image for the notifications of type == TYPE_IMAGE. Specified 123 // image will appear below of the notification. 124 virtual void SetNotificationImage(const std::string& notification_id, 125 const gfx::Image& image) = 0; 126 127 // Sets the image for the icon of the specific action button. 128 virtual void SetNotificationButtonIcon(const std::string& notification_id, 129 int button_index, 130 const gfx::Image& image) = 0; 131 132 // Operations happening especially from GUIs: click, expand, disable, 133 // and settings. 134 // TODO(mukai): settings can be in another class? 135 virtual void DisableNotificationsByExtension(const std::string& id) = 0; 136 virtual void DisableNotificationsByUrl(const std::string& id) = 0; 137 virtual void ShowNotificationSettings(const std::string& id) = 0; 138 virtual void ShowNotificationSettingsDialog(gfx::NativeView context) = 0; 139 virtual void ExpandNotification(const std::string& id) = 0; 140 virtual void ClickOnNotification(const std::string& id) = 0; 141 virtual void ClickOnNotificationButton(const std::string& id, 142 int button_index) = 0; 143 virtual void MarkSinglePopupAsShown(const std::string& id, 144 bool mark_notification_as_read) = 0; 145 virtual void DisplayedNotification(const std::string& id) = 0; 146 virtual void SetQuietMode(bool in_quiet_mode) = 0; 147 virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0; 148 // Informs the notification list whether the message center is visible. 149 // This affects whether or not a message has been "read". 150 virtual void SetMessageCenterVisible(bool visible) = 0; 151 152 protected: 153 MessageCenter(); 154 virtual ~MessageCenter(); 155 156 private: 157 DISALLOW_COPY_AND_ASSIGN(MessageCenter); 158}; 159 160} // namespace message_center 161 162#endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 163