Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1604)

Unified Diff: chrome/browser/notifications/message_center_notification_manager.cc

Issue 441753002: Route newly created notifications to notification provider API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8c84ab20576821b76ae08682612f45333c74c058 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"
@@ -488,6 +493,21 @@ void MessageCenterNotificationManager::AddProfileNotification(
DCHECK(profile_notifications_.find(id) == profile_notifications_.end());
profile_notifications_[id] = profile_notification;
+ // If there exists apps/extensions that have notificationProvider permission,
+ // reroute notifications to one of the apps/extensions.
+ std::string extension_id =
+ GetExtensionTakingOverNotifications(profile_notification->profile());
+ if (!extension_id.empty()) {
+ RouteNotificationToAlternateProvider(
+ notification, profile_notification->profile(), extension_id);
dewittj 2014/08/12 18:47:39 This is still in AddProfileNotification, meaning t
dewittj 2014/08/12 21:04:15 OK after talking I propose a few changes: * Update
liyanhou 2014/08/13 17:30:37 Done. That sound good. I moved RouteToAlternatePro
+ }
+
+ // TODO(liyanhou): Change the logic to only send notifications to one party.
+ // Currently, if there is an app with notificationProvider permission,
+ // notifications will go to both Chrome Notification Center and the app.
+ // Change it to send notifications to message center only when the user chose
+ // default message center (extension_id.empty()).
+
// Create the copy for message center, and ensure the extension ID is correct.
scoped_ptr<message_center::Notification> message_center_notification(
new message_center::Notification(notification));
@@ -512,3 +532,42 @@ 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::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;
+}

Powered by Google App Engine
This is Rietveld 408576698