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 18 matching lines...) Expand all Loading... |
29 // Bind global handlers | 29 // Bind global handlers |
30 global.setInitialSettings = this.onSetInitialSettings_.bind(this); | 30 global.setInitialSettings = this.onSetInitialSettings_.bind(this); |
31 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); | 31 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); |
32 global.setPrinters = this.onSetPrinters_.bind(this); | 32 global.setPrinters = this.onSetPrinters_.bind(this); |
33 global.updateWithPrinterCapabilities = | 33 global.updateWithPrinterCapabilities = |
34 this.onUpdateWithPrinterCapabilities_.bind(this); | 34 this.onUpdateWithPrinterCapabilities_.bind(this); |
35 global.failedToGetPrinterCapabilities = | 35 global.failedToGetPrinterCapabilities = |
36 this.onFailedToGetPrinterCapabilities_.bind(this); | 36 this.onFailedToGetPrinterCapabilities_.bind(this); |
37 global.failedToGetPrivetPrinterCapabilities = | 37 global.failedToGetPrivetPrinterCapabilities = |
38 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); | 38 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); |
| 39 global.failedToGetExtensionPrinterCapabilities = |
| 40 this.onFailedToGetExtensionPrinterCapabilities_.bind(this); |
39 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); | 41 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
40 global.printToCloud = this.onPrintToCloud_.bind(this); | 42 global.printToCloud = this.onPrintToCloud_.bind(this); |
41 global.fileSelectionCancelled = | 43 global.fileSelectionCancelled = |
42 this.onFileSelectionCancelled_.bind(this); | 44 this.onFileSelectionCancelled_.bind(this); |
43 global.fileSelectionCompleted = | 45 global.fileSelectionCompleted = |
44 this.onFileSelectionCompleted_.bind(this); | 46 this.onFileSelectionCompleted_.bind(this); |
45 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); | 47 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); |
46 global.invalidPrinterSettings = | 48 global.invalidPrinterSettings = |
47 this.onInvalidPrinterSettings_.bind(this); | 49 this.onInvalidPrinterSettings_.bind(this); |
48 global.onDidGetDefaultPageLayout = | 50 global.onDidGetDefaultPageLayout = |
49 this.onDidGetDefaultPageLayout_.bind(this); | 51 this.onDidGetDefaultPageLayout_.bind(this); |
50 global.onDidGetPreviewPageCount = | 52 global.onDidGetPreviewPageCount = |
51 this.onDidGetPreviewPageCount_.bind(this); | 53 this.onDidGetPreviewPageCount_.bind(this); |
52 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); | 54 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
53 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); | 55 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); |
54 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); | 56 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); |
55 global.autoCancelForTesting = this.autoCancelForTesting_.bind(this); | 57 global.autoCancelForTesting = this.autoCancelForTesting_.bind(this); |
56 global.onPrivetPrinterChanged = this.onPrivetPrinterChanged_.bind(this); | 58 global.onPrivetPrinterChanged = this.onPrivetPrinterChanged_.bind(this); |
57 global.onPrivetCapabilitiesSet = | 59 global.onPrivetCapabilitiesSet = |
58 this.onPrivetCapabilitiesSet_.bind(this); | 60 this.onPrivetCapabilitiesSet_.bind(this); |
59 global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this); | 61 global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this); |
| 62 global.onExtensionPrintersAdded = |
| 63 this.onExtensionPrintersAdded_.bind(this); |
| 64 global.onExtensionCapabilitiesSet = |
| 65 this.onExtensionCapabilitiesSet_.bind(this); |
60 global.onEnableManipulateSettingsForTest = | 66 global.onEnableManipulateSettingsForTest = |
61 this.onEnableManipulateSettingsForTest_.bind(this); | 67 this.onEnableManipulateSettingsForTest_.bind(this); |
62 global.printPresetOptionsFromDocument = | 68 global.printPresetOptionsFromDocument = |
63 this.onPrintPresetOptionsFromDocument_.bind(this); | 69 this.onPrintPresetOptionsFromDocument_.bind(this); |
64 }; | 70 }; |
65 | 71 |
66 /** | 72 /** |
67 * Event types dispatched from the Chromium native layer. | 73 * Event types dispatched from the Chromium native layer. |
68 * @enum {string} | 74 * @enum {string} |
69 * @const | 75 * @const |
(...skipping 18 matching lines...) Expand all Loading... |
88 PREVIEW_GENERATION_DONE: | 94 PREVIEW_GENERATION_DONE: |
89 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 95 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
90 PREVIEW_GENERATION_FAIL: | 96 PREVIEW_GENERATION_FAIL: |
91 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 97 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
92 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | 98 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
93 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 99 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
94 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', | 100 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', |
95 PRIVET_CAPABILITIES_SET: | 101 PRIVET_CAPABILITIES_SET: |
96 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', | 102 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', |
97 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', | 103 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', |
| 104 EXTENSION_PRINTERS_ADDED: |
| 105 'print_preview.NativeLayer.EXTENSION_PRINTERS_ADDED', |
| 106 EXTENSION_CAPABILITIES_SET: |
| 107 'print_preview.NativeLayer.EXTENSION_CAPABILITIES_SET', |
98 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', | 108 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', |
99 }; | 109 }; |
100 | 110 |
101 /** | 111 /** |
102 * Constant values matching printing::DuplexMode enum. | 112 * Constant values matching printing::DuplexMode enum. |
103 * @enum {number} | 113 * @enum {number} |
104 */ | 114 */ |
105 NativeLayer.DuplexMode = { | 115 NativeLayer.DuplexMode = { |
106 SIMPLEX: 0, | 116 SIMPLEX: 0, |
107 LONG_EDGE: 1, | 117 LONG_EDGE: 1, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 /** | 180 /** |
171 * Requests the privet destination's printing capabilities. A | 181 * Requests the privet destination's printing capabilities. A |
172 * PRIVET_CAPABILITIES_SET event will be dispatched in response. | 182 * PRIVET_CAPABILITIES_SET event will be dispatched in response. |
173 * @param {string} destinationId ID of the destination. | 183 * @param {string} destinationId ID of the destination. |
174 */ | 184 */ |
175 startGetPrivetDestinationCapabilities: function(destinationId) { | 185 startGetPrivetDestinationCapabilities: function(destinationId) { |
176 chrome.send('getPrivetPrinterCapabilities', [destinationId]); | 186 chrome.send('getPrivetPrinterCapabilities', [destinationId]); |
177 }, | 187 }, |
178 | 188 |
179 /** | 189 /** |
| 190 * Requests that extension system dispatches an event requesting the list of |
| 191 * extension managed printers. |
| 192 */ |
| 193 startGetExtensionDestinations: function() { |
| 194 chrome.send('getExtensionPrinters'); |
| 195 }, |
| 196 |
| 197 /** |
| 198 * Requests an extension destination's printing capabilities. A |
| 199 * EXTENSION_CAPABILITIES_SET event will be dispatched in response. |
| 200 * @param {string} destinationId The ID of the destination whose |
| 201 * capabilities are requested. |
| 202 */ |
| 203 startGetExtensionDestinationCapabilities: function(destinationId) { |
| 204 chrome.send('getExtensionPrinterCapabilities', [destinationId]); |
| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 */ | 539 */ |
508 onFailedToGetPrivetPrinterCapabilities_: function(destinationId) { | 540 onFailedToGetPrivetPrinterCapabilities_: function(destinationId) { |
509 var getCapsFailEvent = new Event( | 541 var getCapsFailEvent = new Event( |
510 NativeLayer.EventType.GET_CAPABILITIES_FAIL); | 542 NativeLayer.EventType.GET_CAPABILITIES_FAIL); |
511 getCapsFailEvent.destinationId = destinationId; | 543 getCapsFailEvent.destinationId = destinationId; |
512 getCapsFailEvent.destinationOrigin = | 544 getCapsFailEvent.destinationOrigin = |
513 print_preview.Destination.Origin.PRIVET; | 545 print_preview.Destination.Origin.PRIVET; |
514 this.dispatchEvent(getCapsFailEvent); | 546 this.dispatchEvent(getCapsFailEvent); |
515 }, | 547 }, |
516 | 548 |
| 549 /** |
| 550 * Called when native layer fails to get settings information for a |
| 551 * requested extension destination. |
| 552 * @param {string} destinationId Printer affected by error. |
| 553 * @private |
| 554 */ |
| 555 onFailedToGetExtensionPrinterCapabilities_: function(destinationId) { |
| 556 var getCapsFailEvent = new Event( |
| 557 NativeLayer.EventType.GET_CAPABILITIES_FAIL); |
| 558 getCapsFailEvent.destinationId = destinationId; |
| 559 getCapsFailEvent.destinationOrigin = |
| 560 print_preview.Destination.Origin.EXTENSION; |
| 561 this.dispatchEvent(getCapsFailEvent); |
| 562 }, |
| 563 |
517 /** Reloads the printer list. */ | 564 /** Reloads the printer list. */ |
518 onReloadPrintersList_: function() { | 565 onReloadPrintersList_: function() { |
519 cr.dispatchSimpleEvent(this, NativeLayer.EventType.DESTINATIONS_RELOAD); | 566 cr.dispatchSimpleEvent(this, NativeLayer.EventType.DESTINATIONS_RELOAD); |
520 }, | 567 }, |
521 | 568 |
522 /** | 569 /** |
523 * Called from the C++ layer. | 570 * Called from the C++ layer. |
524 * Take the PDF data handed to us and submit it to the cloud, closing the | 571 * Take the PDF data handed to us and submit it to the cloud, closing the |
525 * print preview dialog once the upload is successful. | 572 * print preview dialog once the upload is successful. |
526 * @param {string} data Data to send as the print job. | 573 * @param {string} data Data to send as the print job. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 * @private | 760 * @private |
714 */ | 761 */ |
715 onPrivetPrintFailed_: function(http_error) { | 762 onPrivetPrintFailed_: function(http_error) { |
716 var privetPrintFailedEvent = | 763 var privetPrintFailedEvent = |
717 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); | 764 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); |
718 privetPrintFailedEvent.httpError = http_error; | 765 privetPrintFailedEvent.httpError = http_error; |
719 this.dispatchEvent(privetPrintFailedEvent); | 766 this.dispatchEvent(privetPrintFailedEvent); |
720 }, | 767 }, |
721 | 768 |
722 /** | 769 /** |
| 770 * @param {Array.<!{extensionId: string, |
| 771 * id: string, |
| 772 * name: string, |
| 773 * description: (string|undefined)}>} printers The list |
| 774 * containing information about printers added by an extension. |
| 775 * @param {boolean} done Whether this is the final list of extension |
| 776 * managed printers. |
| 777 */ |
| 778 onExtensionPrintersAdded_: function(printers, done) { |
| 779 var event = new Event(NativeLayer.EventType.EXTENSION_PRINTERS_ADDED); |
| 780 event.printers = printers; |
| 781 event.done = done; |
| 782 this.dispatchEvent(event); |
| 783 }, |
| 784 |
| 785 /** |
| 786 * Called when an extension responds to a request for an extension printer |
| 787 * capabilities. |
| 788 * @param {string} printerId The printer's ID. |
| 789 * @param {!Object} capabilities The reported printer capabilities. |
| 790 */ |
| 791 onExtensionCapabilitiesSet_: function(printerId, |
| 792 capabilities) { |
| 793 var event = new Event(NativeLayer.EventType.EXTENSION_CAPABILITIES_SET); |
| 794 event.printerId = printerId; |
| 795 event.capabilities = capabilities; |
| 796 this.dispatchEvent(event); |
| 797 }, |
| 798 |
| 799 /** |
723 * Allows for onManipulateSettings to be called | 800 * Allows for onManipulateSettings to be called |
724 * from the native layer. | 801 * from the native layer. |
725 * @private | 802 * @private |
726 */ | 803 */ |
727 onEnableManipulateSettingsForTest_: function() { | 804 onEnableManipulateSettingsForTest_: function() { |
728 global.onManipulateSettingsForTest = | 805 global.onManipulateSettingsForTest = |
729 this.onManipulateSettingsForTest_.bind(this); | 806 this.onManipulateSettingsForTest_.bind(this); |
730 }, | 807 }, |
731 | 808 |
732 /** | 809 /** |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 return this.serializedAppStateStr_; | 1033 return this.serializedAppStateStr_; |
957 } | 1034 } |
958 }; | 1035 }; |
959 | 1036 |
960 // Export | 1037 // Export |
961 return { | 1038 return { |
962 NativeInitialSettings: NativeInitialSettings, | 1039 NativeInitialSettings: NativeInitialSettings, |
963 NativeLayer: NativeLayer | 1040 NativeLayer: NativeLayer |
964 }; | 1041 }; |
965 }); | 1042 }); |
OLD | NEW |