Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: chrome/browser/resources/print_preview/search/cros_destination_resolver.js

Issue 2606043004: Perform printer setup on Chrome OS before selecting printer. (Closed)
Patch Set: address comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /** @enum {string} */
9 var ResolverState = {
10 INITIAL: 'INITIAL',
11 CONFIGURING_PRINTER: 'CONFIGURING_PRINTER',
12 ERROR: 'ERROR',
13 DONE: 'DONE'
14 };
15
16 /**
17 * Overlay used to notify the user of printer setup steps for Chrome OS
18 * printers. Printer installation can occur before any print job is executed.
19 *
20 * @param {!print_preview.DestinationStore} destinationStore The destination
21 * store containing the destination. Used as a proxy to native layer for
22 * resolving the destination.
23 * @param {!print_preview.Destination} destination The destination that has
24 * to be resolved.
25 * @constructor
26 * @extends {print_preview.Overlay}
27 */
28 function CrosDestinationResolver(destinationStore, destination) {
29 print_preview.Overlay.call(this);
30
31 /** @private {!print_preview.DestinationStore} */
32 this.destinationStore_ = destinationStore;
33 /** @private {!print_preview.Destination} */
34 this.destination_ = destination;
35
36 /** @private {!ResolverState} */
37 this.state_ = ResolverState.INITIAL;
38
39 /**
40 * Promise resolver for promise returned by {@code this.run}.
41 * @private {?PromiseResolver<!print_preview.Destination>}
42 */
43 this.promiseResolver_ = null;
44 };
45
46 CrosDestinationResolver.prototype = {
47 __proto__: print_preview.Overlay.prototype,
48
49 /** @override */
50 enterDocument: function() {
51 print_preview.Overlay.prototype.enterDocument.call(this);
52
53 this.tracker.add(
54 this.destinationStore_,
55 print_preview.DestinationStore.EventType.PRINTER_CONFIGURED,
56 this.onDestinationResolved_.bind(this));
57 },
58
59 /** @override */
60 createDom: function() {
61 this.setElementInternal(this.cloneTemplateInternal(
62 'cros-printer-resolver'));
63 },
64
65 /**
66 * Dispatch the request to resolve the destination to the native layer.
67 * @private
68 */
69 startResolveDestination_: function() {
70 assert(this.state_ == ResolverState.INITIAL);
71 assert(!this.promiseResolver_, 'Promise resolver already set');
72 this.promiseResolver_ = new PromiseResolver();
73 this.destinationStore_.resolveCrosDestination(this.destination_);
74 this.setState_(ResolverState.CONFIGURING_PRINTER);
75 },
76
77 /**
78 * Handler for PRINTER_SETUP event. It finalizes the
79 * resolver state once the destination associated with the resolver gets
80 * resolved.
81 * @param {Event} event
dpapad 2017/01/13 22:50:49 s/Event/CustomEvent
skau 2017/01/13 22:57:43 Done.
82 * @private
83 */
84 onDestinationResolved_: function(event) {
85 assert(this.promiseResolver_, 'Promise resolver not found');
86 var detail = event.detail;
87 if (detail.success) {
88 this.setState_(ResolverState.DONE);
89 assert(detail.capabilities);
90 // detail contains printerId and capabilities.
dpapad 2017/01/13 22:50:50 Nit: |detail| contains ....
skau 2017/01/13 22:57:43 Done.
91 this.promiseResolver_.resolve(detail);
92 this.setIsVisible(false);
93 } else {
94 this.setState_(ResolverState.ERROR);
95 this.promiseResolver_.reject();
96 }
97
98 this.promiseResolver_ = null;
99 },
100
101 /**
102 * Sets new resolver state and updates the UI accordingly.
103 * @param {ResolverState} state
dpapad 2017/01/13 22:50:50 !ResolverState
skau 2017/01/13 22:57:43 Done.
104 * @private
105 */
106 setState_: function(state) {
107 if (this.state_ == state)
108 return;
109
110 this.state_ = state;
111 this.updateUI_();
112 },
113
114 /**
115 * Updates the resolver overlay UI to match the resolver state.
116 * @private
117 */
118 updateUI_: function() {
119 // TODO(crbug.com/677567): Replace with meaningful UI.
120 },
121
122 /**
123 * Initiates and shows the resolver overlay.
124 * @param {!HTMLElement} parent The element that should parent the resolver
125 * UI.
126 * @return {!Promise<!print_preview.Destination>} Promise that will be
127 * fulfilled when the destination resolving is finished.
128 */
129 run: function(parent) {
130 this.render(parent);
131 this.setIsVisible(true);
132 this.startResolveDestination_();
133
134 assert(this.promiseResolver_, 'Promise resolver not created.');
135 return this.promiseResolver_.promise;
136 }
137 };
138
139 return {
140 CrosDestinationResolver: CrosDestinationResolver
141 };
142 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698