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