Chromium Code Reviews| Index: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| diff --git a/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js b/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| index 8e1d7de443205c16582434c5e374fa71b1a13b89..0bde662ff593489ca4901fbfdf0284a30944306a 100644 |
| --- a/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| +++ b/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js |
| @@ -40,6 +40,7 @@ var kPrinterListFullHeight = 350; |
| function getEmptyPrinter_() { |
| return { |
| printerAddress: '', |
| + printerAutoconf: false, |
| printerDescription: '', |
| printerId: '', |
| printerManufacturer: '', |
| @@ -169,13 +170,19 @@ Polymer({ |
| }, |
| /** @private */ |
| - switchToManufacturerDialog_: function() { |
| + addPressed_: function() { |
| // Set the default printer queue to be "ipp/print". |
| - if (!this.newPrinter.printerQueue) |
| + if (!this.newPrinter.printerQueue) { |
| this.set('newPrinter.printerQueue', 'ipp/print'); |
| + } else if (this.newPrinter.printerQueue.charAt(0) == '/') { |
| + // 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
|
| + // empty string if the input is just a backslash. |
| + this.set('newPrinter.printerQueue', |
| + this.newPrinter.printerQueue.substring(1)); |
| + } |
| this.$$('add-printer-dialog').close(); |
| - this.fire('open-manufacturer-model-dialog'); |
| + this.fire('open-configuring-printer-dialog'); |
| }, |
| /** @private */ |
| @@ -415,6 +422,42 @@ Polymer({ |
| 'showDiscoveryDialog_'); |
| }, |
| + /** @private */ |
| + addPrinter_: function() { |
| + settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| + addCupsPrinter(this.newPrinter); |
| + }, |
| + |
| + /** |
| + * Handler for getPrinterInfo success. |
| + * @param {!PrinterMakeModel} info |
| + * @private |
| + * */ |
| + onPrinterFound_: function(info) { |
| + this.newPrinter.printerAutoconf = info.autoconf; |
| + this.newPrinter.printerManufacturer = info.manufacturer; |
| + this.newPrinter.printerModel = info.model; |
| + |
| + // Add the printer if it's configurable. Otherwise, forward to the |
| + // manufacturer dialog. |
| + if (this.newPrinter.printerAutoconf) { |
| + this.addPrinter_(); |
| + } else { |
| + this.$$('add-printer-configuring-dialog').close(); |
| + this.fire('open-manufacturer-model-dialog'); |
| + } |
| + }, |
| + |
| + /** |
| + * Handler for getPrinterInfo failure. |
| + * @param {!QueryFailure} rejected |
| + * @private |
| + */ |
| + infoFailed_: function(rejected) { |
| + this.$$('add-printer-configuring-dialog').close(); |
| + this.fire('open-manufacturer-model-dialog'); |
| + }, |
| + |
| /** @private */ |
| openConfiguringPrinterDialog_: function() { |
| this.switchDialog_( |
| @@ -423,13 +466,25 @@ Polymer({ |
| if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { |
| this.configuringDialogTitle = |
| loadTimeData.getString('addPrintersNearbyTitle'); |
| - settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
| - this.newPrinter); |
| - } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| + this.addPrinter_(); |
| + } else if ( |
| + this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
| + this.configuringDialogTitle = |
| + loadTimeData.getString('addPrintersManuallyTitle'); |
| + this.addPrinter_(); |
| + } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { |
| this.configuringDialogTitle = |
| loadTimeData.getString('addPrintersManuallyTitle'); |
| - settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter( |
| - this.newPrinter); |
| + if (this.newPrinter.printerProtocol == 'ipp' || |
| + this.newPrinter.printerProtocol == 'ipps') { |
| + settings.CupsPrintersBrowserProxyImpl.getInstance(). |
| + 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
|
| + then( |
| + this.onPrinterFound_.bind(this), this.infoFailed_.bind(this)); |
| + } else { |
| + this.$$('add-printer-configuring-dialog').close(); |
| + 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.
|
| + } |
| } |
| }, |