chromium/ui/webui/resources/cr_components/most_visited/most_visited.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 most_visited.mojom;

import "mojo/public/mojom/base/text_direction.mojom";
import "skia/public/mojom/skcolor.mojom";
import "url/mojom/url.mojom";

struct MostVisitedTile {
  string title;
  mojo_base.mojom.TextDirection title_direction;
  url.mojom.Url url;
  bool is_query_tile;

  // ======= METRICS =======
  // Identifier of most visited entry source (e.g. top sites).
  int32 source;
  // Identifier of most visited entry title source (e.g. page's title tag).
  int32 title_source;
};

// Theme settings for the NTP MV tiles.
struct MostVisitedTheme {
  skia.mojom.SkColor background_color;
  // True if |background_color| is dark.
  bool use_white_tile_icon;
  // True if the theme is dark (e.g. NTP background color is dark).
  bool is_dark;
};

struct MostVisitedInfo {
  bool custom_links_enabled;
  bool visible;
  array<MostVisitedTile> tiles;
};

// Used to bootstrap the bidirectional communication.
interface MostVisitedPageHandlerFactory {
  // The component calls this method when it is first initialized.
  CreatePageHandler(
           pending_remote<MostVisitedPage> page,
           pending_receiver<MostVisitedPageHandler> handler);
};

// Browser-side handler for requests from WebUI page.
interface MostVisitedPageHandler {
  // Adds tile.
  AddMostVisitedTile(url.mojom.Url url, string title) => (bool success);
  // Deletes tile by |url|.
  DeleteMostVisitedTile(url.mojom.Url url);
  // Moves tile identified by url to a new position at index |new_pos|.
  ReorderMostVisitedTile(url.mojom.Url url, uint8 new_pos);
  // Replaces the custom and most-visited tiles with the default tile set.
  RestoreMostVisitedDefaults();
  // Undoes the last action done to the tiles (add, delete, reorder, restore or
  // update). Note that only the last action can be undone.
  UndoMostVisitedTileAction();
  // Called to get updates on visibility of most visited tiles, whether custom
  // links are enabled, and the tiles themselves.
  UpdateMostVisitedInfo();
  // Updates a tile by url.
  UpdateMostVisitedTile(url.mojom.Url url,
                        url.mojom.Url new_url,
                        string new_title) => (bool success);
  // Prerenders |tile|.
  PrerenderMostVisitedTile(MostVisitedTile tile, bool is_hover_trigger);
  // Preconnects |tile|. Preresolve/preconnects the origin; a socket created
  // by this call will be reused, if possible, for a subsequent attempt to
  // prerender or navigate to this url.
  PreconnectMostVisitedTile(MostVisitedTile tile);
  // Cancel the on-going prerender if exists.
  CancelPrerender();
  // ======= METRICS =======
  // Logs that |tiles| were displayed / updated at |time|. The first instance of
  // this event is used as a proxy for when the NTP has finished loading.
  OnMostVisitedTilesRendered(array<MostVisitedTile> tiles, double time);
  // Logs that |tile| at position |index| was triggered to navigate to that
  // most visited entry.
  // |mouse_button| indicates which mouse button was pressed on the entry. See
  // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
  OnMostVisitedTileNavigation(MostVisitedTile tile,
                              uint32 index,
                              uint8 mouse_button,
                              bool alt_key,
                              bool ctrl_key,
                              bool meta_key,
                              bool shift_key);
};

// WebUI-side handler for requests from the browser.
interface MostVisitedPage {
  // Updates the page with the visibility of most visited tiles, whether custom
  // links are enabled, and the tiles themselves.
  SetMostVisitedInfo(MostVisitedInfo info);
};