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