// 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,
};
// Representation of a Bookmark node to be used by the renderer for display.
// Nodes are mapped using the the `id` and `parent_id` (that can be pointing to
// a Side Panel specific fixed ID for merged nodes), any actions or
// modifications to the nodes needs to be communicated using those ids.
// A merged node is a bookmark node that can contain both local and account
// bookmarks at the same time with no differentiation in the Ui.
struct BookmarksTreeNode {
string id;
string parent_id;
uint32 index;
string title;
// Non-null for page nodes.
string? url;
// Non-null for folder nodes.
array<BookmarksTreeNode>? children;
double? date_added;
double? date_last_used;
// Used to prevent drag events.
bool unmodifiable;
};
// Used by the Read Later WebUI page (for the side panel) to bootstrap
// bidirectional communication.
// Also initializes the `page` remote that allows communication from the browser
// to the renderer.
interface BookmarksPageHandlerFactory {
// The WebUI calls this method when the page is first initialized.
CreateBookmarksPageHandler(pending_remote<BookmarksPage> page,
pending_receiver<BookmarksPageHandler> handler);
};
// Browser-side handler for requests from WebUI page.
// Folder parent ID should use string IDs as it can represent merged nodes.
// Regular ID (non merged folder or url) can be directly passed as int64, it
// can also support string based IDs.
// A merged node is a bookmark node that can contain both local and account
// bookmarks at the same time with no differentiation in the Ui.
interface BookmarksPageHandler {
// Bookmarks the current active tab in the given folder.
BookmarkCurrentTabInFolder(string folder_id);
// Creates a folder in `folder_id` at the first position with `title`.
// Returns the id of the newly created node.
CreateFolder(string folder_id, string title) => (string new_folder_id);
// Drops the dragged bookmarks in the folder corresponding to `folder_id`.
// Result callback is called when all nodes are moved, it contains no data.
// Relies on BookmarkManagerPrivateDragEventRouter to get the data being
// dropped.
DropBookmarks(string folder_id) => ();
// Opens the edit bookmark dialog.
ExecuteEditCommand(array<int64> node_ids, ActionSource source);
// Opens the move bookmark dialog.
ExecuteMoveCommand(array<int64> node_ids, ActionSource source);
// Opens the bookmarks specified by `side_panel_ids` in a new background tab,
// using the same logic as the native bookmarks context menu.
// Some of the `side_panel_ids` may be a folder or a url node, so it could
// also map to a merged node that has an actual string representation.
ExecuteOpenInNewTabCommand(array<string> side_panel_ids, ActionSource source);
// Opens the bookmarks specified by `side_panel_ids` in a new window,
// using the same logic as the native bookmarks context menu.
// Some of the `side_panel_ids` may be a folder or a url node, so it could
// also map to a merged node that has an actual string representation.
ExecuteOpenInNewWindowCommand(array<string> side_panel_ids,
ActionSource source);
// Opens the bookmarks specified by `side_panel_ids` in a new incognito
// window, using the same logic as the native bookmarks context menu.
// Some of the `side_panel_ids` may be a folder or a url node, so it could
// also map to a merged node that has an actual string representation.
ExecuteOpenInIncognitoWindowCommand(array<string> side_panel_ids,
ActionSource source);
// Opens the bookmarks specified by `side_panel_ids` in a new tab group, using
// the same logic as the native bookmarks context menu.
// Some of the `side_panel_ids` may be a folder or a url node, so it could
// also map to a merged node that has an actual string representation.
ExecuteOpenInNewTabGroupCommand(array<string> side_panel_ids,
ActionSource source);
// Opens the bookmarks specified by node_ids in a new split view, using
// the same logic as the native bookmarks context menu.
ExecuteOpenInSplitViewCommand(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);
// Triggers the undo from the BookmarkModel.
Undo();
// Renames the bookmark with `node_id` with `new_title`. The id should map to
// a regular non permanent node as those are the only ones that can be
// renamed.
RenameBookmark(int64 node_id, string new_title);
// Moves the bookmark with `node_id` into the `folder_id` folder.
// `folder_id` can be a merged Side Panel ID. `node_id` should map to a
// regular non permanent node.
MoveBookmark(int64 node_id, string folder_id);
// Removes the bookmarks with id in `node_ids`. All bookmarks are expected to
// map to a regular non permanent node. If some of the nodes are folders, it
// will remove all children as well.
// Result callback is called when all nodes are removed, it contains no data.
RemoveBookmarks(array<int64> node_ids) => ();
// 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();
// Requests all non empty permanent nodes in a merged view (local and account
// nodes are merged into one).
// The `id` of those nodes and the `parent_id` of their direct descendants are
// a fixed string ID reprensenting the merged view nodes.
GetAllBookmarks() => (array<BookmarksTreeNode> nodes);
};
// Called from C++ to TS. (Browser -> Renderer)
interface BookmarksPage {
// Send the information of the newly added node to the Ui.
OnBookmarkNodeAdded(BookmarksTreeNode node);
// Send all the node ids that were removed to the Ui.
OnBookmarkNodesRemoved(array<string> node_ids);
// Send the list of children ids of `folder_id` after a reorder event.
OnBookmarkParentFolderChildrenReordered(string folder_id,
array<string> children_ordered_ids);
// Send the node index of a moved element: old and new Ui indices.
OnBookmarkNodeMoved(string old_parent_index, uint32 old_node_index,
string new_parent_index, uint32 new_node_index);
// Send the new information of the bookmark.
OnBookmarkNodeChanged(string id, string new_title, string new_url);
};