Chromium Code Reviews| 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..7359eb653e5e5c9c45e2816e31d7a9446ec19621 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/balloon_collection_impl_win.cc |
| @@ -0,0 +1,137 @@ |
| +// Copyright (c) 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. |
| + |
| +#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/web_notification_tray_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::WebNotificationTrayWin* host = |
| + ui::WebNotificationTrayWin::GetInstance(); |
| + host->message_center()->SetDelegate(this); |
|
sky
2013/01/18 21:30:56
You never unset this.
dewittj
2013/01/20 19:02:06
File gone.
|
| +} |
| + |
| +BalloonCollectionImplWin::~BalloonCollectionImplWin() { |
| +} |
| + |
| +bool BalloonCollectionImplWin::HasSpace() const { |
| + return true; // Overflow is handled by messagecentertray |
|
sky
2013/01/18 21:30:56
end with period.
dewittj
2013/01/20 19:02:06
File gone.
Pete Williamson
2013/01/23 19:52:16
nit: also camel case it: MessageCenterTray.
dewittj
2013/01/23 22:07:51
File gone.
|
| +} |
| + |
| +void BalloonCollectionImplWin::Add(const Notification& notification, |
| + Profile* profile) { |
| + if (notification.is_html()) |
| + return; // HTML notifications are not supported in Win. |
|
Pete Williamson
2013/01/23 19:52:16
nit - they aren't supported anywhere afaik, so we
dewittj
2013/01/23 22:07:51
File gone.
|
| + 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()); |
| +} |
| + |
|
Pete Williamson
2013/01/23 19:52:16
Overall comment - there is a lot of similarity bet
dewittj
2013/01/23 22:07:51
File gone.
|
| +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) |
|
Pete Williamson
2013/01/23 19:52:16
Why do we need this #define? I would have expecte
dewittj
2013/01/23 22:07:51
File gone.
|
| +// static |
| +BalloonCollection* BalloonCollection::Create() { |
| + if (NotificationUIManager::DelegatesToMessageCenter()) |
| + return new BalloonCollectionImplWin(); |
| + return new BalloonCollectionImpl(); |
| +} |
| +#endif |