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" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/extensions/api/notification_provider/notification_provi der_api.h" | |
13 #include "chrome/browser/notifications/desktop_notification_service.h" | 14 #include "chrome/browser/notifications/desktop_notification_service.h" |
14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
15 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" | 16 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" |
16 #include "chrome/browser/notifications/message_center_settings_controller.h" | 17 #include "chrome/browser/notifications/message_center_settings_controller.h" |
17 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
19 #include "chrome/browser/notifications/notification_conversion_helper.h" | |
18 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" | 20 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/chrome_pages.h" | 23 #include "chrome/browser/ui/chrome_pages.h" |
22 #include "chrome/browser/ui/host_desktop.h" | 24 #include "chrome/browser/ui/host_desktop.h" |
25 #include "chrome/common/extensions/api/notification_provider.h" | |
23 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
24 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
26 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
30 #include "extensions/browser/extension_registry.h" | |
27 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
28 #include "extensions/browser/info_map.h" | 32 #include "extensions/browser/info_map.h" |
29 #include "extensions/common/extension_set.h" | 33 #include "extensions/common/extension_set.h" |
34 #include "extensions/common/permissions/permissions_data.h" | |
30 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
31 #include "ui/message_center/message_center_style.h" | 36 #include "ui/message_center/message_center_style.h" |
32 #include "ui/message_center/message_center_tray.h" | 37 #include "ui/message_center/message_center_tray.h" |
33 #include "ui/message_center/message_center_types.h" | 38 #include "ui/message_center/message_center_types.h" |
34 #include "ui/message_center/notifier_settings.h" | 39 #include "ui/message_center/notifier_settings.h" |
35 | 40 |
36 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
37 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" | 42 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" |
38 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 43 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
39 #endif | 44 #endif |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 return; | 120 return; |
116 | 121 |
117 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 122 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
118 ShowWelcomeNotificationIfNecessary(notification); | 123 ShowWelcomeNotificationIfNecessary(notification); |
119 | 124 |
120 // WARNING: You MUST use AddProfileNotification or update the message center | 125 // WARNING: You MUST use AddProfileNotification or update the message center |
121 // via the notification within a ProfileNotification object or the profile ID | 126 // via the notification within a ProfileNotification object or the profile ID |
122 // will not be correctly set for ChromeOS. | 127 // will not be correctly set for ChromeOS. |
123 AddProfileNotification( | 128 AddProfileNotification( |
124 new ProfileNotification(profile, notification, message_center_)); | 129 new ProfileNotification(profile, notification, message_center_)); |
130 | |
131 // TODO(liyanhou): Change the logic to only send notifications to one party. | |
132 // Currently, if there are apps with notificationProvider permission, | |
133 // notifications will go to both Chrome Notification Center and an app. | |
134 | |
135 // If there exists apps/extensions that have notificationProvider permission, | |
136 // reroute notifications to one of the apps/extensions. | |
137 std::string extension_id = GetExtensionTakingOverNotifications(profile); | |
138 if (!extension_id.empty()) { | |
139 RouteNotificationToAlternateProvider(notification, profile, extension_id); | |
140 } | |
dewittj
2014/08/09 00:29:52
Do you want to modify the Update function too?
liyanhou
2014/08/11 17:21:09
Yes. I was going it in the next CL.
| |
125 } | 141 } |
126 | 142 |
127 bool MessageCenterNotificationManager::Update(const Notification& notification, | 143 bool MessageCenterNotificationManager::Update(const Notification& notification, |
128 Profile* profile) { | 144 Profile* profile) { |
129 const base::string16& replace_id = notification.replace_id(); | 145 const base::string16& replace_id = notification.replace_id(); |
130 if (replace_id.empty()) | 146 if (replace_id.empty()) |
131 return false; | 147 return false; |
132 | 148 |
133 const GURL origin_url = notification.origin_url(); | 149 const GURL origin_url = notification.origin_url(); |
134 DCHECK(origin_url.is_valid()); | 150 DCHECK(origin_url.is_valid()); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 521 |
506 MessageCenterNotificationManager::ProfileNotification* | 522 MessageCenterNotificationManager::ProfileNotification* |
507 MessageCenterNotificationManager::FindProfileNotification( | 523 MessageCenterNotificationManager::FindProfileNotification( |
508 const std::string& id) const { | 524 const std::string& id) const { |
509 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 525 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
510 if (iter == profile_notifications_.end()) | 526 if (iter == profile_notifications_.end()) |
511 return NULL; | 527 return NULL; |
512 | 528 |
513 return (*iter).second; | 529 return (*iter).second; |
514 } | 530 } |
531 | |
532 void MessageCenterNotificationManager::RouteNotificationToAlternateProvider( | |
533 const Notification& notification, | |
534 Profile* profile, | |
535 std::string extension_id) { | |
536 // Convert data from Notification type to NotificationOptions type. | |
537 scoped_ptr<extensions::api::notifications::NotificationOptions> options( | |
538 new extensions::api::notifications::NotificationOptions()); | |
539 NotificationConversionHelper conversion_helper; | |
540 conversion_helper.NotificationToNotificationOptions(notification, | |
541 options.get()); | |
542 | |
543 // Fire event to send the data to an extension/app. | |
544 scoped_ptr<extensions::NotificationProviderEventRouter> event_router( | |
545 new extensions::NotificationProviderEventRouter(profile)); | |
546 event_router->CreateNotification(extension_id, | |
547 notification.notifier_id().id, | |
548 notification.delegate_id(), | |
549 *options); | |
550 } | |
551 | |
552 std::string | |
553 MessageCenterNotificationManager::GetExtensionTakingOverNotifications( | |
554 Profile* profile) { | |
555 // TODO(liyanhou): When additional settings in Chrome Settings is implemented, | |
556 // change choosing the last app with permission to a user selected app. | |
557 extensions::ExtensionRegistry* registry = | |
558 extensions::ExtensionRegistry::Get(profile); | |
559 DCHECK(registry); | |
560 std::string extension_id; | |
561 for (extensions::ExtensionSet::const_iterator it = | |
562 registry->enabled_extensions().begin(); | |
563 it != registry->enabled_extensions().end(); | |
564 ++it) { | |
565 if ((*it->get()).permissions_data()->HasAPIPermission( | |
566 extensions::APIPermission::ID::kNotificationProvider)) | |
567 extension_id = (*it->get()).id(); | |
568 } | |
569 return extension_id; | |
570 } | |
OLD | NEW |