Chromium Code Reviews| Index: content/child/notifications/notification_manager.cc |
| diff --git a/content/child/notifications/notification_manager.cc b/content/child/notifications/notification_manager.cc |
| index 40ad89efb20115ddfb4fdba4a48e4f982cad2d38..2cf15aeaba0429136663d7ed28e186fc2b68e837 100644 |
| --- a/content/child/notifications/notification_manager.cc |
| +++ b/content/child/notifications/notification_manager.cc |
| @@ -13,7 +13,6 @@ |
| #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| #include "content/child/thread_safe_sender.h" |
| #include "content/child/worker_task_runner.h" |
| -#include "content/common/platform_notification_messages.h" |
| #include "content/public/common/platform_notification_data.h" |
| #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" |
| #include "third_party/WebKit/public/platform/modules/notifications/WebNotificationDelegate.h" |
| @@ -114,6 +113,36 @@ void NotificationManager::showPersistent( |
| base::Passed(&owned_callbacks))); |
| } |
| +void NotificationManager::getNotifications( |
| + const blink::WebString& filter_tag, |
| + blink::WebServiceWorkerRegistration* service_worker_registration, |
| + blink::WebNotificationGetCallbacks* callbacks) { |
| + DCHECK(service_worker_registration); |
| + DCHECK(callbacks); |
| + |
| + WebServiceWorkerRegistrationImpl* service_worker_registration_impl = |
| + static_cast<WebServiceWorkerRegistrationImpl*>( |
| + service_worker_registration); |
| + |
| + GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin(); |
|
johnme
2015/03/18 15:03:06
Nit: it seems slightly inconsistent that showPersi
Peter Beverloo
2015/03/19 15:46:44
Extracting it from the SWR is the favorable option
|
| + int64 service_worker_registration_id = |
| + service_worker_registration_impl->registration_id(); |
| + |
| + // TODO(peter): GenerateNotificationId is more of a request id. Consider |
| + // renaming the method in the NotificationDispatcher if this makes sense. |
| + int request_id = |
| + notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); |
|
johnme
2015/03/18 15:03:06
GenerateNotificationId could be made to overflow.
Peter Beverloo
2015/03/19 15:46:44
I added a CHECK_GE in the NotificationDispatcher.
|
| + |
| + pending_get_notification_requests_.AddWithID(callbacks, request_id); |
| + |
| + thread_safe_sender_->Send( |
| + new PlatformNotificationHostMsg_GetNotifications( |
| + request_id, |
| + service_worker_registration_id, |
| + origin, |
| + base::UTF16ToUTF8(filter_tag))); |
| +} |
| + |
| void NotificationManager::close(blink::WebNotificationDelegate* delegate) { |
| if (pending_notifications_.CancelPageNotificationFetches(delegate)) |
| return; |
| @@ -176,6 +205,8 @@ bool NotificationManager::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow); |
| IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose); |
| IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick); |
| + IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidGetNotifications, |
| + OnDidGetNotifications) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| @@ -207,6 +238,34 @@ void NotificationManager::OnDidClick(int notification_id) { |
| iter->second->dispatchClickEvent(); |
| } |
| +void NotificationManager::OnDidGetNotifications( |
| + int request_id, |
| + const std::vector<PersistentNotificationInfo>& notification_infos) { |
| + blink::WebNotificationGetCallbacks* callbacks = |
| + pending_get_notification_requests_.Lookup(request_id); |
| + DCHECK(callbacks); |
| + if (!callbacks) |
| + return; |
| + |
| + scoped_ptr<blink::WebVector<blink::WebPersistentNotificationInfo>> |
| + notifications(new blink::WebVector<blink::WebPersistentNotificationInfo>( |
| + notification_infos.size())); |
| + |
| + for (size_t i = 0; i < notification_infos.size(); ++i) { |
| + blink::WebPersistentNotificationInfo web_notification_info; |
| + web_notification_info.persistentNotificationId = |
| + blink::WebString::fromUTF8(notification_infos[i].first); |
| + web_notification_info.data = |
| + ToWebNotificationData(notification_infos[i].second); |
| + |
| + (*notifications)[i] = web_notification_info; |
| + } |
| + |
| + callbacks->onSuccess(notifications.release()); |
| + |
| + pending_get_notification_requests_.Remove(request_id); |
| +} |
| + |
| void NotificationManager::DisplayPageNotification( |
| const blink::WebSerializedOrigin& origin, |
| const blink::WebNotificationData& notification_data, |