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 | |
9 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
10 #include "base/metrics/histogram_macros.h" | |
11 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
13 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/thread_local.h" | 11 #include "base/threading/thread_local.h" |
15 #include "content/child/notifications/notification_data_conversions.h" | 12 #include "content/child/notifications/notification_data_conversions.h" |
16 #include "content/child/notifications/notification_dispatcher.h" | 13 #include "content/child/notifications/notification_dispatcher.h" |
17 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 14 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
18 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
19 #include "content/child/worker_task_runner.h" | 16 #include "content/child/worker_task_runner.h" |
20 #include "content/public/common/platform_notification_data.h" | 17 #include "content/public/common/platform_notification_data.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 const blink::WebSerializedOrigin& origin, | 88 const blink::WebSerializedOrigin& origin, |
92 const blink::WebNotificationData& notification_data, | 89 const blink::WebNotificationData& notification_data, |
93 blink::WebServiceWorkerRegistration* service_worker_registration, | 90 blink::WebServiceWorkerRegistration* service_worker_registration, |
94 blink::WebNotificationShowCallbacks* callbacks) { | 91 blink::WebNotificationShowCallbacks* callbacks) { |
95 DCHECK(service_worker_registration); | 92 DCHECK(service_worker_registration); |
96 int64 service_worker_registration_id = | 93 int64 service_worker_registration_id = |
97 static_cast<WebServiceWorkerRegistrationImpl*>( | 94 static_cast<WebServiceWorkerRegistrationImpl*>( |
98 service_worker_registration)->registration_id(); | 95 service_worker_registration)->registration_id(); |
99 | 96 |
100 scoped_ptr<blink::WebNotificationShowCallbacks> owned_callbacks(callbacks); | 97 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 | |
119 if (notification_data.icon.isEmpty()) { | 98 if (notification_data.icon.isEmpty()) { |
120 DisplayPersistentNotification(origin, | 99 DisplayPersistentNotification(origin, |
121 notification_data, | 100 notification_data, |
122 service_worker_registration_id, | 101 service_worker_registration_id, |
123 owned_callbacks.Pass(), | 102 owned_callbacks.Pass(), |
124 SkBitmap()); | 103 SkBitmap()); |
125 return; | 104 return; |
126 } | 105 } |
127 | 106 |
128 pending_notifications_.FetchPersistentNotificationResources( | 107 pending_notifications_.FetchPersistentNotificationResources( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 thread_safe_sender_->Send( | 327 thread_safe_sender_->Send( |
349 new PlatformNotificationHostMsg_ShowPersistent( | 328 new PlatformNotificationHostMsg_ShowPersistent( |
350 request_id, | 329 request_id, |
351 service_worker_registration_id, | 330 service_worker_registration_id, |
352 GURL(origin.string()), | 331 GURL(origin.string()), |
353 icon, | 332 icon, |
354 ToPlatformNotificationData(notification_data))); | 333 ToPlatformNotificationData(notification_data))); |
355 } | 334 } |
356 | 335 |
357 } // namespace content | 336 } // namespace content |
OLD | NEW |