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 <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/strings/string_number_conversions.h" | |
12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
13 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
15 #include "content/child/notifications/notification_data_conversions.h" | 14 #include "content/child/notifications/notification_data_conversions.h" |
16 #include "content/child/notifications/notification_dispatcher.h" | 15 #include "content/child/notifications/notification_dispatcher.h" |
17 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 16 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
18 #include "content/child/thread_safe_sender.h" | 17 #include "content/child/thread_safe_sender.h" |
19 #include "content/child/worker_task_runner.h" | 18 #include "content/child/worker_task_runner.h" |
20 #include "content/public/common/platform_notification_data.h" | 19 #include "content/public/common/platform_notification_data.h" |
21 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" | 20 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 notification_data, | 85 notification_data, |
87 delegate)); | 86 delegate)); |
88 } | 87 } |
89 | 88 |
90 void NotificationManager::showPersistent( | 89 void NotificationManager::showPersistent( |
91 const blink::WebSerializedOrigin& origin, | 90 const blink::WebSerializedOrigin& origin, |
92 const blink::WebNotificationData& notification_data, | 91 const blink::WebNotificationData& notification_data, |
93 blink::WebServiceWorkerRegistration* service_worker_registration, | 92 blink::WebServiceWorkerRegistration* service_worker_registration, |
94 blink::WebNotificationShowCallbacks* callbacks) { | 93 blink::WebNotificationShowCallbacks* callbacks) { |
95 DCHECK(service_worker_registration); | 94 DCHECK(service_worker_registration); |
96 int64 service_worker_registration_id = | 95 int64_t service_worker_registration_id = |
97 static_cast<WebServiceWorkerRegistrationImpl*>( | 96 static_cast<WebServiceWorkerRegistrationImpl*>( |
98 service_worker_registration)->registration_id(); | 97 service_worker_registration)->registration_id(); |
99 | 98 |
100 scoped_ptr<blink::WebNotificationShowCallbacks> owned_callbacks(callbacks); | 99 scoped_ptr<blink::WebNotificationShowCallbacks> owned_callbacks(callbacks); |
101 | 100 |
102 // Verify that the author-provided payload size does not exceed our limit. | 101 // Verify that the author-provided payload size does not exceed our limit. |
103 // This is an implementation-defined limit to prevent abuse of notification | 102 // This is an implementation-defined limit to prevent abuse of notification |
104 // data as a storage mechanism. A UMA histogram records the requested sizes, | 103 // data as a storage mechanism. A UMA histogram records the requested sizes, |
105 // which enables us to track how much data authors are attempting to store. | 104 // which enables us to track how much data authors are attempting to store. |
106 // | 105 // |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 blink::WebServiceWorkerRegistration* service_worker_registration, | 139 blink::WebServiceWorkerRegistration* service_worker_registration, |
141 blink::WebNotificationGetCallbacks* callbacks) { | 140 blink::WebNotificationGetCallbacks* callbacks) { |
142 DCHECK(service_worker_registration); | 141 DCHECK(service_worker_registration); |
143 DCHECK(callbacks); | 142 DCHECK(callbacks); |
144 | 143 |
145 WebServiceWorkerRegistrationImpl* service_worker_registration_impl = | 144 WebServiceWorkerRegistrationImpl* service_worker_registration_impl = |
146 static_cast<WebServiceWorkerRegistrationImpl*>( | 145 static_cast<WebServiceWorkerRegistrationImpl*>( |
147 service_worker_registration); | 146 service_worker_registration); |
148 | 147 |
149 GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin(); | 148 GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin(); |
150 int64 service_worker_registration_id = | 149 int64_t service_worker_registration_id = |
151 service_worker_registration_impl->registration_id(); | 150 service_worker_registration_impl->registration_id(); |
152 | 151 |
153 // TODO(peter): GenerateNotificationId is more of a request id. Consider | 152 // TODO(peter): GenerateNotificationId is more of a request id. Consider |
154 // renaming the method in the NotificationDispatcher if this makes sense. | 153 // renaming the method in the NotificationDispatcher if this makes sense. |
155 int request_id = | 154 int request_id = |
156 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); | 155 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
157 | 156 |
158 pending_get_notification_requests_.AddWithID(callbacks, request_id); | 157 pending_get_notification_requests_.AddWithID(callbacks, request_id); |
159 | 158 |
160 thread_safe_sender_->Send( | 159 thread_safe_sender_->Send( |
(...skipping 18 matching lines...) Expand all Loading... |
179 return; | 178 return; |
180 } | 179 } |
181 | 180 |
182 // It should not be possible for Blink to call close() on a Notification which | 181 // It should not be possible for Blink to call close() on a Notification which |
183 // does not exist in either the pending or active notification lists. | 182 // does not exist in either the pending or active notification lists. |
184 NOTREACHED(); | 183 NOTREACHED(); |
185 } | 184 } |
186 | 185 |
187 void NotificationManager::closePersistent( | 186 void NotificationManager::closePersistent( |
188 const blink::WebSerializedOrigin& origin, | 187 const blink::WebSerializedOrigin& origin, |
189 const blink::WebString& persistent_notification_id_string) { | 188 int64_t persistent_notification_id) { |
190 // TODO(peter): Blink should store the persistent_notification_id as an | |
191 // int64_t instead of a string. The id, created by Chromium, is a decimal | |
192 // number that fits in an int64_t, so convert it until the API updates. | |
193 base::string16 string_value = persistent_notification_id_string; | |
194 | |
195 int64_t persistent_notification_id = 0; | |
196 if (!base::StringToInt64(string_value, | |
197 &persistent_notification_id)) { | |
198 NOTREACHED() << "Unable to close persistent notification; invalid id: " | |
199 << string_value; | |
200 return; | |
201 } | |
202 | |
203 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ClosePersistent( | 189 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ClosePersistent( |
204 GURL(origin.string()), | 190 GURL(origin.string()), |
205 persistent_notification_id)); | 191 persistent_notification_id)); |
206 } | 192 } |
207 | 193 |
208 void NotificationManager::notifyDelegateDestroyed( | 194 void NotificationManager::notifyDelegateDestroyed( |
209 blink::WebNotificationDelegate* delegate) { | 195 blink::WebNotificationDelegate* delegate) { |
210 if (pending_notifications_.CancelPageNotificationFetches(delegate)) | 196 if (pending_notifications_.CancelPageNotificationFetches(delegate)) |
211 return; | 197 return; |
212 | 198 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 DCHECK(callbacks); | 280 DCHECK(callbacks); |
295 if (!callbacks) | 281 if (!callbacks) |
296 return; | 282 return; |
297 | 283 |
298 scoped_ptr<blink::WebVector<blink::WebPersistentNotificationInfo>> | 284 scoped_ptr<blink::WebVector<blink::WebPersistentNotificationInfo>> |
299 notifications(new blink::WebVector<blink::WebPersistentNotificationInfo>( | 285 notifications(new blink::WebVector<blink::WebPersistentNotificationInfo>( |
300 notification_infos.size())); | 286 notification_infos.size())); |
301 | 287 |
302 for (size_t i = 0; i < notification_infos.size(); ++i) { | 288 for (size_t i = 0; i < notification_infos.size(); ++i) { |
303 blink::WebPersistentNotificationInfo web_notification_info; | 289 blink::WebPersistentNotificationInfo web_notification_info; |
304 web_notification_info.persistentNotificationId = | 290 web_notification_info.persistentId = notification_infos[i].first; |
305 blink::WebString::fromUTF8(notification_infos[i].first); | |
306 web_notification_info.data = | 291 web_notification_info.data = |
307 ToWebNotificationData(notification_infos[i].second); | 292 ToWebNotificationData(notification_infos[i].second); |
308 | 293 |
309 (*notifications)[i] = web_notification_info; | 294 (*notifications)[i] = web_notification_info; |
310 } | 295 } |
311 | 296 |
312 callbacks->onSuccess(notifications.release()); | 297 callbacks->onSuccess(notifications.release()); |
313 | 298 |
314 pending_get_notification_requests_.Remove(request_id); | 299 pending_get_notification_requests_.Remove(request_id); |
315 } | 300 } |
(...skipping 11 matching lines...) Expand all Loading... |
327 new PlatformNotificationHostMsg_Show( | 312 new PlatformNotificationHostMsg_Show( |
328 notification_id, | 313 notification_id, |
329 GURL(origin.string()), | 314 GURL(origin.string()), |
330 icon, | 315 icon, |
331 ToPlatformNotificationData(notification_data))); | 316 ToPlatformNotificationData(notification_data))); |
332 } | 317 } |
333 | 318 |
334 void NotificationManager::DisplayPersistentNotification( | 319 void NotificationManager::DisplayPersistentNotification( |
335 const blink::WebSerializedOrigin& origin, | 320 const blink::WebSerializedOrigin& origin, |
336 const blink::WebNotificationData& notification_data, | 321 const blink::WebNotificationData& notification_data, |
337 int64 service_worker_registration_id, | 322 int64_t service_worker_registration_id, |
338 scoped_ptr<blink::WebNotificationShowCallbacks> callbacks, | 323 scoped_ptr<blink::WebNotificationShowCallbacks> callbacks, |
339 const SkBitmap& icon) { | 324 const SkBitmap& icon) { |
340 // TODO(peter): GenerateNotificationId is more of a request id. Consider | 325 // TODO(peter): GenerateNotificationId is more of a request id. Consider |
341 // renaming the method in the NotificationDispatcher if this makes sense. | 326 // renaming the method in the NotificationDispatcher if this makes sense. |
342 int request_id = | 327 int request_id = |
343 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); | 328 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
344 | 329 |
345 pending_show_notification_requests_.AddWithID(callbacks.release(), | 330 pending_show_notification_requests_.AddWithID(callbacks.release(), |
346 request_id); | 331 request_id); |
347 | 332 |
348 thread_safe_sender_->Send( | 333 thread_safe_sender_->Send( |
349 new PlatformNotificationHostMsg_ShowPersistent( | 334 new PlatformNotificationHostMsg_ShowPersistent( |
350 request_id, | 335 request_id, |
351 service_worker_registration_id, | 336 service_worker_registration_id, |
352 GURL(origin.string()), | 337 GURL(origin.string()), |
353 icon, | 338 icon, |
354 ToPlatformNotificationData(notification_data))); | 339 ToPlatformNotificationData(notification_data))); |
355 } | 340 } |
356 | 341 |
357 } // namespace content | 342 } // namespace content |
OLD | NEW |