Commit f5c212bb authored by Nnamdi Theodore Johnson-Kanu's avatar Nnamdi Theodore Johnson-Kanu Committed by Commit Bot

[CrOS settings] Fix polymer_modulizer targets in os_printing_page/.

This CL is in preparation for enabling Polymer3 in ChromeOS settings
pages. It fixed issues in os_printing_page/ folder that break
semi-automatic Polymer3 migration. These changes include splitting up
files that contain multiple <dom-module> elements, as this is required
by Polymer3 conversion tools.

Bug: 1045266
Change-Id: Idf9b18aac87b74d34a431ffe5383fd2f845554fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151090Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarRegan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarjimmy gong <jimmyxgong@chromium.org>
Commit-Queue: Nnamdi Theodore Johnson-kanu <tjohnsonkanu@google.com>
Cr-Commit-Position: refs/heads/master@{#762024}
parent 92628a7c
......@@ -6,17 +6,52 @@ import("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
deps = [
":cups_add_print_server_dialog",
":cups_add_printer_dialog",
":cups_add_printer_dialog_elements",
":cups_add_printer_manually_dialog",
":cups_add_printer_manufacturer_model_dialog",
":cups_edit_printer_dialog",
":cups_printer_dialog_error",
":cups_printer_dialog_util",
":cups_printers",
":cups_printers_browser_proxy",
":cups_settings_add_printer_dialog",
":os_printing_page",
]
}
js_library("cups_add_printer_dialog") {
js_library("cups_settings_add_printer_dialog") {
deps = [
":cups_add_print_server_dialog",
":cups_add_printer_dialog",
":cups_add_printer_manually_dialog",
":cups_add_printer_manufacturer_model_dialog",
":cups_printers_browser_proxy",
"../localized_link:localized_link",
"//ui/webui/resources/js:load_time_data",
"//ui/webui/resources/js:web_ui_listener_behavior",
]
}
js_library("cups_add_print_server_dialog") {
deps = [
":cups_printers_browser_proxy",
"../localized_link:localized_link",
"//ui/webui/resources/js:load_time_data",
"//ui/webui/resources/js:web_ui_listener_behavior",
]
}
js_library("cups_add_printer_manufacturer_model_dialog") {
deps = [
":cups_printers_browser_proxy",
"../localized_link:localized_link",
"//ui/webui/resources/js:load_time_data",
"//ui/webui/resources/js:web_ui_listener_behavior",
]
}
js_library("cups_add_printer_manually_dialog") {
deps = [
":cups_printers_browser_proxy",
"../localized_link:localized_link",
......@@ -25,7 +60,11 @@ js_library("cups_add_printer_dialog") {
]
}
js_library("cups_add_printer_dialog_elements") {
js_library("cups_add_printer_dialog") {
deps = [ ":cups_printers_browser_proxy" ]
}
js_library("cups_printer_dialog_error") {
deps = [ ":cups_printers_browser_proxy" ]
}
......@@ -135,8 +174,12 @@ js_library("os_printing_page") {
#js_type_check("closure_compile_module") {
# is_polymer3 = true
# deps = [
# ":cups_settings_add_printer_dialog.m",
# ":cups_add_print_server_dialog.m",
# ":cups_add_printer_manually_dialog.m",
# ":cups_add_printer_dialog.m",
# ":cups_add_printer_dialog_elements.m",
# ":cups_add_printer_manufacturer_model_dialog",
# ":cups_printer_dialog_error.m"
# ":cups_edit_printer_dialog.m",
# ":cups_nearby_printers.m",
# ":cups_printer_dialog_util.m",
......@@ -152,23 +195,53 @@ js_library("os_printing_page") {
# ]
#}
# TODO: Fix and re-enable
#js_library("cups_add_printer_dialog.m") {
# sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_add_printer_dialog.m.js" ]
# deps = [
# # TODO: Fill those in.
# ]
# extra_deps = [ ":cups_add_printer_dialog_module" ]
#}
js_library("cups_settings_add_printer_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_settings_add_printer_dialog.m.js" ]
deps = [
# TODO: Fill those in.
]
extra_deps = [ ":cups_settings_add_printer_dialog_module" ]
}
# TODO: Fix and re-enable
#js_library("cups_add_printer_dialog_elements.m") {
# sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_add_printer_dialog_elements.m.js" ]
# deps = [
# # TODO: Fill those in.
# ]
# extra_deps = [ ":cups_add_printer_dialog_elements_module" ]
#}
js_library("cups_add_print_server_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_add_print_server_dialog.m.js" ]
deps = [
# TODO: Fill those in.
]
extra_deps = [ ":cups_add_print_server_dialog_module" ]
}
js_library("cups_add_printer_manufacturer_model_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_add_printer_manufacturer_model_dialog.m.js" ]
deps = [
# TODO: Fill those in.
]
extra_deps = [ ":cups_add_printer_manufacturer_model_dialog_module" ]
}
js_library("cups_add_printer_manually_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_add_printer_manually_dialog.m.js" ]
deps = [
# TODO: Fill those in.
]
extra_deps = [ ":cups_add_printer_manually_dialog_module" ]
}
js_library("cups_add_printer_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_add_printer_dialog.m.js" ]
deps = [
# TODO: Fill those in.
]
extra_deps = [ ":cups_add_printer_dialog_module" ]
}
js_library("cups_printer_dialog_error.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_printer_dialog_error.m.js" ]
deps = [
# TODO: Fill those in.
]
extra_deps = [ ":cups_printer_dialog_error_module" ]
}
js_library("cups_edit_printer_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/os_printing_page/cups_edit_printer_dialog.m.js" ]
......@@ -270,11 +343,14 @@ import("//tools/polymer/polymer.gni")
group("polymer3_elements") {
public_deps = [
# TODO: Fix and re-enable
#":cups_add_printer_dialog_elements_module",
#":cups_add_printer_dialog_module",
":cups_add_print_server_dialog",
":cups_add_printer_dialog",
":cups_add_printer_dialog_module",
":cups_add_printer_manually_dialog",
":cups_add_printer_manufacturer_model_dialog",
":cups_edit_printer_dialog_module",
":cups_nearby_printers_module",
":cups_printer_dialog_error_module",
":cups_printer_dialog_util_module",
":cups_printer_shared_css_module",
":cups_printer_types_module",
......@@ -287,19 +363,41 @@ group("polymer3_elements") {
]
}
# TODO: Fix and re-enable
#polymer_modulizer("cups_add_printer_dialog") {
# js_file = "cups_add_printer_dialog.js"
# html_file = "cups_add_printer_dialog.html"
# html_type = "dom-module"
#}
polymer_modulizer("cups_settings_add_printer_dialog") {
js_file = "cups_settings_add_printer_dialog.js"
html_file = "cups_settings_add_printer_dialog.html"
html_type = "dom-module"
}
# TODO: Fix and re-enable
#polymer_modulizer("cups_add_printer_dialog_elements") {
# js_file = "cups_add_printer_dialog_elements.js"
# html_file = "cups_add_printer_dialog_elements.html"
# html_type = "dom-module"
#}
polymer_modulizer("cups_add_print_server_dialog") {
js_file = "cups_add_print_server_dialog.js"
html_file = "cups_add_print_server_dialog.html"
html_type = "dom-module"
}
polymer_modulizer("cups_add_printer_manufacturer_model_dialog") {
js_file = "cups_add_printer_manufacturer_model_dialog.js"
html_file = "cups_add_printer_manufacturer_model_dialog.html"
html_type = "dom-module"
}
polymer_modulizer("cups_add_printer_manually_dialog") {
js_file = "cups_add_printer_manually_dialog.js"
html_file = "cups_add_printer_manually_dialog.html"
html_type = "dom-module"
}
polymer_modulizer("cups_add_printer_dialog") {
js_file = "cups_add_printer_dialog.js"
html_file = "cups_add_printer_dialog.html"
html_type = "dom-module"
}
polymer_modulizer("cups_printer_dialog_error") {
js_file = "cups_printer_dialog_error.js"
html_file = "cups_printer_dialog_error.html"
html_type = "dom-module"
}
polymer_modulizer("cups_edit_printer_dialog") {
js_file = "cups_edit_printer_dialog.js"
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="../../i18n_setup.html">
<link rel="import" href="cups_add_printer_dialog.html">
<link rel="import" href="cups_printer_dialog_error.html">
<link rel="import" href="cups_printer_dialog_util.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_browser_proxy.html">
<dom-module id="add-print-server-dialog">
<template>
<style include="cups-printer-shared">
[slot=dialog-body] {
height: 90px;
}
[slot=dialog-buttons] {
width: auto;
}
</style>
<add-printer-dialog id="printServerDialog">
<div slot="dialog-title">
$i18n{addPrintServerTitle}
<printer-dialog-error id="server-dialog-error"
error-text="[[errorText_]]">
</printer-dialog-error>
</div>
<div slot="dialog-body">
<div class="settings-box first two-line">
<cr-input id="printServerAddressInput"
label="$i18n{printServerAddress}"
value="{{printServerAddress_}}"
error-message="$i18n{printServerInvalidUrlAddress}"
on-keypress="onKeypress_"
maxlength=63 autofocus>
</cr-input>
</div>
</div>
<div slot="dialog-buttons">
<cr-button class="cancel-button" on-click="onCancelTap_">
$i18n{cancel}
</cr-button>
<cr-button class="action-button"
on-click="onAddPrintServerTap_"
disabled="[[inProgress_]]">
$i18n{addPrinterButtonText}
</cr-button>
</div>
</add-printer-dialog>
</template>
<script src="cups_add_print_server_dialog.js"></script>
</dom-module>
\ No newline at end of file
// 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 'add-print-server-dialog' is a dialog in which the user can
* add a print server.
*/
Polymer({
is: 'add-print-server-dialog',
properties: {
/** @private {string} */
printServerAddress_: {
type: String,
value: '',
},
/** @private {string} */
errorText_: {
type: String,
value: '',
},
/** @private {boolean} */
inProgress_: {
type: Boolean,
value: false,
},
},
/** @private */
onCancelTap_: function() {
this.$$('add-printer-dialog').close();
},
/** @private */
onAddPrintServerTap_: function() {
this.inProgress_ = true;
this.$$('#printServerAddressInput').invalid = false;
settings.CupsPrintersBrowserProxyImpl.getInstance()
.queryPrintServer(this.printServerAddress_)
.then(
this.onPrintServerAddedSucceeded_.bind(this),
this.onPrintServerAddedFailed_.bind(this));
},
/**
* @param {!CupsPrintersList} printers
* @private
*/
onPrintServerAddedSucceeded_: function(printers) {
this.inProgress_ = false;
this.fire('add-print-server-and-show-toast', {printers: printers});
this.$$('add-printer-dialog').close();
},
/**
* @param {*} addPrintServerError
* @private
*/
onPrintServerAddedFailed_: function(addPrintServerError) {
this.inProgress_ = false;
if (addPrintServerError == PrintServerResult.INCORRECT_URL) {
this.$$('#printServerAddressInput').invalid = true;
return;
}
this.errorText_ = settings.printing.getPrintServerErrorText(
/** @type {PrintServerResult} */ (addPrintServerError));
},
/**
* Keypress event handler. If enter is pressed, trigger the add event.
* @param {!Event} event
* @private
*/
onKeypress_: function(event) {
if (event.key != 'Enter') {
return;
}
event.stopPropagation();
this.onAddPrintServerTap_();
},
});
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="../localized_link/localized_link.html">
<link rel="import" href="../../i18n_setup.html">
<link rel="import" href="cups_add_printer_dialog.html">
<link rel="import" href="cups_printer_dialog_error.html">
<link rel="import" href="cups_add_print_server_dialog.html">
<link rel="import" href="cups_printer_dialog_util.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_browser_proxy.html">
<dom-module id="add-printer-manually-dialog">
<template>
<style include="cups-printer-shared"></style>
<add-printer-dialog>
<div slot="dialog-title">
<span>$i18n{addPrintersManuallyTitle}</span>
<printer-dialog-error error-text="[[errorText_]]">
</printer-dialog-error>
</div>
<div slot="dialog-body">
<div class="settings-box first two-line">
<cr-input class="printer-name-input" autofocus
id="printerNameInput" value="{{newPrinter.printerName}}"
label="$i18n{printerName}" maxlength=64 on-keypress="onKeypress_">
</cr-input>
</div>
<div class="settings-box two-line">
<cr-input id="printerAddressInput" label="$i18n{printerAddress}"
value="{{newPrinter.printerAddress}}" maxlength=63
error-message="$i18n{ippPrinterUnreachable}"
on-keypress="onKeypress_">
</cr-input>
</div>
<div class="settings-box two-line">
<div class="start">
<div id="printerProtocol" class="cr-form-field-label"
aria-hidden="true">
$i18n{printerProtocol}
</div>
<div class="secondary">
<select class="md-select" aria-labelledby="printerProtocol"
value="[[newPrinter.printerProtocol]]"
on-change="onProtocolChange_">
<option value="ipp">$i18n{printerProtocolIpp}</option>
<option value="ipps">$i18n{printerProtocolIpps}</option>
<option value="http">$i18n{printerProtocolHttp}</option>
<option value="https">$i18n{printerProtocolHttps}</option>
<option value="socket">$i18n{printerProtocolAppSocket}
</option>
<option value="lpd">$i18n{printerProtocolLpd}</option>
</select>
</div>
</div>
</div>
<div class="settings-box two-line">
<cr-input id="printerQueueInput" label="$i18n{printerQueue}"
value="{{newPrinter.printerQueue}}" maxlength=64
on-keypress="onKeypress_">
</cr-input>
</div>
</div>
<template is="dom-if" if="[[printServersUiEnabled]]">
<div slot="dialog-buttons">
<!-- Left Group -->
<div>
<cr-button id="print-server-button" on-click="onPrintServerTap_">
$i18n{printServerButtonText}
</cr-button>
</div>
<!-- Right Group -->
<div>
<cr-button class="cancel-button" on-click="onCancelTap_">
$i18n{cancel}
</cr-button>
<cr-button id="addPrinterButton" class="action-button"
on-click="addPressed_"
disabled="[[!canAddPrinter_(newPrinter.*,
addPrinterInProgress_)]]">
$i18n{addPrinterButtonText}
</cr-button>
</div>
</div>
</template>
<template is="dom-if" if="[[!printServersUiEnabled]]">
<div slot="dialog-buttons">
<!-- Left Group -->
<div>
<cr-button class="cancel-button" on-click="onCancelTap_">
$i18n{cancel}
</cr-button>
</div>
<!-- Right Group -->
<div>
<cr-button id="addPrinterButton" class="action-button"
on-click="addPressed_"
disabled="[[!canAddPrinter_(newPrinter.*,
addPrinterInProgress_)]]">
$i18n{addPrinterButtonText}
</cr-button>
</div>
</div>
</template>
</add-printer-dialog>
</template>
<script src="cups_add_printer_manually_dialog.js"></script>
</dom-module>
\ No newline at end of file
// 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 'add-printer-manually-dialog' is a dialog in which user can
* manually enter the information to set up a new printer.
*/
function getEmptyPrinter_() {
return {
ppdManufacturer: '',
ppdModel: '',
printerAddress: '',
printerDescription: '',
printerId: '',
printerManufacturer: '',
printerModel: '',
printerMakeAndModel: '',
printerName: '',
printerPPDPath: '',
printerPpdReference: {
userSuppliedPpdUrl: '',
effectiveMakeAndModel: '',
autoconf: false,
},
printerProtocol: 'ipp',
printerQueue: 'ipp/print',
printerStatus: '',
printServerUri: '',
};
}
Polymer({
is: 'add-printer-manually-dialog',
properties: {
/** @type {!CupsPrinterInfo} */
newPrinter: {type: Object, notify: true, value: getEmptyPrinter_},
/** @private */
addPrinterInProgress_: {
type: Boolean,
value: false,
},
/**
* The error text to be displayed on the dialog.
* @private
*/
errorText_: {
type: String,
value: '',
},
/** @type {boolean} */
printServersUiEnabled: Boolean,
},
observers: [
'printerInfoChanged_(newPrinter.*)',
],
/** @private */
onCancelTap_() {
this.$$('add-printer-dialog').close();
},
/**
* Handler for addCupsPrinter success.
* @param {!PrinterSetupResult} result
* @private
*/
onAddPrinterSucceeded_(result) {
this.fire(
'show-cups-printer-toast',
{resultCode: result, printerName: this.newPrinter.printerName});
this.$$('add-printer-dialog').close();
},
/**
* Handler for addCupsPrinter failure.
* @param {*} result
* @private
*/
onAddPrinterFailed_(result) {
this.errorText_ = settings.printing.getErrorText(
/** @type {PrinterSetupResult} */ (result));
},
/**
* Handler for getPrinterInfo success.
* @param {!PrinterMakeModel} info
* @private
*/
onPrinterFound_(info) {
const newPrinter =
/** @type {CupsPrinterInfo} */ (Object.assign({}, this.newPrinter));
newPrinter.printerManufacturer = info.manufacturer;
newPrinter.printerModel = info.model;
newPrinter.printerMakeAndModel = info.makeAndModel;
newPrinter.printerPpdReference.userSuppliedPpdUrl =
info.ppdRefUserSuppliedPpdUrl;
newPrinter.printerPpdReference.effectiveMakeAndModel =
info.ppdRefEffectiveMakeAndModel;
newPrinter.printerPpdReference.autoconf = info.autoconf;
this.newPrinter = newPrinter;
// Add the printer if it's configurable. Otherwise, forward to the
// manufacturer dialog.
if (info.ppdReferenceResolved) {
settings.CupsPrintersBrowserProxyImpl.getInstance()
.addCupsPrinter(this.newPrinter)
.then(
this.onAddPrinterSucceeded_.bind(this),
this.onAddPrinterFailed_.bind(this));
} else {
this.$$('add-printer-dialog').close();
this.fire('open-manufacturer-model-dialog');
}
},
/**
* Handler for getPrinterInfo failure.
* @param {*} result a PrinterSetupResult with an error code indicating why
* getPrinterInfo failed.
* @private
*/
infoFailed_(result) {
this.addPrinterInProgress_ = false;
if (result == PrinterSetupResult.PRINTER_UNREACHABLE) {
this.$.printerAddressInput.invalid = true;
return;
}
this.errorText_ = settings.printing.getErrorText(
/** @type {PrinterSetupResult} */ (result));
},
/** @private */
addPressed_() {
this.addPrinterInProgress_ = true;
if (this.newPrinter.printerProtocol == 'ipp' ||
this.newPrinter.printerProtocol == 'ipps') {
settings.CupsPrintersBrowserProxyImpl.getInstance()
.getPrinterInfo(this.newPrinter)
.then(this.onPrinterFound_.bind(this), this.infoFailed_.bind(this));
} else {
this.$$('add-printer-dialog').close();
this.fire('open-manufacturer-model-dialog');
}
},
/** @private */
onPrintServerTap_: function() {
this.$$('add-printer-dialog').close();
this.fire('open-add-print-server-dialog');
},
/**
* @param {!Event} event
* @private
*/
onProtocolChange_(event) {
this.set('newPrinter.printerProtocol', event.target.value);
},
/**
* @return {boolean} Whether the add printer button is enabled.
* @private
*/
canAddPrinter_() {
return !this.addPrinterInProgress_ &&
settings.printing.isNameAndAddressValid(this.newPrinter);
},
/** @private */
printerInfoChanged_() {
this.$.printerAddressInput.invalid = false;
this.errorText_ = '';
},
/**
* Keypress event handler. If enter is pressed, printer is added if
* |canAddPrinter_| is true.
* @param {!Event} event
* @private
*/
onKeypress_(event) {
if (event.key != 'Enter') {
return;
}
event.stopPropagation();
if (this.canAddPrinter_()) {
this.addPressed_();
}
},
});
\ No newline at end of file
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="../localized_link/localized_link.html">
<link rel="import" href="../../i18n_setup.html">
<link rel="import" href="cups_add_printer_dialog.html">
<link rel="import" href="cups_printer_dialog_error.html">
<link rel="import" href="cups_printer_dialog_util.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_browser_proxy.html">
<dom-module id="add-printer-manufacturer-model-dialog">
<template>
<style include="cups-printer-shared">
.subtext {
margin-bottom: 10px;
padding-inline-end: 20px;
padding-inline-start: 20px;
}
#make-model-body {
height: 290px;
}
</style>
<add-printer-dialog>
<div slot="dialog-title">
<span>$i18n{manufacturerAndModelDialogTitle}</span>
<printer-dialog-error error-text="[[errorText_]]">
</printer-dialog-error>
</div>
<div id="make-model-body" slot="dialog-body">
<div class="subtext" id="makeModelTextInfo">
<settings-localized-link
localized-string=
"[[getManufacturerAndModelSubtext_(activePrinter.*)]]"
link-url="$i18n{printingCUPSPrintLearnMoreUrl}">
</settings-localized-link>
</div>
<div class="settings-box two-line">
<cr-searchable-drop-down id="manufacturerDropdown"
items="[[manufacturerList]]"
label="$i18n{printerManufacturer}"
value="{{activePrinter.ppdManufacturer}}"
invalid="{{isManufacturerInvalid_}}">
</cr-searchable-drop-down>
</div>
<div class="settings-box two-line">
<cr-searchable-drop-down id="modelDropdown"
items="[[modelList]]"
label="$i18n{printerModel}"
value="{{activePrinter.ppdModel}}"
invalid="{{isModelInvalid_}}">
</cr-searchable-drop-down>
</div>
<div id="ppdLabel" class="cr-form-field-label">
<settings-localized-link localized-string="$i18n{selectDriver}"
link-url="$i18n{printingCUPSPrintPpdLearnMoreUrl}">
</settings-localized-link>
</div>
<div class="settings-box two-line">
<cr-input class="browse-file-input" readonly value="[[newUserPPD_]]"
aria-labelledby="ppdLabel" invalid="[[invalidPPD_]]"
error-message="$i18n{selectDriverErrorMessage}" tabindex="-1">
</cr-input>
<cr-button class="browse-button" on-click="onBrowseFile_"
aria-label="$i18n{selectDriverButtonAriaLabel}">
$i18n{selectDriverButtonText}
</cr-button>
</div>
</div>
<div slot="dialog-buttons">
<div> <!-- Left group -->
<div class="eula" id="eulaUrl" hidden="[[!eulaUrl_]]">
<a href="[[eulaUrl_]]" target="_blank">$i18n{printerEulaNotice}</a>
</div>
</div>
<div> <!-- Right group -->
<cr-button class="cancel-button" on-click="onCancelTap_">
$i18n{cancel}
</cr-button>
<cr-button class="action-button" id="addPrinterButton"
disabled="[[!canAddPrinter_(activePrinter.ppdManufacturer,
activePrinter.ppdModel,
activePrinter.printerPPDPath,
addPrinterInProgress_,
isManufacturerInvalid_,
isModelInvalid_)]]"
on-click="addPrinter_">
$i18n{addPrinterButtonText}
</cr-button>
</div>
</div>
</add-printer-dialog>
</template>
<script src="cups_add_printer_manufacturer_model_dialog.js"></script>
</dom-module>
\ No newline at end of file
// 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
* 'add-printer-manufacturer-model-dialog' is a dialog in which the user can
* manually select the manufacture and model of the new printer.
*/
Polymer({
is: 'add-printer-manufacturer-model-dialog',
properties: {
/** @type {!CupsPrinterInfo} */
activePrinter: {
type: Object,
notify: true,
},
/** @type {?Array<string>} */
manufacturerList: Array,
/** @type {?Array<string>} */
modelList: Array,
/**
* Whether the user selected PPD file is valid.
* @private
*/
invalidPPD_: {
type: Boolean,
value: false,
},
/**
* The base name of a newly selected PPD file.
* @private
*/
newUserPPD_: String,
/**
* The URL to a printer's EULA.
* @private
*/
eulaUrl_: {
type: String,
value: '',
},
/** @private */
addPrinterInProgress_: {
type: Boolean,
value: false,
},
/**
* The error text to be displayed on the dialog.
* @private
*/
errorText_: {
type: String,
value: '',
},
/**
* Indicates whether the value in the Manufacturer dropdown is a valid
* printer manufacturer.
* @private
*/
isManufacturerInvalid_: Boolean,
/**
* Indicates whether the value in the Model dropdown is a valid printer
* model.
* @private
*/
isModelInvalid_: Boolean,
},
observers: [
'selectedManufacturerChanged_(activePrinter.ppdManufacturer)',
'selectedModelChanged_(activePrinter.ppdModel)',
],
/** @override */
attached() {
settings.CupsPrintersBrowserProxyImpl.getInstance()
.getCupsPrinterManufacturersList()
.then(this.manufacturerListChanged_.bind(this));
},
close() {
this.$$('add-printer-dialog').close();
},
/**
* Handler for addCupsPrinter success.
* @param {!PrinterSetupResult} result
* @private
*/
onPrinterAddedSucceeded_(result) {
this.fire(
'show-cups-printer-toast',
{resultCode: result, printerName: this.activePrinter.printerName});
this.close();
},
/**
* Handler for addCupsPrinter failure.
* @param {*} result
* @private
*/
onPrinterAddedFailed_(result) {
this.addPrinterInProgress_ = false;
this.errorText_ = settings.printing.getErrorText(
/** @type {PrinterSetupResult} */ (result));
},
/**
* If the printer is a nearby printer, return make + model with the subtext.
* Otherwise, return printer name.
* @return {string} The additional information subtext of the manufacturer and
* model dialog.
* @private
*/
getManufacturerAndModelSubtext_() {
if (this.activePrinter.printerMakeAndModel) {
return loadTimeData.getStringF(
'manufacturerAndModelAdditionalInformation',
this.activePrinter.printerMakeAndModel);
}
return loadTimeData.getStringF(
'manufacturerAndModelAdditionalInformation',
this.activePrinter.printerName);
},
/**
* @param {string} manufacturer The manufacturer for which we are retrieving
* models.
* @private
*/
selectedManufacturerChanged_(manufacturer) {
// Reset model if manufacturer is changed.
this.set('activePrinter.ppdModel', '');
this.modelList = [];
if (manufacturer && manufacturer.length != 0) {
settings.CupsPrintersBrowserProxyImpl.getInstance()
.getCupsPrinterModelsList(manufacturer)
.then(this.modelListChanged_.bind(this));
}
},
/**
* Attempts to get the EULA Url if the selected printer has one.
* @private
*/
selectedModelChanged_() {
this.errorText_ = '';
if (!this.activePrinter.ppdManufacturer || !this.activePrinter.ppdModel) {
// Do not check for an EULA unless both |ppdManufacturer| and |ppdModel|
// are set. Set |eulaUrl_| to be empty in this case.
this.onGetEulaUrlCompleted_('' /* eulaUrl */);
return;
}
settings.CupsPrintersBrowserProxyImpl.getInstance()
.getEulaUrl(
this.activePrinter.ppdManufacturer, this.activePrinter.ppdModel)
.then(this.onGetEulaUrlCompleted_.bind(this));
},
/**
* @param {string} eulaUrl The URL for the printer's EULA.
* @private
*/
onGetEulaUrlCompleted_(eulaUrl) {
this.eulaUrl_ = eulaUrl;
},
/**
* @param {!ManufacturersInfo} manufacturersInfo
* @private
*/
manufacturerListChanged_(manufacturersInfo) {
if (!manufacturersInfo.success) {
return;
}
this.manufacturerList = manufacturersInfo.manufacturers;
if (this.activePrinter.ppdManufacturer.length != 0) {
settings.CupsPrintersBrowserProxyImpl.getInstance()
.getCupsPrinterModelsList(this.activePrinter.ppdManufacturer)
.then(this.modelListChanged_.bind(this));
}
},
/**
* @param {!ModelsInfo} modelsInfo
* @private
*/
modelListChanged_(modelsInfo) {
if (modelsInfo.success) {
this.modelList = modelsInfo.models;
}
},
/** @private */
onBrowseFile_() {
settings.CupsPrintersBrowserProxyImpl.getInstance()
.getCupsPrinterPPDPath()
.then(this.printerPPDPathChanged_.bind(this));
},
/**
* @param {string} path The full path to the selected PPD file
* @private
*/
printerPPDPathChanged_(path) {
this.set('activePrinter.printerPPDPath', path);
this.invalidPPD_ = !path;
this.newUserPPD_ = settings.printing.getBaseName(path);
},
/** @private */
onCancelTap_() {
this.close();
settings.CupsPrintersBrowserProxyImpl.getInstance().cancelPrinterSetUp(
this.activePrinter);
},
/** @private */
addPrinter_() {
this.addPrinterInProgress_ = true;
settings.CupsPrintersBrowserProxyImpl.getInstance()
.addCupsPrinter(this.activePrinter)
.then(
this.onPrinterAddedSucceeded_.bind(this),
this.onPrinterAddedFailed_.bind(this));
},
/**
* @param {string} ppdManufacturer
* @param {string} ppdModel
* @param {string} printerPPDPath
* @return {boolean} Whether we have enough information to set up the printer
* @private
*/
canAddPrinter_(
ppdManufacturer, ppdModel, printerPPDPath, addPrinterInProgress,
isManufacturerInvalid, isModelInvalid) {
return !addPrinterInProgress &&
settings.printing.isPPDInfoValid(
ppdManufacturer, ppdModel, printerPPDPath) &&
!isManufacturerInvalid && !isModelInvalid;
},
});
......@@ -11,7 +11,8 @@
<link rel="import" href="../../i18n_setup.html">
<link rel="import" href="../localized_link/localized_link.html">
<link rel="import" href="../metrics_recorder.html">
<link rel="import" href="cups_add_printer_dialog_elements.html">
<link rel="import" href="cups_add_printer_dialog.html">
<link rel="import" href="cups_printer_dialog_error.html">
<link rel="import" href="cups_printer_dialog_util.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_browser_proxy.html">
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
<link rel="import" href="chrome://resources/cr_elements/icons.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="cups_printer_dialog_util.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_browser_proxy.html">
<dom-module id="add-printer-dialog">
<template>
<style include="settings-shared">
#dialog {
/* Force a bottom border regardless of scroll state. */
--cr-dialog-body-border-bottom: 1px solid var(--google-grey-300);
}
#dialog [slot=body] {
padding-inline-end: 0;
padding-inline-start: 0;
}
</style>
<cr-dialog id="dialog" close-text="$i18n{close}">
<div slot="title">
<slot name="dialog-title"></slot>
</div>
<div slot="body">
<slot name="dialog-body"></slot>
</div>
<div slot="button-container">
<slot name="dialog-buttons"></slot>
</div>
</cr-dialog>
</template>
<script src="cups_add_printer_dialog_elements.js"></script>
</dom-module>
<dom-module id="printer-dialog-error">
<template>
<style>
......@@ -66,4 +36,5 @@
</div>
</div>
</template>
<script src="cups_printer_dialog_error.js"></script>
</dom-module>
......@@ -2,20 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/** 'add-printer-dialog' is the template of the Add Printer dialog. */
Polymer({
is: 'add-printer-dialog',
/** @private */
attached() {
this.$.dialog.showModal();
},
close() {
this.$.dialog.close();
},
});
/**
* 'printer-dialog-error' is the error container for dialogs.
*/
......
......@@ -13,7 +13,7 @@
<link rel="import" href="chrome://resources/html/cr/ui/focus_without_ink.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="cups_add_printer_dialog.html">
<link rel="import" href="cups_settings_add_printer_dialog.html">
<link rel="import" href="cups_edit_printer_dialog.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_entry_manager.html">
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="../localized_link/localized_link.html">
<link rel="import" href="../../i18n_setup.html">
<link rel="import" href="cups_add_print_server_dialog.html">
<link rel="import" href="cups_add_printer_manually_dialog.html">
<link rel="import" href="cups_add_printer_manufacturer_model_dialog.html">
<link rel="import" href="cups_printer_dialog_util.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_browser_proxy.html">
<dom-module id="settings-cups-add-printer-dialog">
<template>
<style include="settings-shared"></style>
<!-- Manually Add Printer Dialog -->
<template is="dom-if" if="[[showManuallyAddDialog_]]" restamp>
<add-printer-manually-dialog new-printer="{{newPrinter}}"
print-servers-ui-enabled="[[printServersUiEnabled_]]">
</add-printer-manually-dialog>
</template>
<!-- Manufacturer and Model Dialog -->
<template is="dom-if" if="[[showManufacturerDialog_]]" restamp>
<add-printer-manufacturer-model-dialog active-printer="{{newPrinter}}">
</add-printer-manufacturer-model-dialog>
</template>
<!-- Add Print Server Dialog -->
<template is="dom-if" if="[[printServersUiEnabled_]]">
<template is="dom-if" if="[[showAddPrintServerDialog_]]" restamp>
<add-print-server-dialog></add-print-server-dialog>
</template>
</template>
</template>
<script src="cups_settings_add_printer_dialog.js"></script>
</dom-module>
// 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 'settings-cups-add-printer-dialog' includes multiple dialogs to
* set up a new CUPS printer.
* Subdialogs include:
* - 'add-printer-manually-dialog' is a dialog in which user can manually enter
* the information to set up a new printer.
* - 'add-printer-manufacturer-model-dialog' is a dialog in which the user can
* manually select the manufacture and model of the new printer.
* - 'add-print-server-dialog' is a dialog in which the user can
* add a print server.
*/
/**
* Different dialogs in add printer flow.
* @enum {string}
*/
const AddPrinterDialogs = {
MANUALLY: 'add-printer-manually-dialog',
MANUFACTURER: 'add-printer-manufacturer-model-dialog',
PRINTSERVER: 'add-print-server-dialog',
};
/**
* Return a reset CupsPrinterInfo object.
* @return {!CupsPrinterInfo}
*/
function getEmptyPrinter_() {
return {
ppdManufacturer: '',
ppdModel: '',
printerAddress: '',
printerDescription: '',
printerId: '',
printerManufacturer: '',
printerModel: '',
printerMakeAndModel: '',
printerName: '',
printerPPDPath: '',
printerPpdReference: {
userSuppliedPpdUrl: '',
effectiveMakeAndModel: '',
autoconf: false,
},
printerProtocol: 'ipp',
printerQueue: 'ipp/print',
printerStatus: '',
printServerUri: '',
};
}
Polymer({
is: 'settings-cups-add-printer-dialog',
properties: {
/** @type {!CupsPrinterInfo} */
newPrinter: {
type: Object,
},
/** @private {string} */
previousDialog_: String,
/** @private {string} */
currentDialog_: String,
/** @private {boolean} */
showManuallyAddDialog_: {
type: Boolean,
value: false,
},
/** @private {boolean} */
showManufacturerDialog_: {
type: Boolean,
value: false,
},
/** @private {boolean} */
showAddPrintServerDialog_: {
type: Boolean,
value: false,
},
/** @private {boolean} */
printServersUiEnabled_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('consumerPrintServerUiEnabled');
}
},
},
listeners: {
'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_',
'open-manufacturer-model-dialog':
'openManufacturerModelDialogForCurrentPrinter_',
'open-add-print-server-dialog': 'openPrintServerDialog_',
'no-detected-printer': 'onNoDetectedPrinter_',
},
/** Opens the Add manual printer dialog. */
open() {
this.resetData_();
this.switchDialog_(
'', AddPrinterDialogs.MANUALLY, 'showManuallyAddDialog_');
},
/**
* Reset all the printer data in the Add printer flow.
* @private
*/
resetData_() {
if (this.newPrinter) {
this.newPrinter = getEmptyPrinter_();
}
},
/** @private */
openManuallyAddPrinterDialog_() {
this.switchDialog_(
this.currentDialog_, AddPrinterDialogs.MANUALLY,
'showManuallyAddDialog_');
},
/** @private */
openManufacturerModelDialogForCurrentPrinter_() {
this.switchDialog_(
this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
'showManufacturerDialog_');
},
/** @param {!CupsPrinterInfo} printer */
openManufacturerModelDialogForSpecifiedPrinter(printer) {
this.newPrinter = printer;
this.switchDialog_(
'', AddPrinterDialogs.MANUFACTURER, 'showManufacturerDialog_');
},
/** @private */
openPrintServerDialog_: function() {
this.switchDialog_(
this.currentDialog_, AddPrinterDialogs.PRINTSERVER,
'showAddPrintServerDialog_');
},
/**
* Switch dialog from |fromDialog| to |toDialog|.
* @param {string} fromDialog
* @param {string} toDialog
* @param {string} domIfBooleanName The name of the boolean variable
* corresponding to the |toDialog|.
* @private
*/
switchDialog_(fromDialog, toDialog, domIfBooleanName) {
this.previousDialog_ = fromDialog;
this.currentDialog_ = toDialog;
this.set(domIfBooleanName, true);
this.async(function() {
const dialog = this.$$(toDialog);
dialog.addEventListener('close', () => {
this.set(domIfBooleanName, false);
});
});
},
});
......@@ -761,17 +761,41 @@
<structure name="IDR_OS_SETTINGS_CUPS_EDIT_PRINTER_DIALOG_JS"
file="chromeos/os_printing_page/cups_edit_printer_dialog.js"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_SETTINGS_ADD_PRINTER_DIALOG_HTML"
file="chromeos/os_printing_page/cups_settings_add_printer_dialog.html"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_SETTINGS_ADD_PRINTER_DIALOG_JS"
file="chromeos/os_printing_page/cups_settings_add_printer_dialog.js"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_DIALOG_HTML"
file="chromeos/os_printing_page/cups_add_printer_dialog.html"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_DIALOG_JS"
file="chromeos/os_printing_page/cups_add_printer_dialog.js"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_DIALOG_ELEMENTS_HTML"
file="chromeos/os_printing_page/cups_add_printer_dialog_elements.html"
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINT_SERVER_DIALOG_HTML"
file="chromeos/os_printing_page/cups_add_print_server_dialog.html"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINT_SERVER_DIALOG_JS"
file="chromeos/os_printing_page/cups_add_print_server_dialog.js"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_PRINTER_DIALOG_ERROR_HTML"
file="chromeos/os_printing_page/cups_printer_dialog_error.html"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_PRINTER_DIALOG_ERROR_JS"
file="chromeos/os_printing_page/cups_printer_dialog_error.js"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_MANUFACTURER_MODEL_DIALOG_HTML"
file="chromeos/os_printing_page/cups_add_printer_manufacturer_model_dialog.html"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_MANUFACTURER_MODEL_DIALOG_JS"
file="chromeos/os_printing_page/cups_add_printer_manufacturer_model_dialog.js"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_MANUALLY_DIALOG_HTML"
file="chromeos/os_printing_page/cups_add_printer_manually_dialog.html"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_DIALOG_ELEMENTS_JS"
file="chromeos/os_printing_page/cups_add_printer_dialog_elements.js"
<structure name="IDR_OS_SETTINGS_CUPS_ADD_PRINTER_MANUALLY_DIALOG_JS"
file="chromeos/os_printing_page/cups_add_printer_manually_dialog.js"
compress="false" type="chrome_html" />
<structure name="IDR_OS_SETTINGS_CUPS_PRINTER_DIALOG_UTIL_HTML"
file="chromeos/os_printing_page/cups_printer_dialog_util.html"
......
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