Commit 6aa1455d authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

Create scanning web app

Scanning is no longer going to be a part of the print management app, so
remove its code from that app and create a new scanning web app. The
empty app can be opened from chrome://scanning and is hidden behind a
feature flag that is disabled by default.

A subsequent CL will convert the app to a system web app (SWA).

Bug: 1059779
Change-Id: I6d64886ea6e32be85cb265f03af173a0262fdc3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346922
Auto-Submit: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Reviewed-by: default avatarJimmy Gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798185}
parent 399e44a7
......@@ -2509,6 +2509,7 @@ static_library("ui") {
"//chromeos/components/print_management",
"//chromeos/components/proximity_auth",
"//chromeos/components/quick_answers",
"//chromeos/components/scanning",
"//chromeos/components/string_matching",
"//chromeos/components/tether",
"//chromeos/components/web_applications",
......
......@@ -201,6 +201,8 @@
#include "chromeos/components/multidevice/debug_webui/url_constants.h"
#include "chromeos/components/print_management/print_management_ui.h"
#include "chromeos/components/print_management/url_constants.h"
#include "chromeos/components/scanning/scanning_ui.h"
#include "chromeos/components/scanning/url_constants.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/services/multidevice_setup/multidevice_setup_service.h"
......@@ -644,6 +646,10 @@ 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::kChromeUIScanningAppHost) {
return &NewWebUI<chromeos::ScanningUI>;
}
if (base::FeatureList::IsEnabled(chromeos::features::kMediaApp)) {
if (url.host_piece() == chromeos::kChromeUIMediaAppHost)
return &NewWebUI<chromeos::MediaAppUI>;
......
......@@ -48,6 +48,7 @@ source_set("common") {
"//chromeos/components/help_app_ui",
"//chromeos/components/media_app_ui",
"//chromeos/components/print_management",
"//chromeos/components/scanning",
"//chromeos/constants",
"//chromeos/strings",
]
......
......@@ -175,6 +175,7 @@ template("chrome_extra_paks") {
"$root_gen_dir/chromeos/chromeos_media_app_resources.pak",
"$root_gen_dir/chromeos/chromeos_print_management_resources.pak",
"$root_gen_dir/chromeos/chromeos_resources.pak",
"$root_gen_dir/chromeos/chromeos_scanning_app_resources.pak",
"$root_gen_dir/third_party/ink/ink_resources.pak",
"$root_gen_dir/ui/file_manager/file_manager_resources.pak",
]
......@@ -192,6 +193,7 @@ template("chrome_extra_paks") {
"//chromeos/resources:media_app_bundle_resources",
"//chromeos/resources:media_app_resources",
"//chromeos/resources:print_management_resources",
"//chromeos/resources:scanning_app_resources",
"//third_party/ink:ink_resources",
"//ui/file_manager:resources",
]
......
......@@ -316,7 +316,7 @@ if (include_js_tests) {
"chromeos/crostini_upgrader_browsertest.js",
"chromeos/machine_learning_internals_browsertest.js",
"chromeos/print_management/print_management_browsertest.js",
"chromeos/print_management/scanning_page_browsertest.js",
"chromeos/scanning/scanning_app_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://print-management scanning page.
* @fileoverview Test suite for chrome://scanning.
*/
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
......@@ -15,13 +15,13 @@ GEN('#include "content/public/test/browser_test.h"');
* @constructor
* @extends {PolymerTest}
*/
function ScanningPageBrowserTest() {}
function ScanningAppBrowserTest() {}
ScanningPageBrowserTest.prototype = {
ScanningAppBrowserTest.prototype = {
__proto__: PolymerTest.prototype,
browsePreload: 'chrome://print-management/test_loader.html?module=chromeos/' +
'print_management/scanning_page_test.js',
browsePreload: 'chrome://scanning/test_loader.html?module=chromeos/' +
'scanning/scanning_app_test.js',
extraLibraries: [
'//third_party/mocha/mocha.js',
......@@ -30,12 +30,11 @@ ScanningPageBrowserTest.prototype = {
featureList: {
enabled: [
'chromeos::features::kPrintJobManagementApp',
'chromeos::features::kScanningUI',
]
},
};
TEST_F('ScanningPageBrowserTest', 'All', function() {
TEST_F('ScanningAppBrowserTest', 'All', function() {
mocha.run();
});
......@@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(jschettler): use es6 module for mojo binding (crbug/1004256).
// TODO(jschettler): Use es6 module for mojo binding (crbug/1004256).
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://print-management/scanning_page.js';
import 'chrome://scanning/scanning_app.js';
suite('ScanningPageTest', () => {
/** @type {?ScanningPageElement} */
suite('ScanningAppTest', () => {
/** @type {?ScanningAppElement} */
let page = null;
setup(function() {
PolymerTest.clearBody();
page = document.createElement('scanning-page');
page = document.createElement('scanning-app');
document.body.appendChild(page);
});
......
......@@ -48,6 +48,7 @@ group("closure_compile") {
"//chromeos/components/media_app_ui:closure_compile",
"//chromeos/components/multidevice/debug_webui/resources:closure_compile",
"//chromeos/components/print_management:closure_compile",
"//chromeos/components/scanning:closure_compile",
"//chromeos/components/system_apps:closure_compile",
]
......
# Primary OWNERS
baileyberro@chromium.org
jimmyxgong@chromium.org
jschettler@chromium.org
# Backup OWNERS
khorimoto@chromium.org
......
......@@ -4,12 +4,10 @@
#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/components/web_applications/manifest_request_filter.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/grit/chromeos_print_management_resources.h"
#include "chromeos/grit/chromeos_print_management_resources_map.h"
#include "chromeos/strings/grit/chromeos_strings.h"
......@@ -135,10 +133,6 @@ PrintManagementUI::PrintManagementUI(
IDR_PRINT_MANAGEMENT_MANIFEST,
IDS_PRINT_MANAGEMENT_APP_NAME);
if (base::FeatureList::IsEnabled(chromeos::features::kScanningUI)) {
html_source->AddResourcePath("scanning_page.js", IDR_SCANNING_PAGE_JS);
}
content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
html_source.release());
}
......
......@@ -73,6 +73,5 @@ html_to_js("web_components") {
"print_management_fonts_css.js",
"print_management.js",
"print_management_shared_css.js",
"scanning_page.js",
]
}
......@@ -24,7 +24,6 @@
<include name="IDR_PRINT_MANAGEMENT_ICON" file="printing_app_icon.svg" type="BINDATA"/>
<include name="IDR_PRINTING_MANAGER_MOJO_LITE_JS" file="${root_gen_dir}/chromeos/components/print_management/mojom/printing_manager.mojom-lite.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_PRINT_MANAGEMENT_PWA_HTML" file="pwa.html" type="BINDATA" />
<include name="IDR_SCANNING_PAGE_JS" file="${root_gen_dir}/chromeos/components/print_management/resources/scanning_page.js" use_base_dir="false" type="BINDATA"/>
</includes>
<structures>
......
# 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.
assert(is_chromeos, "Scanning App is Chrome OS only")
static_library("scanning") {
sources = [
"scanning_ui.cc",
"scanning_ui.h",
"url_constants.cc",
"url_constants.h",
]
deps = [
"//chromeos/constants",
"//chromeos/resources:scanning_app_resources",
"//content/public/browser",
"//ui/resources",
"//ui/webui",
]
}
group("closure_compile") {
deps = [ "resources:closure_compile_module" ]
}
include_rules = [
"-chrome",
"+chromeos/grit/chromeos_scanning_app_resources.h",
"+content/public/browser",
"+ui/resources",
"+ui/webui",
]
# Primary OWNERS
baileyberro@chromium.org
jimmyxgong@chromium.org
jschettler@chromium.org
# Backup OWNERS
khorimoto@chromium.org
zentaro@chromium.org
# 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("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")
import("//tools/polymer/html_to_js.gni")
js_type_check("closure_compile_module") {
is_polymer3 = true
deps = [ ":scanning_app" ]
}
js_library("scanning_app") {
deps = [
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
}
html_to_js("web_components") {
js_files = [ "scanning_app.js" ]
}
......@@ -8,9 +8,9 @@
<title>Scanning</title>
</head>
<body>
<scanning-page></scanning-page>
<scanning-app></scanning-app>
<script type="module" src="scanning_page.js"></script>
<script type="module" src="scanning_app.js"></script>
<!-- Below mojo script required to run browser tests -->
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js">
</script>
......
......@@ -6,10 +6,10 @@ import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bun
/**
* @fileoverview
* 'scanning-page' is used to interact with connected scanners.
* 'scanning-app' is used to interact with connected scanners.
*/
Polymer({
is: 'scanning-page',
is: 'scanning-app',
_template: html`{__html_template__}`,
......
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/chromeos_scanning_app_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="grit/chromeos_scanning_app_resources_map.cc"
type="resource_file_map_source" />
<output filename="grit/chromeos_scanning_app_resources_map.h"
type="resource_map_header" />
<output filename="chromeos_scanning_app_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<!-- Privileged app host contents. -->
<include name="IDR_SCANNING_APP_INDEX_HTML" file="index.html" type="BINDATA" compress="gzip" />
<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"/>
</includes>
</release>
</grit>
// 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/scanning/scanning_ui.h"
#include <string>
#include "base/containers/span.h"
#include "base/memory/ptr_util.h"
#include "chromeos/components/scanning/url_constants.h"
#include "chromeos/grit/chromeos_scanning_app_resources.h"
#include "chromeos/grit/chromeos_scanning_app_resources_map.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 "services/network/public/mojom/content_security_policy.mojom.h"
#include "ui/resources/grit/webui_resources.h"
namespace chromeos {
namespace {
constexpr char kGeneratedPath[] =
"@out_folder@/gen/chromeos/components/scanning/resources/";
// TODO(jschettler): Replace with webui::SetUpWebUIDataSource() once it no
// longer requires a dependency on //chrome/browser.
void SetUpWebUIDataSource(content::WebUIDataSource* source,
base::span<const GritResourceMap> resources,
const std::string& generated_path,
int default_resource) {
for (const auto& resource : resources) {
std::string path = resource.name;
if (path.rfind(generated_path, 0) == 0)
path = path.substr(generated_path.size());
source->AddResourcePath(path, resource.value);
}
source->SetDefaultResource(default_resource);
source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER);
source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER);
}
} // namespace
ScanningUI::ScanningUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui) {
auto html_source = base::WrapUnique(
content::WebUIDataSource::Create(kChromeUIScanningAppHost));
html_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources chrome://test 'self';");
html_source->DisableTrustedTypesCSP();
const auto resources = base::make_span(kChromeosScanningAppResources,
kChromeosScanningAppResourcesSize);
SetUpWebUIDataSource(html_source.get(), resources, kGeneratedPath,
IDR_SCANNING_APP_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.
#ifndef CHROMEOS_COMPONENTS_SCANNING_SCANNING_UI_H_
#define CHROMEOS_COMPONENTS_SCANNING_SCANNING_UI_H_
#include "ui/webui/mojo_web_ui_controller.h"
namespace content {
class WebUI;
} // namespace content
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_SCANNING_SCANNING_UI_H_
// 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/scanning/url_constants.h"
namespace chromeos {
const char kChromeUIScanningAppHost[] = "scanning";
const char kChromeUIScanningAppUrl[] = "chrome://scanning";
} // 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.
#ifndef CHROMEOS_COMPONENTS_SCANNING_URL_CONSTANTS_H_
#define CHROMEOS_COMPONENTS_SCANNING_URL_CONSTANTS_H_
namespace chromeos {
extern const char kChromeUIScanningAppHost[];
extern const char kChromeUIScanningAppUrl[];
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_SCANNING_URL_CONSTANTS_H_
......@@ -206,3 +206,23 @@ grit("print_management_resources") {
output_dir = "$root_gen_dir/chromeos"
}
grit("scanning_app_resources") {
source = "../components/scanning/resources/scanning_app_resources.grd"
deps = [ "../components/scanning/resources:web_components" ]
outputs = [
"chromeos_scanning_app_resources.pak",
"grit/chromeos_scanning_app_resources.h",
"grit/chromeos_scanning_app_resources_map.cc",
"grit/chromeos_scanning_app_resources_map.h",
]
grit_flags = [
"-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
]
output_dir = "$root_gen_dir/chromeos"
}
......@@ -353,6 +353,9 @@
"chromeos/components/sample_system_web_app_ui/resources/sample_system_web_app_resources.grd": {
"includes": [2640],
},
"chromeos/components/scanning/resources/scanning_app_resources.grd": {
"includes": [2645],
},
"chromeos/components/telemetry_extension_ui/resources/telemetry_extension_resources.grd": {
"includes": [2650],
},
......
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