Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / message_center / web_notification_tray.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
6 #define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
7
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"
20
21 #if defined(OS_WIN)
22 #include "base/threading/thread.h"
23 #endif
24
25 class PrefService;
26 class StatusIcon;
27
28 namespace message_center {
29 class MessageCenter;
30 class MessagePopupCollection;
31 }
32
33 namespace views {
34 class Widget;
35 }
36
37 namespace message_center {
38
39 struct PositionInfo;
40
41 class DesktopPopupAlignmentDelegate;
42 class MessageCenterWidgetDelegate;
43
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 {
52  public:
53   explicit WebNotificationTray(PrefService* local_state);
54   ~WebNotificationTray() override;
55
56   message_center::MessageCenter* message_center();
57
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;
66
67   // StatusIconObserver implementation.
68   void OnStatusIconClicked() override;
69 #if defined(OS_WIN)
70   virtual void OnBalloonClicked() override;
71
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();
75
76   void EnforceStatusIconVisible();
77 #endif
78
79   // StatusIconMenuModel::Delegate implementation.
80   void ExecuteCommand(int command_id, int event_flags) override;
81
82   // Changes the icon and hovertext based on number of unread notifications.
83   void UpdateStatusIcon();
84   void SendHideMessageCenter();
85   void MarkMessageCenterHidden();
86
87   // Gets the point where the status icon was clicked.
88   gfx::Point mouse_click_point() { return mouse_click_point_; }
89   MessageCenterTray* GetMessageCenterTray() override;
90
91  private:
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);
99
100   PositionInfo GetPositionInfo();
101
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();
107
108 #if defined(OS_WIN)
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_;
113 #endif
114
115   MessageCenterWidgetDelegate* message_center_delegate_;
116   scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
117   scoped_ptr<message_center::DesktopPopupAlignmentDelegate> alignment_delegate_;
118
119   StatusIcon* status_icon_;
120   StatusIconMenuModel* status_icon_menu_;
121   scoped_ptr<MessageCenterTray> message_center_tray_;
122   gfx::Point mouse_click_point_;
123
124   bool should_update_tray_content_;
125   bool last_quiet_mode_state_;
126   base::string16 title_;
127
128   DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
129 };
130
131 }  // namespace message_center
132
133 #endif  // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_