Commit 1f4a6497 authored by Jason Lin's avatar Jason Lin Committed by Commit Bot

Add skeleton for Crostini WebUI Installer

More specifically, this CL:
* Adds a mojom file to connect the web frontend part and c++ backend.
* Adds c++ classes implementing web ui controller and some mojom interfaces.
* Adds html and js files implementing the skeleton of the web page, including
  BrowserProxy, which connects the Renderer JS to the backend C++.
* Adds code to display the web page at chrome://crostini-installer if feature
  CrostiniWebUIInstaller is enabled
* Adds skeleton for browser test.

Bug: 929571
Change-Id: Ie9b0931862ec5e40bc21ea7683ffc873e4034f1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778884Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Auto-Submit: Jason Lin <lxj@google.com>
Commit-Queue: Jason Lin <lxj@google.com>
Cr-Commit-Position: refs/heads/master@{#695037}
parent ba82cef1
......@@ -449,6 +449,7 @@ source_set("chrome_content_browser_overlay_manifest") {
if (is_chromeos) {
deps += [
"//chrome/browser/ui/webui/chromeos/add_supervision:mojo_bindings",
"//chrome/browser/ui/webui/chromeos/crostini_installer:mojo_bindings",
"//chrome/browser/ui/webui/chromeos/machine_learning:mojo_bindings",
"//chromeos/services/cellular_setup/public/mojom",
"//chromeos/services/ime/public/mojom",
......
......@@ -47,6 +47,7 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision.mojom.h"
#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom.h"
#include "chrome/browser/ui/webui/chromeos/machine_learning/machine_learning_internals_page_handler.mojom.h"
#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
#include "chromeos/services/ime/public/mojom/input_engine.mojom.h"
......@@ -176,6 +177,7 @@ const service_manager::Manifest& GetChromeContentBrowserOverlayManifest() {
chrome::mojom::OfflinePageAutoFetcher,
chrome::mojom::PrerenderCanceler,
#if defined(OS_CHROMEOS)
chromeos::crostini_installer::mojom::PageHandlerFactory,
chromeos::ime::mojom::InputEngineManager,
chromeos::machine_learning::mojom::PageHandler,
chromeos::media_perception::mojom::MediaPerception,
......
......@@ -5377,6 +5377,7 @@ grit("resources") {
if (is_chromeos) {
deps += [
"//chrome/browser/ui/webui/chromeos/add_supervision:mojo_bindings_js",
"//chrome/browser/ui/webui/chromeos/crostini_installer:mojo_bindings_js",
"//chrome/browser/ui/webui/chromeos/machine_learning:mojo_bindings_js",
]
}
......
......@@ -399,6 +399,13 @@
<include name="IDR_URGENT_PASSWORD_EXPIRY_NOTIFICATION_JS" file="resources\chromeos\password_change\urgent_password_expiry_notification.js" type="chrome_html" />
<include name="IDR_CROSH_BUILTIN_MANIFEST" file="resources\chromeos\crosh_builtin\manifest.json" type="BINDATA" />
<include name="IDR_CROSTINI_INSTALLER_INDEX_HTML" file="resources\chromeos\crostini_installer\index.html" type="BINDATA" />
<include name="IDR_CROSTINI_INSTALLER_APP_HTML" file="resources\chromeos\crostini_installer\app.html" type="BINDATA" />
<include name="IDR_CROSTINI_INSTALLER_APP_JS" file="resources\chromeos\crostini_installer\app.js" type="BINDATA" />
<include name="IDR_CROSTINI_INSTALLER_BROWSER_PROXY_HTML" file="resources\chromeos\crostini_installer\browser_proxy.html" type="BINDATA" />
<include name="IDR_CROSTINI_INSTALLER_BROWSER_PROXY_JS" file="resources\chromeos\crostini_installer\browser_proxy.js" type="BINDATA" />
<include name="IDR_CROSTINI_INSTALLER_MOJO_HTML" file="${root_gen_dir}\chrome\browser\ui\webui\chromeos\crostini_installer\crostini_installer.mojom.html" use_base_dir="false" type="BINDATA" />
<include name="IDR_CROSTINI_INSTALLER_MOJO_LITE_JS" file="${root_gen_dir}\chrome\browser\ui\webui\chromeos\crostini_installer\crostini_installer.mojom-lite.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_CRYPTOHOME_HTML" file="resources\chromeos\cryptohome.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_CRYPTOHOME_JS" file="resources\chromeos\cryptohome.js" type="BINDATA" />
<!-- manifest file of Connectivity Diagnostics app -->
......
......@@ -65,6 +65,7 @@ group("closure_compile") {
"bluetooth_pairing_dialog:closure_compile",
"braille_ime:closure_compile",
"camera/src/js:closure_compile",
"crostini_installer:closure_compile",
"internet_config_dialog:closure_compile",
"internet_detail_dialog:closure_compile",
"login:closure_compile",
......
# Copyright 2019 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("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
deps = [
":app",
":browser_proxy",
]
}
js_library("app") {
deps = [
":browser_proxy",
]
}
js_library("browser_proxy") {
deps = [
"//chrome/browser/ui/webui/chromeos/crostini_installer:mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:cr",
]
}
file://chrome/browser/chromeos/guest_os/OWNERS
<link rel="import" href="chrome://crostini-installer/browser_proxy.html">
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html">
<dom-module id="crostini-installer-app">
<template>
<div>
Hello, Crostini Installer!!!
<cr-button on-click="onInstallButtonTap_">Install</cr-button>
</div>
</template>
<script src="chrome://crostini-installer/app.js"></script>
</dom-module>
// Copyright 2019 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.
Polymer({
is: 'crostini-installer-app',
/** @override */
attached: function() {
// TODO(lxj)
},
/** @override */
detached: function() {
// TODO(lxj)
},
/** @private */
onInstallButtonTap_: function() {
// TODO(lxj)
},
});
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.html">
<link rel="import" href="chrome://crostini-installer/crostini_installer.mojom.html">
<script src="browser_proxy.js"></script>
// Copyright 2019 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.
cr.define('crostini_installer', function() {
class BrowserProxy {
constructor() {
/** @type {chromeos.crostiniInstaller.mojom.PageCallbackRouter} */
this.callbackRouter =
new chromeos.crostiniInstaller.mojom.PageCallbackRouter();
/** @type {chromeos.crostiniInstaller.mojom.PageHandlerRemote} */
this.handler = new chromeos.crostiniInstaller.mojom.PageHandlerRemote();
const factory =
chromeos.crostiniInstaller.mojom.PageHandlerFactory.getRemote();
factory.createPageHandler(
this.callbackRouter.$.bindNewPipeAndPassRemote(),
this.handler.$.bindNewPipeAndPassReceiver());
}
}
cr.addSingletonGetter(BrowserProxy);
return {BrowserProxy: BrowserProxy};
});
<!doctype html>
<html dir="$i18n{textdirection}" lang="$i18n{language}">
<head>
<meta charset="utf8">
</head>
<body>
<crostini-installer-app></crostini-installer-app>
<link rel="import" href="chrome://crostini-installer/app.html">
</body>
</html>
......@@ -1646,6 +1646,10 @@ jumbo_split_static_library("ui") {
"webui/chromeos/cellular_setup/mobile_setup_ui.h",
"webui/chromeos/certificate_manager_dialog_ui.cc",
"webui/chromeos/certificate_manager_dialog_ui.h",
"webui/chromeos/crostini_installer/crostini_installer_page_handler.cc",
"webui/chromeos/crostini_installer/crostini_installer_page_handler.h",
"webui/chromeos/crostini_installer/crostini_installer_ui.cc",
"webui/chromeos/crostini_installer/crostini_installer_ui.h",
"webui/chromeos/cryptohome_ui.cc",
"webui/chromeos/cryptohome_ui.h",
"webui/chromeos/cryptohome_web_ui_handler.cc",
......@@ -1902,6 +1906,7 @@ jumbo_split_static_library("ui") {
"//chrome/browser/resources/chromeos:camera_resources",
"//chrome/browser/ui/webui/app_management:mojo_bindings",
"//chrome/browser/ui/webui/chromeos/add_supervision:mojo_bindings",
"//chrome/browser/ui/webui/chromeos/crostini_installer:mojo_bindings",
"//chrome/browser/ui/webui/chromeos/machine_learning:mojo_bindings",
"//chrome/services/file_util/public/cpp",
"//chromeos",
......
......@@ -163,6 +163,7 @@
#include "chrome/browser/ui/webui/chromeos/cellular_setup/cellular_setup_dialog.h"
#include "chrome/browser/ui/webui/chromeos/cellular_setup/mobile_setup_ui.h"
#include "chrome/browser/ui/webui/chromeos/certificate_manager_dialog_ui.h"
#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h"
#include "chrome/browser/ui/webui/chromeos/cryptohome_ui.h"
#include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
......@@ -540,6 +541,9 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<chromeos::cellular_setup::CellularSetupDialogUI>;
if (url.host_piece() == chrome::kChromeUICertificateManagerHost)
return &NewWebUI<chromeos::CertificateManagerDialogUI>;
if (chromeos::CrostiniInstallerUI::IsEnabled() &&
url.host_piece() == chrome::kChromeUICrostiniInstallerHost)
return &NewWebUI<chromeos::CrostiniInstallerUI>;
if (url.host_piece() == chrome::kChromeUICryptohomeHost)
return &NewWebUI<chromeos::CryptohomeUI>;
if (url.host_piece() == chrome::kChromeUIDriveInternalsHost)
......
# Copyright 2019 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 = [
"crostini_installer.mojom",
]
}
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
// Copyright 2019 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 chromeos.crostini_installer.mojom;
// Lives in the browser process. A renderer uses this to create a page handler
// for controlling Crostini installation.
interface PageHandlerFactory {
// Create a page handler to control Crostini installation.
CreatePageHandler(pending_remote<Page> page,
pending_receiver<PageHandler> handler);
};
// Lives in the browser process. A renderer use this to control Crostini
// installation.
interface PageHandler {};
// Lives in the renderer process. The browser uses this to sends installation
// updates to the web page in the render.
interface Page {};
// Copyright 2019 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/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h"
#include <utility>
#include "base/optional.h"
namespace chromeos {
CrostiniInstallerPageHandler::CrostiniInstallerPageHandler(
mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
pending_page_handler,
mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> pending_page)
: receiver_{this, std::move(pending_page_handler)},
page_{std::move(pending_page)} {}
CrostiniInstallerPageHandler::~CrostiniInstallerPageHandler() = default;
} // namespace chromeos
// Copyright 2019 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_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_
#include "base/macros.h"
#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
class CrostiniInstallerPageHandler
: public chromeos::crostini_installer::mojom::PageHandler {
public:
CrostiniInstallerPageHandler(
mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
pending_page_handler,
mojo::PendingRemote<chromeos::crostini_installer::mojom::Page>
pending_page);
~CrostiniInstallerPageHandler() override;
private:
mojo::Receiver<chromeos::crostini_installer::mojom::PageHandler> receiver_;
mojo::Remote<chromeos::crostini_installer::mojom::Page> page_;
DISALLOW_COPY_AND_ASSIGN(CrostiniInstallerPageHandler);
};
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_PAGE_HANDLER_H_
// Copyright 2019 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/ui/webui/chromeos/crostini_installer/crostini_installer_ui.h"
#include <utility>
#include "base/bind.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer_page_handler.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "chromeos/constants/chromeos_features.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/webui/mojo_web_ui_controller.h"
namespace chromeos {
bool CrostiniInstallerUI::IsEnabled() {
return base::FeatureList::IsEnabled(
chromeos::features::kCrostiniWebUIInstaller);
}
CrostiniInstallerUI::CrostiniInstallerUI(content::WebUI* web_ui)
: ui::MojoWebUIController{web_ui} {
// TODO(lxj): We might want to make sure there is only one instance of this
// class.
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUICrostiniInstallerHost);
source->AddResourcePath("app.html", IDR_CROSTINI_INSTALLER_APP_HTML);
source->AddResourcePath("app.js", IDR_CROSTINI_INSTALLER_APP_JS);
source->AddResourcePath("browser_proxy.html",
IDR_CROSTINI_INSTALLER_BROWSER_PROXY_HTML);
source->AddResourcePath("browser_proxy.js",
IDR_CROSTINI_INSTALLER_BROWSER_PROXY_JS);
source->AddResourcePath("crostini_installer.mojom.html",
IDR_CROSTINI_INSTALLER_MOJO_HTML);
source->AddResourcePath("crostini_installer.mojom-lite.js",
IDR_CROSTINI_INSTALLER_MOJO_LITE_JS);
source->SetDefaultResource(IDR_CROSTINI_INSTALLER_INDEX_HTML);
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
AddHandlerToRegistry(base::BindRepeating(
&CrostiniInstallerUI::BindPageHandlerFactory, base::Unretained(this)));
}
CrostiniInstallerUI::~CrostiniInstallerUI() = default;
void CrostiniInstallerUI::BindPageHandlerFactory(
mojo::PendingReceiver<
chromeos::crostini_installer::mojom::PageHandlerFactory>
pending_receiver) {
if (page_factory_receiver_.is_bound()) {
page_factory_receiver_.reset();
}
page_factory_receiver_.Bind(std::move(pending_receiver));
}
void CrostiniInstallerUI::CreatePageHandler(
mojo::PendingRemote<chromeos::crostini_installer::mojom::Page> pending_page,
mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
pending_page_handler) {
DCHECK(pending_page.is_valid());
page_handler_ = std::make_unique<CrostiniInstallerPageHandler>(
std::move(pending_page_handler), std::move(pending_page));
}
} // namespace chromeos
// Copyright 2019 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_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_
#include "base/macros.h"
#include "chrome/browser/ui/webui/chromeos/crostini_installer/crostini_installer.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/webui/mojo_web_ui_controller.h"
namespace chromeos {
class CrostiniInstallerPageHandler;
// The WebUI for chrome://crostini-installer
class CrostiniInstallerUI
: public ui::MojoWebUIController,
public chromeos::crostini_installer::mojom::PageHandlerFactory {
public:
static bool IsEnabled();
explicit CrostiniInstallerUI(content::WebUI* web_ui);
~CrostiniInstallerUI() override;
private:
void BindPageHandlerFactory(
mojo::PendingReceiver<
chromeos::crostini_installer::mojom::PageHandlerFactory>
pending_receiver);
// chromeos::crostini_installer::mojom::PageHandlerFactory:
void CreatePageHandler(
mojo::PendingRemote<chromeos::crostini_installer::mojom::Page>
pending_page,
mojo::PendingReceiver<chromeos::crostini_installer::mojom::PageHandler>
pending_page_handler) override;
std::unique_ptr<CrostiniInstallerPageHandler> page_handler_;
mojo::Receiver<chromeos::crostini_installer::mojom::PageHandlerFactory>
page_factory_receiver_{this};
DISALLOW_COPY_AND_ASSIGN(CrostiniInstallerUI);
};
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_CROSTINI_INSTALLER_CROSTINI_INSTALLER_UI_H_
......@@ -213,6 +213,7 @@ const char kChromeUICertificateManagerHost[] = "certificate-manager";
const char kChromeUIConfirmPasswordChangeHost[] = "confirm-password-change";
const char kChromeUIConfirmPasswordChangeUrl[] =
"chrome://confirm-password-change";
const char kChromeUICrostiniInstallerHost[] = "crostini-installer";
const char kChromeUICryptohomeHost[] = "cryptohome";
const char kChromeUIDeviceEmulatorHost[] = "device-emulator";
const char kChromeUIDiscoverURL[] = "chrome://oobe/discover";
......@@ -276,6 +277,7 @@ bool IsSystemWebUIHost(base::StringPiece host) {
kChromeUIBluetoothPairingHost,
kChromeUICellularSetupHost,
kChromeUICertificateManagerHost,
kChromeUICrostiniInstallerHost,
kChromeUICryptohomeHost,
kChromeUIDeviceEmulatorHost,
kChromeUIFirstRunHost,
......
......@@ -209,6 +209,7 @@ extern const char kChromeUICertificateManagerDialogURL[];
extern const char kChromeUICertificateManagerHost[];
extern const char kChromeUIConfirmPasswordChangeHost[];
extern const char kChromeUIConfirmPasswordChangeUrl[];
extern const char kChromeUICrostiniInstallerHost[];
extern const char kChromeUICryptohomeHost[];
extern const char kChromeUIDeviceEmulatorHost[];
extern const char kChromeUIDiscoverURL[];
......
......@@ -203,6 +203,7 @@ js2gtest("browser_tests_js_mojo_lite_webui") {
if (is_chromeos) {
sources += [
"chromeos/crostini_installer_browsertest.js",
"chromeos/machine_learning_internals_browsertest.js",
"multidevice_setup/multidevice_setup_browsertest.js",
]
......
// Copyright 2019 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.
/**
* @fileoverview Test suite for the Crostini Installer page.
*/
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
GEN('#include "chromeos/constants/chromeos_features.h"');
function CrostiniInstallerBrowserTest() {}
CrostiniInstallerBrowserTest.prototype = {
__proto__: PolymerTest.prototype,
browsePreload: 'chrome://crostini-installer',
featureList: {enabled: ['chromeos::features::kCrostiniWebUIInstaller']},
};
TEST_F('CrostiniInstallerBrowserTest', 'All', function() {
suite('<crostini-installer-app>', () => {
test('install', done => {
// TODO(lxj)
done();
});
});
mocha.run();
});
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