Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 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" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 blink::WebNotificationShowCallbacks* callbacks) { | 115 blink::WebNotificationShowCallbacks* callbacks) { |
| 116 DCHECK(service_worker_registration); | 116 DCHECK(service_worker_registration); |
| 117 DCHECK_EQ(notification_data.actions.size(), | 117 DCHECK_EQ(notification_data.actions.size(), |
| 118 notification_resources->actionIcons.size()); | 118 notification_resources->actionIcons.size()); |
| 119 | 119 |
| 120 int64_t service_worker_registration_id = | 120 int64_t service_worker_registration_id = |
| 121 static_cast<WebServiceWorkerRegistrationImpl*>( | 121 static_cast<WebServiceWorkerRegistrationImpl*>( |
| 122 service_worker_registration) | 122 service_worker_registration) |
| 123 ->registrationId(); | 123 ->registrationId(); |
| 124 | 124 |
| 125 std::unique_ptr<blink::WebNotificationShowCallbacks> owned_callbacks( | 125 std::unique_ptr<blink::WebNotificationShowCallbacks> owned_callbacks( |
|
danakj
2016/11/30 00:34:00
this variable should go away, and pass a unique_pt
| |
| 126 callbacks); | 126 callbacks); |
| 127 | 127 |
| 128 // Verify that the author-provided payload size does not exceed our limit. | 128 // Verify that the author-provided payload size does not exceed our limit. |
| 129 // This is an implementation-defined limit to prevent abuse of notification | 129 // This is an implementation-defined limit to prevent abuse of notification |
| 130 // data as a storage mechanism. A UMA histogram records the requested sizes, | 130 // data as a storage mechanism. A UMA histogram records the requested sizes, |
| 131 // which enables us to track how much data authors are attempting to store. | 131 // which enables us to track how much data authors are attempting to store. |
| 132 // | 132 // |
| 133 // If the size exceeds this limit, reject the showNotification() promise. This | 133 // If the size exceeds this limit, reject the showNotification() promise. This |
| 134 // is outside of the boundaries set by the specification, but it gives authors | 134 // is outside of the boundaries set by the specification, but it gives authors |
| 135 // an indication that something has gone wrong. | 135 // an indication that something has gone wrong. |
| 136 size_t author_data_size = notification_data.data.size(); | 136 size_t author_data_size = notification_data.data.size(); |
| 137 | 137 |
| 138 UMA_HISTOGRAM_COUNTS_1000("Notifications.AuthorDataSize", author_data_size); | 138 UMA_HISTOGRAM_COUNTS_1000("Notifications.AuthorDataSize", author_data_size); |
| 139 | 139 |
| 140 if (author_data_size > PlatformNotificationData::kMaximumDeveloperDataSize) { | 140 if (author_data_size > PlatformNotificationData::kMaximumDeveloperDataSize) { |
| 141 owned_callbacks->onError(); | 141 owned_callbacks->onError(); |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 | 144 |
| 145 // TODO(peter): GenerateNotificationId is more of a request id. Consider | 145 // TODO(peter): GenerateNotificationId is more of a request id. Consider |
| 146 // renaming the method in the NotificationDispatcher if this makes sense. | 146 // renaming the method in the NotificationDispatcher if this makes sense. |
| 147 int request_id = | 147 int request_id = |
| 148 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); | 148 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
| 149 | 149 |
| 150 pending_show_notification_requests_.AddWithID(owned_callbacks.release(), | 150 pending_show_notification_requests_.AddWithID(std::move(owned_callbacks), |
| 151 request_id); | 151 request_id); |
| 152 | 152 |
| 153 // TODO(mkwst): This is potentially doing the wrong thing with unique | 153 // TODO(mkwst): This is potentially doing the wrong thing with unique |
| 154 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See | 154 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See |
| 155 // https://crbug.com/490074 for detail. | 155 // https://crbug.com/490074 for detail. |
| 156 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ShowPersistent( | 156 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ShowPersistent( |
| 157 request_id, service_worker_registration_id, url::Origin(origin).GetURL(), | 157 request_id, service_worker_registration_id, url::Origin(origin).GetURL(), |
| 158 ToPlatformNotificationData(notification_data), | 158 ToPlatformNotificationData(notification_data), |
| 159 ToNotificationResources(std::move(notification_resources)))); | 159 ToNotificationResources(std::move(notification_resources)))); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void NotificationManager::getNotifications( | 162 void NotificationManager::getNotifications( |
| 163 const blink::WebString& filter_tag, | 163 const blink::WebString& filter_tag, |
| 164 blink::WebServiceWorkerRegistration* service_worker_registration, | 164 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 165 blink::WebNotificationGetCallbacks* callbacks) { | 165 std::unique_ptr<blink::WebNotificationGetCallbacks> callbacks) { |
| 166 DCHECK(service_worker_registration); | 166 DCHECK(service_worker_registration); |
| 167 DCHECK(callbacks); | 167 DCHECK(callbacks); |
| 168 | 168 |
| 169 WebServiceWorkerRegistrationImpl* service_worker_registration_impl = | 169 WebServiceWorkerRegistrationImpl* service_worker_registration_impl = |
| 170 static_cast<WebServiceWorkerRegistrationImpl*>( | 170 static_cast<WebServiceWorkerRegistrationImpl*>( |
| 171 service_worker_registration); | 171 service_worker_registration); |
| 172 | 172 |
| 173 GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin(); | 173 GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin(); |
| 174 int64_t service_worker_registration_id = | 174 int64_t service_worker_registration_id = |
| 175 service_worker_registration_impl->registrationId(); | 175 service_worker_registration_impl->registrationId(); |
| 176 | 176 |
| 177 // TODO(peter): GenerateNotificationId is more of a request id. Consider | 177 // TODO(peter): GenerateNotificationId is more of a request id. Consider |
| 178 // renaming the method in the NotificationDispatcher if this makes sense. | 178 // renaming the method in the NotificationDispatcher if this makes sense. |
| 179 int request_id = | 179 int request_id = |
| 180 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); | 180 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
| 181 | 181 |
| 182 pending_get_notification_requests_.AddWithID(callbacks, request_id); | 182 pending_get_notification_requests_.AddWithID(std::move(callbacks), |
| 183 request_id); | |
| 183 | 184 |
| 184 thread_safe_sender_->Send(new PlatformNotificationHostMsg_GetNotifications( | 185 thread_safe_sender_->Send(new PlatformNotificationHostMsg_GetNotifications( |
| 185 request_id, service_worker_registration_id, origin, | 186 request_id, service_worker_registration_id, origin, |
| 186 base::UTF16ToUTF8(base::StringPiece16(filter_tag)))); | 187 base::UTF16ToUTF8(base::StringPiece16(filter_tag)))); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void NotificationManager::close(blink::WebNotificationDelegate* delegate) { | 190 void NotificationManager::close(blink::WebNotificationDelegate* delegate) { |
| 190 for (auto& iter : active_page_notifications_) { | 191 for (auto& iter : active_page_notifications_) { |
| 191 if (iter.second.delegate != delegate) | 192 if (iter.second.delegate != delegate) |
| 192 continue; | 193 continue; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 305 |
| 305 notifications[i] = web_notification_info; | 306 notifications[i] = web_notification_info; |
| 306 } | 307 } |
| 307 | 308 |
| 308 callbacks->onSuccess(notifications); | 309 callbacks->onSuccess(notifications); |
| 309 | 310 |
| 310 pending_get_notification_requests_.Remove(request_id); | 311 pending_get_notification_requests_.Remove(request_id); |
| 311 } | 312 } |
| 312 | 313 |
| 313 } // namespace content | 314 } // namespace content |
| OLD | NEW |