summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-06 03:57:49 +0000
committerdewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-06 03:57:49 +0000
commit89846d8c1ecb22a19a3822d2a13e76dde4a2feb9 (patch)
treed6b05f5f05121b4d05c278ba3a087f9a7c61fbc7
parentf8bf4cccb0d8f3723a98a01fbf0453c4448c7a54 (diff)
downloadchromium_src-89846d8c1ecb22a19a3822d2a13e76dde4a2feb9.zip
chromium_src-89846d8c1ecb22a19a3822d2a13e76dde4a2feb9.tar.gz
chromium_src-89846d8c1ecb22a19a3822d2a13e76dde4a2feb9.tar.bz2
[Mac][Win] Hide notifications popups when entering fullscreen mode.
They currently remain until expiration which could be forever in the case of webkit notifications. TODO: chromeos. R=mukai@chromium.org, stevenjb@chromium.org TBR=johnnyg@chromium.org BUG=233752 Review URL: https://chromiumcodereview.appspot.com/19027005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215784 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/system/web_notification/web_notification_tray.cc4
-rw-r--r--ash/system/web_notification/web_notification_tray.h1
-rw-r--r--chrome/browser/notifications/message_center_notification_manager.cc20
-rw-r--r--chrome/browser/notifications/message_center_notification_manager.h11
-rw-r--r--chrome/browser/notifications/message_center_notifications_browsertest.cc29
-rw-r--r--chrome/browser/notifications/message_center_notifications_unittest_win.cc3
-rw-r--r--chrome/browser/notifications/notification_ui_manager_impl.h14
-rw-r--r--chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h1
-rw-r--r--chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.mm5
-rw-r--r--chrome/browser/ui/views/message_center/web_notification_tray.cc5
-rw-r--r--chrome/browser/ui/views/message_center/web_notification_tray.h3
-rw-r--r--ui/message_center/message_center_tray_delegate.h6
-rw-r--r--ui/message_center/message_center_tray_unittest.cc4
13 files changed, 98 insertions, 8 deletions
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc
index e59b241..2b33e44 100644
--- a/ash/system/web_notification/web_notification_tray.cc
+++ b/ash/system/web_notification/web_notification_tray.cc
@@ -538,6 +538,10 @@ bool WebNotificationTray::ShowNotifierSettings() {
return ShowMessageCenterInternal(true /* show_settings */);
}
+message_center::MessageCenterTray* WebNotificationTray::GetMessageCenterTray() {
+ return message_center_tray_.get();
+}
+
bool WebNotificationTray::IsPressed() {
return IsMessageCenterBubbleVisible();
}
diff --git a/ash/system/web_notification/web_notification_tray.h b/ash/system/web_notification/web_notification_tray.h
index 0044875..d8b2fd3 100644
--- a/ash/system/web_notification/web_notification_tray.h
+++ b/ash/system/web_notification/web_notification_tray.h
@@ -107,6 +107,7 @@ class ASH_EXPORT WebNotificationTray
virtual bool ShowPopups() OVERRIDE;
virtual void HidePopups() OVERRIDE;
virtual bool ShowNotifierSettings() OVERRIDE;
+ virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE;
// Overridden from TrayBackgroundView.
virtual bool IsPressed() OVERRIDE;
diff --git a/chrome/browser/notifications/message_center_notification_manager.cc b/chrome/browser/notifications/message_center_notification_manager.cc
index 0ccc840..b249f49 100644
--- a/chrome/browser/notifications/message_center_notification_manager.cc
+++ b/chrome/browser/notifications/message_center_notification_manager.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
@@ -19,6 +20,8 @@
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/extensions/extension_set.h"
#include "chrome/common/pref_names.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "ui/message_center/message_center_style.h"
@@ -55,6 +58,9 @@ MessageCenterNotificationManager::MessageCenterNotificationManager(
// views.Other platforms have global ownership and Create will return NULL.
tray_.reset(message_center::CreateMessageCenterTray());
#endif
+ registrar_.Add(this,
+ chrome::NOTIFICATION_FULLSCREEN_CHANGED,
+ content::NotificationService::AllSources());
}
MessageCenterNotificationManager::~MessageCenterNotificationManager() {
@@ -328,6 +334,20 @@ void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest(
tray_.reset(delegate);
}
+void MessageCenterNotificationManager::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ if (type == chrome::NOTIFICATION_FULLSCREEN_CHANGED) {
+ const bool is_fullscreen = *content::Details<bool>(details).ptr();
+
+ if (is_fullscreen && tray_.get() && tray_->GetMessageCenterTray())
+ tray_->GetMessageCenterTray()->HidePopupBubble();
+ } else {
+ NotificationUIManagerImpl::Observe(type, source, details);
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
// ImageDownloads
diff --git a/chrome/browser/notifications/message_center_notification_manager.h b/chrome/browser/notifications/message_center_notification_manager.h
index 89493a2..91701d2 100644
--- a/chrome/browser/notifications/message_center_notification_manager.h
+++ b/chrome/browser/notifications/message_center_notification_manager.h
@@ -16,6 +16,8 @@
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/notification_ui_manager_impl.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_observer.h"
#include "ui/message_center/message_center_tray_delegate.h"
@@ -81,6 +83,12 @@ class MessageCenterNotificationManager
void SetMessageCenterTrayDelegateForTest(
message_center::MessageCenterTrayDelegate* delegate);
+ protected:
+ // content::NotificationObserver override.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
private:
class ImageDownloadsObserver {
public:
@@ -214,6 +222,9 @@ class MessageCenterNotificationManager
scoped_ptr<MessageCenterSettingsController> settings_controller_;
+ // Registrar for the other kind of notifications (event signaling).
+ content::NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager);
};
diff --git a/chrome/browser/notifications/message_center_notifications_browsertest.cc b/chrome/browser/notifications/message_center_notifications_browsertest.cc
index 28b4728..03f8012 100644
--- a/chrome/browser/notifications/message_center_notifications_browsertest.cc
+++ b/chrome/browser/notifications/message_center_notifications_browsertest.cc
@@ -10,6 +10,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/notifications/message_center_notification_manager.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
@@ -17,6 +18,9 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_source.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_switches.h"
#include "ui/message_center/message_center_util.h"
@@ -405,4 +409,29 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest,
delegate->Release();
}
+#if !defined(OS_CHROMEOS) && defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_HideWhenFullscreenEnabled HideWhenFullscreenEnabled
+#else
+#define MAYBE_HideWhenFullscreenEnabled DISABLED_HideWhenFullscreenEnabled
+#endif
+
+IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest,
+ MAYBE_HideWhenFullscreenEnabled) {
+ EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter());
+
+ TestDelegate* delegate;
+ manager()->Add(CreateTestNotification("n", &delegate), profile());
+
+ EXPECT_EQ("Display_", delegate->log());
+ EXPECT_TRUE(message_center()->HasPopupNotifications());
+ bool is_fullscreen = true;
+ // Cast so that Observe() is public.
+ content::NotificationObserver* observer =
+ static_cast<content::NotificationObserver*>(manager());
+ observer->Observe(chrome::NOTIFICATION_FULLSCREEN_CHANGED,
+ content::Source<Profile>(profile()),
+ content::Details<bool>(&is_fullscreen));
+ EXPECT_FALSE(message_center()->HasPopupNotifications());
+}
+
#endif // !defined(OS_MACOSX)
diff --git a/chrome/browser/notifications/message_center_notifications_unittest_win.cc b/chrome/browser/notifications/message_center_notifications_unittest_win.cc
index 130fd9f..fd674e63 100644
--- a/chrome/browser/notifications/message_center_notifications_unittest_win.cc
+++ b/chrome/browser/notifications/message_center_notifications_unittest_win.cc
@@ -41,6 +41,9 @@ class FakeMessageCenterTrayDelegate : public MessageCenterTrayDelegate {
virtual bool ShowMessageCenter() OVERRIDE { return true; }
virtual bool ShowNotifierSettings() OVERRIDE { return true; }
virtual void HideMessageCenter() OVERRIDE {}
+ virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE {
+ return &tray_;
+ }
bool displayed_first_run_balloon() const {
return displayed_first_run_balloon_;
diff --git a/chrome/browser/notifications/notification_ui_manager_impl.h b/chrome/browser/notifications/notification_ui_manager_impl.h
index a56d439..23e0a78 100644
--- a/chrome/browser/notifications/notification_ui_manager_impl.h
+++ b/chrome/browser/notifications/notification_ui_manager_impl.h
@@ -58,23 +58,23 @@ class NotificationUIManagerImpl
Profile* profile) = 0;
// Replace an existing notification of the same id with this one if
- // applicable; subclass returns 'true' if the replacement happened.
+ // applicable. Subclass returns 'true' if the replacement happened.
virtual bool UpdateNotification(const Notification& notification,
Profile* profile) = 0;
- // Attempts to display notifications from the show_queue. Invoked by subclass
- // if it previously returned 'false' from ShowNotifications, which may happen
- // when there is no room to show another notification. When room appears, the
- // subclass should call this method to cause an attempt to show more
- // notifications from the waiting queue.
+ // Attempts to display notifications from the show_queue. Invoked by
+ // subclasses if they previously returned 'false' from ShowNotifications,
+ // which may happen when there is no room to show another notification. When
+ // room appears, the subclass should call this method to cause an attempt to
+ // show more notifications from the waiting queue.
void CheckAndShowNotifications();
- private:
// content::NotificationObserver override.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ private:
// Attempts to display notifications from the show_queue.
void ShowNotifications();
diff --git a/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h b/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h
index 2b4daf1..a01164f 100644
--- a/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h
+++ b/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h
@@ -39,6 +39,7 @@ class MessageCenterTrayBridge :
virtual bool ShowMessageCenter() OVERRIDE;
virtual void HideMessageCenter() OVERRIDE;
virtual bool ShowNotifierSettings() OVERRIDE;
+ virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE;
message_center::MessageCenter* message_center() { return message_center_; }
diff --git a/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.mm b/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.mm
index 2ece534..9185998 100644
--- a/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.mm
+++ b/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.mm
@@ -85,6 +85,11 @@ bool MessageCenterTrayBridge::ShowNotifierSettings() {
return false;
}
+message_center::MessageCenterTray*
+MessageCenterTrayBridge::GetMessageCenterTray() {
+ return tray_.get();
+}
+
void MessageCenterTrayBridge::UpdateStatusItem() {
if (!status_item_view_) {
status_item_view_.reset([[MCStatusItemView alloc] init]);
diff --git a/chrome/browser/ui/views/message_center/web_notification_tray.cc b/chrome/browser/ui/views/message_center/web_notification_tray.cc
index 2d2058a..b3faf1a 100644
--- a/chrome/browser/ui/views/message_center/web_notification_tray.cc
+++ b/chrome/browser/ui/views/message_center/web_notification_tray.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/status_icons/status_icon.h"
#include "chrome/browser/status_icons/status_tray.h"
+#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h"
#include "grit/chromium_strings.h"
#include "grit/theme_resources.h"
@@ -289,6 +290,10 @@ PositionInfo WebNotificationTray::GetPositionInfo() {
return pos_info;
}
+MessageCenterTray* WebNotificationTray::GetMessageCenterTray() {
+ return message_center_tray_.get();
+}
+
void WebNotificationTray::CreateStatusIcon(const gfx::ImageSkia& image,
const string16& tool_tip) {
if (status_icon_)
diff --git a/chrome/browser/ui/views/message_center/web_notification_tray.h b/chrome/browser/ui/views/message_center/web_notification_tray.h
index 1bc6fa4..040f9a6 100644
--- a/chrome/browser/ui/views/message_center/web_notification_tray.h
+++ b/chrome/browser/ui/views/message_center/web_notification_tray.h
@@ -8,6 +8,8 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/status_icons/status_icon_observer.h"
#include "chrome/browser/ui/views/message_center/message_center_widget_delegate.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/rect.h"
#include "ui/message_center/message_center_tray.h"
@@ -69,6 +71,7 @@ class WebNotificationTray : public message_center::MessageCenterTrayDelegate,
// Gets the point where the status icon was clicked.
gfx::Point mouse_click_point() { return mouse_click_point_; }
+ virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE;
private:
FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
diff --git a/ui/message_center/message_center_tray_delegate.h b/ui/message_center/message_center_tray_delegate.h
index 85b2469..bd5c885 100644
--- a/ui/message_center/message_center_tray_delegate.h
+++ b/ui/message_center/message_center_tray_delegate.h
@@ -9,6 +9,8 @@
namespace message_center {
+class MessageCenterTray;
+
// A MessageCenterTrayDelegate class is responsible for managing the various UI
// surfaces that should be displayed when the MessageCenter is changed.
class MESSAGE_CENTER_EXPORT MessageCenterTrayDelegate {
@@ -37,7 +39,9 @@ class MESSAGE_CENTER_EXPORT MessageCenterTrayDelegate {
// Show a platform-specific UI that informs the user how to open the message
// center.
- virtual void DisplayFirstRunBalloon() {};
+ virtual void DisplayFirstRunBalloon() {}
+
+ virtual MessageCenterTray* GetMessageCenterTray() = 0;
};
} // namespace message_center
diff --git a/ui/message_center/message_center_tray_unittest.cc b/ui/message_center/message_center_tray_unittest.cc
index bf2005b..108cee7 100644
--- a/ui/message_center/message_center_tray_unittest.cc
+++ b/ui/message_center/message_center_tray_unittest.cc
@@ -31,6 +31,10 @@ class MockDelegate : public MessageCenterTrayDelegate {
return false;
}
+ virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE {
+ return NULL;
+ }
+
bool show_popups_success_;
bool show_message_center_success_;