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/browser/notifications/notification_message_filter.h" | 5 #include "content/browser/notifications/notification_message_filter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "content/browser/bad_message.h" | 10 #include "content/browser/bad_message.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void NotificationMessageFilter::OnCheckNotificationPermission( | 102 void NotificationMessageFilter::OnCheckNotificationPermission( |
103 const GURL& origin, blink::WebNotificationPermission* permission) { | 103 const GURL& origin, blink::WebNotificationPermission* permission) { |
104 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
105 | 105 |
106 *permission = GetPermissionForOriginOnIO(origin); | 106 *permission = GetPermissionForOriginOnIO(origin); |
107 } | 107 } |
108 | 108 |
109 void NotificationMessageFilter::OnShowPlatformNotification( | 109 void NotificationMessageFilter::OnShowPlatformNotification( |
110 int notification_id, | 110 int notification_id, |
111 const GURL& origin, | 111 const GURL& origin, |
112 const SkBitmap& icon, | 112 const PlatformNotificationData& notification_data, |
113 const PlatformNotificationData& notification_data) { | 113 const NotificationResources& notification_resources) { |
114 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
115 if (!RenderProcessHost::FromID(process_id_)) | 115 if (!RenderProcessHost::FromID(process_id_)) |
116 return; | 116 return; |
117 | 117 |
118 scoped_ptr<DesktopNotificationDelegate> delegate( | 118 scoped_ptr<DesktopNotificationDelegate> delegate( |
119 new PageNotificationDelegate(process_id_, notification_id)); | 119 new PageNotificationDelegate(process_id_, notification_id)); |
120 | 120 |
121 PlatformNotificationService* service = | 121 PlatformNotificationService* service = |
122 GetContentClient()->browser()->GetPlatformNotificationService(); | 122 GetContentClient()->browser()->GetPlatformNotificationService(); |
123 DCHECK(service); | 123 DCHECK(service); |
124 | 124 |
125 if (!VerifyNotificationPermissionGranted(service, origin)) | 125 if (!VerifyNotificationPermissionGranted(service, origin)) |
126 return; | 126 return; |
127 | 127 |
128 base::Closure close_closure; | 128 base::Closure close_closure; |
129 service->DisplayNotification(browser_context_, origin, icon, | 129 service->DisplayNotification( |
130 SanitizeNotificationData(notification_data), | 130 browser_context_, origin, SanitizeNotificationData(notification_data), |
131 std::move(delegate), &close_closure); | 131 notification_resources, std::move(delegate), &close_closure); |
132 | 132 |
133 if (!close_closure.is_null()) | 133 if (!close_closure.is_null()) |
134 close_closures_[notification_id] = close_closure; | 134 close_closures_[notification_id] = close_closure; |
135 } | 135 } |
136 | 136 |
137 void NotificationMessageFilter::OnShowPersistentNotification( | 137 void NotificationMessageFilter::OnShowPersistentNotification( |
138 int request_id, | 138 int request_id, |
139 int64_t service_worker_registration_id, | 139 int64_t service_worker_registration_id, |
140 const GURL& origin, | 140 const GURL& origin, |
141 const SkBitmap& icon, | 141 const PlatformNotificationData& notification_data, |
142 const PlatformNotificationData& notification_data) { | 142 const NotificationResources& notification_resources) { |
143 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 143 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
144 if (GetPermissionForOriginOnIO(origin) != | 144 if (GetPermissionForOriginOnIO(origin) != |
145 blink::WebNotificationPermissionAllowed) { | 145 blink::WebNotificationPermissionAllowed) { |
146 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_SHOW); | 146 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_SHOW); |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 NotificationDatabaseData database_data; | 150 NotificationDatabaseData database_data; |
151 database_data.origin = origin; | 151 database_data.origin = origin; |
152 database_data.service_worker_registration_id = service_worker_registration_id; | 152 database_data.service_worker_registration_id = service_worker_registration_id; |
153 | 153 |
154 PlatformNotificationData sanitized_notification_data = | 154 PlatformNotificationData sanitized_notification_data = |
155 SanitizeNotificationData(notification_data); | 155 SanitizeNotificationData(notification_data); |
156 database_data.notification_data = sanitized_notification_data; | 156 database_data.notification_data = sanitized_notification_data; |
157 | 157 |
158 // TODO(peter): Significantly reduce the amount of information we need to | 158 // TODO(peter): Significantly reduce the amount of information we need to |
159 // retain outside of the database for displaying notifications. | 159 // retain outside of the database for displaying notifications. |
160 notification_context_->WriteNotificationData( | 160 notification_context_->WriteNotificationData( |
161 origin, database_data, | 161 origin, database_data, |
162 base::Bind(&NotificationMessageFilter::DidWritePersistentNotificationData, | 162 base::Bind(&NotificationMessageFilter::DidWritePersistentNotificationData, |
163 weak_factory_io_.GetWeakPtr(), request_id, origin, icon, | 163 weak_factory_io_.GetWeakPtr(), request_id, origin, |
164 sanitized_notification_data)); | 164 sanitized_notification_data, notification_resources)); |
165 } | 165 } |
166 | 166 |
167 void NotificationMessageFilter::DidWritePersistentNotificationData( | 167 void NotificationMessageFilter::DidWritePersistentNotificationData( |
168 int request_id, | 168 int request_id, |
169 const GURL& origin, | 169 const GURL& origin, |
170 const SkBitmap& icon, | |
171 const PlatformNotificationData& notification_data, | 170 const PlatformNotificationData& notification_data, |
| 171 const NotificationResources& notification_resources, |
172 bool success, | 172 bool success, |
173 int64_t persistent_notification_id) { | 173 int64_t persistent_notification_id) { |
174 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 174 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
175 | 175 |
176 if (success) { | 176 if (success) { |
177 PlatformNotificationService* service = | 177 PlatformNotificationService* service = |
178 GetContentClient()->browser()->GetPlatformNotificationService(); | 178 GetContentClient()->browser()->GetPlatformNotificationService(); |
179 DCHECK(service); | 179 DCHECK(service); |
180 | 180 |
181 BrowserThread::PostTask( | 181 BrowserThread::PostTask( |
182 BrowserThread::UI, FROM_HERE, | 182 BrowserThread::UI, FROM_HERE, |
183 base::Bind(&PlatformNotificationService::DisplayPersistentNotification, | 183 base::Bind(&PlatformNotificationService::DisplayPersistentNotification, |
184 base::Unretained(service), // The service is a singleton. | 184 base::Unretained(service), // The service is a singleton. |
185 browser_context_, persistent_notification_id, origin, icon, | 185 browser_context_, persistent_notification_id, origin, |
186 notification_data)); | 186 notification_data, notification_resources)); |
187 } | 187 } |
188 | 188 |
189 Send(new PlatformNotificationMsg_DidShowPersistent(request_id, success)); | 189 Send(new PlatformNotificationMsg_DidShowPersistent(request_id, success)); |
190 } | 190 } |
191 | 191 |
192 void NotificationMessageFilter::OnGetNotifications( | 192 void NotificationMessageFilter::OnGetNotifications( |
193 int request_id, | 193 int request_id, |
194 int64_t service_worker_registration_id, | 194 int64_t service_worker_registration_id, |
195 const GURL& origin, | 195 const GURL& origin, |
196 const std::string& filter_tag) { | 196 const std::string& filter_tag) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 service->CheckPermissionOnUIThread(browser_context_, origin, process_id_); | 304 service->CheckPermissionOnUIThread(browser_context_, origin, process_id_); |
305 | 305 |
306 if (permission == blink::WebNotificationPermissionAllowed) | 306 if (permission == blink::WebNotificationPermissionAllowed) |
307 return true; | 307 return true; |
308 | 308 |
309 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_VERIFY); | 309 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_VERIFY); |
310 return false; | 310 return false; |
311 } | 311 } |
312 | 312 |
313 } // namespace content | 313 } // namespace content |
OLD | NEW |