#include "chrome/browser/ui/views/message_center/web_notification_tray.h"
#include "base/i18n/number_formatting.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/status_icons/status_icon.h"
#include "chrome/browser/status_icons/status_icon_menu_model.h"
#include "chrome/browser/status_icons/status_tray.h"
+#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
#include "grit/chromium_strings.h"
#include "grit/theme_resources.h"
} // namespace internal
MessageCenterTrayDelegate* CreateMessageCenterTray() {
- return new WebNotificationTray();
+ return new WebNotificationTray(g_browser_process->local_state());
}
-WebNotificationTray::WebNotificationTray()
+WebNotificationTray::WebNotificationTray(PrefService* local_state)
: message_center_delegate_(NULL),
status_icon_(NULL),
status_icon_menu_(NULL),
- message_center_visible_(false),
should_update_tray_content_(true) {
message_center_tray_.reset(
new MessageCenterTray(this, g_browser_process->message_center()));
last_quiet_mode_state_ = message_center()->IsQuietMode();
+ popup_collection_.reset(new message_center::MessagePopupCollection(
+ NULL, message_center(), message_center_tray_.get(), false));
+
+#if defined(OS_WIN)
+ // |local_state| can be NULL in tests.
+ if (local_state) {
+ did_force_tray_visible_.reset(new BooleanPrefMember());
+ did_force_tray_visible_->Init(prefs::kMessageCenterForcedOnTaskbar,
+ local_state);
+ }
+#endif
}
WebNotificationTray::~WebNotificationTray() {
// Reset this early so that delegated events during destruction don't cause
// problems.
+ popup_collection_.reset();
message_center_tray_.reset();
DestroyStatusIcon();
}
}
bool WebNotificationTray::ShowPopups() {
- popup_collection_.reset(new message_center::MessagePopupCollection(
- NULL, message_center(), message_center_tray_.get(), false));
+ popup_collection_->DoUpdateIfPossible();
return true;
}
-void WebNotificationTray::HidePopups() { popup_collection_.reset(); }
+void WebNotificationTray::HidePopups() {
+ DCHECK(popup_collection_.get());
+ popup_collection_->MarkAllPopupsShown();
+}
bool WebNotificationTray::ShowMessageCenter() {
message_center_delegate_ =
return true;
}
+bool WebNotificationTray::IsContextMenuEnabled() const {
+ // It can always return true because the notifications are invisible if
+ // the context menu shouldn't be enabled, such as in the lock screen.
+ return true;
+}
+
void WebNotificationTray::OnMessageCenterTrayChanged() {
if (status_icon_) {
bool quiet_mode_state = message_center()->IsQuietMode();
int unread_notifications = message_center()->UnreadNotificationCount();
- string16 tool_tip;
+ base::string16 tool_tip;
if (unread_notifications > 0) {
- string16 str_unread_count = base::FormatNumber(unread_notifications);
+ base::string16 str_unread_count = base::FormatNumber(unread_notifications);
tool_tip = l10n_util::GetStringFUTF16(IDS_MESSAGE_CENTER_TOOLTIP_UNREAD,
str_unread_count);
} else {
}
void WebNotificationTray::CreateStatusIcon(const gfx::ImageSkia& image,
- const string16& tool_tip) {
+ const base::string16& tool_tip) {
if (status_icon_)
return;