Index: chrome/browser/resources/print_preview/native_layer.js |
diff --git a/chrome/browser/resources/print_preview/native_layer.js b/chrome/browser/resources/print_preview/native_layer.js |
index d4beb8926afb27fd2400ba4f8f52f222d76fc2be..d61da749dd9ed820019ba61474f7042017f6cbc4 100644 |
--- a/chrome/browser/resources/print_preview/native_layer.js |
+++ b/chrome/browser/resources/print_preview/native_layer.js |
@@ -36,6 +36,8 @@ cr.define('print_preview', function() { |
this.onFailedToGetPrinterCapabilities_.bind(this); |
global.failedToGetPrivetPrinterCapabilities = |
this.onFailedToGetPrivetPrinterCapabilities_.bind(this); |
+ global.failedToGetExtensionPrinterCapabilities = |
+ this.onFailedToGetExtensionPrinterCapabilities_.bind(this); |
global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
global.printToCloud = this.onPrintToCloud_.bind(this); |
global.fileSelectionCancelled = |
@@ -57,6 +59,10 @@ cr.define('print_preview', function() { |
global.onPrivetCapabilitiesSet = |
this.onPrivetCapabilitiesSet_.bind(this); |
global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this); |
+ global.onExtensionPrintersAdded = |
+ this.onExtensionPrintersAdded_.bind(this); |
+ global.onExtensionCapabilitiesSet = |
+ this.onExtensionCapabilitiesSet_.bind(this); |
global.onEnableManipulateSettingsForTest = |
this.onEnableManipulateSettingsForTest_.bind(this); |
global.printPresetOptionsFromDocument = |
@@ -95,6 +101,10 @@ cr.define('print_preview', function() { |
PRIVET_CAPABILITIES_SET: |
'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', |
PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', |
+ EXTENSION_PRINTERS_ADDED: |
+ 'print_preview.NativeLayer.EXTENSION_PRINTERS_ADDED', |
+ EXTENSION_CAPABILITIES_SET: |
+ 'print_preview.NativeLayer.EXTENSION_CAPABILITIES_SET', |
PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', |
}; |
@@ -177,6 +187,24 @@ cr.define('print_preview', function() { |
}, |
/** |
+ * Requests that extension system dispatches an event requesting the list of |
+ * extension managed printers. |
+ */ |
+ startGetExtensionDestinations: function() { |
+ chrome.send('getExtensionPrinters'); |
+ }, |
+ |
+ /** |
+ * Requests an extension destination's printing capabilities. A |
+ * EXTENSION_CAPABILITIES_SET event will be dispatched in response. |
+ * @param {string} destinationId The ID of the destination whose |
+ * capabilities are requested. |
+ */ |
+ startGetExtensionDestinationCapabilities: function(destinationId) { |
+ chrome.send('getExtensionPrinterCapabilities', [destinationId]); |
+ }, |
+ |
+ /** |
* Requests the destination's printing capabilities. A CAPABILITIES_SET |
* event will be dispatched in response. |
* @param {string} destinationId ID of the destination. |
@@ -299,6 +327,10 @@ cr.define('print_preview', function() { |
assert(!opt_showSystemDialog || (cr.isWindows && destination.isLocal), |
'Implemented for Windows only'); |
+ // TODO(tbarzic): Implement this. |
+ assert(!destination.isExtension, |
+ 'Printing to extension printers not yet implemented.'); |
+ |
var ticket = { |
'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
'mediaSize': printTicketStore.mediaSize.getValue(), |
@@ -514,6 +546,21 @@ cr.define('print_preview', function() { |
this.dispatchEvent(getCapsFailEvent); |
}, |
+ /** |
+ * Called when native layer fails to get settings information for a |
+ * requested extension destination. |
+ * @param {string} destinationId Printer affected by error. |
+ * @private |
+ */ |
+ onFailedToGetExtensionPrinterCapabilities_: function(destinationId) { |
+ var getCapsFailEvent = new Event( |
+ NativeLayer.EventType.GET_CAPABILITIES_FAIL); |
+ getCapsFailEvent.destinationId = destinationId; |
+ getCapsFailEvent.destinationOrigin = |
+ print_preview.Destination.Origin.EXTENSION; |
+ this.dispatchEvent(getCapsFailEvent); |
+ }, |
+ |
/** Reloads the printer list. */ |
onReloadPrintersList_: function() { |
cr.dispatchSimpleEvent(this, NativeLayer.EventType.DESTINATIONS_RELOAD); |
@@ -720,6 +767,36 @@ cr.define('print_preview', function() { |
}, |
/** |
+ * @param {Array.<!{extensionId: string, |
+ * id: string, |
+ * name: string, |
+ * description: (string|undefined)}>} printers The list |
+ * containing information about printers added by an extension. |
+ * @param {boolean} done Whether this is the final list of extension |
+ * managed printers. |
+ */ |
+ onExtensionPrintersAdded_: function(printers, done) { |
+ var event = new Event(NativeLayer.EventType.EXTENSION_PRINTERS_ADDED); |
+ event.printers = printers; |
+ event.done = done; |
+ this.dispatchEvent(event); |
+ }, |
+ |
+ /** |
+ * Called when an extension responds to a request for an extension printer |
+ * capabilities. |
+ * @param {string} printerId The printer's ID. |
+ * @param {!Object} capabilities The reported printer capabilities. |
+ */ |
+ onExtensionCapabilitiesSet_: function(printerId, |
+ capabilities) { |
+ var event = new Event(NativeLayer.EventType.EXTENSION_CAPABILITIES_SET); |
+ event.printerId = printerId; |
+ event.capabilities = capabilities; |
+ this.dispatchEvent(event); |
+ }, |
+ |
+ /** |
* Allows for onManipulateSettings to be called |
* from the native layer. |
* @private |