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

Side by Side Diff: chrome/browser/notifications/notification_ui_manager_mac.mm

Issue 15715008: Reland 201932: Add API function chrome.notifications.getAll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-implement the mac fix. Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/notification_ui_manager_mac.h" 5 #include "chrome/browser/notifications/notification_ui_manager_mac.h"
6 6
7 #include "base/mac/cocoa_protocols.h" 7 #include "base/mac/cocoa_protocols.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/notifications/notification.h" 11 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" 12 #include "chrome/browser/notifications/balloon_notification_ui_manager.h"
13 #include "chrome/browser/notifications/message_center_notification_manager.h" 13 #include "chrome/browser/notifications/message_center_notification_manager.h"
14 #include "chrome/browser/profiles/profile.h"
14 #include "ui/message_center/message_center_util.h" 15 #include "ui/message_center/message_center_util.h"
15 16
16 @class NSUserNotificationCenter; 17 @class NSUserNotificationCenter;
17 18
18 // Since NSUserNotification and NSUserNotificationCenter are new classes in 19 // Since NSUserNotification and NSUserNotificationCenter are new classes in
19 // 10.8, they cannot simply be declared with an @interface. An @implementation 20 // 10.8, they cannot simply be declared with an @interface. An @implementation
20 // is needed to link, but providing one would cause a runtime conflict when 21 // is needed to link, but providing one would cause a runtime conflict when
21 // running on 10.8. Instead, provide the interface defined as a protocol and 22 // running on 10.8. Instead, provide the interface defined as a protocol and
22 // use that instead, because sizeof(id<Protocol>) == sizeof(Class*). In order to 23 // use that instead, because sizeof(id<Protocol>) == sizeof(Class*). In order to
23 // instantiate, use NSClassFromString and simply assign the alloc/init'd result 24 // instantiate, use NSClassFromString and simply assign the alloc/init'd result
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 notification_map_.insert(std::make_pair( 155 notification_map_.insert(std::make_pair(
155 notification.notification_id(), 156 notification.notification_id(),
156 new ControllerNotification(profile, 157 new ControllerNotification(profile,
157 ns_notification, 158 ns_notification,
158 new Notification(notification)))); 159 new Notification(notification))));
159 160
160 [GetNotificationCenter() deliverNotification:ns_notification]; 161 [GetNotificationCenter() deliverNotification:ns_notification];
161 } 162 }
162 } 163 }
163 164
165 std::set<std::string>
166 NotificationUIManagerMac::GetAllIdsByProfileAndSourceOrigin(
167 Profile* profile, const GURL& source_origin) {
168 std::set<std::string> notification_ids =
169 BalloonNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
170 profile, source_origin);
171
172 for (NotificationMap::iterator it = notification_map_.begin();
173 it != notification_map_.end(); ++it) {
174 ControllerNotification* controller_notification = it->second;
175 Notification* model = controller_notification->model;
176 if (model->origin_url() == source_origin &&
177 profile->IsSameProfile(controller_notification->profile)) {
178 notification_ids.insert(model->notification_id());
179 }
180 }
181 return notification_ids;
182 }
183
164 bool NotificationUIManagerMac::CancelById(const std::string& notification_id) { 184 bool NotificationUIManagerMac::CancelById(const std::string& notification_id) {
165 NotificationMap::iterator it = notification_map_.find(notification_id); 185 NotificationMap::iterator it = notification_map_.find(notification_id);
166 if (it == notification_map_.end()) 186 if (it == notification_map_.end())
167 return BalloonNotificationUIManager::CancelById(notification_id); 187 return BalloonNotificationUIManager::CancelById(notification_id);
168 188
169 return RemoveNotification(it->second->view); 189 return RemoveNotification(it->second->view);
170 } 190 }
171 191
172 bool NotificationUIManagerMac::CancelAllBySourceOrigin( 192 bool NotificationUIManagerMac::CancelAllBySourceOrigin(
173 const GURL& source_origin) { 193 const GURL& source_origin) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 notification->Click(); 327 notification->Click();
308 } 328 }
309 329
310 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center 330 - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
311 shouldPresentNotification:(id<CrUserNotification>)nsNotification { 331 shouldPresentNotification:(id<CrUserNotification>)nsNotification {
312 // Always display notifications, regardless of whether the app is foreground. 332 // Always display notifications, regardless of whether the app is foreground.
313 return YES; 333 return YES;
314 } 334 }
315 335
316 @end 336 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698