#include "content/browser/notifications/notification_event_dispatcher_impl.h"
#include <optional>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "content/browser/notifications/devtools_event_logging.h"
#include "content/browser/notifications/platform_notification_context_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/weak_document_ptr.h"
#include "content/public/common/persistent_notification_status.h"
#include "third_party/blink/public/common/notifications/platform_notification_data.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
namespace content {
namespace {
NotificationDispatchCompleteCallback;
PersistentNotificationDispatchCompleteCallback;
NotificationOperationCallback;
NotificationOperationCallbackWithContext;
PersistentNotificationStatus ConvertServiceWorkerStatus(
blink::ServiceWorkerStatusCode service_worker_status) { … }
void ServiceWorkerNotificationEventFinished(
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status) { … }
void DispatchNotificationEventOnRegistration(
const NotificationDatabaseData& notification_database_data,
NotificationOperationCallback dispatch_event_action,
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode service_worker_status,
scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { … }
void FindServiceWorkerRegistration(
const url::Origin& origin,
const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context,
NotificationOperationCallback notification_action_callback,
NotificationDispatchCompleteCallback dispatch_complete_callback,
bool success,
const NotificationDatabaseData& notification_database_data) { … }
void ReadNotificationDatabaseData(
const std::string& notification_id,
const GURL& origin,
PlatformNotificationContext::Interaction interaction,
const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context,
const scoped_refptr<PlatformNotificationContext>& notification_context,
NotificationOperationCallback notification_read_callback,
NotificationDispatchCompleteCallback dispatch_complete_callback) { … }
void DispatchNotificationClickEventOnWorker(
const scoped_refptr<ServiceWorkerVersion>& service_worker,
const NotificationDatabaseData& notification_database_data,
const std::optional<int>& action_index,
const std::optional<std::u16string>& reply,
ServiceWorkerVersion::StatusCallback callback,
blink::ServiceWorkerStatusCode start_worker_status) { … }
void DoDispatchNotificationClickEvent(
const std::optional<int>& action_index,
const std::optional<std::u16string>& reply,
const scoped_refptr<PlatformNotificationContext>& notification_context,
BrowserContext* browser_context,
const ServiceWorkerRegistration* service_worker_registration,
const NotificationDatabaseData& notification_database_data,
NotificationDispatchCompleteCallback dispatch_complete_callback) { … }
void OnPersistentNotificationDataDeleted(
blink::ServiceWorkerStatusCode service_worker_status,
NotificationDispatchCompleteCallback dispatch_complete_callback,
bool success) { … }
void DeleteNotificationDataFromDatabase(
const std::string& notification_id,
const GURL& origin,
const scoped_refptr<PlatformNotificationContext>& notification_context,
NotificationDispatchCompleteCallback dispatch_complete_callback,
blink::ServiceWorkerStatusCode status_code) { … }
void DispatchNotificationCloseEventOnWorker(
const scoped_refptr<ServiceWorkerVersion>& service_worker,
const NotificationDatabaseData& notification_database_data,
ServiceWorkerVersion::StatusCallback callback,
blink::ServiceWorkerStatusCode start_worker_status) { … }
void DoDispatchNotificationCloseEvent(
const std::string& notification_id,
bool by_user,
const scoped_refptr<PlatformNotificationContext>& notification_context,
BrowserContext* browser_context,
const ServiceWorkerRegistration* service_worker_registration,
const NotificationDatabaseData& notification_database_data,
NotificationDispatchCompleteCallback dispatch_complete_callback) { … }
void DispatchNotificationEvent(
BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
const PlatformNotificationContext::Interaction interaction,
NotificationOperationCallbackWithContext notification_action_callback,
NotificationDispatchCompleteCallback dispatch_complete_callback) { … }
void OnDispatchNotificationClickEventComplete(
PersistentNotificationDispatchCompleteCallback dispatch_complete_callback,
PersistentNotificationStatus status,
blink::ServiceWorkerStatusCode service_worker_status) { … }
void OnDispatchNotificationCloseEventComplete(
PersistentNotificationDispatchCompleteCallback dispatch_complete_callback,
PersistentNotificationStatus status,
blink::ServiceWorkerStatusCode service_worker_status) { … }
}
NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { … }
NotificationEventDispatcherImpl*
NotificationEventDispatcherImpl::GetInstance() { … }
NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() = default;
NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() = default;
NotificationEventDispatcherImpl::NonPersistentNotificationListenerInfo::
NonPersistentNotificationListenerInfo(
mojo::Remote<blink::mojom::NonPersistentNotificationListener> remote,
WeakDocumentPtr document,
RenderProcessHost::NotificationServiceCreatorType creator_type)
: … { … }
NotificationEventDispatcherImpl::NonPersistentNotificationListenerInfo::
NonPersistentNotificationListenerInfo(
NotificationEventDispatcherImpl::NonPersistentNotificationListenerInfo&&
info) = default;
NotificationEventDispatcherImpl::NonPersistentNotificationListenerInfo::
~NonPersistentNotificationListenerInfo() = default;
base::optional_ref<content::NotificationEventDispatcherImpl::
NonPersistentNotificationListenerInfo>
NotificationEventDispatcherImpl::GetListenerIfNotifiable(
const std::string& notification_id) { … }
void NotificationEventDispatcherImpl::DispatchNotificationClickEvent(
BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
const std::optional<int>& action_index,
const std::optional<std::u16string>& reply,
NotificationDispatchCompleteCallback dispatch_complete_callback) { … }
void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent(
BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
bool by_user,
NotificationDispatchCompleteCallback dispatch_complete_callback) { … }
void NotificationEventDispatcherImpl::RegisterNonPersistentNotificationListener(
const std::string& notification_id,
mojo::PendingRemote<blink::mojom::NonPersistentNotificationListener>
event_listener_remote,
const WeakDocumentPtr& event_document_ptr,
const RenderProcessHost::NotificationServiceCreatorType creator_type) { … }
void NotificationEventDispatcherImpl::DispatchNonPersistentShowEvent(
const std::string& notification_id) { … }
void NotificationEventDispatcherImpl::DispatchNonPersistentClickEvent(
const std::string& notification_id,
NotificationClickEventCallback callback) { … }
void NotificationEventDispatcherImpl::DispatchNonPersistentCloseEvent(
const std::string& notification_id,
base::OnceClosure completed_closure) { … }
void NotificationEventDispatcherImpl::OnNonPersistentCloseComplete(
const std::string& notification_id,
base::OnceClosure completed_closure) { … }
void NotificationEventDispatcherImpl::
HandleConnectionErrorForNonPersistentNotificationListener(
const std::string& notification_id) { … }
}