Commit d300702e authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Chromium LUCI CQ

[realbox] Moves realbox handlers out of NTP and into its own dir

- This is step 1 to transfer ownership of realbox to the omnibox team.
- The next step is to move the realbox resources into their own dir.

Bug: 1159934
Change-Id: I19c7eb5253524d393c1bed9e0c9b0a36ac23c4ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595205
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845364}
parent 2524587b
...@@ -2010,6 +2010,7 @@ static_library("browser") { ...@@ -2010,6 +2010,7 @@ static_library("browser") {
"//chrome/browser/ui/webui/new_tab_page:mojo_bindings", "//chrome/browser/ui/webui/new_tab_page:mojo_bindings",
"//chrome/browser/ui/webui/omnibox:mojo_bindings", "//chrome/browser/ui/webui/omnibox:mojo_bindings",
"//chrome/browser/ui/webui/read_later:mojo_bindings", "//chrome/browser/ui/webui/read_later:mojo_bindings",
"//chrome/browser/ui/webui/realbox:mojo_bindings",
"//chrome/browser/ui/webui/reset_password:mojo_bindings", "//chrome/browser/ui/webui/reset_password:mojo_bindings",
"//chrome/browser/ui/webui/tab_search:mojo_bindings", "//chrome/browser/ui/webui/tab_search:mojo_bindings",
"//chrome/browser/ui/webui/usb_internals:mojo_bindings", "//chrome/browser/ui/webui/usb_internals:mojo_bindings",
......
...@@ -114,6 +114,7 @@ ...@@ -114,6 +114,7 @@
#include "chrome/browser/speech/speech_recognition_service_factory.h" #include "chrome/browser/speech/speech_recognition_service_factory.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h" #include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "chrome/browser/ui/webui/downloads/downloads_ui.h" #include "chrome/browser/ui/webui/downloads/downloads_ui.h"
#include "chrome/browser/ui/webui/realbox/realbox.mojom.h"
#include "components/search/ntp_features.h" #include "components/search/ntp_features.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#if !defined(OFFICIAL_BUILD) #if !defined(OFFICIAL_BUILD)
...@@ -635,6 +636,9 @@ void PopulateChromeWebUIFrameBinders( ...@@ -635,6 +636,9 @@ void PopulateChromeWebUIFrameBinders(
RegisterWebUIControllerInterfaceBinder< RegisterWebUIControllerInterfaceBinder<
promo_browser_command::mojom::CommandHandler, NewTabPageUI>(map); promo_browser_command::mojom::CommandHandler, NewTabPageUI>(map);
RegisterWebUIControllerInterfaceBinder<realbox::mojom::PageHandler,
NewTabPageUI>(map);
RegisterWebUIControllerInterfaceBinder< RegisterWebUIControllerInterfaceBinder<
customize_themes::mojom::CustomizeThemesHandlerFactory, NewTabPageUI customize_themes::mojom::CustomizeThemesHandlerFactory, NewTabPageUI
#if !BUILDFLAG(IS_CHROMEOS_ASH) #if !BUILDFLAG(IS_CHROMEOS_ASH)
......
...@@ -28,6 +28,7 @@ js_type_check("closure_compile") { ...@@ -28,6 +28,7 @@ js_type_check("closure_compile") {
":one_google_bar_api", ":one_google_bar_api",
":promo_browser_command_proxy", ":promo_browser_command_proxy",
":realbox", ":realbox",
":realbox_browser_proxy",
":realbox_dropdown", ":realbox_dropdown",
":realbox_icon", ":realbox_icon",
":realbox_match", ":realbox_match",
...@@ -46,6 +47,7 @@ js_library("new_tab_page") { ...@@ -46,6 +47,7 @@ js_library("new_tab_page") {
":background_manager", ":background_manager",
":browser_proxy", ":browser_proxy",
":promo_browser_command_proxy", ":promo_browser_command_proxy",
":realbox_browser_proxy",
":utils", ":utils",
"modules:module_descriptor", "modules:module_descriptor",
"modules:module_registry", "modules:module_registry",
...@@ -97,6 +99,13 @@ js_library("promo_browser_command_proxy") { ...@@ -97,6 +99,13 @@ js_library("promo_browser_command_proxy") {
] ]
} }
js_library("realbox_browser_proxy") {
deps = [
"//chrome/browser/ui/webui/realbox:mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:cr.m",
]
}
js_library("middle_slot_promo") { js_library("middle_slot_promo") {
deps = [ deps = [
":browser_proxy", ":browser_proxy",
...@@ -176,7 +185,7 @@ js_library("iframe") { ...@@ -176,7 +185,7 @@ js_library("iframe") {
js_library("realbox") { js_library("realbox") {
deps = [ deps = [
":browser_proxy", ":realbox_browser_proxy",
":realbox_icon", ":realbox_icon",
":utils", ":utils",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
...@@ -187,7 +196,7 @@ js_library("realbox") { ...@@ -187,7 +196,7 @@ js_library("realbox") {
js_library("realbox_dropdown") { js_library("realbox_dropdown") {
deps = [ deps = [
":browser_proxy", ":realbox_browser_proxy",
":realbox_match", ":realbox_match",
":utils", ":utils",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
...@@ -294,6 +303,7 @@ preprocess_if_expr("preprocess") { ...@@ -294,6 +303,7 @@ preprocess_if_expr("preprocess") {
"customize_dialog_types.js", "customize_dialog_types.js",
"new_tab_page.js", "new_tab_page.js",
"promo_browser_command_proxy.js", "promo_browser_command_proxy.js",
"realbox_browser_proxy.js",
"utils.js", "utils.js",
] ]
} }
...@@ -354,6 +364,15 @@ generate_grd("build_search_mojo_grdp") { ...@@ -354,6 +364,15 @@ generate_grd("build_search_mojo_grdp") {
rebase_path("$root_gen_dir/chrome/common/search", root_build_dir) rebase_path("$root_gen_dir/chrome/common/search", root_build_dir)
} }
generate_grd("build_realbox_mojo_grdp") {
grd_prefix = grd_prefix
out_grd = "$target_gen_dir/realbox_mojo_resources.grdp"
input_files = [ "realbox.mojom-lite.js" ]
input_files_base_dir =
rebase_path("$root_gen_dir/chrome/browser/ui/webui/realbox",
root_build_dir)
}
generate_grd("build_drive_mojo_grdp") { generate_grd("build_drive_mojo_grdp") {
grd_prefix = grd_prefix grd_prefix = grd_prefix
out_grd = "$target_gen_dir/drive_mojo_resources.grdp" out_grd = "$target_gen_dir/drive_mojo_resources.grdp"
...@@ -401,6 +420,7 @@ generate_grd("build_grd") { ...@@ -401,6 +420,7 @@ generate_grd("build_grd") {
"$target_gen_dir/icons/resources.grdp", "$target_gen_dir/icons/resources.grdp",
"$target_gen_dir/new_tab_page_mojo_resources.grdp", "$target_gen_dir/new_tab_page_mojo_resources.grdp",
"$target_gen_dir/promo_browser_command_mojo_resources.grdp", "$target_gen_dir/promo_browser_command_mojo_resources.grdp",
"$target_gen_dir/realbox_mojo_resources.grdp",
"$target_gen_dir/search_mojo_resources.grdp", "$target_gen_dir/search_mojo_resources.grdp",
"$target_gen_dir/task_module_mojo_resources.grdp", "$target_gen_dir/task_module_mojo_resources.grdp",
"$target_gen_dir/chrome_cart_mojo_resources.grdp", "$target_gen_dir/chrome_cart_mojo_resources.grdp",
...@@ -411,6 +431,7 @@ generate_grd("build_grd") { ...@@ -411,6 +431,7 @@ generate_grd("build_grd") {
":build_drive_mojo_grdp", ":build_drive_mojo_grdp",
":build_new_tab_page_mojo_grdp", ":build_new_tab_page_mojo_grdp",
":build_promo_browser_command_mojo_grdp", ":build_promo_browser_command_mojo_grdp",
":build_realbox_mojo_grdp",
":build_search_mojo_grdp", ":build_search_mojo_grdp",
":build_task_module_mojo_grdp", ":build_task_module_mojo_grdp",
"icons:build_grdp", "icons:build_grdp",
...@@ -450,6 +471,7 @@ grit("resources") { ...@@ -450,6 +471,7 @@ grit("resources") {
"//chrome/browser/search/drive:mojo_bindings_js", "//chrome/browser/search/drive:mojo_bindings_js",
"//chrome/browser/search/task_module:mojo_bindings_js", "//chrome/browser/search/task_module:mojo_bindings_js",
"//chrome/browser/ui/webui/new_tab_page:mojo_bindings_js", "//chrome/browser/ui/webui/new_tab_page:mojo_bindings_js",
"//chrome/browser/ui/webui/realbox:mojo_bindings_js",
"//chrome/common/search:mojo_bindings_js", "//chrome/common/search:mojo_bindings_js",
] ]
if (!is_official_build) { if (!is_official_build) {
...@@ -501,6 +523,7 @@ if (optimize_webui) { ...@@ -501,6 +523,7 @@ if (optimize_webui) {
"chrome://resources/mojo/url/mojom/url.mojom-lite.js", "chrome://resources/mojo/url/mojom/url.mojom-lite.js",
"new_tab_page.mojom-lite.js", "new_tab_page.mojom-lite.js",
"omnibox.mojom-lite.js", "omnibox.mojom-lite.js",
"realbox.mojom-lite.js",
"one_google_bar_api.js", "one_google_bar_api.js",
"promo_browser_command.mojom-lite.js", "promo_browser_command.mojom-lite.js",
"modules/drive/drive.mojom-lite.js", "modules/drive/drive.mojom-lite.js",
......
...@@ -11,6 +11,7 @@ import 'chrome://resources/mojo/skia/public/mojom/skcolor.mojom-lite.js'; ...@@ -11,6 +11,7 @@ import 'chrome://resources/mojo/skia/public/mojom/skcolor.mojom-lite.js';
import 'chrome://resources/mojo/url/mojom/url.mojom-lite.js'; import 'chrome://resources/mojo/url/mojom/url.mojom-lite.js';
import './omnibox.mojom-lite.js'; import './omnibox.mojom-lite.js';
import './realbox.mojom-lite.js';
import './new_tab_page.mojom-lite.js'; import './new_tab_page.mojom-lite.js';
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js'; import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
......
...@@ -29,4 +29,5 @@ export {ModuleRegistry} from './modules/module_registry.js'; ...@@ -29,4 +29,5 @@ export {ModuleRegistry} from './modules/module_registry.js';
export {recipeTasksDescriptor, shoppingTasksDescriptor} from './modules/task_module/module.js'; export {recipeTasksDescriptor, shoppingTasksDescriptor} from './modules/task_module/module.js';
export {TaskModuleHandlerProxy} from './modules/task_module/task_module_handler_proxy.js'; export {TaskModuleHandlerProxy} from './modules/task_module/task_module_handler_proxy.js';
export {PromoBrowserCommandProxy} from './promo_browser_command_proxy.js'; export {PromoBrowserCommandProxy} from './promo_browser_command_proxy.js';
export {RealboxBrowserProxy} from './realbox_browser_proxy.js';
export {$$, createScrollBorders, decodeString16, mojoString16} from './utils.js'; export {$$, createScrollBorders, decodeString16, mojoString16} from './utils.js';
...@@ -11,7 +11,7 @@ import {skColorToRgba} from 'chrome://resources/js/color_utils.js'; ...@@ -11,7 +11,7 @@ import {skColorToRgba} from 'chrome://resources/js/color_utils.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js'; import {RealboxBrowserProxy} from './realbox_browser_proxy.js';
import {decodeString16, mojoString16, mojoTimeDelta} from './utils.js'; import {decodeString16, mojoString16, mojoTimeDelta} from './utils.js';
/** @typedef {{text: string, inline: string,}} */ /** @typedef {{text: string, inline: string,}} */
...@@ -53,7 +53,7 @@ class RealboxElement extends PolymerElement { ...@@ -53,7 +53,7 @@ class RealboxElement extends PolymerElement {
}, },
/** /**
* @type {!newTabPage.mojom.SearchBoxTheme} * @type {!realbox.mojom.SearchBoxTheme}
*/ */
theme: { theme: {
type: Object, type: Object,
...@@ -197,10 +197,10 @@ class RealboxElement extends PolymerElement { ...@@ -197,10 +197,10 @@ class RealboxElement extends PolymerElement {
constructor() { constructor() {
performance.mark('realbox-creation-start'); performance.mark('realbox-creation-start');
super(); super();
/** @private {newTabPage.mojom.PageHandlerRemote} */ /** @private {realbox.mojom.PageHandlerRemote} */
this.pageHandler_ = BrowserProxy.getInstance().handler; this.pageHandler_ = RealboxBrowserProxy.getInstance().handler;
/** @private {!newTabPage.mojom.PageCallbackRouter} */ /** @private {!realbox.mojom.PageCallbackRouter} */
this.callbackRouter_ = BrowserProxy.getInstance().callbackRouter; this.callbackRouter_ = RealboxBrowserProxy.getInstance().callbackRouter;
/** @private {?number} */ /** @private {?number} */
this.autocompleteResultChangedListenerId_ = null; this.autocompleteResultChangedListenerId_ = null;
/** @private {?number} */ /** @private {?number} */
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import './realbox.mojom-lite.js';
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
/**
* @fileoverview This file provides a singleton class that exposes the Mojo
* handler interface used for bidirectional communication between the NTP
* realbox JS and the browser.
*/
export class RealboxBrowserProxy {
constructor() {
/** @type {!realbox.mojom.PageHandlerRemote} */
this.handler = realbox.mojom.PageHandler.getRemote();
/** @type {realbox.mojom.PageCallbackRouter} */
this.callbackRouter = new realbox.mojom.PageCallbackRouter();
this.handler.setPage(this.callbackRouter.$.bindNewPipeAndPassRemote());
}
}
addSingletonGetter(RealboxBrowserProxy);
...@@ -13,7 +13,7 @@ import {skColorToRgba} from 'chrome://resources/js/color_utils.js'; ...@@ -13,7 +13,7 @@ import {skColorToRgba} from 'chrome://resources/js/color_utils.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js'; import {RealboxBrowserProxy} from './realbox_browser_proxy.js';
import {decodeString16} from './utils.js'; import {decodeString16} from './utils.js';
// A dropdown element that contains autocomplete matches. Provides an API for // A dropdown element that contains autocomplete matches. Provides an API for
...@@ -51,7 +51,7 @@ class RealboxDropdownElement extends PolymerElement { ...@@ -51,7 +51,7 @@ class RealboxDropdownElement extends PolymerElement {
}, },
/** /**
* @type {!newTabPage.mojom.SearchBoxTheme} * @type {!realbox.mojom.SearchBoxTheme}
*/ */
theme: { theme: {
type: Object, type: Object,
...@@ -96,10 +96,10 @@ class RealboxDropdownElement extends PolymerElement { ...@@ -96,10 +96,10 @@ class RealboxDropdownElement extends PolymerElement {
constructor() { constructor() {
super(); super();
/** @private {!newTabPage.mojom.PageCallbackRouter} */ /** @private {!realbox.mojom.PageCallbackRouter} */
this.callbackRouter_ = BrowserProxy.getInstance().callbackRouter; this.callbackRouter_ = RealboxBrowserProxy.getInstance().callbackRouter;
/** @private {newTabPage.mojom.PageHandlerRemote} */ /** @private {realbox.mojom.PageHandlerRemote} */
this.pageHandler_ = BrowserProxy.getInstance().handler; this.pageHandler_ = RealboxBrowserProxy.getInstance().handler;
/** @private {?number} */ /** @private {?number} */
this.autocompleteMatchImageAvailableListenerId_ = null; this.autocompleteMatchImageAvailableListenerId_ = null;
} }
......
...@@ -380,6 +380,7 @@ static_library("ui") { ...@@ -380,6 +380,7 @@ static_library("ui") {
"//chrome/browser/ui/webui/new_tab_page:mojo_bindings", "//chrome/browser/ui/webui/new_tab_page:mojo_bindings",
"//chrome/browser/ui/webui/omnibox:mojo_bindings", "//chrome/browser/ui/webui/omnibox:mojo_bindings",
"//chrome/browser/ui/webui/read_later:mojo_bindings", "//chrome/browser/ui/webui/read_later:mojo_bindings",
"//chrome/browser/ui/webui/realbox:mojo_bindings",
"//chrome/browser/ui/webui/tab_search:mojo_bindings", "//chrome/browser/ui/webui/tab_search:mojo_bindings",
"//chrome/browser/ui/webui/usb_internals:mojo_bindings", "//chrome/browser/ui/webui/usb_internals:mojo_bindings",
"//chrome/browser/video_tutorials", "//chrome/browser/video_tutorials",
...@@ -1417,6 +1418,8 @@ static_library("ui") { ...@@ -1417,6 +1418,8 @@ static_library("ui") {
"webui/read_later/read_later_page_handler.h", "webui/read_later/read_later_page_handler.h",
"webui/read_later/read_later_ui.cc", "webui/read_later/read_later_ui.cc",
"webui/read_later/read_later_ui.h", "webui/read_later/read_later_ui.h",
"webui/realbox/realbox_handler.cc",
"webui/realbox/realbox_handler.h",
"webui/sanitized_image_source.cc", "webui/sanitized_image_source.cc",
"webui/sanitized_image_source.h", "webui/sanitized_image_source.h",
"webui/settings/about_handler.cc", "webui/settings/about_handler.cc",
......
...@@ -8,7 +8,7 @@ mojom("mojo_bindings") { ...@@ -8,7 +8,7 @@ mojom("mojo_bindings") {
sources = [ "new_tab_page.mojom" ] sources = [ "new_tab_page.mojom" ]
public_deps = [ public_deps = [
"//chrome/common/search:mojo_bindings", "//chrome/browser/ui/webui/realbox:mojo_bindings",
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
"//skia/public/mojom", "//skia/public/mojom",
"//url/mojom:url_mojom_gurl", "//url/mojom:url_mojom_gurl",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
module new_tab_page.mojom; module new_tab_page.mojom;
import "chrome/common/search/omnibox.mojom"; import "chrome/browser/ui/webui/realbox/realbox.mojom";
import "mojo/public/mojom/base/string16.mojom"; import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/text_direction.mojom"; import "mojo/public/mojom/base/text_direction.mojom";
import "mojo/public/mojom/base/time.mojom"; import "mojo/public/mojom/base/time.mojom";
...@@ -66,24 +66,6 @@ struct CollectionImage { ...@@ -66,24 +66,6 @@ struct CollectionImage {
url.mojom.Url preview_image_url; url.mojom.Url preview_image_url;
}; };
// Theme settings for the NTP realbox.
struct SearchBoxTheme {
skia.mojom.SkColor bg;
skia.mojom.SkColor icon;
skia.mojom.SkColor icon_selected;
skia.mojom.SkColor placeholder;
skia.mojom.SkColor results_bg;
skia.mojom.SkColor results_bg_hovered;
skia.mojom.SkColor results_bg_selected;
skia.mojom.SkColor results_dim;
skia.mojom.SkColor results_dim_selected;
skia.mojom.SkColor results_text;
skia.mojom.SkColor results_text_selected;
skia.mojom.SkColor results_url;
skia.mojom.SkColor results_url_selected;
skia.mojom.SkColor text;
};
// The background image URL and styling. // The background image URL and styling.
struct BackgroundImage { struct BackgroundImage {
// URL to the background image. Can point to untrusted content. // URL to the background image. Can point to untrusted content.
...@@ -126,7 +108,7 @@ struct Theme { ...@@ -126,7 +108,7 @@ struct Theme {
url.mojom.Url? background_image_attribution_url; url.mojom.Url? background_image_attribution_url;
// Theme settings for the NTP realbox. Matching those of the Omnibox. // Theme settings for the NTP realbox. Matching those of the Omnibox.
SearchBoxTheme search_box; realbox.mojom.SearchBoxTheme search_box;
}; };
// Specifies look of the doodle share button. // Specifies look of the doodle share button.
...@@ -407,40 +389,6 @@ interface PageHandler { ...@@ -407,40 +389,6 @@ interface PageHandler {
OnModulesRendered(double time); OnModulesRendered(double time);
// Logs that the <ntp-app> element's |ready| callback method was called. // Logs that the <ntp-app> element's |ready| callback method was called.
OnAppRendered(double time); OnAppRendered(double time);
// ======= REALBOX =======
// Queries autocomplete matches from the browser.
QueryAutocomplete(mojo_base.mojom.String16 input,
bool prevent_inline_autocomplete);
// Cancels the current autocomplete query. Clears the result set if
// |clear_result| is true.
StopAutocomplete(bool clear_result);
// Handles navigation to an autocomplete match (i.e. an item in the realbox's
// list of matches). Note: |url| is passed solely to verify that the browser
// and renderer are in sync; don't trust this content or use it for anything
// other than verification purposes (i.e. is the URL still the same?).
// TODO(crbug.com/1076604): replace |url| with an unguessable token.
// |mouse_button| indicates which mouse button was pressed on the match. See
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
OpenAutocompleteMatch(uint8 line,
url.mojom.Url url,
bool are_matches_showing,
mojo_base.mojom.TimeDelta time_elapsed_since_last_focus,
uint8 mouse_button,
bool alt_key,
bool ctrl_key,
bool meta_key,
bool shift_key);
// Deletes the AutocompleteMatch in the current results by |line| number if
// it is deletable.
DeleteAutocompleteMatch(uint8 line);
// Tells the browser to allow suggestions with the given suggestion group ID
// to appear in the results if they currently are not allowed to or to prevent
// them from appearing in the results if they are currently permitted to.
ToggleSuggestionGroupIdVisibility(int32 suggestion_group_id);
// Logs the time it took in milliseconds since the first character (in a
// series of characters) was typed until Autocomplete results were painted.
LogCharTypedToRepaintLatency(mojo_base.mojom.TimeDelta latency);
}; };
// WebUI-side handler for requests from the browser. // WebUI-side handler for requests from the browser.
...@@ -452,14 +400,4 @@ interface Page { ...@@ -452,14 +400,4 @@ interface Page {
SetTheme(Theme theme); SetTheme(Theme theme);
// Updates the module visibility. // Updates the module visibility.
SetModulesVisible(bool visible); SetModulesVisible(bool visible);
// ======= REALBOX =======
// Updates the NTP realbox with the autocomplete results.
AutocompleteResultChanged(search.mojom.AutocompleteResult result);
// Updates the NTP realbox popup with the image or favicon data URL for the
// given |match_index| and |url| where |url| is an AutocompleteMatch image_url
// or destination_url for an entity or a navigation suggestion respectively.
AutocompleteMatchImageAvailable(uint32 match_index,
url.mojom.Url url,
string data_url);
}; };
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/scoped_observation.h" #include "base/scoped_observation.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
#include "chrome/browser/search/background/ntp_background_service_observer.h" #include "chrome/browser/search/background/ntp_background_service_observer.h"
#include "chrome/browser/search/instant_service_observer.h" #include "chrome/browser/search/instant_service_observer.h"
#include "chrome/browser/search/one_google_bar/one_google_bar_service.h" #include "chrome/browser/search/one_google_bar/one_google_bar_service.h"
...@@ -24,8 +23,6 @@ ...@@ -24,8 +23,6 @@
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom.h" #include "chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom.h"
#include "chrome/common/search/instant_types.h" #include "chrome/common/search/instant_types.h"
#include "chrome/common/search/ntp_logging_events.h" #include "chrome/common/search/ntp_logging_events.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/favicon_cache.h"
#include "components/search_provider_logos/logo_common.h" #include "components/search_provider_logos/logo_common.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
...@@ -53,7 +50,6 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler, ...@@ -53,7 +50,6 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler,
public NtpBackgroundServiceObserver, public NtpBackgroundServiceObserver,
public OneGoogleBarServiceObserver, public OneGoogleBarServiceObserver,
public ui::SelectFileDialog::Listener, public ui::SelectFileDialog::Listener,
public AutocompleteController::Observer,
public PromoServiceObserver { public PromoServiceObserver {
public: public:
NewTabPageHandler(mojo::PendingReceiver<new_tab_page::mojom::PageHandler> NewTabPageHandler(mojo::PendingReceiver<new_tab_page::mojom::PageHandler>
...@@ -142,21 +138,6 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler, ...@@ -142,21 +138,6 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler,
double time) override; double time) override;
void OnModuleUsage(const std::string& module_id) override; void OnModuleUsage(const std::string& module_id) override;
void OnModulesRendered(double time) override; void OnModulesRendered(double time) override;
void QueryAutocomplete(const base::string16& input,
bool prevent_inline_autocomplete) override;
void StopAutocomplete(bool clear_result) override;
void OpenAutocompleteMatch(uint8_t line,
const GURL& url,
bool are_matches_showing,
base::TimeDelta time_elapsed_since_last_focus,
uint8_t mouse_button,
bool alt_key,
bool ctrl_key,
bool meta_key,
bool shift_key) override;
void DeleteAutocompleteMatch(uint8_t line) override;
void ToggleSuggestionGroupIdVisibility(int32_t suggestion_group_id) override;
void LogCharTypedToRepaintLatency(base::TimeDelta latency) override;
private: private:
// InstantServiceObserver: // InstantServiceObserver:
...@@ -183,22 +164,11 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler, ...@@ -183,22 +164,11 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler,
void* params) override; void* params) override;
void FileSelectionCanceled(void* params) override; void FileSelectionCanceled(void* params) override;
// AutocompleteController::Observer:
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override;
void OnLogoAvailable( void OnLogoAvailable(
GetDoodleCallback callback, GetDoodleCallback callback,
search_provider_logos::LogoCallbackReason type, search_provider_logos::LogoCallbackReason type,
const base::Optional<search_provider_logos::EncodedLogo>& logo); const base::Optional<search_provider_logos::EncodedLogo>& logo);
void OnRealboxBitmapFetched(int match_index,
const GURL& image_url,
const SkBitmap& bitmap);
void OnRealboxFaviconFetched(int match_index,
const GURL& page_url,
const gfx::Image& favicon);
void LogEvent(NTPLoggingEventType event); void LogEvent(NTPLoggingEventType event);
typedef base::OnceCallback<void(bool success, typedef base::OnceCallback<void(bool success,
...@@ -229,11 +199,6 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler, ...@@ -229,11 +199,6 @@ class NewTabPageHandler : public new_tab_page::mojom::PageHandler,
base::Optional<base::TimeTicks> one_google_bar_load_start_time_; base::Optional<base::TimeTicks> one_google_bar_load_start_time_;
Profile* profile_; Profile* profile_;
scoped_refptr<ui::SelectFileDialog> select_file_dialog_; scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
std::unique_ptr<AutocompleteController> autocomplete_controller_;
FaviconCache favicon_cache_;
BitmapFetcherService* bitmap_fetcher_service_;
std::vector<BitmapFetcherService::RequestId> bitmap_request_ids_;
base::TimeTicks time_user_first_modified_realbox_;
content::WebContents* web_contents_; content::WebContents* web_contents_;
base::Time ntp_navigation_start_time_; base::Time ntp_navigation_start_time_;
NTPUserDataLogger logger_; NTPUserDataLogger logger_;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page_handler.h" #include "chrome/browser/ui/webui/new_tab_page/new_tab_page_handler.h"
#include "chrome/browser/ui/webui/new_tab_page/promo_browser_command/promo_browser_command_handler.h" #include "chrome/browser/ui/webui/new_tab_page/promo_browser_command/promo_browser_command_handler.h"
#include "chrome/browser/ui/webui/new_tab_page/untrusted_source.h" #include "chrome/browser/ui/webui/new_tab_page/untrusted_source.h"
#include "chrome/browser/ui/webui/realbox/realbox_handler.h"
#include "chrome/browser/ui/webui/sanitized_image_source.h" #include "chrome/browser/ui/webui/sanitized_image_source.h"
#include "chrome/browser/ui/webui/theme_source.h" #include "chrome/browser/ui/webui/theme_source.h"
#include "chrome/browser/ui/webui/webui_util.h" #include "chrome/browser/ui/webui/webui_util.h"
...@@ -354,6 +355,12 @@ void NewTabPageUI::BindInterface( ...@@ -354,6 +355,12 @@ void NewTabPageUI::BindInterface(
page_factory_receiver_.Bind(std::move(pending_receiver)); page_factory_receiver_.Bind(std::move(pending_receiver));
} }
void NewTabPageUI::BindInterface(
mojo::PendingReceiver<realbox::mojom::PageHandler> pending_page_handler) {
realbox_handler_ = std::make_unique<RealboxHandler>(
std::move(pending_page_handler), profile_, web_contents_);
}
void NewTabPageUI::BindInterface( void NewTabPageUI::BindInterface(
mojo::PendingReceiver<promo_browser_command::mojom::CommandHandler> mojo::PendingReceiver<promo_browser_command::mojom::CommandHandler>
pending_page_handler) { pending_page_handler) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/ui/webui/new_tab_page/foo/foo.mojom.h" // nogncheck crbug.com/1125897 #include "chrome/browser/ui/webui/new_tab_page/foo/foo.mojom.h" // nogncheck crbug.com/1125897
#endif #endif
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom.h" #include "chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom.h"
#include "chrome/browser/ui/webui/realbox/realbox.mojom-forward.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
...@@ -37,6 +38,7 @@ class InstantService; ...@@ -37,6 +38,7 @@ class InstantService;
class NewTabPageHandler; class NewTabPageHandler;
class Profile; class Profile;
class PromoBrowserCommandHandler; class PromoBrowserCommandHandler;
class RealboxHandler;
class TaskModuleHandler; class TaskModuleHandler;
class CartHandler; class CartHandler;
class DriveHandler; class DriveHandler;
...@@ -59,6 +61,11 @@ class NewTabPageUI ...@@ -59,6 +61,11 @@ class NewTabPageUI
mojo::PendingReceiver<new_tab_page::mojom::PageHandlerFactory> mojo::PendingReceiver<new_tab_page::mojom::PageHandlerFactory>
pending_receiver); pending_receiver);
// Instantiates the implementor of the realbox::mojom::PageHandler mojo
// interface passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<realbox::mojom::PageHandler> pending_page_handler);
// Instantiates the implementor of the // Instantiates the implementor of the
// promo_browser_command::mojom::CommandHandler mojo interface passing the // promo_browser_command::mojom::CommandHandler mojo interface passing the
// pending receiver that will be internally bound. // pending receiver that will be internally bound.
...@@ -131,6 +138,7 @@ class NewTabPageUI ...@@ -131,6 +138,7 @@ class NewTabPageUI
mojo::Receiver<customize_themes::mojom::CustomizeThemesHandlerFactory> mojo::Receiver<customize_themes::mojom::CustomizeThemesHandlerFactory>
customize_themes_factory_receiver_; customize_themes_factory_receiver_;
std::unique_ptr<PromoBrowserCommandHandler> promo_browser_command_handler_; std::unique_ptr<PromoBrowserCommandHandler> promo_browser_command_handler_;
std::unique_ptr<RealboxHandler> realbox_handler_;
#if !defined(OFFICIAL_BUILD) #if !defined(OFFICIAL_BUILD)
std::unique_ptr<FooHandler> foo_handler_; std::unique_ptr<FooHandler> foo_handler_;
#endif #endif
......
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojo_bindings") {
sources = [ "realbox.mojom" ]
public_deps = [
"//chrome/common/search:mojo_bindings",
"//mojo/public/mojom/base",
"//skia/public/mojom",
"//url/mojom:url_mojom_gurl",
]
}
monorail {
component: "UI>Browser>Omnibox"
}
mahmadi@chromium.org
tommycli@chromium.org
file://components/omnibox/OWNERS
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
\ No newline at end of file
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module realbox.mojom;
import "chrome/common/search/omnibox.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/time.mojom";
import "skia/public/mojom/skcolor.mojom";
import "url/mojom/url.mojom";
// Theme settings for the NTP realbox.
struct SearchBoxTheme {
skia.mojom.SkColor bg;
skia.mojom.SkColor icon;
skia.mojom.SkColor icon_selected;
skia.mojom.SkColor placeholder;
skia.mojom.SkColor results_bg;
skia.mojom.SkColor results_bg_hovered;
skia.mojom.SkColor results_bg_selected;
skia.mojom.SkColor results_dim;
skia.mojom.SkColor results_dim_selected;
skia.mojom.SkColor results_text;
skia.mojom.SkColor results_text_selected;
skia.mojom.SkColor results_url;
skia.mojom.SkColor results_url_selected;
skia.mojom.SkColor text;
};
// Browser-side handler for requests from WebUI page.
interface PageHandler {
// The RealboxBrowserProxy singleton calls this when it's first initialized.
SetPage(pending_remote<Page> page);
// Queries autocomplete matches from the browser.
QueryAutocomplete(mojo_base.mojom.String16 input,
bool prevent_inline_autocomplete);
// Cancels the current autocomplete query. Clears the result set if
// |clear_result| is true.
StopAutocomplete(bool clear_result);
// Handles navigation to an autocomplete match (i.e. an item in the realbox's
// list of matches). Note: |url| is passed solely to verify that the browser
// and renderer are in sync; don't trust this content or use it for anything
// other than verification purposes (i.e. is the URL still the same?).
// TODO(crbug.com/1076604): replace |url| with an unguessable token.
// |mouse_button| indicates which mouse button was pressed on the match. See
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
OpenAutocompleteMatch(uint8 line,
url.mojom.Url url,
bool are_matches_showing,
mojo_base.mojom.TimeDelta time_elapsed_since_last_focus,
uint8 mouse_button,
bool alt_key,
bool ctrl_key,
bool meta_key,
bool shift_key);
// Deletes the AutocompleteMatch in the current results by |line| number if
// it is deletable.
DeleteAutocompleteMatch(uint8 line);
// Tells the browser to allow suggestions with the given suggestion group ID
// to appear in the results if they currently are not allowed to or to prevent
// them from appearing in the results if they are currently permitted to.
ToggleSuggestionGroupIdVisibility(int32 suggestion_group_id);
// Logs the time it took in milliseconds since the first character (in a
// series of characters) was typed until Autocomplete results were painted.
LogCharTypedToRepaintLatency(mojo_base.mojom.TimeDelta latency);
};
// WebUI-side handler for requests from the browser.
interface Page {
// Updates the NTP realbox with the autocomplete results.
AutocompleteResultChanged(search.mojom.AutocompleteResult result);
// Updates the NTP realbox popup with the image or favicon data URL for the
// given |match_index| and |url| where |url| is an AutocompleteMatch image_url
// or destination_url for an entity or a navigation suggestion respectively.
AutocompleteMatchImageAvailable(uint32 match_index,
url.mojom.Url url,
string data_url);
};
This diff is collapsed.
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_REALBOX_REALBOX_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_REALBOX_REALBOX_HANDLER_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
#include "chrome/browser/ui/webui/realbox/realbox.mojom.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/favicon_cache.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
class GURL;
class Profile;
namespace content {
class WebContents;
} // namespace content
namespace gfx {
class Image;
} // namespace gfx
// Handles bidirectional communication between NTP realbox JS and the browser.
class RealboxHandler : public realbox::mojom::PageHandler,
public AutocompleteController::Observer {
public:
RealboxHandler(
mojo::PendingReceiver<realbox::mojom::PageHandler> pending_page_handler,
Profile* profile,
content::WebContents* web_contents);
~RealboxHandler() override;
// realbox::mojom::PageHandler:
void SetPage(mojo::PendingRemote<realbox::mojom::Page> pending_page) override;
void QueryAutocomplete(const base::string16& input,
bool prevent_inline_autocomplete) override;
void StopAutocomplete(bool clear_result) override;
void OpenAutocompleteMatch(uint8_t line,
const GURL& url,
bool are_matches_showing,
base::TimeDelta time_elapsed_since_last_focus,
uint8_t mouse_button,
bool alt_key,
bool ctrl_key,
bool meta_key,
bool shift_key) override;
void DeleteAutocompleteMatch(uint8_t line) override;
void ToggleSuggestionGroupIdVisibility(int32_t suggestion_group_id) override;
void LogCharTypedToRepaintLatency(base::TimeDelta latency) override;
// AutocompleteController::Observer:
void OnResultChanged(AutocompleteController* controller,
bool default_match_changed) override;
void OnRealboxBitmapFetched(int match_index,
const GURL& image_url,
const SkBitmap& bitmap);
void OnRealboxFaviconFetched(int match_index,
const GURL& page_url,
const gfx::Image& favicon);
private:
Profile* profile_;
content::WebContents* web_contents_;
std::unique_ptr<AutocompleteController> autocomplete_controller_;
BitmapFetcherService* bitmap_fetcher_service_;
std::vector<BitmapFetcherService::RequestId> bitmap_request_ids_;
FaviconCache favicon_cache_;
base::TimeTicks time_user_first_modified_realbox_;
mojo::Remote<realbox::mojom::Page> page_;
mojo::Receiver<realbox::mojom::PageHandler> page_handler_;
base::WeakPtrFactory<RealboxHandler> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(RealboxHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_REALBOX_REALBOX_HANDLER_H_
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {BrowserProxy, decodeString16, mojoString16} from 'chrome://new-tab-page/new_tab_page.js'; import {decodeString16, mojoString16, RealboxBrowserProxy} from 'chrome://new-tab-page/new_tab_page.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {getDeepActiveElement} from 'chrome://resources/js/util.m.js'; import {getDeepActiveElement} from 'chrome://resources/js/util.m.js';
import {assertStyle, createTestProxy, createTheme} from 'chrome://test/new_tab_page/test_support.js'; import {assertStyle, createTheme} from 'chrome://test/new_tab_page/test_support.js';
import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js'; import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js';
import {eventToPromise} from 'chrome://test/test_util.m.js'; import {eventToPromise} from 'chrome://test/test_util.m.js';
...@@ -18,11 +18,11 @@ const CLASSES = { ...@@ -18,11 +18,11 @@ const CLASSES = {
}; };
/** /**
* Helps track realbox browser call arguments. The mocked browser proxy returned * Helps track realbox browser call arguments. A mocked page handler remote
* by |createTestProxy()| resolves the browser call promises with the arguments * resolves the browser call promises with the arguments as an array making the
* as an array making the tests prone to change if the arguments change. This * tests prone to change if the arguments change. This class extends the page
* class, however, resolves the browser call promises with named arguments. * handler remote, resolving the browser call promises with named arguments.
* @implements {newTabPage.mojom.PageHandlerRemote} * @implements {realbox.mojom.PageHandlerRemote}
* @extends {TestBrowserProxy} * @extends {TestBrowserProxy}
*/ */
class TestRealboxBrowserProxy extends TestBrowserProxy { class TestRealboxBrowserProxy extends TestBrowserProxy {
...@@ -80,6 +80,19 @@ class TestRealboxBrowserProxy extends TestBrowserProxy { ...@@ -80,6 +80,19 @@ class TestRealboxBrowserProxy extends TestBrowserProxy {
} }
} }
/**
* Creates a mock test proxy.
* @return {TestBrowserProxy}
*/
export function createTestProxy() {
const testProxy = TestBrowserProxy.fromClass(RealboxBrowserProxy);
testProxy.callbackRouter = new realbox.mojom.PageCallbackRouter();
testProxy.callbackRouterRemote =
testProxy.callbackRouter.$.bindNewPipeAndPassRemote();
testProxy.handler = new TestRealboxBrowserProxy();
return testProxy;
}
/** /**
* @param {string} name * @param {string} name
* @param {!ClipboardEvent} * @param {!ClipboardEvent}
...@@ -173,7 +186,7 @@ suite('NewTabPageRealboxTest', () => { ...@@ -173,7 +186,7 @@ suite('NewTabPageRealboxTest', () => {
let realbox; let realbox;
/** /**
* @implements {BrowserProxy} * @implements {RealboxBrowserProxy}
* @extends {TestBrowserProxy} * @extends {TestBrowserProxy}
*/ */
let testProxy; let testProxy;
...@@ -189,8 +202,7 @@ suite('NewTabPageRealboxTest', () => { ...@@ -189,8 +202,7 @@ suite('NewTabPageRealboxTest', () => {
PolymerTest.clearBody(); PolymerTest.clearBody();
testProxy = createTestProxy(); testProxy = createTestProxy();
testProxy.handler = new TestRealboxBrowserProxy(); RealboxBrowserProxy.instance_ = testProxy;
BrowserProxy.instance_ = testProxy;
realbox = document.createElement('ntp-realbox'); realbox = document.createElement('ntp-realbox');
document.body.appendChild(realbox); document.body.appendChild(realbox);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment