1// Copyright 2019 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5module new_tab_page.mojom; 6 7import "skia/public/mojom/skcolor.mojom"; 8import "url/mojom/url.mojom"; 9import "mojo/public/mojom/base/text_direction.mojom"; 10 11struct MostVisitedTile { 12 string title; 13 mojo_base.mojom.TextDirection title_direction; 14 url.mojom.Url url; 15}; 16 17struct MostVisitedInfo { 18 bool custom_links_enabled; 19 bool visible; 20 array<MostVisitedTile> tiles; 21}; 22 23struct ThemeColors { 24 // The theme's frame color. 25 skia.mojom.SkColor frame; 26 // The theme's active tab color. 27 skia.mojom.SkColor active_tab; 28}; 29 30// A collection of background images. 31struct BackgroundCollection { 32 // Collection identifier. 33 string id; 34 // Localized string of the collection name. 35 string label; 36 // URL to a preview image for the collection. Can point to untrusted content. 37 url.mojom.Url preview_image_url; 38}; 39 40// A background image in a collection. 41struct BackgroundImage { 42 // Localized string of extra image info. 43 string label; 44 // URL to a preview of the image. Can point to untrusted content. 45 url.mojom.Url preview_image_url; 46}; 47 48// A predefined theme provided by Chrome. Created from data embedded in the 49// Chrome binary. 50struct ChromeTheme { 51 // Theme identifier. 52 int32 id; 53 // Localized string of the theme name. 54 string label; 55 ThemeColors colors; 56}; 57 58enum ThemeType { 59 DEFAULT, 60 AUTOGENERATED, 61 CHROME, 62 THIRD_PARTY, 63}; 64 65// Additional info for third-party themes. 66struct ThirdPartyThemeInfo { 67 // ID in the Chrome Web Store. 68 string id; 69 // Human-readable theme name. 70 string name; 71}; 72 73union ThemeInfo { 74 // Set if the theme is a Chrome theme. 75 int32 chrome_theme_id; 76 // Set if the theme is autogenerated. 77 ThemeColors autogenerated_theme_colors; 78 // Set if the theme is a third-party theme. 79 ThirdPartyThemeInfo third_party_theme_info; 80}; 81 82// A generic theme. 83struct Theme { 84 // The theme's type (e.g. default or third-party). 85 ThemeType type; 86 skia.mojom.SkColor background_color; 87 skia.mojom.SkColor shortcut_background_color; 88 skia.mojom.SkColor shortcut_text_color; 89 // True if the theme is dark (e.g. NTP background color is dark). 90 bool is_dark; 91 // Color of Google logo. If not set show the logo multi-colored. 92 skia.mojom.SkColor? logo_color; 93 // URL to the background image. Can point to untrusted content. 94 url.mojom.Url? background_image_url; 95 // Human readable attributions of the background image. 96 string? background_image_attribution_1; 97 string? background_image_attribution_2; 98 // URL associated with the background image. Used for href. 99 url.mojom.Url? background_image_attribution_url; 100 101 // TODO(crbug.com/1040682): Additional info about the theme depending on the 102 // type. That should be optional since only some themes require it. However, 103 // making this field optional crashes JS. 104 ThemeInfo info; 105}; 106 107// The contents of a doodle. 108union DoodleContent { 109 // Doodle image encoded as data URL. Set for static and animated doodles. 110 string image; 111 // URL pointing to doodle page. Set for interactive doodles. 112 url.mojom.Url url; 113}; 114 115// A doodle. Retrieved from the Google doodle server. 116struct Doodle { 117 // The doodle content. 118 DoodleContent content; 119}; 120 121// Used by the WebUI page to bootstrap bidirectional communication. 122interface PageHandlerFactory { 123 // The WebUI page's |BrowserProxy| singleton calls this method when the page 124 // is first initialized. 125 CreatePageHandler(pending_remote<Page> page, 126 pending_receiver<PageHandler> handler); 127}; 128 129// Browser-side handler for requests from WebUI page. 130interface PageHandler { 131 // Adds tile. 132 AddMostVisitedTile(url.mojom.Url url, string title) => (bool success); 133 // Deletes tile by |url|. 134 DeleteMostVisitedTile(url.mojom.Url url); 135 // Moves tile identified by url to a new position at index |new_pos|. 136 ReorderMostVisitedTile(url.mojom.Url url, uint8 new_pos); 137 // Replaces the custom and most-visited tiles with the default tile set. 138 RestoreMostVisitedDefaults(); 139 // Set the visibility and whether custom links are enabled. 140 SetMostVisitedSettings(bool customLinksEnabled, bool visible); 141 // Undoes the last action done to the tiles (add, delete, reorder, restore or 142 // update). Note that only the last action can be undone. 143 UndoMostVisitedTileAction(); 144 // Called to update the tiles. 145 UpdateMostVisitedInfo(); 146 // Updates a tile by url. 147 UpdateMostVisitedTile(url.mojom.Url url, url.mojom.Url new_url, 148 string new_title) 149 => (bool success); 150 // Returns the pre-defined Chrome themes. 151 GetChromeThemes() => (array<ChromeTheme> chromeThemes); 152 // Applies the default theme. 153 ApplyDefaultTheme(); 154 // Applies autogenerated theme for the given color. 155 ApplyAutogeneratedTheme(skia.mojom.SkColor frame_color); 156 // Applies the predefined Chrome theme with the given ID. 157 ApplyChromeTheme(int32 id); 158 // Confirms changes made to the theme. 159 ConfirmThemeChanges(); 160 // Reverts changes made to the theme. 161 RevertThemeChanges(); 162 // Returns the collections of background images. 163 GetBackgroundCollections() => (array<BackgroundCollection> collections); 164 // Returns the images of a collection identified by |collection_id|. 165 GetBackgroundImages(string collection_id) => (array<BackgroundImage> images); 166 // Invisibly focuses the omnibox. 167 FocusOmnibox(); 168 // Pastes |text| into the omnibox. 169 PasteIntoOmnibox(string text); 170 // Gets current doodle if there is one. 171 GetDoodle() => (Doodle? doodle); 172}; 173 174// WebUI-side handler for requests from the browser. 175interface Page { 176 // Updates the page with most-visited info which includes whether the 177 // tiles should be shown, if links can be customized and the tiles. 178 SetMostVisitedInfo(MostVisitedInfo info); 179 // Sets the current theme. 180 SetTheme(Theme theme); 181 // If |focused| fakes focus on the fakebox. 182 SetFakeboxFocused(bool focused); 183 // If |visible| shows the fakebox. 184 SetFakeboxVisible(bool visible); 185}; 186