chromium/chrome/browser/ui/webui/side_panel/bookmarks/bookmarks.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 side_panel.mojom;

import "ui/base/mojom/window_open_disposition.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";

// Used to indicate the source item from which the action is triggered.
enum ActionSource {
  kBookmark,
  kPriceTracking,
};

// Used to indicate the order bookmarks are sorted in the side panel.
// Do not reorder or re-use values, used by profile prefs and metrics.
// This must be kept in sync with BookmarksSidePanelSortType in
// tools/metrics/histograms/enums.xml.
enum SortOrder {
  kNewest = 0,
  kOldest = 1,
  kLastOpened = 2,
  kAlphabetical = 3,
  kReverseAlphabetical = 4,

  // Must be last. May add new values before this one.
  kCount = 5,
};

// Used to indicate the order bookmarks are sorted in the side panel.
// Do not reorder or re-use values, used by profile prefs and metrics.
// This must be kept in sync with BookmarksSidePanelViewType in
// tools/metrics/histograms/enums.xml.
enum ViewType {
  kCompact = 0,
  kExpanded = 1,

  // Must be last. May add new values before this one.
  kCount = 2,
};

// Used by the Read Later WebUI page (for the side panel) to bootstrap
// bidirectional communication.
interface BookmarksPageHandlerFactory {
  // The WebUI calls this method when the page is first initialized.
  CreateBookmarksPageHandler(pending_receiver<BookmarksPageHandler> handler);
};

// Browser-side handler for requests from WebUI page.
interface BookmarksPageHandler {
  // Bookmarks the current active tab in the given folder.
  BookmarkCurrentTabInFolder(int64 folder_id);

  // Opens the bookmarks specified by node_ids in a new background tab, using
  // the same logic as the native bookmarks context menu.
  ExecuteOpenInNewTabCommand(array<int64> node_ids, ActionSource source);

  // Opens the bookmarks specified by node_ids in a new window, using the same
  // logic as the native bookmarks context menu.
  ExecuteOpenInNewWindowCommand(array<int64> node_ids, ActionSource source);

  // Opens the bookmarks specified by node_ids in a new incognito window, using
  // the same logic as the native bookmarks context menu.
  ExecuteOpenInIncognitoWindowCommand(array<int64> node_ids,
                                      ActionSource source);

  // Opens the bookmarks specified by node_ids in a new tab group, using
  // the same logic as the native bookmarks context menu.
  ExecuteOpenInNewTabGroupCommand(array<int64> node_ids, ActionSource source);

  // Moves bookmark specified by node_id to be a direct descendant of the
  // Bookmarks Bar folder, using the same logic as the native bookmarks context
  // menu.
  ExecuteAddToBookmarksBarCommand(int64 node_id, ActionSource source);

  // Moves bookmark specified by node_id to be a direct descendant of the
  // Other Bookmarks folder, using the same logic as the native bookmarks
  // context menu.
  ExecuteRemoveFromBookmarksBarCommand(int64 node_id, ActionSource source);

  // Deletes bookmarks specified by node_ids, using the same logic as the
  // native bookmarks context menu.
  ExecuteDeleteCommand(array<int64> node_ids, ActionSource source);

  // Opens the bookmark specified by node_id. Passes the parent folder
  // depth for metrics collection and the action source to identify
  // from which surface this request is made.
  OpenBookmark(int64 node_id, int32 parent_folder_depth,
               ui.mojom.ClickModifiers click_modifiers,
               ActionSource source);

  // Called when the sort option has been updated and the profile pref should be
  // updated.
  SetSortOrder(SortOrder sort_order);

  // Called when the view option has been updated and the profile pref should be
  // updated.
  SetViewType(ViewType view_type);

  // Opens a context menu for a bookmark node. The id parameter is internally
  // an int64 but gets passed as a string from the chrome.bookmarks Extension
  // API. The point parameter is the location where the context menu is
  // triggered. The source parameter is the type of source item from which
  // the context menu is triggered.
  ShowContextMenu(string id, gfx.mojom.Point point, ActionSource source);

  // Notify the backend that the UI is ready to be shown.
  ShowUI();
};