1 // Copyright 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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
6 #define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/prefs/pref_member.h"
10 #include "chrome/browser/status_icons/status_icon_menu_model.h"
11 #include "chrome/browser/status_icons/status_icon_observer.h"
12 #include "chrome/browser/ui/views/message_center/message_center_widget_delegate.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "ui/base/models/simple_menu_model.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/message_center/message_center_tray.h"
18 #include "ui/message_center/message_center_tray_delegate.h"
19 #include "ui/views/widget/widget_observer.h"
22 #include "base/threading/thread.h"
28 namespace message_center {
30 class MessagePopupCollection;
37 namespace message_center {
41 class DesktopPopupAlignmentDelegate;
42 class MessageCenterWidgetDelegate;
44 // A MessageCenterTrayDelegate implementation that exposes the MessageCenterTray
45 // via a system tray icon. The notification popups will be displayed in the
46 // corner of the screen and the message center will be displayed by the system
47 // tray icon on click.
48 class WebNotificationTray : public message_center::MessageCenterTrayDelegate,
49 public StatusIconObserver,
50 public base::SupportsWeakPtr<WebNotificationTray>,
51 public StatusIconMenuModel::Delegate {
53 explicit WebNotificationTray(PrefService* local_state);
54 ~WebNotificationTray() override;
56 message_center::MessageCenter* message_center();
58 // MessageCenterTrayDelegate implementation.
59 bool ShowPopups() override;
60 void HidePopups() override;
61 bool ShowMessageCenter() override;
62 void HideMessageCenter() override;
63 void OnMessageCenterTrayChanged() override;
64 bool ShowNotifierSettings() override;
65 bool IsContextMenuEnabled() const override;
67 // StatusIconObserver implementation.
68 void OnStatusIconClicked() override;
70 virtual void OnBalloonClicked() override;
72 // This shows a platform-specific balloon informing the user of the existence
73 // of the message center in the status tray area.
74 void DisplayFirstRunBalloon();
76 void EnforceStatusIconVisible();
79 // StatusIconMenuModel::Delegate implementation.
80 void ExecuteCommand(int command_id, int event_flags) override;
82 // Changes the icon and hovertext based on number of unread notifications.
83 void UpdateStatusIcon();
84 void SendHideMessageCenter();
85 void MarkMessageCenterHidden();
87 // Gets the point where the status icon was clicked.
88 gfx::Point mouse_click_point() { return mouse_click_point_; }
89 MessageCenterTray* GetMessageCenterTray() override;
92 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
93 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
94 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
95 ManyMessageCenterNotifications);
96 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
97 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManuallyCloseMessageCenter);
98 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, StatusIconBehavior);
100 PositionInfo GetPositionInfo();
102 void CreateStatusIcon(const gfx::ImageSkia& image,
103 const base::string16& tool_tip);
104 void DestroyStatusIcon();
105 void AddQuietModeMenu(StatusIcon* status_icon);
106 MessageCenterWidgetDelegate* GetMessageCenterWidgetDelegateForTest();
109 // This member variable keeps track of whether EnforceStatusIconVisible has
110 // been invoked on this machine, so the user still has control after we try
111 // promoting it the first time.
112 scoped_ptr<BooleanPrefMember> did_force_tray_visible_;
115 MessageCenterWidgetDelegate* message_center_delegate_;
116 scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
117 scoped_ptr<message_center::DesktopPopupAlignmentDelegate> alignment_delegate_;
119 StatusIcon* status_icon_;
120 StatusIconMenuModel* status_icon_menu_;
121 scoped_ptr<MessageCenterTray> message_center_tray_;
122 gfx::Point mouse_click_point_;
124 bool should_update_tray_content_;
125 bool last_quiet_mode_state_;
126 base::string16 title_;
128 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
131 } // namespace message_center
133 #endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_