Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 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', |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 70 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', | 72 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', |
| 71 PREVIEW_GENERATION_DONE: | 73 PREVIEW_GENERATION_DONE: |
| 72 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 74 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
| 73 PREVIEW_GENERATION_FAIL: | 75 PREVIEW_GENERATION_FAIL: |
| 74 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 76 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
| 75 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | 77 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
| 76 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 78 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
| 77 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', | 79 PRIVET_PRINTER_CHANGED: 'print_preview.NativeLayer.PRIVET_PRINTER_CHANGED', |
| 78 PRIVET_CAPABILITIES_SET: | 80 PRIVET_CAPABILITIES_SET: |
| 79 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', | 81 'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET', |
| 80 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED' | 82 PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED', |
| 83 MANIPULATE_SETTINGS_FOR_TEST: | |
| 84 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST' | |
| 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 /** Navigates the user to the Google Cloud Print management page. */ | 370 /** Navigates the user to the Google Cloud Print management page. */ |
| 367 startManageCloudDestinations: function() { | 371 startManageCloudDestinations: function() { |
| 368 chrome.send('manageCloudPrinters'); | 372 chrome.send('manageCloudPrinters'); |
| 369 }, | 373 }, |
| 370 | 374 |
| 371 /** Forces browser to open a new tab with the given URL address. */ | 375 /** Forces browser to open a new tab with the given URL address. */ |
| 372 startForceOpenNewTab: function(url) { | 376 startForceOpenNewTab: function(url) { |
| 373 chrome.send('forceOpenNewTab', [url]); | 377 chrome.send('forceOpenNewTab', [url]); |
| 374 }, | 378 }, |
| 375 | 379 |
| 380 doneManipulatingSettings: function() { | |
| 381 chrome.send('UILoadedForTest'); | |
| 382 }, | |
| 383 | |
| 376 /** | 384 /** |
| 377 * @param {!Object} initialSettings Object containing all initial settings. | 385 * @param {!Object} initialSettings Object containing all initial settings. |
| 378 */ | 386 */ |
| 379 onSetInitialSettings_: function(initialSettings) { | 387 onSetInitialSettings_: function(initialSettings) { |
| 380 var numberFormatSymbols = | 388 var numberFormatSymbols = |
| 381 print_preview.MeasurementSystem.parseNumberFormat( | 389 print_preview.MeasurementSystem.parseNumberFormat( |
| 382 initialSettings['numberFormat']); | 390 initialSettings['numberFormat']); |
| 383 var unitType = print_preview.MeasurementSystem.UnitType.IMPERIAL; | 391 var unitType = print_preview.MeasurementSystem.UnitType.IMPERIAL; |
| 384 if (initialSettings['measurementSystem'] != null) { | 392 if (initialSettings['measurementSystem'] != null) { |
| 385 unitType = initialSettings['measurementSystem']; | 393 unitType = initialSettings['measurementSystem']; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 /** | 673 /** |
| 666 * @param {string} http_error The HTTP response code or -1 if not an HTTP | 674 * @param {string} http_error The HTTP response code or -1 if not an HTTP |
| 667 * error. | 675 * error. |
| 668 * @private | 676 * @private |
| 669 */ | 677 */ |
| 670 onPrivetPrintFailed_: function(http_error) { | 678 onPrivetPrintFailed_: function(http_error) { |
| 671 var privetPrintFailedEvent = | 679 var privetPrintFailedEvent = |
| 672 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); | 680 new Event(NativeLayer.EventType.PRIVET_PRINT_FAILED); |
| 673 privetPrintFailedEvent.httpError = http_error; | 681 privetPrintFailedEvent.httpError = http_error; |
| 674 this.dispatchEvent(privetPrintFailedEvent); | 682 this.dispatchEvent(privetPrintFailedEvent); |
| 683 }, | |
| 684 | |
| 685 /** | |
| 686 * Function that allows for onManipulateSettings to be called | |
| 687 * from the native layer, specifically during testing. | |
| 688 */ | |
| 689 onEnableManipulateSettingsForTest_: function() { | |
| 690 global['onManipulateSettingsForTest'] = | |
| 691 this.onManipulateSettingsForTest_.bind(this); | |
| 692 }, | |
| 693 | |
| 694 /** | |
| 695 * Function call from browsertest to start clicking certain buttons. | |
| 696 * @param {string} messageName The setting that is to be manipulated, | |
| 697 * such as the layout settings, or page numbers | |
| 698 * @param {string, boolean, undefined} Is the value that we want to | |
| 699 * set the particular setting to. For layout settings, page numbers, | |
| 700 * and margins, its a string. For 'headers and footers' and | |
| 701 * 'background colors and images,' its a boolean. For Save as PDF, | |
| 702 * its undefined as it isn't needed. | |
| 703 */ | |
| 704 onManipulateSettingsForTest_: function(messageName, parameter) { | |
| 705 var manipulateSettingsEvent = | |
| 706 new Event(NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST); | |
| 707 manipulateSettingsEvent.messageName = messageName; | |
| 708 if (messageName == 'SAVE_AS_PDF') { | |
| 709 } | |
| 710 else if (messageName == 'LAYOUT_SETTINGS') { | |
| 711 manipulateSettingsEvent.isPortrait = parameter; | |
| 712 } | |
| 713 else if (messageName == 'PAGE_NUMBERS') { | |
| 714 manipulateSettingsEvent.pageNumbers = parameter; | |
| 715 } | |
| 716 else if (messageName == 'HEADERS_AND_FOOTERS') { | |
| 717 manipulateSettingsEvent.headersAndFooters = parameter; | |
| 718 } | |
| 719 else if (messageName == 'BACKGROUND_COLORS_AND_IMAGES') { | |
| 720 manipulateSettingsEvent.backgroundColorsAndImages = parameter; | |
| 721 } | |
| 722 else if (messageName == 'MARGINS') { | |
|
Aleksey Shlyapnikov
2014/06/18 21:57:35
Move all elses on the same line with }
ivandavid
2014/06/20 01:00:25
Done.
| |
| 723 manipulateSettingsEvent.margins = parameter; | |
| 724 } | |
|
Aleksey Shlyapnikov
2014/06/18 21:57:35
Why not pass a dictionary here (for example, simil
ivandavid
2014/06/20 01:00:25
Done.
| |
| 725 this.dispatchEvent(manipulateSettingsEvent); | |
| 675 } | 726 } |
| 676 }; | 727 }; |
| 677 | 728 |
| 678 /** | 729 /** |
| 679 * Initial settings retrieved from the native layer. | 730 * Initial settings retrieved from the native layer. |
| 680 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be | 731 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be |
| 681 * in auto-print mode. | 732 * in auto-print mode. |
| 682 * @param {string} thousandsDelimeter Character delimeter of thousands digits. | 733 * @param {string} thousandsDelimeter Character delimeter of thousands digits. |
| 683 * @param {string} decimalDelimeter Character delimeter of the decimal point. | 734 * @param {string} decimalDelimeter Character delimeter of the decimal point. |
| 684 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of | 735 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 return this.serializedAppStateStr_; | 901 return this.serializedAppStateStr_; |
| 851 } | 902 } |
| 852 }; | 903 }; |
| 853 | 904 |
| 854 // Export | 905 // Export |
| 855 return { | 906 return { |
| 856 NativeInitialSettings: NativeInitialSettings, | 907 NativeInitialSettings: NativeInitialSettings, |
| 857 NativeLayer: NativeLayer | 908 NativeLayer: NativeLayer |
| 858 }; | 909 }; |
| 859 }); | 910 }); |
| OLD | NEW |