| 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 #ifndef CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | 5 #ifndef CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ |
| 6 #define CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | 6 #define CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/id_map.h" | |
| 12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 15 #include "content/child/notifications/notification_dispatcher.h" | 13 #include "content/child/notifications/notification_dispatcher.h" |
| 16 #include "content/child/notifications/notification_image_loader.h" | 14 #include "content/child/notifications/pending_notifications_tracker.h" |
| 17 #include "content/child/worker_task_runner.h" | 15 #include "content/child/worker_task_runner.h" |
| 18 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onManager.h" | 16 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onManager.h" |
| 19 | 17 |
| 20 class SkBitmap; | 18 class SkBitmap; |
| 21 | 19 |
| 22 namespace blink { | |
| 23 class WebURL; | |
| 24 } | |
| 25 | |
| 26 namespace content { | 20 namespace content { |
| 27 | 21 |
| 28 class ThreadSafeSender; | 22 class ThreadSafeSender; |
| 29 | 23 |
| 30 class NotificationManager : public blink::WebNotificationManager, | 24 class NotificationManager : public blink::WebNotificationManager, |
| 31 public WorkerTaskRunner::Observer { | 25 public WorkerTaskRunner::Observer { |
| 32 public: | 26 public: |
| 33 ~NotificationManager() override; | 27 ~NotificationManager() override; |
| 34 | 28 |
| 35 // |thread_safe_sender| and |notification_dispatcher| are used if | 29 // |thread_safe_sender| and |notification_dispatcher| are used if |
| (...skipping 30 matching lines...) Expand all Loading... |
| 66 NotificationManager( | 60 NotificationManager( |
| 67 ThreadSafeSender* thread_safe_sender, | 61 ThreadSafeSender* thread_safe_sender, |
| 68 base::SingleThreadTaskRunner* main_thread_task_runner, | 62 base::SingleThreadTaskRunner* main_thread_task_runner, |
| 69 NotificationDispatcher* notification_dispatcher); | 63 NotificationDispatcher* notification_dispatcher); |
| 70 | 64 |
| 71 // IPC message handlers. | 65 // IPC message handlers. |
| 72 void OnDidShow(int notification_id); | 66 void OnDidShow(int notification_id); |
| 73 void OnDidClose(int notification_id); | 67 void OnDidClose(int notification_id); |
| 74 void OnDidClick(int notification_id); | 68 void OnDidClick(int notification_id); |
| 75 | 69 |
| 76 // Asynchronously starts loading |image_url| on the main thread and returns a | 70 // To be called when a page notification is ready to be displayed. Will |
| 77 // reference to the notification image loaded responsible for this. |callback| | 71 // inform the browser process about all available data. The |delegate|, |
| 78 // will be invoked on the calling thread when the load is complete. | 72 // owned by Blink, will be used to feed back events associated with the |
| 79 scoped_refptr<NotificationImageLoader> CreateImageLoader( | 73 // notification to the JavaScript object. |
| 80 const blink::WebURL& image_url, | 74 void DisplayPageNotification( |
| 81 const NotificationImageLoadedCallback& callback) const; | 75 const blink::WebSerializedOrigin& origin, |
| 76 const blink::WebNotificationData& notification_data, |
| 77 blink::WebNotificationDelegate* delegate, |
| 78 const SkBitmap& icon); |
| 82 | 79 |
| 83 // Sends an IPC to the browser process to display the notification, | 80 // To be called when a persistent notification is ready to be displayed. Will |
| 84 // accompanied by the downloaded icon. | 81 // inform the browser process about all available data. The |callbacks| will |
| 85 void DisplayNotification(const blink::WebSerializedOrigin& origin, | 82 // be used to inform the Promise pending in Blink that the notification has |
| 86 const blink::WebNotificationData& notification_data, | 83 // been send to the browser process to be displayed. |
| 87 blink::WebNotificationDelegate* delegate, | |
| 88 scoped_refptr<NotificationImageLoader> image_loader); | |
| 89 | |
| 90 // Sends an IPC to the browser process to display the persistent notification, | |
| 91 // accompanied by the downloaded icon. | |
| 92 void DisplayPersistentNotification( | 84 void DisplayPersistentNotification( |
| 93 const blink::WebSerializedOrigin& origin, | 85 const blink::WebSerializedOrigin& origin, |
| 94 const blink::WebNotificationData& notification_data, | 86 const blink::WebNotificationData& notification_data, |
| 95 int64 service_worker_registration_id, | 87 int64 service_worker_registration_id, |
| 96 int request_id, | 88 scoped_ptr<blink::WebNotificationShowCallbacks> callbacks, |
| 97 scoped_refptr<NotificationImageLoader> image_loader); | 89 const SkBitmap& icon); |
| 98 | |
| 99 // Removes the notification identified by |delegate| from the set of | |
| 100 // pending notifications, and returns whether it could be found. | |
| 101 bool RemovePendingPageNotification(blink::WebNotificationDelegate* delegate); | |
| 102 | 90 |
| 103 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 91 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 104 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
| 105 scoped_refptr<NotificationDispatcher> notification_dispatcher_; | 92 scoped_refptr<NotificationDispatcher> notification_dispatcher_; |
| 106 | 93 |
| 107 // Tracking display requests for persistent notifications. | 94 // Tracker which stores all pending Notifications, both page and persistent |
| 108 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> | 95 // ones, until all their associated resources have been fetched. |
| 109 persistent_notification_requests_; | 96 PendingNotificationsTracker pending_notifications_; |
| 110 | |
| 111 // A map tracking Page-bound notifications whose icon is still being | |
| 112 // downloaded. These downloads can be cancelled by the developer. | |
| 113 std::map<blink::WebNotificationDelegate*, | |
| 114 scoped_refptr<NotificationImageLoader>> | |
| 115 pending_page_notifications_; | |
| 116 | |
| 117 // A set tracking Persistent notifications whose icon is still being | |
| 118 // downloaded. These downloads cannot be cancelled by the developer. | |
| 119 std::set<scoped_refptr<NotificationImageLoader>> | |
| 120 pending_persistent_notifications_; | |
| 121 | 97 |
| 122 // Map to store the delegate associated with a notification request Id. | 98 // Map to store the delegate associated with a notification request Id. |
| 123 std::map<int, blink::WebNotificationDelegate*> active_notifications_; | 99 std::map<int, blink::WebNotificationDelegate*> active_page_notifications_; |
| 124 | |
| 125 base::WeakPtrFactory<NotificationManager> weak_factory_; | |
| 126 | 100 |
| 127 DISALLOW_COPY_AND_ASSIGN(NotificationManager); | 101 DISALLOW_COPY_AND_ASSIGN(NotificationManager); |
| 128 }; | 102 }; |
| 129 | 103 |
| 130 } // namespace content | 104 } // namespace content |
| 131 | 105 |
| 132 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | 106 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |