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

Unified Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 2402303002: Implement the ability to close alerts programatically (Closed)
Patch Set: review Created 4 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/notifications/alert_notification_service.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_platform_bridge_mac.mm
diff --git a/chrome/browser/notifications/notification_platform_bridge_mac.mm b/chrome/browser/notifications/notification_platform_bridge_mac.mm
index 6b3c20dc60e789395257adb0ddd1f115608ac000..5890dc3422bd7f3537c70e970478c85f897ce877 100644
--- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
+++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
@@ -114,8 +114,16 @@ NotificationPlatformBridge* NotificationPlatformBridge::Create() {
// Interface to communicate with the Alert XPC service.
@interface NotificationRemoteDispatcher : NSObject
+// Deliver a notification to the XPC service to be displayed as an alert.
- (void)dispatchNotification:(NSDictionary*)data;
+// Close a notification for a given |notificationId| and |profileId|.
+- (void)closeNotificationWithId:(NSString*)notificationId
+ withProfileId:(NSString*)profileId;
+
+// Close all notifications.
+- (void)closeAllNotifications;
+
@end
// /////////////////////////////////////////////////////////////////////////////
@@ -137,9 +145,11 @@ NotificationPlatformBridgeMac::NotificationPlatformBridgeMac(
NotificationPlatformBridgeMac::~NotificationPlatformBridgeMac() {
[notification_center_ setDelegate:nil];
- // TODO(miguelg) remove only alerts shown by the XPC service.
// TODO(miguelg) do not remove banners if possible.
[notification_center_ removeAllDeliveredNotifications];
+#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
+ [notification_remote_dispatcher_ closeAllNotifications];
+#endif // BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
}
void NotificationPlatformBridgeMac::Display(
@@ -231,8 +241,9 @@ void NotificationPlatformBridgeMac::Display(
void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
const std::string& notification_id) {
NSString* candidate_id = base::SysUTF8ToNSString(notification_id);
-
NSString* current_profile_id = base::SysUTF8ToNSString(profile_id);
+
+ bool notification_removed = false;
for (NSUserNotification* toast in
[notification_center_ deliveredNotifications]) {
NSString* toast_id =
@@ -244,8 +255,19 @@ void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
if ([toast_id isEqualToString:candidate_id] &&
[persistent_profile_id isEqualToString:current_profile_id]) {
[notification_center_ removeDeliveredNotification:toast];
+ notification_removed = true;
+ break;
}
}
+#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
+ // If no banner existed with that ID try to see if there is an alert
+ // in the xpc server.
+ if (!notification_removed) {
+ [notification_remote_dispatcher_
+ closeNotificationWithId:candidate_id
+ withProfileId:current_profile_id];
+ }
+#endif // ENABLE_XPC_NOTIFICATIONS
}
bool NotificationPlatformBridgeMac::GetDisplayed(
@@ -441,6 +463,16 @@ bool NotificationPlatformBridgeMac::VerifyNotificationData(
[[xpcConnection_ remoteObjectProxy] deliverNotification:data];
}
+- (void)closeNotificationWithId:(NSString*)notificationId
+ withProfileId:(NSString*)profileId {
+ [[xpcConnection_ remoteObjectProxy] closeNotificationWithId:notificationId
+ withProfileId:profileId];
+}
+
+- (void)closeAllNotifications {
+ [[xpcConnection_ remoteObjectProxy] closeAllNotifications];
+}
+
// NotificationReply implementation
- (void)notificationClick:(NSDictionary*)notificationResponseData {
NotificationPlatformBridgeMac::ProcessNotificationResponse(
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/notifications/alert_notification_service.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698