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