| 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 new Event(NativeLayer.EventType.PRIVET_PRINTER_CHANGED); | 654 new Event(NativeLayer.EventType.PRIVET_PRINTER_CHANGED); |
| 648 privetPrinterChangedEvent.printer = printer; | 655 privetPrinterChangedEvent.printer = printer; |
| 649 this.dispatchEvent(privetPrinterChangedEvent); | 656 this.dispatchEvent(privetPrinterChangedEvent); |
| 650 }, | 657 }, |
| 651 | 658 |
| 652 /** | 659 /** |
| 653 * Called when the privet printer search is over. | 660 * Called when the privet printer search is over. |
| 654 * @private | 661 * @private |
| 655 */ | 662 */ |
| 656 onPrivetPrinterSearchDone_: function() { | 663 onPrivetPrinterSearchDone_: function() { |
| 657 var privetPrinterSearchDoneEvent = new Event( | 664 var privetPrinterSearchDoneEvent = |
| 658 NativeLayer.EventType.PRIVET_PRINTER_SEARCH_DONE); | 665 new Event(NativeLayer.EventType.PRIVET_PRINTER_SEARCH_DONE); |
| 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 = |
| 669 NativeLayer.EventType.PRIVET_CAPABILITIES_SET); | 676 new Event(NativeLayer.EventType.PRIVET_CAPABILITIES_SET); |
| 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 {string} http_error The HTTP response code or -1 if not an HTTP |
| 684 * error. |
| 685 * @private |
| 686 */ |
| 687 onPrivetPrintFailed_: function(http_error) { |
| 688 var privetPrintFailedEvent = |
| 689 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); |
| 690 privetPrintFailedEvent.httpError = http_error; |
| 691 this.dispatchEvent(privetPrintFailedEvent); |
| 673 } | 692 } |
| 674 }; | 693 }; |
| 675 | 694 |
| 676 /** | 695 /** |
| 677 * Initial settings retrieved from the native layer. | 696 * Initial settings retrieved from the native layer. |
| 678 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be | 697 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be |
| 679 * in auto-print mode. | 698 * in auto-print mode. |
| 680 * @param {string} thousandsDelimeter Character delimeter of thousands digits. | 699 * @param {string} thousandsDelimeter Character delimeter of thousands digits. |
| 681 * @param {string} decimalDelimeter Character delimeter of the decimal point. | 700 * @param {string} decimalDelimeter Character delimeter of the decimal point. |
| 682 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of | 701 * @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_; | 867 return this.serializedAppStateStr_; |
| 849 } | 868 } |
| 850 }; | 869 }; |
| 851 | 870 |
| 852 // Export | 871 // Export |
| 853 return { | 872 return { |
| 854 NativeInitialSettings: NativeInitialSettings, | 873 NativeInitialSettings: NativeInitialSettings, |
| 855 NativeLayer: NativeLayer | 874 NativeLayer: NativeLayer |
| 856 }; | 875 }; |
| 857 }); | 876 }); |
| OLD | NEW |