diff options
Diffstat (limited to 'chromium/chrome/browser/resources/print_preview/new/destination_dialog.js')
-rw-r--r-- | chromium/chrome/browser/resources/print_preview/new/destination_dialog.js | 107 |
1 files changed, 104 insertions, 3 deletions
diff --git a/chromium/chrome/browser/resources/print_preview/new/destination_dialog.js b/chromium/chrome/browser/resources/print_preview/new/destination_dialog.js index ad5fc91a47d..8500c9fd721 100644 --- a/chromium/chrome/browser/resources/print_preview/new/destination_dialog.js +++ b/chromium/chrome/browser/resources/print_preview/new/destination_dialog.js @@ -36,6 +36,7 @@ Polymer({ showCloudPrintPromo: { type: Boolean, notify: true, + observer: 'onShowCloudPrintPromoChanged_', }, /** @private {!Array<!print_preview.Destination>} */ @@ -73,6 +74,14 @@ Polymer({ /** @private {!EventTracker} */ tracker_: new EventTracker(), + /** @private {!print_preview.DestinationSearchMetricsContext} */ + metrics_: new print_preview.DestinationSearchMetricsContext(), + + // <if expr="chromeos"> + /** @private {?print_preview.Destination} */ + destinationInConfiguring_: null, + // </if> + /** @override */ ready: function() { this.$$('.promo-text').innerHTML = @@ -81,6 +90,8 @@ Polymer({ attrs: { 'is': (node, v) => v == 'action-link', 'class': (node, v) => v == 'sign-in', + 'tabindex': (node, v) => v == '0', + 'role': (node, v) => v == 'link', }, }); }, @@ -165,6 +176,13 @@ Polymer({ onCloseOrCancel_: function() { if (this.searchQuery_) this.$.searchBox.setValue(''); + if (this.$.dialog.getNative().returnValue == 'success') { + this.metrics_.record(print_preview.Metrics.DestinationSearchBucket + .DESTINATION_CLOSED_CHANGED); + } else { + this.metrics_.record(print_preview.Metrics.DestinationSearchBucket + .DESTINATION_CLOSED_UNCHANGED); + } }, /** @private */ @@ -173,12 +191,71 @@ Polymer({ }, /** - * @param {!CustomEvent} e Event containing the selected destination. + * @param {!CustomEvent} e Event containing the selected destination list item + * element. * @private */ onDestinationSelected_: function(e) { - this.destinationStore.selectDestination( - /** @type {!print_preview.Destination} */ (e.detail)); + const listItem = + /** @type {!PrintPreviewDestinationListItemElement} */ (e.detail); + const destination = listItem.destination; + + // 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; + } + + // 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; + listItem.onConfigureComplete(response.success); + if (response.success) { + destination.capabilities = response.capabilities; + 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(); }, @@ -186,6 +263,8 @@ Polymer({ this.loadingDestinations_ = this.destinationStore.isPrintDestinationSearchInProgress; this.$.dialog.showModal(); + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.DESTINATION_SHOWN); }, /** @return {boolean} Whether the dialog is open. */ @@ -200,6 +279,8 @@ Polymer({ /** @private */ onSignInClick_: function() { + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.SIGNIN_TRIGGERED); print_preview.NativeLayer.getInstance().signIn(false).then(() => { this.destinationStore.onDestinationsReload(); }); @@ -218,6 +299,10 @@ Polymer({ const invitations = this.userInfo.activeUser ? this.invitationStore.invitations(this.userInfo.activeUser) : []; + if (this.invitation_ != invitations[0]) { + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.INVITATION_AVAILABLE); + } this.invitation_ = invitations.length > 0 ? invitations[0] : null; }, @@ -260,12 +345,16 @@ Polymer({ /** @private */ onInvitationAcceptClick_: function() { + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.INVITATION_ACCEPTED); this.invitationStore.processInvitation(assert(this.invitation_), true); this.updateInvitations_(); }, /** @private */ onInvitationRejectClick_: function() { + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.INVITATION_REJECTED); this.invitationStore.processInvitation(assert(this.invitation_), false); this.updateInvitations_(); }, @@ -281,6 +370,8 @@ Polymer({ this.notifyPath('userInfo.loggedIn'); this.destinationStore.reloadUserCookieBasedDestinations(); this.invitationStore.startLoadingInvitations(); + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.ACCOUNT_CHANGED); } else { print_preview.NativeLayer.getInstance().signIn(true).then( this.destinationStore.onDestinationsReload.bind( @@ -292,6 +383,16 @@ Polymer({ break; } } + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.ADD_ACCOUNT_SELECTED); + } + }, + + /** @private */ + onShowCloudPrintPromoChanged_: function() { + if (this.showCloudPrintPromo) { + this.metrics_.record( + print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT); } }, }); |