| 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> |
| 8 |
| 7 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 12 #include "content/child/notifications/notification_data_conversions.h" | 15 #include "content/child/notifications/notification_data_conversions.h" |
| 13 #include "content/child/notifications/notification_dispatcher.h" | 16 #include "content/child/notifications/notification_dispatcher.h" |
| 14 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 17 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 15 #include "content/child/thread_safe_sender.h" | 18 #include "content/child/thread_safe_sender.h" |
| 16 #include "content/child/worker_task_runner.h" | 19 #include "content/child/worker_task_runner.h" |
| 17 #include "content/public/common/platform_notification_data.h" | 20 #include "content/public/common/platform_notification_data.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const blink::WebSerializedOrigin& origin, | 91 const blink::WebSerializedOrigin& origin, |
| 89 const blink::WebNotificationData& notification_data, | 92 const blink::WebNotificationData& notification_data, |
| 90 blink::WebServiceWorkerRegistration* service_worker_registration, | 93 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 91 blink::WebNotificationShowCallbacks* callbacks) { | 94 blink::WebNotificationShowCallbacks* callbacks) { |
| 92 DCHECK(service_worker_registration); | 95 DCHECK(service_worker_registration); |
| 93 int64 service_worker_registration_id = | 96 int64 service_worker_registration_id = |
| 94 static_cast<WebServiceWorkerRegistrationImpl*>( | 97 static_cast<WebServiceWorkerRegistrationImpl*>( |
| 95 service_worker_registration)->registration_id(); | 98 service_worker_registration)->registration_id(); |
| 96 | 99 |
| 97 scoped_ptr<blink::WebNotificationShowCallbacks> owned_callbacks(callbacks); | 100 scoped_ptr<blink::WebNotificationShowCallbacks> owned_callbacks(callbacks); |
| 101 |
| 102 // Verify that the author-provided payload size does not exceed our limit. |
| 103 // This is an implementation-defined limit to prevent abuse of notification |
| 104 // 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. |
| 106 // |
| 107 // If the size exceeds this limit, reject the showNotification() promise. This |
| 108 // is outside of the boundaries set by the specification, but it gives authors |
| 109 // an indication that something has gone wrong. |
| 110 size_t author_data_size = notification_data.data.size(); |
| 111 UMA_HISTOGRAM_MEMORY_KB("Notifications.AuthorDataSizeKB", |
| 112 static_cast<int>(ceil(author_data_size / 1024.0))); |
| 113 |
| 114 if (author_data_size > PlatformNotificationData::kMaximumDeveloperDataSize) { |
| 115 owned_callbacks->onError(); |
| 116 return; |
| 117 } |
| 118 |
| 98 if (notification_data.icon.isEmpty()) { | 119 if (notification_data.icon.isEmpty()) { |
| 99 DisplayPersistentNotification(origin, | 120 DisplayPersistentNotification(origin, |
| 100 notification_data, | 121 notification_data, |
| 101 service_worker_registration_id, | 122 service_worker_registration_id, |
| 102 owned_callbacks.Pass(), | 123 owned_callbacks.Pass(), |
| 103 SkBitmap()); | 124 SkBitmap()); |
| 104 return; | 125 return; |
| 105 } | 126 } |
| 106 | 127 |
| 107 pending_notifications_.FetchPersistentNotificationResources( | 128 pending_notifications_.FetchPersistentNotificationResources( |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 thread_safe_sender_->Send( | 348 thread_safe_sender_->Send( |
| 328 new PlatformNotificationHostMsg_ShowPersistent( | 349 new PlatformNotificationHostMsg_ShowPersistent( |
| 329 request_id, | 350 request_id, |
| 330 service_worker_registration_id, | 351 service_worker_registration_id, |
| 331 GURL(origin.string()), | 352 GURL(origin.string()), |
| 332 icon, | 353 icon, |
| 333 ToPlatformNotificationData(notification_data))); | 354 ToPlatformNotificationData(notification_data))); |
| 334 } | 355 } |
| 335 | 356 |
| 336 } // namespace content | 357 } // namespace content |
| OLD | NEW |