| Index: chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
|
| diff --git a/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc b/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
|
| index 646af7d136d9bd501743a84c3a8685745e6e99e7..bc9de457d6002caf5ebeb0bdfc6cb51c9bb971a9 100644
|
| --- a/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
|
| +++ b/chrome/browser/ui/views/ash/balloon_collection_impl_ash.cc
|
| @@ -4,17 +4,103 @@
|
|
|
| #include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h"
|
|
|
| +#include "ash/ash_switches.h"
|
| +#include "ash/shell.h"
|
| +#include "ash/system/status_area_widget.h"
|
| +#include "base/command_line.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/ui/views/notifications/balloon_view_views.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/browser/ui/browser_finder.h"
|
| +#include "chrome/browser/ui/views/ash/balloon_view_ash.h"
|
| #include "chrome/browser/ui/views/notifications/balloon_view_host.h"
|
| +#include "chrome/browser/ui/views/notifications/balloon_view_views.h"
|
| +
|
| +namespace {
|
| +
|
| +bool IsAshNotifyEnabled() {
|
| + return CommandLine::ForCurrentProcess()->HasSwitch(ash::switches::kAshNotify);
|
| +}
|
| +
|
| +} // namespace
|
|
|
| BalloonCollectionImplAsh::BalloonCollectionImplAsh() {
|
| + if (IsAshNotifyEnabled()) {
|
| + ash::Shell::GetInstance()->status_area_widget()->
|
| + web_notification_tray()->SetDelegate(this);
|
| + }
|
| }
|
|
|
| BalloonCollectionImplAsh::~BalloonCollectionImplAsh() {
|
| }
|
|
|
| +bool BalloonCollectionImplAsh::HasSpace() const {
|
| + if (!IsAshNotifyEnabled())
|
| + return BalloonCollectionImpl::HasSpace();
|
| + return true; // Overflow is handled by ash::WebNotificationTray.
|
| +}
|
| +
|
| +void BalloonCollectionImplAsh::Add(const Notification& notification,
|
| + Profile* profile) {
|
| + if (IsAshNotifyEnabled()) {
|
| + if (notification.is_html())
|
| + return; // HTML notifications are not supported in Ash.
|
| + if (notification.title().empty() && notification.body().empty())
|
| + return; // Empty notification, don't show.
|
| + }
|
| + return BalloonCollectionImpl::Add(notification, profile);
|
| +}
|
| +
|
| +void BalloonCollectionImplAsh::DisableExtension(
|
| + const std::string& notifcation_id) {
|
| + Balloon* balloon = base().FindBalloonById(notifcation_id);
|
| + if (!balloon)
|
| + return;
|
| + ExtensionService* extension_service =
|
| + balloon->profile()->GetExtensionService();
|
| + const GURL& origin = balloon->notification().origin_url();
|
| + const extensions::Extension* extension =
|
| + extension_service->extensions()->GetExtensionOrAppByURL(
|
| + ExtensionURLInfo(origin));
|
| + if (!extension)
|
| + return;
|
| + extension_service->DisableExtension(
|
| + extension->id(), extensions::Extension::DISABLE_USER_ACTION);
|
| +}
|
| +
|
| +void BalloonCollectionImplAsh::DisableNotificationsFromSource(
|
| + const std::string& notifcation_id) {
|
| + Balloon* balloon = base().FindBalloonById(notifcation_id);
|
| + if (!balloon)
|
| + return;
|
| + DesktopNotificationService* service =
|
| + DesktopNotificationServiceFactory::GetForProfile(balloon->profile());
|
| + service->DenyPermission(balloon->notification().origin_url());
|
| +}
|
| +
|
| +void BalloonCollectionImplAsh::NotificationRemoved(
|
| + const std::string& notifcation_id) {
|
| + RemoveById(notifcation_id);
|
| +}
|
| +
|
| +void BalloonCollectionImplAsh::ShowSettings(const std::string& notifcation_id) {
|
| + Balloon* balloon = base().FindBalloonById(notifcation_id);
|
| + Profile* profile =
|
| + balloon ? balloon->profile() : ProfileManager::GetDefaultProfile();
|
| + Browser* browser = browser::FindOrCreateTabbedBrowser(profile);
|
| + browser->ShowContentSettingsPage(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
|
| +}
|
| +
|
| +void BalloonCollectionImplAsh::OnClicked(const std::string& notifcation_id) {
|
| + Balloon* balloon = base().FindBalloonById(notifcation_id);
|
| + if (!balloon)
|
| + return;
|
| + balloon->OnClick();
|
| +}
|
| +
|
| bool BalloonCollectionImplAsh::AddWebUIMessageCallback(
|
| const Notification& notification,
|
| const std::string& message,
|
| @@ -65,13 +151,18 @@ bool BalloonCollectionImplAsh::UpdateAndShowNotification(
|
| Balloon* BalloonCollectionImplAsh::MakeBalloon(
|
| const Notification& notification, Profile* profile) {
|
| Balloon* balloon = new Balloon(notification, profile, this);
|
| - ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this);
|
| - if (system_notifications_.find(notification.notification_id()) !=
|
| - system_notifications_.end())
|
| - balloon_view->set_enable_web_ui(true);
|
| - balloon->set_view(balloon_view);
|
| - gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height());
|
| - balloon->set_content_size(size);
|
| + if (!IsAshNotifyEnabled()) {
|
| + ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this);
|
| + if (system_notifications_.find(notification.notification_id()) !=
|
| + system_notifications_.end())
|
| + balloon_view->set_enable_web_ui(true);
|
| + balloon->set_view(balloon_view);
|
| + gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height());
|
| + balloon->set_content_size(size);
|
| + } else {
|
| + BalloonViewAsh* balloon_view = new BalloonViewAsh(this);
|
| + balloon->set_view(balloon_view);
|
| + }
|
| return balloon;
|
| }
|
|
|
|
|