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/extensions/extension_info_map.h" | 10 #include "chrome/browser/extensions/extension_info_map.h" |
11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/notifications/desktop_notification_service.h" | 12 #include "chrome/browser/notifications/desktop_notification_service.h" |
13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
14 #include "chrome/browser/notifications/message_center_settings_controller.h" | 14 #include "chrome/browser/notifications/message_center_settings_controller.h" |
15 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
18 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
19 #include "chrome/browser/ui/host_desktop.h" | 19 #include "chrome/browser/ui/host_desktop.h" |
20 #include "chrome/common/extensions/extension_set.h" | 20 #include "chrome/common/extensions/extension_set.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
24 #include "ui/message_center/message_center_style.h" | 24 #include "ui/message_center/message_center_style.h" |
25 #include "ui/message_center/message_center_tray.h" | 25 #include "ui/message_center/message_center_tray.h" |
26 #include "ui/message_center/notifier_settings.h" | 26 #include "ui/message_center/notifier_settings.h" |
27 | 27 |
28 MessageCenterNotificationManager::MessageCenterNotificationManager( | 28 MessageCenterNotificationManager::MessageCenterNotificationManager( |
29 message_center::MessageCenter* message_center) | 29 message_center::MessageCenter* message_center) |
30 : message_center_(message_center), | 30 : message_center_(message_center), |
31 settings_controller_(new MessageCenterSettingsController) { | 31 settings_controller_(new MessageCenterSettingsController) { |
32 message_center_->SetDelegate(this); | 32 message_center_->SetDelegate(this); |
33 message_center_->AddObserver(this); | 33 message_center_->AddObserver(this); |
34 | 34 |
35 #if defined(OS_WIN) || defined(OS_MACOSX) | 35 #if defined(OS_WIN) || defined(OS_MACOSX) |
36 // On Windows and Mac, the notification manager owns the tray icon and views. | 36 // On Windows and Mac, the notification manager owns the tray icon and views. |
37 // Other platforms have global ownership and Create will return NULL. | 37 // Other platforms have global ownership and Create will return NULL. |
38 tray_.reset(message_center::CreateMessageCenterTray()); | 38 tray_.reset(message_center::CreateMessageCenterTray()); |
39 #endif | 39 #endif |
40 } | 40 } |
41 | 41 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 DCHECK(message_center_->HasNotification(old_id)); | 159 DCHECK(message_center_->HasNotification(old_id)); |
160 | 160 |
161 // Add/remove notification in the local list but just update the same | 161 // Add/remove notification in the local list but just update the same |
162 // one in MessageCenter. | 162 // one in MessageCenter. |
163 old_notification->notification().Close(false); // Not by user. | 163 old_notification->notification().Close(false); // Not by user. |
164 delete old_notification; | 164 delete old_notification; |
165 profile_notifications_.erase(old_id); | 165 profile_notifications_.erase(old_id); |
166 ProfileNotification* new_notification = | 166 ProfileNotification* new_notification = |
167 new ProfileNotification(profile, notification, message_center_); | 167 new ProfileNotification(profile, notification, message_center_); |
168 profile_notifications_[notification.notification_id()] = new_notification; | 168 profile_notifications_[notification.notification_id()] = new_notification; |
| 169 |
| 170 // Now pass a copy to message center. |
| 171 scoped_ptr<message_center::Notification> message_center_notification( |
| 172 make_scoped_ptr(new message_center::Notification(notification))); |
| 173 message_center_notification->set_extension_id( |
| 174 new_notification->GetExtensionId()); |
169 message_center_->UpdateNotification(old_id, | 175 message_center_->UpdateNotification(old_id, |
170 notification.notification_id(), | 176 message_center_notification.Pass()); |
171 notification.title(), | 177 |
172 notification.body(), | |
173 notification.optional_fields(), | |
174 notification.delegate()); | |
175 new_notification->StartDownloads(); | 178 new_notification->StartDownloads(); |
176 return true; | 179 return true; |
177 } | 180 } |
178 } | 181 } |
179 return false; | 182 return false; |
180 } | 183 } |
181 | 184 |
182 //////////////////////////////////////////////////////////////////////////////// | 185 //////////////////////////////////////////////////////////////////////////////// |
183 // MessageCenter::Delegate | 186 // MessageCenter::Delegate |
184 | 187 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 // private | 451 // private |
449 | 452 |
450 void MessageCenterNotificationManager::AddProfileNotification( | 453 void MessageCenterNotificationManager::AddProfileNotification( |
451 ProfileNotification* profile_notification) { | 454 ProfileNotification* profile_notification) { |
452 const Notification& notification = profile_notification->notification(); | 455 const Notification& notification = profile_notification->notification(); |
453 std::string id = notification.notification_id(); | 456 std::string id = notification.notification_id(); |
454 // Notification ids should be unique. | 457 // Notification ids should be unique. |
455 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); | 458 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); |
456 profile_notifications_[id] = profile_notification; | 459 profile_notifications_[id] = profile_notification; |
457 | 460 |
458 message_center_->AddNotification(notification.type(), | 461 // Create the copy for message center, and ensure the extension ID is correct. |
459 notification.notification_id(), | 462 scoped_ptr<message_center::Notification> message_center_notification( |
460 notification.title(), | 463 new message_center::Notification(notification)); |
461 notification.body(), | 464 message_center_notification->set_extension_id( |
462 notification.display_source(), | 465 profile_notification->GetExtensionId()); |
463 profile_notification->GetExtensionId(), | 466 message_center_->AddNotification(message_center_notification.Pass()); |
464 notification.optional_fields(), | 467 |
465 notification.delegate()); | |
466 profile_notification->StartDownloads(); | 468 profile_notification->StartDownloads(); |
467 } | 469 } |
468 | 470 |
469 void MessageCenterNotificationManager::RemoveProfileNotification( | 471 void MessageCenterNotificationManager::RemoveProfileNotification( |
470 ProfileNotification* profile_notification, | 472 ProfileNotification* profile_notification, |
471 bool by_user) { | 473 bool by_user) { |
472 profile_notification->notification().Close(by_user); | 474 profile_notification->notification().Close(by_user); |
473 std::string id = profile_notification->notification().notification_id(); | 475 std::string id = profile_notification->notification().notification_id(); |
474 profile_notifications_.erase(id); | 476 profile_notifications_.erase(id); |
475 delete profile_notification; | 477 delete profile_notification; |
476 } | 478 } |
477 | 479 |
478 MessageCenterNotificationManager::ProfileNotification* | 480 MessageCenterNotificationManager::ProfileNotification* |
479 MessageCenterNotificationManager::FindProfileNotification( | 481 MessageCenterNotificationManager::FindProfileNotification( |
480 const std::string& id) const { | 482 const std::string& id) const { |
481 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 483 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
482 if (iter == profile_notifications_.end()) | 484 if (iter == profile_notifications_.end()) |
483 return NULL; | 485 return NULL; |
484 | 486 |
485 return (*iter).second; | 487 return (*iter).second; |
486 } | 488 } |
OLD | NEW |