| 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_registry_simple.h" | |
| 10 #include "base/prefs/pref_service.h" | |
| 11 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 12 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/browser/extensions/api/notification_provider/notification_provi
der_api.h" | 11 #include "chrome/browser/extensions/api/notification_provider/notification_provi
der_api.h" |
| 14 #include "chrome/browser/notifications/extension_welcome_notification.h" | 12 #include "chrome/browser/notifications/extension_welcome_notification.h" |
| 15 #include "chrome/browser/notifications/extension_welcome_notification_factory.h" | 13 #include "chrome/browser/notifications/extension_welcome_notification_factory.h" |
| 16 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" | 14 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" |
| 17 #include "chrome/browser/notifications/message_center_settings_controller.h" | 15 #include "chrome/browser/notifications/message_center_settings_controller.h" |
| 18 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 19 #include "chrome/browser/notifications/notification_conversion_helper.h" | 17 #include "chrome/browser/notifications/notification_conversion_helper.h" |
| 20 #include "chrome/browser/notifications/profile_notification.h" | 18 #include "chrome/browser/notifications/profile_notification.h" |
| 21 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" | 19 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/common/extensions/api/notification_provider.h" | 21 #include "chrome/common/extensions/api/notification_provider.h" |
| 24 #include "chrome/common/pref_names.h" | |
| 25 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 27 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/common/extension_set.h" | 25 #include "extensions/common/extension_set.h" |
| 29 #include "extensions/common/permissions/permissions_data.h" | 26 #include "extensions/common/permissions/permissions_data.h" |
| 30 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
| 31 #include "ui/message_center/message_center_style.h" | 28 #include "ui/message_center/message_center_style.h" |
| 32 #include "ui/message_center/message_center_tray.h" | 29 #include "ui/message_center/message_center_tray.h" |
| 33 #include "ui/message_center/message_center_types.h" | 30 #include "ui/message_center/message_center_types.h" |
| 34 #include "ui/message_center/notifier_settings.h" | 31 #include "ui/message_center/notifier_settings.h" |
| 35 | 32 |
| 36 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 37 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos
.h" | 34 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos
.h" |
| 38 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 35 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 39 #endif | 36 #endif |
| 40 | 37 |
| 41 #if defined(USE_ASH) | 38 #if defined(USE_ASH) |
| 42 #include "ash/shell.h" | 39 #include "ash/shell.h" |
| 43 #include "ash/system/web_notification/web_notification_tray.h" | 40 #include "ash/system/web_notification/web_notification_tray.h" |
| 44 #endif | 41 #endif |
| 45 | 42 |
| 46 #if defined(OS_WIN) | |
| 47 // The first-run balloon will be shown |kFirstRunIdleDelaySeconds| after all | |
| 48 // popups go away and the user has notifications in the message center. | |
| 49 const int kFirstRunIdleDelaySeconds = 1; | |
| 50 #endif | |
| 51 | |
| 52 MessageCenterNotificationManager::MessageCenterNotificationManager( | 43 MessageCenterNotificationManager::MessageCenterNotificationManager( |
| 53 message_center::MessageCenter* message_center, | 44 message_center::MessageCenter* message_center, |
| 54 PrefService* local_state, | |
| 55 scoped_ptr<message_center::NotifierSettingsProvider> settings_provider) | 45 scoped_ptr<message_center::NotifierSettingsProvider> settings_provider) |
| 56 : message_center_(message_center), | 46 : message_center_(message_center), |
| 57 #if defined(OS_WIN) | |
| 58 first_run_idle_timeout_( | |
| 59 base::TimeDelta::FromSeconds(kFirstRunIdleDelaySeconds)), | |
| 60 #endif | |
| 61 settings_provider_(settings_provider.Pass()), | 47 settings_provider_(settings_provider.Pass()), |
| 62 system_observer_(this), | 48 system_observer_(this), |
| 63 stats_collector_(message_center), | 49 stats_collector_(message_center), |
| 64 google_now_stats_collector_(message_center) | 50 google_now_stats_collector_(message_center) |
| 65 #if defined(OS_WIN) | |
| 66 , | |
| 67 weak_factory_(this) | |
| 68 #endif | |
| 69 { | 51 { |
| 70 #if defined(OS_WIN) | |
| 71 first_run_pref_.Init(prefs::kMessageCenterShowedFirstRunBalloon, local_state); | |
| 72 #endif | |
| 73 | |
| 74 message_center_->AddObserver(this); | 52 message_center_->AddObserver(this); |
| 75 message_center_->SetNotifierSettingsProvider(settings_provider_.get()); | 53 message_center_->SetNotifierSettingsProvider(settings_provider_.get()); |
| 76 | 54 |
| 77 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
| 78 blockers_.push_back( | 56 blockers_.push_back( |
| 79 new LoginStateNotificationBlockerChromeOS(message_center)); | 57 new LoginStateNotificationBlockerChromeOS(message_center)); |
| 80 #else | 58 #else |
| 81 blockers_.push_back(new ScreenLockNotificationBlocker(message_center)); | 59 blockers_.push_back(new ScreenLockNotificationBlocker(message_center)); |
| 82 #endif | 60 #endif |
| 83 blockers_.push_back(new FullscreenNotificationBlocker(message_center)); | 61 blockers_.push_back(new FullscreenNotificationBlocker(message_center)); |
| 84 | 62 |
| 85 #if defined(OS_WIN) || defined(OS_MACOSX) \ | 63 #if defined(OS_WIN) || defined(OS_MACOSX) \ |
| 86 || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 64 || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 87 // On Windows, Linux and Mac, the notification manager owns the tray icon and | 65 // On Windows, Linux and Mac, the notification manager owns the tray icon and |
| 88 // views.Other platforms have global ownership and Create will return NULL. | 66 // views.Other platforms have global ownership and Create will return NULL. |
| 89 tray_.reset(message_center::CreateMessageCenterTray()); | 67 tray_.reset(message_center::CreateMessageCenterTray()); |
| 90 #endif | 68 #endif |
| 91 } | 69 } |
| 92 | 70 |
| 93 MessageCenterNotificationManager::~MessageCenterNotificationManager() { | 71 MessageCenterNotificationManager::~MessageCenterNotificationManager() { |
| 94 message_center_->SetNotifierSettingsProvider(NULL); | 72 message_center_->SetNotifierSettingsProvider(NULL); |
| 95 message_center_->RemoveObserver(this); | 73 message_center_->RemoveObserver(this); |
| 96 | 74 |
| 97 STLDeleteContainerPairSecondPointers(profile_notifications_.begin(), | 75 STLDeleteContainerPairSecondPointers(profile_notifications_.begin(), |
| 98 profile_notifications_.end()); | 76 profile_notifications_.end()); |
| 99 profile_notifications_.clear(); | 77 profile_notifications_.clear(); |
| 100 } | 78 } |
| 101 | 79 |
| 102 void MessageCenterNotificationManager::RegisterPrefs( | |
| 103 PrefRegistrySimple* registry) { | |
| 104 registry->RegisterBooleanPref(prefs::kMessageCenterShowedFirstRunBalloon, | |
| 105 false); | |
| 106 registry->RegisterBooleanPref(prefs::kMessageCenterShowIcon, true); | |
| 107 registry->RegisterBooleanPref(prefs::kMessageCenterForcedOnTaskbar, false); | |
| 108 } | |
| 109 | |
| 110 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
| 111 // NotificationUIManager | 81 // NotificationUIManager |
| 112 | 82 |
| 113 void MessageCenterNotificationManager::Add(const Notification& notification, | 83 void MessageCenterNotificationManager::Add(const Notification& notification, |
| 114 Profile* profile) { | 84 Profile* profile) { |
| 115 if (Update(notification, profile)) | 85 if (Update(notification, profile)) |
| 116 return; | 86 return; |
| 117 | 87 |
| 118 ProfileNotification* profile_notification = | 88 ProfileNotification* profile_notification = |
| 119 new ProfileNotification(profile, notification); | 89 new ProfileNotification(profile, notification); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 268 } |
| 299 | 269 |
| 300 //////////////////////////////////////////////////////////////////////////////// | 270 //////////////////////////////////////////////////////////////////////////////// |
| 301 // MessageCenter::Observer | 271 // MessageCenter::Observer |
| 302 void MessageCenterNotificationManager::OnNotificationRemoved( | 272 void MessageCenterNotificationManager::OnNotificationRemoved( |
| 303 const std::string& id, | 273 const std::string& id, |
| 304 bool by_user) { | 274 bool by_user) { |
| 305 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 275 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 306 if (iter != profile_notifications_.end()) | 276 if (iter != profile_notifications_.end()) |
| 307 RemoveProfileNotification(iter->second); | 277 RemoveProfileNotification(iter->second); |
| 308 | |
| 309 #if defined(OS_WIN) | |
| 310 CheckFirstRunTimer(); | |
| 311 #endif | |
| 312 } | 278 } |
| 313 | 279 |
| 314 void MessageCenterNotificationManager::OnCenterVisibilityChanged( | 280 void MessageCenterNotificationManager::OnCenterVisibilityChanged( |
| 315 message_center::Visibility visibility) { | 281 message_center::Visibility visibility) { |
| 316 #if defined(OS_WIN) | |
| 317 if (visibility == message_center::VISIBILITY_TRANSIENT) | |
| 318 CheckFirstRunTimer(); | |
| 319 #endif | |
| 320 } | 282 } |
| 321 | 283 |
| 322 void MessageCenterNotificationManager::OnNotificationUpdated( | 284 void MessageCenterNotificationManager::OnNotificationUpdated( |
| 323 const std::string& id) { | 285 const std::string& id) { |
| 324 #if defined(OS_WIN) | |
| 325 CheckFirstRunTimer(); | |
| 326 #endif | |
| 327 } | 286 } |
| 328 | 287 |
| 329 void MessageCenterNotificationManager::EnsureMessageCenterClosed() { | 288 void MessageCenterNotificationManager::EnsureMessageCenterClosed() { |
| 330 if (tray_.get()) | 289 if (tray_.get() && tray_->GetMessageCenterTray()) |
| 331 tray_->GetMessageCenterTray()->HideMessageCenterBubble(); | 290 tray_->GetMessageCenterTray()->HideMessageCenterBubble(); |
| 332 | 291 |
| 333 #if defined(USE_ASH) | 292 #if defined(USE_ASH) |
| 334 if (ash::Shell::HasInstance()) { | 293 if (ash::Shell::HasInstance()) { |
| 335 ash::WebNotificationTray* tray = | 294 ash::WebNotificationTray* tray = |
| 336 ash::Shell::GetInstance()->GetWebNotificationTray(); | 295 ash::Shell::GetInstance()->GetWebNotificationTray(); |
| 337 if (tray) | 296 if (tray) |
| 338 tray->GetMessageCenterTray()->HideMessageCenterBubble(); | 297 tray->GetMessageCenterTray()->HideMessageCenterBubble(); |
| 339 } | 298 } |
| 340 #endif | 299 #endif |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 it != registry->enabled_extensions().end(); | 371 it != registry->enabled_extensions().end(); |
| 413 ++it) { | 372 ++it) { |
| 414 if ((*it->get()).permissions_data()->HasAPIPermission( | 373 if ((*it->get()).permissions_data()->HasAPIPermission( |
| 415 extensions::APIPermission::ID::kNotificationProvider)) { | 374 extensions::APIPermission::ID::kNotificationProvider)) { |
| 416 extension_id = (*it->get()).id(); | 375 extension_id = (*it->get()).id(); |
| 417 return extension_id; | 376 return extension_id; |
| 418 } | 377 } |
| 419 } | 378 } |
| 420 return extension_id; | 379 return extension_id; |
| 421 } | 380 } |
| OLD | NEW |