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

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

Issue 2047643003: DO NOT SUBMIT. Implement an XPCService for notifications. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge to use AlertNotificationService Created 4 years, 5 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/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 e96756be9d07f2003944297157bc9d80f3a2cb7c..c425102a105446cb416f3d5208b7734be58de682 100644
--- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
+++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
@@ -29,6 +29,11 @@
#include "url/gurl.h"
#include "url/origin.h"
+#import "base/mac/bundle_locations.h"
+#import "chrome/browser/ui/cocoa/notifications/notification_delivery.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+
@class NSUserNotification;
@class NSUserNotificationCenter;
@@ -74,6 +79,21 @@ void ProfileLoadedCallback(NotificationCommon::Operation operation,
}
} // namespace
+void ProcessNotificationResponse(NotificationCommon::Operation operation,
+ NotificationCommon::Type type,
+ const std::string& profile_id,
+ bool incognito,
+ const std::string& origin,
+ const std::string& notification_id,
+ int32_t button_index) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ ProfileManager* profileManager = g_browser_process->profile_manager();
+ DCHECK(profileManager);
+
+ profileManager->LoadProfile(
+ profile_id, incognito, base::Bind(&ProfileLoadedCallback, operation, type,
+ origin, notification_id, button_index));
+}
// static
NotificationPlatformBridge* NotificationPlatformBridge::Create() {
@@ -93,7 +113,9 @@ NotificationPlatformBridge* NotificationPlatformBridge::Create() {
NotificationPlatformBridgeMac::NotificationPlatformBridgeMac(
NSUserNotificationCenter* notification_center)
: delegate_([NotificationCenterDelegate alloc]),
- notification_center_(notification_center) {
+ notification_center_(notification_center),
+ notification_remote_dispatcher_(
+ [[NotificationRemoteDispatcher alloc] init]) {
[notification_center_ setDelegate:delegate_.get()];
}
@@ -168,8 +190,19 @@ void NotificationPlatformBridgeMac::Display(
[builder setIncognito:incognito];
[builder setNotificationType:[NSNumber numberWithInteger:notification_type]];
- NSUserNotification* toast = [builder buildUserNotification];
- [notification_center_ deliverNotification:toast];
+ NSLog(@"BUNDLE %@",
+ [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]);
+ NSLog(@"NOTIFICATION TYPE %@",
+ [[NSBundle mainBundle]
+ objectForInfoDictionaryKey:@"NSUserNotificationAlertStyle"]);
+ if (notification.never_timeout()) {
+ NSDictionary* dict = [builder buildDictionary];
+ [notification_remote_dispatcher_ dispatchNotification:dict];
+ } else {
+ LOG(WARNING) << "DELIVER NOTIFICATION";
+ NSUserNotification* toast = [builder buildUserNotification];
+ [notification_center_ deliverNotification:toast];
+ }
}
void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
@@ -327,7 +360,84 @@ bool NotificationPlatformBridgeMac::VerifyNotificationData(
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
shouldPresentNotification:(NSUserNotification*)nsNotification {
// Always display notifications, regardless of whether the app is foreground.
+ LOG(WARNING) << "SHOULD PRESENT? ";
return YES;
}
@end
+
+@implementation NotificationRemoteDispatcher
+
+@synthesize xpcConnection = _xpcConnection;
+
+- (instancetype)init {
+ // scoped ns object probably?
+ _xpcConnection = [[NSXPCConnection alloc]
+ initWithServiceName:[NSString
+ stringWithFormat:@"%@.AlertNotificationService",
+ [base::mac::OuterBundle()
+ bundleIdentifier]]];
+ _xpcConnection.remoteObjectInterface =
+ [NSXPCInterface interfaceWithProtocol:@protocol(NotificationDelivery)];
+ _xpcConnection.interruptionHandler = ^{
+ NSLog(@"conn interruptionHandler: %@", _xpcConnection);
+ };
+ _xpcConnection.invalidationHandler = ^{
+ NSLog(@"conn invalidationHandler %@", _xpcConnection);
+ };
+
+ _xpcConnection.exportedInterface =
+ [NSXPCInterface interfaceWithProtocol:@protocol(NotificationReply)];
+ _xpcConnection.exportedObject = self;
+ [_xpcConnection resume];
+
+ return self;
+}
+
+- (void)dispatchNotification:(NSDictionary*)data {
+ LOG(WARNING) << "DISPATCHING XPC ALERT";
+
+ [[_xpcConnection remoteObjectProxy] deliverNotification:data];
+
+ //[conn invalidate];
+ //[conn release];
+}
+
+// NotificationReply implementation
+//// Need to merge with local on clicks.
+- (void)notificationClick:(NSDictionary*)notificationResponseData {
+ NSLog(@"ALERT CLICKED AND RECEIVED BACK IN CHROME with %@",
+ notificationResponseData);
+ if (!NotificationPlatformBridgeMac::VerifyNotificationData(
+ notificationResponseData))
+ return;
+
+ NSNumber* buttonIndex = [notificationResponseData
+ objectForKey:notification_constants::kNotificationButtonIndex];
+ NSNumber* operation = [notificationResponseData
+ objectForKey:notification_constants::kNotificationOperation];
+
+ std::string notificationOrigin =
+ base::SysNSStringToUTF8([notificationResponseData
+ objectForKey:notification_constants::kNotificationOrigin]);
+ std::string notificationId = base::SysNSStringToUTF8([notificationResponseData
+ objectForKey:notification_constants::kNotificationId]);
+ std::string profileId = base::SysNSStringToUTF8([notificationResponseData
+ objectForKey:notification_constants::kNotificationProfileId]);
+ NSNumber* isIncognito = [notificationResponseData
+ objectForKey:notification_constants::kNotificationIncognito];
+ NSNumber* notificationType = [notificationResponseData
+ objectForKey:notification_constants::kNotificationType];
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(ProcessNotificationResponse,
+ static_cast<NotificationCommon::Operation>(
+ operation.unsignedIntValue),
+ static_cast<NotificationCommon::Type>(
+ notificationType.unsignedIntValue),
+ profileId, [isIncognito boolValue], notificationOrigin,
+ notificationId, buttonIndex.intValue));
+}
+
+@end
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_mac.h ('k') | chrome/browser/ui/cocoa/notifications/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698