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

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

Issue 2915703002: Query printers for autoconf info during setup. (Closed)
Patch Set: close the right dialog Created 3 years, 6 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 22 matching lines...) Expand all
33 */ 33 */
34 var kPrinterListFullHeight = 350; 34 var kPrinterListFullHeight = 350;
35 35
36 /** 36 /**
37 * Return a reset CupsPrinterInfo object. 37 * Return a reset CupsPrinterInfo object.
38 * @return {!CupsPrinterInfo} 38 * @return {!CupsPrinterInfo}
39 */ 39 */
40 function getEmptyPrinter_() { 40 function getEmptyPrinter_() {
41 return { 41 return {
42 printerAddress: '', 42 printerAddress: '',
43 printerAutoconf: false,
43 printerDescription: '', 44 printerDescription: '',
44 printerId: '', 45 printerId: '',
45 printerManufacturer: '', 46 printerManufacturer: '',
46 printerModel: '', 47 printerModel: '',
47 printerName: '', 48 printerName: '',
48 printerPPDPath: '', 49 printerPPDPath: '',
49 printerProtocol: 'ipp', 50 printerProtocol: 'ipp',
50 printerQueue: '', 51 printerQueue: '',
51 printerStatus: '', 52 printerStatus: '',
52 }; 53 };
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 this.$$('add-printer-dialog').close(); 163 this.$$('add-printer-dialog').close();
163 this.fire('open-discovery-printers-dialog'); 164 this.fire('open-discovery-printers-dialog');
164 }, 165 },
165 166
166 /** @private */ 167 /** @private */
167 onCancelTap_: function() { 168 onCancelTap_: function() {
168 this.$$('add-printer-dialog').close(); 169 this.$$('add-printer-dialog').close();
169 }, 170 },
170 171
171 /** @private */ 172 /** @private */
172 switchToManufacturerDialog_: function() { 173 addPressed_: function() {
173 // Set the default printer queue to be "ipp/print". 174 // Set the default printer queue to be "ipp/print".
174 if (!this.newPrinter.printerQueue) 175 if (!this.newPrinter.printerQueue) {
175 this.set('newPrinter.printerQueue', 'ipp/print'); 176 this.set('newPrinter.printerQueue', 'ipp/print');
177 } else if (this.newPrinter.printerQueue.charAt(0) == '/') {
178 // Strip a leading backslashes. It is expected that this results in an
stevenjb 2017/06/08 15:58:28 s/a leading backslashes/the leading backslash/ Al
skau 2017/06/08 22:11:26 It's not for UI presentation. It's been moved int
179 // empty string if the input is just a backslash.
180 this.set('newPrinter.printerQueue',
181 this.newPrinter.printerQueue.substring(1));
182 }
176 183
177 this.$$('add-printer-dialog').close(); 184 this.$$('add-printer-dialog').close();
178 this.fire('open-manufacturer-model-dialog'); 185 this.fire('open-configuring-printer-dialog');
179 }, 186 },
180 187
181 /** @private */ 188 /** @private */
182 onAddressChanged_: function() { 189 onAddressChanged_: function() {
183 // TODO(xdai): Check if the printer address exists and then show the 190 // TODO(xdai): Check if the printer address exists and then show the
184 // corresponding message after the API is ready. 191 // corresponding message after the API is ready.
185 // The format of address is: ip-address-or-hostname:port-number. 192 // The format of address is: ip-address-or-hostname:port-number.
186 }, 193 },
187 194
188 /** 195 /**
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 'showManuallyAddDialog_'); 416 'showManuallyAddDialog_');
410 }, 417 },
411 418
412 /** @private */ 419 /** @private */
413 openDiscoveryPrintersDialog_: function() { 420 openDiscoveryPrintersDialog_: function() {
414 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, 421 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY,
415 'showDiscoveryDialog_'); 422 'showDiscoveryDialog_');
416 }, 423 },
417 424
418 /** @private */ 425 /** @private */
426 addPrinter_: function() {
427 settings.CupsPrintersBrowserProxyImpl.getInstance().
428 addCupsPrinter(this.newPrinter);
429 },
430
431 /**
432 * Handler for getPrinterInfo success.
433 * @param {!PrinterMakeModel} info
434 * @private
435 * */
436 onPrinterFound_: function(info) {
437 this.newPrinter.printerAutoconf = info.autoconf;
438 this.newPrinter.printerManufacturer = info.manufacturer;
439 this.newPrinter.printerModel = info.model;
440
441 // Add the printer if it's configurable. Otherwise, forward to the
442 // manufacturer dialog.
443 if (this.newPrinter.printerAutoconf) {
444 this.addPrinter_();
445 } else {
446 this.$$('add-printer-configuring-dialog').close();
447 this.fire('open-manufacturer-model-dialog');
448 }
449 },
450
451 /**
452 * Handler for getPrinterInfo failure.
453 * @param {!QueryFailure} rejected
454 * @private
455 */
456 infoFailed_: function(rejected) {
457 this.$$('add-printer-configuring-dialog').close();
458 this.fire('open-manufacturer-model-dialog');
459 },
460
461 /** @private */
419 openConfiguringPrinterDialog_: function() { 462 openConfiguringPrinterDialog_: function() {
420 this.switchDialog_( 463 this.switchDialog_(
421 this.currentDialog_, AddPrinterDialogs.CONFIGURING, 464 this.currentDialog_, AddPrinterDialogs.CONFIGURING,
422 'showConfiguringDialog_'); 465 'showConfiguringDialog_');
423 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { 466 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) {
424 this.configuringDialogTitle = 467 this.configuringDialogTitle =
425 loadTimeData.getString('addPrintersNearbyTitle'); 468 loadTimeData.getString('addPrintersNearbyTitle');
426 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( 469 this.addPrinter_();
427 this.newPrinter); 470 } else if (
428 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 471 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
429 this.configuringDialogTitle = 472 this.configuringDialogTitle =
430 loadTimeData.getString('addPrintersManuallyTitle'); 473 loadTimeData.getString('addPrintersManuallyTitle');
431 settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( 474 this.addPrinter_();
432 this.newPrinter); 475 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) {
476 this.configuringDialogTitle =
477 loadTimeData.getString('addPrintersManuallyTitle');
478 if (this.newPrinter.printerProtocol == 'ipp' ||
479 this.newPrinter.printerProtocol == 'ipps') {
480 settings.CupsPrintersBrowserProxyImpl.getInstance().
481 getPrinterInfo(this.newPrinter).
stevenjb 2017/06/08 15:58:27 Does getPrinterInfo ever return an error (e.g. if
skau 2017/06/08 22:11:26 No. If there's an error in getPrinterInfo, we rej
482 then(
483 this.onPrinterFound_.bind(this), this.infoFailed_.bind(this));
484 } else {
485 this.$$('add-printer-configuring-dialog').close();
486 this.fire('open-manufacturer-model-dialog');
stevenjb 2017/06/08 15:58:27 Looks like we do these two things in several place
skau 2017/06/08 22:11:26 Done.
487 }
433 } 488 }
434 }, 489 },
435 490
436 /** @private */ 491 /** @private */
437 openManufacturerModelDialog_: function() { 492 openManufacturerModelDialog_: function() {
438 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, 493 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
439 'showManufacturerDialog_'); 494 'showManufacturerDialog_');
440 }, 495 },
441 496
442 /** @private */ 497 /** @private */
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 onAddPrinter_: function(success, printerName) { 543 onAddPrinter_: function(success, printerName) {
489 this.$$('add-printer-configuring-dialog').close(); 544 this.$$('add-printer-configuring-dialog').close();
490 if (success) 545 if (success)
491 return; 546 return;
492 547
493 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { 548 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
494 this.setupFailed = true; 549 this.setupFailed = true;
495 } 550 }
496 }, 551 },
497 }); 552 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698