Index: chrome/browser/ui/views/balloon_collection_impl_win.cc |
diff --git a/chrome/browser/ui/views/balloon_collection_impl_win.cc b/chrome/browser/ui/views/balloon_collection_impl_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..461257253926c3e74a1ebb2df8c4359bcf8b4cae |
--- /dev/null |
+++ b/chrome/browser/ui/views/balloon_collection_impl_win.cc |
@@ -0,0 +1,137 @@ |
+// 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/ui/views/balloon_collection_impl_win.h" |
+ |
+#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/notifications/balloon.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_ui_manager.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/chrome_pages.h" |
+#include "chrome/browser/ui/views/balloon_view_win.h" |
+#include "chrome/browser/ui/views/message_center/message_center_tray_host_win.h" |
+#include "chrome/browser/ui/views/notifications/balloon_view_host.h" |
+#include "chrome/browser/ui/views/notifications/balloon_view_views.h" |
+#include "ui/message_center/message_center_tray.h" |
+ |
+BalloonCollectionImplWin::BalloonCollectionImplWin() { |
+ ui::MessageCenterTrayHostWin* host = |
+ ui::MessageCenterTrayHostWin::GetInstance(); |
+ host->message_center()->SetDelegate(this); |
+} |
+ |
+BalloonCollectionImplWin::~BalloonCollectionImplWin() { |
+} |
+ |
+bool BalloonCollectionImplWin::HasSpace() const { |
+ return true; // Overflow is handled by messagecentertray |
+} |
+ |
+void BalloonCollectionImplWin::Add(const Notification& notification, |
+ Profile* profile) { |
+ if (notification.is_html()) |
+ return; // HTML notifications are not supported in Win. |
+ if (notification.title().empty() && notification.body().empty()) |
+ return; // Empty notification, don't show. |
+ return BalloonCollectionImpl::Add(notification, profile); |
+} |
+ |
+void BalloonCollectionImplWin::DisableExtension( |
+ const std::string& notification_id) { |
+ Balloon* balloon = base().FindBalloonById(notification_id); |
+ const extensions::Extension* extension = GetBalloonExtension(balloon); |
+ if (!extension) |
+ return; |
+ balloon->profile()->GetExtensionService()->DisableExtension( |
+ extension->id(), extensions::Extension::DISABLE_USER_ACTION); |
+} |
+ |
+void BalloonCollectionImplWin::DisableNotificationsFromSource( |
+ const std::string& notification_id) { |
+ Balloon* balloon = base().FindBalloonById(notification_id); |
+ if (!balloon) |
+ return; |
+ DesktopNotificationService* service = |
+ DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); |
+ service->DenyPermission(balloon->notification().origin_url()); |
+} |
+ |
+void BalloonCollectionImplWin::NotificationRemoved( |
+ const std::string& notification_id) { |
+ RemoveById(notification_id); |
+} |
+ |
+void BalloonCollectionImplWin::ShowSettings( |
+ const std::string& notification_id) { |
+ Balloon* balloon = base().FindBalloonById(notification_id); |
+ Profile* profile = |
+ balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); |
+ Browser* browser = chrome::FindOrCreateTabbedBrowser( |
+ profile, |
+ chrome::HOST_DESKTOP_TYPE_NATIVE); |
+ if (GetBalloonExtension(balloon)) |
+ chrome::ShowExtensions(browser); |
+ else |
+ chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
+} |
+ |
+void BalloonCollectionImplWin::OnClicked(const std::string& notification_id) { |
+ Balloon* balloon = base().FindBalloonById(notification_id); |
+ if (!balloon) |
+ return; |
+ balloon->OnClick(); |
+} |
+ |
+void BalloonCollectionImplWin::OnButtonClicked( |
+ const std::string& notification_id, int button_index) { |
+ Balloon* balloon = base().FindBalloonById(notification_id); |
+ if (balloon) |
+ balloon->OnButtonClick(button_index); |
+} |
+ |
+bool BalloonCollectionImplWin::UpdateNotification( |
+ const Notification& notification) { |
+ Balloon* balloon = base().FindBalloon(notification); |
+ if (!balloon) |
+ return false; |
+ balloon->Update(notification); |
+ return true; |
+} |
+ |
+bool BalloonCollectionImplWin::UpdateAndShowNotification( |
+ const Notification& notification) { |
+ return UpdateNotification(notification); |
+} |
+ |
+Balloon* BalloonCollectionImplWin::MakeBalloon( |
+ const Notification& notification, Profile* profile) { |
+ Balloon* balloon = new Balloon(notification, profile, this); |
+ BalloonViewWin* balloon_view = new BalloonViewWin(this); |
+ balloon->set_view(balloon_view); |
+ return balloon; |
+} |
+ |
+const extensions::Extension* BalloonCollectionImplWin::GetBalloonExtension( |
+ Balloon* balloon) { |
+ if (!balloon) |
+ return NULL; |
+ ExtensionService* extension_service = |
+ balloon->profile()->GetExtensionService(); |
+ const GURL& origin = balloon->notification().origin_url(); |
+ return extension_service->extensions()->GetExtensionOrAppByURL( |
+ ExtensionURLInfo(origin)); |
+} |
+ |
+#if defined(OS_WIN) |
+// static |
+BalloonCollection* BalloonCollection::Create() { |
+ if (NotificationUIManager::DelegatesToMessageCenter()) |
+ return new BalloonCollectionImplWin(); |
+ return new BalloonCollectionImpl(); |
+} |
+#endif |