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

Side by Side Diff: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js

Issue 2825153002: Update CUPS settings UI to allow USB printers to be added via discovery. (Closed)
Patch Set: Update CUPS settings UI to allow USB printers to be added via discovery. Created 3 years, 7 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 'settings-cups-add-printer-dialog' includes multiple dialogs to 6 * @fileoverview 'settings-cups-add-printer-dialog' includes multiple dialogs to
7 * set up a new CUPS printer. 7 * set up a new CUPS printer.
8 * Subdialogs include: 8 * Subdialogs include:
9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on 9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on
10 * the network that are available for setup. 10 * the network that are available for setup.
(...skipping 15 matching lines...) Expand all
26 MANUFACTURER: 'add-printer-manufacturer-model-dialog', 26 MANUFACTURER: 'add-printer-manufacturer-model-dialog',
27 }; 27 };
28 28
29 /** 29 /**
30 * The maximum height of the discovered printers list when the searching spinner 30 * The maximum height of the discovered printers list when the searching spinner
31 * is not showing. 31 * is not showing.
32 * @const {number} 32 * @const {number}
33 */ 33 */
34 var kPrinterListFullHeight = 350; 34 var kPrinterListFullHeight = 350;
35 35
36 /**
37 * Return a reset CupsPrinterInfo object.
38 * @return {!CupsPrinterInfo}
39 */
40 function getEmptyPrinter_() {
41 return {
42 printerAddress: '',
43 printerDescription: '',
44 printerId: '',
45 printerManufacturer: '',
46 printerModel: '',
47 printerName: '',
48 printerPPDPath: '',
49 printerProtocol: 'ipp',
50 printerQueue: '',
51 printerStatus: '',
52 };
53 }
54
36 Polymer({ 55 Polymer({
37 is: 'add-printer-discovery-dialog', 56 is: 'add-printer-discovery-dialog',
38 57
39 behaviors: [WebUIListenerBehavior], 58 behaviors: [WebUIListenerBehavior],
40 59
41 properties: { 60 properties: {
42 /** @type {!Array<!CupsPrinterInfo>|undefined} */ 61 /** @type {!Array<!CupsPrinterInfo>|undefined} */
43 discoveredPrinters: { 62 discoveredPrinters: {
44 type: Array, 63 type: Array,
45 }, 64 },
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 /** @private */ 111 /** @private */
93 stopDiscoveringPrinters_: function() { 112 stopDiscoveringPrinters_: function() {
94 settings.CupsPrintersBrowserProxyImpl.getInstance(). 113 settings.CupsPrintersBrowserProxyImpl.getInstance().
95 stopDiscoveringPrinters(); 114 stopDiscoveringPrinters();
96 this.discovering_ = false; 115 this.discovering_ = false;
97 }, 116 },
98 117
99 /** @private */ 118 /** @private */
100 switchToManualAddDialog_: function() { 119 switchToManualAddDialog_: function() {
101 this.stopDiscoveringPrinters_(); 120 this.stopDiscoveringPrinters_();
121 // We're abandoning discovery in favor of manual specification, so
122 // drop the selection if one exists.
123 this.selectedPrinter = getEmptyPrinter_();
102 this.$$('add-printer-dialog').close(); 124 this.$$('add-printer-dialog').close();
103 this.fire('open-manually-add-printer-dialog'); 125 this.fire('open-manually-add-printer-dialog');
104 }, 126 },
105 127
106 /** @private */ 128 /** @private */
107 onCancelTap_: function() { 129 onCancelTap_: function() {
108 this.stopDiscoveringPrinters_(); 130 this.stopDiscoveringPrinters_();
109 this.$$('add-printer-dialog').close(); 131 this.$$('add-printer-dialog').close();
110 }, 132 },
111 133
112 /** @private */ 134 /** @private */
113 switchToConfiguringDialog_: function() { 135 switchToManufacturerDialog_: function() {
114 this.stopDiscoveringPrinters_(); 136 this.stopDiscoveringPrinters_();
137 // If we're switching to the manufacturer/model dialog, clear the existing
138 // data we have about the PPD (if any), as we're dropping that in favor of
139 // user selections.
140 this.selectedPrinter.printerManufacturer = '';
141 this.selectedPrinter.printerModel = '';
142 this.selectedPrinter.printerPPDPath = '';
xdai1 2017/05/11 22:50:28 You probably don't need these three lines. After t
Carlson 2017/05/11 23:57:10 That's true, but when we actually do select a prin
xdai1 2017/05/12 00:30:43 Acknowledged.
115 this.$$('add-printer-dialog').close(); 143 this.$$('add-printer-dialog').close();
116 this.fire('open-configuring-printer-dialog'); 144 this.fire('open-manufacturer-model-dialog');
117 }, 145 },
118 }); 146 });
119 147
120 Polymer({ 148 Polymer({
121 is: 'add-printer-manually-dialog', 149 is: 'add-printer-manually-dialog',
122 150
123 properties: { 151 properties: {
124 /** @type {!CupsPrinterInfo} */ 152 /** @type {!CupsPrinterInfo} */
125 newPrinter: { 153 newPrinter: {
126 type: Object, 154 type: Object,
127 notify: true, 155 notify: true,
128 value: function() { 156 value: getEmptyPrinter_
xdai1 2017/05/11 22:50:28 getEmptyPrinter_()?
Carlson 2017/05/11 23:57:11 I don't think so? https://www.polymer-project.or
xdai1 2017/05/12 00:30:43 Acknowledged.
129 return {
130 printerAddress: '',
131 printerDescription: '',
132 printerId: '',
133 printerManufacturer: '',
134 printerModel: '',
135 printerName: '',
136 printerPPDPath: '',
137 printerProtocol: 'ipp',
138 printerQueue: '',
139 printerStatus: '',
140 };
141 },
142 }, 157 },
143 }, 158 },
144 159
145 /** @private */ 160 /** @private */
146 switchToDiscoveryDialog_: function() { 161 switchToDiscoveryDialog_: function() {
147 this.$$('add-printer-dialog').close(); 162 this.$$('add-printer-dialog').close();
148 this.fire('open-discovery-printers-dialog'); 163 this.fire('open-discovery-printers-dialog');
149 }, 164 },
150 165
151 /** @private */ 166 /** @private */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 /** @type {?Array<string>} */ 207 /** @type {?Array<string>} */
193 manufacturerList: { 208 manufacturerList: {
194 type: Array, 209 type: Array,
195 }, 210 },
196 211
197 /** @type {?Array<string>} */ 212 /** @type {?Array<string>} */
198 modelList: { 213 modelList: {
199 type: Array, 214 type: Array,
200 }, 215 },
201 216
217 /** @type {string} */
218 previousDialog: String,
219
202 setupFailed: { 220 setupFailed: {
203 type: Boolean, 221 type: Boolean,
204 value: false, 222 value: false,
205 }, 223 },
206 }, 224 },
207 225
208 observers: [ 226 observers: [
209 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', 227 'selectedManufacturerChanged_(newPrinter.printerManufacturer)',
210 ], 228 ],
211 229
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 /** 274 /**
257 * @param {!ModelsInfo} modelsInfo 275 * @param {!ModelsInfo} modelsInfo
258 * @private 276 * @private
259 */ 277 */
260 modelListChanged_: function(modelsInfo) { 278 modelListChanged_: function(modelsInfo) {
261 if (modelsInfo.success) 279 if (modelsInfo.success)
262 this.modelList = modelsInfo.models; 280 this.modelList = modelsInfo.models;
263 }, 281 },
264 282
265 /** @private */ 283 /** @private */
266 switchToManualAddDialog_: function() { 284 switchToPreviousDialog_: function() {
267 this.$$('add-printer-dialog').close(); 285 this.$$('add-printer-dialog').close();
268 this.fire('open-manually-add-printer-dialog'); 286 if (this.previousDialog == AddPrinterDialogs.DISCOVERY) {
287 this.fire('open-discovery-printers-dialog');
288 } else if (this.previousDialog == AddPrinterDialogs.MANUALLY) {
289 this.fire('open-manually-add-printer-dialog');
290 }
269 }, 291 },
270 292
271 /** @private */ 293 /** @private */
272 onCancelTap_: function() { 294 onCancelTap_: function() {
273 this.$$('add-printer-dialog').close(); 295 this.$$('add-printer-dialog').close();
274 }, 296 },
275 297
276 /** @private */ 298 /** @private */
277 switchToConfiguringDialog_: function() { 299 switchToConfiguringDialog_: function() {
278 this.$$('add-printer-dialog').close(); 300 this.$$('add-printer-dialog').close();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 }, 336 },
315 }); 337 });
316 338
317 Polymer({ 339 Polymer({
318 is: 'settings-cups-add-printer-dialog', 340 is: 'settings-cups-add-printer-dialog',
319 341
320 behaviors: [WebUIListenerBehavior], 342 behaviors: [WebUIListenerBehavior],
321 343
322 properties: { 344 properties: {
323 /** @type {!CupsPrinterInfo} */ 345 /** @type {!CupsPrinterInfo} */
324 selectedPrinter: {
325 type: Object,
326 },
327
328 /** @type {!CupsPrinterInfo} */
329 newPrinter: { 346 newPrinter: {
330 type: Object, 347 type: Object,
331 }, 348 },
332 349
333 /** @type {boolean} whether the new printer setup is failed. */ 350 /** @type {boolean} whether the new printer setup is failed. */
334 setupFailed: { 351 setupFailed: {
335 type: Boolean, 352 type: Boolean,
336 value: false, 353 value: false,
337 }, 354 },
338 355
339 configuringDialogTitle: String, 356 configuringDialogTitle: String,
340 357
341 /** @private {string} */ 358 /** @type {string} */
342 previousDialog_: String, 359 previousDialog: String,
343 360
344 /** @private {string} */ 361 /** @private {string} */
345 currentDialog_: String, 362 currentDialog_: String,
346 363
347 /** @private {boolean} */ 364 /** @private {boolean} */
348 showDiscoveryDialog_: Boolean, 365 showDiscoveryDialog_: Boolean,
349 366
350 /** @private {boolean} */ 367 /** @private {boolean} */
351 showManuallyAddDialog_: Boolean, 368 showManuallyAddDialog_: Boolean,
352 369
(...skipping 13 matching lines...) Expand all
366 }, 383 },
367 384
368 /** @override */ 385 /** @override */
369 ready: function() { 386 ready: function() {
370 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); 387 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this));
371 }, 388 },
372 389
373 /** Opens the Add printer discovery dialog. */ 390 /** Opens the Add printer discovery dialog. */
374 open: function() { 391 open: function() {
375 this.resetData_(); 392 this.resetData_();
376 this.switchDialog_( 393 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_');
377 '', AddPrinterDialogs.MANUALLY, 'showManuallyAddDialog_');
378 }, 394 },
379 395
380 /** 396 /**
381 * Reset all the printer data in the Add printer flow. 397 * Reset all the printer data in the Add printer flow.
382 * @private 398 * @private
383 */ 399 */
384 resetData_: function() { 400 resetData_: function() {
385 if (this.selectedPrinter)
386 this.selectedPrinter = this.getEmptyPrinter_();
387 if (this.newPrinter) 401 if (this.newPrinter)
388 this.newPrinter = this.getEmptyPrinter_(); 402 this.newPrinter = getEmptyPrinter_();
389 this.setupFailed = false; 403 this.setupFailed = false;
390 }, 404 },
391 405
392 /**
393 * @return {!CupsPrinterInfo}
394 * @private
395 */
396 getEmptyPrinter_: function() {
397 return {
398 printerAddress: '',
399 printerDescription: '',
400 printerId: '',
401 printerManufacturer: '',
402 printerModel: '',
403 printerName: '',
404 printerPPDPath: '',
405 printerProtocol: 'ipp',
406 printerQueue: '',
407 printerStatus: '',
408 };
409 },
410
411 /** @private */ 406 /** @private */
412 openManuallyAddPrinterDialog_: function() { 407 openManuallyAddPrinterDialog_: function() {
413 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, 408 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY,
414 'showManuallyAddDialog_'); 409 'showManuallyAddDialog_');
415 }, 410 },
416 411
417 /** @private */ 412 /** @private */
418 openDiscoveryPrintersDialog_: function() { 413 openDiscoveryPrintersDialog_: function() {
419 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, 414 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY,
420 'showDiscoveryDialog_'); 415 'showDiscoveryDialog_');
421 }, 416 },
422 417
423 /** @private */ 418 /** @private */
424 openConfiguringPrinterDialog_: function() { 419 openConfiguringPrinterDialog_: function() {
425 this.switchDialog_( 420 this.switchDialog_(
xdai1 2017/05/11 22:50:28 After your change, the previous dialog for configu
Carlson 2017/05/11 23:57:11 That's true right now, but isn't the right thing i
xdai1 2017/05/12 00:30:43 Because the previous dialog will always be this.pr
Carlson 2017/05/12 17:12:46 Took me a while, but I understand now. I'm not su
xdai1 2017/05/12 17:56:55 Yes. I'm fine to file a bug for this.
Carlson 2017/05/12 18:14:09 Filed crbug/721841
426 this.currentDialog_, AddPrinterDialogs.CONFIGURING, 421 this.currentDialog_, AddPrinterDialogs.CONFIGURING,
427 'showConfiguringDialog_'); 422 'showConfiguringDialog_');
428 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { 423 if (this.previousDialog == AddPrinterDialogs.DISCOVERY) {
429 this.configuringDialogTitle = 424 this.configuringDialogTitle =
430 loadTimeData.getString('addPrintersNearbyTitle'); 425 loadTimeData.getString('addPrintersNearbyTitle');
431 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( 426 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter(
432 this.selectedPrinter); 427 this.selectedPrinter);
433 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 428 } else if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) {
434 this.configuringDialogTitle = 429 this.configuringDialogTitle =
435 loadTimeData.getString('addPrintersManuallyTitle'); 430 loadTimeData.getString('addPrintersManuallyTitle');
436 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( 431 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter(
437 this.newPrinter); 432 this.newPrinter);
438 } 433 }
439 }, 434 },
440 435
441 /** @private */ 436 /** @private */
442 openManufacturerModelDialog_: function() { 437 openManufacturerModelDialog_: function() {
443 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, 438 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
444 'showManufacturerDialog_'); 439 'showManufacturerDialog_');
445 }, 440 },
446 441
447 /** @private */ 442 /** @private */
448 configuringDialogClosed_: function() { 443 configuringDialogClosed_: function() {
449 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { 444 if (this.previousDialog == AddPrinterDialogs.MANUALLY) {
xdai1 2017/05/11 22:50:28 Same as above.
Carlson 2017/05/11 23:57:10 Same reply here. Eventually this will be needed a
xdai1 2017/05/12 00:30:43 Acknowledged.
Carlson 2017/05/12 17:12:46 Actually, this one is a real problem looking more
450 this.switchDialog_( 445 this.switchDialog_(
451 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); 446 this.currentDialog_, this.previousDialog, 'showManuallyAddDialog_');
452 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 447 } else if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) {
453 this.switchDialog_( 448 this.switchDialog_(
454 this.currentDialog_, this.previousDialog_, 'showManufacturerDialog_'); 449 this.currentDialog_, this.previousDialog, 'showManufacturerDialog_');
455 } 450 }
456 }, 451 },
457 452
458 /** 453 /**
459 * Switch dialog from |fromDialog| to |toDialog|. 454 * Switch dialog from |fromDialog| to |toDialog|.
460 * @param {string} fromDialog 455 * @param {string} fromDialog
461 * @param {string} toDialog 456 * @param {string} toDialog
462 * @param {string} domIfBooleanName The name of the boolean variable 457 * @param {string} domIfBooleanName The name of the boolean variable
463 * corresponding to the |toDialog|. 458 * corresponding to the |toDialog|.
464 * @private 459 * @private
465 */ 460 */
466 switchDialog_: function(fromDialog, toDialog, domIfBooleanName) { 461 switchDialog_: function(fromDialog, toDialog, domIfBooleanName) {
467 this.previousDialog_ = fromDialog; 462 this.previousDialog = fromDialog;
468 this.currentDialog_ = toDialog; 463 this.currentDialog_ = toDialog;
469 464
470 this.set(domIfBooleanName, true); 465 this.set(domIfBooleanName, true);
471 this.async(function() { 466 this.async(function() {
472 var dialog = this.$$(toDialog); 467 var dialog = this.$$(toDialog);
473 dialog.addEventListener('close', function() { 468 dialog.addEventListener('close', function() {
474 this.set(domIfBooleanName, false); 469 this.set(domIfBooleanName, false);
475 }.bind(this)); 470 }.bind(this));
476 }); 471 });
477 }, 472 },
478 473
479 /** 474 /**
480 * @return {string} The name of the current printer in configuration. 475 * @return {string} The name of the current printer in configuration.
481 * @private 476 * @private
482 */ 477 */
483 getConfiguringPrinterName_: function() { 478 getConfiguringPrinterName_: function() {
xdai1 2017/05/11 22:50:28 This function can be removed now. And in configuri
Carlson 2017/05/11 23:57:10 Good point, done.
484 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) 479 if (this.previousDialog == AddPrinterDialogs.DISCOVERY ||
485 return this.selectedPrinter.printerName; 480 this.previousDialog == AddPrinterDialogs.MANUALLY ||
486 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || 481 this.previousDialog == AddPrinterDialogs.MANUFACTURER) {
487 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
488 return this.newPrinter.printerName; 482 return this.newPrinter.printerName;
489 } 483 }
490 return ''; 484 return '';
491 }, 485 },
492 486
493 /** 487 /**
494 * @param {boolean} success 488 * @param {boolean} success
495 * @param {string} printerName 489 * @param {string} printerName
496 * @private 490 * @private
497 */ 491 */
498 onAddPrinter_: function(success, printerName) { 492 onAddPrinter_: function(success, printerName) {
499 this.$$('add-printer-configuring-dialog').close(); 493 this.$$('add-printer-configuring-dialog').close();
500 if (success) 494 if (success)
501 return; 495 return;
502 496
503 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 497 if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) {
504 this.setupFailed = true; 498 this.setupFailed = true;
505 } 499 }
506 }, 500 },
507 }); 501 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698