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 fb1a6c934b76f0f7b42c020c6e821ea594d1808b..0c768d5a287cbc8aa6de9a3bff8a7b797780939f 100644 |
--- a/chrome/browser/notifications/message_center_notification_manager.cc |
+++ b/chrome/browser/notifications/message_center_notification_manager.cc |
@@ -7,9 +7,14 @@ |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/notifications/desktop_notification_service.h" |
+#include "chrome/browser/notifications/desktop_notification_service_factory.h" |
#include "chrome/browser/notifications/notification.h" |
#include "chrome/browser/prefs/pref_service.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/extension_set.h" |
#include "chrome/common/pref_names.h" |
@@ -135,32 +140,59 @@ bool MessageCenterNotificationManager::UpdateNotification( |
void MessageCenterNotificationManager::DisableExtension( |
const std::string& notification_id) { |
- NOTIMPLEMENTED(); |
+ ProfileNotification* profile_notification = |
+ FindProfileNotification(notification_id); |
+ std::string extension_id = profile_notification->GetExtensionId(); |
+ DCHECK(!extension_id.empty()); // or UI should not have enabled the command. |
stevenjb
2013/01/24 23:59:54
two spaces before //
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ profile_notification->profile()->GetExtensionService()->DisableExtension( |
+ extension_id, extensions::Extension::DISABLE_USER_ACTION); |
} |
void MessageCenterNotificationManager::DisableNotificationsFromSource( |
const std::string& notification_id) { |
- NOTIMPLEMENTED(); |
+ ProfileNotification* profile_notification = |
+ FindProfileNotification(notification_id); |
+ const GURL& source_url = profile_notification->notification().origin_url(); |
+ DCHECK(source_url.is_valid()); // or UI should not have enabled the command. |
stevenjb
2013/01/24 23:59:54
; //
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ DesktopNotificationService* service = |
+ DesktopNotificationServiceFactory::GetForProfile( |
+ profile_notification->profile()); |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable 'source'
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ service->DenyPermission(source_url); |
} |
void MessageCenterNotificationManager::NotificationRemoved( |
const std::string& notification_id) { |
- NOTIMPLEMENTED(); |
+ ProfileNotification* profile_notification = |
+ FindProfileNotification(notification_id); |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ RemoveProfileNotification(profile_notification); |
} |
void MessageCenterNotificationManager::ShowSettings( |
const std::string& notification_id) { |
- NOTIMPLEMENTED(); |
+ ProfileNotification* profile_notification = |
+ FindProfileNotification(notification_id); |
+ Profile* profile = profile_notification->profile(); |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variables
Dmitry Titov
2013/01/25 00:47:45
Removed 'profile', left those used twice...
|
+ Browser* browser = |
+ chrome::FindOrCreateTabbedBrowser(profile, |
+ chrome::HOST_DESKTOP_TYPE_NATIVE); |
+ if (profile_notification->GetExtensionId().empty()) |
+ chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
+ else |
+ chrome::ShowExtensions(browser); |
} |
void MessageCenterNotificationManager::OnClicked( |
const std::string& notification_id) { |
- NOTIMPLEMENTED(); |
+ ProfileNotification* profile_notification = |
+ FindProfileNotification(notification_id); |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ profile_notification->notification().Click(); |
} |
void MessageCenterNotificationManager::OnButtonClicked( |
const std::string& notification_id, int button_index) { |
- NOTIMPLEMENTED(); |
+ ProfileNotification* profile_notification = |
+ FindProfileNotification(notification_id); |
stevenjb
2013/01/24 23:59:54
nit: Don't need local variable
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ profile_notification->notification().ButtonClick(button_index); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -211,3 +243,15 @@ void MessageCenterNotificationManager::RemoveProfileNotification( |
profile_notifications_.erase(id); |
delete profile_notification; |
} |
+ |
+MessageCenterNotificationManager::ProfileNotification* |
+ MessageCenterNotificationManager::FindProfileNotification( |
+ const std::string& id) const { |
+ NotificationMap::const_iterator iter = profile_notifications_.find(id); |
+ if (iter == profile_notifications_.end()) { |
+ NOTREACHED(); // If the notification is shown in UI, it must be in the map. |
stevenjb
2013/01/24 23:59:54
; //
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ return NULL; |
+ } |
stevenjb
2013/01/24 23:59:54
This should be DCHECK(iter != profile_notification
Dmitry Titov
2013/01/25 00:47:45
Done.
|
+ DCHECK((*iter).second); |
+ return (*iter).second; |
+} |