Commit 94f715a1 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

scanning: Add ScanService mojom js bindings to UI

Hook up the Mojo interface provider to the scanning UI and generate
js-lite bindings from scanning.mojom.

A subsequent CL (http://crrev/c/2378138) uses the ScanService Mojo
interface to get the connected scanners and add them to a dropdown in
the UI.

Bug: 1059779
Change-Id: I4270721ac585d668ee1ad5405695590ba78e7711
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2368238Reviewed-by: default avatarJimmy Gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803479}
parent 1f2bdb35
...@@ -175,6 +175,8 @@ ...@@ -175,6 +175,8 @@
#include "chromeos/components/multidevice/debug_webui/proximity_auth_ui.h" #include "chromeos/components/multidevice/debug_webui/proximity_auth_ui.h"
#include "chromeos/components/print_management/mojom/printing_manager.mojom.h" #include "chromeos/components/print_management/mojom/printing_manager.mojom.h"
#include "chromeos/components/print_management/print_management_ui.h" #include "chromeos/components/print_management/print_management_ui.h"
#include "chromeos/components/scanning/mojom/scanning.mojom.h"
#include "chromeos/components/scanning/scanning_ui.h"
#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h" #include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
#include "chromeos/services/multidevice_setup/multidevice_setup_service.h" #include "chromeos/services/multidevice_setup/multidevice_setup_service.h"
#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h" #include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
...@@ -639,6 +641,9 @@ void PopulateChromeWebUIFrameBinders( ...@@ -639,6 +641,9 @@ void PopulateChromeWebUIFrameBinders(
RegisterWebUIControllerInterfaceBinder< RegisterWebUIControllerInterfaceBinder<
chromeos::network_diagnostics::mojom::NetworkDiagnosticsRoutines, chromeos::network_diagnostics::mojom::NetworkDiagnosticsRoutines,
chromeos::NetworkUI>(map); chromeos::NetworkUI>(map);
RegisterWebUIControllerInterfaceBinder<chromeos::scanning::mojom::ScanService,
chromeos::ScanningUI>(map);
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) && !defined(OFFICIAL_BUILD) #if defined(OS_CHROMEOS) && !defined(OFFICIAL_BUILD)
......
...@@ -161,6 +161,8 @@ ...@@ -161,6 +161,8 @@
#include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_service_factory.h" #include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_service_factory.h"
#include "chrome/browser/chromeos/printing/print_management/printing_manager.h" #include "chrome/browser/chromeos/printing/print_management/printing_manager.h"
#include "chrome/browser/chromeos/printing/print_management/printing_manager_factory.h" #include "chrome/browser/chromeos/printing/print_management/printing_manager_factory.h"
#include "chrome/browser/chromeos/scanning/scan_service.h"
#include "chrome/browser/chromeos/scanning/scan_service_factory.h"
#include "chrome/browser/chromeos/secure_channel/secure_channel_client_provider.h" #include "chrome/browser/chromeos/secure_channel/secure_channel_client_provider.h"
#include "chrome/browser/chromeos/web_applications/chrome_camera_app_ui_delegate.h" #include "chrome/browser/chromeos/web_applications/chrome_camera_app_ui_delegate.h"
#include "chrome/browser/chromeos/web_applications/chrome_help_app_ui_delegate.h" #include "chrome/browser/chromeos/web_applications/chrome_help_app_ui_delegate.h"
...@@ -364,6 +366,24 @@ NewWebUI<chromeos::printing::printing_manager::PrintManagementUI>( ...@@ -364,6 +366,24 @@ NewWebUI<chromeos::printing::printing_manager::PrintManagementUI>(
base::BindRepeating(&BindPrintManagement, Profile::FromWebUI(web_ui))); base::BindRepeating(&BindPrintManagement, Profile::FromWebUI(web_ui)));
} }
void BindScanService(
Profile* profile,
mojo::PendingReceiver<chromeos::scanning::mojom::ScanService>
pending_receiver) {
chromeos::ScanService* service =
chromeos::ScanServiceFactory::GetForBrowserContext(profile);
if (service)
service->BindInterface(std::move(pending_receiver));
}
template <>
WebUIController* NewWebUI<chromeos::ScanningUI>(WebUI* web_ui,
const GURL& url) {
return new chromeos::ScanningUI(
web_ui,
base::BindRepeating(&BindScanService, Profile::FromWebUI(web_ui)));
}
void BindMultiDeviceSetup( void BindMultiDeviceSetup(
Profile* profile, Profile* profile,
mojo::PendingReceiver<chromeos::multidevice_setup::mojom::MultiDeviceSetup> mojo::PendingReceiver<chromeos::multidevice_setup::mojom::MultiDeviceSetup>
......
...@@ -13,6 +13,7 @@ static_library("scanning") { ...@@ -13,6 +13,7 @@ static_library("scanning") {
] ]
deps = [ deps = [
"//chromeos/components/scanning/mojom",
"//chromeos/constants", "//chromeos/constants",
"//chromeos/resources:scanning_app_resources", "//chromeos/resources:scanning_app_resources",
"//content/public/browser", "//content/public/browser",
......
...@@ -9,15 +9,26 @@ import("//tools/polymer/html_to_js.gni") ...@@ -9,15 +9,26 @@ import("//tools/polymer/html_to_js.gni")
js_type_check("closure_compile_module") { js_type_check("closure_compile_module") {
is_polymer3 = true is_polymer3 = true
deps = [ ":scanning_app" ] deps = [
":mojo_interface_provider",
":scanning_app",
]
} }
js_library("scanning_app") { js_library("scanning_app") {
deps = [ deps = [
":mojo_interface_provider",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
] ]
} }
js_library("mojo_interface_provider") {
deps = [
"//chromeos/components/scanning/mojom:mojom_js_library_for_compile",
"//ui/webui/resources/js:cr.m",
]
}
html_to_js("web_components") { html_to_js("web_components") {
js_files = [ "scanning_app.js" ] js_files = [ "scanning_app.js" ]
} }
// 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 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://resources/mojo/mojo/public/mojom/base/big_buffer.mojom-lite.js';
import 'chrome://resources/mojo/mojo/public/mojom/base/string16.mojom-lite.js';
import 'chrome://resources/mojo/mojo/public/mojom/base/unguessable_token.mojom-lite.js';
import './scanning.mojom-lite.js';
/** @type {?chromeos.scanning.mojom.ScanServiceInterface} */
let scanService = null;
/** @param {!chromeos.scanning.mojom.ScanServiceInterface} testScanService */
export function setScanServiceForTesting(testScanService) {
scanService = testScanService;
}
/** @return {!chromeos.scanning.mojom.ScanServiceInterface} */
export function getScanService() {
if (scanService) {
return scanService;
}
scanService = chromeos.scanning.mojom.ScanService.getRemote();
return scanService;
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {getScanService} from './mojo_interface_provider.js';
/** /**
* @fileoverview * @fileoverview
...@@ -13,10 +14,17 @@ Polymer({ ...@@ -13,10 +14,17 @@ Polymer({
_template: html`{__html_template__}`, _template: html`{__html_template__}`,
/** @private {?chromeos.scanning.mojom.ScanServiceInterface} */
scanService_: null,
/** @override */
created() {
this.scanService_ = getScanService();
},
/** @override */ /** @override */
ready() { ready() {
// TODO(jschettler): Remove this once the app has more capabilities. // TODO(jschettler): Remove this once the app has more capabilities.
this.$$('#header').textContent = 'Chrome OS Scanning'; this.$$('#header').textContent = 'Chrome OS Scanning';
}, },
}); });
...@@ -14,8 +14,13 @@ ...@@ -14,8 +14,13 @@
<includes> <includes>
<!-- Privileged app host contents. --> <!-- Privileged app host contents. -->
<include name="IDR_SCANNING_APP_INDEX_HTML" file="index.html" type="BINDATA" compress="gzip" /> <include name="IDR_SCANNING_APP_INDEX_HTML" file="index.html" type="BINDATA" compress="gzip" />
<include name="IDR_SCANNING_MOJO_LITE_JS" file="${root_gen_dir}/chromeos/components/scanning/mojom/scanning.mojom-lite.js" compress="gzip" use_base_dir="false" type="BINDATA" />
<include name="IDR_SCANNING_APP_JS" file="${root_gen_dir}/chromeos/components/scanning/resources/scanning_app.js" use_base_dir="false" compress="gzip" type="BINDATA"/> <include name="IDR_SCANNING_APP_JS" file="${root_gen_dir}/chromeos/components/scanning/resources/scanning_app.js" use_base_dir="false" compress="gzip" type="BINDATA"/>
<include name="IDR_SCANNING_APP_ICON" file="app_icon_192.png" type="BINDATA" /> <include name="IDR_SCANNING_APP_ICON" file="app_icon_192.png" type="BINDATA" />
</includes> </includes>
<structures>
<structure name="IDR_SCANNING_APP_MOJO_INTERFACE_PROVIDER_JS" file="mojo_interface_provider.js" type="chrome_html" />
</structures>
</release> </release>
</grit> </grit>
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/containers/span.h" #include "base/containers/span.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chromeos/components/scanning/mojom/scanning.mojom.h"
#include "chromeos/components/scanning/url_constants.h" #include "chromeos/components/scanning/url_constants.h"
#include "chromeos/grit/chromeos_scanning_app_resources.h" #include "chromeos/grit/chromeos_scanning_app_resources.h"
#include "chromeos/grit/chromeos_scanning_app_resources_map.h" #include "chromeos/grit/chromeos_scanning_app_resources_map.h"
...@@ -45,8 +46,9 @@ void SetUpWebUIDataSource(content::WebUIDataSource* source, ...@@ -45,8 +46,9 @@ void SetUpWebUIDataSource(content::WebUIDataSource* source,
} // namespace } // namespace
ScanningUI::ScanningUI(content::WebUI* web_ui) ScanningUI::ScanningUI(content::WebUI* web_ui, BindScanServiceCallback callback)
: ui::MojoWebUIController(web_ui) { : ui::MojoWebUIController(web_ui),
bind_pending_receiver_callback_(std::move(callback)) {
auto html_source = base::WrapUnique( auto html_source = base::WrapUnique(
content::WebUIDataSource::Create(kChromeUIScanningAppHost)); content::WebUIDataSource::Create(kChromeUIScanningAppHost));
html_source->OverrideContentSecurityPolicy( html_source->OverrideContentSecurityPolicy(
...@@ -59,10 +61,20 @@ ScanningUI::ScanningUI(content::WebUI* web_ui) ...@@ -59,10 +61,20 @@ ScanningUI::ScanningUI(content::WebUI* web_ui)
SetUpWebUIDataSource(html_source.get(), resources, kGeneratedPath, SetUpWebUIDataSource(html_source.get(), resources, kGeneratedPath,
IDR_SCANNING_APP_INDEX_HTML); IDR_SCANNING_APP_INDEX_HTML);
html_source->AddResourcePath("scanning.mojom-lite.js",
IDR_SCANNING_MOJO_LITE_JS);
content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
html_source.release()); html_source.release());
} }
ScanningUI::~ScanningUI() = default; ScanningUI::~ScanningUI() = default;
void ScanningUI::BindInterface(
mojo::PendingReceiver<scanning::mojom::ScanService> pending_receiver) {
bind_pending_receiver_callback_.Run(std::move(pending_receiver));
}
WEB_UI_CONTROLLER_TYPE_IMPL(ScanningUI)
} // namespace chromeos } // namespace chromeos
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef CHROMEOS_COMPONENTS_SCANNING_SCANNING_UI_H_ #ifndef CHROMEOS_COMPONENTS_SCANNING_SCANNING_UI_H_
#define CHROMEOS_COMPONENTS_SCANNING_SCANNING_UI_H_ #define CHROMEOS_COMPONENTS_SCANNING_SCANNING_UI_H_
#include "base/callback.h"
#include "chromeos/components/scanning/mojom/scanning.mojom-forward.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/webui/mojo_web_ui_controller.h" #include "ui/webui/mojo_web_ui_controller.h"
namespace content { namespace content {
...@@ -16,11 +19,27 @@ namespace chromeos { ...@@ -16,11 +19,27 @@ namespace chromeos {
// The WebUI for chrome://scanning. // The WebUI for chrome://scanning.
class ScanningUI : public ui::MojoWebUIController { class ScanningUI : public ui::MojoWebUIController {
public: public:
explicit ScanningUI(content::WebUI* web_ui); using BindScanServiceCallback = base::RepeatingCallback<void(
mojo::PendingReceiver<scanning::mojom::ScanService>)>;
// |callback| should bind the pending receiver to an implementation of
// chromeos::scanning::mojom::ScanService.
ScanningUI(content::WebUI* web_ui, BindScanServiceCallback callback);
~ScanningUI() override; ~ScanningUI() override;
ScanningUI(const ScanningUI&) = delete; ScanningUI(const ScanningUI&) = delete;
ScanningUI& operator=(const ScanningUI&) = delete; ScanningUI& operator=(const ScanningUI&) = delete;
// Instantiates the implementor of the chromeos::scanning::mojom::ScanService
// Mojo interface by passing the pending receiver that will be internally
// bound.
void BindInterface(
mojo::PendingReceiver<scanning::mojom::ScanService> pending_receiver);
private:
const BindScanServiceCallback bind_pending_receiver_callback_;
WEB_UI_CONTROLLER_TYPE_DECL();
}; };
} // namespace chromeos } // namespace chromeos
......
...@@ -210,7 +210,10 @@ grit("print_management_resources") { ...@@ -210,7 +210,10 @@ grit("print_management_resources") {
grit("scanning_app_resources") { grit("scanning_app_resources") {
source = "../components/scanning/resources/scanning_app_resources.grd" source = "../components/scanning/resources/scanning_app_resources.grd"
deps = [ "../components/scanning/resources:web_components" ] deps = [
"../components/scanning/mojom:mojom_js",
"../components/scanning/resources:web_components",
]
outputs = [ outputs = [
"chromeos_scanning_app_resources.pak", "chromeos_scanning_app_resources.pak",
......
...@@ -368,9 +368,10 @@ ...@@ -368,9 +368,10 @@
}, },
"chromeos/components/scanning/resources/scanning_app_resources.grd": { "chromeos/components/scanning/resources/scanning_app_resources.grd": {
"includes": [2645], "includes": [2645],
"structures": [2650],
}, },
"chromeos/components/telemetry_extension_ui/resources/telemetry_extension_resources.grd": { "chromeos/components/telemetry_extension_ui/resources/telemetry_extension_resources.grd": {
"includes": [2650], "includes": [2655],
}, },
"chromeos/resources/chromeos_resources.grd": { "chromeos/resources/chromeos_resources.grd": {
"includes": [2660], "includes": [2660],
......
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