// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module emoji_picker.mojom;
import "mojo/public/mojom/base/time.mojom";
import "url/mojom/url.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
// Capture any relevant enabled features from the system.
enum Feature {
// Extends the emoji picker to include symbols and emoticons alongside
// emojis as insertable options for the user.
EMOJI_PICKER_EXTENSION = 0,
// Extends the search functionality of emoji picker by implementing multi word
// prefix search across all categories.
EMOJI_PICKER_SEARCH_EXTENSION = 1,
// Extends the emoji picker to include gifs as an insertable option for the
// user.
EMOJI_PICKER_GIF_SUPPORT = 2,
// NOTE: Skip `3` (which was used for jelly support before).
// Extends the emoji picker with Seal support.
EMOJI_PICKER_SEAL_SUPPORT = 4,
// Extends the emoji picker with global variant grouping by syncing skin tone
// and gender preferences between emojis.
EMOJI_PICKER_VARIANT_GROUPING_SUPPORT = 5,
// Use Mojo for search
EMOJI_PICKER_MOJO_SEARCH = 6,
};
// The below structs are used to represent the Response format from the Tenor
// search and featured API endpoints which contains just enough information for
// the frontend to display GIFs.
// https://developers.google.com/tenor/guides/endpoints#response-format-search
// https://developers.google.com/tenor/guides/endpoints#response-format-featured
enum Status {
kHttpOk, // 200 OK
kNetError, // No internet connection
kHttpError, // Every other HTTP response status code
};
// Different categories within the emoji picker
enum Category {
kEmojis,
kSymbols,
kEmoticons,
kGifs,
};
struct TenorGifResponse {
string next;
array<GifResponse> results;
};
struct GifResponse {
string id;
string content_description;
GifUrls url;
gfx.mojom.Size preview_size;
gfx.mojom.Size full_size;
};
struct GifUrls {
url.mojom.Url full;
url.mojom.Url preview;
url.mojom.Url preview_image;
};
struct EmojiVariant {
string base;
string variant;
};
struct HistoryItem {
string emoji;
mojo_base.mojom.JSTime timestamp;
};
// Used by the WebUI page to bootstrap bidirectional communication.
interface PageHandlerFactory {
// The WebUI calls this method when the page is first initialized.
CreatePageHandler(pending_receiver<PageHandler> handler);
};
// Browser-side handler for requests from WebUI page.
interface PageHandler {
// Request the UI to be shown. Using this interface, dialog can be invisible
// while rendering to avoid UI showing in incomplete state.
ShowUI();
// Request backend to insert emoji (will close the picker).
// emoji: The emoji to insert in string form e.g. "😂".
// is_variant: If the emoji is a variant / base emoji, used for metrics.
// search_length: Length of search string, used for metrics
InsertEmoji(string emoji, bool is_variant, int16 search_length);
// Request backend to insert gif (will close the picker).
// gif: The gif to insert in the form of the url returned from the tenor API.
// e.g. "https://media.tenor.com/m8ggSG6nLqIAAAAC/christmas-minions.gif".
InsertGif(url.mojom.Url gif);
// Allows the emoji picker to identify if it was initialized in a incognito
// text field (so it will disable storing preference etc.)
IsIncognitoTextField() => (bool incognito);
// Returns a comma separated list of features activated within the emoji
// picker (ie. any feature flags or other related switches).
GetFeatureList() => (array<Feature> feature_list);
// Returns a list of GIF categories from the Tenor API
// (https://developers.google.com/tenor/guides/endpoints#categories).
GetCategories() => (Status status, array<string> gif_categories);
// Returns a list of the current global featured GIFs from the Tenor API
// (https://developers.google.com/tenor/guides/endpoints#base-url-featured).
GetFeaturedGifs(string? pos) => (Status status,
TenorGifResponse featured_gifs);
// Returns a list of the most relevant GIFs for a given search set of search
// terms or categories from the Tenor API
// (https://developers.google.com/tenor/guides/endpoints#base-url-search).
SearchGifs(string query, string? pos) => (Status status,
TenorGifResponse search_gifs);
// Returns a list of GIFs for the specified IDs
// (https://developers.google.com/tenor/guides/endpoints#posts).
GetGifsByIds(array<string> ids) => (Status status,
array<GifResponse> selected_gifs);
// Send a signal that emoji UI is fully loaded for metrics.
OnUiFullyLoaded();
// Find out the initial category to show for the emoji picker
GetInitialCategory() => (Category category);
// Find out the initial query to search for in the emoji picker
GetInitialQuery() => (string query);
// Update emoji picker history in chrome prefs
UpdateHistoryInPrefs(Category category, array<HistoryItem> history);
// Update preferred emoji variants in chrome prefs.
UpdatePreferredVariantsInPrefs(array<EmojiVariant> preferred_variants);
// Gets the emoji picker history from chrome prefs.
GetHistoryFromPrefs(Category category) => (array<HistoryItem> history);
};