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

Unified Diff: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js

Issue 2380753004: [CUPS] Implement the Webui handler for the printers auto discovery. (Closed)
Patch Set: Rebase Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
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 e27685ae8d6bdcefa78c01d3cc26d098e3a592ee..ba7cd363c1b22d54a521bbe59e943b8dbb4b25dc 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
@@ -26,11 +26,19 @@ var AddPrinterDialogs = {
MANUFACTURER: 'add-printer-manufacturer-model-dialog',
};
+/**
+ * The maximum height of the discovered printers list when the searching spinner
+ * is not showing.
michaelpg 2016/10/04 22:31:10 @const {number}
xdai1 2016/10/04 23:36:19 Done.
+ */
+var printerListFullHeight = 350;
michaelpg 2016/10/04 22:31:10 kPrinterListFullHeight or PRINTER_LIST_FULL_HEIGHT
xdai1 2016/10/04 23:36:19 Done.
+
Polymer({
is: 'add-printer-discovery-dialog',
+ behaviors: [WebUIListenerBehavior],
+
properties: {
- /** @type {!Array<!CupsPrinterInfo>} */
+ /** @type {!Array<!CupsPrinterInfo>|undefined} */
discoveredPrinters: {
type: Array,
},
@@ -40,26 +48,71 @@ Polymer({
type: Object,
notify: true,
},
+
+ discovering_: {
+ type: Boolean,
+ value: false,
+ },
},
/** @override */
ready: function() {
- // TODO(xdai): Get the discovered printer list after the API is ready.
+ this.discovering_ = true;
michaelpg 2016/10/04 22:31:10 Why not set the initial value to true, above?
xdai1 2016/10/04 23:36:19 Done.
+ settings.CupsPrintersBrowserProxyImpl.getInstance().
+ startDiscoveringPrinters();
+ this.addWebUIListener('on-printer-discovered',
+ this.onPrinterDiscovered_.bind(this));
+ this.addWebUIListener('on-printer-discovery-done',
+ this.onPrinterDiscoveryDone_.bind(this));
+ this.addWebUIListener('on-printer-discovery-failed',
+ this.onPrinterDiscoveryDone_.bind(this));
+ },
+
+ /**
+ * @param {!Array<!CupsPrinterInfo>} printers
+ * @private
+ */
+ onPrinterDiscovered_: function(printers) {
+ this.discovering_ = true;
+ if (!this.discoveredPrinters)
+ this.discoveredPrinters = printers;
+ else
+ this.discoveredPrinters = this.discoveredPrinters.concat(printers);
michaelpg 2016/10/04 22:31:10 instead of replacing the whole array (which might
xdai1 2016/10/04 23:36:19 Seems like it could not push back a CupsPrinterInf
+ },
+
+ /** @private */
+ onPrinterDiscoveryDone_: function() {
+ this.discovering_ = false;
+ this.$$('add-printer-list').style.maxHeight = printerListFullHeight + 'px';
+ if (!this.discoveredPrinters)
+ this.$.noPrinterMessage.hidden = false;
michaelpg 2016/10/04 22:31:10 this.$.nPM.hidden = !!this.discoveredPrinters;
xdai1 2016/10/04 23:36:19 Done.
+ else
+ this.$.noPrinterMessage.hidden = true;
+ },
+
+ /** @private */
+ stopDiscoveringPrinters_: function() {
+ settings.CupsPrintersBrowserProxyImpl.getInstance().
+ stopDiscoveringPrinters();
+ this.discovering_ = false;
},
/** @private */
switchToManualAddDialog_: function() {
+ this.stopDiscoveringPrinters_();
this.$$('add-printer-dialog').close();
this.fire('open-manually-add-printer-dialog');
},
/** @private */
onCancelTap_: function() {
+ this.stopDiscoveringPrinters_();
this.$$('add-printer-dialog').close();
},
/** @private */
switchToConfiguringDialog_: function() {
+ this.stopDiscoveringPrinters_();
this.$$('add-printer-dialog').close();
this.fire('open-configuring-printer-dialog');
},
@@ -329,8 +382,14 @@ Polymer({
openConfiguringPrinterDialog_: function() {
this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING,
'showConfiguringDialog_');
- settings.CupsPrintersBrowserProxyImpl.getInstance().
- addCupsPrinter(this.newPrinter);
+ if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) {
+ settings.CupsPrintersBrowserProxyImpl.getInstance().
+ addCupsPrinter(this.selectedPrinter);
+ } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY ||
+ this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
+ settings.CupsPrintersBrowserProxyImpl.getInstance().
+ addCupsPrinter(this.newPrinter);
+ }
},
/** @private */
@@ -398,9 +457,11 @@ Polymer({
if (success)
return;
- if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER)
+ if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
this.setupFailed = true;
- this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
- 'showManufacturerDialog_');
+ } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) {
+ this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
+ 'showManufacturerDialog_');
+ }
},
});

Powered by Google App Engine
This is Rietveld 408576698