[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 1 | // Copyright (c) 2013 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 | |
[email protected] | 7097278 | 2013-03-08 20:22:10 | [diff] [blame] | 5 | #ifndef UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_ |
| 6 | #define UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_ |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 7 | |
avi | c326e4f5 | 2015-12-24 17:44:49 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 10 | #include <string> |
lwchkg | 99addc85 | 2016-02-10 16:14:55 | [diff] [blame] | 11 | #include <vector> |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 12 | |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
avi | c326e4f5 | 2015-12-24 17:44:49 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | 3b3a3064 | 2013-06-11 19:48:38 | [diff] [blame] | 15 | #include "base/strings/string16.h" |
[email protected] | a87200d | 2013-03-07 01:04:11 | [diff] [blame] | 16 | #include "ui/gfx/image/image.h" |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 17 | #include "ui/message_center/message_center_export.h" |
[email protected] | 15999de | 2013-06-28 12:44:38 | [diff] [blame] | 18 | #include "url/gurl.h" |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 19 | |
mukai | 523714f | 2014-10-17 01:10:48 | [diff] [blame] | 20 | class MessageCenterNotificationsTest; |
[email protected] | 4d11b08b | 2014-01-27 22:19:07 | [diff] [blame] | 21 | class MessageCenterTrayBridgeTest; |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 22 | |
| 23 | namespace ash { |
| 24 | class WebNotificationTrayTest; |
| 25 | } |
| 26 | |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 27 | namespace message_center { |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 28 | namespace test { |
| 29 | class MessagePopupCollectionTest; |
| 30 | } |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 31 | |
mukai | 523714f | 2014-10-17 01:10:48 | [diff] [blame] | 32 | class MessageCenterNotificationManagerTest; |
[email protected] | 7097278 | 2013-03-08 20:22:10 | [diff] [blame] | 33 | class NotifierSettingsDelegate; |
| 34 | class NotifierSettingsProvider; |
| 35 | |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 36 | // Brings up the settings dialog and returns a weak reference to the delegate, |
| 37 | // which is typically the view. If the dialog already exists, it is brought to |
| 38 | // the front, otherwise it is created. |
| 39 | MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings( |
| 40 | NotifierSettingsProvider* provider, |
| 41 | gfx::NativeView context); |
| 42 | |
| 43 | // The struct to distinguish the notifiers. |
| 44 | struct MESSAGE_CENTER_EXPORT NotifierId { |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 45 | enum NotifierType { |
| 46 | APPLICATION, |
| 47 | WEB_PAGE, |
[email protected] | c77be0a | 2013-05-01 12:58:26 | [diff] [blame] | 48 | SYSTEM_COMPONENT, |
| 49 | }; |
| 50 | |
[email protected] | de22ffea | 2013-12-07 03:34:29 | [diff] [blame] | 51 | // Constructor for non WEB_PAGE type. |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 52 | NotifierId(NotifierType type, const std::string& id); |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 53 | |
| 54 | // Constructor for WEB_PAGE type. |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 55 | explicit NotifierId(const GURL& url); |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 56 | |
vmpstr | 0ae825e7 | 2016-02-25 20:31:31 | [diff] [blame] | 57 | NotifierId(const NotifierId& other); |
| 58 | |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 59 | bool operator==(const NotifierId& other) const; |
[email protected] | a3b599f | 2013-12-13 09:03:12 | [diff] [blame] | 60 | // Allows NotifierId to be used as a key in std::map. |
| 61 | bool operator<(const NotifierId& other) const; |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 62 | |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 63 | NotifierType type; |
| 64 | |
[email protected] | de22ffea | 2013-12-07 03:34:29 | [diff] [blame] | 65 | // The identifier of the app notifier. Empty if it's WEB_PAGE. |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 66 | std::string id; |
| 67 | |
| 68 | // The URL pattern of the notifer. |
| 69 | GURL url; |
| 70 | |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 71 | // The identifier of the profile where the notification is created. This is |
| 72 | // used for ChromeOS multi-profile support and can be empty. |
| 73 | std::string profile_id; |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 74 | |
| 75 | private: |
mukai | 523714f | 2014-10-17 01:10:48 | [diff] [blame] | 76 | friend class MessageCenterNotificationManagerTest; |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 77 | friend class MessageCenterTrayTest; |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 78 | friend class NotificationControllerTest; |
| 79 | friend class PopupCollectionTest; |
| 80 | friend class TrayViewControllerTest; |
mukai | 523714f | 2014-10-17 01:10:48 | [diff] [blame] | 81 | friend class ::MessageCenterNotificationsTest; |
| 82 | friend class ::MessageCenterTrayBridgeTest; |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 83 | friend class ash::WebNotificationTrayTest; |
mukai | 523714f | 2014-10-17 01:10:48 | [diff] [blame] | 84 | friend class test::MessagePopupCollectionTest; |
[email protected] | 218fe37 | 2013-12-11 03:22:12 | [diff] [blame] | 85 | FRIEND_TEST_ALL_PREFIXES(PopupControllerTest, Creation); |
| 86 | FRIEND_TEST_ALL_PREFIXES(NotificationListTest, UnreadCountNoNegative); |
| 87 | FRIEND_TEST_ALL_PREFIXES(NotificationListTest, TestHasNotificationOfType); |
| 88 | |
| 89 | // The default constructor which doesn't specify the notifier. Used for tests. |
| 90 | NotifierId(); |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | // The struct to hold the information of notifiers. The information will be |
| 94 | // used by NotifierSettingsView. |
| 95 | struct MESSAGE_CENTER_EXPORT Notifier { |
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 96 | Notifier(const NotifierId& notifier_id, |
| 97 | const base::string16& name, |
| 98 | bool enabled); |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 99 | ~Notifier(); |
| 100 | |
| 101 | NotifierId notifier_id; |
[email protected] | c77be0a | 2013-05-01 12:58:26 | [diff] [blame] | 102 | |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 103 | // The human-readable name of the notifier such like the extension name. |
| 104 | // It can be empty. |
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 105 | base::string16 name; |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 106 | |
| 107 | // True if the source is allowed to send notifications. True is default. |
| 108 | bool enabled; |
| 109 | |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 110 | // The icon image of the notifier. The extension icon or favicon. |
[email protected] | a87200d | 2013-03-07 01:04:11 | [diff] [blame] | 111 | gfx::Image icon; |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 112 | |
| 113 | private: |
| 114 | DISALLOW_COPY_AND_ASSIGN(Notifier); |
| 115 | }; |
| 116 | |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 117 | struct MESSAGE_CENTER_EXPORT NotifierGroup { |
| 118 | NotifierGroup(const gfx::Image& icon, |
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 119 | const base::string16& name, |
lwchkg | 99addc85 | 2016-02-10 16:14:55 | [diff] [blame] | 120 | const base::string16& login_info); |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 121 | ~NotifierGroup(); |
| 122 | |
| 123 | // Icon of a notifier group. |
| 124 | const gfx::Image icon; |
| 125 | |
| 126 | // Display name of a notifier group. |
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 127 | const base::string16 name; |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 128 | |
| 129 | // More display information about the notifier group. |
[email protected] | 2aadf21 | 2013-12-18 20:03:44 | [diff] [blame] | 130 | base::string16 login_info; |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 131 | |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 132 | private: |
| 133 | DISALLOW_COPY_AND_ASSIGN(NotifierGroup); |
| 134 | }; |
| 135 | |
[email protected] | 940c2ba | 2013-06-20 17:13:58 | [diff] [blame] | 136 | // An observer class implemented by the view of the NotifierSettings to get |
| 137 | // notified when the controller has changed data. |
| 138 | class MESSAGE_CENTER_EXPORT NotifierSettingsObserver { |
| 139 | public: |
| 140 | // Called when an icon in the controller has been updated. |
[email protected] | f0e2a929 | 2013-07-02 23:04:00 | [diff] [blame] | 141 | virtual void UpdateIconImage(const NotifierId& notifier_id, |
[email protected] | 940c2ba | 2013-06-20 17:13:58 | [diff] [blame] | 142 | const gfx::Image& icon) = 0; |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 143 | |
| 144 | // Called when any change happens to the set of notifier groups. |
| 145 | virtual void NotifierGroupChanged() = 0; |
[email protected] | 7fe808b | 2014-05-22 03:38:21 | [diff] [blame] | 146 | |
| 147 | // Called when a notifier is enabled or disabled. |
| 148 | virtual void NotifierEnabledChanged(const NotifierId& notifier_id, |
| 149 | bool enabled) = 0; |
[email protected] | 940c2ba | 2013-06-20 17:13:58 | [diff] [blame] | 150 | }; |
| 151 | |
[email protected] | 7097278 | 2013-03-08 20:22:10 | [diff] [blame] | 152 | // A class used by NotifierSettingsView to integrate with a setting system |
| 153 | // for the clients of this module. |
| 154 | class MESSAGE_CENTER_EXPORT NotifierSettingsProvider { |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 155 | public: |
lwchkg | 99addc85 | 2016-02-10 16:14:55 | [diff] [blame] | 156 | virtual ~NotifierSettingsProvider() {} |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 157 | |
[email protected] | 940c2ba | 2013-06-20 17:13:58 | [diff] [blame] | 158 | // Sets the delegate. |
| 159 | virtual void AddObserver(NotifierSettingsObserver* observer) = 0; |
| 160 | virtual void RemoveObserver(NotifierSettingsObserver* observer) = 0; |
| 161 | |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 162 | // Returns the number of notifier groups available. |
| 163 | virtual size_t GetNotifierGroupCount() const = 0; |
| 164 | |
| 165 | // Requests the model for a particular notifier group. |
| 166 | virtual const message_center::NotifierGroup& GetNotifierGroupAt( |
| 167 | size_t index) const = 0; |
| 168 | |
[email protected] | 23bc585 | 2013-08-08 22:18:25 | [diff] [blame] | 169 | // Returns true if the notifier group at |index| is active. |
| 170 | virtual bool IsNotifierGroupActiveAt(size_t index) const = 0; |
| 171 | |
[email protected] | 76c589d6 | 2013-08-07 14:29:52 | [diff] [blame] | 172 | // Informs the settings provider that further requests to GetNotifierList |
| 173 | // should return notifiers for the specified notifier group. |
| 174 | virtual void SwitchToNotifierGroup(size_t index) = 0; |
| 175 | |
| 176 | // Requests the currently active notifier group. |
| 177 | virtual const message_center::NotifierGroup& GetActiveNotifierGroup() |
| 178 | const = 0; |
| 179 | |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 180 | // Collects the current notifier list and fills to |notifiers|. Caller takes |
| 181 | // the ownership of the elements of |notifiers|. |
| 182 | virtual void GetNotifierList(std::vector<Notifier*>* notifiers) = 0; |
| 183 | |
| 184 | // Called when the |enabled| for the |notifier| has been changed by user |
| 185 | // operation. |
| 186 | virtual void SetNotifierEnabled(const Notifier& notifier, bool enabled) = 0; |
| 187 | |
| 188 | // Called when the settings window is closed. |
| 189 | virtual void OnNotifierSettingsClosing() = 0; |
[email protected] | 550168f | 2013-11-02 03:37:56 | [diff] [blame] | 190 | |
| 191 | // Called to determine if a particular notifier can respond to a request for |
| 192 | // more information. |
| 193 | virtual bool NotifierHasAdvancedSettings(const NotifierId& notifier_id) |
| 194 | const = 0; |
| 195 | |
| 196 | // Called upon request for more information about a particular notifier. |
| 197 | virtual void OnNotifierAdvancedSettingsRequested( |
| 198 | const NotifierId& notifier_id, |
| 199 | const std::string* notification_id) = 0; |
[email protected] | ed30198 | 2013-02-15 11:06:57 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | } // namespace message_center |
| 203 | |
[email protected] | 7097278 | 2013-03-08 20:22:10 | [diff] [blame] | 204 | #endif // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_ |