| 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" | 7 #include "ash/shell.h" |
| 9 #include "ash/system/status_area_widget.h" | 8 #include "ash/system/status_area_widget.h" |
| 10 #include "base/command_line.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/notifications/balloon.h" | 10 #include "chrome/browser/notifications/balloon.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service.h" | 11 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 12 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 15 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "chrome/browser/ui/chrome_pages.h" | 16 #include "chrome/browser/ui/chrome_pages.h" |
| 19 #include "chrome/browser/ui/views/ash/balloon_view_ash.h" | 17 #include "chrome/browser/ui/views/ash/balloon_view_ash.h" |
| 20 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" | 18 #include "chrome/browser/ui/views/notifications/balloon_view_host.h" |
| 21 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" | 19 #include "chrome/browser/ui/views/notifications/balloon_view_views.h" |
| 22 | 20 |
| 23 namespace { | |
| 24 | |
| 25 bool IsAshNotifyEnabled() { | |
| 26 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 27 ash::switches::kAshNotifyDisabled); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 BalloonCollectionImplAsh::BalloonCollectionImplAsh() { | 21 BalloonCollectionImplAsh::BalloonCollectionImplAsh() { |
| 33 if (IsAshNotifyEnabled()) { | 22 ash::Shell::GetInstance()->status_area_widget()-> |
| 34 ash::Shell::GetInstance()->status_area_widget()-> | 23 web_notification_tray()->SetDelegate(this); |
| 35 web_notification_tray()->SetDelegate(this); | |
| 36 } | |
| 37 } | 24 } |
| 38 | 25 |
| 39 BalloonCollectionImplAsh::~BalloonCollectionImplAsh() { | 26 BalloonCollectionImplAsh::~BalloonCollectionImplAsh() { |
| 40 } | 27 } |
| 41 | 28 |
| 42 bool BalloonCollectionImplAsh::HasSpace() const { | 29 bool BalloonCollectionImplAsh::HasSpace() const { |
| 43 if (!IsAshNotifyEnabled()) | |
| 44 return BalloonCollectionImpl::HasSpace(); | |
| 45 return true; // Overflow is handled by ash::WebNotificationTray. | 30 return true; // Overflow is handled by ash::WebNotificationTray. |
| 46 } | 31 } |
| 47 | 32 |
| 48 void BalloonCollectionImplAsh::Add(const Notification& notification, | 33 void BalloonCollectionImplAsh::Add(const Notification& notification, |
| 49 Profile* profile) { | 34 Profile* profile) { |
| 50 if (IsAshNotifyEnabled()) { | 35 if (notification.is_html()) |
| 51 if (notification.is_html()) | 36 return; // HTML notifications are not supported in Ash. |
| 52 return; // HTML notifications are not supported in Ash. | 37 if (notification.title().empty() && notification.body().empty()) |
| 53 if (notification.title().empty() && notification.body().empty()) | 38 return; // Empty notification, don't show. |
| 54 return; // Empty notification, don't show. | |
| 55 } | |
| 56 return BalloonCollectionImpl::Add(notification, profile); | 39 return BalloonCollectionImpl::Add(notification, profile); |
| 57 } | 40 } |
| 58 | 41 |
| 59 void BalloonCollectionImplAsh::DisableExtension( | 42 void BalloonCollectionImplAsh::DisableExtension( |
| 60 const std::string& notifcation_id) { | 43 const std::string& notifcation_id) { |
| 61 Balloon* balloon = base().FindBalloonById(notifcation_id); | 44 Balloon* balloon = base().FindBalloonById(notifcation_id); |
| 62 const extensions::Extension* extension = GetBalloonExtension(balloon); | 45 const extensions::Extension* extension = GetBalloonExtension(balloon); |
| 63 if (!extension) | 46 if (!extension) |
| 64 return; | 47 return; |
| 65 balloon->profile()->GetExtensionService()->DisableExtension( | 48 balloon->profile()->GetExtensionService()->DisableExtension( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 if (!balloon_host) | 96 if (!balloon_host) |
| 114 return false; | 97 return false; |
| 115 chromeos::BalloonViewHost* balloon_view_host = | 98 chromeos::BalloonViewHost* balloon_view_host = |
| 116 static_cast<chromeos::BalloonViewHost*>(balloon_host); | 99 static_cast<chromeos::BalloonViewHost*>(balloon_host); |
| 117 return balloon_view_host->AddWebUIMessageCallback(message, callback); | 100 return balloon_view_host->AddWebUIMessageCallback(message, callback); |
| 118 #else | 101 #else |
| 119 return false; | 102 return false; |
| 120 #endif | 103 #endif |
| 121 } | 104 } |
| 122 | 105 |
| 123 void BalloonCollectionImplAsh::AddSystemNotification( | |
| 124 const Notification& notification, | |
| 125 Profile* profile, | |
| 126 bool sticky) { | |
| 127 system_notifications_.insert(notification.notification_id()); | |
| 128 | |
| 129 // Add balloons to the front of the stack. This ensures that system | |
| 130 // notifications will always be displayed. NOTE: This has the side effect | |
| 131 // that system notifications are displayed in inverse order, with the most | |
| 132 // recent notification always at the front of the list. | |
| 133 AddImpl(notification, profile, true /* add to front*/); | |
| 134 } | |
| 135 | |
| 136 bool BalloonCollectionImplAsh::UpdateNotification( | 106 bool BalloonCollectionImplAsh::UpdateNotification( |
| 137 const Notification& notification) { | 107 const Notification& notification) { |
| 138 Balloon* balloon = base().FindBalloon(notification); | 108 Balloon* balloon = base().FindBalloon(notification); |
| 139 if (!balloon) | 109 if (!balloon) |
| 140 return false; | 110 return false; |
| 141 balloon->Update(notification); | 111 balloon->Update(notification); |
| 142 return true; | 112 return true; |
| 143 } | 113 } |
| 144 | 114 |
| 145 bool BalloonCollectionImplAsh::UpdateAndShowNotification( | 115 bool BalloonCollectionImplAsh::UpdateAndShowNotification( |
| 146 const Notification& notification) { | 116 const Notification& notification) { |
| 147 return UpdateNotification(notification); | 117 return UpdateNotification(notification); |
| 148 } | 118 } |
| 149 | 119 |
| 150 Balloon* BalloonCollectionImplAsh::MakeBalloon( | 120 Balloon* BalloonCollectionImplAsh::MakeBalloon( |
| 151 const Notification& notification, Profile* profile) { | 121 const Notification& notification, Profile* profile) { |
| 152 Balloon* balloon = new Balloon(notification, profile, this); | 122 Balloon* balloon = new Balloon(notification, profile, this); |
| 153 if (!IsAshNotifyEnabled()) { | 123 BalloonViewAsh* balloon_view = new BalloonViewAsh(this); |
| 154 ::BalloonViewImpl* balloon_view = new ::BalloonViewImpl(this); | 124 balloon->set_view(balloon_view); |
| 155 if (system_notifications_.find(notification.notification_id()) != | |
| 156 system_notifications_.end()) | |
| 157 balloon_view->set_enable_web_ui(true); | |
| 158 balloon->set_view(balloon_view); | |
| 159 gfx::Size size(layout().min_balloon_width(), layout().min_balloon_height()); | |
| 160 balloon->set_content_size(size); | |
| 161 } else { | |
| 162 BalloonViewAsh* balloon_view = new BalloonViewAsh(this); | |
| 163 balloon->set_view(balloon_view); | |
| 164 } | |
| 165 return balloon; | 125 return balloon; |
| 166 } | 126 } |
| 167 | 127 |
| 168 const extensions::Extension* BalloonCollectionImplAsh::GetBalloonExtension( | 128 const extensions::Extension* BalloonCollectionImplAsh::GetBalloonExtension( |
| 169 Balloon* balloon) { | 129 Balloon* balloon) { |
| 170 if (!balloon) | 130 if (!balloon) |
| 171 return NULL; | 131 return NULL; |
| 172 ExtensionService* extension_service = | 132 ExtensionService* extension_service = |
| 173 balloon->profile()->GetExtensionService(); | 133 balloon->profile()->GetExtensionService(); |
| 174 const GURL& origin = balloon->notification().origin_url(); | 134 const GURL& origin = balloon->notification().origin_url(); |
| 175 return extension_service->extensions()->GetExtensionOrAppByURL( | 135 return extension_service->extensions()->GetExtensionOrAppByURL( |
| 176 ExtensionURLInfo(origin)); | 136 ExtensionURLInfo(origin)); |
| 177 } | 137 } |
| 178 | 138 |
| 179 // For now, only use BalloonCollectionImplAsh on ChromeOS, until | |
| 180 // system_notifications_ is replaced with status area notifications. | |
| 181 #if defined(OS_CHROMEOS) | |
| 182 // static | 139 // static |
| 183 BalloonCollection* BalloonCollection::Create() { | 140 BalloonCollection* BalloonCollection::Create() { |
| 184 return new BalloonCollectionImplAsh(); | 141 return new BalloonCollectionImplAsh(); |
| 185 } | 142 } |
| 186 #endif | |
| OLD | NEW |