Chromium Code Reviews| 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 // private | 486 // private |
| 482 | 487 |
| 483 void MessageCenterNotificationManager::AddProfileNotification( | 488 void MessageCenterNotificationManager::AddProfileNotification( |
| 484 ProfileNotification* profile_notification) { | 489 ProfileNotification* profile_notification) { |
| 485 const Notification& notification = profile_notification->notification(); | 490 const Notification& notification = profile_notification->notification(); |
| 486 std::string id = notification.delegate_id(); | 491 std::string id = notification.delegate_id(); |
| 487 // Notification ids should be unique. | 492 // Notification ids should be unique. |
| 488 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); | 493 DCHECK(profile_notifications_.find(id) == profile_notifications_.end()); |
| 489 profile_notifications_[id] = profile_notification; | 494 profile_notifications_[id] = profile_notification; |
| 490 | 495 |
| 496 // If there exists apps/extensions that have notificationProvider permission, | |
| 497 // reroute notifications to one of the apps/extensions. | |
| 498 std::string extension_id = | |
| 499 GetExtensionTakingOverNotifications(profile_notification->profile()); | |
| 500 if (!extension_id.empty()) { | |
| 501 RouteNotificationToAlternateProvider( | |
| 502 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
| |
| 503 } | |
| 504 | |
| 505 // TODO(liyanhou): Change the logic to only send notifications to one party. | |
| 506 // Currently, if there is an app with notificationProvider permission, | |
| 507 // notifications will go to both Chrome Notification Center and the app. | |
| 508 // Change it to send notifications to message center only when the user chose | |
| 509 // default message center (extension_id.empty()). | |
| 510 | |
| 491 // Create the copy for message center, and ensure the extension ID is correct. | 511 // Create the copy for message center, and ensure the extension ID is correct. |
| 492 scoped_ptr<message_center::Notification> message_center_notification( | 512 scoped_ptr<message_center::Notification> message_center_notification( |
| 493 new message_center::Notification(notification)); | 513 new message_center::Notification(notification)); |
| 494 message_center_->AddNotification(message_center_notification.Pass()); | 514 message_center_->AddNotification(message_center_notification.Pass()); |
| 495 | 515 |
| 496 profile_notification->StartDownloads(); | 516 profile_notification->StartDownloads(); |
| 497 } | 517 } |
| 498 | 518 |
| 499 void MessageCenterNotificationManager::RemoveProfileNotification( | 519 void MessageCenterNotificationManager::RemoveProfileNotification( |
| 500 ProfileNotification* profile_notification) { | 520 ProfileNotification* profile_notification) { |
| 501 std::string id = profile_notification->notification().delegate_id(); | 521 std::string id = profile_notification->notification().delegate_id(); |
| 502 profile_notifications_.erase(id); | 522 profile_notifications_.erase(id); |
| 503 delete profile_notification; | 523 delete profile_notification; |
| 504 } | 524 } |
| 505 | 525 |
| 506 MessageCenterNotificationManager::ProfileNotification* | 526 MessageCenterNotificationManager::ProfileNotification* |
| 507 MessageCenterNotificationManager::FindProfileNotification( | 527 MessageCenterNotificationManager::FindProfileNotification( |
| 508 const std::string& id) const { | 528 const std::string& id) const { |
| 509 NotificationMap::const_iterator iter = profile_notifications_.find(id); | 529 NotificationMap::const_iterator iter = profile_notifications_.find(id); |
| 510 if (iter == profile_notifications_.end()) | 530 if (iter == profile_notifications_.end()) |
| 511 return NULL; | 531 return NULL; |
| 512 | 532 |
| 513 return (*iter).second; | 533 return (*iter).second; |
| 514 } | 534 } |
| 535 | |
| 536 void MessageCenterNotificationManager::RouteNotificationToAlternateProvider( | |
| 537 const Notification& notification, | |
| 538 Profile* profile, | |
| 539 std::string extension_id) { | |
| 540 // Convert data from Notification type to NotificationOptions type. | |
| 541 scoped_ptr<extensions::api::notifications::NotificationOptions> options( | |
| 542 new extensions::api::notifications::NotificationOptions()); | |
| 543 NotificationConversionHelper::NotificationToNotificationOptions( | |
| 544 notification, options.get()); | |
| 545 | |
| 546 // Fire event to send the data to an extension/app. | |
| 547 scoped_ptr<extensions::NotificationProviderEventRouter> event_router( | |
| 548 new extensions::NotificationProviderEventRouter(profile)); | |
| 549 event_router->CreateNotification(extension_id, | |
| 550 notification.notifier_id().id, | |
| 551 notification.delegate_id(), | |
| 552 *options); | |
| 553 } | |
| 554 | |
| 555 std::string | |
| 556 MessageCenterNotificationManager::GetExtensionTakingOverNotifications( | |
| 557 Profile* profile) { | |
| 558 // TODO(liyanhou): When additional settings in Chrome Settings is implemented, | |
| 559 // change choosing the last app with permission to a user selected app. | |
| 560 extensions::ExtensionRegistry* registry = | |
| 561 extensions::ExtensionRegistry::Get(profile); | |
| 562 DCHECK(registry); | |
| 563 std::string extension_id; | |
| 564 for (extensions::ExtensionSet::const_iterator it = | |
| 565 registry->enabled_extensions().begin(); | |
| 566 it != registry->enabled_extensions().end(); | |
| 567 ++it) { | |
| 568 if ((*it->get()).permissions_data()->HasAPIPermission( | |
| 569 extensions::APIPermission::ID::kNotificationProvider)) | |
| 570 extension_id = (*it->get()).id(); | |
| 571 } | |
| 572 return extension_id; | |
| 573 } | |
| OLD | NEW |