chromium/extensions/common/mojom/event_dispatcher.mojom

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

module extensions.mojom;

import "extensions/common/mojom/host_id.mojom";
import "mojo/public/mojom/base/values.mojom";
import "url/mojom/url.mojom";
// EventDispatch is a one-per-renderer-processs interface that is responsible
// for triggering API events that extensions have registered listeners for in
// the renderer (either the extension process renderer, for extension-origin
// pages, or a web renderer, for content script listeners).
// The interface is implemented in //extensions/renderer code, and is
// called on the browser side by the EventRouter.
// `event_will_run_in_lazy_background_page_script` indicates that during the
// event dispatch the event will, at least, run in a lazy background page
// script. It is should always be false for service workers.
interface EventDispatcher {
    // Sent to the renderer to dispatch an event to a listener.
    DispatchEvent(DispatchEventParams params,
                  mojo_base.mojom.ListValue event_args) => (
                    // TODO(crbug.com/40277737): Remove this variable once
                    // crbug.com/1470045  allows us to only ack for lazy
                    // background page events.
                    bool event_will_run_in_lazy_background_page_script);
};

struct EventFilteringInfo {
  url.mojom.Url? url;

  string? service_type;

  // TODO(yoichio): Use nullable when https://crbug.com/657632 is fixed.
  bool has_instance_id;
  int32 instance_id;

  string? window_type;

  // TODO(yoichio): Use nullable when https://crbug.com/657632 is fixed.
  bool has_window_exposed_by_default;
  bool window_exposed_by_default;
};

struct DispatchEventParams {
  // If this event is for a service worker, then this is the worker thread
  // id. Otherwise, this is 0.
  int32 worker_thread_id;

  // The |HostID| to route the event to.
  HostID host_id;

  // The name of the event to dispatch.
  string event_name;

  // The id of the event for use in the EventAck response message.
  int32 event_id;

  // Whether or not the event is part of a user gesture.
  bool is_user_gesture;

  // Additional filtering info for the event.
  EventFilteringInfo filtering_info;
};