Commit 9811b184 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview componentization: Correctly setup CrOS local destinations

Chrome OS local destinations need to be set up before they can be
selected. Add the logic to request setup from the handler and select
the destination only when configuration is complete.

Bug: 773928
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Iccfacad27bac15182abbfeb47f4ec9f274b46fa6
Reviewed-on: https://chromium-review.googlesource.com/1012191
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551089}
parent 7a1b71e9
......@@ -574,6 +574,14 @@ cr.define('print_preview', function() {
return this.isOffline || this.shouldShowInvalidCertificateError;
}
/** @return {boolean} Whether the destination is ready to be selected. */
get readyForSelection() {
return (!cr.isChromeOS ||
this.origin_ != print_preview.DestinationOrigin.CROS ||
this.capabilities_ != null) &&
!this.isProvisional;
}
/**
* @return {string} Human readable status for a destination that is offline
* or has a bad certificate. */
......
......@@ -71,7 +71,7 @@ print_preview.CapabilitiesResponse;
* @typedef {{
* printerId: string,
* success: boolean,
* capabilities: Object,
* capabilities: !print_preview.Cdd,
* }}
*/
print_preview.PrinterSetupResponse;
......
......@@ -73,6 +73,11 @@ Polymer({
/** @private {!EventTracker} */
tracker_: new EventTracker(),
// <if expr="chromeos">
/** @private {?print_preview.Destination} */
destinationInConfiguring_: null,
// </if>
/** @override */
ready: function() {
this.$$('.promo-text').innerHTML =
......@@ -178,31 +183,65 @@ Polymer({
* @private
*/
onDestinationSelected_: function(e) {
const lastFocusedElement =
const listItem =
/** @type {!PrintPreviewDestinationListItemElement} */ (e.detail);
const destination = lastFocusedElement.destination;
const destination = listItem.destination;
if (!destination.isProvisional) {
this.destinationStore.selectDestination(destination);
this.$.dialog.close();
// ChromeOS local destinations that don't have capabilities need to be
// configured before selecting, and provisional destinations need to be
// resolved. Other destinations can be selected.
if (destination.readyForSelection) {
this.selectDestination_(destination);
return;
}
this.$.provisionalResolver.resolveDestination(destination)
.then((resolvedDestination) => {
this.destinationStore.selectDestination(resolvedDestination);
this.$.dialog.close();
})
.catch(function() {
console.error(
'Failed to resolve provisional destination: ' + destination.id);
})
.then(() => {
if (this.$.dialog.open && !!lastFocusedElement &&
!lastFocusedElement.hidden) {
lastFocusedElement.focus();
}
});
// Provisional destinations
if (destination.isProvisional) {
this.$.provisionalResolver.resolveDestination(destination)
.then(this.selectDestination_.bind(this))
.catch(function() {
console.error(
'Failed to resolve provisional destination: ' + destination.id);
})
.then(() => {
if (this.$.dialog.open && !!listItem && !listItem.hidden) {
listItem.focus();
}
});
return;
}
// <if expr="chromeos">
// Destination must be a CrOS local destination that needs to be set up.
// The user is only allowed to set up printer at one time.
if (this.destinationInConfiguring_)
return;
// Show the configuring status to the user and resolve the destination.
listItem.onConfigureRequestAccepted();
this.destinationInConfiguring_ = destination;
this.destinationStore.resolveCrosDestination(destination)
.then(
response => {
this.destinationInConfiguring_ = null;
destination.capabilities = response.capabilities;
listItem.onConfigureComplete(true);
this.selectDestination_(destination);
},
() => {
this.destinationInConfiguring_ = null;
listItem.onConfigureComplete(false);
});
// </if>
},
/**
* @param {!print_preview.Destination} destination The destination to select.
* @private
*/
selectDestination_: function(destination) {
this.destinationStore.selectDestination(destination);
this.$.dialog.close();
},
show: function() {
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html">
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/html/load_time_data.html">
<link rel="import" href="../native_layer.html">
<link rel="import" href="../data/destination.html">
......@@ -123,13 +124,17 @@
<span class="extension-icon" role="button" tabindex="0"></span>
</span>
<if expr="chromeos">
<span class="configuring-in-progress-text" hidden>
<span class="configuring-in-progress-text"
hidden$="[[!checkConfigurationStatus_(statusEnum_.IN_PROGRESS,
configurationStatus_)]]">
$i18n{configuringInProgressText}
<span class="configuring-text-jumping-dots">
<span>.</span><span>.</span><span>.</span>
</span>
</span>
<span class="configuring-failed-text" hidden>
<span class="configuring-failed-text"
hidden$="[[!checkConfigurationStatus_(statusEnum_.FAILED,
configurationStatus_)]]">
$i18n{configuringFailedText}
</span>
</if>
......
......@@ -2,6 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.exportPath('print_preview_new');
// <if expr="chromeos">
/** @enum {number} */
print_preview_new.DestinationConfigStatus = {
IDLE: 0,
IN_PROGRESS: 1,
FAILED: 2,
};
// </if>
Polymer({
is: 'print-preview-destination-list-item',
......@@ -20,6 +31,23 @@ Polymer({
/** @private {string} */
searchHint_: String,
// <if expr="chromeos">
/** @private {!print_preview_new.DestinationConfigStatus} */
configurationStatus_: {
type: Number,
value: print_preview_new.DestinationConfigStatus.IDLE,
},
/**
* Mirroring the enum so that it can be used from HTML bindings.
* @private
*/
statusEnum_: {
type: Object,
value: print_preview_new.DestinationConfigStatus,
},
// </if>
},
observers: [
......@@ -51,6 +79,40 @@ Polymer({
loadTimeData.getString('gcpCertificateErrorLearnMoreURL'));
},
// <if expr="chromeos">
/**
* Called if the printer configuration request is accepted. Show the waiting
* message to the user as the configuration might take longer than expected.
*/
onConfigureRequestAccepted: function() {
// It must be a Chrome OS CUPS printer which hasn't been set up before.
assert(
this.destination.origin == print_preview.DestinationOrigin.CROS &&
!this.destination.capabilities);
this.configurationStatus_ =
print_preview_new.DestinationConfigStatus.IN_PROGRESS;
},
/**
* Called when the printer configuration request completes.
* @param {boolean} success Whether configuration was successful.
*/
onConfigureComplete: function(success) {
this.configurationStatus_ = success ?
print_preview_new.DestinationConfigStatus.IDLE :
print_preview_new.DestinationConfigStatus.FAILED;
},
/**
* @param {!print_preview_new.DestinationConfigStatus} status
* @return {boolean} Whether the current configuration status is |status|.
* @private
*/
checkConfigurationStatus_: function(status) {
return this.configurationStatus_ == status;
},
// </if>
update: function() {
this.updateSearchHint_();
this.updateHighlighting_();
......
......@@ -293,7 +293,8 @@
allowexternalscript="true" />
<structure name="IDR_PRINT_PREVIEW_NEW_DESTINATION_DIALOG_JS"
file="new/destination_dialog.js"
type="chrome_html" />
type="chrome_html"
preprocess="true" />
<structure name="IDR_PRINT_PREVIEW_NEW_DESTINATION_LIST_HTML"
file="new/destination_list.html"
type="chrome_html" />
......@@ -306,7 +307,8 @@
preprocess="true" />
<structure name="IDR_PRINT_PREVIEW_NEW_DESTINATION_LIST_ITEM_JS"
file="new/destination_list_item.js"
type="chrome_html" />
type="chrome_html"
preprocess="true" />
<structure name="IDR_PRINT_PREVIEW_NEW_PROVISIONAL_DESTINATION_RESOLVER_HTML"
file="new/provisional_destination_resolver.html"
type="chrome_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