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_dispatcher.h" | 11 #include "content/child/notifications/notification_dispatcher.h" |
11 #include "content/child/notifications/notification_image_loader.h" | 12 #include "content/child/notifications/notification_image_loader.h" |
12 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 13 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
13 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
14 #include "content/child/worker_task_runner.h" | 15 #include "content/child/worker_task_runner.h" |
15 #include "content/common/platform_notification_messages.h" | 16 #include "content/common/platform_notification_messages.h" |
16 #include "content/public/common/show_desktop_notification_params.h" | 17 #include "content/public/common/platform_notification_data.h" |
17 #include "third_party/WebKit/public/platform/WebNotificationData.h" | 18 #include "third_party/WebKit/public/platform/WebNotificationData.h" |
18 #include "third_party/WebKit/public/platform/WebNotificationDelegate.h" | 19 #include "third_party/WebKit/public/platform/WebNotificationDelegate.h" |
19 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" | 20 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
21 | 22 |
22 using blink::WebNotificationPermission; | 23 using blink::WebNotificationPermission; |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 namespace { | 26 namespace { |
26 | 27 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 void NotificationManager::DisplayNotification( | 240 void NotificationManager::DisplayNotification( |
240 const blink::WebSerializedOrigin& origin, | 241 const blink::WebSerializedOrigin& origin, |
241 const blink::WebNotificationData& notification_data, | 242 const blink::WebNotificationData& notification_data, |
242 blink::WebNotificationDelegate* delegate, | 243 blink::WebNotificationDelegate* delegate, |
243 scoped_refptr<NotificationImageLoader> image_loader) { | 244 scoped_refptr<NotificationImageLoader> image_loader) { |
244 int notification_id = | 245 int notification_id = |
245 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); | 246 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
246 | 247 |
247 active_notifications_[notification_id] = delegate; | 248 active_notifications_[notification_id] = delegate; |
248 | 249 |
249 ShowDesktopNotificationHostMsgParams params; | 250 SkBitmap icon; |
250 params.origin = GURL(origin.string()); | 251 if (image_loader) |
251 params.title = notification_data.title; | 252 icon = image_loader->GetDecodedImage(); |
252 params.body = notification_data.body; | |
253 | 253 |
254 if (image_loader) | 254 thread_safe_sender_->Send( |
255 params.icon = image_loader->GetDecodedImage(); | 255 new PlatformNotificationHostMsg_Show( |
256 | 256 notification_id, |
257 // TODO(peter): Remove the usage of the Blink WebTextDirection enumeration for | 257 GURL(origin.string()), |
258 // the text direction of notifications throughout Chrome. | 258 icon, |
259 params.direction = blink::WebTextDirectionLeftToRight; | 259 ToPlatformNotificationData(notification_data))); |
260 params.replace_id = notification_data.tag; | |
261 | |
262 thread_safe_sender_->Send(new PlatformNotificationHostMsg_Show( | |
263 notification_id, params)); | |
264 | 260 |
265 // If this Notification contained an icon, it can be safely deleted now. | 261 // If this Notification contained an icon, it can be safely deleted now. |
266 RemovePendingPageNotification(delegate); | 262 RemovePendingPageNotification(delegate); |
267 } | 263 } |
268 | 264 |
269 void NotificationManager::DisplayPersistentNotification( | 265 void NotificationManager::DisplayPersistentNotification( |
270 const blink::WebSerializedOrigin& origin, | 266 const blink::WebSerializedOrigin& origin, |
271 const blink::WebNotificationData& notification_data, | 267 const blink::WebNotificationData& notification_data, |
272 int64 service_worker_registration_id, | 268 int64 service_worker_registration_id, |
273 int request_id, | 269 int request_id, |
274 scoped_refptr<NotificationImageLoader> image_loader) { | 270 scoped_refptr<NotificationImageLoader> image_loader) { |
275 ShowDesktopNotificationHostMsgParams params; | 271 SkBitmap icon; |
276 params.origin = GURL(origin.string()); | |
277 params.title = notification_data.title; | |
278 params.body = notification_data.body; | |
279 | |
280 // TODO(peter): Remove the usage of the Blink WebTextDirection enumeration for | |
281 // the text direction of notifications throughout Chrome. | |
282 params.direction = blink::WebTextDirectionLeftToRight; | |
283 params.replace_id = notification_data.tag; | |
284 | |
285 if (image_loader) { | 272 if (image_loader) { |
286 pending_persistent_notifications_.erase(image_loader); | 273 pending_persistent_notifications_.erase(image_loader); |
287 params.icon = image_loader->GetDecodedImage(); | 274 icon = image_loader->GetDecodedImage(); |
288 } | 275 } |
289 | 276 |
290 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ShowPersistent( | 277 thread_safe_sender_->Send( |
291 request_id, service_worker_registration_id, params)); | 278 new PlatformNotificationHostMsg_ShowPersistent( |
| 279 request_id, |
| 280 service_worker_registration_id, |
| 281 GURL(origin.string()), |
| 282 icon, |
| 283 ToPlatformNotificationData(notification_data))); |
292 } | 284 } |
293 | 285 |
294 bool NotificationManager::RemovePendingPageNotification( | 286 bool NotificationManager::RemovePendingPageNotification( |
295 blink::WebNotificationDelegate* delegate) { | 287 blink::WebNotificationDelegate* delegate) { |
296 const auto& iter = pending_page_notifications_.find(delegate); | 288 const auto& iter = pending_page_notifications_.find(delegate); |
297 if (iter == pending_page_notifications_.end()) | 289 if (iter == pending_page_notifications_.end()) |
298 return false; | 290 return false; |
299 | 291 |
300 pending_page_notifications_.erase(iter); | 292 pending_page_notifications_.erase(iter); |
301 return true; | 293 return true; |
302 } | 294 } |
303 | 295 |
304 } // namespace content | 296 } // namespace content |
OLD | NEW |