blob: f01a069f852eb8da736c546b7811b20b5662406f [file] [log] [blame]
[email protected]ed301982013-02-15 11:06:571// 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]70972782013-03-08 20:22:105#ifndef UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
6#define UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
[email protected]ed301982013-02-15 11:06:577
avic326e4f52015-12-24 17:44:498#include <stddef.h>
9
[email protected]ed301982013-02-15 11:06:5710#include <string>
lwchkg99addc852016-02-10 16:14:5511#include <vector>
[email protected]ed301982013-02-15 11:06:5712
[email protected]218fe372013-12-11 03:22:1213#include "base/gtest_prod_util.h"
avic326e4f52015-12-24 17:44:4914#include "base/macros.h"
[email protected]3b3a30642013-06-11 19:48:3815#include "base/strings/string16.h"
[email protected]a87200d2013-03-07 01:04:1116#include "ui/gfx/image/image.h"
[email protected]ed301982013-02-15 11:06:5717#include "ui/message_center/message_center_export.h"
[email protected]15999de2013-06-28 12:44:3818#include "url/gurl.h"
[email protected]ed301982013-02-15 11:06:5719
mukai523714f2014-10-17 01:10:4820class MessageCenterNotificationsTest;
[email protected]4d11b08b2014-01-27 22:19:0721class MessageCenterTrayBridgeTest;
[email protected]218fe372013-12-11 03:22:1222
23namespace ash {
24class WebNotificationTrayTest;
25}
26
[email protected]ed301982013-02-15 11:06:5727namespace message_center {
[email protected]218fe372013-12-11 03:22:1228namespace test {
29class MessagePopupCollectionTest;
30}
[email protected]ed301982013-02-15 11:06:5731
mukai523714f2014-10-17 01:10:4832class MessageCenterNotificationManagerTest;
[email protected]70972782013-03-08 20:22:1033class NotifierSettingsDelegate;
34class NotifierSettingsProvider;
35
[email protected]f0e2a9292013-07-02 23:04:0036// 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.
39MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings(
40 NotifierSettingsProvider* provider,
41 gfx::NativeView context);
42
43// The struct to distinguish the notifiers.
44struct MESSAGE_CENTER_EXPORT NotifierId {
[email protected]ed301982013-02-15 11:06:5745 enum NotifierType {
46 APPLICATION,
47 WEB_PAGE,
[email protected]c77be0a2013-05-01 12:58:2648 SYSTEM_COMPONENT,
49 };
50
[email protected]de22ffea2013-12-07 03:34:2951 // Constructor for non WEB_PAGE type.
[email protected]f0e2a9292013-07-02 23:04:0052 NotifierId(NotifierType type, const std::string& id);
[email protected]ed301982013-02-15 11:06:5753
54 // Constructor for WEB_PAGE type.
[email protected]f0e2a9292013-07-02 23:04:0055 explicit NotifierId(const GURL& url);
[email protected]ed301982013-02-15 11:06:5756
vmpstr0ae825e72016-02-25 20:31:3157 NotifierId(const NotifierId& other);
58
[email protected]f0e2a9292013-07-02 23:04:0059 bool operator==(const NotifierId& other) const;
[email protected]a3b599f2013-12-13 09:03:1260 // Allows NotifierId to be used as a key in std::map.
61 bool operator<(const NotifierId& other) const;
[email protected]ed301982013-02-15 11:06:5762
[email protected]f0e2a9292013-07-02 23:04:0063 NotifierType type;
64
[email protected]de22ffea2013-12-07 03:34:2965 // The identifier of the app notifier. Empty if it's WEB_PAGE.
[email protected]ed301982013-02-15 11:06:5766 std::string id;
67
68 // The URL pattern of the notifer.
69 GURL url;
70
[email protected]33aa554d2013-12-06 00:47:5371 // 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]218fe372013-12-11 03:22:1274
75 private:
mukai523714f2014-10-17 01:10:4876 friend class MessageCenterNotificationManagerTest;
[email protected]218fe372013-12-11 03:22:1277 friend class MessageCenterTrayTest;
[email protected]218fe372013-12-11 03:22:1278 friend class NotificationControllerTest;
79 friend class PopupCollectionTest;
80 friend class TrayViewControllerTest;
mukai523714f2014-10-17 01:10:4881 friend class ::MessageCenterNotificationsTest;
82 friend class ::MessageCenterTrayBridgeTest;
[email protected]218fe372013-12-11 03:22:1283 friend class ash::WebNotificationTrayTest;
mukai523714f2014-10-17 01:10:4884 friend class test::MessagePopupCollectionTest;
[email protected]218fe372013-12-11 03:22:1285 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]f0e2a9292013-07-02 23:04:0091};
92
93// The struct to hold the information of notifiers. The information will be
94// used by NotifierSettingsView.
95struct MESSAGE_CENTER_EXPORT Notifier {
[email protected]2aadf212013-12-18 20:03:4496 Notifier(const NotifierId& notifier_id,
97 const base::string16& name,
98 bool enabled);
[email protected]f0e2a9292013-07-02 23:04:0099 ~Notifier();
100
101 NotifierId notifier_id;
[email protected]c77be0a2013-05-01 12:58:26102
[email protected]ed301982013-02-15 11:06:57103 // The human-readable name of the notifier such like the extension name.
104 // It can be empty.
[email protected]2aadf212013-12-18 20:03:44105 base::string16 name;
[email protected]ed301982013-02-15 11:06:57106
107 // True if the source is allowed to send notifications. True is default.
108 bool enabled;
109
[email protected]ed301982013-02-15 11:06:57110 // The icon image of the notifier. The extension icon or favicon.
[email protected]a87200d2013-03-07 01:04:11111 gfx::Image icon;
[email protected]ed301982013-02-15 11:06:57112
113 private:
114 DISALLOW_COPY_AND_ASSIGN(Notifier);
115};
116
[email protected]76c589d62013-08-07 14:29:52117struct MESSAGE_CENTER_EXPORT NotifierGroup {
118 NotifierGroup(const gfx::Image& icon,
[email protected]2aadf212013-12-18 20:03:44119 const base::string16& name,
lwchkg99addc852016-02-10 16:14:55120 const base::string16& login_info);
[email protected]76c589d62013-08-07 14:29:52121 ~NotifierGroup();
122
123 // Icon of a notifier group.
124 const gfx::Image icon;
125
126 // Display name of a notifier group.
[email protected]2aadf212013-12-18 20:03:44127 const base::string16 name;
[email protected]76c589d62013-08-07 14:29:52128
129 // More display information about the notifier group.
[email protected]2aadf212013-12-18 20:03:44130 base::string16 login_info;
[email protected]76c589d62013-08-07 14:29:52131
[email protected]76c589d62013-08-07 14:29:52132 private:
133 DISALLOW_COPY_AND_ASSIGN(NotifierGroup);
134};
135
[email protected]940c2ba2013-06-20 17:13:58136// An observer class implemented by the view of the NotifierSettings to get
137// notified when the controller has changed data.
138class MESSAGE_CENTER_EXPORT NotifierSettingsObserver {
139 public:
140 // Called when an icon in the controller has been updated.
[email protected]f0e2a9292013-07-02 23:04:00141 virtual void UpdateIconImage(const NotifierId& notifier_id,
[email protected]940c2ba2013-06-20 17:13:58142 const gfx::Image& icon) = 0;
[email protected]76c589d62013-08-07 14:29:52143
144 // Called when any change happens to the set of notifier groups.
145 virtual void NotifierGroupChanged() = 0;
[email protected]7fe808b2014-05-22 03:38:21146
147 // Called when a notifier is enabled or disabled.
148 virtual void NotifierEnabledChanged(const NotifierId& notifier_id,
149 bool enabled) = 0;
[email protected]940c2ba2013-06-20 17:13:58150};
151
[email protected]70972782013-03-08 20:22:10152// A class used by NotifierSettingsView to integrate with a setting system
153// for the clients of this module.
154class MESSAGE_CENTER_EXPORT NotifierSettingsProvider {
[email protected]ed301982013-02-15 11:06:57155 public:
lwchkg99addc852016-02-10 16:14:55156 virtual ~NotifierSettingsProvider() {}
[email protected]76c589d62013-08-07 14:29:52157
[email protected]940c2ba2013-06-20 17:13:58158 // Sets the delegate.
159 virtual void AddObserver(NotifierSettingsObserver* observer) = 0;
160 virtual void RemoveObserver(NotifierSettingsObserver* observer) = 0;
161
[email protected]76c589d62013-08-07 14:29:52162 // 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]23bc5852013-08-08 22:18:25169 // Returns true if the notifier group at |index| is active.
170 virtual bool IsNotifierGroupActiveAt(size_t index) const = 0;
171
[email protected]76c589d62013-08-07 14:29:52172 // 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]ed301982013-02-15 11:06:57180 // 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]550168f2013-11-02 03:37:56190
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]ed301982013-02-15 11:06:57200};
201
202} // namespace message_center
203
[email protected]70972782013-03-08 20:22:10204#endif // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_