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 |
(...skipping 30 matching lines...) Expand all Loading... | |
41 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); | 41 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); |
42 global['printScalingDisabledForSourcePDF'] = | 42 global['printScalingDisabledForSourcePDF'] = |
43 this.onPrintScalingDisabledForSourcePDF_.bind(this); | 43 this.onPrintScalingDisabledForSourcePDF_.bind(this); |
44 global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this); | 44 global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this); |
45 global['autoCancelForTesting'] = this.autoCancelForTesting_.bind(this); | 45 global['autoCancelForTesting'] = this.autoCancelForTesting_.bind(this); |
46 global['onPrivetPrinterChanged'] = this.onPrivetPrinterChanged_.bind(this); | 46 global['onPrivetPrinterChanged'] = this.onPrivetPrinterChanged_.bind(this); |
47 global['onPrivetPrinterSearchDone'] = | 47 global['onPrivetPrinterSearchDone'] = |
48 this.onPrivetPrinterSearchDone_.bind(this); | 48 this.onPrivetPrinterSearchDone_.bind(this); |
49 global['onPrivetCapabilitiesSet'] = | 49 global['onPrivetCapabilitiesSet'] = |
50 this.onPrivetCapabilitiesSet_.bind(this); | 50 this.onPrivetCapabilitiesSet_.bind(this); |
51 global['onPrivetPrintFailed'] = this.onPrivetPrintFailed_.bind(this); | |
51 }; | 52 }; |
52 | 53 |
53 /** | 54 /** |
54 * Event types dispatched from the Chromium native layer. | 55 * Event types dispatched from the Chromium native layer. |
55 * @enum {string} | 56 * @enum {string} |
56 * @const | 57 * @const |
57 */ | 58 */ |
58 NativeLayer.EventType = { | 59 NativeLayer.EventType = { |
59 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | 60 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', |
60 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', | 61 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', |
(...skipping 13 matching lines...) Expand all Loading... | |
74 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 75 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
75 PREVIEW_GENERATION_FAIL: | 76 PREVIEW_GENERATION_FAIL: |
76 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 77 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
77 PREVIEW_RELOAD: 'print_preview.NativeLayer.PREVIEW_RELOAD', | 78 PREVIEW_RELOAD: 'print_preview.NativeLayer.PREVIEW_RELOAD', |
78 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | 79 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
79 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 80 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
80 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', | 81 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', |
81 PRIVET_PRINTER_SEARCH_DONE: | 82 PRIVET_PRINTER_SEARCH_DONE: |
82 'print_preview.NativeLayer.PRIVET_PRINTER_SEARCH_DONE', | 83 'print_preview.NativeLayer.PRIVET_PRINTER_SEARCH_DONE', |
83 PRIVET_CAPABILITIES_SET: | 84 PRIVET_CAPABILITIES_SET: |
84 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET' | 85 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', |
86 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED' | |
85 }; | 87 }; |
86 | 88 |
87 /** | 89 /** |
88 * Constant values matching printing::DuplexMode enum. | 90 * Constant values matching printing::DuplexMode enum. |
89 * @enum {number} | 91 * @enum {number} |
90 */ | 92 */ |
91 NativeLayer.DuplexMode = { | 93 NativeLayer.DuplexMode = { |
92 SIMPLEX: 0, | 94 SIMPLEX: 0, |
93 LONG_EDGE: 1, | 95 LONG_EDGE: 1, |
94 UNKNOWN_DUPLEX_MODE: -1 | 96 UNKNOWN_DUPLEX_MODE: -1 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 'duplex': printTicketStore.duplex.getValue() ? | 268 'duplex': printTicketStore.duplex.getValue() ? |
267 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, | 269 NativeLayer.DuplexMode.LONG_EDGE : NativeLayer.DuplexMode.SIMPLEX, |
268 'copies': printTicketStore.copies.getValueAsNumber(), | 270 'copies': printTicketStore.copies.getValueAsNumber(), |
269 'collate': printTicketStore.collate.getValue(), | 271 'collate': printTicketStore.collate.getValue(), |
270 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), | 272 'shouldPrintBackgrounds': printTicketStore.cssBackground.getValue(), |
271 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), | 273 'shouldPrintSelectionOnly': printTicketStore.selectionOnly.getValue(), |
272 'previewModifiable': documentInfo.isModifiable, | 274 'previewModifiable': documentInfo.isModifiable, |
273 'printToPDF': destination.id == | 275 'printToPDF': destination.id == |
274 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 276 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
275 'printWithCloudPrint': !destination.isLocal, | 277 'printWithCloudPrint': !destination.isLocal, |
278 'printWithPrivet': destination.isPrivet, | |
276 'deviceName': destination.id, | 279 'deviceName': destination.id, |
277 'isFirstRequest': false, | 280 'isFirstRequest': false, |
278 'requestID': -1, | 281 'requestID': -1, |
279 'fitToPageEnabled': printTicketStore.fitToPage.getValue() | 282 'fitToPageEnabled': printTicketStore.fitToPage.getValue() |
280 }; | 283 }; |
281 | 284 |
282 if (!destination.isLocal) { | 285 if (!destination.isLocal) { |
283 // We can't set cloudPrintID if the destination is "Print with Cloud | 286 // We can't set cloudPrintID if the destination is "Print with Cloud |
284 // Print" because the native system will try to print to Google Cloud | 287 // Print" because the native system will try to print to Google Cloud |
285 // Print with this ID instead of opening a Google Cloud Print dialog. | 288 // Print with this ID instead of opening a Google Cloud Print dialog. |
286 ticket['cloudPrintID'] = destination.id; | 289 ticket['cloudPrintID'] = destination.id; |
287 } | 290 } |
288 | 291 |
289 if (printTicketStore.marginsType.isCapabilityAvailable() && | 292 if (printTicketStore.marginsType.isCapabilityAvailable() && |
290 printTicketStore.marginsType.isValueEqual( | 293 printTicketStore.marginsType.isValueEqual( |
291 print_preview.ticket_items.MarginsType.Value.CUSTOM)) { | 294 print_preview.ticket_items.MarginsType.Value.CUSTOM)) { |
292 var customMargins = printTicketStore.customMargins.getValue(); | 295 var customMargins = printTicketStore.customMargins.getValue(); |
293 var orientationEnum = | 296 var orientationEnum = |
294 print_preview.ticket_items.CustomMargins.Orientation; | 297 print_preview.ticket_items.CustomMargins.Orientation; |
295 ticket['marginsCustom'] = { | 298 ticket['marginsCustom'] = { |
296 'marginTop': customMargins.get(orientationEnum.TOP), | 299 'marginTop': customMargins.get(orientationEnum.TOP), |
297 'marginRight': customMargins.get(orientationEnum.RIGHT), | 300 'marginRight': customMargins.get(orientationEnum.RIGHT), |
298 'marginBottom': customMargins.get(orientationEnum.BOTTOM), | 301 'marginBottom': customMargins.get(orientationEnum.BOTTOM), |
299 'marginLeft': customMargins.get(orientationEnum.LEFT) | 302 'marginLeft': customMargins.get(orientationEnum.LEFT) |
300 }; | 303 }; |
301 } | 304 } |
302 | 305 |
306 if (destination.isPrivet) { | |
307 ticket['ticket'] = printTicketStore.createPrintTicket(destination); | |
308 } | |
309 | |
303 if (opt_isOpenPdfInPreview) { | 310 if (opt_isOpenPdfInPreview) { |
304 ticket['OpenPDFInPreview'] = true; | 311 ticket['OpenPDFInPreview'] = true; |
305 } | 312 } |
306 | 313 |
307 chrome.send('print', [JSON.stringify(ticket)]); | 314 chrome.send('print', [JSON.stringify(ticket)]); |
308 }, | 315 }, |
309 | 316 |
310 /** Requests that the current pending print request be cancelled. */ | 317 /** Requests that the current pending print request be cancelled. */ |
311 startCancelPendingPrint: function() { | 318 startCancelPendingPrint: function() { |
312 chrome.send('cancelPendingPrintRequest'); | 319 chrome.send('cancelPendingPrintRequest'); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 this.dispatchEvent(privetPrinterSearchDoneEvent); | 666 this.dispatchEvent(privetPrinterSearchDoneEvent); |
660 }, | 667 }, |
661 | 668 |
662 /** | 669 /** |
663 * @param {Object} printer Specifies information about the printer that was | 670 * @param {Object} printer Specifies information about the printer that was |
664 * added. | 671 * added. |
665 * @private | 672 * @private |
666 */ | 673 */ |
667 onPrivetCapabilitiesSet_: function(printer, capabilities) { | 674 onPrivetCapabilitiesSet_: function(printer, capabilities) { |
668 var privetCapabilitiesSetEvent = new Event( | 675 var privetCapabilitiesSetEvent = new Event( |
669 NativeLayer.EventType.PRIVET_CAPABILITIES_SET); | 676 NativeLayer.EventType.PRIVET_CAPABILITIES_SET); |
Toscano
2013/11/06 22:05:35
Needs two more spaces indent.
Noam Samuel
2013/11/06 23:59:11
Done.
| |
670 privetCapabilitiesSetEvent.printer = printer; | 677 privetCapabilitiesSetEvent.printer = printer; |
671 privetCapabilitiesSetEvent.capabilities = capabilities; | 678 privetCapabilitiesSetEvent.capabilities = capabilities; |
672 this.dispatchEvent(privetCapabilitiesSetEvent); | 679 this.dispatchEvent(privetCapabilitiesSetEvent); |
680 }, | |
681 | |
682 /** | |
683 * @param {number} http_error HTTP Error code for the privet local error. | |
684 * @private | |
685 */ | |
686 onPrivetPrintFailed_: function(http_error) { | |
687 var privetPrintFailedEvent = new Event( | |
688 NativeLayer.EventType.PRIVET_PRINT_FAILED); | |
Toscano
2013/11/06 22:05:35
Needs two more spaces indent.
Toscano
2013/11/06 22:05:35
Should break on higher order operator:
var privet
Noam Samuel
2013/11/06 23:59:11
Done.
| |
689 privetPrintFailedEvent.http_error = http_error; | |
690 this.dispatchEvent(privetPrintFailedEvent); | |
673 } | 691 } |
674 }; | 692 }; |
675 | 693 |
676 /** | 694 /** |
677 * Initial settings retrieved from the native layer. | 695 * Initial settings retrieved from the native layer. |
678 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be | 696 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be |
679 * in auto-print mode. | 697 * in auto-print mode. |
680 * @param {string} thousandsDelimeter Character delimeter of thousands digits. | 698 * @param {string} thousandsDelimeter Character delimeter of thousands digits. |
681 * @param {string} decimalDelimeter Character delimeter of the decimal point. | 699 * @param {string} decimalDelimeter Character delimeter of the decimal point. |
682 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of | 700 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 return this.serializedAppStateStr_; | 866 return this.serializedAppStateStr_; |
849 } | 867 } |
850 }; | 868 }; |
851 | 869 |
852 // Export | 870 // Export |
853 return { | 871 return { |
854 NativeInitialSettings: NativeInitialSettings, | 872 NativeInitialSettings: NativeInitialSettings, |
855 NativeLayer: NativeLayer | 873 NativeLayer: NativeLayer |
856 }; | 874 }; |
857 }); | 875 }); |
OLD | NEW |