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 * extensionId: string, |
| 72 * extensionName: string, |
| 73 * id: string, |
| 74 * name: string, |
| 75 * description: (string|undefined), |
| 76 * }} |
| 77 */ |
| 78 print_preview.ProvisionalDestinationInfo; |
| 79 |
69 cr.define('print_preview', function() { | 80 cr.define('print_preview', function() { |
70 'use strict'; | 81 'use strict'; |
71 | 82 |
72 /** | 83 /** |
73 * An interface to the native Chromium printing system layer. | 84 * An interface to the native Chromium printing system layer. |
74 * @constructor | 85 * @constructor |
75 */ | 86 */ |
76 function NativeLayer() { | 87 function NativeLayer() { |
77 // Bind global handlers | 88 // Bind global handlers |
78 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); | 89 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); |
79 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); | 90 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
80 global.printToCloud = this.onPrintToCloud_.bind(this); | 91 global.printToCloud = this.onPrintToCloud_.bind(this); |
81 global.fileSelectionCancelled = | 92 global.fileSelectionCancelled = |
82 this.onFileSelectionCancelled_.bind(this); | 93 this.onFileSelectionCancelled_.bind(this); |
83 global.fileSelectionCompleted = | 94 global.fileSelectionCompleted = |
84 this.onFileSelectionCompleted_.bind(this); | 95 this.onFileSelectionCompleted_.bind(this); |
85 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); | 96 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); |
86 global.invalidPrinterSettings = | 97 global.invalidPrinterSettings = |
87 this.onInvalidPrinterSettings_.bind(this); | 98 this.onInvalidPrinterSettings_.bind(this); |
88 global.onDidGetDefaultPageLayout = | 99 global.onDidGetDefaultPageLayout = |
89 this.onDidGetDefaultPageLayout_.bind(this); | 100 this.onDidGetDefaultPageLayout_.bind(this); |
90 global.onDidGetPreviewPageCount = | 101 global.onDidGetPreviewPageCount = |
91 this.onDidGetPreviewPageCount_.bind(this); | 102 this.onDidGetPreviewPageCount_.bind(this); |
92 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); | 103 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
93 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); | 104 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); |
94 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); | |
95 global.onEnableManipulateSettingsForTest = | 105 global.onEnableManipulateSettingsForTest = |
96 this.onEnableManipulateSettingsForTest_.bind(this); | 106 this.onEnableManipulateSettingsForTest_.bind(this); |
97 global.printPresetOptionsFromDocument = | 107 global.printPresetOptionsFromDocument = |
98 this.onPrintPresetOptionsFromDocument_.bind(this); | 108 this.onPrintPresetOptionsFromDocument_.bind(this); |
99 global.onProvisionalPrinterResolved = | |
100 this.onProvisionalDestinationResolved_.bind(this); | |
101 global.failedToResolveProvisionalPrinter = | |
102 this.failedToResolveProvisionalDestination_.bind(this); | |
103 | 109 |
104 /** @private {!cr.EventTarget} */ | 110 /** @private {!cr.EventTarget} */ |
105 this.eventTarget_ = new cr.EventTarget(); | 111 this.eventTarget_ = new cr.EventTarget(); |
106 } | 112 } |
107 | 113 |
108 /** @private {?print_preview.NativeLayer} */ | 114 /** @private {?print_preview.NativeLayer} */ |
109 var currentInstance = null; | 115 var currentInstance = null; |
110 | 116 |
111 /** | 117 /** |
112 * @return {!print_preview.NativeLayer} The singleton instance. | 118 * @return {!print_preview.NativeLayer} The singleton instance. |
(...skipping 12 matching lines...) Expand all Loading... |
125 NativeLayer.setInstance = function(instance) { | 131 NativeLayer.setInstance = function(instance) { |
126 currentInstance = instance; | 132 currentInstance = instance; |
127 }; | 133 }; |
128 | 134 |
129 /** | 135 /** |
130 * Event types dispatched from the Chromium native layer. | 136 * Event types dispatched from the Chromium native layer. |
131 * @enum {string} | 137 * @enum {string} |
132 * @const | 138 * @const |
133 */ | 139 */ |
134 NativeLayer.EventType = { | 140 NativeLayer.EventType = { |
135 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | |
136 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', | 141 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', |
137 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', | 142 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', |
138 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', | 143 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', |
139 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', | 144 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', |
140 FILE_SELECTION_COMPLETE: | 145 FILE_SELECTION_COMPLETE: |
141 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', | 146 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', |
142 MANIPULATE_SETTINGS_FOR_TEST: | 147 MANIPULATE_SETTINGS_FOR_TEST: |
143 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', | 148 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', |
144 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', | 149 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', |
145 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', | 150 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', |
146 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', | 151 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', |
147 PREVIEW_GENERATION_DONE: | 152 PREVIEW_GENERATION_DONE: |
148 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 153 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
149 PREVIEW_GENERATION_FAIL: | 154 PREVIEW_GENERATION_FAIL: |
150 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 155 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
151 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | 156 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', |
152 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 157 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
153 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', | 158 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', |
154 PROVISIONAL_DESTINATION_RESOLVED: | |
155 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED' | |
156 }; | 159 }; |
157 | 160 |
158 /** | 161 /** |
159 * Constant values matching printing::DuplexMode enum. | 162 * Constant values matching printing::DuplexMode enum. |
160 * @enum {number} | 163 * @enum {number} |
161 */ | 164 */ |
162 NativeLayer.DuplexMode = { | 165 NativeLayer.DuplexMode = { |
163 SIMPLEX: 0, | 166 SIMPLEX: 0, |
164 LONG_EDGE: 1, | 167 LONG_EDGE: 1, |
165 UNKNOWN_DUPLEX_MODE: -1 | 168 UNKNOWN_DUPLEX_MODE: -1 |
(...skipping 19 matching lines...) Expand all Loading... |
185 | 188 |
186 NativeLayer.prototype = { | 189 NativeLayer.prototype = { |
187 /** @return {!cr.EventTarget} The event target for the native layer.*/ | 190 /** @return {!cr.EventTarget} The event target for the native layer.*/ |
188 getEventTarget: function() { | 191 getEventTarget: function() { |
189 return this.eventTarget_; | 192 return this.eventTarget_; |
190 }, | 193 }, |
191 | 194 |
192 /** | 195 /** |
193 * Requests access token for cloud print requests. | 196 * Requests access token for cloud print requests. |
194 * @param {string} authType type of access token. | 197 * @param {string} authType type of access token. |
| 198 * @return {!Promise<string>} |
195 */ | 199 */ |
196 startGetAccessToken: function(authType) { | 200 getAccessToken: function(authType) { |
197 chrome.send('getAccessToken', [authType]); | 201 return cr.sendWithPromise('getAccessToken', authType); |
198 }, | 202 }, |
199 | 203 |
200 /** | 204 /** |
201 * Gets the initial settings to initialize the print preview with. | 205 * Gets the initial settings to initialize the print preview with. |
202 * @return {!Promise<!print_preview.NativeInitialSettings>} | 206 * @return {!Promise<!print_preview.NativeInitialSettings>} |
203 */ | 207 */ |
204 getInitialSettings: function() { | 208 getInitialSettings: function() { |
205 return cr.sendWithPromise('getInitialSettings').then( | 209 return cr.sendWithPromise('getInitialSettings').then( |
206 /** | 210 /** |
207 * @param {!Object} initialSettings Object containing the raw | 211 * @param {!Object} initialSettings Object containing the raw |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 * capabilities are requested. | 293 * capabilities are requested. |
290 * @return {!Promise<!print_preview.Cdd>} | 294 * @return {!Promise<!print_preview.Cdd>} |
291 */ | 295 */ |
292 getExtensionPrinterCapabilities: function(destinationId) { | 296 getExtensionPrinterCapabilities: function(destinationId) { |
293 return cr.sendWithPromise('getExtensionPrinterCapabilities', | 297 return cr.sendWithPromise('getExtensionPrinterCapabilities', |
294 destinationId); | 298 destinationId); |
295 }, | 299 }, |
296 | 300 |
297 /** | 301 /** |
298 * Requests Chrome to resolve provisional extension destination by granting | 302 * Requests Chrome to resolve provisional extension destination by granting |
299 * the provider extension access to the printer. Chrome will respond with | 303 * 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 | 304 * @param {string} provisionalDestinationId |
| 305 * @return {!Promise<!print_preview.ProvisionalDestinationInfo>} |
304 */ | 306 */ |
305 grantExtensionPrinterAccess: function(provisionalDestinationId) { | 307 grantExtensionPrinterAccess: function(provisionalDestinationId) { |
306 chrome.send('grantExtensionPrinterAccess', [provisionalDestinationId]); | 308 return cr.sendWithPromise('grantExtensionPrinterAccess', |
| 309 provisionalDestinationId); |
307 }, | 310 }, |
308 | 311 |
309 /** | 312 /** |
310 * Requests that Chrome peform printer setup for the given printer. | 313 * Requests that Chrome peform printer setup for the given printer. |
311 * @param {string} printerId | 314 * @param {string} printerId |
312 * @return {!Promise<!print_preview.PrinterSetupResponse>} | 315 * @return {!Promise<!print_preview.PrinterSetupResponse>} |
313 */ | 316 */ |
314 setupPrinter: function(printerId) { | 317 setupPrinter: function(printerId) { |
315 return cr.sendWithPromise('setupPrinter', printerId); | 318 return cr.sendWithPromise('setupPrinter', printerId); |
316 }, | 319 }, |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { | 681 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { |
679 var pagePreviewGenEvent = new Event( | 682 var pagePreviewGenEvent = new Event( |
680 NativeLayer.EventType.PAGE_PREVIEW_READY); | 683 NativeLayer.EventType.PAGE_PREVIEW_READY); |
681 pagePreviewGenEvent.pageIndex = pageNumber; | 684 pagePreviewGenEvent.pageIndex = pageNumber; |
682 pagePreviewGenEvent.previewUid = previewUid; | 685 pagePreviewGenEvent.previewUid = previewUid; |
683 pagePreviewGenEvent.previewResponseId = previewResponseId; | 686 pagePreviewGenEvent.previewResponseId = previewResponseId; |
684 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); | 687 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); |
685 }, | 688 }, |
686 | 689 |
687 /** | 690 /** |
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. | 691 * Update the print preview when new preview data is available. |
703 * Create the PDF plugin as needed. | 692 * Create the PDF plugin as needed. |
704 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 693 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
705 * @param {number} previewUid Preview unique identifier. | 694 * @param {number} previewUid Preview unique identifier. |
706 * @param {number} previewResponseId The preview request id that resulted in | 695 * @param {number} previewResponseId The preview request id that resulted in |
707 * this response. | 696 * this response. |
708 * @private | 697 * @private |
709 */ | 698 */ |
710 onUpdatePrintPreview_: function(previewUid, previewResponseId) { | 699 onUpdatePrintPreview_: function(previewUid, previewResponseId) { |
711 var previewGenDoneEvent = new Event( | 700 var previewGenDoneEvent = new Event( |
(...skipping 12 matching lines...) Expand all Loading... |
724 * @private | 713 * @private |
725 */ | 714 */ |
726 onPrintPresetOptionsFromDocument_: function(options) { | 715 onPrintPresetOptionsFromDocument_: function(options) { |
727 var printPresetOptionsEvent = new Event( | 716 var printPresetOptionsEvent = new Event( |
728 NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 717 NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
729 printPresetOptionsEvent.optionsFromDocument = options; | 718 printPresetOptionsEvent.optionsFromDocument = options; |
730 this.eventTarget_.dispatchEvent(printPresetOptionsEvent); | 719 this.eventTarget_.dispatchEvent(printPresetOptionsEvent); |
731 }, | 720 }, |
732 | 721 |
733 /** | 722 /** |
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 | 723 * Allows for onManipulateSettings to be called |
771 * from the native layer. | 724 * from the native layer. |
772 * @private | 725 * @private |
773 */ | 726 */ |
774 onEnableManipulateSettingsForTest_: function() { | 727 onEnableManipulateSettingsForTest_: function() { |
775 global.onManipulateSettingsForTest = | 728 global.onManipulateSettingsForTest = |
776 this.onManipulateSettingsForTest_.bind(this); | 729 this.onManipulateSettingsForTest_.bind(this); |
777 }, | 730 }, |
778 | 731 |
779 /** | 732 /** |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 return this.serializedDefaultDestinationSelectionRulesStr_; | 944 return this.serializedDefaultDestinationSelectionRulesStr_; |
992 } | 945 } |
993 }; | 946 }; |
994 | 947 |
995 // Export | 948 // Export |
996 return { | 949 return { |
997 NativeInitialSettings: NativeInitialSettings, | 950 NativeInitialSettings: NativeInitialSettings, |
998 NativeLayer: NativeLayer | 951 NativeLayer: NativeLayer |
999 }; | 952 }; |
1000 }); | 953 }); |
OLD | NEW |