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.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * An interface to the native Chromium printing system layer. | 9 * An interface to the native Chromium printing system layer. |
10 * @constructor | 10 * @constructor |
11 * @extends {cr.EventTarget} | 11 * @extends {cr.EventTarget} |
12 */ | 12 */ |
13 function NativeLayer() { | 13 function NativeLayer() { |
14 cr.EventTarget.call(this); | 14 cr.EventTarget.call(this); |
15 | 15 |
16 // Bind global handlers | 16 // Bind global handlers |
17 global['setInitialSettings'] = this.onSetInitialSettings_.bind(this); | 17 global.setInitialSettings = this.onSetInitialSettings_.bind(this); |
18 global['setUseCloudPrint'] = this.onSetUseCloudPrint_.bind(this); | 18 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); |
19 global['setPrinters'] = this.onSetPrinters_.bind(this); | 19 global.setPrinters = this.onSetPrinters_.bind(this); |
20 global['updateWithPrinterCapabilities'] = | 20 global.updateWithPrinterCapabilities = |
21 this.onUpdateWithPrinterCapabilities_.bind(this); | 21 this.onUpdateWithPrinterCapabilities_.bind(this); |
22 global['failedToGetPrinterCapabilities'] = | 22 global.failedToGetPrinterCapabilities = |
23 this.onFailedToGetPrinterCapabilities_.bind(this); | 23 this.onFailedToGetPrinterCapabilities_.bind(this); |
24 global['failedToGetPrivetPrinterCapabilities'] = | 24 global.failedToGetPrivetPrinterCapabilities = |
25 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); | 25 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); |
26 global['reloadPrintersList'] = this.onReloadPrintersList_.bind(this); | 26 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
27 global['printToCloud'] = this.onPrintToCloud_.bind(this); | 27 global.printToCloud = this.onPrintToCloud_.bind(this); |
28 global['fileSelectionCancelled'] = | 28 global.fileSelectionCancelled = |
29 this.onFileSelectionCancelled_.bind(this); | 29 this.onFileSelectionCancelled_.bind(this); |
30 global['fileSelectionCompleted'] = | 30 global.fileSelectionCompleted = |
31 this.onFileSelectionCompleted_.bind(this); | 31 this.onFileSelectionCompleted_.bind(this); |
32 global['printPreviewFailed'] = this.onPrintPreviewFailed_.bind(this); | 32 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); |
33 global['invalidPrinterSettings'] = | 33 global.invalidPrinterSettings = |
34 this.onInvalidPrinterSettings_.bind(this); | 34 this.onInvalidPrinterSettings_.bind(this); |
35 global['onDidGetDefaultPageLayout'] = | 35 global.onDidGetDefaultPageLayout = |
36 this.onDidGetDefaultPageLayout_.bind(this); | 36 this.onDidGetDefaultPageLayout_.bind(this); |
37 global['onDidGetPreviewPageCount'] = | 37 global.onDidGetPreviewPageCount = |
38 this.onDidGetPreviewPageCount_.bind(this); | 38 this.onDidGetPreviewPageCount_.bind(this); |
39 global['onDidPreviewPage'] = this.onDidPreviewPage_.bind(this); | 39 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
40 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); | 40 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); |
41 global['printScalingDisabledForSourcePDF'] = | 41 global.printScalingDisabledForSourcePDF = |
42 this.onPrintScalingDisabledForSourcePDF_.bind(this); | 42 this.onPrintScalingDisabledForSourcePDF_.bind(this); |
43 global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this); | 43 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); |
44 global['autoCancelForTesting'] = this.autoCancelForTesting_.bind(this); | 44 global.autoCancelForTesting = this.autoCancelForTesting_.bind(this); |
45 global['onPrivetPrinterChanged'] = this.onPrivetPrinterChanged_.bind(this); | 45 global.onPrivetPrinterChanged = this.onPrivetPrinterChanged_.bind(this); |
46 global['onPrivetCapabilitiesSet'] = | 46 global.onPrivetCapabilitiesSet = |
47 this.onPrivetCapabilitiesSet_.bind(this); | 47 this.onPrivetCapabilitiesSet_.bind(this); |
48 global['onPrivetPrintFailed'] = this.onPrivetPrintFailed_.bind(this); | 48 global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this); |
49 global.onEnableManipulateSettingsForTest = | |
50 this.onEnableManipulateSettingsForTest_.bind(this); | |
49 }; | 51 }; |
50 | 52 |
51 /** | 53 /** |
52 * Event types dispatched from the Chromium native layer. | 54 * Event types dispatched from the Chromium native layer. |
53 * @enum {string} | 55 * @enum {string} |
54 * @const | 56 * @const |
55 */ | 57 */ |
56 NativeLayer.EventType = { | 58 NativeLayer.EventType = { |
57 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | 59 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', |
58 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', | 60 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', |
59 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', | 61 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', |
60 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', | 62 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', |
61 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', | 63 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', |
62 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', | 64 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', |
63 FILE_SELECTION_COMPLETE: | 65 FILE_SELECTION_COMPLETE: |
64 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', | 66 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', |
65 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL', | 67 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL', |
66 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', | 68 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', |
67 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', | 69 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', |
70 MANIPULATE_SETTINGS_FOR_TEST: | |
71 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', | |
68 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', | 72 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', |
69 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', | 73 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', |
70 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', | 74 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', |
71 PREVIEW_GENERATION_DONE: | 75 PREVIEW_GENERATION_DONE: |
72 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 76 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
73 PREVIEW_GENERATION_FAIL: | 77 PREVIEW_GENERATION_FAIL: |
74 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 78 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
75 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | 79 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
76 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 80 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
77 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', | 81 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', |
78 PRIVET_CAPABILITIES_SET: | 82 PRIVET_CAPABILITIES_SET: |
79 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', | 83 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', |
80 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED' | 84 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', |
81 }; | 85 }; |
82 | 86 |
83 /** | 87 /** |
84 * Constant values matching printing::DuplexMode enum. | 88 * Constant values matching printing::DuplexMode enum. |
85 * @enum {number} | 89 * @enum {number} |
86 */ | 90 */ |
87 NativeLayer.DuplexMode = { | 91 NativeLayer.DuplexMode = { |
88 SIMPLEX: 0, | 92 SIMPLEX: 0, |
89 LONG_EDGE: 1, | 93 LONG_EDGE: 1, |
90 UNKNOWN_DUPLEX_MODE: -1 | 94 UNKNOWN_DUPLEX_MODE: -1 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 /** | 165 /** |
162 * Requests the destination's printing capabilities. A CAPABILITIES_SET | 166 * Requests the destination's printing capabilities. A CAPABILITIES_SET |
163 * event will be dispatched in response. | 167 * event will be dispatched in response. |
164 * @param {string} destinationId ID of the destination. | 168 * @param {string} destinationId ID of the destination. |
165 */ | 169 */ |
166 startGetLocalDestinationCapabilities: function(destinationId) { | 170 startGetLocalDestinationCapabilities: function(destinationId) { |
167 chrome.send('getPrinterCapabilities', [destinationId]); | 171 chrome.send('getPrinterCapabilities', [destinationId]); |
168 }, | 172 }, |
169 | 173 |
170 /** | 174 /** |
171 * @param {!print_preview.Destination} destination Destination to print to. | |
172 * @param {!print_preview.ticket_items.Color} color Color ticket item. | |
173 * @return {number} Native layer color model. | |
174 * @private | |
175 */ | |
176 getNativeColorModel_: function(destination, color) { | |
177 // For non-local printers native color model is ignored anyway. | |
178 var option = destination.isLocal ? color.getSelectedOption() : null; | |
179 var nativeColorModel = parseInt(option ? option.vendor_id : null); | |
180 if (isNaN(nativeColorModel)) { | |
181 return color.getValue() ? | |
182 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY; | |
183 } | |
184 return nativeColorModel; | |
185 }, | |
186 | |
187 /** | |
Aleksey Shlyapnikov
2014/07/09 01:45:07
Please bring this and related code back.
| |
188 * Requests that a preview be generated. The following events may be | 175 * Requests that a preview be generated. The following events may be |
189 * dispatched in response: | 176 * dispatched in response: |
190 * - PAGE_COUNT_READY | 177 * - PAGE_COUNT_READY |
191 * - PAGE_LAYOUT_READY | 178 * - PAGE_LAYOUT_READY |
192 * - PAGE_PREVIEW_READY | 179 * - PAGE_PREVIEW_READY |
193 * - PREVIEW_GENERATION_DONE | 180 * - PREVIEW_GENERATION_DONE |
194 * - PREVIEW_GENERATION_FAIL | 181 * - PREVIEW_GENERATION_FAIL |
195 * @param {print_preview.Destination} destination Destination to print to. | 182 * @param {print_preview.Destination} destination Destination to print to. |
196 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 183 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
197 * state of the print ticket. | 184 * state of the print ticket. |
198 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 185 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
199 * @param {number} ID of the preview request. | 186 * @param {number} ID of the preview request. |
200 */ | 187 */ |
201 startGetPreview: function( | 188 startGetPreview: function( |
202 destination, printTicketStore, documentInfo, requestId) { | 189 destination, printTicketStore, documentInfo, requestId) { |
203 assert(printTicketStore.isTicketValidForPreview(), | 190 assert(printTicketStore.isTicketValidForPreview(), |
204 'Trying to generate preview when ticket is not valid'); | 191 'Trying to generate preview when ticket is not valid'); |
205 | 192 |
206 var ticket = { | 193 var ticket = { |
207 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 194 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
208 'mediaSize': printTicketStore.mediaSize.getValue(), | 195 'mediaSize': printTicketStore.mediaSize.getValue(), |
209 'landscape': printTicketStore.landscape.getValue(), | 196 'landscape': printTicketStore.landscape.getValue(), |
210 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 197 'color': printTicketStore.color.getValue() ? |
198 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, | |
211 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), | 199 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), |
212 'marginsType': printTicketStore.marginsType.getValue(), | 200 'marginsType': printTicketStore.marginsType.getValue(), |
213 'isFirstRequest': requestId == 0, | 201 'isFirstRequest': requestId == 0, |
214 'requestID': requestId, | 202 'requestID': requestId, |
215 'previewModifiable': documentInfo.isModifiable, | 203 'previewModifiable': documentInfo.isModifiable, |
216 'printToPDF': | 204 'printToPDF': |
217 destination != null && | 205 destination != null && |
218 destination.id == | 206 destination.id == |
219 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 207 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
220 'printWithCloudPrint': destination != null && !destination.isLocal, | 208 'printWithCloudPrint': destination != null && !destination.isLocal, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the | 258 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the |
271 * system's preview application. | 259 * system's preview application. |
272 */ | 260 */ |
273 startPrint: function(destination, printTicketStore, cloudPrintInterface, | 261 startPrint: function(destination, printTicketStore, cloudPrintInterface, |
274 documentInfo, opt_isOpenPdfInPreview) { | 262 documentInfo, opt_isOpenPdfInPreview) { |
275 assert(printTicketStore.isTicketValid(), | 263 assert(printTicketStore.isTicketValid(), |
276 'Trying to print when ticket is not valid'); | 264 'Trying to print when ticket is not valid'); |
277 | 265 |
278 var ticket = { | 266 var ticket = { |
279 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 267 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
280 'mediaSize': printTicketStore.mediaSize.getValue(), | |
281 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, | 268 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, |
282 'landscape': printTicketStore.landscape.getValue(), | 269 'landscape': printTicketStore.landscape.getValue(), |
283 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 270 'color': printTicketStore.color.getValue() ? |
271 NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY, | |
284 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), | 272 'headerFooterEnabled': printTicketStore.headerFooter.getValue(), |
285 'marginsType': printTicketStore.marginsType.getValue(), | 273 'marginsType': printTicketStore.marginsType.getValue(), |
286 'generateDraftData': true, // TODO(rltoscano): What should this be? | 274 'generateDraftData': true, // TODO(rltoscano): What should this be? |
287 'duplex': printTicketStore.duplex.getValue() ? | 275 'duplex': printTicketStore.duplex.getValue() ? |
288 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, | 276 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, |
289 'copies': printTicketStore.copies.getValueAsNumber(), | 277 'copies': printTicketStore.copies.getValueAsNumber(), |
290 'collate': printTicketStore.collate.getValue(), | 278 'collate': printTicketStore.collate.getValue(), |
291 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), | 279 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), |
292 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), | 280 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), |
293 'previewModifiable': documentInfo.isModifiable, | 281 'previewModifiable': documentInfo.isModifiable, |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 /** | 669 /** |
682 * @param {string} http_error The HTTP response code or -1 if not an HTTP | 670 * @param {string} http_error The HTTP response code or -1 if not an HTTP |
683 * error. | 671 * error. |
684 * @private | 672 * @private |
685 */ | 673 */ |
686 onPrivetPrintFailed_: function(http_error) { | 674 onPrivetPrintFailed_: function(http_error) { |
687 var privetPrintFailedEvent = | 675 var privetPrintFailedEvent = |
688 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); | 676 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); |
689 privetPrintFailedEvent.httpError = http_error; | 677 privetPrintFailedEvent.httpError = http_error; |
690 this.dispatchEvent(privetPrintFailedEvent); | 678 this.dispatchEvent(privetPrintFailedEvent); |
679 }, | |
680 | |
681 /** | |
682 * Allows for onManipulateSettings to be called | |
683 * from the native layer. | |
684 * @private | |
685 */ | |
686 onEnableManipulateSettingsForTest_: function() { | |
687 global.onManipulateSettingsForTest = | |
688 this.onManipulateSettingsForTest_.bind(this); | |
689 }, | |
690 | |
691 /** | |
692 * Dispatches an event to print_preview.js to change | |
693 * a particular setting for print preview. | |
694 * @param {!Object} settings Object containing the value to be | |
695 * changed and that value should be set to. | |
696 * @private | |
697 */ | |
698 onManipulateSettingsForTest_: function(settings) { | |
699 var manipulateSettingsEvent = | |
700 new Event(NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST); | |
701 manipulateSettingsEvent.settings = settings; | |
702 this.dispatchEvent(manipulateSettingsEvent); | |
703 }, | |
704 | |
705 /** | |
706 * Sends a message to the test, letting it know that an | |
707 * option has been set to a particular value and that the change has | |
708 * finished modifying the preview area. | |
709 */ | |
710 previewReadyForTest: function() { | |
711 if (global.onManipulateSettingsForTest) | |
712 chrome.send('UILoadedForTest'); | |
713 }, | |
714 | |
715 /** | |
716 * Notifies the test that the option it tried to change | |
717 * had not been changed successfully. | |
718 */ | |
719 previewFailedForTest: function() { | |
720 if (global.onManipulateSettingsForTest) | |
721 chrome.send('UIFailedLoadingForTest'); | |
691 } | 722 } |
692 }; | 723 }; |
693 | 724 |
694 /** | 725 /** |
695 * Initial settings retrieved from the native layer. | 726 * Initial settings retrieved from the native layer. |
696 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be | 727 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be |
697 * in auto-print mode. | 728 * in auto-print mode. |
698 * @param {string} thousandsDelimeter Character delimeter of thousands digits. | 729 * @param {string} thousandsDelimeter Character delimeter of thousands digits. |
699 * @param {string} decimalDelimeter Character delimeter of the decimal point. | 730 * @param {string} decimalDelimeter Character delimeter of the decimal point. |
700 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of | 731 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 return this.serializedAppStateStr_; | 897 return this.serializedAppStateStr_; |
867 } | 898 } |
868 }; | 899 }; |
869 | 900 |
870 // Export | 901 // Export |
871 return { | 902 return { |
872 NativeInitialSettings: NativeInitialSettings, | 903 NativeInitialSettings: NativeInitialSettings, |
873 NativeLayer: NativeLayer | 904 NativeLayer: NativeLayer |
874 }; | 905 }; |
875 }); | 906 }); |
OLD | NEW |