| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h" | 5 #include "chrome/browser/ui/views/ash/balloon_collection_impl_ash.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/system/status_area_widget.h" |
| 10 #include "base/command_line.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" |
| 7 #include "chrome/browser/notifications/balloon.h" | 12 #include "chrome/browser/notifications/balloon.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 8 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "chrome/browser/ui/views/ash/balloon_view_ash.h" |
| 19 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" |
| 9 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" | 20 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" |
| 10 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" | 21 |
| 22 namespace { |
| 23 |
| 24 bool IsAshNotifyEnabled() { |
| 25 return CommandLine::ForCurrentProcess()->HasSwitch(ash::switches::kAshNotify); |
| 26 } |
| 27 |
| 28 } // namespace |
| 11 | 29 |
| 12 BalloonCollectionImplAsh::BalloonCollectionImplAsh() { | 30 BalloonCollectionImplAsh::BalloonCollectionImplAsh() { |
| 31 if (IsAshNotifyEnabled()) { |
| 32 ash::Shell::GetInstance()->status_area_widget()-> |
| 33 web_notification_tray()->SetDelegate(this); |
| 34 } |
| 13 } | 35 } |
| 14 | 36 |
| 15 BalloonCollectionImplAsh::~BalloonCollectionImplAsh() { | 37 BalloonCollectionImplAsh::~BalloonCollectionImplAsh() { |
| 16 } | 38 } |
| 17 | 39 |
| 40 bool BalloonCollectionImplAsh::HasSpace() const { |
| 41 if (!IsAshNotifyEnabled()) |
| 42 return BalloonCollectionImpl::HasSpace(); |
| 43 return true; // Overflow is handled by ash::WebNotificationTray. |
| 44 } |
| 45 |
| 46 void BalloonCollectionImplAsh::Add(const Notification& notification, |
| 47 Profile* profile) { |
| 48 if (IsAshNotifyEnabled()) { |
| 49 if (notification.is_html()) |
| 50 return; // HTML notifications are not supported in Ash. |
| 51 if (notification.title().empty() && notification.body().empty()) |
| 52 return; // Empty notification, don't show. |
| 53 } |
| 54 return BalloonCollectionImpl::Add(notification, profile); |
| 55 } |
| 56 |
| 57 void BalloonCollectionImplAsh::DisableExtension( |
| 58 const std::string& notifcation_id) { |
| 59 Balloon* balloon = base().FindBalloonById(notifcation_id); |
| 60 if (!balloon) |
| 61 return; |
| 62 ExtensionService* extension_service = |
| 63 balloon->profile()->GetExtensionService(); |
| 64 const GURL& origin = balloon->notification().origin_url(); |
| 65 const extensions::Extension* extension = |
| 66 extension_service->extensions()->GetExtensionOrAppByURL( |
| 67 ExtensionURLInfo(origin)); |
| 68 if (!extension) |
| 69 return; |
| 70 extension_service->DisableExtension( |
| 71 extension->id(), extensions::Extension::DISABLE_USER_ACTION); |
| 72 } |
| 73 |
| 74 void BalloonCollectionImplAsh::DisableNotificationsFromSource( |
| 75 const std::string& notifcation_id) { |
| 76 Balloon* balloon = base().FindBalloonById(notifcation_id); |
| 77 if (!balloon) |
| 78 return; |
| 79 DesktopNotificationService* service = |
| 80 DesktopNotificationServiceFactory::GetForProfile(balloon->profile()); |
| 81 service->DenyPermission(balloon->notification().origin_url()); |
| 82 } |
| 83 |
| 84 void BalloonCollectionImplAsh::NotificationRemoved( |
| 85 const std::string& notifcation_id) { |
| 86 RemoveById(notifcation_id); |
| 87 } |
| 88 |
| 89 void BalloonCollectionImplAsh::ShowSettings(const std::string& notifcation_id) { |
| 90 Balloon* balloon = base().FindBalloonById(notifcation_id); |
| 91 Profile* profile = |
| 92 balloon ? balloon->profile() : ProfileManager::GetDefaultProfile(); |
| 93 Browser* browser = browser::FindOrCreateTabbedBrowser(profile); |
| 94 browser->ShowContentSettingsPage(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 95 } |
| 96 |
| 97 void BalloonCollectionImplAsh::OnClicked(const std::string& notifcation_id) { |
| 98 Balloon* balloon = base().FindBalloonById(notifcation_id); |
| 99 if (!balloon) |
| 100 return; |
| 101 balloon->OnClick(); |
| 102 } |
| 103 |
| 18 bool BalloonCollectionImplAsh::AddWebUIMessageCallback( | 104 bool BalloonCollectionImplAsh::AddWebUIMessageCallback( |
| 19 const Notification& notification, | 105 const Notification& notification, |
| 20 const std::string& message, | 106 const std::string& message, |
| 21 const chromeos::BalloonViewHost::MessageCallback& callback) { | 107 const chromeos::BalloonViewHost::MessageCallback& callback) { |
| 22 #if defined(OS_CHROMEOS) | 108 #if defined(OS_CHROMEOS) |
| 23 Balloon* balloon = base().FindBalloon(notification); | 109 Balloon* balloon = base().FindBalloon(notification); |
| 24 if (!balloon) | 110 if (!balloon) |
| 25 return false; | 111 return false; |
| 26 | 112 |
| 27 BalloonHost* balloon_host = balloon->balloon_view()->GetHost(); | 113 BalloonHost* balloon_host = balloon->balloon_view()->GetHost(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 58 } | 144 } |
| 59 | 145 |
| 60 bool BalloonCollectionImplAsh::UpdateAndShowNotification( | 146 bool BalloonCollectionImplAsh::UpdateAndShowNotification( |
| 61 const Notification& notification) { | 147 const Notification& notification) { |
| 62 return UpdateNotification(notification); | 148 return UpdateNotification(notification); |
| 63 } | 149 } |
| 64 | 150 |
| 65 Balloon* BalloonCollectionImplAsh::MakeBalloon( | 151 Balloon* BalloonCollectionImplAsh::MakeBalloon( |
| 66 const Notification& notification, Profile* profile) { | 152 const Notification& notification, Profile* profile) { |
| 67 Balloon* balloon = new Balloon(notification, profile, this); | 153 Balloon* balloon = new Balloon(notification, profile, this); |
| 68 ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this); | 154 if (!IsAshNotifyEnabled()) { |
| 69 if (system_notifications_.find(notification.notification_id()) != | 155 ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this); |
| 70 system_notifications_.end()) | 156 if (system_notifications_.find(notification.notification_id()) != |
| 71 balloon_view->set_enable_web_ui(true); | 157 system_notifications_.end()) |
| 72 balloon->set_view(balloon_view); | 158 balloon_view->set_enable_web_ui(true); |
| 73 gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height()); | 159 balloon->set_view(balloon_view); |
| 74 balloon->set_content_size(size); | 160 gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height()); |
| 161 balloon->set_content_size(size); |
| 162 } else { |
| 163 BalloonViewAsh* balloon_view = new BalloonViewAsh(this); |
| 164 balloon->set_view(balloon_view); |
| 165 } |
| 75 return balloon; | 166 return balloon; |
| 76 } | 167 } |
| 77 | 168 |
| 78 // For now, only use BalloonCollectionImplAsh on ChromeOS, until | 169 // For now, only use BalloonCollectionImplAsh on ChromeOS, until |
| 79 // system_notifications_ is replaced with status area notifications. | 170 // system_notifications_ is replaced with status area notifications. |
| 80 #if defined(OS_CHROMEOS) | 171 #if defined(OS_CHROMEOS) |
| 81 // static | 172 // static |
| 82 BalloonCollection* BalloonCollection::Create() { | 173 BalloonCollection* BalloonCollection::Create() { |
| 83 return new BalloonCollectionImplAsh(); | 174 return new BalloonCollectionImplAsh(); |
| 84 } | 175 } |
| 85 #endif | 176 #endif |
| OLD | NEW |