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