Index: chrome/browser/notifications/message_center_notification_manager.cc |
diff --git a/chrome/browser/notifications/message_center_notification_manager.cc b/chrome/browser/notifications/message_center_notification_manager.cc |
index 8afa5a1714d82d9df32ebe9b709082e145d3dd02..8580abf0e994092927ed9c2a6ef63022314af79f 100644 |
--- a/chrome/browser/notifications/message_center_notification_manager.cc |
+++ b/chrome/browser/notifications/message_center_notification_manager.cc |
@@ -10,23 +10,28 @@ |
#include "base/prefs/pref_service.h" |
#include "base/stl_util.h" |
#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/extensions/api/notification_provider/notification_provider_api.h" |
#include "chrome/browser/notifications/desktop_notification_service.h" |
#include "chrome/browser/notifications/desktop_notification_service_factory.h" |
#include "chrome/browser/notifications/fullscreen_notification_blocker.h" |
#include "chrome/browser/notifications/message_center_settings_controller.h" |
#include "chrome/browser/notifications/notification.h" |
+#include "chrome/browser/notifications/notification_conversion_helper.h" |
#include "chrome/browser/notifications/screen_lock_notification_blocker.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/chrome_pages.h" |
#include "chrome/browser/ui/host_desktop.h" |
+#include "chrome/common/extensions/api/notification_provider.h" |
#include "chrome/common/pref_names.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/url_constants.h" |
+#include "extensions/browser/extension_registry.h" |
#include "extensions/browser/extension_system.h" |
#include "extensions/browser/info_map.h" |
#include "extensions/common/extension_set.h" |
+#include "extensions/common/permissions/permissions_data.h" |
#include "ui/gfx/image/image_skia.h" |
#include "ui/message_center/message_center_style.h" |
#include "ui/message_center/message_center_tray.h" |
@@ -122,6 +127,17 @@ void MessageCenterNotificationManager::Add(const Notification& notification, |
// will not be correctly set for ChromeOS. |
AddProfileNotification( |
new ProfileNotification(profile, notification, message_center_)); |
+ |
+ // TODO(liyanhou): Change the logic to only send notifications to one party. |
+ // Currently, if there are apps with notificationProvider permission, |
+ // notifications will go to both Chrome Notification Center and an app. |
+ |
+ // If there exists apps/extensions that have notificationProvider permission, |
+ // reroute notifications to one of the apps/extensions. |
+ std::string extension_id = GetExtensionTakingOverNotifications(profile); |
+ if (!extension_id.empty()) { |
+ RouteNotificationToAlternateProvider(notification, profile, extension_id); |
+ } |
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.
|
} |
bool MessageCenterNotificationManager::Update(const Notification& notification, |
@@ -512,3 +528,43 @@ MessageCenterNotificationManager::ProfileNotification* |
return (*iter).second; |
} |
+ |
+void MessageCenterNotificationManager::RouteNotificationToAlternateProvider( |
+ const Notification& notification, |
+ Profile* profile, |
+ std::string extension_id) { |
+ // Convert data from Notification type to NotificationOptions type. |
+ scoped_ptr<extensions::api::notifications::NotificationOptions> options( |
+ new extensions::api::notifications::NotificationOptions()); |
+ NotificationConversionHelper conversion_helper; |
+ conversion_helper.NotificationToNotificationOptions(notification, |
+ options.get()); |
+ |
+ // Fire event to send the data to an extension/app. |
+ scoped_ptr<extensions::NotificationProviderEventRouter> event_router( |
+ new extensions::NotificationProviderEventRouter(profile)); |
+ event_router->CreateNotification(extension_id, |
+ notification.notifier_id().id, |
+ notification.delegate_id(), |
+ *options); |
+} |
+ |
+std::string |
+MessageCenterNotificationManager::GetExtensionTakingOverNotifications( |
+ Profile* profile) { |
+ // TODO(liyanhou): When additional settings in Chrome Settings is implemented, |
+ // change choosing the last app with permission to a user selected app. |
+ extensions::ExtensionRegistry* registry = |
+ extensions::ExtensionRegistry::Get(profile); |
+ DCHECK(registry); |
+ std::string extension_id; |
+ for (extensions::ExtensionSet::const_iterator it = |
+ registry->enabled_extensions().begin(); |
+ it != registry->enabled_extensions().end(); |
+ ++it) { |
+ if ((*it->get()).permissions_data()->HasAPIPermission( |
+ extensions::APIPermission::ID::kNotificationProvider)) |
+ extension_id = (*it->get()).id(); |
+ } |
+ return extension_id; |
+} |