| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * @typedef {{ | 61 * @typedef {{ |
| 62 * printerId: string, | 62 * printerId: string, |
| 63 * success: boolean, | 63 * success: boolean, |
| 64 * capabilities: Object, | 64 * capabilities: Object, |
| 65 * }} | 65 * }} |
| 66 */ | 66 */ |
| 67 print_preview.PrinterSetupResponse; | 67 print_preview.PrinterSetupResponse; |
| 68 | 68 |
| 69 /** |
| 70 * @typedef {{ |
| 71 * completed: boolean, |
| 72 * accessToken: string, |
| 73 * }} |
| 74 */ |
| 75 print_preview.AccessTokenResponse; |
| 76 |
| 77 /** |
| 78 * @typedef {{ |
| 79 * extensionId: string, |
| 80 * extensionName: string, |
| 81 * id: string, |
| 82 * name: string, |
| 83 * description: (string|undefined), |
| 84 * }} |
| 85 */ |
| 86 print_preview.ProvisionalDestinationInfo; |
| 87 |
| 69 cr.define('print_preview', function() { | 88 cr.define('print_preview', function() { |
| 70 'use strict'; | 89 'use strict'; |
| 71 | 90 |
| 72 /** | 91 /** |
| 73 * An interface to the native Chromium printing system layer. | 92 * An interface to the native Chromium printing system layer. |
| 74 * @constructor | 93 * @constructor |
| 75 */ | 94 */ |
| 76 function NativeLayer() { | 95 function NativeLayer() { |
| 77 // Bind global handlers | 96 // Bind global handlers |
| 78 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); | 97 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); |
| 79 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); | 98 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
| 80 global.printToCloud = this.onPrintToCloud_.bind(this); | 99 global.printToCloud = this.onPrintToCloud_.bind(this); |
| 81 global.fileSelectionCancelled = | 100 global.fileSelectionCancelled = |
| 82 this.onFileSelectionCancelled_.bind(this); | 101 this.onFileSelectionCancelled_.bind(this); |
| 83 global.fileSelectionCompleted = | 102 global.fileSelectionCompleted = |
| 84 this.onFileSelectionCompleted_.bind(this); | 103 this.onFileSelectionCompleted_.bind(this); |
| 85 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); | 104 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); |
| 86 global.invalidPrinterSettings = | 105 global.invalidPrinterSettings = |
| 87 this.onInvalidPrinterSettings_.bind(this); | 106 this.onInvalidPrinterSettings_.bind(this); |
| 88 global.onDidGetDefaultPageLayout = | 107 global.onDidGetDefaultPageLayout = |
| 89 this.onDidGetDefaultPageLayout_.bind(this); | 108 this.onDidGetDefaultPageLayout_.bind(this); |
| 90 global.onDidGetPreviewPageCount = | 109 global.onDidGetPreviewPageCount = |
| 91 this.onDidGetPreviewPageCount_.bind(this); | 110 this.onDidGetPreviewPageCount_.bind(this); |
| 92 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); | 111 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
| 93 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); | 112 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); |
| 94 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); | |
| 95 global.onEnableManipulateSettingsForTest = | 113 global.onEnableManipulateSettingsForTest = |
| 96 this.onEnableManipulateSettingsForTest_.bind(this); | 114 this.onEnableManipulateSettingsForTest_.bind(this); |
| 97 global.printPresetOptionsFromDocument = | 115 global.printPresetOptionsFromDocument = |
| 98 this.onPrintPresetOptionsFromDocument_.bind(this); | 116 this.onPrintPresetOptionsFromDocument_.bind(this); |
| 99 global.onProvisionalPrinterResolved = | |
| 100 this.onProvisionalDestinationResolved_.bind(this); | |
| 101 global.failedToResolveProvisionalPrinter = | |
| 102 this.failedToResolveProvisionalDestination_.bind(this); | |
| 103 | 117 |
| 104 /** @private {!cr.EventTarget} */ | 118 /** @private {!cr.EventTarget} */ |
| 105 this.eventTarget_ = new cr.EventTarget(); | 119 this.eventTarget_ = new cr.EventTarget(); |
| 106 } | 120 } |
| 107 | 121 |
| 108 /** @private {?print_preview.NativeLayer} */ | 122 /** @private {?print_preview.NativeLayer} */ |
| 109 var currentInstance = null; | 123 var currentInstance = null; |
| 110 | 124 |
| 111 /** | 125 /** |
| 112 * @return {!print_preview.NativeLayer} The singleton instance. | 126 * @return {!print_preview.NativeLayer} The singleton instance. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 125 NativeLayer.setInstance = function(instance) { | 139 NativeLayer.setInstance = function(instance) { |
| 126 currentInstance = instance; | 140 currentInstance = instance; |
| 127 }; | 141 }; |
| 128 | 142 |
| 129 /** | 143 /** |
| 130 * Event types dispatched from the Chromium native layer. | 144 * Event types dispatched from the Chromium native layer. |
| 131 * @enum {string} | 145 * @enum {string} |
| 132 * @const | 146 * @const |
| 133 */ | 147 */ |
| 134 NativeLayer.EventType = { | 148 NativeLayer.EventType = { |
| 135 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | |
| 136 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', | 149 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', |
| 137 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', | 150 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', |
| 138 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', | 151 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', |
| 139 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', | 152 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', |
| 140 FILE_SELECTION_COMPLETE: | 153 FILE_SELECTION_COMPLETE: |
| 141 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', | 154 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', |
| 142 MANIPULATE_SETTINGS_FOR_TEST: | 155 MANIPULATE_SETTINGS_FOR_TEST: |
| 143 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', | 156 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', |
| 144 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', | 157 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', |
| 145 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', | 158 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', |
| 146 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', | 159 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', |
| 147 PREVIEW_GENERATION_DONE: | 160 PREVIEW_GENERATION_DONE: |
| 148 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 161 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
| 149 PREVIEW_GENERATION_FAIL: | 162 PREVIEW_GENERATION_FAIL: |
| 150 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 163 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
| 151 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | 164 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
| 152 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 165 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
| 153 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', | 166 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', |
| 154 PROVISIONAL_DESTINATION_RESOLVED: | |
| 155 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED' | |
| 156 }; | 167 }; |
| 157 | 168 |
| 158 /** | 169 /** |
| 159 * Constant values matching printing::DuplexMode enum. | 170 * Constant values matching printing::DuplexMode enum. |
| 160 * @enum {number} | 171 * @enum {number} |
| 161 */ | 172 */ |
| 162 NativeLayer.DuplexMode = { | 173 NativeLayer.DuplexMode = { |
| 163 SIMPLEX: 0, | 174 SIMPLEX: 0, |
| 164 LONG_EDGE: 1, | 175 LONG_EDGE: 1, |
| 165 UNKNOWN_DUPLEX_MODE: -1 | 176 UNKNOWN_DUPLEX_MODE: -1 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 185 | 196 |
| 186 NativeLayer.prototype = { | 197 NativeLayer.prototype = { |
| 187 /** @return {!cr.EventTarget} The event target for the native layer.*/ | 198 /** @return {!cr.EventTarget} The event target for the native layer.*/ |
| 188 getEventTarget: function() { | 199 getEventTarget: function() { |
| 189 return this.eventTarget_; | 200 return this.eventTarget_; |
| 190 }, | 201 }, |
| 191 | 202 |
| 192 /** | 203 /** |
| 193 * Requests access token for cloud print requests. | 204 * Requests access token for cloud print requests. |
| 194 * @param {string} authType type of access token. | 205 * @param {string} authType type of access token. |
| 206 * @return {!Promise<!print_preview.AccessTokenResponse>} |
| 195 */ | 207 */ |
| 196 startGetAccessToken: function(authType) { | 208 getAccessToken: function(authType) { |
| 197 chrome.send('getAccessToken', [authType]); | 209 return cr.sendWithPromise('getAccessToken', authType); |
| 198 }, | 210 }, |
| 199 | 211 |
| 200 /** | 212 /** |
| 201 * Gets the initial settings to initialize the print preview with. | 213 * Gets the initial settings to initialize the print preview with. |
| 202 * @return {!Promise<!print_preview.NativeInitialSettings>} | 214 * @return {!Promise<!print_preview.NativeInitialSettings>} |
| 203 */ | 215 */ |
| 204 getInitialSettings: function() { | 216 getInitialSettings: function() { |
| 205 return cr.sendWithPromise('getInitialSettings').then( | 217 return cr.sendWithPromise('getInitialSettings').then( |
| 206 /** | 218 /** |
| 207 * @param {!Object} initialSettings Object containing the raw | 219 * @param {!Object} initialSettings Object containing the raw |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 * capabilities are requested. | 301 * capabilities are requested. |
| 290 * @return {!Promise<!print_preview.Cdd>} | 302 * @return {!Promise<!print_preview.Cdd>} |
| 291 */ | 303 */ |
| 292 getExtensionPrinterCapabilities: function(destinationId) { | 304 getExtensionPrinterCapabilities: function(destinationId) { |
| 293 return cr.sendWithPromise('getExtensionPrinterCapabilities', | 305 return cr.sendWithPromise('getExtensionPrinterCapabilities', |
| 294 destinationId); | 306 destinationId); |
| 295 }, | 307 }, |
| 296 | 308 |
| 297 /** | 309 /** |
| 298 * Requests Chrome to resolve provisional extension destination by granting | 310 * Requests Chrome to resolve provisional extension destination by granting |
| 299 * the provider extension access to the printer. Chrome will respond with | 311 * the provider extension access to the printer. |
| 300 * the resolved destination properties by calling | |
| 301 * {@code onProvisionalPrinterResolved}, or in case of an error | |
| 302 * {@code failedToResolveProvisionalPrinter} | |
| 303 * @param {string} provisionalDestinationId | 312 * @param {string} provisionalDestinationId |
| 313 * @return {!Promise<!print_preview.ProvisionalDestinationInfo>} |
| 304 */ | 314 */ |
| 305 grantExtensionPrinterAccess: function(provisionalDestinationId) { | 315 grantExtensionPrinterAccess: function(provisionalDestinationId) { |
| 306 chrome.send('grantExtensionPrinterAccess', [provisionalDestinationId]); | 316 return cr.sendWithPromise('grantExtensionPrinterAccess', |
| 317 provisionalDestinationId); |
| 307 }, | 318 }, |
| 308 | 319 |
| 309 /** | 320 /** |
| 310 * Requests that Chrome peform printer setup for the given printer. | 321 * Requests that Chrome peform printer setup for the given printer. |
| 311 * @param {string} printerId | 322 * @param {string} printerId |
| 312 * @return {!Promise<!print_preview.PrinterSetupResponse>} | 323 * @return {!Promise<!print_preview.PrinterSetupResponse>} |
| 313 */ | 324 */ |
| 314 setupPrinter: function(printerId) { | 325 setupPrinter: function(printerId) { |
| 315 return cr.sendWithPromise('setupPrinter', printerId); | 326 return cr.sendWithPromise('setupPrinter', printerId); |
| 316 }, | 327 }, |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { | 689 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { |
| 679 var pagePreviewGenEvent = new Event( | 690 var pagePreviewGenEvent = new Event( |
| 680 NativeLayer.EventType.PAGE_PREVIEW_READY); | 691 NativeLayer.EventType.PAGE_PREVIEW_READY); |
| 681 pagePreviewGenEvent.pageIndex = pageNumber; | 692 pagePreviewGenEvent.pageIndex = pageNumber; |
| 682 pagePreviewGenEvent.previewUid = previewUid; | 693 pagePreviewGenEvent.previewUid = previewUid; |
| 683 pagePreviewGenEvent.previewResponseId = previewResponseId; | 694 pagePreviewGenEvent.previewResponseId = previewResponseId; |
| 684 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); | 695 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); |
| 685 }, | 696 }, |
| 686 | 697 |
| 687 /** | 698 /** |
| 688 * Notification that access token is ready. | |
| 689 * @param {string} authType Type of access token. | |
| 690 * @param {string} accessToken Access token. | |
| 691 * @private | |
| 692 */ | |
| 693 onDidGetAccessToken_: function(authType, accessToken) { | |
| 694 var getAccessTokenEvent = new Event( | |
| 695 NativeLayer.EventType.ACCESS_TOKEN_READY); | |
| 696 getAccessTokenEvent.authType = authType; | |
| 697 getAccessTokenEvent.accessToken = accessToken; | |
| 698 this.eventTarget_.dispatchEvent(getAccessTokenEvent); | |
| 699 }, | |
| 700 | |
| 701 /** | |
| 702 * Update the print preview when new preview data is available. | 699 * Update the print preview when new preview data is available. |
| 703 * Create the PDF plugin as needed. | 700 * Create the PDF plugin as needed. |
| 704 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 701 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
| 705 * @param {number} previewUid Preview unique identifier. | 702 * @param {number} previewUid Preview unique identifier. |
| 706 * @param {number} previewResponseId The preview request id that resulted in | 703 * @param {number} previewResponseId The preview request id that resulted in |
| 707 * this response. | 704 * this response. |
| 708 * @private | 705 * @private |
| 709 */ | 706 */ |
| 710 onUpdatePrintPreview_: function(previewUid, previewResponseId) { | 707 onUpdatePrintPreview_: function(previewUid, previewResponseId) { |
| 711 var previewGenDoneEvent = new Event( | 708 var previewGenDoneEvent = new Event( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 724 * @private | 721 * @private |
| 725 */ | 722 */ |
| 726 onPrintPresetOptionsFromDocument_: function(options) { | 723 onPrintPresetOptionsFromDocument_: function(options) { |
| 727 var printPresetOptionsEvent = new Event( | 724 var printPresetOptionsEvent = new Event( |
| 728 NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 725 NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| 729 printPresetOptionsEvent.optionsFromDocument = options; | 726 printPresetOptionsEvent.optionsFromDocument = options; |
| 730 this.eventTarget_.dispatchEvent(printPresetOptionsEvent); | 727 this.eventTarget_.dispatchEvent(printPresetOptionsEvent); |
| 731 }, | 728 }, |
| 732 | 729 |
| 733 /** | 730 /** |
| 734 * Called when Chrome reports that attempt to resolve a provisional | |
| 735 * destination failed. | |
| 736 * @param {string} destinationId The provisional destination ID. | |
| 737 * @private | |
| 738 */ | |
| 739 failedToResolveProvisionalDestination_: function(destinationId) { | |
| 740 var evt = new Event( | |
| 741 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); | |
| 742 evt.provisionalId = destinationId; | |
| 743 evt.destination = null; | |
| 744 this.eventTarget_.dispatchEvent(evt); | |
| 745 }, | |
| 746 | |
| 747 /** | |
| 748 * Called when Chrome reports that a provisional destination has been | |
| 749 * successfully resolved. | |
| 750 * Currently used only for extension provided destinations. | |
| 751 * @param {string} provisionalDestinationId The provisional destination id. | |
| 752 * @param {!{extensionId: string, | |
| 753 * extensionName: string, | |
| 754 * id: string, | |
| 755 * name: string, | |
| 756 * description: (string|undefined)}} destinationInfo The resolved | |
| 757 * destination info. | |
| 758 * @private | |
| 759 */ | |
| 760 onProvisionalDestinationResolved_: function(provisionalDestinationId, | |
| 761 destinationInfo) { | |
| 762 var evt = new Event( | |
| 763 NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED); | |
| 764 evt.provisionalId = provisionalDestinationId; | |
| 765 evt.destination = destinationInfo; | |
| 766 this.eventTarget_.dispatchEvent(evt); | |
| 767 }, | |
| 768 | |
| 769 /** | |
| 770 * Allows for onManipulateSettings to be called | 731 * Allows for onManipulateSettings to be called |
| 771 * from the native layer. | 732 * from the native layer. |
| 772 * @private | 733 * @private |
| 773 */ | 734 */ |
| 774 onEnableManipulateSettingsForTest_: function() { | 735 onEnableManipulateSettingsForTest_: function() { |
| 775 global.onManipulateSettingsForTest = | 736 global.onManipulateSettingsForTest = |
| 776 this.onManipulateSettingsForTest_.bind(this); | 737 this.onManipulateSettingsForTest_.bind(this); |
| 777 }, | 738 }, |
| 778 | 739 |
| 779 /** | 740 /** |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 return this.serializedDefaultDestinationSelectionRulesStr_; | 952 return this.serializedDefaultDestinationSelectionRulesStr_; |
| 992 } | 953 } |
| 993 }; | 954 }; |
| 994 | 955 |
| 995 // Export | 956 // Export |
| 996 return { | 957 return { |
| 997 NativeInitialSettings: NativeInitialSettings, | 958 NativeInitialSettings: NativeInitialSettings, |
| 998 NativeLayer: NativeLayer | 959 NativeLayer: NativeLayer |
| 999 }; | 960 }; |
| 1000 }); | 961 }); |
| OLD | NEW |