chromium/content/browser/notifications/notification_event_dispatcher_impl.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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;

// Derives a PersistentNotificationStatus from the ServiceWorkerStatusCode.
PersistentNotificationStatus ConvertServiceWorkerStatus(
    blink::ServiceWorkerStatusCode service_worker_status) {}

// To be called when a notification event has finished with a
// blink::ServiceWorkerStatusCode result. Will run or post a task to call
// |dispatch_complete_callback| on the UI thread with a
// PersistentNotificationStatus derived from the service worker status.
void ServiceWorkerNotificationEventFinished(
    NotificationDispatchCompleteCallback dispatch_complete_callback,
    blink::ServiceWorkerStatusCode service_worker_status) {}

// Dispatches the given notification action event on
// |service_worker_registration| if the registration was available.
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) {}

// Finds the ServiceWorkerRegistration associated with the |origin| and
// |service_worker_registration_id|. Must be called on the UI thread.
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) {}

// Reads the data associated with the |notification_id| belonging to |origin|
// from the notification context.
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) {}

// -----------------------------------------------------------------------------

// Dispatches the notificationclick event on |service_worker|.
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) {}

// Dispatches the notification click event on the |service_worker_registration|.
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) {}

// -----------------------------------------------------------------------------

// Called when the notification data has been deleted to finish the notification
// close event.
void OnPersistentNotificationDataDeleted(
    blink::ServiceWorkerStatusCode service_worker_status,
    NotificationDispatchCompleteCallback dispatch_complete_callback,
    bool success) {}

// Called when the persistent notification close event has been handled
// to remove the notification from the database.
void DeleteNotificationDataFromDatabase(
    const std::string& notification_id,
    const GURL& origin,
    const scoped_refptr<PlatformNotificationContext>& notification_context,
    NotificationDispatchCompleteCallback dispatch_complete_callback,
    blink::ServiceWorkerStatusCode status_code) {}

// Dispatches the notificationclose event on |service_worker|.
void DispatchNotificationCloseEventOnWorker(
    const scoped_refptr<ServiceWorkerVersion>& service_worker,
    const NotificationDatabaseData& notification_database_data,
    ServiceWorkerVersion::StatusCallback callback,
    blink::ServiceWorkerStatusCode start_worker_status) {}

// Dispatches the notification close event on the service worker registration.
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) {}

// Dispatches any notification event. The actual, specific event dispatch should
// be done by the |notification_action_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) {}

}  // namespace

// static
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) {}

// Only fire the notification listeners (including show, click and
// close) when it exists in the map and the document is currently
// not in back/forward cache.
// See https://crbug.com/1350944
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) {}

}  // namespace content