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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
13 #include "content/child/notifications/notification_data_conversions.h" | 13 #include "content/child/notifications/notification_data_conversions.h" |
14 #include "content/child/notifications/notification_dispatcher.h" | 14 #include "content/child/notifications/notification_dispatcher.h" |
15 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 15 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
16 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
17 #include "content/public/common/notification_resources.h" | 17 #include "content/public/common/notification_resources.h" |
18 #include "content/public/common/platform_notification_data.h" | 18 #include "content/public/common/platform_notification_data.h" |
19 #include "third_party/WebKit/public/platform/URLConversion.h" | 19 #include "third_party/WebKit/public/platform/URLConversion.h" |
20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
21 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onDelegate.h" | 21 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onDelegate.h" |
22 #include "url/origin.h" | 22 #include "url/origin.h" |
23 | 23 |
| 24 using blink::WebString; |
| 25 |
24 namespace content { | 26 namespace content { |
25 namespace { | 27 namespace { |
26 | 28 |
27 int CurrentWorkerId() { | 29 int CurrentWorkerId() { |
28 return WorkerThread::GetCurrentId(); | 30 return WorkerThread::GetCurrentId(); |
29 } | 31 } |
30 | 32 |
31 NotificationResources ToNotificationResources( | 33 NotificationResources ToNotificationResources( |
32 std::unique_ptr<blink::WebNotificationResources> web_resources) { | 34 std::unique_ptr<blink::WebNotificationResources> web_resources) { |
33 NotificationResources resources; | 35 NotificationResources resources; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 DCHECK_EQ(0u, notification_data.actions.size()); | 91 DCHECK_EQ(0u, notification_data.actions.size()); |
90 DCHECK_EQ(0u, notification_resources->actionIcons.size()); | 92 DCHECK_EQ(0u, notification_resources->actionIcons.size()); |
91 | 93 |
92 GURL origin_gurl = url::Origin(origin).GetURL(); | 94 GURL origin_gurl = url::Origin(origin).GetURL(); |
93 | 95 |
94 int notification_id = | 96 int notification_id = |
95 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); | 97 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
96 | 98 |
97 active_page_notifications_[notification_id] = ActiveNotificationData( | 99 active_page_notifications_[notification_id] = ActiveNotificationData( |
98 delegate, origin_gurl, | 100 delegate, origin_gurl, |
99 base::UTF16ToUTF8(base::StringPiece16(notification_data.tag))); | 101 notification_data.tag.utf8( |
| 102 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD)); |
100 | 103 |
101 // TODO(mkwst): This is potentially doing the wrong thing with unique | 104 // TODO(mkwst): This is potentially doing the wrong thing with unique |
102 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See | 105 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See |
103 // https://crbug.com/490074 for detail. | 106 // https://crbug.com/490074 for detail. |
104 thread_safe_sender_->Send(new PlatformNotificationHostMsg_Show( | 107 thread_safe_sender_->Send(new PlatformNotificationHostMsg_Show( |
105 notification_id, origin_gurl, | 108 notification_id, origin_gurl, |
106 ToPlatformNotificationData(notification_data), | 109 ToPlatformNotificationData(notification_data), |
107 ToNotificationResources(std::move(notification_resources)))); | 110 ToNotificationResources(std::move(notification_resources)))); |
108 } | 111 } |
109 | 112 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // TODO(peter): GenerateNotificationId is more of a request id. Consider | 177 // TODO(peter): GenerateNotificationId is more of a request id. Consider |
175 // renaming the method in the NotificationDispatcher if this makes sense. | 178 // renaming the method in the NotificationDispatcher if this makes sense. |
176 int request_id = | 179 int request_id = |
177 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); | 180 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
178 | 181 |
179 pending_get_notification_requests_.AddWithID(std::move(callbacks), | 182 pending_get_notification_requests_.AddWithID(std::move(callbacks), |
180 request_id); | 183 request_id); |
181 | 184 |
182 thread_safe_sender_->Send(new PlatformNotificationHostMsg_GetNotifications( | 185 thread_safe_sender_->Send(new PlatformNotificationHostMsg_GetNotifications( |
183 request_id, service_worker_registration_id, origin, | 186 request_id, service_worker_registration_id, origin, |
184 base::UTF16ToUTF8(base::StringPiece16(filter_tag)))); | 187 filter_tag.utf8( |
| 188 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD))); |
185 } | 189 } |
186 | 190 |
187 void NotificationManager::close(blink::WebNotificationDelegate* delegate) { | 191 void NotificationManager::close(blink::WebNotificationDelegate* delegate) { |
188 for (auto& iter : active_page_notifications_) { | 192 for (auto& iter : active_page_notifications_) { |
189 if (iter.second.delegate != delegate) | 193 if (iter.second.delegate != delegate) |
190 continue; | 194 continue; |
191 | 195 |
192 thread_safe_sender_->Send(new PlatformNotificationHostMsg_Close( | 196 thread_safe_sender_->Send(new PlatformNotificationHostMsg_Close( |
193 iter.second.origin, iter.second.tag, iter.first)); | 197 iter.second.origin, iter.second.tag, iter.first)); |
194 active_page_notifications_.erase(iter.first); | 198 active_page_notifications_.erase(iter.first); |
195 return; | 199 return; |
196 } | 200 } |
197 | 201 |
198 // It should not be possible for Blink to call close() on a Notification which | 202 // It should not be possible for Blink to call close() on a Notification which |
199 // does not exist in either the pending or active notification lists. | 203 // does not exist in either the pending or active notification lists. |
200 NOTREACHED(); | 204 NOTREACHED(); |
201 } | 205 } |
202 | 206 |
203 void NotificationManager::closePersistent( | 207 void NotificationManager::closePersistent( |
204 const blink::WebSecurityOrigin& origin, | 208 const blink::WebSecurityOrigin& origin, |
205 const blink::WebString& tag, | 209 const blink::WebString& tag, |
206 const blink::WebString& notification_id) { | 210 const blink::WebString& notification_id) { |
207 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ClosePersistent( | 211 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ClosePersistent( |
208 // TODO(mkwst): This is potentially doing the wrong thing with unique | 212 // TODO(mkwst): This is potentially doing the wrong thing with unique |
209 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See | 213 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See |
210 // https://crbug.com/490074 for detail. | 214 // https://crbug.com/490074 for detail. |
211 url::Origin(origin).GetURL(), base::UTF16ToUTF8(base::StringPiece16(tag)), | 215 url::Origin(origin).GetURL(), |
212 base::UTF16ToUTF8(base::StringPiece16(notification_id)))); | 216 tag.utf8(WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD), |
| 217 notification_id.utf8( |
| 218 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD))); |
213 } | 219 } |
214 | 220 |
215 void NotificationManager::notifyDelegateDestroyed( | 221 void NotificationManager::notifyDelegateDestroyed( |
216 blink::WebNotificationDelegate* delegate) { | 222 blink::WebNotificationDelegate* delegate) { |
217 for (auto& iter : active_page_notifications_) { | 223 for (auto& iter : active_page_notifications_) { |
218 if (iter.second.delegate != delegate) | 224 if (iter.second.delegate != delegate) |
219 continue; | 225 continue; |
220 | 226 |
221 active_page_notifications_.erase(iter.first); | 227 active_page_notifications_.erase(iter.first); |
222 return; | 228 return; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 308 |
303 notifications[i] = web_notification_info; | 309 notifications[i] = web_notification_info; |
304 } | 310 } |
305 | 311 |
306 callbacks->onSuccess(notifications); | 312 callbacks->onSuccess(notifications); |
307 | 313 |
308 pending_get_notification_requests_.Remove(request_id); | 314 pending_get_notification_requests_.Remove(request_id); |
309 } | 315 } |
310 | 316 |
311 } // namespace content | 317 } // namespace content |
OLD | NEW |