Skip to content

Commit

Permalink
PrintJobManagement: Add skeleton code for new PrintJobManagement web app
Browse files Browse the repository at this point in the history
- This CL includes only the skeleton code to open an empty app from
  chrome://print-management.
- The app and browsertests are in Polymer3.
- Includes basic browsertest to test if app is loaded correctly.
- Future CL will set this app as an System Web App.
- This app is hidden behind a feature flag by default.

Bug: 1053704
Test: browsertest

Change-Id: I777c9912568e10621d763be50052f830fa63e765
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2066878
Reviewed-by: James Cook <jamescook@chromium.org>
Reviewed-by: Samuel Huang <huangs@chromium.org>
Reviewed-by: calamity <calamity@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: Zentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: jimmy gong <jimmyxgong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748293}
  • Loading branch information
Jimmy Gong authored and Commit Bot committed Mar 9, 2020
1 parent 9a51776 commit 5209c65
Show file tree
Hide file tree
Showing 22 changed files with 323 additions and 2 deletions.
1 change: 1 addition & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,7 @@ jumbo_static_library("ui") {
"//chromeos/components/multidevice",
"//chromeos/components/multidevice/debug_webui",
"//chromeos/components/multidevice/logging",
"//chromeos/components/print_management",
"//chromeos/components/proximity_auth",
"//chromeos/components/tether",
"//chromeos/components/web_applications",
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
#include "chromeos/components/media_app_ui/url_constants.h"
#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/url_constants.h"
#include "chromeos/components/sample_system_web_app_ui/url_constants.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
Expand Down Expand Up @@ -579,6 +581,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<chromeos::settings::OSSettingsUI>;
if (url.host_piece() == chrome::kChromeUIPowerHost)
return &NewWebUI<chromeos::PowerUI>;
if (base::FeatureList::IsEnabled(
chromeos::features::kPrintJobManagementApp) &&
url.host_piece() == chromeos::kChromeUIPrintManagementHost)
return &NewWebUI<chromeos::PrintManagementUI>;
if (base::FeatureList::IsEnabled(chromeos::features::kMediaApp)) {
if (url.host_piece() == chromeos::kChromeUIMediaAppHost)
return &NewWebUI<chromeos::MediaAppUI>;
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/web_applications/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ source_set("common") {
"//ash/public/cpp",
"//chromeos/components/help_app_ui",
"//chromeos/components/media_app_ui",
"//chromeos/components/print_management",
"//chromeos/constants",
"//chromeos/strings",
]
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_paks.gni
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ template("chrome_extra_paks") {
"$root_gen_dir/chromeos/chromeos_help_app_resources.pak",
"$root_gen_dir/chromeos/chromeos_media_app_bundle_resources.pak",
"$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/third_party/ink/ink_resources.pak",
"$root_gen_dir/ui/file_manager/file_manager_resources.pak",
Expand All @@ -178,6 +179,7 @@ template("chrome_extra_paks") {
"//chromeos/resources:help_app_resources",
"//chromeos/resources:media_app_bundle_resources",
"//chromeos/resources:media_app_resources",
"//chromeos/resources:print_management_resources",
"//third_party/ink:ink_resources",
"//ui/file_manager:resources",
]
Expand Down
1 change: 1 addition & 0 deletions chrome/test/data/webui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ js2gtest("browser_tests_js_mojo_lite_webui") {
"chromeos/crostini_installer_browsertest.js",
"chromeos/crostini_upgrader_browsertest.js",
"chromeos/machine_learning_internals_browsertest.js",
"chromeos/print_management/print_management_browsertest.js",
"multidevice_setup/multidevice_setup_browsertest.js",
]
deps += [ "//chromeos/services/machine_learning/public/cpp:test_support" ]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

/**
* @fileoverview Test suite for chrome://print-management.
*/

GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
GEN('#include "chromeos/constants/chromeos_features.h"');

/**
* @constructor
* @extends {PolymerTest}
*/
function PrintManagementBrowserTest() {}

PrintManagementBrowserTest.prototype = {
__proto__: PolymerTest.prototype,

browsePreload: 'chrome://print-management/test_loader.html?module=chromeos/' +
'print_management/print_management_test.js',

extraLibraries: [
'//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js',
],

featureList: {
enabled: [
'chromeos::features::kPrintJobManagementApp',
]
},
};

TEST_F('PrintManagementBrowserTest', 'All', function() {
mocha.run();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.

// TODO(jimmyxgong): use es6 module for mojo binding crbug/1004256
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://print-management/print_management.js';

suite('PrintManagementTest', () => {
/** @type {?PrintManagementElement} */
let page = null;

setup(function() {
PolymerTest.clearBody();
page = document.createElement('print-management');
document.body.appendChild(page);
});

teardown(function() {
page.remove();
page = null;
});

test('MainPageLoaded', () => {
// TODO(jimmyxgong): Remove this stub test once the app has more
// capabilities to test.
assertEquals('Print Management', page.$$('#header').textContent);
});
});
1 change: 1 addition & 0 deletions chromeos/components/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ group("closure_compile") {
"//chromeos/components/help_app_ui:closure_compile",
"//chromeos/components/media_app_ui:closure_compile",
"//chromeos/components/multidevice/debug_webui/resources:closure_compile",
"//chromeos/components/print_management:closure_compile",
]

if (!is_official_build) {
Expand Down
26 changes: 26 additions & 0 deletions chromeos/components/print_management/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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, "Print Management is Chrome OS only")

static_library("print_management") {
sources = [
"print_management_ui.cc",
"print_management_ui.h",
"url_constants.cc",
"url_constants.h",
]

deps = [
"//chromeos/constants",
"//chromeos/resources:print_management_resources",
"//content/public/browser",
"//ui/resources",
"//ui/webui",
]
}

group("closure_compile") {
deps = [ "resources:closure_compile_module" ]
}
7 changes: 7 additions & 0 deletions chromeos/components/print_management/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include_rules = [
"-chrome",
"+chromeos/grit/chromeos_print_management_resources.h",
"+content/public/browser",
"+ui/resources",
"+ui/webui",
]
9 changes: 9 additions & 0 deletions chromeos/components/print_management/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Primary OWNERS
baileyberro@chromium.org
jimmyxgong@chromium.org

# Backup OWNERS
khorimoto@chromium.org
zentaro@chromium.org

# COMPONENT: OS>Systems>Printing
35 changes: 35 additions & 0 deletions chromeos/components/print_management/print_management_ui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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/print_management_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 {

PrintManagementUI::PrintManagementUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui) {
auto html_source = base::WrapUnique(
content::WebUIDataSource::Create(kChromeUIPrintManagementHost));
html_source->OverrideContentSecurityPolicyScriptSrc(
"script-src chrome://resources chrome://test 'self';");

html_source->AddResourcePath("print_management.js", IDR_PRINT_MANAGEMENT_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_PRINT_MANAGEMENT_INDEX_HTML);

content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
html_source.release());
}

PrintManagementUI::~PrintManagementUI() = default;

} // namespace chromeos
24 changes: 24 additions & 0 deletions chromeos/components/print_management/print_management_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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_PRINT_MANAGEMENT_UI_H_
#define CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_PRINT_MANAGEMENT_UI_H_

namespace chromeos {

// The WebUI for chrome://print-management/.
class PrintManagementUI : public ui::MojoWebUIController {
public:
explicit PrintManagementUI(content::WebUI* web_ui);
~PrintManagementUI() override;

PrintManagementUI(const PrintManagementUI&) = delete;
PrintManagementUI& operator=(const PrintManagementUI&) = delete;
};

} // namespace chromeos

#endif // CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_PRINT_MANAGEMENT_UI_H_
29 changes: 29 additions & 0 deletions chromeos/components/print_management/resources/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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/polymer.gni")

js_type_check("closure_compile_module") {
is_polymer3 = true
deps = [ ":print_management" ]
}

js_library("print_management") {
deps = [
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
}

polymer_modulizer("print_management") {
js_file = "print_management.js"
html_file = "print_management.html"
html_type = "v3-ready"
}

group("polymer3_elements") {
deps = [ ":print_management_module" ]
}
18 changes: 18 additions & 0 deletions chromeos/components/print_management/resources/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- 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. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Print Management</title>
</head>
<body>
<print-management></print-management>

<script type="module" src="print_management.js"></script>
<!-- Below mojo script required to run browser tests -->
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js">
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="header"></div>
22 changes: 22 additions & 0 deletions chromeos/components/print_management/resources/print_management.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

/**
* @fileoverview
* 'print-management' is used as the main app to display print jobs.
*/
Polymer({
is: 'print-management',

_template: html`{__html_template__}`,

/** @override */
ready() {
// TODO(jimmyxgong): Remove this once the app has more capabilities.
this.$$('#header').textContent = 'Print Management';
},

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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_print_management_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="grit/chromeos_print_management_resources_map.cc"
type="resource_file_map_source" />
<output filename="grit/chromeos_print_management_resources_map.h"
type="resource_map_header" />
<output filename="chromeos_print_management_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<!-- Privileged app host contents. -->
<include name="IDR_PRINT_MANAGEMENT_INDEX_HTML" file="index.html" type="BINDATA" compress="gzip" />
<include name="IDR_PRINT_MANAGEMENT_JS" file="${root_gen_dir}/chromeos/components/print_management/resources/print_management.js" use_base_dir="false" compress="gzip" type="BINDATA"/>
</includes>
</release>
</grit>
11 changes: 11 additions & 0 deletions chromeos/components/print_management/url_constants.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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/url_constants.h"

namespace chromeos {

const char kChromeUIPrintManagementHost[] = "print-management";

} // namespace chromeos
14 changes: 14 additions & 0 deletions chromeos/components/print_management/url_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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_PRINT_MANAGEMENT_URL_CONSTANTS_H_
#define CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_URL_CONSTANTS_H_

namespace chromeos {

extern const char kChromeUIPrintManagementHost[];

} // namespace chromeos

#endif // CHROMEOS_COMPONENTS_PRINT_MANAGEMENT_URL_CONSTANTS_H_
23 changes: 23 additions & 0 deletions chromeos/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,26 @@ grit("media_app_bundle_resources") {
]
output_dir = "$root_gen_dir/chromeos"
}

grit("print_management_resources") {
source =
"../components/print_management/resources/print_management_resources.grd"

source_is_generated = true

deps = [ "../components/print_management/resources:polymer3_elements" ]

outputs = [
"grit/chromeos_print_management_resources.h",
"grit/chromeos_print_management_resources_map.cc",
"grit/chromeos_print_management_resources_map.h",
"chromeos_print_management_resources.pak",
]

grit_flags = [
"-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
]

output_dir = "$root_gen_dir/chromeos"
}
Loading

0 comments on commit 5209c65

Please sign in to comment.