Commit 0c010e46 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

Convert scanning UI to page

Make the scanning UI a page of the Print Management app. This allows the
page to share API setup and resource loading with the rest of the app.

The scanning page can be accessed by navigating to
chrome://print-management/scanning.html when the
print-job-management-app and scanning-ui feature flags are enabled.

Bug: 1059779
Test: browser_tests --gtest_filter=ScanningPageBrowserTest.All
Change-Id: I90c235bdc00d7c2599d790b819fa5ced19ad3711
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109819Reviewed-by: default avatarjimmy gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759548}
parent a3df8462
......@@ -193,7 +193,6 @@
#include "chromeos/components/multidevice/debug_webui/proximity_auth_ui.h"
#include "chromeos/components/multidevice/debug_webui/url_constants.h"
#include "chromeos/components/print_management/print_management_ui.h"
#include "chromeos/components/print_management/scanning_ui.h"
#include "chromeos/components/print_management/url_constants.h"
#include "chromeos/components/sample_system_web_app_ui/url_constants.h"
#include "chromeos/constants/chromeos_features.h"
......@@ -606,10 +605,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
chromeos::features::kPrintJobManagementApp) &&
url.host_piece() == chromeos::kChromeUIPrintManagementHost)
return &NewWebUI<chromeos::printing::printing_manager::PrintManagementUI>;
if (base::FeatureList::IsEnabled(chromeos::features::kScanningUI) &&
url.host_piece() == chromeos::kChromeUIScanningHost) {
return &NewWebUI<chromeos::ScanningUI>;
}
if (base::FeatureList::IsEnabled(chromeos::features::kMediaApp)) {
if (url.host_piece() == chromeos::kChromeUIMediaAppHost)
return &NewWebUI<chromeos::MediaAppUI>;
......
......@@ -360,7 +360,7 @@ js2gtest("browser_tests_js_mojo_lite_webui") {
"chromeos/crostini_upgrader_browsertest.js",
"chromeos/machine_learning_internals_browsertest.js",
"chromeos/print_management/print_management_browsertest.js",
"chromeos/print_management/scanning_ui_browsertest.js",
"chromeos/print_management/scanning_page_browsertest.js",
"multidevice_setup/multidevice_setup_browsertest.js",
]
deps += [ "//chromeos/services/machine_learning/public/cpp:test_support" ]
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
/**
* @fileoverview Test suite for chrome://scanning.
* @fileoverview Test suite for chrome://print-management scanning page.
*/
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
......@@ -13,13 +13,13 @@ GEN('#include "chromeos/constants/chromeos_features.h"');
* @constructor
* @extends {PolymerTest}
*/
function ScanningUIBrowserTest() {}
function ScanningPageBrowserTest() {}
ScanningUIBrowserTest.prototype = {
ScanningPageBrowserTest.prototype = {
__proto__: PolymerTest.prototype,
browsePreload: 'chrome://scanning/test_loader.html?module=chromeos/' +
'print_management/scanning_ui_test.js',
browsePreload: 'chrome://print-management/test_loader.html?module=chromeos/' +
'print_management/scanning_page_test.js',
extraLibraries: [
'//third_party/mocha/mocha.js',
......@@ -28,11 +28,12 @@ ScanningUIBrowserTest.prototype = {
featureList: {
enabled: [
'chromeos::features::kPrintJobManagementApp',
'chromeos::features::kScanningUI',
]
},
};
TEST_F('ScanningUIBrowserTest', 'All', function() {
TEST_F('ScanningPageBrowserTest', 'All', function() {
mocha.run();
});
......@@ -4,15 +4,15 @@
// TODO(jschettler): use es6 module for mojo binding (crbug/1004256).
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://scanning/scanning_ui.js';
import 'chrome://print-management/scanning_page.js';
suite('ScanningUITest', () => {
/** @type {?ScanningUIElement} */
suite('ScanningPageTest', () => {
/** @type {?ScanningPageElement} */
let page = null;
setup(function() {
PolymerTest.clearBody();
page = document.createElement('scanning-ui');
page = document.createElement('scanning-page');
document.body.appendChild(page);
});
......@@ -22,8 +22,8 @@ suite('ScanningUITest', () => {
});
test('MainPageLoaded', () => {
// TODO(jschettler): Remove this stub test once the UI has more capabilities
// to test.
assertEquals('Scanning UI', page.$$('#header').textContent);
// TODO(jschettler): Remove this stub test once the page has more
// capabilities to test.
assertEquals('Chrome OS Scanning', page.$$('#header').textContent);
});
});
......@@ -8,8 +8,6 @@ static_library("print_management") {
sources = [
"print_management_ui.cc",
"print_management_ui.h",
"scanning_ui.cc",
"scanning_ui.h",
"url_constants.cc",
"url_constants.h",
]
......
......@@ -4,9 +4,11 @@
#include "chromeos/components/print_management/print_management_ui.h"
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "chromeos/components/print_management/mojom/printing_manager.mojom.h"
#include "chromeos/components/print_management/url_constants.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/grit/chromeos_print_management_resources.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "content/public/browser/web_contents.h"
......@@ -65,6 +67,11 @@ PrintManagementUI::PrintManagementUI(
AddPrintManagementStrings(html_source.get());
if (base::FeatureList::IsEnabled(chromeos::features::kScanningUI)) {
html_source->AddResourcePath("scanning.html", IDR_SCANNING_HTML);
html_source->AddResourcePath("scanning_page.js", IDR_SCANNING_PAGE_JS);
}
content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
html_source.release());
}
......
......@@ -51,9 +51,9 @@ polymer_modulizer("print_job_entry") {
html_type = "v3-ready"
}
polymer_modulizer("scanning_ui") {
js_file = "scanning_ui.js"
html_file = "scanning_ui.html"
polymer_modulizer("scanning_page") {
js_file = "scanning_page.js"
html_file = "scanning_page.html"
html_type = "v3-ready"
}
......@@ -61,6 +61,6 @@ group("polymer3_elements") {
public_deps = [
":print_job_entry_module",
":print_management_module",
":scanning_ui_module",
":scanning_page_module",
]
}
......@@ -21,8 +21,8 @@
<include name="IDR_PRINT_MANAGEMENT_ICON" file="app_icon_192.png" type="BINDATA" compress="gzip" />
<include name="IDR_PRINTING_MANAGER_MOJO_LITE_JS" file="${root_gen_dir}/chromeos/components/print_management/mojom/printing_manager.mojom-lite.js" compress="gzip" use_base_dir="false" type="BINDATA" />
<include name="IDR_PRINT_MANAGEMENT_PWA_HTML" file="pwa.html" type="BINDATA" compress="gzip" />
<include name="IDR_SCANNING_UI_INDEX_HTML" file="scanning_ui_index.html" type="BINDATA" compress="gzip" />
<include name="IDR_SCANNING_UI_JS" file="${root_gen_dir}/chromeos/components/print_management/resources/scanning_ui.js" use_base_dir="false" compress="gzip" type="BINDATA"/>
<include name="IDR_SCANNING_HTML" file="scanning.html" type="BINDATA" compress="gzip" />
<include name="IDR_SCANNING_PAGE_JS" file="${root_gen_dir}/chromeos/components/print_management/resources/scanning_page.js" use_base_dir="false" compress="gzip" type="BINDATA"/>
</includes>
<structures>
......
......@@ -5,12 +5,12 @@
<html>
<head>
<meta charset="utf-8">
<title>Scanning UI</title>
<title>Scanning</title>
</head>
<body>
<scanning-ui></scanning-ui>
<scanning-page></scanning-page>
<script type="module" src="scanning_ui.js"></script>
<script type="module" src="scanning_page.js"></script>
<!-- Below mojo script required to run browser tests -->
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js">
</script>
......
......@@ -6,17 +6,17 @@ import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bun
/**
* @fileoverview
* 'scanning-ui' is used to interact with connected scanners.
* 'scanning-page' is used to interact with connected scanners.
*/
Polymer({
is: 'scanning-ui',
is: 'scanning-page',
_template: html`{__html_template__}`,
/** @override */
ready() {
// TODO(jschettler): Remove this once the app has more capabilities.
this.$$('#header').textContent = 'Scanning UI';
this.$$('#header').textContent = 'Chrome OS Scanning';
},
});
// 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.
#include "chromeos/components/print_management/scanning_ui.h"
#include "base/memory/ptr_util.h"
#include "chromeos/components/print_management/url_constants.h"
#include "chromeos/grit/chromeos_print_management_resources.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/resources/grit/webui_resources.h"
namespace chromeos {
ScanningUI::ScanningUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui) {
auto html_source =
base::WrapUnique(content::WebUIDataSource::Create(kChromeUIScanningHost));
html_source->OverrideContentSecurityPolicyScriptSrc(
"script-src chrome://resources chrome://test 'self';");
html_source->AddResourcePath("scanning_ui.js", IDR_SCANNING_UI_JS);
html_source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER);
html_source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER);
html_source->SetDefaultResource(IDR_SCANNING_UI_INDEX_HTML);
content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
html_source.release());
}
ScanningUI::~ScanningUI() = default;
} // namespace chromeos
// 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.
#include "ui/webui/mojo_web_ui_controller.h"
#ifndef CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_SCANNING_UI_H_
#define CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_SCANNING_UI_H_
namespace chromeos {
// The WebUI for chrome://scanning.
class ScanningUI : public ui::MojoWebUIController {
public:
explicit ScanningUI(content::WebUI* web_ui);
~ScanningUI() override;
ScanningUI(const ScanningUI&) = delete;
ScanningUI& operator=(const ScanningUI&) = delete;
};
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_SCANNING_UI_H_
......@@ -9,6 +9,4 @@ namespace chromeos {
const char kChromeUIPrintManagementHost[] = "print-management";
const char kChromeUIPrintManagementAppUrl[] = "chrome://print-management";
const char kChromeUIScanningHost[] = "scanning";
} // namespace chromeos
......@@ -10,8 +10,6 @@ namespace chromeos {
extern const char kChromeUIPrintManagementHost[];
extern const char kChromeUIPrintManagementAppUrl[];
extern const char kChromeUIScanningHost[];
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_URL_CONSTANTS_H_
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