OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/notifications/notification_manager.h" | 5 #include "content/child/notifications/notification_manager.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
10 #include "content/child/notifications/notification_data_conversions.h" | 10 #include "content/child/notifications/notification_data_conversions.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 blink::WebNotificationPermissionAllowed; | 166 blink::WebNotificationPermissionAllowed; |
167 thread_safe_sender_->Send(new PlatformNotificationHostMsg_CheckPermission( | 167 thread_safe_sender_->Send(new PlatformNotificationHostMsg_CheckPermission( |
168 GURL(origin.string()), &permission)); | 168 GURL(origin.string()), &permission)); |
169 | 169 |
170 return permission; | 170 return permission; |
171 } | 171 } |
172 | 172 |
173 bool NotificationManager::OnMessageReceived(const IPC::Message& message) { | 173 bool NotificationManager::OnMessageReceived(const IPC::Message& message) { |
174 bool handled = true; | 174 bool handled = true; |
175 IPC_BEGIN_MESSAGE_MAP(NotificationManager, message) | 175 IPC_BEGIN_MESSAGE_MAP(NotificationManager, message) |
176 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShowPersistent, | |
177 OnDidShowPersistent) | |
178 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow); | 176 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow); |
179 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose); | 177 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose); |
180 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick); | 178 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick); |
181 IPC_MESSAGE_UNHANDLED(handled = false) | 179 IPC_MESSAGE_UNHANDLED(handled = false) |
182 IPC_END_MESSAGE_MAP() | 180 IPC_END_MESSAGE_MAP() |
183 | 181 |
184 return handled; | 182 return handled; |
185 } | 183 } |
186 | 184 |
187 void NotificationManager::OnDidShowPersistent(int request_id) { | |
188 blink::WebNotificationShowCallbacks* callbacks = | |
189 persistent_notification_requests_.Lookup(request_id); | |
190 DCHECK(callbacks); | |
191 | |
192 // There currently isn't a case in which the promise would be rejected per | |
193 // our implementation, so always resolve it here. | |
194 callbacks->onSuccess(); | |
195 | |
196 persistent_notification_requests_.Remove(request_id); | |
197 } | |
198 | |
199 void NotificationManager::OnDidShow(int notification_id) { | 185 void NotificationManager::OnDidShow(int notification_id) { |
200 const auto& iter = active_notifications_.find(notification_id); | 186 const auto& iter = active_notifications_.find(notification_id); |
201 if (iter == active_notifications_.end()) | 187 if (iter == active_notifications_.end()) |
202 return; | 188 return; |
203 | 189 |
204 iter->second->dispatchShowEvent(); | 190 iter->second->dispatchShowEvent(); |
205 } | 191 } |
206 | 192 |
207 void NotificationManager::OnDidClose(int notification_id) { | 193 void NotificationManager::OnDidClose(int notification_id) { |
208 const auto& iter = active_notifications_.find(notification_id); | 194 const auto& iter = active_notifications_.find(notification_id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // If this Notification contained an icon, it can be safely deleted now. | 247 // If this Notification contained an icon, it can be safely deleted now. |
262 RemovePendingPageNotification(delegate); | 248 RemovePendingPageNotification(delegate); |
263 } | 249 } |
264 | 250 |
265 void NotificationManager::DisplayPersistentNotification( | 251 void NotificationManager::DisplayPersistentNotification( |
266 const blink::WebSerializedOrigin& origin, | 252 const blink::WebSerializedOrigin& origin, |
267 const blink::WebNotificationData& notification_data, | 253 const blink::WebNotificationData& notification_data, |
268 int64 service_worker_registration_id, | 254 int64 service_worker_registration_id, |
269 int request_id, | 255 int request_id, |
270 scoped_refptr<NotificationImageLoader> image_loader) { | 256 scoped_refptr<NotificationImageLoader> image_loader) { |
| 257 blink::WebNotificationShowCallbacks* callbacks = |
| 258 persistent_notification_requests_.Lookup(request_id); |
| 259 DCHECK(callbacks); |
| 260 |
271 SkBitmap icon; | 261 SkBitmap icon; |
272 if (image_loader) { | 262 if (image_loader) { |
273 pending_persistent_notifications_.erase(image_loader); | 263 pending_persistent_notifications_.erase(image_loader); |
274 icon = image_loader->GetDecodedImage(); | 264 icon = image_loader->GetDecodedImage(); |
275 } | 265 } |
276 | 266 |
277 thread_safe_sender_->Send( | 267 thread_safe_sender_->Send( |
278 new PlatformNotificationHostMsg_ShowPersistent( | 268 new PlatformNotificationHostMsg_ShowPersistent( |
279 request_id, | |
280 service_worker_registration_id, | 269 service_worker_registration_id, |
281 GURL(origin.string()), | 270 GURL(origin.string()), |
282 icon, | 271 icon, |
283 ToPlatformNotificationData(notification_data))); | 272 ToPlatformNotificationData(notification_data))); |
| 273 |
| 274 // There currently isn't a case in which the promise would be rejected per |
| 275 // our implementation, so always resolve it here. |
| 276 callbacks->onSuccess(); |
| 277 |
| 278 persistent_notification_requests_.Remove(request_id); |
284 } | 279 } |
285 | 280 |
286 bool NotificationManager::RemovePendingPageNotification( | 281 bool NotificationManager::RemovePendingPageNotification( |
287 blink::WebNotificationDelegate* delegate) { | 282 blink::WebNotificationDelegate* delegate) { |
288 const auto& iter = pending_page_notifications_.find(delegate); | 283 const auto& iter = pending_page_notifications_.find(delegate); |
289 if (iter == pending_page_notifications_.end()) | 284 if (iter == pending_page_notifications_.end()) |
290 return false; | 285 return false; |
291 | 286 |
292 pending_page_notifications_.erase(iter); | 287 pending_page_notifications_.erase(iter); |
293 return true; | 288 return true; |
294 } | 289 } |
295 | 290 |
296 } // namespace content | 291 } // namespace content |
OLD | NEW |