Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / message_center / web_notification_tray.cc
index 6c6675f..ced0fea 100644 (file)
@@ -5,12 +5,14 @@
 #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"
@@ -121,23 +123,34 @@ Alignment GetAnchorAlignment(const gfx::Rect& work_area, gfx::Point corner) {
 }  // 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();
 }
@@ -147,12 +160,14 @@ message_center::MessageCenter* WebNotificationTray::message_center() {
 }
 
 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_ =
@@ -186,6 +201,12 @@ bool WebNotificationTray::ShowNotifierSettings() {
   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();
@@ -232,9 +253,9 @@ void WebNotificationTray::UpdateStatusIcon() {
 
   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 {
@@ -315,7 +336,7 @@ MessageCenterTray* WebNotificationTray::GetMessageCenterTray() {
 }
 
 void WebNotificationTray::CreateStatusIcon(const gfx::ImageSkia& image,
-                                           const string16& tool_tip) {
+                                           const base::string16& tool_tip) {
   if (status_icon_)
     return;