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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 global.onDidGetPreviewPageCount = | 50 global.onDidGetPreviewPageCount = |
51 this.onDidGetPreviewPageCount_.bind(this); | 51 this.onDidGetPreviewPageCount_.bind(this); |
52 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); | 52 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
53 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); | 53 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); |
54 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); | 54 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); |
55 global.autoCancelForTesting = this.autoCancelForTesting_.bind(this); | 55 global.autoCancelForTesting = this.autoCancelForTesting_.bind(this); |
56 global.onPrivetPrinterChanged = this.onPrivetPrinterChanged_.bind(this); | 56 global.onPrivetPrinterChanged = this.onPrivetPrinterChanged_.bind(this); |
57 global.onPrivetCapabilitiesSet = | 57 global.onPrivetCapabilitiesSet = |
58 this.onPrivetCapabilitiesSet_.bind(this); | 58 this.onPrivetCapabilitiesSet_.bind(this); |
59 global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this); | 59 global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this); |
| 60 global.onExtensionPrintersAdded = |
| 61 this.onExtensionPrintersAdded_.bind(this); |
| 62 global.onExtensionCapabilitiesSet = |
| 63 this.onExtensionCapabilitiesSet_.bind(this); |
60 global.onEnableManipulateSettingsForTest = | 64 global.onEnableManipulateSettingsForTest = |
61 this.onEnableManipulateSettingsForTest_.bind(this); | 65 this.onEnableManipulateSettingsForTest_.bind(this); |
62 global.printPresetOptionsFromDocument = | 66 global.printPresetOptionsFromDocument = |
63 this.onPrintPresetOptionsFromDocument_.bind(this); | 67 this.onPrintPresetOptionsFromDocument_.bind(this); |
64 }; | 68 }; |
65 | 69 |
66 /** | 70 /** |
67 * Event types dispatched from the Chromium native layer. | 71 * Event types dispatched from the Chromium native layer. |
68 * @enum {string} | 72 * @enum {string} |
69 * @const | 73 * @const |
(...skipping 18 matching lines...) Expand all Loading... |
88 PREVIEW_GENERATION_DONE: | 92 PREVIEW_GENERATION_DONE: |
89 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 93 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
90 PREVIEW_GENERATION_FAIL: | 94 PREVIEW_GENERATION_FAIL: |
91 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 95 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
92 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | 96 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
93 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 97 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
94 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', | 98 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', |
95 PRIVET_CAPABILITIES_SET: | 99 PRIVET_CAPABILITIES_SET: |
96 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', | 100 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', |
97 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', | 101 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', |
| 102 EXTENSION_PRINTERS_ADDED: |
| 103 'print_preview.NativeLayer.EXTENSION_PRINTERS_ADDED', |
| 104 EXTENSION_CAPABILITIES_SET: |
| 105 'print_preview.NativeLayer.EXTENSION_CAPABILITIES_SET', |
98 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', | 106 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', |
99 }; | 107 }; |
100 | 108 |
101 /** | 109 /** |
102 * Constant values matching printing::DuplexMode enum. | 110 * Constant values matching printing::DuplexMode enum. |
103 * @enum {number} | 111 * @enum {number} |
104 */ | 112 */ |
105 NativeLayer.DuplexMode = { | 113 NativeLayer.DuplexMode = { |
106 SIMPLEX: 0, | 114 SIMPLEX: 0, |
107 LONG_EDGE: 1, | 115 LONG_EDGE: 1, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 /** | 178 /** |
171 * Requests the privet destination's printing capabilities. A | 179 * Requests the privet destination's printing capabilities. A |
172 * PRIVET_CAPABILITIES_SET event will be dispatched in response. | 180 * PRIVET_CAPABILITIES_SET event will be dispatched in response. |
173 * @param {string} destinationId ID of the destination. | 181 * @param {string} destinationId ID of the destination. |
174 */ | 182 */ |
175 startGetPrivetDestinationCapabilities: function(destinationId) { | 183 startGetPrivetDestinationCapabilities: function(destinationId) { |
176 chrome.send('getPrivetPrinterCapabilities', [destinationId]); | 184 chrome.send('getPrivetPrinterCapabilities', [destinationId]); |
177 }, | 185 }, |
178 | 186 |
179 /** | 187 /** |
| 188 * Requests that extension system dispatches an event requesting the list of |
| 189 * extension managed printers. |
| 190 */ |
| 191 startGetExtensionDestinations: function() { |
| 192 chrome.send('getExtensionPrinters'); |
| 193 }, |
| 194 |
| 195 /** |
| 196 * Requests an extension destination's printing capabilities. A |
| 197 * EXTENSION_CAPABILITIES_SET event will be dispatched in response. |
| 198 * @param {string} extensionId The ID of the extension from which the |
| 199 * capabilities should be requested. |
| 200 * @param {string} printerId The ID of the printer whose capabilities are |
| 201 * requested. |
| 202 */ |
| 203 startGetExtensionDestinationCapabilities: function(extensionId, printerId) { |
| 204 chrome.send('getExtensionPrinterCapabilities', [extensionId, printerId]); |
| 205 }, |
| 206 |
| 207 /** |
180 * Requests the destination's printing capabilities. A CAPABILITIES_SET | 208 * Requests the destination's printing capabilities. A CAPABILITIES_SET |
181 * event will be dispatched in response. | 209 * event will be dispatched in response. |
182 * @param {string} destinationId ID of the destination. | 210 * @param {string} destinationId ID of the destination. |
183 */ | 211 */ |
184 startGetLocalDestinationCapabilities: function(destinationId) { | 212 startGetLocalDestinationCapabilities: function(destinationId) { |
185 chrome.send('getPrinterCapabilities', [destinationId]); | 213 chrome.send('getPrinterCapabilities', [destinationId]); |
186 }, | 214 }, |
187 | 215 |
188 /** | 216 /** |
189 * @param {!print_preview.Destination} destination Destination to print to. | 217 * @param {!print_preview.Destination} destination Destination to print to. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 */ | 320 */ |
293 startPrint: function(destination, printTicketStore, cloudPrintInterface, | 321 startPrint: function(destination, printTicketStore, cloudPrintInterface, |
294 documentInfo, opt_isOpenPdfInPreview, | 322 documentInfo, opt_isOpenPdfInPreview, |
295 opt_showSystemDialog) { | 323 opt_showSystemDialog) { |
296 assert(printTicketStore.isTicketValid(), | 324 assert(printTicketStore.isTicketValid(), |
297 'Trying to print when ticket is not valid'); | 325 'Trying to print when ticket is not valid'); |
298 | 326 |
299 assert(!opt_showSystemDialog || (cr.isWindows && destination.isLocal), | 327 assert(!opt_showSystemDialog || (cr.isWindows && destination.isLocal), |
300 'Implemented for Windows only'); | 328 'Implemented for Windows only'); |
301 | 329 |
| 330 // TODO(tbarzic): Implement this. |
| 331 assert(!destination.isExtension, |
| 332 'Printing to extension printers not yet implemented.'); |
| 333 |
302 var ticket = { | 334 var ticket = { |
303 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 335 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
304 'mediaSize': printTicketStore.mediaSize.getValue(), | 336 'mediaSize': printTicketStore.mediaSize.getValue(), |
305 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, | 337 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, |
306 'landscape': printTicketStore.landscape.getValue(), | 338 'landscape': printTicketStore.landscape.getValue(), |
307 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 339 'color': this.getNativeColorModel_(destination, printTicketStore.color), |
308 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), | 340 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), |
309 'marginsType': printTicketStore.marginsType.getValue(), | 341 'marginsType': printTicketStore.marginsType.getValue(), |
310 'generateDraftData': true, // TODO(rltoscano): What should this be? | 342 'generateDraftData': true, // TODO(rltoscano): What should this be? |
311 'duplex': printTicketStore.duplex.getValue() ? | 343 'duplex': printTicketStore.duplex.getValue() ? |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 * @private | 745 * @private |
714 */ | 746 */ |
715 onPrivetPrintFailed_: function(http_error) { | 747 onPrivetPrintFailed_: function(http_error) { |
716 var privetPrintFailedEvent = | 748 var privetPrintFailedEvent = |
717 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); | 749 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); |
718 privetPrintFailedEvent.httpError = http_error; | 750 privetPrintFailedEvent.httpError = http_error; |
719 this.dispatchEvent(privetPrintFailedEvent); | 751 this.dispatchEvent(privetPrintFailedEvent); |
720 }, | 752 }, |
721 | 753 |
722 /** | 754 /** |
| 755 * @param {Array.<{extensionId: string, |
| 756 * id: string, |
| 757 * name: string, |
| 758 * description: (string|undefined)}>} printers The list |
| 759 * containing information about printers added by an extension. |
| 760 * @param {boolean} done Whether this is the final list of extension |
| 761 * managed printers. |
| 762 */ |
| 763 onExtensionPrintersAdded_: function(printers, done) { |
| 764 var event = new Event(NativeLayer.EventType.EXTENSION_PRINTERS_ADDED); |
| 765 event.printers = printers; |
| 766 event.done = done; |
| 767 this.dispatchEvent(event); |
| 768 }, |
| 769 |
| 770 /** |
| 771 * Called when an extension responds to a request for an extension printer |
| 772 * capabilities. |
| 773 * @param {string} extensionId The ID of extension that manages the printer. |
| 774 * @param {string} printerId The printer's ID (within the extension's |
| 775 * space). |
| 776 * @param {Object} capabilities The reported printer capabilities. |
| 777 */ |
| 778 onExtensionCapabilitiesSet_: function(extensionId, |
| 779 printerId, |
| 780 capabilities) { |
| 781 var event = new Event(NativeLayer.EventType.EXTENSION_CAPABILITIES_SET); |
| 782 event.extensionID = extensionId; |
| 783 event.printerID = printerId; |
| 784 event.capabilities = capabilities; |
| 785 this.dispatchEvent(event); |
| 786 }, |
| 787 |
| 788 /** |
723 * Allows for onManipulateSettings to be called | 789 * Allows for onManipulateSettings to be called |
724 * from the native layer. | 790 * from the native layer. |
725 * @private | 791 * @private |
726 */ | 792 */ |
727 onEnableManipulateSettingsForTest_: function() { | 793 onEnableManipulateSettingsForTest_: function() { |
728 global.onManipulateSettingsForTest = | 794 global.onManipulateSettingsForTest = |
729 this.onManipulateSettingsForTest_.bind(this); | 795 this.onManipulateSettingsForTest_.bind(this); |
730 }, | 796 }, |
731 | 797 |
732 /** | 798 /** |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 return this.serializedAppStateStr_; | 1022 return this.serializedAppStateStr_; |
957 } | 1023 } |
958 }; | 1024 }; |
959 | 1025 |
960 // Export | 1026 // Export |
961 return { | 1027 return { |
962 NativeInitialSettings: NativeInitialSettings, | 1028 NativeInitialSettings: NativeInitialSettings, |
963 NativeLayer: NativeLayer | 1029 NativeLayer: NativeLayer |
964 }; | 1030 }; |
965 }); | 1031 }); |
OLD | NEW |