| 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/notifications/message_center_notification_manager.h" | 5 #include "chrome/browser/notifications/message_center_notification_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/extensions/extension_info_map.h" | 11 #include "chrome/browser/extensions/extension_info_map.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service.h" | 13 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 15 #include "chrome/browser/notifications/message_center_settings_controller.h" | 15 #include "chrome/browser/notifications/message_center_settings_controller.h" |
| 16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
| 20 #include "chrome/browser/ui/host_desktop.h" | 20 #include "chrome/browser/ui/host_desktop.h" |
| 21 #include "chrome/common/extensions/extension_set.h" | 21 #include "chrome/common/extensions/extension_set.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
| 27 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
| 28 #include "ui/message_center/message_center_style.h" | 28 #include "ui/message_center/message_center_style.h" |
| 29 #include "ui/message_center/message_center_tray.h" | 29 #include "ui/message_center/message_center_tray.h" |
| 30 #include "ui/message_center/message_center_types.h" |
| 30 #include "ui/message_center/notifier_settings.h" | 31 #include "ui/message_center/notifier_settings.h" |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 // The first-run balloon will be shown |kFirstRunIdleDelaySeconds| after all | 34 // The first-run balloon will be shown |kFirstRunIdleDelaySeconds| after all |
| 34 // popups go away and the user has notifications in the message center. | 35 // popups go away and the user has notifications in the message center. |
| 35 const int kFirstRunIdleDelaySeconds = 1; | 36 const int kFirstRunIdleDelaySeconds = 1; |
| 36 } // namespace | 37 } // namespace |
| 37 | 38 |
| 38 MessageCenterNotificationManager::MessageCenterNotificationManager( | 39 MessageCenterNotificationManager::MessageCenterNotificationManager( |
| 39 message_center::MessageCenter* message_center, | 40 message_center::MessageCenter* message_center, |
| 40 PrefService* local_state, | 41 PrefService* local_state, |
| 41 scoped_ptr<message_center::NotifierSettingsProvider> settings_provider) | 42 scoped_ptr<message_center::NotifierSettingsProvider> settings_provider) |
| 42 : message_center_(message_center), | 43 : message_center_(message_center), |
| 43 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 44 first_run_idle_timeout_( | 45 first_run_idle_timeout_( |
| 45 base::TimeDelta::FromSeconds(kFirstRunIdleDelaySeconds)), | 46 base::TimeDelta::FromSeconds(kFirstRunIdleDelaySeconds)), |
| 46 weak_factory_(this), | 47 weak_factory_(this), |
| 47 #endif | 48 #endif |
| 48 settings_provider_(settings_provider.Pass()) { | 49 settings_provider_(settings_provider.Pass()) { |
| 49 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 50 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state); | 51 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state); |
| 51 #endif | 52 #endif |
| 52 | 53 |
| 53 message_center_->SetDelegate(this); | |
| 54 message_center_->AddObserver(this); | 54 message_center_->AddObserver(this); |
| 55 message_center_->SetNotifierSettingsProvider(settings_provider_.get()); | 55 message_center_->SetNotifierSettingsProvider(settings_provider_.get()); |
| 56 | 56 |
| 57 #if defined(OS_WIN) || defined(OS_MACOSX) \ | 57 #if defined(OS_WIN) || defined(OS_MACOSX) \ |
| 58 || (defined(USE_AURA) && !defined(USE_ASH)) | 58 || (defined(USE_AURA) && !defined(USE_ASH)) |
| 59 // On Windows, Linux and Mac, the notification manager owns the tray icon and | 59 // On Windows, Linux and Mac, the notification manager owns the tray icon and |
| 60 // views.Other platforms have global ownership and Create will return NULL. | 60 // views.Other platforms have global ownership and Create will return NULL. |
| 61 tray_.reset(message_center::CreateMessageCenterTray()); | 61 tray_.reset(message_center::CreateMessageCenterTray()); |
| 62 #endif | 62 #endif |
| 63 registrar_.Add(this, | 63 registrar_.Add(this, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 message_center_notification.Pass()); | 223 message_center_notification.Pass()); |
| 224 | 224 |
| 225 new_notification->StartDownloads(); | 225 new_notification->StartDownloads(); |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 return false; | 229 return false; |
| 230 } | 230 } |
| 231 | 231 |
| 232 //////////////////////////////////////////////////////////////////////////////// | 232 //////////////////////////////////////////////////////////////////////////////// |
| 233 // MessageCenter::Delegate | |
| 234 | |
| 235 void MessageCenterNotificationManager::ShowSettings( | |
| 236 const std::string& notification_id) { | |
| 237 // The per-message-center Settings button passes an empty string. | |
| 238 if (notification_id.empty()) { | |
| 239 NOTIMPLEMENTED(); | |
| 240 return; | |
| 241 } | |
| 242 | |
| 243 ProfileNotification* profile_notification = | |
| 244 FindProfileNotification(notification_id); | |
| 245 if (!profile_notification) | |
| 246 return; | |
| 247 | |
| 248 Browser* browser = | |
| 249 chrome::FindOrCreateTabbedBrowser(profile_notification->profile(), | |
| 250 chrome::HOST_DESKTOP_TYPE_NATIVE); | |
| 251 if (profile_notification->GetExtensionId().empty()) | |
| 252 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
| 253 else | |
| 254 chrome::ShowExtensions(browser, std::string()); | |
| 255 } | |
| 256 | |
| 257 //////////////////////////////////////////////////////////////////////////////// | |
| 258 // MessageCenter::Observer | 233 // MessageCenter::Observer |
| 259 void MessageCenterNotificationManager::OnNotificationRemoved( | 234 void MessageCenterNotificationManager::OnNotificationRemoved( |
| 260 const std::string& notification_id, | 235 const std::string& notification_id, |
| 261 bool by_user) { | 236 bool by_user) { |
| 262 // Do not call FindProfileNotification(). Some tests create notifications | 237 // Do not call FindProfileNotification(). Some tests create notifications |
| 263 // directly to MessageCenter, but this method will be called for the removals | 238 // directly to MessageCenter, but this method will be called for the removals |
| 264 // of such notifications. | 239 // of such notifications. |
| 265 NotificationMap::const_iterator iter = | 240 NotificationMap::const_iterator iter = |
| 266 profile_notifications_.find(notification_id); | 241 profile_notifications_.find(notification_id); |
| 267 if (iter != profile_notifications_.end()) | 242 if (iter != profile_notifications_.end()) |
| 268 RemoveProfileNotification(iter->second); | 243 RemoveProfileNotification(iter->second); |
| 269 | 244 |
| 270 #if defined(OS_WIN) | 245 #if defined(OS_WIN) |
| 271 CheckFirstRunTimer(); | 246 CheckFirstRunTimer(); |
| 272 #endif | 247 #endif |
| 273 } | 248 } |
| 274 | 249 |
| 275 void MessageCenterNotificationManager::OnNotificationCenterClosed() { | 250 void MessageCenterNotificationManager::OnCenterVisibilityChanged( |
| 276 // When the center is open it halts all notifications, so we need to listen | 251 message_center::Visibility visibility) { |
| 277 // for events indicating it's been closed. | 252 switch (visibility) { |
| 278 CheckAndShowNotifications(); | 253 case message_center::VISIBILITY_TRANSIENT: |
| 254 // When the center is open it halts all notifications, so we need to |
| 255 // listen for events indicating it's been closed. |
| 256 CheckAndShowNotifications(); |
| 279 #if defined(OS_WIN) | 257 #if defined(OS_WIN) |
| 280 CheckFirstRunTimer(); | 258 CheckFirstRunTimer(); |
| 281 #endif | 259 #endif |
| 260 break; |
| 261 case message_center::VISIBILITY_MESSAGE_CENTER: |
| 262 content::RecordAction( |
| 263 content::UserMetricsAction("Notifications.ShowMessageCenter")); |
| 264 break; |
| 265 case message_center::VISIBILITY_SETTINGS: |
| 266 content::RecordAction( |
| 267 content::UserMetricsAction("Notifications.ShowSettings")); |
| 268 break; |
| 269 } |
| 282 } | 270 } |
| 283 | 271 |
| 284 void MessageCenterNotificationManager::OnNotificationUpdated( | 272 void MessageCenterNotificationManager::OnNotificationUpdated( |
| 285 const std::string& notification_id) { | 273 const std::string& notification_id) { |
| 286 #if defined(OS_WIN) | 274 #if defined(OS_WIN) |
| 287 CheckFirstRunTimer(); | 275 CheckFirstRunTimer(); |
| 288 #endif | 276 #endif |
| 289 } | 277 } |
| 290 | 278 |
| 291 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest( | 279 void MessageCenterNotificationManager::SetMessageCenterTrayDelegateForTest( |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 | 501 |
| 514 MessageCenterNotificationManager::ProfileNotification* | 502 MessageCenterNotificationManager::ProfileNotification* |
| 515 MessageCenterNotificationManager::FindProfileNotification( | 503 MessageCenterNotificationManager::FindProfileNotification( |
| 516 const std::string& id) const { | 504 const std::string& id) const { |
| 517 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 505 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 518 if (iter == profile_notifications_.end()) | 506 if (iter == profile_notifications_.end()) |
| 519 return NULL; | 507 return NULL; |
| 520 | 508 |
| 521 return (*iter).second; | 509 return (*iter).second; |
| 522 } | 510 } |
| OLD | NEW |