chromium/third_party/blink/public/mojom/notifications/notification.mojom

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

module blink.mojom;

import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/time.mojom";
import "skia/public/mojom/bitmap.mojom";
import "url/mojom/url.mojom";

// Directionality options that can be indicated for notifications.
enum NotificationDirection {
  LEFT_TO_RIGHT,
  RIGHT_TO_LEFT,
  AUTO,
};

// The different types of actions that can be added to a Notification.
enum NotificationActionType {
  BUTTON,
  TEXT
};

// Scenarios that define the notification behavior.
enum NotificationScenario {
  DEFAULT,
  INCOMING_CALL
};

// Structure representing an action button associated with a Notification.
struct NotificationAction {
  // Type of action this structure represents.
  NotificationActionType type;

  // Action name that the author can use to distinguish them.
  string action;

  // Title of the action button.
  mojo_base.mojom.String16 title;

  // URL of the icon for the button. May be empty if no url was specified.
  url.mojom.Url icon;

  // Placeholder to display for text-based actions in absence of user input.
  mojo_base.mojom.String16? placeholder;
};

// Structure representing the information associated with a Web Notification.
struct NotificationData {
  // The maximum size of developer-provided data to be stored in the |data|
  // property of this structure, in bytes.
  const uint64 kMaximumDeveloperDataSize = 1048576; // 1024 * 1024 (= 1 MB)

  // Title to be displayed with the Web Notification.
  mojo_base.mojom.String16 title;

  // Hint to determine the directionality of the displayed notification.
  NotificationDirection direction = LEFT_TO_RIGHT;

  // BCP 47 language tag describing the notification's contents. Optional.
  string? lang;

  // Contents of the notification.
  mojo_base.mojom.String16 body;

  // Tag of the notification. Notifications sharing both their origin and their
  // tag will replace the first displayed notification.
  string tag;

  // URL of the image contents of the notification. May be empty if no url was
  // specified.
  url.mojom.Url image;

  // URL of the icon which is to be displayed with the notification.
  url.mojom.Url icon;

  // URL of the badge representing the website displaying the notification.
  url.mojom.Url badge;

  // Vibration pattern for the notification. Each element in the array
  // represents a number of milliseconds to vibrate (even indices), or wait
  // (odd indices). This follows the syntax of the Vibration API - see
  // https://w3c.github.io/vibration/
  //
  // TODO(https://crbug.com/797306): Make this an array of base::TimeDeltas.
  array<int32>? vibration_pattern;

  // The time at which the event the notification represents took place,
  // in milliseconds since the Unix epoch.
  // TODO(https://crbug.com/797306): Use base::TimeTicks instead of a double.
  double timestamp = 0;

  // Whether default notification indicators (sound, vibration, light) should
  // be played again if the notification is replacing an older notification.
  bool renotify = false;

  // Whether default notification indicators (sound, vibration, light) should
  // be suppressed.
  bool silent = false;

  // Whether the notification should remain onscreen indefinitely, rather than
  // being auto-minimized to the notification center (if allowed by platform).
  bool require_interaction = false;

  // Developer-provided data associated with the notification, in the form of
  // a serialized string. Must not exceed the number of bytes specified by
  // |kMaximumDeveloperDataSize|.
  array<uint8>? data;

  // Actions that should be shown as buttons on the notification.
  array<NotificationAction>? actions;

  // Time when to show this notification.
  mojo_base.mojom.Time? show_trigger_timestamp;

  // The notification scenario can be either DEFAULT or INCOMING_CALL. If the
  // latter was selected and the Notification was triggered by an installed web
  // app, it should have a ringtone, customized action buttons, and increased
  // priority. See the proposal's explainer at:
  // https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/Notifications/notifications_actions_customization.md
  NotificationScenario scenario = DEFAULT;
};

// Structure representing the resources associated with a Web Notification.
struct NotificationResources {
  // Image contents of the notification. May be empty if no image was specified.
  skia.mojom.BitmapN32? image;

  // Icon to be displayed with the notification.
  skia.mojom.BitmapN32? icon;

  // Badge representing the website displaying the notification.
  skia.mojom.BitmapN32? badge;

  // Icons for the actions. The size of |action_icons| must match the size
  // of |actions| in the corresponding NotificationData.
  array<skia.mojom.BitmapN32?>? action_icons;
};