diff options
62 files changed, 295 insertions, 4437 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index fa7e70d..1e87a41 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -8271,9 +8271,6 @@ The following plug-in is unresponsive: <ph name="PLUGIN_NAME">$1 <message name="IDS_NOTIFICATIONS_HEADER" desc="Label for Notifications exception management page on Content Settings dialog"> Notifications exceptions </message> - <message name="IDS_NOTIFICATIONS_SETTINGS_BUTTON" desc="Label for the Settings button for Notifications tab of Content Settings dialog."> - Settings... - </message> <message name="IDS_NOTIFICATIONS_ALLOW_RADIO" desc="A radio button in Content Settings dialog to allow all sites to show notifications."> Allow all sites to show desktop notifications </message> @@ -12871,30 +12868,9 @@ Some features may be unavailable. Please check that the profile exists and you <message name="IDS_NOTIFICATION_OPTIONS_MENU_LABEL" desc="Text for the menu option"> Options </message> - <message name="IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE" desc="Text for the menu option to revoke notification permission."> - Disable notifications from <ph name="site">$1<ex>mail.google.com</ex></ph> - </message> <message name="IDS_NOTIFICATION_BALLOON_ENABLE_MESSAGE" desc="Text for the menu option to enable notification permission."> Enable notifications from <ph name="site">$1<ex>mail.google.com</ex></ph> </message> - <message name="IDS_NOTIFICATION_CHOOSE_POSITION" desc="Menu label for position choice submenu."> - Choose position - </message> - <message name="IDS_NOTIFICATION_POSITION_DEFAULT" desc="Menu label for positioning in default location"> - Use default - </message> - <message name="IDS_NOTIFICATION_POSITION_LOWER_LEFT" desc="Menu label for positioning in lower left corner"> - Lower left - </message> - <message name="IDS_NOTIFICATION_POSITION_LOWER_RIGHT" desc="Menu label for positioning in lower right corner"> - Lower right - </message> - <message name="IDS_NOTIFICATION_POSITION_UPPER_LEFT" desc="Menu label for positioning in upper left corner"> - Upper left - </message> - <message name="IDS_NOTIFICATION_POSITION_UPPER_RIGHT" desc="Menu label for positioning in upper right corner"> - Upper right - </message> <message name="IDS_NOTIFICATION_WELCOME_BODY" desc="Notification body for the Welcome Notification"> Stay connected to what you need to know, across all devices. </message> diff --git a/chrome/app/theme/default_100_percent/notification_wrench.png b/chrome/app/theme/default_100_percent/notification_wrench.png Binary files differdeleted file mode 100644 index 6b90d1a..0000000 --- a/chrome/app/theme/default_100_percent/notification_wrench.png +++ /dev/null diff --git a/chrome/app/theme/default_100_percent/notification_wrench_hover.png b/chrome/app/theme/default_100_percent/notification_wrench_hover.png Binary files differdeleted file mode 100644 index 7df11ba..0000000 --- a/chrome/app/theme/default_100_percent/notification_wrench_hover.png +++ /dev/null diff --git a/chrome/app/theme/default_100_percent/notification_wrench_pressed.png b/chrome/app/theme/default_100_percent/notification_wrench_pressed.png Binary files differdeleted file mode 100644 index 88d2875..0000000 --- a/chrome/app/theme/default_100_percent/notification_wrench_pressed.png +++ /dev/null diff --git a/chrome/app/theme/default_200_percent/notification_wrench.png b/chrome/app/theme/default_200_percent/notification_wrench.png Binary files differdeleted file mode 100644 index 28e9baa..0000000 --- a/chrome/app/theme/default_200_percent/notification_wrench.png +++ /dev/null diff --git a/chrome/app/theme/default_200_percent/notification_wrench_hover.png b/chrome/app/theme/default_200_percent/notification_wrench_hover.png Binary files differdeleted file mode 100644 index 79560df..0000000 --- a/chrome/app/theme/default_200_percent/notification_wrench_hover.png +++ /dev/null diff --git a/chrome/app/theme/default_200_percent/notification_wrench_pressed.png b/chrome/app/theme/default_200_percent/notification_wrench_pressed.png Binary files differdeleted file mode 100644 index 9c6ade4..0000000 --- a/chrome/app/theme/default_200_percent/notification_wrench_pressed.png +++ /dev/null diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index 5419909..fc6c465 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -114,9 +114,6 @@ <structure type="chrome_scaled_image" name="IDR_BACK_H" file="common/browser_back_hover.png" /> <structure type="chrome_scaled_image" name="IDR_BACK_P" file="common/browser_back_pressed.png" /> </if> - <structure type="chrome_scaled_image" name="IDR_BALLOON_WRENCH" file="notification_wrench.png" /> - <structure type="chrome_scaled_image" name="IDR_BALLOON_WRENCH_H" file="notification_wrench_hover.png" /> - <structure type="chrome_scaled_image" name="IDR_BALLOON_WRENCH_P" file="notification_wrench_pressed.png" /> <structure type="chrome_scaled_image" name="IDR_BLOCKED_COOKIES" file="common/blocked_cookies.png" /> <structure type="chrome_scaled_image" name="IDR_BLOCKED_DOWNLOADS" file="common/blocked_downloads.png" /> <structure type="chrome_scaled_image" name="IDR_BLOCKED_IMAGES" file="common/blocked_images.png" /> diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc index 9dbe637a..b4b0cec 100644 --- a/chrome/browser/background/background_contents_service.cc +++ b/chrome/browser/background/background_contents_service.cc @@ -72,7 +72,7 @@ void CloseBalloon(const std::string& balloon_id) { g_browser_process->notification_ui_manager(); bool cancelled ALLOW_UNUSED = notification_ui_manager->CancelById(balloon_id); #if defined(ENABLE_NOTIFICATIONS) - if (cancelled && message_center::IsRichNotificationEnabled()) { + if (cancelled) { // TODO(dewittj): Add this functionality to the notification UI manager's // API. g_browser_process->message_center()->SetVisibility( diff --git a/chrome/browser/background/background_contents_service_unittest.cc b/chrome/browser/background/background_contents_service_unittest.cc index 68f35cb..9f7d075 100644 --- a/chrome/browser/background/background_contents_service_unittest.cc +++ b/chrome/browser/background/background_contents_service_unittest.cc @@ -162,9 +162,6 @@ class BackgroundContentsServiceNotificationTest // Overridden from testing::Test virtual void SetUp() { BrowserWithTestWindowTest::SetUp(); - if (!NotificationUIManager::DelegatesToMessageCenter()) - return; - // In ChromeOS environment, BrowserWithTestWindowTest initializes // MessageCenter. #if !defined(OS_CHROMEOS) @@ -348,9 +345,6 @@ TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) { #if defined(ENABLE_NOTIFICATIONS) && !defined(TOOLKIT_GTK) TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloon) { - if (!NotificationUIManager::DelegatesToMessageCenter()) - return; - scoped_refptr<extensions::Extension> extension = extension_test_util::LoadManifest("image_loading_tracker", "app.json"); ASSERT_TRUE(extension.get()); @@ -363,9 +357,6 @@ TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloon) { // Verify if a test notification can show the default extension icon for // a crash notification for an extension without icon. TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloonNoIcon) { - if (!NotificationUIManager::DelegatesToMessageCenter()) - return; - // Extension manifest file with no 'icon' field. scoped_refptr<extensions::Extension> extension = extension_test_util::LoadManifest("app", "manifest.json"); diff --git a/chrome/browser/chrome_notification_types.h b/chrome/browser/chrome_notification_types.h index 3805fbc..496cf21 100644 --- a/chrome/browser/chrome_notification_types.h +++ b/chrome/browser/chrome_notification_types.h @@ -590,20 +590,6 @@ enum NotificationType { // found update. NOTIFICATION_EXTENSION_UPDATE_FOUND, - // Desktop Notifications --------------------------------------------------- - - // This notification is sent when a balloon is connected to a renderer - // process to render the balloon contents. The source is a - // Source<BalloonHost> with a pointer to the the balloon. A - // NOTIFY_BALLOON_DISCONNECTED is guaranteed before the source pointer - // becomes junk. No details expected. - NOTIFICATION_NOTIFY_BALLOON_CONNECTED, - - // This message is sent after a balloon is disconnected from the renderer - // process. The source is a Source<BalloonHost> with a pointer to the - // balloon host (the pointer is usable). No details are expected. - NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, - // Upgrade notifications --------------------------------------------------- // Sent when Chrome believes an update has been installed and available for diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc index 1ee1c10..14bfc28 100644 --- a/chrome/browser/extensions/api/notifications/notifications_api.cc +++ b/chrome/browser/extensions/api/notifications/notifications_api.cc @@ -254,66 +254,64 @@ bool NotificationsApiFunction::CreateNotification( // Then, handle any optional data that's been provided. message_center::RichNotificationData optional_fields; - if (message_center::IsRichNotificationEnabled()) { - if (options->priority.get()) - optional_fields.priority = *options->priority; - - if (options->event_time.get()) - optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); - - if (options->buttons.get()) { - // Currently we allow up to 2 buttons. - size_t number_of_buttons = options->buttons->size(); - number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; - - for (size_t i = 0; i < number_of_buttons; i++) { - message_center::ButtonInfo info( - base::UTF8ToUTF16((*options->buttons)[i]->title)); - NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), - &info.icon); - optional_fields.buttons.push_back(info); - } + if (options->priority.get()) + optional_fields.priority = *options->priority; + + if (options->event_time.get()) + optional_fields.timestamp = base::Time::FromJsTime(*options->event_time); + + if (options->buttons.get()) { + // Currently we allow up to 2 buttons. + size_t number_of_buttons = options->buttons->size(); + number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; + + for (size_t i = 0; i < number_of_buttons; i++) { + message_center::ButtonInfo info( + base::UTF8ToUTF16((*options->buttons)[i]->title)); + NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), + &info.icon); + optional_fields.buttons.push_back(info); } + } - if (options->context_message) { - optional_fields.context_message = - base::UTF8ToUTF16(*options->context_message); - } + if (options->context_message) { + optional_fields.context_message = + base::UTF8ToUTF16(*options->context_message); + } - bool has_image = NotificationBitmapToGfxImage(options->image_bitmap.get(), - &optional_fields.image); - // We should have an image if and only if the type is an image type. - if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) - return false; + bool has_image = NotificationBitmapToGfxImage(options->image_bitmap.get(), + &optional_fields.image); + // We should have an image if and only if the type is an image type. + if (has_image != (type == message_center::NOTIFICATION_TYPE_IMAGE)) + return false; - // We should have list items if and only if the type is a multiple type. - bool has_list_items = options->items.get() && options->items->size() > 0; - if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE)) - return false; + // We should have list items if and only if the type is a multiple type. + bool has_list_items = options->items.get() && options->items->size() > 0; + if (has_list_items != (type == message_center::NOTIFICATION_TYPE_MULTIPLE)) + return false; - if (options->progress.get() != NULL) { - // We should have progress if and only if the type is a progress type. - if (type != message_center::NOTIFICATION_TYPE_PROGRESS) { - SetError(kUnexpectedProgressValueForNonProgressType); - return false; - } - optional_fields.progress = *options->progress; - // Progress value should range from 0 to 100. - if (optional_fields.progress < 0 || optional_fields.progress > 100) { - SetError(kInvalidProgressValue); - return false; - } + if (options->progress.get() != NULL) { + // We should have progress if and only if the type is a progress type. + if (type != message_center::NOTIFICATION_TYPE_PROGRESS) { + SetError(kUnexpectedProgressValueForNonProgressType); + return false; + } + optional_fields.progress = *options->progress; + // Progress value should range from 0 to 100. + if (optional_fields.progress < 0 || optional_fields.progress > 100) { + SetError(kInvalidProgressValue); + return false; } + } - if (has_list_items) { - using api::notifications::NotificationItem; - std::vector<linked_ptr<NotificationItem> >::iterator i; - for (i = options->items->begin(); i != options->items->end(); ++i) { - message_center::NotificationItem item( - base::UTF8ToUTF16(i->get()->title), - base::UTF8ToUTF16(i->get()->message)); - optional_fields.items.push_back(item); - } + if (has_list_items) { + using api::notifications::NotificationItem; + std::vector<linked_ptr<NotificationItem> >::iterator i; + for (i = options->items->begin(); i != options->items->end(); ++i) { + message_center::NotificationItem item( + base::UTF8ToUTF16(i->get()->title), + base::UTF8ToUTF16(i->get()->message)); + optional_fields.items.push_back(item); } } @@ -360,73 +358,71 @@ bool NotificationsApiFunction::UpdateNotification( notification->set_icon(icon); } - if (message_center::IsRichNotificationEnabled()) { - if (options->priority) - notification->set_priority(*options->priority); - - if (options->event_time) - notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); - - if (options->buttons) { - // Currently we allow up to 2 buttons. - size_t number_of_buttons = options->buttons->size(); - number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; - - std::vector<message_center::ButtonInfo> buttons; - for (size_t i = 0; i < number_of_buttons; i++) { - message_center::ButtonInfo button( - base::UTF8ToUTF16((*options->buttons)[i]->title)); - NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), - &button.icon); - buttons.push_back(button); - } - notification->set_buttons(buttons); - } + if (options->priority) + notification->set_priority(*options->priority); - if (options->context_message) { - notification->set_context_message( - base::UTF8ToUTF16(*options->context_message)); - } + if (options->event_time) + notification->set_timestamp(base::Time::FromJsTime(*options->event_time)); - gfx::Image image; - if (NotificationBitmapToGfxImage(options->image_bitmap.get(), &image)) { - // We should have an image if and only if the type is an image type. - if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE) - return false; - notification->set_image(image); + if (options->buttons) { + // Currently we allow up to 2 buttons. + size_t number_of_buttons = options->buttons->size(); + number_of_buttons = number_of_buttons > 2 ? 2 : number_of_buttons; + + std::vector<message_center::ButtonInfo> buttons; + for (size_t i = 0; i < number_of_buttons; i++) { + message_center::ButtonInfo button( + base::UTF8ToUTF16((*options->buttons)[i]->title)); + NotificationBitmapToGfxImage((*options->buttons)[i]->icon_bitmap.get(), + &button.icon); + buttons.push_back(button); } + notification->set_buttons(buttons); + } + + if (options->context_message) { + notification->set_context_message( + base::UTF8ToUTF16(*options->context_message)); + } + + gfx::Image image; + if (NotificationBitmapToGfxImage(options->image_bitmap.get(), &image)) { + // We should have an image if and only if the type is an image type. + if (notification->type() != message_center::NOTIFICATION_TYPE_IMAGE) + return false; + notification->set_image(image); + } - if (options->progress) { - // We should have progress if and only if the type is a progress type. - if (notification->type() != message_center::NOTIFICATION_TYPE_PROGRESS) { - SetError(kUnexpectedProgressValueForNonProgressType); - return false; - } - int progress = *options->progress; - // Progress value should range from 0 to 100. - if (progress < 0 || progress > 100) { - SetError(kInvalidProgressValue); - return false; - } - notification->set_progress(progress); + if (options->progress) { + // We should have progress if and only if the type is a progress type. + if (notification->type() != message_center::NOTIFICATION_TYPE_PROGRESS) { + SetError(kUnexpectedProgressValueForNonProgressType); + return false; + } + int progress = *options->progress; + // Progress value should range from 0 to 100. + if (progress < 0 || progress > 100) { + SetError(kInvalidProgressValue); + return false; } + notification->set_progress(progress); + } + + if (options->items.get() && options->items->size() > 0) { + // We should have list items if and only if the type is a multiple type. + if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE) + return false; - if (options->items.get() && options->items->size() > 0) { - // We should have list items if and only if the type is a multiple type. - if (notification->type() != message_center::NOTIFICATION_TYPE_MULTIPLE) - return false; - - std::vector<message_center::NotificationItem> items; - using api::notifications::NotificationItem; - std::vector<linked_ptr<NotificationItem> >::iterator i; - for (i = options->items->begin(); i != options->items->end(); ++i) { - message_center::NotificationItem item( - base::UTF8ToUTF16(i->get()->title), - base::UTF8ToUTF16(i->get()->message)); - items.push_back(item); - } - notification->set_items(items); + std::vector<message_center::NotificationItem> items; + using api::notifications::NotificationItem; + std::vector<linked_ptr<NotificationItem> >::iterator i; + for (i = options->items->begin(); i != options->items->end(); ++i) { + message_center::NotificationItem item( + base::UTF8ToUTF16(i->get()->title), + base::UTF8ToUTF16(i->get()->message)); + items.push_back(item); } + notification->set_items(items); } // Then override if it's already set. diff --git a/chrome/browser/extensions/api/notifications/notifications_apitest.cc b/chrome/browser/extensions/api/notifications/notifications_apitest.cc index d859955..6456550 100644 --- a/chrome/browser/extensions/api/notifications/notifications_apitest.cc +++ b/chrome/browser/extensions/api/notifications/notifications_apitest.cc @@ -456,16 +456,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) { ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_; } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_TestByUser TestByUser -#else -#define MAYBE_TestByUser DISABLED_TestByUser -#endif - -IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestByUser) { - ASSERT_TRUE(message_center::IsRichNotificationEnabled()); - +IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) { const extensions::Extension* extension = LoadExtensionAndWait("notifications/api/by_user"); ASSERT_TRUE(extension) << message_; @@ -626,13 +617,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestProgressNotification) { } } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_TestPartialUpdate TestPartialUpdate -#else -#define MAYBE_TestPartialUpdate DISABLED_TestPartialUpdate -#endif -IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestPartialUpdate) { +IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestPartialUpdate) { scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); // Create a new notification. @@ -726,14 +711,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestPartialUpdate) { EXPECT_EQ(0u, notification->buttons().size()); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_TestGetPermissionLevel TestGetPermissionLevel -#else -#define MAYBE_TestGetPermissionLevel DISABLED_TestGetPermissionLevel -#endif - -IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetPermissionLevel) { +IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestGetPermissionLevel) { scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); // Get permission level for the extension whose notifications are enabled. @@ -786,15 +764,7 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetPermissionLevel) { } } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_TestOnPermissionLevelChanged TestOnPermissionLevelChanged -#else -#define MAYBE_TestOnPermissionLevelChanged DISABLED_TestOnPermissionLevelChanged -#endif - -IN_PROC_BROWSER_TEST_F(NotificationsApiTest, - MAYBE_TestOnPermissionLevelChanged) { +IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestOnPermissionLevelChanged) { const extensions::Extension* extension = LoadExtensionAndWait("notifications/api/permission"); ASSERT_TRUE(extension) << message_; diff --git a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc index c92f149..ccaf59e 100644 --- a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc +++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc @@ -5,11 +5,9 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/notifications/balloon.h" -#include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/balloon_host.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_delegate.h" +#include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" @@ -30,12 +28,6 @@ #include "ui/message_center/message_center_util.h" #include "ui/message_center/notification_list.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/notifications/notification_ui_manager.h" -#else -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" -#endif - using content::NavigationController; using content::WebContents; using extensions::Extension; @@ -137,69 +129,32 @@ class MAYBE_ExtensionCrashRecoveryTest : public ExtensionCrashRecoveryTestBase { protected: virtual void AcceptNotification(size_t index) OVERRIDE { - if (message_center::IsRichNotificationEnabled()) { - message_center::MessageCenter* message_center = - message_center::MessageCenter::Get(); - ASSERT_GT(message_center->NotificationCount(), index); - message_center::NotificationList::Notifications::reverse_iterator it = - message_center->GetVisibleNotifications().rbegin(); - for (size_t i=0; i < index; ++i) - it++; - std::string id = (*it)->id(); - message_center->ClickOnNotification(id); -#if defined(TOOLKIT_GTK) - } else { - Balloon* balloon = GetNotificationDelegate(index); - ASSERT_TRUE(balloon); - balloon->OnClick(); -#endif - } + message_center::MessageCenter* message_center = + message_center::MessageCenter::Get(); + ASSERT_GT(message_center->NotificationCount(), index); + message_center::NotificationList::Notifications::reverse_iterator it = + message_center->GetVisibleNotifications().rbegin(); + for (size_t i=0; i < index; ++i) + it++; + std::string id = (*it)->id(); + message_center->ClickOnNotification(id); WaitForExtensionLoad(); } virtual void CancelNotification(size_t index) OVERRIDE { - if (message_center::IsRichNotificationEnabled()) { - message_center::MessageCenter* message_center = - message_center::MessageCenter::Get(); - ASSERT_GT(message_center->NotificationCount(), index); - message_center::NotificationList::Notifications::reverse_iterator it = - message_center->GetVisibleNotifications().rbegin(); - for (size_t i=0; i < index; i++) { it++; } - ASSERT_TRUE(g_browser_process->notification_ui_manager()-> - CancelById((*it)->id())); -#if defined(TOOLKIT_GTK) - } else { - Balloon* balloon = GetNotificationDelegate(index); - ASSERT_TRUE(balloon); - std::string id = balloon->notification().notification_id(); - ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(id)); -#endif - } + message_center::MessageCenter* message_center = + message_center::MessageCenter::Get(); + ASSERT_GT(message_center->NotificationCount(), index); + message_center::NotificationList::Notifications::reverse_iterator it = + message_center->GetVisibleNotifications().rbegin(); + for (size_t i=0; i < index; i++) { it++; } + ASSERT_TRUE(g_browser_process->notification_ui_manager()-> + CancelById((*it)->id())); } virtual size_t CountBalloons() OVERRIDE { - if (message_center::IsRichNotificationEnabled()) - return message_center::MessageCenter::Get()->NotificationCount(); - -#if defined(TOOLKIT_GTK) - return BalloonNotificationUIManager::GetInstanceForTesting()-> - balloon_collection()->GetActiveBalloons().size(); -#else - CHECK(false); - return 0; -#endif + return message_center::MessageCenter::Get()->NotificationCount(); } - - private: -#if defined(TOOLKIT_GTK) - Balloon* GetNotificationDelegate(size_t index) { - BalloonNotificationUIManager* manager = - BalloonNotificationUIManager::GetInstanceForTesting(); - BalloonCollection::Balloons balloons = - manager->balloon_collection()->GetActiveBalloons(); - return index < balloons.size() ? balloons.at(index) : NULL; - } -#endif }; // Flaky: http://crbug.com/242167. diff --git a/chrome/browser/local_discovery/privet_notifications.cc b/chrome/browser/local_discovery/privet_notifications.cc index f242d1b..551f715 100644 --- a/chrome/browser/local_discovery/privet_notifications.cc +++ b/chrome/browser/local_discovery/privet_notifications.cc @@ -221,9 +221,7 @@ void PrivetNotificationService::DeviceCacheFlushed() { bool PrivetNotificationService::IsEnabled() { CommandLine* command_line = CommandLine::ForCurrentProcess(); return !command_line->HasSwitch(switches::kDisableDeviceDiscovery) && - !command_line->HasSwitch( - switches::kDisableDeviceDiscoveryNotifications) && - message_center::IsRichNotificationEnabled(); + !command_line->HasSwitch(switches::kDisableDeviceDiscoveryNotifications); } // static diff --git a/chrome/browser/notifications/balloon.cc b/chrome/browser/notifications/balloon.cc deleted file mode 100644 index 3da956b..0000000 --- a/chrome/browser/notifications/balloon.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/balloon.h" - -#include "base/logging.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/notification.h" -#include "chrome/browser/profiles/profile.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -#if !defined(USE_AURA) -// static -int BalloonView::GetHorizontalMargin() { - // TODO: implement for linux (non-aura) and mac. - return 0; -} -#endif - -Balloon::Balloon(const Notification& notification, Profile* profile, - BalloonCollection* collection) - : profile_(profile), - notification_(new Notification(notification)), - collection_(collection) { -} - -Balloon::~Balloon() { -} - -void Balloon::SetPosition(const gfx::Point& upper_left, bool reposition) { - position_ = upper_left; - if (reposition && balloon_view_.get()) - balloon_view_->RepositionToBalloon(); -} - -void Balloon::ResizeDueToAutoResize(const gfx::Size& size) { - collection_->ResizeBalloon(this, size); -} - -void Balloon::set_view(BalloonView* balloon_view) { - balloon_view_.reset(balloon_view); -} - -void Balloon::Show() { - notification_->Display(); - if (balloon_view_.get()) { - balloon_view_->Show(this); - balloon_view_->RepositionToBalloon(); - } -} - -void Balloon::Update(const Notification& notification) { - notification_->Close(false); - notification_.reset(new Notification(notification)); - notification_->Display(); - if (balloon_view_.get()) { - balloon_view_->Update(); - } -} - -void Balloon::OnClick() { - notification_->Click(); -} - -void Balloon::OnClose(bool by_user) { - notification_->Close(by_user); - collection_->OnBalloonClosed(this); -} - -void Balloon::OnButtonClick(int button_index) { - notification_->ButtonClick(button_index); -} - -void Balloon::CloseByScript() { - // A user-initiated close begins with the view and then closes this object; - // we simulate that with a script-initiated close but pass |by_user|=false. - DCHECK(balloon_view_.get()); - balloon_view_->Close(false); -} - -std::string Balloon::GetExtensionId() { - const ExtensionService* service = profile()->GetExtensionService(); - const extensions::Extension* extension = - service->extensions()->GetExtensionOrAppByURL( - notification().origin_url()); - return extension ? extension->id() : std::string(); -} diff --git a/chrome/browser/notifications/balloon.h b/chrome/browser/notifications/balloon.h deleted file mode 100644 index 51b520d..0000000 --- a/chrome/browser/notifications/balloon.h +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Handles the visible notification (or balloons). - -#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_H_ -#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_H_ - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -class Balloon; -class BalloonCollection; -class BalloonHost; -class Notification; -class Profile; - -// Interface for a view that displays a balloon. -class BalloonView { - public: - virtual ~BalloonView() {} - - // Show the view on the screen. - virtual void Show(Balloon* balloon) = 0; - - // Notify that the content of notification has chagned. - virtual void Update() = 0; - - // Reposition the view to match the position of its balloon. - virtual void RepositionToBalloon() = 0; - - // Close the view. - virtual void Close(bool by_user) = 0; - - // The total size of the view. - virtual gfx::Size GetSize() const = 0; - - // The host for the view's contents. May be NULL if an implementation does - // not have a host associated with it (i.e. does not do html rendering). - virtual BalloonHost* GetHost() const = 0; - - // Returns the horizontal margin the content is inset by. - static int GetHorizontalMargin(); -}; - -// Represents a Notification on the screen. -class Balloon { - public: - Balloon(const Notification& notification, - Profile* profile, - BalloonCollection* collection); - virtual ~Balloon(); - - const Notification& notification() const { return *notification_.get(); } - Profile* profile() const { return profile_; } - - gfx::Point GetPosition() const { - return position_ + offset_; - } - void SetPosition(const gfx::Point& upper_left, bool reposition); - - const gfx::Vector2d& offset() const { return offset_; } - void set_offset(const gfx::Vector2d& offset) { offset_ = offset; } - void add_offset(const gfx::Vector2d& offset) { offset_.Add(offset); } - - const gfx::Size& content_size() const { return content_size_; } - void set_content_size(const gfx::Size& size) { content_size_ = size; } - - const BalloonCollection* collection() const { return collection_; } - - const gfx::Size& min_scrollbar_size() const { return min_scrollbar_size_; } - void set_min_scrollbar_size(const gfx::Size& size) { - min_scrollbar_size_ = size; - } - - // Request a new content size for this balloon. This will get passed - // to the balloon collection for checking against available space and - // min/max restrictions. - void ResizeDueToAutoResize(const gfx::Size& size); - - // Provides a view for this balloon. Ownership transfers to this object. - void set_view(BalloonView* balloon_view); - - // Returns the balloon view associated with the balloon. - BalloonView* balloon_view() const { return balloon_view_.get(); } - - // Returns the viewing size for the balloon (content + frame). - gfx::Size GetViewSize() const { return balloon_view_->GetSize(); } - - // Shows the balloon. - virtual void Show(); - - // Notify that the content of notification has changed. - virtual void Update(const Notification& notification); - - // Called when the balloon is clicked by the user. - virtual void OnClick(); - - // Called when the user clicks a button in the balloon. - virtual void OnButtonClick(int button_index); - - // Called when the balloon is closed, either by user (through the UI) - // or by a script. - virtual void OnClose(bool by_user); - - // Called by script to cause the balloon to close. - virtual void CloseByScript(); - - // Returns the ID of the extension that created this balloon's notification. - std::string GetExtensionId(); - - private: - // Non-owned pointer to the profile. - Profile* profile_; - - // The notification being shown in this balloon. - scoped_ptr<Notification> notification_; - - // The collection that this balloon belongs to. Non-owned pointer. - BalloonCollection* collection_; - - // The actual UI element for the balloon. - scoped_ptr<BalloonView> balloon_view_; - - // Position and size of the balloon on the screen. - gfx::Point position_; - gfx::Size content_size_; - - // Temporary offset for balloons that need to be positioned in a non-standard - // position for keeping the close buttons under the mouse cursor. - gfx::Vector2d offset_; - - // Smallest size for this balloon where scrollbars will be shown. - gfx::Size min_scrollbar_size_; - - DISALLOW_COPY_AND_ASSIGN(Balloon); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_H_ diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc deleted file mode 100644 index 48059f5..0000000 --- a/chrome/browser/notifications/balloon_collection.cc +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/balloon_collection.h" - -BalloonCollection::BalloonCollection() - : space_change_listener_(NULL) { -} - -BalloonCollection::~BalloonCollection() { -} diff --git a/chrome/browser/notifications/balloon_collection.h b/chrome/browser/notifications/balloon_collection.h deleted file mode 100644 index 5d54b7d..0000000 --- a/chrome/browser/notifications/balloon_collection.h +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Handles the visible notification (or balloons). - -#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_ -#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_ - -#include <deque> -#include <string> - -#include "base/callback.h" - -class Balloon; -class GURL; -class Notification; -class Profile; - -namespace gfx { -class Size; -} - -class BalloonCollection { - public: - class BalloonSpaceChangeListener { - public: - virtual ~BalloonSpaceChangeListener() {} - - // Called when there is more or less space for balloons due to - // monitor size changes or balloons disappearing. - virtual void OnBalloonSpaceChanged() = 0; - }; - - // Do not change existing values without migration path; these - // are stored as integers in user preferences. - enum PositionPreference { - UPPER_RIGHT = 0, - LOWER_RIGHT = 1, - UPPER_LEFT = 2, - LOWER_LEFT = 3, - - // The default position is different on different platforms. - DEFAULT_POSITION = -1 - }; - - static BalloonCollection* Create(); - - BalloonCollection(); - - virtual ~BalloonCollection(); - - // Adds a new balloon for the specified notification. - virtual void Add(const Notification& notification, - Profile* profile) = 0; - - // Returns true if any balloon has this notification id. - virtual const Notification* FindById(const std::string& id) const = 0; - - // Removes any balloons that have this notification id. Returns - // true if anything was removed. - virtual bool RemoveById(const std::string& id) = 0; - - // Removes any balloons that have this source origin. Returns - // true if anything was removed. - virtual bool RemoveBySourceOrigin(const GURL& source_origin) = 0; - - // Removes any balloons matching |profile. Returns true if any were removed. - virtual bool RemoveByProfile(Profile* profile) = 0; - - // Removes all balloons. - virtual void RemoveAll() = 0; - - // Is there room to add another notification? - virtual bool HasSpace() const = 0; - - // Request the resizing of a balloon. - virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) = 0; - - // Set the position preference for the collection. - virtual void SetPositionPreference(PositionPreference position) = 0; - - // Update for new screen dimensions. - virtual void DisplayChanged() = 0; - - // Inform the collection that a balloon was closed. - virtual void OnBalloonClosed(Balloon* source) = 0; - - // Get const collection of the active balloons. - typedef std::deque<Balloon*> Balloons; - virtual const Balloons& GetActiveBalloons() = 0; - - BalloonSpaceChangeListener* space_change_listener() { - return space_change_listener_; - } - void set_space_change_listener(BalloonSpaceChangeListener* listener) { - space_change_listener_ = listener; - } - - void set_on_collection_changed_callback(const base::Closure& callback) { - on_collection_changed_callback_ = callback; - } - - protected: - // Non-owned pointer to an object listening for space changes. - BalloonSpaceChangeListener* space_change_listener_; - - // For use only with testing. This callback is invoked when a balloon - // is added or removed from the collection. - base::Closure on_collection_changed_callback_; -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_ diff --git a/chrome/browser/notifications/balloon_collection_base.cc b/chrome/browser/notifications/balloon_collection_base.cc deleted file mode 100644 index b7f8669..0000000 --- a/chrome/browser/notifications/balloon_collection_base.cc +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/balloon_collection_base.h" - -#include "base/stl_util.h" -#include "chrome/browser/notifications/balloon.h" -#include "chrome/browser/notifications/notification.h" -#include "url/gurl.h" - -BalloonCollectionBase::BalloonCollectionBase() { -} - -BalloonCollectionBase::~BalloonCollectionBase() { - STLDeleteElements(&balloons_); -} - -void BalloonCollectionBase::Add(Balloon* balloon, bool add_to_front) { - if (add_to_front) - balloons_.push_front(balloon); - else - balloons_.push_back(balloon); -} - -void BalloonCollectionBase::Remove(Balloon* balloon) { - // Free after removing. - scoped_ptr<Balloon> to_delete(balloon); - Balloons::iterator iter; - for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { - if ((*iter) == balloon) { - balloons_.erase(iter); - return; - } - } -} - -const Notification* BalloonCollectionBase::FindById( - const std::string& id) const { - Balloons::const_iterator iter; - for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { - if ((*iter)->notification().notification_id() == id) { - return &((*iter)->notification()); - } - } - return NULL; -} - -bool BalloonCollectionBase::CloseById(const std::string& id) { - // Use a local list of balloons to close to avoid breaking - // iterator changes on each close. - Balloons to_close; - Balloons::iterator iter; - for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { - if ((*iter)->notification().notification_id() == id) - to_close.push_back(*iter); - } - for (iter = to_close.begin(); iter != to_close.end(); ++iter) - (*iter)->CloseByScript(); - - return !to_close.empty(); -} - -bool BalloonCollectionBase::CloseAllBySourceOrigin( - const GURL& source_origin) { - // Use a local list of balloons to close to avoid breaking - // iterator changes on each close. - Balloons to_close; - Balloons::iterator iter; - for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { - if ((*iter)->notification().origin_url() == source_origin) - to_close.push_back(*iter); - } - for (iter = to_close.begin(); iter != to_close.end(); ++iter) - (*iter)->CloseByScript(); - - return !to_close.empty(); -} - -bool BalloonCollectionBase::CloseAllByProfile(Profile* profile) { - // Use a local list of balloons to close to avoid breaking - // iterator changes on each close. - Balloons to_close; - Balloons::iterator iter; - for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { - if ((*iter)->profile() == profile) - to_close.push_back(*iter); - } - for (iter = to_close.begin(); iter != to_close.end(); ++iter) - (*iter)->CloseByScript(); - - return !to_close.empty(); -} - -void BalloonCollectionBase::CloseAll() { - // Use a local list of balloons to close to avoid breaking - // iterator changes on each close. - Balloons to_close = balloons_; - for (Balloons::iterator iter = to_close.begin(); - iter != to_close.end(); ++iter) - (*iter)->CloseByScript(); -} - -Balloon* BalloonCollectionBase::FindBalloonById( - const std::string& notification_id) { - Balloons::iterator iter; - for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { - if ((*iter)->notification().notification_id() == notification_id) { - return *iter; - } - } - return NULL; -} - -Balloon* BalloonCollectionBase::FindBalloon(const Notification& notification) { - return FindBalloonById(notification.notification_id()); -} diff --git a/chrome/browser/notifications/balloon_collection_base.h b/chrome/browser/notifications/balloon_collection_base.h deleted file mode 100644 index 89f3341..0000000 --- a/chrome/browser/notifications/balloon_collection_base.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Handles the visible notification (or balloons). - -#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_ -#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_ - -#include <deque> -#include <string> - -#include "base/basictypes.h" - -class Balloon; -class GURL; -class Notification; -class Profile; - -// This class provides support for implementing a BalloonCollection -// including the parts common between Chrome UI and ChromeOS UI. -class BalloonCollectionBase { - public: - BalloonCollectionBase(); - virtual ~BalloonCollectionBase(); - - typedef std::deque<Balloon*> Balloons; - - // Adds a balloon to the collection. Takes ownership of pointer. - virtual void Add(Balloon* balloon, bool add_to_front); - - // Removes a balloon from the collection (if present). Frees - // the pointer after removal. - virtual void Remove(Balloon* balloon); - - // Returns true if any balloon matches the given notification id. - virtual const Notification* FindById(const std::string& id) const; - - // Finds any balloon matching the given notification id, and - // calls CloseByScript on it. Returns true if anything was - // found. - virtual bool CloseById(const std::string& id); - - // Finds all balloons matching the given notification source, - // and calls CloseByScript on them. Returns true if anything - // was found. - virtual bool CloseAllBySourceOrigin(const GURL& source_origin); - - // Finds all balloons matching the given profile and calls CloseByScript - // on them. Returns true if anything was found. - virtual bool CloseAllByProfile(Profile* profile); - - // Calls CloseByScript on all balloons. - virtual void CloseAll(); - - const Balloons& balloons() const { return balloons_; } - - // Returns the balloon matching the given notification id, or - // NULL if there is no matching balloon. - Balloon* FindBalloonById(const std::string& notification_id); - - // Returns the balloon matching the given notification, or - // NULL if there is no matching balloon. - Balloon* FindBalloon(const Notification& notification); - - // The number of balloons being displayed. - int count() const { return static_cast<int>(balloons_.size()); } - - private: - // Queue of active balloons. Pointers are owned by this class. - Balloons balloons_; - - DISALLOW_COPY_AND_ASSIGN(BalloonCollectionBase); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_ diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc deleted file mode 100644 index 86e850b..0000000 --- a/chrome/browser/notifications/balloon_collection_impl.cc +++ /dev/null @@ -1,463 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/balloon_collection_impl.h" - -#include "base/bind.h" -#include "base/logging.h" -#include "base/stl_util.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/notifications/balloon.h" -#include "chrome/browser/notifications/balloon_host.h" -#include "chrome/browser/notifications/notification.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/panels/docked_panel_collection.h" -#include "chrome/browser/ui/panels/panel.h" -#include "chrome/browser/ui/panels/panel_manager.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_service.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/screen.h" -#include "ui/gfx/size.h" - -// Portion of the screen allotted for notifications. When notification balloons -// extend over this, no new notifications are shown until some are closed. -const double kPercentBalloonFillFactor = 0.7; - -// Allow at least this number of balloons on the screen. -const int kMinAllowedBalloonCount = 2; - -// The spacing between the balloon and the panel. -const int kVerticalSpacingBetweenBalloonAndPanel = 5; - -// Delay from the mouse leaving the balloon collection before -// there is a relayout, in milliseconds. -const int kRepositionDelayMs = 300; - - -BalloonCollectionImpl::BalloonCollectionImpl() - : reposition_factory_(this), - added_as_message_loop_observer_(false) { - registrar_.Add(this, chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, - content::NotificationService::AllSources()); - registrar_.Add(this, chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, - content::NotificationService::AllSources()); - - SetPositionPreference(BalloonCollection::DEFAULT_POSITION); -} - -BalloonCollectionImpl::~BalloonCollectionImpl() { - RemoveMessageLoopObserver(); -} - -void BalloonCollectionImpl::AddImpl(const Notification& notification, - Profile* profile, - bool add_to_front) { - Balloon* new_balloon = MakeBalloon(notification, profile); - // The +1 on width is necessary because width is fixed on notifications, - // so since we always have the max size, we would always hit the scrollbar - // condition. We are only interested in comparing height to maximum. - new_balloon->set_min_scrollbar_size(gfx::Size(1 + layout_.max_balloon_width(), - layout_.max_balloon_height())); - new_balloon->SetPosition(layout_.OffScreenLocation(), false); - new_balloon->Show(); - int count = base_.count(); - if (count > 0 && layout_.RequiresOffsets()) - new_balloon->set_offset(base_.balloons()[count - 1]->offset()); - base_.Add(new_balloon, add_to_front); - PositionBalloons(false); - - // There may be no listener in a unit test. - if (space_change_listener_) - space_change_listener_->OnBalloonSpaceChanged(); - - // This is used only for testing. - if (!on_collection_changed_callback_.is_null()) - on_collection_changed_callback_.Run(); -} - -void BalloonCollectionImpl::Add(const Notification& notification, - Profile* profile) { - AddImpl(notification, profile, false); -} - -const Notification* BalloonCollectionImpl::FindById( - const std::string& id) const { - return base_.FindById(id); -} - -bool BalloonCollectionImpl::RemoveById(const std::string& id) { - return base_.CloseById(id); -} - -bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) { - return base_.CloseAllBySourceOrigin(origin); -} - -bool BalloonCollectionImpl::RemoveByProfile(Profile* profile) { - return base_.CloseAllByProfile(profile); -} - -void BalloonCollectionImpl::RemoveAll() { - base_.CloseAll(); -} - -bool BalloonCollectionImpl::HasSpace() const { - int count = base_.count(); - if (count < kMinAllowedBalloonCount) - return true; - - int max_balloon_size = 0; - int total_size = 0; - layout_.GetMaxLinearSize(&max_balloon_size, &total_size); - - int current_max_size = max_balloon_size * count; - int max_allowed_size = static_cast<int>(total_size * - kPercentBalloonFillFactor); - return current_max_size < max_allowed_size - max_balloon_size; -} - -void BalloonCollectionImpl::ResizeBalloon(Balloon* balloon, - const gfx::Size& size) { - balloon->set_content_size(Layout::ConstrainToSizeLimits(size)); - PositionBalloons(true); -} - -void BalloonCollectionImpl::DisplayChanged() { - layout_.RefreshSystemMetrics(); - PositionBalloons(true); -} - -void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) { - // We want to free the balloon when finished. - const Balloons& balloons = base_.balloons(); - - Balloons::const_iterator it = balloons.begin(); - if (layout_.RequiresOffsets()) { - gfx::Vector2d offset; - bool apply_offset = false; - while (it != balloons.end()) { - if (*it == source) { - ++it; - if (it != balloons.end()) { - apply_offset = true; - offset.set_y((source)->offset().y() - (*it)->offset().y() + - (*it)->content_size().height() - source->content_size().height()); - } - } else { - if (apply_offset) - (*it)->add_offset(offset); - ++it; - } - } - // Start listening for UI events so we cancel the offset when the mouse - // leaves the balloon area. - if (apply_offset) - AddMessageLoopObserver(); - } - - base_.Remove(source); - PositionBalloons(true); - - // There may be no listener in a unit test. - if (space_change_listener_) - space_change_listener_->OnBalloonSpaceChanged(); - - // This is used only for testing. - if (!on_collection_changed_callback_.is_null()) - on_collection_changed_callback_.Run(); -} - -const BalloonCollection::Balloons& BalloonCollectionImpl::GetActiveBalloons() { - return base_.balloons(); -} - -void BalloonCollectionImpl::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - gfx::Rect bounds; - switch (type) { - case chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED: - case chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE: - layout_.enable_computing_panel_offset(); - if (layout_.ComputeOffsetToMoveAbovePanels()) - PositionBalloons(true); - break; - default: - NOTREACHED(); - break; - } -} - -void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) { - const Balloons& balloons = base_.balloons(); - - layout_.RefreshSystemMetrics(); - gfx::Point origin = layout_.GetLayoutOrigin(); - for (Balloons::const_iterator it = balloons.begin(); - it != balloons.end(); - ++it) { - gfx::Point upper_left = layout_.NextPosition((*it)->GetViewSize(), &origin); - (*it)->SetPosition(upper_left, reposition); - } -} - -gfx::Rect BalloonCollectionImpl::GetBalloonsBoundingBox() const { - // Start from the layout origin. - gfx::Rect bounds = gfx::Rect(layout_.GetLayoutOrigin(), gfx::Size(0, 0)); - - // For each balloon, extend the rectangle. This approach is indifferent to - // the orientation of the balloons. - const Balloons& balloons = base_.balloons(); - Balloons::const_iterator iter; - for (iter = balloons.begin(); iter != balloons.end(); ++iter) { - gfx::Rect balloon_box = gfx::Rect((*iter)->GetPosition(), - (*iter)->GetViewSize()); - bounds.Union(balloon_box); - } - - return bounds; -} - -void BalloonCollectionImpl::AddMessageLoopObserver() { - if (!added_as_message_loop_observer_) { - base::MessageLoopForUI::current()->AddObserver(this); - added_as_message_loop_observer_ = true; - } -} - -void BalloonCollectionImpl::RemoveMessageLoopObserver() { - if (added_as_message_loop_observer_) { - base::MessageLoopForUI::current()->RemoveObserver(this); - added_as_message_loop_observer_ = false; - } -} - -void BalloonCollectionImpl::CancelOffsets() { - reposition_factory_.InvalidateWeakPtrs(); - - // Unhook from listening to all UI events. - RemoveMessageLoopObserver(); - - const Balloons& balloons = base_.balloons(); - for (Balloons::const_iterator it = balloons.begin(); - it != balloons.end(); - ++it) - (*it)->set_offset(gfx::Vector2d()); - - PositionBalloons(true); -} - -void BalloonCollectionImpl::HandleMouseMoveEvent() { - if (!IsCursorInBalloonCollection()) { - // Mouse has left the region. Schedule a reposition after - // a short delay. - if (!reposition_factory_.HasWeakPtrs()) { - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&BalloonCollectionImpl::CancelOffsets, - reposition_factory_.GetWeakPtr()), - base::TimeDelta::FromMilliseconds(kRepositionDelayMs)); - } - } else { - // Mouse moved back into the region. Cancel the reposition. - reposition_factory_.InvalidateWeakPtrs(); - } -} - -BalloonCollectionImpl::Layout::Layout() - : placement_(INVALID), - need_to_compute_panel_offset_(false), - offset_to_move_above_panels_(0) { - RefreshSystemMetrics(); -} - -void BalloonCollectionImpl::Layout::GetMaxLinearSize(int* max_balloon_size, - int* total_size) const { - DCHECK(max_balloon_size && total_size); - - // All placement schemes are vertical, so we only care about height. - *total_size = work_area_.height(); - *max_balloon_size = max_balloon_height(); -} - -gfx::Point BalloonCollectionImpl::Layout::GetLayoutOrigin() const { - // For lower-left and lower-right positioning, we need to add an offset - // to ensure balloons to stay on top of panels to avoid overlapping. - int x = 0; - int y = 0; - switch (placement_) { - case VERTICALLY_FROM_TOP_LEFT: { - x = work_area_.x() + HorizontalEdgeMargin(); - y = work_area_.y() + VerticalEdgeMargin() + offset_to_move_above_panels_; - break; - } - case VERTICALLY_FROM_TOP_RIGHT: { - x = work_area_.right() - HorizontalEdgeMargin(); - y = work_area_.y() + VerticalEdgeMargin() + offset_to_move_above_panels_; - break; - } - case VERTICALLY_FROM_BOTTOM_LEFT: - x = work_area_.x() + HorizontalEdgeMargin(); - y = work_area_.bottom() - VerticalEdgeMargin() - - offset_to_move_above_panels_; - break; - case VERTICALLY_FROM_BOTTOM_RIGHT: - x = work_area_.right() - HorizontalEdgeMargin(); - y = work_area_.bottom() - VerticalEdgeMargin() - - offset_to_move_above_panels_; - break; - default: - NOTREACHED(); - break; - } - return gfx::Point(x, y); -} - -gfx::Point BalloonCollectionImpl::Layout::NextPosition( - const gfx::Size& balloon_size, - gfx::Point* position_iterator) const { - DCHECK(position_iterator); - - int x = 0; - int y = 0; - switch (placement_) { - case VERTICALLY_FROM_TOP_LEFT: - x = position_iterator->x(); - y = position_iterator->y(); - position_iterator->set_y(position_iterator->y() + balloon_size.height() + - InterBalloonMargin()); - break; - case VERTICALLY_FROM_TOP_RIGHT: - x = position_iterator->x() - balloon_size.width(); - y = position_iterator->y(); - position_iterator->set_y(position_iterator->y() + balloon_size.height() + - InterBalloonMargin()); - break; - case VERTICALLY_FROM_BOTTOM_LEFT: - position_iterator->set_y(position_iterator->y() - balloon_size.height() - - InterBalloonMargin()); - x = position_iterator->x(); - y = position_iterator->y(); - break; - case VERTICALLY_FROM_BOTTOM_RIGHT: - position_iterator->set_y(position_iterator->y() - balloon_size.height() - - InterBalloonMargin()); - x = position_iterator->x() - balloon_size.width(); - y = position_iterator->y(); - break; - default: - NOTREACHED(); - break; - } - return gfx::Point(x, y); -} - -gfx::Point BalloonCollectionImpl::Layout::OffScreenLocation() const { - gfx::Point location = GetLayoutOrigin(); - switch (placement_) { - case VERTICALLY_FROM_TOP_LEFT: - case VERTICALLY_FROM_BOTTOM_LEFT: - location.Offset(0, kBalloonMaxHeight); - break; - case VERTICALLY_FROM_TOP_RIGHT: - case VERTICALLY_FROM_BOTTOM_RIGHT: - location.Offset(-kBalloonMaxWidth - BalloonView::GetHorizontalMargin(), - kBalloonMaxHeight); - break; - default: - NOTREACHED(); - break; - } - return location; -} - -bool BalloonCollectionImpl::Layout::RequiresOffsets() const { - // Layout schemes that grow up from the bottom require offsets; - // schemes that grow down do not require offsets. - bool offsets = (placement_ == VERTICALLY_FROM_BOTTOM_LEFT || - placement_ == VERTICALLY_FROM_BOTTOM_RIGHT); - return offsets; -} - -// static -gfx::Size BalloonCollectionImpl::Layout::ConstrainToSizeLimits( - const gfx::Size& size) { - // restrict to the min & max sizes - return gfx::Size( - std::max(min_balloon_width(), - std::min(max_balloon_width(), size.width())), - std::max(min_balloon_height(), - std::min(max_balloon_height(), size.height()))); -} - -bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels() { - // If the offset is not enabled due to that we have not received a - // notification about panel, don't proceed because we don't want to call - // PanelManager::GetInstance() to create an instance when panel is not - // present. - if (!need_to_compute_panel_offset_) - return false; - - const DockedPanelCollection::Panels& panels = - PanelManager::GetInstance()->docked_collection()->panels(); - int offset_to_move_above_panels = 0; - - // The offset is the maximum height of panels that could overlap with the - // balloons. - if (NeedToMoveAboveLeftSidePanels()) { - for (DockedPanelCollection::Panels::const_reverse_iterator iter = - panels.rbegin(); - iter != panels.rend(); ++iter) { - // No need to check panels beyond the area occupied by the balloons. - if ((*iter)->GetBounds().x() >= work_area_.x() + max_balloon_width()) - break; - - int current_height = (*iter)->GetBounds().height(); - if (current_height > offset_to_move_above_panels) - offset_to_move_above_panels = current_height; - } - } else if (NeedToMoveAboveRightSidePanels()) { - for (DockedPanelCollection::Panels::const_iterator iter = panels.begin(); - iter != panels.end(); ++iter) { - // No need to check panels beyond the area occupied by the balloons. - if ((*iter)->GetBounds().right() <= - work_area_.right() - max_balloon_width()) - break; - - int current_height = (*iter)->GetBounds().height(); - if (current_height > offset_to_move_above_panels) - offset_to_move_above_panels = current_height; - } - } - - // Ensure that we have some sort of margin between the 1st balloon and the - // panel beneath it even the vertical edge margin is 0 as on Mac. - if (offset_to_move_above_panels && !VerticalEdgeMargin()) - offset_to_move_above_panels += kVerticalSpacingBetweenBalloonAndPanel; - - // If no change is detected, return false to indicate that we do not need to - // reposition balloons. - if (offset_to_move_above_panels_ == offset_to_move_above_panels) - return false; - - offset_to_move_above_panels_ = offset_to_move_above_panels; - return true; -} - -bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() { - bool changed = false; - - // TODO(scottmg): NativeScreen is wrong. http://crbug.com/133312 - gfx::Rect new_work_area = - gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); - if (work_area_ != new_work_area) { - work_area_.SetRect(new_work_area.x(), new_work_area.y(), - new_work_area.width(), new_work_area.height()); - changed = true; - } - - return changed; -} diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h deleted file mode 100644 index 3ab9600..0000000 --- a/chrome/browser/notifications/balloon_collection_impl.h +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Handles the visible notification (or balloons). - -#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ -#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ - -#include <deque> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/weak_ptr.h" -#include "base/message_loop/message_loop.h" -#include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/balloon_collection_base.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" - -// A balloon collection represents a set of notification balloons being -// shown on the screen. It positions new notifications according to -// a layout, and monitors for balloons being closed, which it reports -// up to its parent, the notification UI manager. -class BalloonCollectionImpl : public BalloonCollection, - public content::NotificationObserver, - public base::MessageLoopForUI::Observer { - public: - BalloonCollectionImpl(); - virtual ~BalloonCollectionImpl(); - - // BalloonCollection interface. - virtual void Add(const Notification& notification, - Profile* profile) OVERRIDE; - virtual const Notification* FindById(const std::string& id) const OVERRIDE; - virtual bool RemoveById(const std::string& id) OVERRIDE; - virtual bool RemoveBySourceOrigin(const GURL& source_origin) OVERRIDE; - virtual bool RemoveByProfile(Profile* profile) OVERRIDE; - virtual void RemoveAll() OVERRIDE; - virtual bool HasSpace() const OVERRIDE; - virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) OVERRIDE; - virtual void SetPositionPreference(PositionPreference position) OVERRIDE; - virtual void DisplayChanged() OVERRIDE; - virtual void OnBalloonClosed(Balloon* source) OVERRIDE; - virtual const Balloons& GetActiveBalloons() OVERRIDE; - - // content::NotificationObserver interface. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - // base_ is embedded, so this is a simple accessor for the number of - // balloons in the collection. - int count() const { return base_.count(); } - - static int min_balloon_width() { return Layout::min_balloon_width(); } - static int max_balloon_width() { return Layout::max_balloon_width(); } - static int min_balloon_height() { return Layout::min_balloon_height(); } - static int max_balloon_height() { return Layout::max_balloon_height(); } - - protected: - // Calculates layout values for the balloons including - // the scaling, the max/min sizes, and the upper left corner of each. - class Layout { - public: - Layout(); - - // These enumerations all are based on a screen orientation where - // the origin is the top-left. - enum Placement { - INVALID, - VERTICALLY_FROM_TOP_LEFT, - VERTICALLY_FROM_TOP_RIGHT, - VERTICALLY_FROM_BOTTOM_LEFT, - VERTICALLY_FROM_BOTTOM_RIGHT - }; - - // Refresh the work area and balloon placement. - void OnDisplaySettingsChanged(); - - // TODO(johnnyg): Scale the size to account for the system font factor. - static int min_balloon_width() { return kBalloonMinWidth; } - static int max_balloon_width() { return kBalloonMaxWidth; } - static int min_balloon_height() { return kBalloonMinHeight; } - static int max_balloon_height() { return kBalloonMaxHeight; } - - // Utility function constrains the input rectangle to the min and max sizes. - static gfx::Size ConstrainToSizeLimits(const gfx::Size& rect); - - void set_placement(Placement placement) { placement_ = placement; } - - // Returns both the total space available and the maximum - // allowed per balloon. - // - // The size may be a height or length depending on the way that - // balloons are laid out. - void GetMaxLinearSize(int* max_balloon_size, int* total_size) const; - - // Refresh the cached values for work area and drawing metrics. - // The application should call this method to re-acquire metrics after - // any resolution or settings change. - // Returns true if and only if a metric changed. - bool RefreshSystemMetrics(); - - // Returns the origin for the sequence of balloons depending on layout. - // Should not be used to place a balloon -- only to call NextPosition(). - gfx::Point GetLayoutOrigin() const; - - // Compute the position for the next balloon. - // Start with *position_iterator = GetLayoutOrigin() and call repeatedly - // to get a sequence of positions. Return value is the upper-left coordinate - // for each next balloon. - gfx::Point NextPosition(const gfx::Size& balloon_size, - gfx::Point* position_iterator) const; - - // Return a offscreen location which is offscreen for this layout, - // to be used as the initial position for an animation into view. - gfx::Point OffScreenLocation() const; - - // Returns true if the layout requires offsetting for keeping the close - // buttons under the cursor during rapid-close interaction. - bool RequiresOffsets() const; - - // Returns true if there is change to the offset that requires the balloons - // to be repositioned. - bool ComputeOffsetToMoveAbovePanels(); - - void enable_computing_panel_offset() { - need_to_compute_panel_offset_ = true; - } - - private: - // Layout parameters - int VerticalEdgeMargin() const; - int HorizontalEdgeMargin() const; - int InterBalloonMargin() const; - - bool NeedToMoveAboveLeftSidePanels() const; - bool NeedToMoveAboveRightSidePanels() const; - - // Minimum and maximum size of balloon content. - static const int kBalloonMinWidth = 300; - static const int kBalloonMaxWidth = 300; - static const int kBalloonMinHeight = 24; - static const int kBalloonMaxHeight = 160; - - Placement placement_; - gfx::Rect work_area_; - - // The flag that indicates that the panel offset computation should be - // performed. - bool need_to_compute_panel_offset_; - - // The offset that guarantees that the notificaitions shown in the - // lower-right or lower-left corner of the screen will go above currently - // shown panels and will not be obscured by them. - int offset_to_move_above_panels_; - - DISALLOW_COPY_AND_ASSIGN(Layout); - }; - - // Creates a new balloon. Overridable by derived classes and unit tests. - // The caller is responsible for freeing the pointer returned. - virtual Balloon* MakeBalloon(const Notification& notification, - Profile* profile); - - // Protected implementation of Add with additional add_to_front parameter - // for use by derived classes. - void AddImpl(const Notification& notification, - Profile* profile, - bool add_to_front); - - // Gets a bounding box for all the current balloons in screen coordinates. - gfx::Rect GetBalloonsBoundingBox() const; - - BalloonCollectionBase& base() { return base_; } - Layout& layout() { return layout_; } - - private: - // Adjusts the positions of the balloons (e.g., when one is closed). - // Implemented by each platform for specific UI requirements. - void PositionBalloons(bool is_reposition); - - // Cross-platform internal implementation for PositionBalloons. - void PositionBalloonsInternal(bool is_reposition); - - // Base implementation for the collection of active balloons. - BalloonCollectionBase base_; - - // The layout parameters for balloons in this collection. - Layout layout_; - - content::NotificationRegistrar registrar_; - - // Start and stop observing all UI events. - void AddMessageLoopObserver(); - void RemoveMessageLoopObserver(); - - // Cancel all offset and reposition the balloons normally. - void CancelOffsets(); - - // Handles a mouse motion while the balloons are temporarily offset. - void HandleMouseMoveEvent(); - - // Is the current cursor in the balloon area? - bool IsCursorInBalloonCollection() const; - - // Factory for generating delayed reposition tasks on mouse motion. - base::WeakPtrFactory<BalloonCollectionImpl> reposition_factory_; - - // Is the balloon collection currently listening for UI events? - bool added_as_message_loop_observer_; - - DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc deleted file mode 100644 index 0522ad0..0000000 --- a/chrome/browser/notifications/balloon_host.cc +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/balloon_host.h" - -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" -#include "chrome/browser/notifications/balloon.h" -#include "chrome/browser/notifications/balloon_collection_impl.h" -#include "chrome/browser/notifications/notification.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/renderer_preferences_util.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_tabstrip.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/url_constants.h" -#include "content/public/browser/navigation_controller.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/site_instance.h" -#include "content/public/browser/web_contents.h" -#include "content/public/common/bindings_policy.h" -#include "content/public/common/renderer_preferences.h" -#include "extensions/browser/view_type_utils.h" -#include "extensions/common/extension_messages.h" -#include "ipc/ipc_message.h" - -using content::SiteInstance; -using content::WebContents; - -BalloonHost::BalloonHost(Balloon* balloon) - : balloon_(balloon), - initialized_(false), - should_notify_on_disconnect_(false), - enable_web_ui_(false), - extension_function_dispatcher_(balloon_->profile(), this) { - site_instance_ = SiteInstance::CreateForURL( - balloon_->profile(), balloon_->notification().content_url()); -} - -void BalloonHost::Shutdown() { - NotifyDisconnect(); - web_contents_.reset(); - site_instance_ = NULL; - balloon_ = NULL; // No longer safe to access |balloon_| -} - -extensions::WindowController* -BalloonHost::GetExtensionWindowController() const { - // Notifications don't have a window controller. - return NULL; -} - -content::WebContents* BalloonHost::GetAssociatedWebContents() const { - return NULL; -} - -const base::string16& BalloonHost::GetSource() const { - return balloon_->notification().display_source(); -} - -void BalloonHost::CloseContents(WebContents* source) { - if (!balloon_) - return; - balloon_->CloseByScript(); - NotifyDisconnect(); -} - -void BalloonHost::HandleMouseDown() { - if (balloon_) - balloon_->OnClick(); -} - -void BalloonHost::ResizeDueToAutoResize(WebContents* source, - const gfx::Size& pref_size) { - if (balloon_) - balloon_->ResizeDueToAutoResize(pref_size); -} - -void BalloonHost::AddNewContents(WebContents* source, - WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture, - bool* was_blocked) { - Browser* browser = chrome::FindLastActiveWithProfile( - Profile::FromBrowserContext(new_contents->GetBrowserContext()), - chrome::GetActiveDesktop()); - if (browser) { - chrome::AddWebContents(browser, NULL, new_contents, disposition, - initial_pos, user_gesture, was_blocked); - } -} - -void BalloonHost::RenderViewCreated(content::RenderViewHost* render_view_host) { - gfx::Size min_size(BalloonCollectionImpl::min_balloon_width(), - BalloonCollectionImpl::min_balloon_height()); - gfx::Size max_size(BalloonCollectionImpl::max_balloon_width(), - BalloonCollectionImpl::max_balloon_height()); - render_view_host->EnableAutoResize(min_size, max_size); - - if (enable_web_ui_) - render_view_host->AllowBindings(content::BINDINGS_POLICY_WEB_UI); -} - -void BalloonHost::RenderViewReady() { - should_notify_on_disconnect_ = true; - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, - content::Source<BalloonHost>(this), - content::NotificationService::NoDetails()); -} - -void BalloonHost::RenderProcessGone(base::TerminationStatus status) { - CloseContents(web_contents_.get()); -} - -bool BalloonHost::OnMessageReceived(const IPC::Message& message) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(BalloonHost, message) - IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void BalloonHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { - extension_function_dispatcher_.Dispatch(params, - web_contents_->GetRenderViewHost()); -} - -void BalloonHost::Init() { - DCHECK(!web_contents_.get()) << "BalloonViewHost already initialized."; - web_contents_.reset(WebContents::Create( - WebContents::CreateParams(balloon_->profile(), site_instance_.get()))); - extensions::SetViewType( - web_contents_.get(), extensions::VIEW_TYPE_NOTIFICATION); - web_contents_->SetDelegate(this); - extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( - web_contents_.get()); - Observe(web_contents_.get()); - renderer_preferences_util::UpdateFromSystemSettings( - web_contents_->GetMutableRendererPrefs(), balloon_->profile()); - web_contents_->GetRenderViewHost()->SyncRendererPrefs(); - - web_contents_->GetController().LoadURL( - balloon_->notification().content_url(), content::Referrer(), - content::PAGE_TRANSITION_LINK, std::string()); - - initialized_ = true; -} - -void BalloonHost::EnableWebUI() { - DCHECK(!web_contents_.get()) << - "EnableWebUI has to be called before a renderer is created."; - enable_web_ui_ = true; -} - -BalloonHost::~BalloonHost() { -} - -void BalloonHost::NotifyDisconnect() { - if (!should_notify_on_disconnect_) - return; - - should_notify_on_disconnect_ = false; - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, - content::Source<BalloonHost>(this), - content::NotificationService::NoDetails()); -} - -bool BalloonHost::IsRenderViewReady() const { - return should_notify_on_disconnect_; -} diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h deleted file mode 100644 index 65c832b..0000000 --- a/chrome/browser/notifications/balloon_host.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_ -#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_ - -#include <string> -#include <vector> - -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/web_contents_delegate.h" -#include "content/public/browser/web_contents_observer.h" -#include "extensions/browser/extension_function_dispatcher.h" - -class Balloon; -class Browser; - -namespace content { -class SiteInstance; -}; - -class BalloonHost : public content::WebContentsDelegate, - public content::WebContentsObserver, - public extensions::ExtensionFunctionDispatcher::Delegate { - public: - explicit BalloonHost(Balloon* balloon); - - // Initialize the view. - void Init(); - - // Stops showing the balloon. - void Shutdown(); - - // extensions::ExtensionFunctionDispatcher::Delegate overrides. - virtual extensions::WindowController* GetExtensionWindowController() - const OVERRIDE; - virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; - - const base::string16& GetSource() const; - - content::WebContents* web_contents() const { return web_contents_.get(); } - - // Enable Web UI. This has to be called before renderer is created. - void EnableWebUI(); - - // Returns whether the associated render view is ready. Used only for testing. - bool IsRenderViewReady() const; - - protected: - virtual ~BalloonHost(); - - scoped_ptr<content::WebContents> web_contents_; - - private: - // content::WebContentsDelegate implementation: - virtual void CloseContents(content::WebContents* source) OVERRIDE; - virtual void HandleMouseDown() OVERRIDE; - virtual void ResizeDueToAutoResize(content::WebContents* source, - const gfx::Size& pref_size) OVERRIDE; - virtual void AddNewContents(content::WebContents* source, - content::WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture, - bool* was_blocked) OVERRIDE; - - // content::WebContentsObserver implementation: - virtual void RenderViewCreated( - content::RenderViewHost* render_view_host) OVERRIDE; - virtual void RenderViewReady() OVERRIDE; - virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - - // Message handlers - void OnRequest(const ExtensionHostMsg_Request_Params& params); - - // Called to send an event that the balloon has been disconnected from - // a renderer (if should_notify_on_disconnect_ is true). - void NotifyDisconnect(); - - // Non-owned pointer to the associated balloon. - Balloon* balloon_; - - // True after Init() has completed. - bool initialized_; - - // Indicates whether we should notify about disconnection of this balloon. - // This is used to ensure disconnection notifications only happen if - // a connection notification has happened and that they happen only once. - bool should_notify_on_disconnect_; - - // Site instance for the balloon/profile, to be used for opening new links. - scoped_refptr<content::SiteInstance> site_instance_; - - // A flag to enable Web UI. - bool enable_web_ui_; - - extensions::ExtensionFunctionDispatcher extension_function_dispatcher_; -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_ diff --git a/chrome/browser/notifications/balloon_notification_ui_manager.cc b/chrome/browser/notifications/balloon_notification_ui_manager.cc deleted file mode 100644 index a420ce5..0000000 --- a/chrome/browser/notifications/balloon_notification_ui_manager.cc +++ /dev/null @@ -1,307 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" - -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "base/prefs/pref_service.h" -#include "base/stl_util.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/fullscreen.h" -#include "chrome/browser/idle.h" -#include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/notification.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/pref_names.h" -#include "content/public/browser/notification_service.h" - -// A class which represents a notification waiting to be shown. -class QueuedNotification { - public: - QueuedNotification(const Notification& notification, Profile* profile) - : notification_(notification), - profile_(profile) { - } - - const Notification& notification() const { return notification_; } - Profile* profile() const { return profile_; } - - void Replace(const Notification& new_notification) { - notification_ = new_notification; - } - - private: - // The notification to be shown. - Notification notification_; - - // Non owned pointer to the user's profile. - Profile* profile_; - - DISALLOW_COPY_AND_ASSIGN(QueuedNotification); -}; - -BalloonNotificationUIManager::BalloonNotificationUIManager( - PrefService* local_state) - : NotificationPrefsManager(local_state), - // Passes NULL to blockers since |message_center| is not used from balloon - // notifications. - screen_lock_blocker_(NULL), - fullscreen_blocker_(NULL), - system_observer_(this) { - position_pref_.Init( - prefs::kDesktopNotificationPosition, - local_state, - base::Bind( - &BalloonNotificationUIManager::OnDesktopNotificationPositionChanged, - base::Unretained(this))); -} - -BalloonNotificationUIManager::~BalloonNotificationUIManager() { -} - -void BalloonNotificationUIManager::SetBalloonCollection( - BalloonCollection* balloon_collection) { - DCHECK(!balloon_collection_.get() || - balloon_collection_->GetActiveBalloons().size() == 0); - DCHECK(balloon_collection); - balloon_collection_.reset(balloon_collection); - balloon_collection_->SetPositionPreference( - static_cast<BalloonCollection::PositionPreference>( - position_pref_.GetValue())); - balloon_collection_->set_space_change_listener(this); -} - -void BalloonNotificationUIManager::Add(const Notification& notification, - Profile* profile) { - if (Update(notification, profile)) { - return; - } - - VLOG(1) << "Added notification. URL: " - << notification.content_url().spec(); - show_queue_.push_back(linked_ptr<QueuedNotification>( - new QueuedNotification(notification, profile))); - CheckAndShowNotifications(); -} - -bool BalloonNotificationUIManager::Update(const Notification& notification, - Profile* profile) { - const GURL& origin = notification.origin_url(); - const base::string16& replace_id = notification.replace_id(); - - if (replace_id.empty()) - return false; - - // First check the queue of pending notifications for replacement. - // Then check the list of notifications already being shown. - for (NotificationDeque::const_iterator iter = show_queue_.begin(); - iter != show_queue_.end(); ++iter) { - if (profile == (*iter)->profile() && - origin == (*iter)->notification().origin_url() && - replace_id == (*iter)->notification().replace_id()) { - (*iter)->Replace(notification); - return true; - } - } - - return UpdateNotification(notification, profile); -} - -const Notification* BalloonNotificationUIManager::FindById( - const std::string& id) const { - for (NotificationDeque::const_iterator iter = show_queue_.begin(); - iter != show_queue_.end(); ++iter) { - if ((*iter)->notification().notification_id() == id) { - return &((*iter)->notification()); - } - } - return balloon_collection_->FindById(id); -} - -bool BalloonNotificationUIManager::CancelById(const std::string& id) { - // See if this ID hasn't been shown yet. - for (NotificationDeque::iterator iter = show_queue_.begin(); - iter != show_queue_.end(); ++iter) { - if ((*iter)->notification().notification_id() == id) { - show_queue_.erase(iter); - return true; - } - } - // If it has been shown, remove it from the balloon collections. - return balloon_collection_->RemoveById(id); -} - -std::set<std::string> -BalloonNotificationUIManager::GetAllIdsByProfileAndSourceOrigin( - Profile* profile, - const GURL& source) { - std::set<std::string> notification_ids; - for (NotificationDeque::iterator iter = show_queue_.begin(); - iter != show_queue_.end(); iter++) { - if ((*iter)->notification().origin_url() == source && - profile->IsSameProfile((*iter)->profile())) { - notification_ids.insert((*iter)->notification().notification_id()); - } - } - - const BalloonCollection::Balloons& balloons = - balloon_collection_->GetActiveBalloons(); - for (BalloonCollection::Balloons::const_iterator iter = balloons.begin(); - iter != balloons.end(); ++iter) { - if (profile->IsSameProfile((*iter)->profile()) && - source == (*iter)->notification().origin_url()) { - notification_ids.insert((*iter)->notification().notification_id()); - } - } - return notification_ids; -} - -bool BalloonNotificationUIManager::CancelAllBySourceOrigin(const GURL& source) { - // Same pattern as CancelById, but more complicated than the above - // because there may be multiple notifications from the same source. - bool removed = false; - for (NotificationDeque::iterator loopiter = show_queue_.begin(); - loopiter != show_queue_.end(); ) { - if ((*loopiter)->notification().origin_url() != source) { - ++loopiter; - continue; - } - - loopiter = show_queue_.erase(loopiter); - removed = true; - } - return balloon_collection_->RemoveBySourceOrigin(source) || removed; -} - -bool BalloonNotificationUIManager::CancelAllByProfile(Profile* profile) { - // Same pattern as CancelAllBySourceOrigin. - bool removed = false; - for (NotificationDeque::iterator loopiter = show_queue_.begin(); - loopiter != show_queue_.end(); ) { - if ((*loopiter)->profile() != profile) { - ++loopiter; - continue; - } - - loopiter = show_queue_.erase(loopiter); - removed = true; - } - return balloon_collection_->RemoveByProfile(profile) || removed; -} - -void BalloonNotificationUIManager::CancelAll() { - balloon_collection_->RemoveAll(); -} - -BalloonCollection* BalloonNotificationUIManager::balloon_collection() { - return balloon_collection_.get(); -} - -NotificationPrefsManager* BalloonNotificationUIManager::prefs_manager() { - return this; -} - -bool BalloonNotificationUIManager::ShowNotification( - const Notification& notification, - Profile* profile) { - if (!balloon_collection_->HasSpace()) - return false; - balloon_collection_->Add(notification, profile); - return true; -} - -void BalloonNotificationUIManager::OnBalloonSpaceChanged() { - CheckAndShowNotifications(); -} - -void BalloonNotificationUIManager::OnBlockingStateChanged( - message_center::NotificationBlocker* blocker) { - CheckAndShowNotifications(); -} - -bool BalloonNotificationUIManager::UpdateNotification( - const Notification& notification, - Profile* profile) { - const GURL& origin = notification.origin_url(); - const base::string16& replace_id = notification.replace_id(); - - DCHECK(!replace_id.empty()); - - const BalloonCollection::Balloons& balloons = - balloon_collection_->GetActiveBalloons(); - for (BalloonCollection::Balloons::const_iterator iter = balloons.begin(); - iter != balloons.end(); ++iter) { - if (profile == (*iter)->profile() && - origin == (*iter)->notification().origin_url() && - replace_id == (*iter)->notification().replace_id()) { - (*iter)->Update(notification); - return true; - } - } - - return false; -} - -BalloonCollection::PositionPreference -BalloonNotificationUIManager::GetPositionPreference() const { - return static_cast<BalloonCollection::PositionPreference>( - position_pref_.GetValue()); -} - -void BalloonNotificationUIManager::SetPositionPreference( - BalloonCollection::PositionPreference preference) { - position_pref_.SetValue(static_cast<int>(preference)); - balloon_collection_->SetPositionPreference(preference); -} - -void BalloonNotificationUIManager::CheckAndShowNotifications() { - screen_lock_blocker_.CheckState(); - fullscreen_blocker_.CheckState(); - if (screen_lock_blocker_.is_locked() || - fullscreen_blocker_.is_fullscreen_mode()) { - return; - } - ShowNotifications(); -} - -void BalloonNotificationUIManager::OnDesktopNotificationPositionChanged() { - balloon_collection_->SetPositionPreference( - static_cast<BalloonCollection::PositionPreference>( - position_pref_.GetValue())); -} - -void BalloonNotificationUIManager::ShowNotifications() { - while (!show_queue_.empty()) { - linked_ptr<QueuedNotification> queued_notification(show_queue_.front()); - show_queue_.pop_front(); - if (!ShowNotification(queued_notification->notification(), - queued_notification->profile())) { - show_queue_.push_front(queued_notification); - return; - } - } -} - -// static -BalloonNotificationUIManager* - BalloonNotificationUIManager::GetInstanceForTesting() { - if (NotificationUIManager::DelegatesToMessageCenter()) { - LOG(ERROR) << "Attempt to run a test that requires " - << "BalloonNotificationUIManager while delegating to a " - << "native MessageCenter. Test will fail. Ask dimich@"; - return NULL; - } - return static_cast<BalloonNotificationUIManager*>( - g_browser_process->notification_ui_manager()); -} - -void BalloonNotificationUIManager::GetQueuedNotificationsForTesting( - std::vector<const Notification*>* notifications) { - for (NotificationDeque::const_iterator iter = show_queue_.begin(); - iter != show_queue_.end(); ++iter) { - notifications->push_back(&(*iter)->notification()); - } -} diff --git a/chrome/browser/notifications/balloon_notification_ui_manager.h b/chrome/browser/notifications/balloon_notification_ui_manager.h deleted file mode 100644 index 6b34b0e..0000000 --- a/chrome/browser/notifications/balloon_notification_ui_manager.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_NOTIFICATION_UI_MANAGER_H_ -#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_NOTIFICATION_UI_MANAGER_H_ - -#include <deque> -#include <string> - -#include "base/memory/linked_ptr.h" -#include "base/memory/scoped_ptr.h" -#include "base/prefs/pref_member.h" -#include "chrome/browser/notifications/balloon.h" -#include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/fullscreen_notification_blocker.h" -#include "chrome/browser/notifications/notification_prefs_manager.h" -#include "chrome/browser/notifications/notification_system_observer.h" -#include "chrome/browser/notifications/notification_ui_manager.h" -#include "chrome/browser/notifications/screen_lock_notification_blocker.h" - -class Notification; -class PrefService; -class Profile; -class QueuedNotification; - -// The notification manager manages use of the desktop for notifications. -// It maintains a queue of pending notifications when space becomes constrained. -class BalloonNotificationUIManager - : public NotificationUIManager, - public NotificationPrefsManager, - public BalloonCollection::BalloonSpaceChangeListener, - public message_center::NotificationBlocker::Observer { - public: - explicit BalloonNotificationUIManager(PrefService* local_state); - virtual ~BalloonNotificationUIManager(); - - // Initializes the UI manager with a balloon collection; this object - // takes ownership of the balloon collection. - void SetBalloonCollection(BalloonCollection* balloon_collection); - - // NotificationUIManager overrides: - virtual void Add(const Notification& notification, - Profile* profile) OVERRIDE; - virtual bool Update(const Notification& notification, - Profile* profile) OVERRIDE; - virtual const Notification* FindById( - const std::string& notification_id) const OVERRIDE; - virtual bool CancelById(const std::string& notification_id) OVERRIDE; - virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( - Profile* profile, - const GURL& source) OVERRIDE; - virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; - virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; - virtual void CancelAll() OVERRIDE; - - // NotificationPrefsManager overrides: - virtual BalloonCollection::PositionPreference - GetPositionPreference() const OVERRIDE; - virtual void SetPositionPreference( - BalloonCollection::PositionPreference preference) OVERRIDE; - - BalloonCollection* balloon_collection(); - NotificationPrefsManager* prefs_manager(); - - // Helper used to pull the static instance for testing. - // In tests, use this instead of g_browser_process->notification_ui_manager(). - static BalloonNotificationUIManager* GetInstanceForTesting(); - - void GetQueuedNotificationsForTesting( - std::vector<const Notification*>* notifications); - - private: - bool ShowNotification(const Notification& notification, Profile* profile); - bool UpdateNotification(const Notification& notification, Profile* profile); - - // Attempts to display notifications from the show_queue. Invoked if they - // previously returned 'false' from ShowNotifications, which may happen when - // there is no room to show another notification or notifications are blocked. - void CheckAndShowNotifications(); - - void ShowNotifications(); - - void OnDesktopNotificationPositionChanged(); - - // BalloonCollectionObserver overrides: - virtual void OnBalloonSpaceChanged() OVERRIDE; - - // NotificationBlocker::Observer overrides: - virtual void OnBlockingStateChanged( - message_center::NotificationBlocker* blocker) OVERRIDE; - - // A queue of notifications which are waiting to be shown. - typedef std::deque<linked_ptr<QueuedNotification> > NotificationDeque; - NotificationDeque show_queue_; - - // An owned pointer to the collection of active balloons. - scoped_ptr<BalloonCollection> balloon_collection_; - - ScreenLockNotificationBlocker screen_lock_blocker_; - FullscreenNotificationBlocker fullscreen_blocker_; - - // Prefs listener for the position preference. - IntegerPrefMember position_pref_; - - NotificationSystemObserver system_observer_; - - DISALLOW_COPY_AND_ASSIGN(BalloonNotificationUIManager); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_NOTIFICATION_UI_MANAGER_H_ diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index 2f82841..a52747d 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -384,33 +384,6 @@ base::string16 DesktopNotificationService::CreateDataUrl( } // static -std::string DesktopNotificationService::AddNotification( - const GURL& origin_url, - const base::string16& title, - const base::string16& message, - const GURL& icon_url, - const base::string16& replace_id, - NotificationDelegate* delegate, - Profile* profile) { - if (message_center::IsRichNotificationEnabled()) { - // For message center create a non-HTML notification with |icon_url|. - Notification notification(origin_url, icon_url, title, message, - blink::WebTextDirectionDefault, - base::string16(), replace_id, delegate); - g_browser_process->notification_ui_manager()->Add(notification, profile); - return notification.notification_id(); - } - - // Generate a data URL embedding the icon URL, title, and message. - GURL content_url(CreateDataUrl( - icon_url, title, message, blink::WebTextDirectionDefault)); - Notification notification( - GURL(), content_url, base::string16(), replace_id, delegate); - g_browser_process->notification_ui_manager()->Add(notification, profile); - return notification.notification_id(); -} - -// static std::string DesktopNotificationService::AddIconNotification( const GURL& origin_url, const base::string16& title, @@ -419,26 +392,11 @@ std::string DesktopNotificationService::AddIconNotification( const base::string16& replace_id, NotificationDelegate* delegate, Profile* profile) { - if (message_center::IsRichNotificationEnabled()) { - // For message center create a non-HTML notification with |icon|. - Notification notification(origin_url, icon, title, message, - blink::WebTextDirectionDefault, - base::string16(), replace_id, delegate); - g_browser_process->notification_ui_manager()->Add(notification, profile); - return notification.notification_id(); - } - - GURL icon_url; - if (!icon.IsEmpty()) - icon_url = GURL(webui::GetBitmapDataUrl(*icon.ToSkBitmap())); - return AddNotification( - origin_url, title, message, icon_url, replace_id, delegate, profile); -} - -// static -void DesktopNotificationService::RemoveNotification( - const std::string& notification_id) { - g_browser_process->notification_ui_manager()->CancelById(notification_id); + Notification notification(origin_url, icon, title, message, + blink::WebTextDirectionDefault, + base::string16(), replace_id, delegate); + g_browser_process->notification_ui_manager()->Add(notification, profile); + return notification.notification_id(); } DesktopNotificationService::DesktopNotificationService( @@ -635,10 +593,7 @@ bool DesktopNotificationService::ShowDesktopNotification( base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId( const GURL& origin, int process_id) { // If the source is an extension, lookup the display name. - // Message center prefers to use extension name if the notification - // is allowed by an extension. - if (NotificationUIManager::DelegatesToMessageCenter() || - origin.SchemeIs(extensions::kExtensionScheme)) { + if (origin.SchemeIs(extensions::kExtensionScheme)) { extensions::InfoMap* extension_info_map = extensions::ExtensionSystem::Get(profile_)->info_map(); if (extension_info_map) { @@ -746,8 +701,7 @@ void DesktopNotificationService::SetNotifierEnabled( void DesktopNotificationService::ShowWelcomeNotificationIfNecessary( const Notification& notification) { - if (!chrome_now_welcome_notification_ && - message_center::IsRichNotificationEnabled()) { + if (!chrome_now_welcome_notification_) { chrome_now_welcome_notification_ = ExtensionWelcomeNotification::Create(kChromeNowExtensionID, profile_); } diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h index 941f78d..745200f 100644 --- a/chrome/browser/notifications/desktop_notification_service.h +++ b/chrome/browser/notifications/desktop_notification_service.h @@ -105,20 +105,7 @@ class DesktopNotificationService : public KeyedService, static base::string16 CreateDataUrl(int resource, const std::vector<std::string>& subst); - // Add a desktop notification. On non-Ash platforms this will generate a HTML - // notification from the input parameters. On Ash it will generate a normal - // ash notification. Returns the notification id. - // TODO(mukai): remove these methods. HTML notifications are no longer - // supported. - static std::string AddNotification(const GURL& origin_url, - const base::string16& title, - const base::string16& message, - const GURL& icon_url, - const base::string16& replace_id, - NotificationDelegate* delegate, - Profile* profile); - - // Same as above, but takes a gfx::Image for the icon instead. + // Add a desktop notification. static std::string AddIconNotification(const GURL& origin_url, const base::string16& title, const base::string16& message, @@ -127,9 +114,6 @@ class DesktopNotificationService : public KeyedService, NotificationDelegate* delegate, Profile* profile); - // Remove any active notification corresponding to |notification_id|. - static void RemoveNotification(const std::string& notification_id); - // The default content setting determines how to handle origins that haven't // been allowed or denied yet. If |provider_id| is not NULL, the id of the // provider which provided the default setting is assigned to it. diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc deleted file mode 100644 index 0e96bc3..0000000 --- a/chrome/browser/notifications/desktop_notifications_unittest.cc +++ /dev/null @@ -1,588 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/desktop_notifications_unittest.h" - -#include "base/prefs/testing_pref_service.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" -#include "chrome/browser/notifications/fake_balloon_view.h" -#include "chrome/browser/prefs/browser_prefs.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/base/chrome_unit_test_suite.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/testing_profile_manager.h" -#include "content/public/common/show_desktop_notification_params.h" -#include "ui/base/ime/input_method_initializer.h" -#include "ui/gl/gl_surface.h" -#include "ui/message_center/message_center.h" - -#if defined(USE_ASH) -#include "ash/shell.h" -#include "ash/test/test_shell_delegate.h" -#include "ui/aura/env.h" -#include "ui/aura/window_event_dispatcher.h" -#include "ui/compositor/scoped_animation_duration_scale_mode.h" -#include "ui/compositor/test/context_factories_for_test.h" -#endif - -#if defined(USE_AURA) -#include "ui/wm/core/wm_state.h" -#endif - - -using content::BrowserThread; - -// static -const int MockBalloonCollection::kMockBalloonSpace = 5; - -// static -std::string DesktopNotificationsTest::log_output_; - -MockBalloonCollection::MockBalloonCollection() {} - -MockBalloonCollection::~MockBalloonCollection() {} - -void MockBalloonCollection::Add(const Notification& notification, - Profile* profile) { - // Swap in a logging proxy for the purpose of logging calls that - // would be made into javascript, then pass this down to the - // balloon collection. - Notification test_notification( - notification.origin_url(), - notification.content_url(), - notification.display_source(), - notification.replace_id(), - new LoggingNotificationProxy(notification.notification_id())); - BalloonCollectionImpl::Add(test_notification, profile); -} - -bool MockBalloonCollection::HasSpace() const { - return count() < kMockBalloonSpace; -} - -Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification, - Profile* profile) { - // Start with a normal balloon but mock out the view. - Balloon* balloon = BalloonCollectionImpl::MakeBalloon(notification, profile); - balloon->set_view(new FakeBalloonView(balloon)); - balloons_.push_back(balloon); - return balloon; -} - -void MockBalloonCollection::OnBalloonClosed(Balloon* source) { - std::deque<Balloon*>::iterator it; - for (it = balloons_.begin(); it != balloons_.end(); ++it) { - if (*it == source) { - balloons_.erase(it); - BalloonCollectionImpl::OnBalloonClosed(source); - break; - } - } -} - -const BalloonCollection::Balloons& MockBalloonCollection::GetActiveBalloons() { - return balloons_; -} - -int MockBalloonCollection::UppermostVerticalPosition() { - int min = 0; - std::deque<Balloon*>::iterator iter; - for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) { - int pos = (*iter)->GetPosition().y(); - if (iter == balloons_.begin() || pos < min) - min = pos; - } - return min; -} - -DesktopNotificationsTest::DesktopNotificationsTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - balloon_collection_(NULL) { -} - -DesktopNotificationsTest::~DesktopNotificationsTest() { -} - -void DesktopNotificationsTest::SetUp() { - ChromeUnitTestSuite::InitializeProviders(); - ChromeUnitTestSuite::InitializeResourceBundle(); - ui::InitializeInputMethodForTesting(); -#if defined(USE_AURA) - wm_state_.reset(new wm::WMState); -#endif -#if defined(USE_ASH) - ui::ScopedAnimationDurationScaleMode normal_duration_mode( - ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); - // The message center is notmally initialized on |g_browser_process| which - // is not created for these tests. - message_center::MessageCenter::Initialize(); - // The ContextFactory must exist before any Compositors are created. - bool enable_pixel_output = false; - ui::InitializeContextFactoryForTests(enable_pixel_output); - // MockBalloonCollection retrieves information about the screen on creation. - // So it is necessary to make sure the desktop gets created first. - ash::Shell::CreateInstance(new ash::test::TestShellDelegate); -#endif - chrome::RegisterLocalState(local_state_.registry()); - profile_.reset(new TestingProfile()); - ui_manager_.reset(new BalloonNotificationUIManager(&local_state_)); - balloon_collection_ = new MockBalloonCollection(); - ui_manager_->SetBalloonCollection(balloon_collection_); - service_.reset(new DesktopNotificationService(profile(), ui_manager_.get())); - log_output_.clear(); -} - -void DesktopNotificationsTest::TearDown() { - service_.reset(NULL); - ui_manager_.reset(NULL); - profile_.reset(NULL); -#if defined(USE_ASH) - ash::Shell::DeleteInstance(); - // The message center is notmally shutdown on |g_browser_process| which - // is not created for these tests. - message_center::MessageCenter::Shutdown(); - aura::Env::DeleteInstance(); - ui::TerminateContextFactoryForTests(); -#endif -#if defined(USE_AURA) - wm_state_.reset(); -#endif - ui::ShutdownInputMethodForTesting(); -} - -content::ShowDesktopNotificationHostMsgParams -DesktopNotificationsTest::StandardTestNotification() { - content::ShowDesktopNotificationHostMsgParams params; - params.notification_id = 0; - params.origin = GURL("http://www.google.com"); - params.icon_url = GURL("/icon.png"); - params.title = base::ASCIIToUTF16("Title"); - params.body = base::ASCIIToUTF16("Text"); - params.direction = blink::WebTextDirectionDefault; - return params; -} - -TEST_F(DesktopNotificationsTest, TestShow) { - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - params.notification_id = 1; - - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - base::MessageLoopForUI::current()->RunUntilIdle(); - EXPECT_EQ(1, balloon_collection_->count()); - - content::ShowDesktopNotificationHostMsgParams params2 = - StandardTestNotification(); - params2.notification_id = 2; - params2.origin = GURL("http://www.google.com"); - params2.body = base::ASCIIToUTF16("Text"); - - EXPECT_TRUE(service_->ShowDesktopNotification( - params2, 0, 0, DesktopNotificationService::PageNotification)); - base::MessageLoopForUI::current()->RunUntilIdle(); - EXPECT_EQ(2, balloon_collection_->count()); - - EXPECT_EQ("notification displayed\n" - "notification displayed\n", - log_output_); -} - -TEST_F(DesktopNotificationsTest, TestClose) { - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - params.notification_id = 1; - - // Request a notification; should open a balloon. - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - base::MessageLoopForUI::current()->RunUntilIdle(); - EXPECT_EQ(1, balloon_collection_->count()); - - // Close all the open balloons. - while (balloon_collection_->count() > 0) { - (*(balloon_collection_->GetActiveBalloons().begin()))->OnClose(true); - } - - EXPECT_EQ("notification displayed\n" - "notification closed by user\n", - log_output_); -} - -TEST_F(DesktopNotificationsTest, TestCancel) { - int process_id = 0; - int route_id = 0; - int notification_id = 1; - - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - params.notification_id = notification_id; - - // Request a notification; should open a balloon. - EXPECT_TRUE(service_->ShowDesktopNotification( - params, process_id, route_id, - DesktopNotificationService::PageNotification)); - base::MessageLoopForUI::current()->RunUntilIdle(); - EXPECT_EQ(1, balloon_collection_->count()); - - // Cancel the same notification - service_->CancelDesktopNotification(process_id, - route_id, - notification_id); - base::MessageLoopForUI::current()->RunUntilIdle(); - // Verify that the balloon collection is now empty. - EXPECT_EQ(0, balloon_collection_->count()); - - EXPECT_EQ("notification displayed\n" - "notification closed by script\n", - log_output_); -} - -#if defined(OS_WIN) || defined(TOOLKIT_VIEWS) -TEST_F(DesktopNotificationsTest, TestPositioning) { - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - std::string expected_log; - // Create some toasts. After each but the first, make sure there - // is a minimum separation between the toasts. - int last_top = 0; - for (int id = 0; id <= 3; ++id) { - params.notification_id = id; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - expected_log.append("notification displayed\n"); - int top = balloon_collection_->UppermostVerticalPosition(); - if (id > 0) - EXPECT_LE(top, last_top - balloon_collection_->MinHeight()); - last_top = top; - } - - EXPECT_EQ(expected_log, log_output_); -} - -TEST_F(DesktopNotificationsTest, TestVariableSize) { - content::ShowDesktopNotificationHostMsgParams params; - params.origin = GURL("http://long.google.com"); - params.icon_url = GURL("/icon.png"); - params.title = base::ASCIIToUTF16("Really Really Really Really Really Really " - "Really Really Really Really Really Really " - "Really Really Really Really Really Really " - "Really Long Title"), - params.body = base::ASCIIToUTF16("Text"); - params.notification_id = 0; - - std::string expected_log; - // Create some toasts. After each but the first, make sure there - // is a minimum separation between the toasts. - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - expected_log.append("notification displayed\n"); - - params.origin = GURL("http://short.google.com"); - params.title = base::ASCIIToUTF16("Short title"); - params.notification_id = 1; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - expected_log.append("notification displayed\n"); - - std::deque<Balloon*>& balloons = balloon_collection_->balloons(); - std::deque<Balloon*>::iterator iter; - for (iter = balloons.begin(); iter != balloons.end(); ++iter) { - if ((*iter)->notification().origin_url().host() == "long.google.com") { - EXPECT_GE((*iter)->GetViewSize().height(), - balloon_collection_->MinHeight()); - EXPECT_LE((*iter)->GetViewSize().height(), - balloon_collection_->MaxHeight()); - } else { - EXPECT_EQ((*iter)->GetViewSize().height(), - balloon_collection_->MinHeight()); - } - } - EXPECT_EQ(expected_log, log_output_); -} -#endif - -TEST_F(DesktopNotificationsTest, TestCancelByProfile) { - int process_id = 0; - int route_id = 0; - - TestingBrowserProcess* browser_process = - TestingBrowserProcess::GetGlobal(); - TestingProfileManager profile_manager(browser_process); - ASSERT_TRUE(profile_manager.SetUp()); - - TestingProfile* second_profile = - profile_manager.CreateTestingProfile("SecondTestingProfile"); - - scoped_ptr<DesktopNotificationService> second_service( - new DesktopNotificationService(second_profile, ui_manager_.get())); - - // Request lots of identical notifications. - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - params.notification_id = 1; - // Notice that the first one is the only one that doesn't use - // the second profile. - EXPECT_TRUE(service_->ShowDesktopNotification( - params, process_id, route_id, - DesktopNotificationService::PageNotification)); - - // |kLotsOfToasts| must be large enough to trigger a resize of the underlying - // std::deque while we're clearing it. - const int kLotsOfToasts = 20; - for (int id = 2; id <= kLotsOfToasts; ++id) { - params.notification_id = id; - EXPECT_TRUE(second_service->ShowDesktopNotification( - params, process_id, route_id, - DesktopNotificationService::PageNotification)); - } - base::MessageLoopForUI::current()->RunUntilIdle(); - - ui_manager_->CancelAllByProfile(second_profile); - - // Verify that the balloon collection only contains the single - // notification from the first profile. - EXPECT_EQ(1, balloon_collection_->count()); -} - -TEST_F(DesktopNotificationsTest, TestCancelBySourceOrigin) { - int process_id = 0; - int route_id = 0; - - // Request lots of identical notifications. - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - - // After the first, all the notifications are from attacker.com. - content::ShowDesktopNotificationHostMsgParams odd_params = - StandardTestNotification(); - odd_params.origin = GURL("attacker.com"); - - // Show the only non-attacker.com notification. - params.notification_id = 1; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, process_id, route_id, - DesktopNotificationService::PageNotification)); - - // |kLotsOfToasts| must be large enough to trigger a resize of the underlying - // std::deque while we're clearing it. - const int kLotsOfToasts = 20; - for (int id = 2; id <= kLotsOfToasts; ++id) { - odd_params.notification_id = id; - EXPECT_TRUE(service_->ShowDesktopNotification( - odd_params, process_id, route_id, - DesktopNotificationService::PageNotification)); - } - base::MessageLoopForUI::current()->RunUntilIdle(); - - ui_manager_->CancelAllBySourceOrigin(odd_params.origin); - - // Verify that the balloon collection only contains the single - // notification which is not from the canceled origin. - EXPECT_EQ(1, balloon_collection_->count()); -} - -TEST_F(DesktopNotificationsTest, TestQueueing) { - int process_id = 0; - int route_id = 0; - - // Request lots of identical notifications. - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - const int kLotsOfToasts = 20; - for (int id = 1; id <= kLotsOfToasts; ++id) { - params.notification_id = id; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, process_id, route_id, - DesktopNotificationService::PageNotification)); - } - base::MessageLoopForUI::current()->RunUntilIdle(); - - // Build up an expected log of what should be happening. - std::string expected_log; - for (int i = 0; i < balloon_collection_->max_balloon_count(); ++i) { - expected_log.append("notification displayed\n"); - } - - // The max number that our balloon collection can hold should be - // shown. - EXPECT_EQ(balloon_collection_->max_balloon_count(), - balloon_collection_->count()); - EXPECT_EQ(expected_log, log_output_); - - // Cancel the notifications from the start; the balloon space should - // remain full. - { - int id; - for (id = 1; - id <= kLotsOfToasts - balloon_collection_->max_balloon_count(); - ++id) { - service_->CancelDesktopNotification(process_id, route_id, id); - base::MessageLoopForUI::current()->RunUntilIdle(); - expected_log.append("notification closed by script\n"); - expected_log.append("notification displayed\n"); - EXPECT_EQ(balloon_collection_->max_balloon_count(), - balloon_collection_->count()); - EXPECT_EQ(expected_log, log_output_); - } - - // Now cancel the rest. It should empty the balloon space. - for (; id <= kLotsOfToasts; ++id) { - service_->CancelDesktopNotification(process_id, route_id, id); - expected_log.append("notification closed by script\n"); - base::MessageLoopForUI::current()->RunUntilIdle(); - EXPECT_EQ(expected_log, log_output_); - } - } - - // Verify that the balloon collection is now empty. - EXPECT_EQ(0, balloon_collection_->count()); -} - -TEST_F(DesktopNotificationsTest, TestEarlyDestruction) { - // Create some toasts and then prematurely delete the notification service, - // just to make sure nothing crashes/leaks. - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - for (int id = 0; id <= 3; ++id) { - params.notification_id = id; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - } - service_.reset(NULL); -} - -TEST_F(DesktopNotificationsTest, TestUserInputEscaping) { - // Create a test script with some HTML; assert that it doesn't get into the - // data:// URL that's produced for the balloon. - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - params.title = base::ASCIIToUTF16("<script>window.alert('uh oh');</script>"); - params.body = base::ASCIIToUTF16("<i>this text is in italics</i>"); - params.notification_id = 1; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - - base::MessageLoopForUI::current()->RunUntilIdle(); - EXPECT_EQ(1, balloon_collection_->count()); - Balloon* balloon = (*balloon_collection_->balloons().begin()); - GURL data_url = balloon->notification().content_url(); - EXPECT_EQ(std::string::npos, data_url.spec().find("<script>")); - EXPECT_EQ(std::string::npos, data_url.spec().find("<i>")); - // URL-encoded versions of tags should also not be found. - EXPECT_EQ(std::string::npos, data_url.spec().find("%3cscript%3e")); - EXPECT_EQ(std::string::npos, data_url.spec().find("%3ci%3e")); -} - -TEST_F(DesktopNotificationsTest, TestBoundingBox) { - // Create some notifications. - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - for (int id = 0; id <= 3; ++id) { - params.notification_id = id; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - } - - gfx::Rect box = balloon_collection_->GetBalloonsBoundingBox(); - - // Try this for all positions. - BalloonCollection::PositionPreference pref; - for (pref = BalloonCollection::UPPER_RIGHT; - pref <= BalloonCollection::LOWER_LEFT; - pref = static_cast<BalloonCollection::PositionPreference>(pref + 1)) { - // Make sure each balloon's 4 corners are inside the box. - std::deque<Balloon*>& balloons = balloon_collection_->balloons(); - std::deque<Balloon*>::iterator iter; - for (iter = balloons.begin(); iter != balloons.end(); ++iter) { - int min_x = (*iter)->GetPosition().x(); - int max_x = min_x + (*iter)->GetViewSize().width() - 1; - int min_y = (*iter)->GetPosition().y(); - int max_y = min_y + (*iter)->GetViewSize().height() - 1; - - EXPECT_TRUE(box.Contains(gfx::Point(min_x, min_y))); - EXPECT_TRUE(box.Contains(gfx::Point(min_x, max_y))); - EXPECT_TRUE(box.Contains(gfx::Point(max_x, min_y))); - EXPECT_TRUE(box.Contains(gfx::Point(max_x, max_y))); - } - } -} - -TEST_F(DesktopNotificationsTest, TestPositionPreference) { - // Set position preference to lower right. - local_state_.SetInteger(prefs::kDesktopNotificationPosition, - BalloonCollection::LOWER_RIGHT); - - // Create some notifications. - content::ShowDesktopNotificationHostMsgParams params = - StandardTestNotification(); - for (int id = 0; id <= 3; ++id) { - params.notification_id = id; - EXPECT_TRUE(service_->ShowDesktopNotification( - params, 0, 0, DesktopNotificationService::PageNotification)); - } - - std::deque<Balloon*>& balloons = balloon_collection_->balloons(); - std::deque<Balloon*>::iterator iter; - - // Check that they decrease in y-position (for MAC, with reversed - // coordinates, they should increase). - int last_y = -1; - int last_x = -1; - - for (iter = balloons.begin(); iter != balloons.end(); ++iter) { - int current_x = (*iter)->GetPosition().x(); - int current_y = (*iter)->GetPosition().y(); - if (last_x > 0) - EXPECT_EQ(last_x, current_x); - - if (last_y > 0) { -#if defined(OS_MACOSX) - EXPECT_GT(current_y, last_y); -#else - EXPECT_LT(current_y, last_y); -#endif - } - - last_x = current_x; - last_y = current_y; - } - - // Now change the position to upper right. This should cause an immediate - // repositioning, and we check for the reverse ordering. - local_state_.SetInteger(prefs::kDesktopNotificationPosition, - BalloonCollection::UPPER_RIGHT); - last_x = -1; - last_y = -1; - - for (iter = balloons.begin(); iter != balloons.end(); ++iter) { - int current_x = (*iter)->GetPosition().x(); - int current_y = (*iter)->GetPosition().y(); - - if (last_x > 0) - EXPECT_EQ(last_x, current_x); - - if (last_y > 0) { -#if defined(OS_MACOSX) - EXPECT_LT(current_y, last_y); -#else - EXPECT_GT(current_y, last_y); -#endif - } - - last_x = current_x; - last_y = current_y; - } - - // Now change the position to upper left. Confirm that the X value for the - // balloons gets smaller. - local_state_.SetInteger(prefs::kDesktopNotificationPosition, - BalloonCollection::UPPER_LEFT); - - int current_x = (*balloons.begin())->GetPosition().x(); - EXPECT_LT(current_x, last_x); -} diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h deleted file mode 100644 index 47eaf77..0000000 --- a/chrome/browser/notifications/desktop_notifications_unittest.h +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ -#define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ - -#include <deque> -#include <string> - -#include "base/message_loop/message_loop.h" -#include "base/prefs/testing_pref_service.h" -#include "chrome/browser/notifications/balloon_collection_impl.h" -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/notification.h" -#include "chrome/browser/notifications/notification_test_util.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/test/render_view_test.h" -#include "content/public/test/test_browser_thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -#if defined(USE_AURA) -namespace wm { -class WMState; -} -#endif - -class ActiveDesktopMonitor; -class DesktopNotificationsTest; -typedef LoggingNotificationDelegate<DesktopNotificationsTest> - LoggingNotificationProxy; - -// Test version of the balloon collection which counts the number -// of notifications that are added to it. -class MockBalloonCollection : public BalloonCollectionImpl { - public: - MockBalloonCollection(); - virtual ~MockBalloonCollection(); - - // Our mock collection has an area large enough for a fixed number - // of balloons. - static const int kMockBalloonSpace; - int max_balloon_count() const { return kMockBalloonSpace; } - - // BalloonCollectionImpl overrides - virtual void Add(const Notification& notification, - Profile* profile) OVERRIDE; - virtual bool HasSpace() const OVERRIDE; - virtual Balloon* MakeBalloon(const Notification& notification, - Profile* profile) OVERRIDE; - virtual void DisplayChanged() OVERRIDE {} - virtual void OnBalloonClosed(Balloon* source) OVERRIDE; - virtual const BalloonCollection::Balloons& GetActiveBalloons() OVERRIDE; - - // Number of balloons being shown. - std::deque<Balloon*>& balloons() { return balloons_; } - int count() const { return balloons_.size(); } - - // Returns the highest y-coordinate of all the balloons in the collection. - int UppermostVerticalPosition(); - - // Returns the height bounds of a balloon. - int MinHeight() { return Layout::min_balloon_height(); } - int MaxHeight() { return Layout::max_balloon_height(); } - - // Returns the bounding box. - gfx::Rect GetBalloonsBoundingBox() { - return BalloonCollectionImpl::GetBalloonsBoundingBox(); - } - - private: - std::deque<Balloon*> balloons_; -}; - -class DesktopNotificationsTest : public testing::Test { - public: - DesktopNotificationsTest(); - virtual ~DesktopNotificationsTest(); - - static void log(const std::string& message) { - log_output_.append(message); - } - - Profile* profile() { return profile_.get(); } - - protected: - // testing::Test overrides - virtual void SetUp() OVERRIDE; - virtual void TearDown() OVERRIDE; - - void AllowOrigin(const GURL& origin) { - service_->GrantPermission(origin); - } - - void DenyOrigin(const GURL& origin) { - service_->DenyPermission(origin); - } - - // Constructs a notification parameter structure for use in tests. - content::ShowDesktopNotificationHostMsgParams StandardTestNotification(); - - // Must be first member. Because we're running a unit test in browser_tests - // we need to handle TestingBrowserProcess initialization ourselves. - TestingBrowserProcessInitializer initializer_; - - // Create a message loop to allow notifications code to post tasks, - // and a thread so that notifications code runs on the expected thread. - base::MessageLoopForUI message_loop_; - content::TestBrowserThread ui_thread_; - - // Local state mock. - TestingPrefServiceSimple local_state_; - - // Test profile. - scoped_ptr<TestingProfile> profile_; - - // Mock balloon collection -- owned by the NotificationUIManager - MockBalloonCollection* balloon_collection_; - - // Real UI manager. - scoped_ptr<BalloonNotificationUIManager> ui_manager_; - - // Real DesktopNotificationService - scoped_ptr<DesktopNotificationService> service_; - - // Contains the cumulative output of the unit test. - static std::string log_output_; - - private: -#if defined(USE_AURA) - scoped_ptr<wm::WMState> wm_state_; -#endif - - DISALLOW_COPY_AND_ASSIGN(DesktopNotificationsTest); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ diff --git a/chrome/browser/notifications/fake_balloon_view.cc b/chrome/browser/notifications/fake_balloon_view.cc deleted file mode 100644 index e9b43d1..0000000 --- a/chrome/browser/notifications/fake_balloon_view.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/fake_balloon_view.h" - -FakeBalloonView::FakeBalloonView(Balloon* balloon) - : balloon_(balloon) { -} - -FakeBalloonView::~FakeBalloonView() { -} - -void FakeBalloonView::Show(Balloon* balloon) { -} - -void FakeBalloonView::Update() { -} - -void FakeBalloonView::RepositionToBalloon() { -} - -void FakeBalloonView::Close(bool by_user) { - balloon_->OnClose(by_user); -} - -gfx::Size FakeBalloonView::GetSize() const { - return balloon_->content_size(); -} - -BalloonHost* FakeBalloonView::GetHost() const { - return NULL; -} diff --git a/chrome/browser/notifications/fake_balloon_view.h b/chrome/browser/notifications/fake_balloon_view.h deleted file mode 100644 index 58ca320..0000000 --- a/chrome/browser/notifications/fake_balloon_view.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_FAKE_BALLOON_VIEW_H_ -#define CHROME_BROWSER_NOTIFICATIONS_FAKE_BALLOON_VIEW_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "chrome/browser/notifications/balloon.h" - -// Test version of a balloon view which doesn't do anything viewable, but does -// know how to close itself the same as a regular BalloonView. -class FakeBalloonView : public BalloonView { - public: - explicit FakeBalloonView(Balloon* balloon); - virtual ~FakeBalloonView(); - - private: - // Overridden from BalloonView: - virtual void Show(Balloon* balloon) OVERRIDE; - virtual void Update() OVERRIDE; - virtual void RepositionToBalloon() OVERRIDE; - virtual void Close(bool by_user) OVERRIDE; - virtual gfx::Size GetSize() const OVERRIDE; - virtual BalloonHost* GetHost() const OVERRIDE; - - // Non-owned pointer. - Balloon* balloon_; - - DISALLOW_COPY_AND_ASSIGN(FakeBalloonView); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_FAKE_BALLOON_VIEW_H_ diff --git a/chrome/browser/notifications/message_center_notification_manager.cc b/chrome/browser/notifications/message_center_notification_manager.cc index 6d500ec..bfbac75 100644 --- a/chrome/browser/notifications/message_center_notification_manager.cc +++ b/chrome/browser/notifications/message_center_notification_manager.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" +#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/notifications/desktop_notification_service.h" @@ -90,6 +91,12 @@ MessageCenterNotificationManager::~MessageCenterNotificationManager() { message_center_->RemoveObserver(this); } +void MessageCenterNotificationManager::RegisterPrefs( + PrefRegistrySimple* registry) { + registry->RegisterBooleanPref(prefs::kMessageCenterShowedFirstRunBalloon, + false); +} + //////////////////////////////////////////////////////////////////////////////// // NotificationUIManager diff --git a/chrome/browser/notifications/message_center_notification_manager.h b/chrome/browser/notifications/message_center_notification_manager.h index a87520d..52f3c165 100644 --- a/chrome/browser/notifications/message_center_notification_manager.h +++ b/chrome/browser/notifications/message_center_notification_manager.h @@ -27,6 +27,7 @@ class MessageCenterSettingsController; class Notification; +class PrefRegistrySimple; class PrefService; class Profile; @@ -48,6 +49,9 @@ class MessageCenterNotificationManager scoped_ptr<message_center::NotifierSettingsProvider> settings_provider); virtual ~MessageCenterNotificationManager(); + // Registers preferences. + static void RegisterPrefs(PrefRegistrySimple* registry); + // NotificationUIManager virtual void Add(const Notification& notification, Profile* profile) OVERRIDE; diff --git a/chrome/browser/notifications/message_center_notifications_browsertest.cc b/chrome/browser/notifications/message_center_notifications_browsertest.cc index d4e7ee4..ae50396 100644 --- a/chrome/browser/notifications/message_center_notifications_browsertest.cc +++ b/chrome/browser/notifications/message_center_notifications_browsertest.cc @@ -152,28 +152,17 @@ class MessageCenterNotificationsTest : public InProcessBrowserTest { #if !defined(OS_MACOSX) IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, RetrieveBaseParts) { - // Make sure comamnd-line switch has an effect. - EXPECT_EQ(NotificationUIManager::DelegatesToMessageCenter(), - message_center::IsRichNotificationEnabled()); EXPECT_TRUE(manager()); EXPECT_TRUE(message_center()); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_BasicAddCancel BasicAddCancel -#else -#define MAYBE_BasicAddCancel DISABLED_BasicAddCancel -#endif - -IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_BasicAddCancel) { +IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicAddCancel) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); // Someone may create system notifications like "you're in multi-profile // mode..." or something which may change the expectation. // TODO(mukai): move this to SetUpOnMainThread() after fixing the side-effect @@ -185,21 +174,13 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_BasicAddCancel) { EXPECT_EQ(0u, message_center()->NotificationCount()); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_BasicDelegate BasicDelegate -#else -#define MAYBE_BasicDelegate DISABLED_BasicDelegate -#endif - -IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_BasicDelegate) { +IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicDelegate) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); TestDelegate* delegate; manager()->Add(CreateTestNotification("hey", &delegate), profile()); // Verify that delegate accumulated correct log of events. @@ -210,22 +191,13 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_BasicDelegate) { delegate->Release(); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_ButtonClickedDelegate ButtonClickedDelegate -#else -#define MAYBE_ButtonClickedDelegate DISABLED_ButtonClickedDelegate -#endif - -IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, - MAYBE_ButtonClickedDelegate) { +IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, ButtonClickedDelegate) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); TestDelegate* delegate; manager()->Add(CreateTestNotification("n", &delegate), profile()); message_center()->ClickOnNotificationButton("n", 1); @@ -234,22 +206,14 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, delegate->Release(); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_UpdateExistingNotification UpdateExistingNotification -#else -#define MAYBE_UpdateExistingNotification DISABLED_UpdateExistingNotification -#endif - IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, - MAYBE_UpdateExistingNotification) { + UpdateExistingNotification) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); TestDelegate* delegate; manager()->Add(CreateTestNotification("n", &delegate), profile()); TestDelegate* delegate2; @@ -263,22 +227,13 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, delegate2->Release(); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_QueueWhenCenterVisible QueueWhenCenterVisible -#else -#define MAYBE_QueueWhenCenterVisible DISABLED_QueueWhenCenterVisible -#endif - -IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, - MAYBE_QueueWhenCenterVisible) { +IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, QueueWhenCenterVisible) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); TestAddObserver observer(message_center()); TestDelegate* delegate; @@ -300,24 +255,14 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, delegate2->Release(); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_UpdateNonProgressNotificationWhenCenterVisible \ - UpdateNonProgressNotificationWhenCenterVisible -#else -#define MAYBE_UpdateNonProgressNotificationWhenCenterVisible \ - DISABLED_UpdateNonProgressNotificationWhenCenterVisible -#endif - IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, - MAYBE_UpdateNonProgressNotificationWhenCenterVisible) { + UpdateNonProgressNotificationWhenCenterVisible) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); TestAddObserver observer(message_center()); TestDelegate* delegate; @@ -341,25 +286,15 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, delegate->Release(); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_UpdateNonProgressToProgressNotificationWhenCenterVisible \ - UpdateNonProgressToProgressNotificationWhenCenterVisible -#else -#define MAYBE_UpdateNonProgressToProgressNotificationWhenCenterVisible \ - DISABLED_UpdateNonProgressToProgressNotificationWhenCenterVisible -#endif - IN_PROC_BROWSER_TEST_F( MessageCenterNotificationsTest, - MAYBE_UpdateNonProgressToProgressNotificationWhenCenterVisible) { + UpdateNonProgressToProgressNotificationWhenCenterVisible) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); TestAddObserver observer(message_center()); TestDelegate* delegate; @@ -383,24 +318,14 @@ IN_PROC_BROWSER_TEST_F( delegate->Release(); } -// MessaceCenter-specific test. -#if defined(RUN_MESSAGE_CENTER_TESTS) -#define MAYBE_UpdateProgressNotificationWhenCenterVisible \ - UpdateProgressNotificationWhenCenterVisible -#else -#define MAYBE_UpdateProgressNotificationWhenCenterVisible \ - DISABLED_UpdateProgressNotificationWhenCenterVisible -#endif - IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, - MAYBE_UpdateProgressNotificationWhenCenterVisible) { + UpdateProgressNotificationWhenCenterVisible) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) return; #endif - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); TestAddObserver observer(message_center()); TestDelegate* delegate; @@ -422,7 +347,7 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, delegate->Release(); } -#if !defined(OS_CHROMEOS) && defined(RUN_MESSAGE_CENTER_TESTS) +#if !defined(OS_CHROMEOS) #define MAYBE_HideWhenFullscreenEnabled HideWhenFullscreenEnabled #else #define MAYBE_HideWhenFullscreenEnabled DISABLED_HideWhenFullscreenEnabled @@ -430,8 +355,6 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_HideWhenFullscreenEnabled) { - EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter()); - TestDelegate* delegate; manager()->Add(CreateTestNotification("n", &delegate), profile()); diff --git a/chrome/browser/notifications/message_center_notifications_unittest_win.cc b/chrome/browser/notifications/message_center_notifications_unittest_win.cc index 2f2c4ec..500db7b 100644 --- a/chrome/browser/notifications/message_center_notifications_unittest_win.cc +++ b/chrome/browser/notifications/message_center_notifications_unittest_win.cc @@ -9,7 +9,6 @@ #include "base/values.h" #include "chrome/browser/notifications/message_center_notification_manager.h" #include "chrome/browser/notifications/notification.h" -#include "chrome/browser/notifications/notification_prefs_manager.h" #include "chrome/browser/notifications/notification_test_util.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/scoped_testing_local_state.h" @@ -28,9 +27,7 @@ namespace message_center { class MessageCenterNotificationManagerTest : public testing::Test { protected: - MessageCenterNotificationManagerTest() { - NotificationPrefsManager::RegisterPrefs(local_state_.registry()); - } + MessageCenterNotificationManagerTest() {} virtual void SetUp() { // Clear the preference and initialize. diff --git a/chrome/browser/notifications/notification.cc b/chrome/browser/notifications/notification.cc index 4708376..d555353 100644 --- a/chrome/browser/notifications/notification.cc +++ b/chrome/browser/notifications/notification.cc @@ -83,14 +83,6 @@ Notification::Notification( delegate_(delegate) { // It's important to leave |icon_url_| empty with rich notifications enabled, // to prevent "Downloading" the data url and overwriting the existing |icon|. - if (!message_center::IsRichNotificationEnabled()) { - // "Upconvert" the string parameters to a data: URL. Some balloon views - // require content URL to render anything, so this serves as a backup. - if (!icon.IsEmpty()) - icon_url_ = GURL(webui::GetBitmapDataUrl(*icon.ToSkBitmap())); - content_url_ = GURL( - DesktopNotificationService::CreateDataUrl(icon_url_, title, body, dir)); - } } Notification::Notification(const GURL& origin_url, diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc index 587ed7c..f3d20d2 100644 --- a/chrome/browser/notifications/notification_browsertest.cc +++ b/chrome/browser/notifications/notification_browsertest.cc @@ -18,10 +18,6 @@ #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" -#include "chrome/browser/notifications/balloon.h" -#include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/balloon_host.h" -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" @@ -118,83 +114,6 @@ class MessageCenterChangeObserver DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); }; -class NotificationBalloonChangeObserver - : public content::NotificationObserver, - public NotificationChangeObserver { - public: - NotificationBalloonChangeObserver() - : collection_(BalloonNotificationUIManager::GetInstanceForTesting()-> - balloon_collection()), - collection_changed_(false), - notification_received_(false), - running_(false), - done_(false) { - registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, - content::NotificationService::AllSources()); - registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, - content::NotificationService::AllSources()); - collection_->set_on_collection_changed_callback( - base::Bind(&NotificationBalloonChangeObserver::OnCollectionChanged, - base::Unretained(this))); - } - - virtual ~NotificationBalloonChangeObserver() { - collection_->set_on_collection_changed_callback(base::Closure()); - } - - // NotificationChangeObserver: - virtual bool Wait() OVERRIDE { - if (!Check()) { - running_ = true; - message_loop_runner_ = new content::MessageLoopRunner; - message_loop_runner_->Run(); - EXPECT_TRUE(done_); - } - return done_; - } - - bool Check() { - if (done_) - return true; - - if (collection_changed_ && notification_received_) { - done_ = true; - if (running_) { - message_loop_runner_->Quit(); - running_ = false; - } - } - return done_; - } - - void OnCollectionChanged() { - collection_changed_ = true; - Check(); - } - - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE { - DCHECK(type == chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED || - type == chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED); - notification_received_ = true; - Check(); - } - - private: - content::NotificationRegistrar registrar_; - BalloonCollection* collection_; - - bool collection_changed_; - bool notification_received_; - bool running_; - bool done_; - scoped_refptr<content::MessageLoopRunner> message_loop_runner_; - - DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver); -}; - } // namespace class NotificationsTest : public InProcessBrowserTest { @@ -204,13 +123,8 @@ class NotificationsTest : public InProcessBrowserTest { protected: int GetNotificationCount(); - NotificationChangeObserver* CreateObserver(); - void CloseBrowserWindow(Browser* browser); void CrashTab(Browser* browser, int index); - const std::deque<Balloon*>& GetActiveBalloons(); - void CrashNotification(Balloon* balloon); - bool CloseNotificationAndWait(const Notification& notification); void SetDefaultPermissionSetting(ContentSetting setting); void DenyOrigin(const GURL& origin); @@ -248,19 +162,7 @@ class NotificationsTest : public InProcessBrowserTest { }; int NotificationsTest::GetNotificationCount() { - if (message_center::IsRichNotificationEnabled()) { - return message_center::MessageCenter::Get()->NotificationCount(); - } else { - return BalloonNotificationUIManager::GetInstanceForTesting()-> - balloon_collection()->GetActiveBalloons().size(); - } -} - -NotificationChangeObserver* NotificationsTest::CreateObserver() { - if (message_center::IsRichNotificationEnabled()) - return new MessageCenterChangeObserver(); - else - return new NotificationBalloonChangeObserver(); + return message_center::MessageCenter::Get()->NotificationCount(); } void NotificationsTest::CloseBrowserWindow(Browser* browser) { @@ -275,25 +177,6 @@ void NotificationsTest::CrashTab(Browser* browser, int index) { content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index)); } -const std::deque<Balloon*>& NotificationsTest::GetActiveBalloons() { - return BalloonNotificationUIManager::GetInstanceForTesting()-> - balloon_collection()->GetActiveBalloons(); -} - -void NotificationsTest::CrashNotification(Balloon* balloon) { - content::CrashTab(balloon->balloon_view()->GetHost()->web_contents()); -} - -bool NotificationsTest::CloseNotificationAndWait( - const Notification& notification) { - scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); - bool success = g_browser_process->notification_ui_manager()-> - CancelById(notification.notification_id()); - if (success) - return observer->Wait(); - return false; -} - void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) { DesktopNotificationService* service = GetDesktopNotificationService(); service->SetDefaultContentSetting(setting); @@ -339,14 +222,14 @@ std::string NotificationsTest::CreateNotification( "createNotification('%s', '%s', '%s', '%s');", icon, title, body, replace_id); - scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); + MessageCenterChangeObserver observer; std::string result; bool success = content::ExecuteScriptAndExtractString( browser->tab_strip_model()->GetActiveWebContents(), script, &result); if (success && result != "-1" && wait_for_new_balloon) - success = observer->Wait(); + success = observer.Wait(); EXPECT_TRUE(success); return result; @@ -384,7 +267,7 @@ bool NotificationsTest::CancelNotification( "cancelNotification('%s');", notification_id); - scoped_ptr<NotificationChangeObserver> observer(CreateObserver()); + MessageCenterChangeObserver observer; std::string result; bool success = content::ExecuteScriptAndExtractString( browser->tab_strip_model()->GetActiveWebContents(), @@ -392,7 +275,7 @@ bool NotificationsTest::CancelNotification( &result); if (!success || result != "1") return false; - return observer->Wait(); + return observer.Wait(); } bool NotificationsTest::PerformActionOnInfoBar( @@ -529,22 +412,12 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); ASSERT_EQ(1, GetNotificationCount()); - if (message_center::IsRichNotificationEnabled()) { - message_center::NotificationList::Notifications notifications = - message_center::MessageCenter::Get()->GetVisibleNotifications(); - EXPECT_EQ(base::ASCIIToUTF16("My Title"), - (*notifications.rbegin())->title()); - EXPECT_EQ(base::ASCIIToUTF16("My Body"), - (*notifications.rbegin())->message()); - } else { - const std::deque<Balloon*>& balloons = GetActiveBalloons(); - ASSERT_EQ(1U, balloons.size()); - Balloon* balloon = balloons[0]; - const Notification& notification = balloon->notification(); - EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); - EXPECT_EQ(base::ASCIIToUTF16("My Title"), notification.title()); - EXPECT_EQ(base::ASCIIToUTF16("My Body"), notification.message()); - } + message_center::NotificationList::Notifications notifications = + message_center::MessageCenter::Get()->GetVisibleNotifications(); + EXPECT_EQ(base::ASCIIToUTF16("My Title"), + (*notifications.rbegin())->title()); + EXPECT_EQ(base::ASCIIToUTF16("My Body"), + (*notifications.rbegin())->message()); } IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { @@ -558,16 +431,11 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) { EXPECT_NE("-1", result); ASSERT_EQ(1, GetNotificationCount()); - if (message_center::IsRichNotificationEnabled()) { - message_center::NotificationList::Notifications notifications = - message_center::MessageCenter::Get()->GetVisibleNotifications(); - message_center::MessageCenter::Get()->RemoveNotification( - (*notifications.rbegin())->id(), - true); // by_user - } else { - const std::deque<Balloon*>& balloons = GetActiveBalloons(); - EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); - } + message_center::NotificationList::Notifications notifications = + message_center::MessageCenter::Get()->GetVisibleNotifications(); + message_center::MessageCenter::Get()->RemoveNotification( + (*notifications.rbegin())->id(), + true); // by_user ASSERT_EQ(0, GetNotificationCount()); } @@ -742,16 +610,11 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { ASSERT_TRUE(CheckOriginInSetting(settings, GetTestPageURL().GetOrigin())); EXPECT_EQ(1, GetNotificationCount()); - if (message_center::IsRichNotificationEnabled()) { - message_center::NotificationList::Notifications notifications = - message_center::MessageCenter::Get()->GetVisibleNotifications(); - message_center::MessageCenter::Get()->RemoveNotification( - (*notifications.rbegin())->id(), - true); // by_user - } else { - const std::deque<Balloon*>& balloons = GetActiveBalloons(); - ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification())); - } + message_center::NotificationList::Notifications notifications = + message_center::MessageCenter::Get()->GetVisibleNotifications(); + message_center::MessageCenter::Get()->RemoveNotification( + (*notifications.rbegin())->id(), + true); // by_user ASSERT_EQ(0, GetNotificationCount()); } @@ -819,25 +682,6 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, CrashTab(browser(), 0); } -IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { - // Notifications don't have their own process with the message center. - if (message_center::IsRichNotificationEnabled()) - return; - - ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); - - // Test killing a notification doesn't crash Chrome. - AllowAllOrigins(); - ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); - CreateSimpleNotification(browser(), true); - ASSERT_EQ(1, GetNotificationCount()); - - const std::deque<Balloon*>& balloons = GetActiveBalloons(); - ASSERT_EQ(1U, balloons.size()); - CrashNotification(balloons[0]); - ASSERT_EQ(0, GetNotificationCount()); -} - IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); @@ -938,21 +782,10 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); EXPECT_NE("-1", result); - if (message_center::IsRichNotificationEnabled()) { - ASSERT_EQ(1, GetNotificationCount()); - message_center::NotificationList::Notifications notifications = - message_center::MessageCenter::Get()->GetVisibleNotifications(); - EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); - EXPECT_EQ(base::ASCIIToUTF16("Body2"), - (*notifications.rbegin())->message()); - } else { - const std::deque<Balloon*>& balloons = GetActiveBalloons(); - ASSERT_EQ(1U, balloons.size()); - Balloon* balloon = balloons[0]; - const Notification& notification = balloon->notification(); - GURL EXPECTED_ICON_URL = embedded_test_server()->GetURL(kExpectedIconUrl); - EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); - EXPECT_EQ(base::ASCIIToUTF16("Title2"), notification.title()); - EXPECT_EQ(base::ASCIIToUTF16("Body2"), notification.message()); - } + ASSERT_EQ(1, GetNotificationCount()); + message_center::NotificationList::Notifications notifications = + message_center::MessageCenter::Get()->GetVisibleNotifications(); + EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); + EXPECT_EQ(base::ASCIIToUTF16("Body2"), + (*notifications.rbegin())->message()); } diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc deleted file mode 100644 index 5a199f6..0000000 --- a/chrome/browser/notifications/notification_options_menu_model.cc +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/notification_options_menu_model.h" - -#include <string> - -#include "base/logging.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/notifications/balloon.h" -#include "chrome/browser/notifications/balloon_collection.h" -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" -#include "chrome/browser/notifications/notification.h" -#include "chrome/browser/notifications/notification_prefs_manager.h" -#include "chrome/browser/notifications/notification_ui_manager.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/chrome_pages.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/content_settings_types.h" -#include "chrome/common/url_constants.h" -#include "content/public/browser/web_contents_delegate.h" -#include "extensions/common/constants.h" -#include "extensions/common/extension.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -// Menu commands -const int kTogglePermissionCommand = 0; -const int kToggleExtensionCommand = 1; -const int kOpenContentSettingsCommand = 2; -const int kCornerSelectionSubMenu = 3; - -const int kCornerGroupId = 10; -const int kCornerUpperLeft = 11; -const int kCornerUpperRight = 12; -const int kCornerLowerLeft = 13; -const int kCornerLowerRight = 14; -const int kCornerDefault = 20; - -CornerSelectionMenuModel::CornerSelectionMenuModel(Balloon* balloon) - : ui::SimpleMenuModel(this), - balloon_(balloon) { - AddRadioItem(kCornerDefault, - l10n_util::GetStringUTF16(IDS_NOTIFICATION_POSITION_DEFAULT), - kCornerGroupId); - AddSeparator(ui::NORMAL_SEPARATOR); - AddRadioItem(kCornerUpperLeft, - l10n_util::GetStringUTF16(IDS_NOTIFICATION_POSITION_UPPER_LEFT), - kCornerGroupId); - AddRadioItem(kCornerUpperRight, - l10n_util::GetStringUTF16(IDS_NOTIFICATION_POSITION_UPPER_RIGHT), - kCornerGroupId); - AddRadioItem(kCornerLowerLeft, - l10n_util::GetStringUTF16(IDS_NOTIFICATION_POSITION_LOWER_LEFT), - kCornerGroupId); - AddRadioItem(kCornerLowerRight, - l10n_util::GetStringUTF16(IDS_NOTIFICATION_POSITION_LOWER_RIGHT), - kCornerGroupId); -} - -CornerSelectionMenuModel::~CornerSelectionMenuModel() { -} - -bool CornerSelectionMenuModel::IsCommandIdChecked(int command_id) const { - // TODO(dimich): MessageCenter does not use this preference (yet?) - if (NotificationUIManager::DelegatesToMessageCenter()) - return false; - - NotificationPrefsManager* prefs = - static_cast<BalloonNotificationUIManager*>( - g_browser_process->notification_ui_manager())->prefs_manager(); - - BalloonCollection::PositionPreference current = - prefs->GetPositionPreference(); - - if (command_id == kCornerUpperLeft) - return (current == BalloonCollection::UPPER_LEFT); - else if (command_id == kCornerUpperRight) - return (current == BalloonCollection::UPPER_RIGHT); - else if (command_id == kCornerLowerLeft) - return (current == BalloonCollection::LOWER_LEFT); - else if (command_id == kCornerLowerRight) - return (current == BalloonCollection::LOWER_RIGHT); - else if (command_id == kCornerDefault) - return (current == BalloonCollection::DEFAULT_POSITION); - - NOTREACHED(); - return false; -} - -bool CornerSelectionMenuModel::IsCommandIdEnabled(int command_id) const { - // All the menu options are always enabled. - return true; -} - -bool CornerSelectionMenuModel::GetAcceleratorForCommandId( - int command_id, ui::Accelerator* accelerator) { - // Currently no accelerators. - return false; -} - -void CornerSelectionMenuModel::ExecuteCommand(int command_id, int event_flags) { - // TODO(dimich): MessageCenter does not use this preference (yet?) - if (NotificationUIManager::DelegatesToMessageCenter()) - return; - - NotificationPrefsManager* prefs = - static_cast<BalloonNotificationUIManager*>( - g_browser_process->notification_ui_manager())->prefs_manager(); - - if (command_id == kCornerUpperLeft) - prefs->SetPositionPreference(BalloonCollection::UPPER_LEFT); - else if (command_id == kCornerUpperRight) - prefs->SetPositionPreference(BalloonCollection::UPPER_RIGHT); - else if (command_id == kCornerLowerLeft) - prefs->SetPositionPreference(BalloonCollection::LOWER_LEFT); - else if (command_id == kCornerLowerRight) - prefs->SetPositionPreference(BalloonCollection::LOWER_RIGHT); - else if (command_id == kCornerDefault) - prefs->SetPositionPreference(BalloonCollection::DEFAULT_POSITION); - else - NOTREACHED(); -} - -NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon) - : ui::SimpleMenuModel(this), - balloon_(balloon) { - const Notification& notification = balloon->notification(); - const GURL& origin = notification.origin_url(); - - if (origin.SchemeIs(extensions::kExtensionScheme)) { - ExtensionService* extension_service = - balloon_->profile()->GetExtensionService(); - const extensions::Extension* extension = - extension_service->extensions()->GetExtensionOrAppByURL(origin); - // We get back no extension here when we show the notification after - // the extension has crashed. - if (extension) { - const base::string16 disable_label = l10n_util::GetStringUTF16( - IDS_EXTENSIONS_DISABLE); - AddItem(kToggleExtensionCommand, disable_label); - } - } else if (!notification.display_source().empty()) { - const base::string16 disable_label = l10n_util::GetStringFUTF16( - IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, - notification.display_source()); - AddItem(kTogglePermissionCommand, disable_label); - } - - if (!notification.display_source().empty()) { - const base::string16 settings_label = l10n_util::GetStringUTF16( - IDS_NOTIFICATIONS_SETTINGS_BUTTON); - AddItem(kOpenContentSettingsCommand, settings_label); - } - - corner_menu_model_.reset(new CornerSelectionMenuModel(balloon)); - AddSubMenu(kCornerSelectionSubMenu, - l10n_util::GetStringUTF16(IDS_NOTIFICATION_CHOOSE_POSITION), - corner_menu_model_.get()); -} - -NotificationOptionsMenuModel::~NotificationOptionsMenuModel() { -} - -bool NotificationOptionsMenuModel::IsItemForCommandIdDynamic(int command_id) - const { - return command_id == kTogglePermissionCommand || - command_id == kToggleExtensionCommand; -} - -base::string16 NotificationOptionsMenuModel::GetLabelForCommandId( - int command_id) const { - // TODO(tfarina,johnnyg): Remove this code if we decide to close notifications - // after permissions are revoked. - if (command_id == kTogglePermissionCommand || - command_id == kToggleExtensionCommand) { - const Notification& notification = balloon_->notification(); - const GURL& origin = notification.origin_url(); - - DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); - if (origin.SchemeIs(extensions::kExtensionScheme)) { - ExtensionService* extension_service = - balloon_->profile()->GetExtensionService(); - const extensions::Extension* extension = - extension_service->extensions()->GetExtensionOrAppByURL(origin); - if (extension) { - return l10n_util::GetStringUTF16( - extension_service->IsExtensionEnabled(extension->id()) ? - IDS_EXTENSIONS_DISABLE : - IDS_EXTENSIONS_ENABLE); - } - } else { - if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) { - return l10n_util::GetStringFUTF16( - IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, - notification.display_source()); - } else { - return l10n_util::GetStringFUTF16( - IDS_NOTIFICATION_BALLOON_ENABLE_MESSAGE, - notification.display_source()); - } - } - } else if (command_id == kOpenContentSettingsCommand) { - return l10n_util::GetStringUTF16(IDS_NOTIFICATIONS_SETTINGS_BUTTON); - } - return base::string16(); -} - -bool NotificationOptionsMenuModel::IsCommandIdChecked(int /* command_id */) - const { - // Nothing in the menu is checked. - return false; -} - -bool NotificationOptionsMenuModel::IsCommandIdEnabled(int /* command_id */) - const { - // All the menu options are always enabled. - return true; -} - -bool NotificationOptionsMenuModel::GetAcceleratorForCommandId( - int /* command_id */, ui::Accelerator* /* accelerator */) { - // Currently no accelerators. - return false; -} - -void NotificationOptionsMenuModel::ExecuteCommand(int command_id, - int event_flags) { - DesktopNotificationService* service = - DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); - ExtensionService* extension_service = - balloon_->profile()->GetExtensionService(); - const GURL& origin = balloon_->notification().origin_url(); - switch (command_id) { - case kTogglePermissionCommand: - if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) - service->DenyPermission(origin); - else - service->GrantPermission(origin); - break; - case kToggleExtensionCommand: { - const extensions::Extension* extension = - extension_service->extensions()->GetExtensionOrAppByURL(origin); - if (extension) { - const std::string& id = extension->id(); - if (extension_service->IsExtensionEnabled(id)) - extension_service->DisableExtension( - id, extensions::Extension::DISABLE_USER_ACTION); - else - extension_service->EnableExtension(id); - } - break; - } - case kOpenContentSettingsCommand: { - chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); - Browser* browser = chrome::FindLastActiveWithProfile( - balloon_->profile(), active_desktop); - if (!browser) { - // It is possible that there is no browser window (e.g. when there are - // background pages). - browser = new Browser(Browser::CreateParams(balloon_->profile(), - active_desktop)); - } - chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); - break; - } - default: - NOTREACHED(); - break; - } -} diff --git a/chrome/browser/notifications/notification_options_menu_model.h b/chrome/browser/notifications/notification_options_menu_model.h deleted file mode 100644 index 67b171a..0000000 --- a/chrome/browser/notifications/notification_options_menu_model.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OPTIONS_MENU_MODEL_H_ -#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OPTIONS_MENU_MODEL_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/base/models/simple_menu_model.h" - -class Balloon; - -// Model for the corner-selection submenu. -class CornerSelectionMenuModel : public ui::SimpleMenuModel, - public ui::SimpleMenuModel::Delegate { - public: - explicit CornerSelectionMenuModel(Balloon* balloon); - virtual ~CornerSelectionMenuModel(); - - // Overridden from ui::SimpleMenuModel::Delegate: - virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; - virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; - virtual bool GetAcceleratorForCommandId( - int command_id, - ui::Accelerator* accelerator) OVERRIDE; - virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; - - private: - // Not owned. - Balloon* balloon_; - - DISALLOW_COPY_AND_ASSIGN(CornerSelectionMenuModel); -}; - -// Model for the notification options menu itself. -class NotificationOptionsMenuModel : public ui::SimpleMenuModel, - public ui::SimpleMenuModel::Delegate { - public: - explicit NotificationOptionsMenuModel(Balloon* balloon); - virtual ~NotificationOptionsMenuModel(); - - // Overridden from ui::SimpleMenuModel: - virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE; - virtual base::string16 GetLabelForCommandId(int command_id) const OVERRIDE; - - // Overridden from ui::SimpleMenuModel::Delegate: - virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; - virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; - virtual bool GetAcceleratorForCommandId( - int command_id, - ui::Accelerator* accelerator) OVERRIDE; - virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; - - private: - Balloon* balloon_; // Not owned. - - scoped_ptr<CornerSelectionMenuModel> corner_menu_model_; - - DISALLOW_COPY_AND_ASSIGN(NotificationOptionsMenuModel); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OPTIONS_MENU_MODEL_H_ diff --git a/chrome/browser/notifications/notification_prefs_manager.cc b/chrome/browser/notifications/notification_prefs_manager.cc deleted file mode 100644 index a77eb63..0000000 --- a/chrome/browser/notifications/notification_prefs_manager.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/notification_prefs_manager.h" - -#include "base/prefs/pref_registry_simple.h" -#include "base/prefs/pref_service.h" -#include "chrome/common/pref_names.h" - -NotificationPrefsManager::NotificationPrefsManager(PrefService* prefs) { -#if defined(OS_CHROMEOS) - static bool have_cleared = false; - - if (!have_cleared) { - // Option menu for changing desktop notification position on ChromeOS is - // disabled. Force preference to default. - prefs->ClearPref(prefs::kDesktopNotificationPosition); - have_cleared = true; - } -#endif -} - -// static -void NotificationPrefsManager::RegisterPrefs(PrefRegistrySimple* registry) { - registry->RegisterIntegerPref(prefs::kDesktopNotificationPosition, - BalloonCollection::DEFAULT_POSITION); - registry->RegisterBooleanPref(prefs::kMessageCenterShowedFirstRunBalloon, - false); -} diff --git a/chrome/browser/notifications/notification_prefs_manager.h b/chrome/browser/notifications/notification_prefs_manager.h deleted file mode 100644 index 9bb1be2..0000000 --- a/chrome/browser/notifications/notification_prefs_manager.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PREFS_MANAGER_H_ -#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PREFS_MANAGER_H_ - -#include "chrome/browser/notifications/balloon_collection.h" - -class PrefService; -class PrefRegistrySimple; - -// This interface is used to access and mutate the preferences related to -// desktop notifications. -class NotificationPrefsManager { - public: - explicit NotificationPrefsManager(PrefService* prefs); - virtual ~NotificationPrefsManager() {} - - // Registers preferences. - static void RegisterPrefs(PrefRegistrySimple* registry); - - // Gets the preference indicating where notifications should be placed. - virtual BalloonCollection::PositionPreference - GetPositionPreference() const = 0; - - // Sets the preference that indicates where notifications should - // be placed on the screen. - virtual void SetPositionPreference( - BalloonCollection::PositionPreference preference) = 0; - - protected: - NotificationPrefsManager() {} - - private: - DISALLOW_COPY_AND_ASSIGN(NotificationPrefsManager); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PREFS_MANAGER_H_ diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc index c4e841f..eae219d 100644 --- a/chrome/browser/notifications/notification_ui_manager.cc +++ b/chrome/browser/notifications/notification_ui_manager.cc @@ -13,41 +13,14 @@ #include "chrome/browser/profiles/profile_manager.h" #include "ui/message_center/message_center_util.h" -#if !defined(OS_CHROMEOS) -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" -#endif - -// static -bool NotificationUIManager::DelegatesToMessageCenter() { - // In ChromeOS, it always uses MessageCenterNotificationManager. The flag of - // --enable-rich-notifications switches the contents and behaviors inside of - // the message center. -#if defined(OS_CHROMEOS) - return true; -#endif - return message_center::IsRichNotificationEnabled(); -} - // static NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { - if (DelegatesToMessageCenter()) { - ProfileInfoCache* profile_info_cache = - &g_browser_process->profile_manager()->GetProfileInfoCache(); - scoped_ptr<message_center::NotifierSettingsProvider> settings_provider( - new MessageCenterSettingsController(profile_info_cache)); - return new MessageCenterNotificationManager( - g_browser_process->message_center(), - local_state, - settings_provider.Pass()); - } - -#if defined(TOOLKIT_GTK) - BalloonNotificationUIManager* balloon_manager = - new BalloonNotificationUIManager(local_state); - balloon_manager->SetBalloonCollection(BalloonCollection::Create()); - return balloon_manager; -#else - CHECK(false); - return NULL; -#endif + ProfileInfoCache* profile_info_cache = + &g_browser_process->profile_manager()->GetProfileInfoCache(); + scoped_ptr<message_center::NotifierSettingsProvider> settings_provider( + new MessageCenterSettingsController(profile_info_cache)); + return new MessageCenterNotificationManager( + g_browser_process->message_center(), + local_state, + settings_provider.Pass()); } diff --git a/chrome/browser/notifications/notification_ui_manager.h b/chrome/browser/notifications/notification_ui_manager.h index 5018e0e..56db9da 100644 --- a/chrome/browser/notifications/notification_ui_manager.h +++ b/chrome/browser/notifications/notification_ui_manager.h @@ -58,13 +58,6 @@ class NotificationUIManager { // Used when the app is terminating. virtual void CancelAll() = 0; - // Temporary, while we have two implementations of Notifications UI Managers. - // One is older BalloonCollection-based and uses renderers to show - // notifications, another delegates to the new MessageCenter and uses native - // UI widgets. - // TODO(dimich): remove these eventually. - static bool DelegatesToMessageCenter(); - protected: NotificationUIManager() {} diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.cc b/chrome/browser/notifications/sync_notifier/synced_notification.cc index 69224f7..d99813c 100644 --- a/chrome/browser/notifications/sync_notifier/synced_notification.cc +++ b/chrome/browser/notifications/sync_notifier/synced_notification.cc @@ -37,10 +37,6 @@ const char kDefaultSyncedNotificationScheme[] = "https:"; // try to supply them with more than this number of buttons. const unsigned int kMaxNotificationButtonIndex = 2; -bool UseRichNotifications() { - return message_center::IsRichNotificationEnabled(); -} - // Schema-less specs default badly in windows. If we find one, add the schema // we expect instead of allowing windows specific GURL code to make it default // to "file:". @@ -100,7 +96,7 @@ void SyncedNotification::Show(Profile* profile) { } // |notifier_service| can be NULL in tests. - if (UseRichNotifications() && notifier_service_) { + if (notifier_service_) { notifier_service_->ShowWelcomeToastIfNecessary(this, notification_manager_); } @@ -123,118 +119,104 @@ void SyncedNotification::Show(Profile* profile) { new ChromeNotifierDelegate(GetKey(), notifier_service_); // Some inputs and fields are only used if there is a notification center. - if (UseRichNotifications()) { - base::Time creation_time = - base::Time::FromDoubleT(static_cast<double>(GetCreationTime())); - int priority = GetPriority(); - unsigned int button_count = GetButtonCount(); - - // Deduce which notification template to use from the data. - message_center::NotificationType notification_type = - message_center::NOTIFICATION_TYPE_BASE_FORMAT; - if (!image_url.is_empty()) { - notification_type = message_center::NOTIFICATION_TYPE_IMAGE; - } else if (button_count > 0) { - notification_type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; - } - - // Fill the optional fields with the information we need to make a - // notification. - message_center::RichNotificationData rich_notification_data; - rich_notification_data.timestamp = creation_time; - if (priority != SyncedNotification::kUndefinedPriority) - rich_notification_data.priority = priority; - - // Fill in the button data. - // TODO(petewil): Today Rich notifiations are limited to two buttons. - // When rich notifications supports more, remove the - // "&& i < kMaxNotificationButtonIndex" clause below. - for (unsigned int i = 0; - i < button_count - && i < button_bitmaps_.size() - && i < kMaxNotificationButtonIndex; - ++i) { - // Stop at the first button with no title - std::string title = GetButtonTitle(i); - if (title.empty()) - break; - message_center::ButtonInfo button_info(base::UTF8ToUTF16(title)); - if (!button_bitmaps_[i].IsEmpty()) - button_info.icon = button_bitmaps_[i]; - rich_notification_data.buttons.push_back(button_info); - } + base::Time creation_time = + base::Time::FromDoubleT(static_cast<double>(GetCreationTime())); + int priority = GetPriority(); + unsigned int button_count = GetButtonCount(); + + // Deduce which notification template to use from the data. + message_center::NotificationType notification_type = + message_center::NOTIFICATION_TYPE_BASE_FORMAT; + if (!image_url.is_empty()) { + notification_type = message_center::NOTIFICATION_TYPE_IMAGE; + } else if (button_count > 0) { + notification_type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; + } - // Fill in the bitmap images. - if (!image_bitmap_.IsEmpty()) - rich_notification_data.image = image_bitmap_; - - if (!app_icon_bitmap_.IsEmpty()) { - // Since we can't control the size of images we download, resize using a - // high quality filter down to the appropriate icon size. - // TODO(dewittj): Remove this when correct resources are sent via the - // protobuf. - SkBitmap new_app_icon = - skia::ImageOperations::Resize(app_icon_bitmap_.AsBitmap(), - skia::ImageOperations::RESIZE_BEST, - message_center::kSmallImageSize, - message_center::kSmallImageSize); - - // The app icon should be in grayscale. - // TODO(dewittj): Remove this when correct resources are sent via the - // protobuf. - color_utils::HSL shift = {-1, 0, 0.6}; - SkBitmap grayscale = - SkBitmapOperations::CreateHSLShiftedBitmap(new_app_icon, shift); - gfx::Image small_image = - gfx::Image(gfx::ImageSkia(gfx::ImageSkiaRep(grayscale, 1.0f))); - rich_notification_data.small_image = small_image; - } + // Fill the optional fields with the information we need to make a + // notification. + message_center::RichNotificationData rich_notification_data; + rich_notification_data.timestamp = creation_time; + if (priority != SyncedNotification::kUndefinedPriority) + rich_notification_data.priority = priority; + + // Fill in the button data. + // TODO(petewil): Today Rich notifiations are limited to two buttons. + // When rich notifications supports more, remove the + // "&& i < kMaxNotificationButtonIndex" clause below. + for (unsigned int i = 0; + i < button_count + && i < button_bitmaps_.size() + && i < kMaxNotificationButtonIndex; + ++i) { + // Stop at the first button with no title + std::string title = GetButtonTitle(i); + if (title.empty()) + break; + message_center::ButtonInfo button_info(base::UTF8ToUTF16(title)); + if (!button_bitmaps_[i].IsEmpty()) + button_info.icon = button_bitmaps_[i]; + rich_notification_data.buttons.push_back(button_info); + } - // Set the ContextMessage inside the rich notification data for the - // annotation. - rich_notification_data.context_message = annotation; + // Fill in the bitmap images. + if (!image_bitmap_.IsEmpty()) + rich_notification_data.image = image_bitmap_; + + if (!app_icon_bitmap_.IsEmpty()) { + // Since we can't control the size of images we download, resize using a + // high quality filter down to the appropriate icon size. + // TODO(dewittj): Remove this when correct resources are sent via the + // protobuf. + SkBitmap new_app_icon = + skia::ImageOperations::Resize(app_icon_bitmap_.AsBitmap(), + skia::ImageOperations::RESIZE_BEST, + message_center::kSmallImageSize, + message_center::kSmallImageSize); + + // The app icon should be in grayscale. + // TODO(dewittj): Remove this when correct resources are sent via the + // protobuf. + color_utils::HSL shift = {-1, 0, 0.6}; + SkBitmap grayscale = + SkBitmapOperations::CreateHSLShiftedBitmap(new_app_icon, shift); + gfx::Image small_image = + gfx::Image(gfx::ImageSkia(gfx::ImageSkiaRep(grayscale, 1.0f))); + rich_notification_data.small_image = small_image; + } - // Set the clickable flag to change the cursor on hover if a valid - // destination is found. - rich_notification_data.clickable = GetDefaultDestinationUrl().is_valid(); + // Set the ContextMessage inside the rich notification data for the + // annotation. + rich_notification_data.context_message = annotation; - // If there is at least one person sending, use the first picture. - // TODO(petewil): Someday combine multiple profile photos here. - gfx::Image icon_bitmap = app_icon_bitmap_; - if (GetProfilePictureCount() >= 1) { - icon_bitmap = sender_bitmap_; - } + // Set the clickable flag to change the cursor on hover if a valid + // destination is found. + rich_notification_data.clickable = GetDefaultDestinationUrl().is_valid(); - Notification ui_notification(notification_type, - GetOriginUrl(), - notification_heading, - notification_text, - icon_bitmap, - blink::WebTextDirectionDefault, - message_center::NotifierId(GetOriginUrl()), - display_source, - replace_key, - rich_notification_data, - delegate.get()); - // In case the notification is not supposed to be toasted, pretend that it - // has already been shown. - ui_notification.set_shown_as_popup(!toast_state_); - - notification_manager_->Add(ui_notification, profile); - } else { - // In this case we have a Webkit Notification, not a Rich Notification. - Notification ui_notification(GetOriginUrl(), - GetAppIconUrl(), - notification_heading, - notification_text, - blink::WebTextDirectionDefault, - display_source, - replace_key, - delegate.get()); - - notification_manager_->Add(ui_notification, profile); + // If there is at least one person sending, use the first picture. + // TODO(petewil): Someday combine multiple profile photos here. + gfx::Image icon_bitmap = app_icon_bitmap_; + if (GetProfilePictureCount() >= 1) { + icon_bitmap = sender_bitmap_; } + Notification ui_notification(notification_type, + GetOriginUrl(), + notification_heading, + notification_text, + icon_bitmap, + blink::WebTextDirectionDefault, + message_center::NotifierId(GetOriginUrl()), + display_source, + replace_key, + rich_notification_data, + delegate.get()); + // In case the notification is not supposed to be toasted, pretend that it + // has already been shown. + ui_notification.set_shown_as_popup(!toast_state_); + + notification_manager_->Add(ui_notification, profile); + DVLOG(1) << "Showing Synced Notification! " << heading << " " << text << " " << GetAppIconUrl() << " " << replace_key << " " << GetProfilePictureUrl(0) << " " << GetReadState(); @@ -265,13 +247,6 @@ void SyncedNotification::HideAllForAppId(std::string app_id_name) { void SyncedNotification::QueueBitmapFetchJobs( ChromeNotifierService* notifier_service, Profile* profile) { - // If we are not using the MessageCenter, call show now, and the existing - // code will handle the bitmap fetch for us. - if (!UseRichNotifications()) { - Show(profile); - return; - } - // Save off the arguments for the call to Show. notifier_service_ = notifier_service; profile_ = profile; diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc index f558fec..bda9330 100644 --- a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc +++ b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc @@ -29,10 +29,6 @@ namespace { const int kNotificationPriority = static_cast<int>( message_center::LOW_PRIORITY); -bool UseRichNotifications() { - return message_center::IsRichNotificationEnabled(); -} - } // namespace namespace notifier { @@ -257,10 +253,6 @@ TEST_F(SyncedNotificationTest, UpdateTest) { } TEST_F(SyncedNotificationTest, ShowTest) { - - if (!UseRichNotifications()) - return; - // Call the method under test using the pre-populated data. notification1_->Show(NULL); @@ -279,9 +271,6 @@ TEST_F(SyncedNotificationTest, ShowTest) { TEST_F(SyncedNotificationTest, DismissTest) { - if (!UseRichNotifications()) - return; - // Call the method under test using a dismissed notification. notification4_->Show(NULL); @@ -304,9 +293,6 @@ TEST_F(SyncedNotificationTest, CreateBitmapFetcherTest) { } TEST_F(SyncedNotificationTest, OnFetchCompleteTest) { - if (!UseRichNotifications()) - return; - // Set up the internal state that FetchBitmaps() would have set. notification1_->notification_manager_ = notification_manager(); @@ -357,9 +343,6 @@ TEST_F(SyncedNotificationTest, OnFetchCompleteTest) { // TODO(petewil): Empty bitmap should count as a successful fetch. TEST_F(SyncedNotificationTest, EmptyBitmapTest) { - if (!UseRichNotifications()) - return; - // Set up the internal state that FetchBitmaps() would have set. notification1_->notification_manager_ = notification_manager(); @@ -406,9 +389,6 @@ TEST_F(SyncedNotificationTest, EmptyBitmapTest) { } TEST_F(SyncedNotificationTest, ShowIfNewlyEnabledTest) { - if (!UseRichNotifications()) - return; - // Call the method using the wrong app id, nothing should get shown. notification1_->ShowAllForAppId(NULL, kAppId2); @@ -433,9 +413,6 @@ TEST_F(SyncedNotificationTest, ShowIfNewlyEnabledTest) { } TEST_F(SyncedNotificationTest, HideIfNewlyRemovedTest) { - if (!UseRichNotifications()) - return; - // Add the notification to the notification manger, so it exists before we // we remove it. notification1_->Show(NULL); diff --git a/chrome/browser/notifications/sync_notifier/welcome_delegate.cc b/chrome/browser/notifications/sync_notifier/welcome_delegate.cc index cc1ae6c..12076e4 100644 --- a/chrome/browser/notifications/sync_notifier/welcome_delegate.cc +++ b/chrome/browser/notifications/sync_notifier/welcome_delegate.cc @@ -22,12 +22,10 @@ namespace { void UpdateMessageCenter() { NotificationUIManager* notification_ui_manager = g_browser_process->notification_ui_manager(); - if (notification_ui_manager->DelegatesToMessageCenter()) { - MessageCenterNotificationManager* message_center_notification_manager = - static_cast<MessageCenterNotificationManager*>(notification_ui_manager); + MessageCenterNotificationManager* message_center_notification_manager = + static_cast<MessageCenterNotificationManager*>(notification_ui_manager); - message_center_notification_manager->EnsureMessageCenterClosed(); - } + message_center_notification_manager->EnsureMessageCenterClosed(); } } // namespace diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index dda16c2..d87bb3c 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -50,7 +50,7 @@ #include "chrome/browser/net/ssl_config_service_manager.h" #include "chrome/browser/network_time/network_time_service.h" #include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/notification_prefs_manager.h" +#include "chrome/browser/notifications/message_center_notification_manager.h" #include "chrome/browser/pepper_flash_settings_manager.h" #include "chrome/browser/plugins/plugin_finder.h" #include "chrome/browser/prefs/chrome_pref_service_factory.h" @@ -261,7 +261,7 @@ void RegisterLocalState(PrefRegistrySimple* registry) { #endif #if defined(ENABLE_NOTIFICATIONS) - NotificationPrefsManager::RegisterPrefs(registry); + MessageCenterNotificationManager::RegisterPrefs(registry); #endif #if defined(ENABLE_PLUGINS) diff --git a/chrome/browser/task_manager/notification_resource_provider.cc b/chrome/browser/task_manager/notification_resource_provider.cc deleted file mode 100644 index 7aaad2c..0000000 --- a/chrome/browser/task_manager/notification_resource_provider.cc +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/task_manager/notification_resource_provider.h" - -#include "base/strings/string16.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/devtools/devtools_window.h" -#include "chrome/browser/notifications/balloon_host.h" -#include "chrome/browser/notifications/balloon_notification_ui_manager.h" -#include "chrome/browser/task_manager/task_manager.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/web_contents.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image_skia.h" - -namespace task_manager { - -class NotificationResource : public Resource { - public: - explicit NotificationResource(BalloonHost* balloon_host); - virtual ~NotificationResource(); - - // Resource interface - virtual base::string16 GetTitle() const OVERRIDE; - virtual base::string16 GetProfileName() const OVERRIDE; - virtual gfx::ImageSkia GetIcon() const OVERRIDE; - virtual base::ProcessHandle GetProcess() const OVERRIDE; - virtual int GetUniqueChildProcessId() const OVERRIDE; - virtual Type GetType() const OVERRIDE; - virtual bool CanInspect() const OVERRIDE; - virtual void Inspect() const OVERRIDE; - virtual bool SupportNetworkUsage() const OVERRIDE; - virtual void SetSupportNetworkUsage() OVERRIDE { } - - private: - // The icon painted for notifications. . - static gfx::ImageSkia* default_icon_; - - // Non-owned pointer to the balloon host. - BalloonHost* balloon_host_; - - // Cached data about the balloon host. - base::ProcessHandle process_handle_; - int pid_; - int unique_process_id_; - base::string16 title_; - - DISALLOW_COPY_AND_ASSIGN(NotificationResource); -}; - -gfx::ImageSkia* NotificationResource::default_icon_ = NULL; - -NotificationResource::NotificationResource(BalloonHost* balloon_host) - : balloon_host_(balloon_host) { - if (!default_icon_) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); - } - process_handle_ = - balloon_host_->web_contents()->GetRenderProcessHost()->GetHandle(); - unique_process_id_ = - balloon_host_->web_contents()->GetRenderProcessHost()->GetID(); - pid_ = base::GetProcId(process_handle_); - title_ = l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NOTIFICATION_PREFIX, - balloon_host_->GetSource()); -} - -NotificationResource::~NotificationResource() { -} - -base::string16 NotificationResource::GetTitle() const { - return title_; -} - -base::string16 NotificationResource::GetProfileName() const { - return base::string16(); -} - -gfx::ImageSkia NotificationResource::GetIcon() const { - return *default_icon_; -} - -base::ProcessHandle NotificationResource::GetProcess() const { - return process_handle_; -} - -int NotificationResource::GetUniqueChildProcessId() const { - return unique_process_id_; -} - -Resource::Type NotificationResource::GetType() const { - return NOTIFICATION; -} - -bool NotificationResource::CanInspect() const { - return true; -} - -void NotificationResource::Inspect() const { - DevToolsWindow::OpenDevToolsWindow( - balloon_host_->web_contents()->GetRenderViewHost()); -} - -bool NotificationResource::SupportNetworkUsage() const { - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// NotificationResourceProvider class -//////////////////////////////////////////////////////////////////////////////// - -// static -NotificationResourceProvider* -NotificationResourceProvider::Create(TaskManager* task_manager) { - return new NotificationResourceProvider(task_manager); -} - -NotificationResourceProvider:: - NotificationResourceProvider(TaskManager* task_manager) - : task_manager_(task_manager), - updating_(false) { -} - -NotificationResourceProvider::~NotificationResourceProvider() { -} - -Resource* NotificationResourceProvider::GetResource( - int origin_pid, - int child_id, - int route_id) { - // TODO(johnnyg): provide resources by pid if necessary. - return NULL; -} - -void NotificationResourceProvider::StartUpdating() { - // MessageCenter does not use Balloons. - if (NotificationUIManager::DelegatesToMessageCenter()) - return; - - DCHECK(!updating_); - updating_ = true; - - // Add all the existing BalloonHosts. - BalloonNotificationUIManager* balloon_manager = - static_cast<BalloonNotificationUIManager*>( - g_browser_process->notification_ui_manager()); - BalloonCollection* collection = balloon_manager->balloon_collection(); - const BalloonCollection::Balloons& balloons = - collection->GetActiveBalloons(); - for (BalloonCollection::Balloons::const_iterator it = balloons.begin(); - it != balloons.end(); ++it) { - BalloonHost* balloon_host = (*it)->balloon_view()->GetHost(); - if (balloon_host) - AddToTaskManager(balloon_host); - } - // Register for notifications about extension process changes. - registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, - content::NotificationService::AllSources()); - registrar_.Add(this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, - content::NotificationService::AllSources()); -} - -void NotificationResourceProvider::StopUpdating() { - // MessageCenter does not use Balloons. - if (NotificationUIManager::DelegatesToMessageCenter()) - return; - - DCHECK(updating_); - updating_ = false; - - // Unregister for notifications about extension process changes. - registrar_.Remove(this, chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED, - content::NotificationService::AllSources()); - registrar_.Remove(this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, - content::NotificationService::AllSources()); - - // Delete all the resources. - STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); - resources_.clear(); -} - -void NotificationResourceProvider::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED: - AddToTaskManager(content::Source<BalloonHost>(source).ptr()); - break; - case chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED: - RemoveFromTaskManager(content::Source<BalloonHost>(source).ptr()); - break; - default: - NOTREACHED() << "Unexpected notification."; - return; - } -} - -void NotificationResourceProvider::AddToTaskManager( - BalloonHost* balloon_host) { - // The resource may already be tracked, if the task manager was opened - // while the BalloonHost was waiting to connect. - if (resources_.count(balloon_host)) - return; - NotificationResource* resource = new NotificationResource(balloon_host); - resources_[balloon_host] = resource; - task_manager_->AddResource(resource); -} - -void NotificationResourceProvider::RemoveFromTaskManager( - BalloonHost* balloon_host) { - if (!updating_) - return; - std::map<BalloonHost*, NotificationResource*>::iterator iter = - resources_.find(balloon_host); - if (iter == resources_.end()) - return; - - // Remove the resource from the Task Manager. - NotificationResource* resource = iter->second; - task_manager_->RemoveResource(resource); - - // Remove it from the map. - resources_.erase(iter); - - // Finally, delete the resource. - delete resource; -} - -} // namespace task_manager diff --git a/chrome/browser/task_manager/notification_resource_provider.h b/chrome/browser/task_manager/notification_resource_provider.h deleted file mode 100644 index eb3a730..0000000 --- a/chrome/browser/task_manager/notification_resource_provider.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TASK_MANAGER_NOTIFICATION_RESOURCE_PROVIDER_H_ -#define CHROME_BROWSER_TASK_MANAGER_NOTIFICATION_RESOURCE_PROVIDER_H_ - -#include <map> -#include <vector> - -#include "base/basictypes.h" -#include "chrome/browser/task_manager/resource_provider.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" - -class BalloonHost; -class TaskManager; - -namespace task_manager { - -class NotificationResource; - -class NotificationResourceProvider : public ResourceProvider, - public content::NotificationObserver { - public: - static NotificationResourceProvider* Create(TaskManager* task_manager); - - // ResourceProvider interface - virtual Resource* GetResource(int origin_pid, - int child_id, - int route_id) OVERRIDE; - virtual void StartUpdating() OVERRIDE; - virtual void StopUpdating() OVERRIDE; - - // content::NotificationObserver interface - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - private: - explicit NotificationResourceProvider(TaskManager* task_manager); - virtual ~NotificationResourceProvider(); - - void AddToTaskManager(BalloonHost* balloon_host); - void RemoveFromTaskManager(BalloonHost* balloon_host); - - TaskManager* task_manager_; - - // Maps the actual resources (BalloonHost*) to the Task Manager resources. - std::map<BalloonHost*, NotificationResource*> resources_; - - // A scoped container for notification registries. - content::NotificationRegistrar registrar_; - - bool updating_; - - DISALLOW_COPY_AND_ASSIGN(NotificationResourceProvider); -}; - -} // namespace task_manager - -#endif // CHROME_BROWSER_TASK_MANAGER_NOTIFICATION_RESOURCE_PROVIDER_H_ diff --git a/chrome/browser/task_manager/task_manager.cc b/chrome/browser/task_manager/task_manager.cc index 2986e48..f8834a1 100644 --- a/chrome/browser/task_manager/task_manager.cc +++ b/chrome/browser/task_manager/task_manager.cc @@ -47,10 +47,6 @@ #include "ui/base/text/bytes_formatting.h" #include "ui/gfx/image/image_skia.h" -#if defined(TOOLKIT_GTK) -#include "chrome/browser/task_manager/notification_resource_provider.h" -#endif - #if defined(OS_MACOSX) #include "content/public/browser/browser_child_process_host.h" #endif @@ -276,13 +272,6 @@ TaskManagerModel::TaskManagerModel(TaskManager* task_manager) scoped_ptr<WebContentsInformation>( new task_manager::GuestInformation()))); -#if defined(TOOLKIT_GTK) && defined(ENABLE_NOTIFICATIONS) - ResourceProvider* provider = - task_manager::NotificationResourceProvider::Create(task_manager); - if (provider) - AddResourceProvider(provider); -#endif - AddResourceProvider(new task_manager::WorkerResourceProvider(task_manager)); } diff --git a/chrome/browser/task_manager/task_manager_notification_browsertest.cc b/chrome/browser/task_manager/task_manager_notification_browsertest.cc deleted file mode 100644 index d9d1217..0000000 --- a/chrome/browser/task_manager/task_manager_notification_browsertest.cc +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/task_manager/task_manager.h" - -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/extensions/extension_browsertest.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/notifications/notification.h" -#include "chrome/browser/notifications/notification_test_util.h" -#include "chrome/browser/notifications/notification_ui_manager.h" -#include "chrome/browser/task_manager/task_manager_browsertest_util.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_dialogs.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/base/ui_test_utils.h" -#include "content/public/common/content_switches.h" -#include "grit/generated_resources.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/message_center/message_center_switches.h" -#include "ui/message_center/message_center_util.h" - -using task_manager::browsertest_util::WaitForTaskManagerRows; - -class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest { - protected: - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - ExtensionBrowserTest::SetUpCommandLine(command_line); - } - - // Returns the text we expect to see in the TaskManager for a given - // notification. - base::string16 GetTitle(const char* ascii_name) { - return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NOTIFICATION_PREFIX, - base::ASCIIToUTF16(ascii_name)); - } -}; - -// TODO(linux_aura) http://crbug.com/163931 -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) -#define MAYBE_NoticeNotificationChanges DISABLED_NoticeNotificationChanges -// Broken on gtk, see http://crbug.com/355442 -#elif defined(TOOLKIT_GTK) -#define MAYBE_NoticeNotificationChanges DISABLED_NoticeNotificationChanges -#else -#define MAYBE_NoticeNotificationChanges NoticeNotificationChanges -#endif -IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest, - MAYBE_NoticeNotificationChanges) { - // These tests do not apply with Message Center-only platforms (e.g. Ash) - // where notifications do not instantiate a new renderer. - if (message_center::IsRichNotificationEnabled()) - return; - - // Show a notification. - NotificationUIManager* notifications = - g_browser_process->notification_ui_manager(); - - base::string16 content = DesktopNotificationService::CreateDataUrl( - GURL(), base::ASCIIToUTF16("Hello World!"), base::string16(), - blink::WebTextDirectionDefault); - - // Show an initial notification before popping up the task manager. - scoped_refptr<NotificationDelegate> del0(new MockNotificationDelegate("n0")); - Notification n0( - GURL(), GURL(content), base::ASCIIToUTF16("Test 0"), base::string16(), - del0.get()); - notifications->Add(n0, browser()->profile()); - - // Show the task manager. - chrome::ShowTaskManager(browser()); - - // This notification should show up in the task manager. - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); - - scoped_refptr<NotificationDelegate> del1(new MockNotificationDelegate("n1")); - Notification n1( - GURL(), GURL(content), base::ASCIIToUTF16("Test 1"), base::string16(), - del1.get()); - scoped_refptr<NotificationDelegate> del2(new MockNotificationDelegate("n2")); - Notification n2( - GURL(), GURL(content), base::ASCIIToUTF16("Test 2"), base::string16(), - del2.get()); - - // Show two more notifications with the task manager running, then cancel - // all three notifications. - notifications->Add(n1, browser()->profile()); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 1"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 2"))); - - notifications->Add(n2, browser()->profile()); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 1"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2"))); - - notifications->CancelById(n1.notification_id()); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2"))); - - notifications->CancelById(n0.notification_id()); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 0"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2"))); - - notifications->CancelById(n2.notification_id()); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 0"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1"))); - ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 2"))); -} diff --git a/chrome/browser/ui/views/message_center/web_notification_tray_browsertest.cc b/chrome/browser/ui/views/message_center/web_notification_tray_browsertest.cc index 823aabc..fcb8bcb 100644 --- a/chrome/browser/ui/views/message_center/web_notification_tray_browsertest.cc +++ b/chrome/browser/ui/views/message_center/web_notification_tray_browsertest.cc @@ -207,7 +207,6 @@ IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, ManyPopupNotifications) { IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, ManuallyCloseMessageCenter) { NotificationUIManager* manager = g_browser_process->notification_ui_manager(); - ASSERT_TRUE(manager->DelegatesToMessageCenter()); MessageCenterNotificationManager* mc_manager = static_cast<MessageCenterNotificationManager*>(manager); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2135fad..874f026c 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1369,18 +1369,6 @@ 'browser/network_time/network_time_service_factory.h', 'browser/network_time/network_time_tracker.cc', 'browser/network_time/network_time_tracker.h', - 'browser/notifications/balloon.cc', - 'browser/notifications/balloon.h', - 'browser/notifications/balloon_collection.cc', - 'browser/notifications/balloon_collection.h', - 'browser/notifications/balloon_collection_base.cc', - 'browser/notifications/balloon_collection_base.h', - 'browser/notifications/balloon_collection_impl.cc', - 'browser/notifications/balloon_collection_impl.h', - 'browser/notifications/balloon_host.cc', - 'browser/notifications/balloon_host.h', - 'browser/notifications/balloon_notification_ui_manager.cc', - 'browser/notifications/balloon_notification_ui_manager.h', 'browser/notifications/desktop_notification_service.cc', 'browser/notifications/desktop_notification_service.h', 'browser/notifications/desktop_notification_service_factory.cc', @@ -1388,8 +1376,6 @@ 'browser/notifications/desktop_notification_service_win.cc', 'browser/notifications/extension_welcome_notification.cc', 'browser/notifications/extension_welcome_notification.h', - 'browser/notifications/fake_balloon_view.cc', - 'browser/notifications/fake_balloon_view.h', 'browser/notifications/message_center_notification_manager.cc', 'browser/notifications/message_center_notification_manager.h', 'browser/notifications/message_center_notification_manager_win.cc', @@ -1409,10 +1395,6 @@ 'browser/notifications/notification_delegate.h', 'browser/notifications/notification_object_proxy.cc', 'browser/notifications/notification_object_proxy.h', - 'browser/notifications/notification_options_menu_model.cc', - 'browser/notifications/notification_options_menu_model.h', - 'browser/notifications/notification_prefs_manager.cc', - 'browser/notifications/notification_prefs_manager.h', 'browser/notifications/notification_system_observer.cc', 'browser/notifications/notification_system_observer.h', 'browser/notifications/notification_ui_manager.cc', diff --git a/chrome/chrome_nibs.gyp b/chrome/chrome_nibs.gyp index 5b1b982..f5a5f4a 100644 --- a/chrome/chrome_nibs.gyp +++ b/chrome/chrome_nibs.gyp @@ -182,10 +182,6 @@ 'browser/ui/cocoa/multi_key_equivalent_button.mm', 'browser/ui/cocoa/new_tab_button.h', 'browser/ui/cocoa/new_tab_button.mm', - 'browser/ui/cocoa/notifications/balloon_controller.h', - 'browser/ui/cocoa/notifications/balloon_controller.mm', - 'browser/ui/cocoa/notifications/balloon_view.h', - 'browser/ui/cocoa/notifications/balloon_view.mm', 'browser/ui/cocoa/nsmenuitem_additions.h', 'browser/ui/cocoa/nsmenuitem_additions.mm', 'browser/ui/cocoa/nsview_additions.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index cbaf0361..01daeba 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -73,8 +73,6 @@ 'browser/extensions/updater/extension_cache_fake.cc', 'browser/extensions/window_open_interactive_apitest.cc', 'browser/mouseleave_browsertest.cc', - 'browser/notifications/desktop_notifications_unittest.cc', - 'browser/notifications/desktop_notifications_unittest.h', 'browser/password_manager/password_generation_interactive_uitest.cc', 'browser/renderer_context_menu/render_view_context_menu_browsertest_util.cc', 'browser/renderer_context_menu/render_view_context_menu_browsertest_util.h', @@ -1298,7 +1296,6 @@ 'browser/task_manager/task_manager_browsertest.cc', 'browser/task_manager/task_manager_browsertest_util.cc', 'browser/task_manager/task_manager_browsertest_util.h', - 'browser/task_manager/task_manager_notification_browsertest.cc', 'browser/themes/theme_service_browsertest.cc', 'browser/translate/translate_browsertest.cc', 'browser/translate/translate_manager_browsertest.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 5aaf28740..8a5e781 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1029,10 +1029,6 @@ const char kShowUpdatePromotionInfoBar[] = // true, we draw a custom chrome frame (thicker title bar and blue border). const char kUseCustomChromeFrame[] = "browser.custom_chrome_frame"; -// The preferred position (which corner of screen) for desktop notifications. -const char kDesktopNotificationPosition[] = - "browser.desktop_notification_position"; - // Dictionary of content settings applied to all hosts by default. const char kDefaultContentSettings[] = "profile.default_content_settings"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 18ffd65..5da9a11 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -334,7 +334,6 @@ extern const char kDefaultBrowserSettingEnabled[]; extern const char kShowUpdatePromotionInfoBar[]; #endif extern const char kUseCustomChromeFrame[]; -extern const char kDesktopNotificationPosition[]; extern const char kDefaultContentSettings[]; extern const char kContentSettingsClearOnExitMigrated[]; extern const char kContentSettingsVersion[]; diff --git a/ui/message_center/dummy_message_center.cc b/ui/message_center/dummy_message_center.cc index 54b3082..7a77495 100644 --- a/ui/message_center/dummy_message_center.cc +++ b/ui/message_center/dummy_message_center.cc @@ -16,10 +16,6 @@ namespace message_center { -bool IsRichNotificationEnabled() { - return false; -} - // static void MessageCenter::Initialize() { } diff --git a/ui/message_center/message_center_util.cc b/ui/message_center/message_center_util.cc index c242205..3faa89b 100644 --- a/ui/message_center/message_center_util.cc +++ b/ui/message_center/message_center_util.cc @@ -9,16 +9,6 @@ namespace message_center { -// TODO(dimich): remove this function when balloon notifications are removed -// completely. -bool IsRichNotificationEnabled() { -#if defined(OS_MACOSX) || defined(USE_AURA) - return true; -#else - return false; -#endif -} - MessageCenterShowState GetMessageCenterShowState() { #if defined(OS_MACOSX) std::string tray_behavior = diff --git a/ui/message_center/message_center_util.h b/ui/message_center/message_center_util.h index dfad47c..881866a 100644 --- a/ui/message_center/message_center_util.h +++ b/ui/message_center/message_center_util.h @@ -9,14 +9,6 @@ namespace message_center { -MESSAGE_CENTER_EXPORT bool IsRichNotificationEnabled(); - -// If Rich Notificaitons are enabled by default on a platform, run the -// corresponding tests on that platform. -#if defined(OS_WIN) || defined(USE_AURA) || defined(OS_MACOSX) -#define RUN_MESSAGE_CENTER_TESTS 1 -#endif - enum MessageCenterShowState { MESSAGE_CENTER_SHOW_NEVER = 0, MESSAGE_CENTER_SHOW_UNREAD, |