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_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_ |
6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_ | 6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "content/common/service_worker/service_worker_status_code.h" | 16 #include "content/common/service_worker/service_worker_status_code.h" |
17 #include "content/public/browser/browser_message_filter.h" | 17 #include "content/public/browser/browser_message_filter.h" |
18 #include "content/public/browser/notification_database_data.h" | 18 #include "content/public/browser/notification_database_data.h" |
19 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 19 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
20 | 20 |
21 class GURL; | 21 class GURL; |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 class BrowserContext; | 25 class BrowserContext; |
| 26 class NotificationIdGenerator; |
26 struct NotificationResources; | 27 struct NotificationResources; |
27 class PlatformNotificationContextImpl; | 28 class PlatformNotificationContextImpl; |
28 struct PlatformNotificationData; | 29 struct PlatformNotificationData; |
29 class PlatformNotificationService; | 30 class PlatformNotificationService; |
30 class ResourceContext; | 31 class ResourceContext; |
31 class ServiceWorkerContextWrapper; | 32 class ServiceWorkerContextWrapper; |
32 class ServiceWorkerRegistration; | 33 class ServiceWorkerRegistration; |
33 | 34 |
34 class NotificationMessageFilter : public BrowserMessageFilter { | 35 class NotificationMessageFilter : public BrowserMessageFilter { |
35 public: | 36 public: |
36 NotificationMessageFilter( | 37 NotificationMessageFilter( |
37 int process_id, | 38 int process_id, |
38 PlatformNotificationContextImpl* notification_context, | 39 PlatformNotificationContextImpl* notification_context, |
39 ResourceContext* resource_context, | 40 ResourceContext* resource_context, |
40 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, | 41 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, |
41 BrowserContext* browser_context); | 42 BrowserContext* browser_context); |
42 | 43 |
43 // To be called by the notification's delegate when it has closed, so that | 44 // To be called by non-persistent notification delegates when they are closed, |
44 // the close closure associated with that notification can be removed. | 45 // so that the close closure associated with that notification can be removed. |
45 void DidCloseNotification(int notification_id); | 46 void DidCloseNotification(const std::string& notification_id); |
46 | 47 |
47 // BrowserMessageFilter implementation. Called on the UI thread. | 48 // BrowserMessageFilter implementation. Called on the UI thread. |
48 void OnDestruct() const override; | 49 void OnDestruct() const override; |
49 bool OnMessageReceived(const IPC::Message& message) override; | 50 bool OnMessageReceived(const IPC::Message& message) override; |
50 void OverrideThreadForMessage(const IPC::Message& message, | 51 void OverrideThreadForMessage(const IPC::Message& message, |
51 content::BrowserThread::ID* thread) override; | 52 content::BrowserThread::ID* thread) override; |
52 | 53 |
53 protected: | 54 protected: |
54 ~NotificationMessageFilter() override; | 55 ~NotificationMessageFilter() override; |
55 | 56 |
56 private: | 57 private: |
57 friend class base::DeleteHelper<NotificationMessageFilter>; | 58 friend class base::DeleteHelper<NotificationMessageFilter>; |
58 friend class BrowserThread; | 59 friend class BrowserThread; |
59 | 60 |
60 void OnShowPlatformNotification( | 61 void OnShowPlatformNotification( |
61 int notification_id, | 62 int non_persistent_notification_id, |
62 const GURL& origin, | 63 const GURL& origin, |
63 const PlatformNotificationData& notification_data, | 64 const PlatformNotificationData& notification_data, |
64 const NotificationResources& notification_resources); | 65 const NotificationResources& notification_resources); |
65 void OnShowPersistentNotification( | 66 void OnShowPersistentNotification( |
66 int request_id, | 67 int request_id, |
67 int64_t service_worker_registration_id, | 68 int64_t service_worker_registration_id, |
68 const GURL& origin, | 69 const GURL& origin, |
69 const PlatformNotificationData& notification_data, | 70 const PlatformNotificationData& notification_data, |
70 const NotificationResources& notification_resources); | 71 const NotificationResources& notification_resources); |
71 void OnGetNotifications(int request_id, | 72 void OnGetNotifications(int request_id, |
72 int64_t service_worker_registration_id, | 73 int64_t service_worker_registration_id, |
73 const GURL& origin, | 74 const GURL& origin, |
74 const std::string& filter_tag); | 75 const std::string& filter_tag); |
75 void OnClosePlatformNotification(int notification_id); | 76 void OnClosePlatformNotification(const GURL& origin, |
| 77 const std::string& tag, |
| 78 int non_persistent_notification_id); |
76 void OnClosePersistentNotification(const GURL& origin, | 79 void OnClosePersistentNotification(const GURL& origin, |
77 int64_t persistent_notification_id); | 80 const std::string& tag, |
| 81 const std::string& notification_id); |
78 | 82 |
79 // Callback to be invoked by the notification context when the notification | 83 // Callback to be invoked by the notification context when the notification |
80 // data for the persistent notification may have been written, as indicated by | 84 // data for the persistent notification may have been written, as indicated by |
81 // |success|. Will present the notification to the user when successful. | 85 // |success|. Will present the notification to the user when successful. |
82 void DidWritePersistentNotificationData( | 86 void DidWritePersistentNotificationData( |
83 int request_id, | 87 int request_id, |
84 int64_t service_worker_registration_id, | 88 int64_t service_worker_registration_id, |
85 const GURL& origin, | 89 const GURL& origin, |
86 const PlatformNotificationData& notification_data, | 90 const PlatformNotificationData& notification_data, |
87 const NotificationResources& notification_resources, | 91 const NotificationResources& notification_resources, |
88 bool success, | 92 bool success, |
89 int64_t persistent_notification_id); | 93 const std::string& notification_id); |
90 | 94 |
91 // Callback to be invoked by the service worker context when the service | 95 // Callback to be invoked by the service worker context when the service |
92 // worker registration was retrieved. Will present the notification to the | 96 // worker registration was retrieved. Will present the notification to the |
93 // user when successful. | 97 // user when successful. |
94 void DidFindServiceWorkerRegistration( | 98 void DidFindServiceWorkerRegistration( |
95 int request_id, | 99 int request_id, |
96 const GURL& origin, | 100 const GURL& origin, |
97 const PlatformNotificationData& notification_data, | 101 const PlatformNotificationData& notification_data, |
98 const NotificationResources& notification_resources, | 102 const NotificationResources& notification_resources, |
99 int64_t persistent_notification_id, | 103 const std::string& notification_id, |
100 content::ServiceWorkerStatusCode service_worker_status, | 104 content::ServiceWorkerStatusCode service_worker_status, |
101 scoped_refptr<ServiceWorkerRegistration> registration); | 105 scoped_refptr<ServiceWorkerRegistration> registration); |
102 | 106 |
103 // Callback to be invoked when all notifications belonging to a Service Worker | 107 // Callback to be invoked when all notifications belonging to a Service Worker |
104 // registration have been read from the database. The |success| argument | 108 // registration have been read from the database. The |success| argument |
105 // indicates whether the data could be read successfully, whereas the actual | 109 // indicates whether the data could be read successfully, whereas the actual |
106 // notifications will be stored in |notifications|. | 110 // notifications will be stored in |notifications|. |
107 void DidGetNotifications( | 111 void DidGetNotifications( |
108 int request_id, | 112 int request_id, |
109 const std::string& filter_tag, | 113 const std::string& filter_tag, |
(...skipping 11 matching lines...) Expand all Loading... |
121 blink::mojom::PermissionStatus GetPermissionForOriginOnIO( | 125 blink::mojom::PermissionStatus GetPermissionForOriginOnIO( |
122 const GURL& origin) const; | 126 const GURL& origin) const; |
123 | 127 |
124 // Verifies that Web Notification permission has been granted for |origin| in | 128 // Verifies that Web Notification permission has been granted for |origin| in |
125 // cases where the renderer shouldn't send messages if it weren't the case. If | 129 // cases where the renderer shouldn't send messages if it weren't the case. If |
126 // no permission has been granted, a bad message has been received and the | 130 // no permission has been granted, a bad message has been received and the |
127 // renderer should be killed accordingly. | 131 // renderer should be killed accordingly. |
128 bool VerifyNotificationPermissionGranted(PlatformNotificationService* service, | 132 bool VerifyNotificationPermissionGranted(PlatformNotificationService* service, |
129 const GURL& origin); | 133 const GURL& origin); |
130 | 134 |
| 135 // Returns the NotificationIdGenerator instance owned by the context. |
| 136 NotificationIdGenerator* GetNotificationIdGenerator() const; |
| 137 |
131 int process_id_; | 138 int process_id_; |
132 scoped_refptr<PlatformNotificationContextImpl> notification_context_; | 139 scoped_refptr<PlatformNotificationContextImpl> notification_context_; |
133 ResourceContext* resource_context_; | 140 ResourceContext* resource_context_; |
134 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 141 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
135 BrowserContext* browser_context_; | 142 BrowserContext* browser_context_; |
136 | 143 |
137 // Map mapping notification ids to their associated close closures. | 144 // Map mapping notification IDs associated with non-persistent notifications |
138 std::map<int, base::Closure> close_closures_; | 145 // to the closures that may be used for programmatically closing them. |
| 146 std::unordered_map<std::string, base::Closure> close_closures_; |
139 | 147 |
140 base::WeakPtrFactory<NotificationMessageFilter> weak_factory_io_; | 148 base::WeakPtrFactory<NotificationMessageFilter> weak_factory_io_; |
141 | 149 |
142 DISALLOW_COPY_AND_ASSIGN(NotificationMessageFilter); | 150 DISALLOW_COPY_AND_ASSIGN(NotificationMessageFilter); |
143 }; | 151 }; |
144 | 152 |
145 } // namespace content | 153 } // namespace content |
146 | 154 |
147 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_ | 155 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_MESSAGE_FILTER_H_ |
OLD | NEW |