web_notification_tray.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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 25class PrefService; 26class StatusIcon; 27 28namespace message_center { 29class MessageCenter; 30class MessagePopupCollection; 31} 32 33namespace views { 34class Widget; 35} 36 37namespace message_center { 38 39struct PositionInfo; 40 41class MessageCenterWidgetDelegate; 42 43// A MessageCenterTrayDelegate implementation that exposes the MessageCenterTray 44// via a system tray icon. The notification popups will be displayed in the 45// corner of the screen and the message center will be displayed by the system 46// tray icon on click. 47class WebNotificationTray : public message_center::MessageCenterTrayDelegate, 48 public StatusIconObserver, 49 public base::SupportsWeakPtr<WebNotificationTray>, 50 public StatusIconMenuModel::Delegate { 51 public: 52 explicit WebNotificationTray(PrefService* local_state); 53 virtual ~WebNotificationTray(); 54 55 message_center::MessageCenter* message_center(); 56 57 // MessageCenterTrayDelegate implementation. 58 virtual bool ShowPopups() OVERRIDE; 59 virtual void HidePopups() OVERRIDE; 60 virtual bool ShowMessageCenter() OVERRIDE; 61 virtual void HideMessageCenter() OVERRIDE; 62 virtual void OnMessageCenterTrayChanged() OVERRIDE; 63 virtual bool ShowNotifierSettings() OVERRIDE; 64 virtual bool IsContextMenuEnabled() const OVERRIDE; 65 66 // StatusIconObserver implementation. 67 virtual void OnStatusIconClicked() OVERRIDE; 68#if defined(OS_WIN) 69 virtual void OnBalloonClicked() OVERRIDE; 70 71 // This shows a platform-specific balloon informing the user of the existence 72 // of the message center in the status tray area. 73 void DisplayFirstRunBalloon(); 74 75 void EnforceStatusIconVisible(); 76#endif 77 78 // StatusIconMenuModel::Delegate implementation. 79 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 80 81 // Changes the icon and hovertext based on number of unread notifications. 82 void UpdateStatusIcon(); 83 void SendHideMessageCenter(); 84 void MarkMessageCenterHidden(); 85 86 // Gets the point where the status icon was clicked. 87 gfx::Point mouse_click_point() { return mouse_click_point_; } 88 virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE; 89 90 private: 91 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); 92 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); 93 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, 94 ManyMessageCenterNotifications); 95 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); 96 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManuallyCloseMessageCenter); 97 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, StatusIconBehavior); 98 99 PositionInfo GetPositionInfo(); 100 101 void CreateStatusIcon(const gfx::ImageSkia& image, 102 const base::string16& tool_tip); 103 void DestroyStatusIcon(); 104 void AddQuietModeMenu(StatusIcon* status_icon); 105 MessageCenterWidgetDelegate* GetMessageCenterWidgetDelegateForTest(); 106 107#if defined(OS_WIN) 108 // This member variable keeps track of whether EnforceStatusIconVisible has 109 // been invoked on this machine, so the user still has control after we try 110 // promoting it the first time. 111 scoped_ptr<BooleanPrefMember> did_force_tray_visible_; 112#endif 113 114 MessageCenterWidgetDelegate* message_center_delegate_; 115 scoped_ptr<message_center::MessagePopupCollection> popup_collection_; 116 117 StatusIcon* status_icon_; 118 StatusIconMenuModel* status_icon_menu_; 119 scoped_ptr<MessageCenterTray> message_center_tray_; 120 gfx::Point mouse_click_point_; 121 122 bool should_update_tray_content_; 123 bool last_quiet_mode_state_; 124 base::string16 title_; 125 126 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); 127}; 128 129} // namespace message_center 130 131#endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ 132