| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.exportPath('print_preview'); | 5 cr.exportPath('print_preview'); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @typedef {{selectSaveAsPdfDestination: boolean, | 8 * @typedef {{selectSaveAsPdfDestination: boolean, |
| 9 * layoutSettings.portrait: boolean, | 9 * layoutSettings.portrait: boolean, |
| 10 * pageRange: string, | 10 * pageRange: string, |
| 11 * headersAndFooters: boolean, | 11 * headersAndFooters: boolean, |
| 12 * backgroundColorsAndImages: boolean, | 12 * backgroundColorsAndImages: boolean, |
| 13 * margins: number}} | 13 * margins: number}} |
| 14 * @see chrome/browser/printing/print_preview_pdf_generated_browsertest.cc | 14 * @see chrome/browser/printing/print_preview_pdf_generated_browsertest.cc |
| 15 */ | 15 */ |
| 16 print_preview.PreviewSettings; | 16 print_preview.PreviewSettings; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * @typedef {{ | 19 * @typedef {{ |
| 20 * deviceName: string, |
| 21 * printerName: string, |
| 22 * printerDescription: (string | undefined), |
| 23 * cupsEnterprisePrinter: (boolean | undefined), |
| 24 * printerOptions: (Object | undefined), |
| 25 * }} |
| 26 */ |
| 27 print_preview.LocalDestinationInfo; |
| 28 |
| 29 /** |
| 30 * @typedef {{ |
| 20 * printerId: string, | 31 * printerId: string, |
| 21 * success: boolean, | 32 * success: boolean, |
| 22 * capabilities: Object, | 33 * capabilities: Object, |
| 23 * }} | 34 * }} |
| 24 */ | 35 */ |
| 25 print_preview.PrinterSetupResponse; | 36 print_preview.PrinterSetupResponse; |
| 26 | 37 |
| 27 cr.define('print_preview', function() { | 38 cr.define('print_preview', function() { |
| 28 'use strict'; | 39 'use strict'; |
| 29 | 40 |
| 30 /** | 41 /** |
| 31 * An interface to the native Chromium printing system layer. | 42 * An interface to the native Chromium printing system layer. |
| 32 * @constructor | 43 * @constructor |
| 33 */ | 44 */ |
| 34 function NativeLayer() { | 45 function NativeLayer() { |
| 35 // Bind global handlers | 46 // Bind global handlers |
| 36 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); | 47 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); |
| 37 global.setPrinters = this.onSetPrinters_.bind(this); | |
| 38 global.updateWithPrinterCapabilities = | 48 global.updateWithPrinterCapabilities = |
| 39 this.onUpdateWithPrinterCapabilities_.bind(this); | 49 this.onUpdateWithPrinterCapabilities_.bind(this); |
| 40 global.failedToGetPrinterCapabilities = | 50 global.failedToGetPrinterCapabilities = |
| 41 this.onFailedToGetPrinterCapabilities_.bind(this); | 51 this.onFailedToGetPrinterCapabilities_.bind(this); |
| 42 global.failedToGetPrivetPrinterCapabilities = | 52 global.failedToGetPrivetPrinterCapabilities = |
| 43 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); | 53 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); |
| 44 global.failedToGetExtensionPrinterCapabilities = | 54 global.failedToGetExtensionPrinterCapabilities = |
| 45 this.onFailedToGetExtensionPrinterCapabilities_.bind(this); | 55 this.onFailedToGetExtensionPrinterCapabilities_.bind(this); |
| 46 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); | 56 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
| 47 global.printToCloud = this.onPrintToCloud_.bind(this); | 57 global.printToCloud = this.onPrintToCloud_.bind(this); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 initialSettings['shouldPrintSelectionOnly'] || false, | 223 initialSettings['shouldPrintSelectionOnly'] || false, |
| 214 initialSettings['printerName'] || null, | 224 initialSettings['printerName'] || null, |
| 215 initialSettings['appState'] || null, | 225 initialSettings['appState'] || null, |
| 216 initialSettings['defaultDestinationSelectionRules'] || null); | 226 initialSettings['defaultDestinationSelectionRules'] || null); |
| 217 }); | 227 }); |
| 218 }, | 228 }, |
| 219 | 229 |
| 220 /** | 230 /** |
| 221 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET | 231 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET |
| 222 * event will be dispatched in response. | 232 * event will be dispatched in response. |
| 233 * @return {!Promise<!Array<print_preview.LocalDestinationInfo>>} |
| 223 */ | 234 */ |
| 224 startGetLocalDestinations: function() { | 235 getPrinters: function() { |
| 225 chrome.send('getPrinters'); | 236 return cr.sendWithPromise('getPrinters'); |
| 226 }, | 237 }, |
| 227 | 238 |
| 228 /** | 239 /** |
| 229 * Requests the network's privet print destinations. A number of | 240 * Requests the network's privet print destinations. A number of |
| 230 * PRIVET_PRINTER_CHANGED events will be fired in response, followed by a | 241 * PRIVET_PRINTER_CHANGED events will be fired in response, followed by a |
| 231 * PRIVET_SEARCH_ENDED. | 242 * PRIVET_SEARCH_ENDED. |
| 232 */ | 243 */ |
| 233 startGetPrivetDestinations: function() { | 244 startGetPrivetDestinations: function() { |
| 234 chrome.send('getPrivetPrinters'); | 245 chrome.send('getPrivetPrinters'); |
| 235 }, | 246 }, |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 */ | 554 */ |
| 544 onSetUseCloudPrint_: function(settings) { | 555 onSetUseCloudPrint_: function(settings) { |
| 545 var cloudPrintEnableEvent = new Event( | 556 var cloudPrintEnableEvent = new Event( |
| 546 NativeLayer.EventType.CLOUD_PRINT_ENABLE); | 557 NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| 547 cloudPrintEnableEvent.baseCloudPrintUrl = settings['cloudPrintUrl'] || ''; | 558 cloudPrintEnableEvent.baseCloudPrintUrl = settings['cloudPrintUrl'] || ''; |
| 548 cloudPrintEnableEvent.appKioskMode = settings['appKioskMode'] || false; | 559 cloudPrintEnableEvent.appKioskMode = settings['appKioskMode'] || false; |
| 549 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent); | 560 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent); |
| 550 }, | 561 }, |
| 551 | 562 |
| 552 /** | 563 /** |
| 553 * Updates the print preview with local printers. | |
| 554 * Called from PrintPreviewHandler::SetupPrinterList(). | |
| 555 * @param {Array} printers Array of printer info objects. | |
| 556 * @private | |
| 557 */ | |
| 558 onSetPrinters_: function(printers) { | |
| 559 var localDestsSetEvent = new Event( | |
| 560 NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 561 localDestsSetEvent.destinationInfos = printers; | |
| 562 this.eventTarget_.dispatchEvent(localDestsSetEvent); | |
| 563 }, | |
| 564 | |
| 565 /** | |
| 566 * Called when native layer gets settings information for a requested local | 564 * Called when native layer gets settings information for a requested local |
| 567 * destination. | 565 * destination. |
| 568 * @param {Object} settingsInfo printer setting information. | 566 * @param {Object} settingsInfo printer setting information. |
| 569 * @private | 567 * @private |
| 570 */ | 568 */ |
| 571 onUpdateWithPrinterCapabilities_: function(settingsInfo) { | 569 onUpdateWithPrinterCapabilities_: function(settingsInfo) { |
| 572 assert(settingsInfo.capabilities, | 570 assert(settingsInfo.capabilities, |
| 573 'Capabilities update without capabilites'); | 571 'Capabilities update without capabilites'); |
| 574 var capsSetEvent = new Event(NativeLayer.EventType.CAPABILITIES_SET); | 572 var capsSetEvent = new Event(NativeLayer.EventType.CAPABILITIES_SET); |
| 575 capsSetEvent.settingsInfo = settingsInfo; | 573 capsSetEvent.settingsInfo = settingsInfo; |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 return this.serializedDefaultDestinationSelectionRulesStr_; | 1114 return this.serializedDefaultDestinationSelectionRulesStr_; |
| 1117 } | 1115 } |
| 1118 }; | 1116 }; |
| 1119 | 1117 |
| 1120 // Export | 1118 // Export |
| 1121 return { | 1119 return { |
| 1122 NativeInitialSettings: NativeInitialSettings, | 1120 NativeInitialSettings: NativeInitialSettings, |
| 1123 NativeLayer: NativeLayer | 1121 NativeLayer: NativeLayer |
| 1124 }; | 1122 }; |
| 1125 }); | 1123 }); |
| OLD | NEW |