Chromium Code Reviews| 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, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 global.onExtensionCapabilitiesSet = | 64 global.onExtensionCapabilitiesSet = |
| 65 this.onExtensionCapabilitiesSet_.bind(this); | 65 this.onExtensionCapabilitiesSet_.bind(this); |
| 66 global.onEnableManipulateSettingsForTest = | 66 global.onEnableManipulateSettingsForTest = |
| 67 this.onEnableManipulateSettingsForTest_.bind(this); | 67 this.onEnableManipulateSettingsForTest_.bind(this); |
| 68 global.printPresetOptionsFromDocument = | 68 global.printPresetOptionsFromDocument = |
| 69 this.onPrintPresetOptionsFromDocument_.bind(this); | 69 this.onPrintPresetOptionsFromDocument_.bind(this); |
| 70 global.onProvisionalPrinterResolved = | 70 global.onProvisionalPrinterResolved = |
| 71 this.onProvisionalDestinationResolved_.bind(this); | 71 this.onProvisionalDestinationResolved_.bind(this); |
| 72 global.failedToResolveProvisionalPrinter = | 72 global.failedToResolveProvisionalPrinter = |
| 73 this.failedToResolveProvisionalDestination_.bind(this); | 73 this.failedToResolveProvisionalDestination_.bind(this); |
| 74 global.onPrinterSetup = this.onPrinterSetupResolved_.bind(this); | |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 /** | 77 /** |
| 77 * Event types dispatched from the Chromium native layer. | 78 * Event types dispatched from the Chromium native layer. |
| 78 * @enum {string} | 79 * @enum {string} |
| 79 * @const | 80 * @const |
| 80 */ | 81 */ |
| 81 NativeLayer.EventType = { | 82 NativeLayer.EventType = { |
| 82 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | 83 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', |
| 83 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', | 84 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 104 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', | 105 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', |
| 105 PRIVET_CAPABILITIES_SET: | 106 PRIVET_CAPABILITIES_SET: |
| 106 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', | 107 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', |
| 107 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', | 108 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', |
| 108 EXTENSION_PRINTERS_ADDED: | 109 EXTENSION_PRINTERS_ADDED: |
| 109 'print_preview.NativeLayer.EXTENSION_PRINTERS_ADDED', | 110 'print_preview.NativeLayer.EXTENSION_PRINTERS_ADDED', |
| 110 EXTENSION_CAPABILITIES_SET: | 111 EXTENSION_CAPABILITIES_SET: |
| 111 'print_preview.NativeLayer.EXTENSION_CAPABILITIES_SET', | 112 'print_preview.NativeLayer.EXTENSION_CAPABILITIES_SET', |
| 112 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', | 113 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', |
| 113 PROVISIONAL_DESTINATION_RESOLVED: | 114 PROVISIONAL_DESTINATION_RESOLVED: |
| 114 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED' | 115 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED', |
| 116 PRINTER_SETUP: 'print_preview.NativeLayer.PRINTER_SETUP' | |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 /** | 119 /** |
| 118 * Constant values matching printing::DuplexMode enum. | 120 * Constant values matching printing::DuplexMode enum. |
| 119 * @enum {number} | 121 * @enum {number} |
| 120 */ | 122 */ |
| 121 NativeLayer.DuplexMode = { | 123 NativeLayer.DuplexMode = { |
| 122 SIMPLEX: 0, | 124 SIMPLEX: 0, |
| 123 LONG_EDGE: 1, | 125 LONG_EDGE: 1, |
| 124 UNKNOWN_DUPLEX_MODE: -1 | 126 UNKNOWN_DUPLEX_MODE: -1 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 * the resolved destination properties by calling | 227 * the resolved destination properties by calling |
| 226 * {@code onProvisionalPrinterResolved}, or in case of an error | 228 * {@code onProvisionalPrinterResolved}, or in case of an error |
| 227 * {@code failedToResolveProvisionalPrinter} | 229 * {@code failedToResolveProvisionalPrinter} |
| 228 * @param {string} provisionalDestinationId | 230 * @param {string} provisionalDestinationId |
| 229 */ | 231 */ |
| 230 grantExtensionPrinterAccess: function(provisionalDestinationId) { | 232 grantExtensionPrinterAccess: function(provisionalDestinationId) { |
| 231 chrome.send('grantExtensionPrinterAccess', [provisionalDestinationId]); | 233 chrome.send('grantExtensionPrinterAccess', [provisionalDestinationId]); |
| 232 }, | 234 }, |
| 233 | 235 |
| 234 /** | 236 /** |
| 237 * Requests that Chrome peform printer setup for the given printer. | |
| 238 * @param {string} printerId | |
| 239 */ | |
| 240 setupPrinter: function(printerId) { | |
| 241 chrome.send('setupPrinter', [printerId]); | |
|
dpapad
2017/01/11 20:36:30
Nit (optional): Instead of using chrome.send, expo
skau
2017/01/12 00:36:16
Done.
| |
| 242 }, | |
| 243 | |
| 244 /** | |
| 235 * @param {!print_preview.Destination} destination Destination to print to. | 245 * @param {!print_preview.Destination} destination Destination to print to. |
| 236 * @param {!print_preview.ticket_items.Color} color Color ticket item. | 246 * @param {!print_preview.ticket_items.Color} color Color ticket item. |
| 237 * @return {number} Native layer color model. | 247 * @return {number} Native layer color model. |
| 238 * @private | 248 * @private |
| 239 */ | 249 */ |
| 240 getNativeColorModel_: function(destination, color) { | 250 getNativeColorModel_: function(destination, color) { |
| 241 // For non-local printers native color model is ignored anyway. | 251 // For non-local printers native color model is ignored anyway. |
| 242 var option = destination.isLocal ? color.getSelectedOption() : null; | 252 var option = destination.isLocal ? color.getSelectedOption() : null; |
| 243 var nativeColorModel = parseInt(option ? option.vendor_id : null, 10); | 253 var nativeColorModel = parseInt(option ? option.vendor_id : null, 10); |
| 244 if (isNaN(nativeColorModel)) { | 254 if (isNaN(nativeColorModel)) { |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 830 */ | 840 */ |
| 831 failedToResolveProvisionalDestination_: function(destinationId) { | 841 failedToResolveProvisionalDestination_: function(destinationId) { |
| 832 var evt = new Event( | 842 var evt = new Event( |
| 833 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); | 843 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); |
| 834 evt.provisionalId = destinationId; | 844 evt.provisionalId = destinationId; |
| 835 evt.destination = null; | 845 evt.destination = null; |
| 836 this.dispatchEvent(evt); | 846 this.dispatchEvent(evt); |
| 837 }, | 847 }, |
| 838 | 848 |
| 839 /** | 849 /** |
| 850 * Called when printer setup has been completed. | |
| 851 * @param {string} printerId The id of the printer in the backend. | |
| 852 * @param {boolean} success True if the setup was successful. | |
| 853 * @param {Object} capabilities A capabilities object suitable for | |
| 854 * Destination.capabilities. | |
| 855 * @private | |
| 856 */ | |
| 857 onPrinterSetupResolved_: function(printerId, success, capabilities) { | |
| 858 var evt = new Event(NativeLayer.EventType.PRINTER_SETUP); | |
| 859 evt.printerId = printerId; | |
| 860 evt.success = success; | |
| 861 evt.capabilities = capabilities; | |
| 862 this.dispatchEvent(evt); | |
| 863 }, | |
| 864 | |
| 865 /** | |
| 840 * Called when Chrome reports that a provisional destination has been | 866 * Called when Chrome reports that a provisional destination has been |
| 841 * successfully resolved. | 867 * successfully resolved. |
| 842 * Currently used only for extension provided destinations. | 868 * Currently used only for extension provided destinations. |
| 843 * @param {string} provisionalDestinationId The provisional destination id. | 869 * @param {string} provisionalDestinationId The provisional destination id. |
| 844 * @param {!{extensionId: string, | 870 * @param {!{extensionId: string, |
| 845 * extensionName: string, | 871 * extensionName: string, |
| 846 * id: string, | 872 * id: string, |
| 847 * name: string, | 873 * name: string, |
| 848 * description: (string|undefined)}} destinationInfo The resolved | 874 * description: (string|undefined)}} destinationInfo The resolved |
| 849 * destination info. | 875 * destination info. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 return this.serializedDefaultDestinationSelectionRulesStr_; | 1121 return this.serializedDefaultDestinationSelectionRulesStr_; |
| 1096 } | 1122 } |
| 1097 }; | 1123 }; |
| 1098 | 1124 |
| 1099 // Export | 1125 // Export |
| 1100 return { | 1126 return { |
| 1101 NativeInitialSettings: NativeInitialSettings, | 1127 NativeInitialSettings: NativeInitialSettings, |
| 1102 NativeLayer: NativeLayer | 1128 NativeLayer: NativeLayer |
| 1103 }; | 1129 }; |
| 1104 }); | 1130 }); |
| OLD | NEW |