Commit 87b50670 authored by Andre Vincent's avatar Andre Vincent Committed by Chromium LUCI CQ

[ntp] Creates mojo interface for drive module

Returns string from the Drive Handler.

Fixed: 1161315
Change-Id: I4dbf393f8792cb5fc49d744cc3270086fa622f2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601258
Commit-Queue: Andre Vincent <andrevincent@google.com>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841207}
parent bf76dfd9
...@@ -2003,6 +2003,7 @@ static_library("browser") { ...@@ -2003,6 +2003,7 @@ static_library("browser") {
"//chrome/browser/resource_coordinator:tab_manager_features", "//chrome/browser/resource_coordinator:tab_manager_features",
"//chrome/browser/safe_browsing", "//chrome/browser/safe_browsing",
"//chrome/browser/safe_browsing:advanced_protection", "//chrome/browser/safe_browsing:advanced_protection",
"//chrome/browser/search/drive:mojo_bindings",
"//chrome/browser/search/task_module:mojo_bindings", "//chrome/browser/search/task_module:mojo_bindings",
"//chrome/browser/sharing:buildflags", "//chrome/browser/sharing:buildflags",
"//chrome/browser/sharing/proto", "//chrome/browser/sharing/proto",
...@@ -3881,6 +3882,8 @@ static_library("browser") { ...@@ -3881,6 +3882,8 @@ static_library("browser") {
"search/chrome_colors/chrome_colors_factory.h", "search/chrome_colors/chrome_colors_factory.h",
"search/chrome_colors/chrome_colors_service.cc", "search/chrome_colors/chrome_colors_service.cc",
"search/chrome_colors/chrome_colors_service.h", "search/chrome_colors/chrome_colors_service.h",
"search/drive/drive_handler.cc",
"search/drive/drive_handler.h",
"search/instant_service.cc", "search/instant_service.cc",
"search/instant_service.h", "search/instant_service.h",
"search/instant_service_factory.cc", "search/instant_service_factory.cc",
......
...@@ -108,6 +108,7 @@ ...@@ -108,6 +108,7 @@
#include "chrome/browser/payments/payment_credential_factory.h" #include "chrome/browser/payments/payment_credential_factory.h"
#include "chrome/browser/payments/payment_request_factory.h" #include "chrome/browser/payments/payment_request_factory.h"
#include "chrome/browser/promo_browser_command/promo_browser_command.mojom.h" #include "chrome/browser/promo_browser_command/promo_browser_command.mojom.h"
#include "chrome/browser/search/drive/drive.mojom.h"
#include "chrome/browser/search/task_module/task_module.mojom.h" #include "chrome/browser/search/task_module/task_module.mojom.h"
#include "chrome/browser/speech/speech_recognition_client_browser_interface.h" #include "chrome/browser/speech/speech_recognition_client_browser_interface.h"
#include "chrome/browser/speech/speech_recognition_client_browser_interface_factory.h" #include "chrome/browser/speech/speech_recognition_client_browser_interface_factory.h"
...@@ -661,6 +662,11 @@ void PopulateChromeWebUIFrameBinders( ...@@ -661,6 +662,11 @@ void PopulateChromeWebUIFrameBinders(
NewTabPageUI>(map); NewTabPageUI>(map);
} }
if (base::FeatureList::IsEnabled(ntp_features::kNtpDriveModule)) {
RegisterWebUIControllerInterfaceBinder<drive::mojom::DriveHandler,
NewTabPageUI>(map);
}
if (base::FeatureList::IsEnabled(ntp_features::kNtpRecipeTasksModule) || if (base::FeatureList::IsEnabled(ntp_features::kNtpRecipeTasksModule) ||
base::FeatureList::IsEnabled(ntp_features::kNtpShoppingTasksModule)) { base::FeatureList::IsEnabled(ntp_features::kNtpShoppingTasksModule)) {
RegisterWebUIControllerInterfaceBinder< RegisterWebUIControllerInterfaceBinder<
......
...@@ -363,6 +363,15 @@ generate_grd("build_search_mojo_grdp") { ...@@ -363,6 +363,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_drive_mojo_grdp") {
grd_prefix = grd_prefix
out_grd = "$target_gen_dir/drive_mojo_resources.grdp"
input_files = [ "drive.mojom-lite.js" ]
input_files_base_dir =
rebase_path("$root_gen_dir/chrome/browser/search/drive", root_build_dir)
resource_path_prefix = "modules/drive"
}
generate_grd("build_task_module_mojo_grdp") { generate_grd("build_task_module_mojo_grdp") {
grd_prefix = grd_prefix grd_prefix = grd_prefix
out_grd = "$target_gen_dir/task_module_mojo_resources.grdp" out_grd = "$target_gen_dir/task_module_mojo_resources.grdp"
...@@ -404,9 +413,11 @@ generate_grd("build_grd") { ...@@ -404,9 +413,11 @@ generate_grd("build_grd") {
"$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",
"$target_gen_dir/drive_mojo_resources.grdp",
] ]
deps = [ deps = [
":build_chrome_cart_mojo_grdp", ":build_chrome_cart_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_search_mojo_grdp", ":build_search_mojo_grdp",
...@@ -445,6 +456,7 @@ grit("resources") { ...@@ -445,6 +456,7 @@ grit("resources") {
":build_grd", ":build_grd",
"//chrome/browser/cart:mojo_bindings_js", "//chrome/browser/cart:mojo_bindings_js",
"//chrome/browser/promo_browser_command:mojo_bindings_js", "//chrome/browser/promo_browser_command: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/common/search:mojo_bindings_js", "//chrome/common/search:mojo_bindings_js",
...@@ -500,6 +512,7 @@ if (optimize_webui) { ...@@ -500,6 +512,7 @@ if (optimize_webui) {
"omnibox.mojom-lite.js", "omnibox.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/task_module/task_module.mojom-lite.js", "modules/task_module/task_module.mojom-lite.js",
"foo.mojom-lite.js", "foo.mojom-lite.js",
"modules/cart/chrome_cart.mojom-lite.js", "modules/cart/chrome_cart.mojom-lite.js",
......
...@@ -94,6 +94,7 @@ preprocess_if_expr("preprocess") { ...@@ -94,6 +94,7 @@ preprocess_if_expr("preprocess") {
"module_registry.js", "module_registry.js",
"task_module/task_module_handler_proxy.js", "task_module/task_module_handler_proxy.js",
"cart/chrome_cart_proxy.js", "cart/chrome_cart_proxy.js",
"drive/drive_module_proxy.js",
] ]
if (!is_official_build) { if (!is_official_build) {
in_files += [ "dummy/foo_proxy.js" ] in_files += [ "dummy/foo_proxy.js" ]
......
...@@ -7,11 +7,19 @@ import("//tools/polymer/html_to_js.gni") ...@@ -7,11 +7,19 @@ import("//tools/polymer/html_to_js.gni")
js_library("module") { js_library("module") {
deps = [ deps = [
":drive_module_proxy",
"..:module_descriptor", "..:module_descriptor",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
] ]
} }
js_library("drive_module_proxy") {
deps = [
"//chrome/browser/search/drive:mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:cr.m",
]
}
html_to_js("web_components") { html_to_js("web_components") {
js_files = [ "module.js" ] js_files = [ "module.js" ]
} }
// 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 './drive.mojom-lite.js';
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
/**
* @fileoverview This file provides a class that exposes the Mojo handler
* interface used for sending requests from NTP dummy module JS to the browser
* and receiving the browser response.
*/
export class DriveProxy {
constructor() {
/** @type {!drive.mojom.DriveHandlerRemote} */
this.handler = drive.mojom.DriveHandler.getRemote();
}
}
addSingletonGetter(DriveProxy);
...@@ -7,6 +7,7 @@ import '../module_header.js'; ...@@ -7,6 +7,7 @@ import '../module_header.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 {ModuleDescriptor} from '../module_descriptor.js'; import {ModuleDescriptor} from '../module_descriptor.js';
import {DriveProxy} from './drive_module_proxy.js';
/** /**
* @fileoverview The Drive module, which serves as an inside look in to * @fileoverview The Drive module, which serves as an inside look in to
...@@ -29,6 +30,8 @@ customElements.define(DriveModuleElement.is, DriveModuleElement); ...@@ -29,6 +30,8 @@ customElements.define(DriveModuleElement.is, DriveModuleElement);
* @return {!Promise<?DriveModuleElement>} * @return {!Promise<?DriveModuleElement>}
*/ */
async function createDriveElement() { async function createDriveElement() {
const {testString} = await DriveProxy.getInstance().handler.getTestString();
console.log(testString);
return new DriveModuleElement(); return new DriveModuleElement();
} }
......
...@@ -18,11 +18,12 @@ export {BackgroundSelectionType} from './customize_dialog_types.js'; ...@@ -18,11 +18,12 @@ export {BackgroundSelectionType} from './customize_dialog_types.js';
export {ImgElement} from './img.js'; export {ImgElement} from './img.js';
export {ChromeCartProxy} from './modules/cart/chrome_cart_proxy.js'; export {ChromeCartProxy} from './modules/cart/chrome_cart_proxy.js';
export {chromeCartDescriptor} from './modules/cart/module.js'; export {chromeCartDescriptor} from './modules/cart/module.js';
export {DriveProxy} from './modules/drive/drive_module_proxy.js';
export {driveDescriptor} from './modules/drive/module.js';
// <if expr="not is_official_build"> // <if expr="not is_official_build">
export {FooProxy} from './modules/dummy/foo_proxy.js'; export {FooProxy} from './modules/dummy/foo_proxy.js';
export {dummyDescriptor} from './modules/dummy/module.js'; export {dummyDescriptor} from './modules/dummy/module.js';
// </if> // </if>
export {driveDescriptor} from './modules/drive/module.js';
export {ModuleDescriptor} from './modules/module_descriptor.js'; export {ModuleDescriptor} from './modules/module_descriptor.js';
export {ModuleRegistry} from './modules/module_registry.js'; 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';
......
# 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 = [ "drive.mojom" ]
}
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
// 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 drive.mojom;
// TODO(crbug/1163760): Create struct to model Drive data response.
// Browser-side handler for requests from NTP Module UI.
interface DriveHandler {
// TODO(crbug/1163760): Replace GetTestString method with
// method to retrieve file info from recent drive files.
GetTestString() => (string test_string);
};
// 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.
#include "chrome/browser/search/drive/drive_handler.h"
#include "base/strings/string_number_conversions.h"
DriveHandler::DriveHandler(
mojo::PendingReceiver<drive::mojom::DriveHandler> handler)
: handler_(this, std::move(handler)) {}
DriveHandler::~DriveHandler() = default;
void DriveHandler::GetTestString(GetTestStringCallback callback) {
std::move(callback).Run("This is the return from the Drive Handler");
}
// 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_SEARCH_DRIVE_DRIVE_HANDLER_H_
#define CHROME_BROWSER_SEARCH_DRIVE_DRIVE_HANDLER_H_
#include "chrome/browser/search/drive/drive.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
// Handles requests of drive modules sent from JS.
class DriveHandler : public drive::mojom::DriveHandler {
public:
explicit DriveHandler(
mojo::PendingReceiver<drive::mojom::DriveHandler> handler);
~DriveHandler() override;
// drive::mojom::DriveHandler:
void GetTestString(GetTestStringCallback callback) override;
private:
mojo::Receiver<drive::mojom::DriveHandler> handler_;
};
#endif // CHROME_BROWSER_SEARCH_DRIVE_DRIVE_HANDLER_H_
...@@ -1536,6 +1536,7 @@ static_library("ui") { ...@@ -1536,6 +1536,7 @@ static_library("ui") {
"//chrome/browser/resource_coordinator:tab_metrics_event_proto", "//chrome/browser/resource_coordinator:tab_metrics_event_proto",
"//chrome/browser/resource_coordinator/tab_ranker", "//chrome/browser/resource_coordinator/tab_ranker",
"//chrome/browser/safe_browsing:advanced_protection", "//chrome/browser/safe_browsing:advanced_protection",
"//chrome/browser/search/drive:mojo_bindings",
"//chrome/browser/search/task_module:mojo_bindings", "//chrome/browser/search/task_module:mojo_bindings",
"//chrome/browser/ui/color:color_headers", "//chrome/browser/ui/color:color_headers",
"//chrome/browser/ui/color:mixers", "//chrome/browser/ui/color:mixers",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/buildflags.h" #include "chrome/browser/buildflags.h"
#include "chrome/browser/cart/cart_handler.h" #include "chrome/browser/cart/cart_handler.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/drive/drive_handler.h"
#include "chrome/browser/search/instant_service.h" #include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h" #include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search/task_module/task_module_handler.h" #include "chrome/browser/search/task_module/task_module_handler.h"
...@@ -357,6 +358,12 @@ void NewTabPageUI::BindInterface( ...@@ -357,6 +358,12 @@ void NewTabPageUI::BindInterface(
task_module_handler_ = std::make_unique<TaskModuleHandler>( task_module_handler_ = std::make_unique<TaskModuleHandler>(
std::move(pending_receiver), profile_); std::move(pending_receiver), profile_);
} }
void NewTabPageUI::BindInterface(
mojo::PendingReceiver<drive::mojom::DriveHandler> pending_receiver) {
drive_handler_ = std::make_unique<DriveHandler>(std::move(pending_receiver));
}
#if !defined(OFFICIAL_BUILD) #if !defined(OFFICIAL_BUILD)
void NewTabPageUI::BindInterface( void NewTabPageUI::BindInterface(
mojo::PendingReceiver<foo::mojom::FooHandler> pending_page_handler) { mojo::PendingReceiver<foo::mojom::FooHandler> pending_page_handler) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/cart/chrome_cart.mojom.h" #include "chrome/browser/cart/chrome_cart.mojom.h"
#include "chrome/browser/promo_browser_command/promo_browser_command.mojom-forward.h" #include "chrome/browser/promo_browser_command/promo_browser_command.mojom-forward.h"
#include "chrome/browser/search/drive/drive.mojom.h"
#include "chrome/browser/search/instant_service_observer.h" #include "chrome/browser/search/instant_service_observer.h"
#include "chrome/browser/search/task_module/task_module.mojom.h" #include "chrome/browser/search/task_module/task_module.mojom.h"
#if !defined(OFFICIAL_BUILD) #if !defined(OFFICIAL_BUILD)
...@@ -38,6 +39,7 @@ class Profile; ...@@ -38,6 +39,7 @@ class Profile;
class PromoBrowserCommandHandler; class PromoBrowserCommandHandler;
class TaskModuleHandler; class TaskModuleHandler;
class CartHandler; class CartHandler;
class DriveHandler;
class NewTabPageUI class NewTabPageUI
: public ui::MojoWebUIController, : public ui::MojoWebUIController,
...@@ -78,6 +80,11 @@ class NewTabPageUI ...@@ -78,6 +80,11 @@ class NewTabPageUI
mojo::PendingReceiver<task_module::mojom::TaskModuleHandler> mojo::PendingReceiver<task_module::mojom::TaskModuleHandler>
pending_receiver); pending_receiver);
// Instantiates the implementor of drive::mojom::DriveHandler mojo interface
// passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<drive::mojom::DriveHandler> pending_receiver);
#if !defined(OFFICIAL_BUILD) #if !defined(OFFICIAL_BUILD)
// Instantiates the implementor of the foo::mojom::FooHandler mojo interface // Instantiates the implementor of the foo::mojom::FooHandler mojo interface
// passing the pending receiver that will be internally bound. // passing the pending receiver that will be internally bound.
...@@ -137,6 +144,7 @@ class NewTabPageUI ...@@ -137,6 +144,7 @@ class NewTabPageUI
// Mojo implementations for modules: // Mojo implementations for modules:
std::unique_ptr<TaskModuleHandler> task_module_handler_; std::unique_ptr<TaskModuleHandler> task_module_handler_;
std::unique_ptr<DriveHandler> drive_handler_;
WEB_UI_CONTROLLER_TYPE_DECL(); WEB_UI_CONTROLLER_TYPE_DECL();
......
...@@ -2,12 +2,31 @@ ...@@ -2,12 +2,31 @@
// 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 {driveDescriptor} from 'chrome://new-tab-page/new_tab_page.js'; import {driveDescriptor, DriveProxy} from 'chrome://new-tab-page/new_tab_page.js';
import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js';
suite('NewTabPageModulesDriveModuleTest', () => { suite('NewTabPageModulesDriveModuleTest', () => {
/**
* @implements {DriveProxy}
* @extends {TestBrowserProxy}
*/
let testProxy;
setup(() => {
PolymerTest.clearBody();
testProxy = TestBrowserProxy.fromClass(DriveProxy);
testProxy.handler =
TestBrowserProxy.fromClass(drive.mojom.DriveHandlerRemote);
DriveProxy.instance_ = testProxy;
});
test('module appears on render', async () => { test('module appears on render', async () => {
testProxy.handler.setResultFor(
'getTestString', Promise.resolve({dataItem: 'test string'}));
await driveDescriptor.initialize(); await driveDescriptor.initialize();
const module = driveDescriptor.element; const module = driveDescriptor.element;
assertTrue(!!module); assertTrue(!!module);
await testProxy.handler.whenCalled('getTestString');
assertTrue(!!driveDescriptor.element);
}); });
}); });
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