| 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/browser/notifications/notification_message_filter.h" | 5 #include "content/browser/notifications/notification_message_filter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 13 #include "content/browser/notifications/notification_event_dispatcher_impl.h" |
| 13 #include "content/browser/notifications/notification_id_generator.h" | 14 #include "content/browser/notifications/notification_id_generator.h" |
| 14 #include "content/browser/notifications/page_notification_delegate.h" | 15 #include "content/browser/notifications/page_notification_delegate.h" |
| 15 #include "content/browser/notifications/platform_notification_context_impl.h" | 16 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 16 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 17 #include "content/common/platform_notification_messages.h" | 18 #include "content/common/platform_notification_messages.h" |
| 18 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/desktop_notification_delegate.h" | 22 #include "content/public/browser/desktop_notification_delegate.h" |
| 22 #include "content/public/browser/notification_database_data.h" | 23 #include "content/public/browser/notification_database_data.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, | 90 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, |
| 90 BrowserContext* browser_context) | 91 BrowserContext* browser_context) |
| 91 : BrowserMessageFilter(PlatformNotificationMsgStart), | 92 : BrowserMessageFilter(PlatformNotificationMsgStart), |
| 92 process_id_(process_id), | 93 process_id_(process_id), |
| 93 notification_context_(notification_context), | 94 notification_context_(notification_context), |
| 94 resource_context_(resource_context), | 95 resource_context_(resource_context), |
| 95 service_worker_context_(service_worker_context), | 96 service_worker_context_(service_worker_context), |
| 96 browser_context_(browser_context), | 97 browser_context_(browser_context), |
| 97 weak_factory_io_(this) {} | 98 weak_factory_io_(this) {} |
| 98 | 99 |
| 99 NotificationMessageFilter::~NotificationMessageFilter() {} | 100 NotificationMessageFilter::~NotificationMessageFilter() = default; |
| 100 | 101 |
| 101 void NotificationMessageFilter::DidCloseNotification( | 102 void NotificationMessageFilter::DidCloseNotification( |
| 102 const std::string& notification_id) { | 103 const std::string& notification_id) { |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 104 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 104 close_closures_.erase(notification_id); | 105 close_closures_.erase(notification_id); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void NotificationMessageFilter::OnDestruct() const { | 108 void NotificationMessageFilter::OnDestruct() const { |
| 109 NotificationEventDispatcherImpl* event_dispatcher = |
| 110 content::NotificationEventDispatcherImpl::GetInstance(); |
| 111 DCHECK(event_dispatcher); |
| 112 event_dispatcher->RendererGone(process_id_); |
| 108 BrowserThread::DeleteOnIOThread::Destruct(this); | 113 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 109 } | 114 } |
| 110 | 115 |
| 111 bool NotificationMessageFilter::OnMessageReceived(const IPC::Message& message) { | 116 bool NotificationMessageFilter::OnMessageReceived(const IPC::Message& message) { |
| 112 bool handled = true; | 117 bool handled = true; |
| 113 IPC_BEGIN_MESSAGE_MAP(NotificationMessageFilter, message) | 118 IPC_BEGIN_MESSAGE_MAP(NotificationMessageFilter, message) |
| 114 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_Show, | 119 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_Show, |
| 115 OnShowPlatformNotification) | 120 OnShowPlatformNotification) |
| 116 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_ShowPersistent, | 121 IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_ShowPersistent, |
| 117 OnShowPersistentNotification) | 122 OnShowPersistentNotification) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 DCHECK(service); | 159 DCHECK(service); |
| 155 | 160 |
| 156 if (!VerifyNotificationPermissionGranted(service, origin)) | 161 if (!VerifyNotificationPermissionGranted(service, origin)) |
| 157 return; | 162 return; |
| 158 | 163 |
| 159 std::string notification_id = | 164 std::string notification_id = |
| 160 GetNotificationIdGenerator()->GenerateForNonPersistentNotification( | 165 GetNotificationIdGenerator()->GenerateForNonPersistentNotification( |
| 161 origin, notification_data.tag, non_persistent_notification_id, | 166 origin, notification_data.tag, non_persistent_notification_id, |
| 162 process_id_); | 167 process_id_); |
| 163 | 168 |
| 169 NotificationEventDispatcherImpl* event_dispatcher = |
| 170 content::NotificationEventDispatcherImpl::GetInstance(); |
| 171 event_dispatcher->RegisterNonPersistentNotification( |
| 172 notification_id, process_id_, non_persistent_notification_id); |
| 173 |
| 164 std::unique_ptr<DesktopNotificationDelegate> delegate( | 174 std::unique_ptr<DesktopNotificationDelegate> delegate( |
| 165 new PageNotificationDelegate(process_id_, non_persistent_notification_id, | 175 new PageNotificationDelegate(process_id_, non_persistent_notification_id, |
| 166 notification_id)); | 176 notification_id)); |
| 167 | 177 |
| 168 base::Closure close_closure; | 178 base::Closure close_closure; |
| 169 service->DisplayNotification(browser_context_, notification_id, origin, | 179 service->DisplayNotification(browser_context_, notification_id, origin, |
| 170 SanitizeNotificationData(notification_data), | 180 SanitizeNotificationData(notification_data), |
| 171 notification_resources, std::move(delegate), | 181 notification_resources, std::move(delegate), |
| 172 &close_closure); | 182 &close_closure); |
| 173 | 183 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_VERIFY); | 400 bad_message::ReceivedBadMessage(this, bad_message::NMF_NO_PERMISSION_VERIFY); |
| 391 return false; | 401 return false; |
| 392 } | 402 } |
| 393 | 403 |
| 394 NotificationIdGenerator* NotificationMessageFilter::GetNotificationIdGenerator() | 404 NotificationIdGenerator* NotificationMessageFilter::GetNotificationIdGenerator() |
| 395 const { | 405 const { |
| 396 return notification_context_->notification_id_generator(); | 406 return notification_context_->notification_id_generator(); |
| 397 } | 407 } |
| 398 | 408 |
| 399 } // namespace content | 409 } // namespace content |
| OLD | NEW |