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 |
11 * @extends {cr.EventTarget} | 11 * @extends {cr.EventTarget} |
12 */ | 12 */ |
13 function NativeLayer() { | 13 function NativeLayer() { |
14 cr.EventTarget.call(this); | 14 cr.EventTarget.call(this); |
15 | 15 |
16 // Bind global handlers | 16 // Bind global handlers |
17 global['setInitialSettings'] = this.onSetInitialSettings_.bind(this); | 17 global['setInitialSettings'] = this.onSetInitialSettings_.bind(this); |
| 18 global['setPdfCapabilities'] = this.onSetPdfCapabilities_.bind(this); |
18 global['setUseCloudPrint'] = this.onSetUseCloudPrint_.bind(this); | 19 global['setUseCloudPrint'] = this.onSetUseCloudPrint_.bind(this); |
19 global['setPrinters'] = this.onSetPrinters_.bind(this); | 20 global['setPrinters'] = this.onSetPrinters_.bind(this); |
20 global['updateWithPrinterCapabilities'] = | 21 global['updateWithPrinterCapabilities'] = |
21 this.onUpdateWithPrinterCapabilities_.bind(this); | 22 this.onUpdateWithPrinterCapabilities_.bind(this); |
22 global['failedToGetPrinterCapabilities'] = | 23 global['failedToGetPrinterCapabilities'] = |
23 this.onFailedToGetPrinterCapabilities_.bind(this); | 24 this.onFailedToGetPrinterCapabilities_.bind(this); |
24 global['failedToGetPrivetPrinterCapabilities'] = | 25 global['failedToGetPrivetPrinterCapabilities'] = |
25 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); | 26 this.onFailedToGetPrivetPrinterCapabilities_.bind(this); |
26 global['reloadPrintersList'] = this.onReloadPrintersList_.bind(this); | 27 global['reloadPrintersList'] = this.onReloadPrintersList_.bind(this); |
27 global['printToCloud'] = this.onPrintToCloud_.bind(this); | 28 global['printToCloud'] = this.onPrintToCloud_.bind(this); |
28 global['fileSelectionCancelled'] = | 29 global['fileSelectionCancelled'] = |
29 this.onFileSelectionCancelled_.bind(this); | 30 this.onFileSelectionCancelled_.bind(this); |
30 global['fileSelectionCompleted'] = | 31 global['fileSelectionCompleted'] = |
31 this.onFileSelectionCompleted_.bind(this); | 32 this.onFileSelectionCompleted_.bind(this); |
32 global['printPreviewFailed'] = this.onPrintPreviewFailed_.bind(this); | 33 global['printPreviewFailed'] = this.onPrintPreviewFailed_.bind(this); |
33 global['invalidPrinterSettings'] = | 34 global['invalidPrinterSettings'] = |
34 this.onInvalidPrinterSettings_.bind(this); | 35 this.onInvalidPrinterSettings_.bind(this); |
35 global['onDidGetDefaultPageLayout'] = | 36 global['onDidGetDefaultPageLayout'] = |
36 this.onDidGetDefaultPageLayout_.bind(this); | 37 this.onDidGetDefaultPageLayout_.bind(this); |
37 global['onDidGetPreviewPageCount'] = | 38 global['onDidGetPreviewPageCount'] = |
38 this.onDidGetPreviewPageCount_.bind(this); | 39 this.onDidGetPreviewPageCount_.bind(this); |
39 global['onDidPreviewPage'] = this.onDidPreviewPage_.bind(this); | 40 global['onDidPreviewPage'] = this.onDidPreviewPage_.bind(this); |
40 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); | 41 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); |
41 global['printScalingDisabledForSourcePDF'] = | 42 global['printScalingDisabledForSourcePDF'] = |
42 this.onPrintScalingDisabledForSourcePDF_.bind(this); | 43 this.onPrintScalingDisabledForSourcePDF_.bind(this); |
43 global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this); | 44 global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this); |
44 global['autoCancelForTesting'] = this.autoCancelForTesting_.bind(this); | 45 global['autoCancelForTesting'] = this.autoCancelForTesting_.bind(this); |
45 global['onPrivetPrinterChanged'] = this.onPrivetPrinterChanged_.bind(this); | 46 global['onPrivetPrinterChanged'] = this.onPrivetPrinterChanged_.bind(this); |
46 global['onPrivetCapabilitiesSet'] = | 47 global['onPrivetCapabilitiesSet'] = |
47 this.onPrivetCapabilitiesSet_.bind(this); | 48 this.onPrivetCapabilitiesSet_.bind(this); |
48 global['onPrivetPrintFailed'] = this.onPrivetPrintFailed_.bind(this); | 49 global['onPrivetPrintFailed'] = this.onPrivetPrintFailed_.bind(this); |
49 }; | 50 }; |
50 | 51 |
51 /** | 52 /** |
52 * Event types dispatched from the Chromium native layer. | 53 * Event types dispatched from the Chromium native layer. |
53 * @enum {string} | 54 * @enum {string} |
54 * @const | 55 * @const |
55 */ | 56 */ |
56 NativeLayer.EventType = { | 57 NativeLayer.EventType = { |
57 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | 58 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', |
58 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', | 59 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', |
59 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', | 60 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', |
60 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', | 61 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', |
61 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', | 62 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', |
62 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', | 63 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', |
63 FILE_SELECTION_COMPLETE: | 64 FILE_SELECTION_COMPLETE: |
64 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', | 65 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', |
65 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL', | 66 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL', |
66 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', | 67 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', |
67 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', | 68 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', |
68 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', | 69 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', |
69 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', | 70 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', |
70 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', | 71 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', |
| 72 PDF_CAPABILITIES_READY: 'print_preview.NativeLayer.PDF_CAPABILITIES_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' |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 */ | 119 */ |
118 startGetAccessToken: function(authType) { | 120 startGetAccessToken: function(authType) { |
119 chrome.send('getAccessToken', [authType]); | 121 chrome.send('getAccessToken', [authType]); |
120 }, | 122 }, |
121 | 123 |
122 /** Gets the initial settings to initialize the print preview with. */ | 124 /** Gets the initial settings to initialize the print preview with. */ |
123 startGetInitialSettings: function() { | 125 startGetInitialSettings: function() { |
124 chrome.send('getInitialSettings'); | 126 chrome.send('getInitialSettings'); |
125 }, | 127 }, |
126 | 128 |
| 129 /** Requests PDF printer capabilities, such as media size. */ |
| 130 startGetPdfCapabilities: function() { |
| 131 chrome.send('getPdfCapabilities'); |
| 132 }, |
| 133 |
127 /** | 134 /** |
128 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET | 135 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET |
129 * event will be dispatched in response. | 136 * event will be dispatched in response. |
130 */ | 137 */ |
131 startGetLocalDestinations: function() { | 138 startGetLocalDestinations: function() { |
132 chrome.send('getPrinters'); | 139 chrome.send('getPrinters'); |
133 }, | 140 }, |
134 | 141 |
135 /** | 142 /** |
136 * Requests the network's privet print destinations. A number of | 143 * Requests the network's privet print destinations. A number of |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 initialSettings['printerName'] || null, | 405 initialSettings['printerName'] || null, |
399 initialSettings['appState'] || null); | 406 initialSettings['appState'] || null); |
400 | 407 |
401 var initialSettingsSetEvent = new Event( | 408 var initialSettingsSetEvent = new Event( |
402 NativeLayer.EventType.INITIAL_SETTINGS_SET); | 409 NativeLayer.EventType.INITIAL_SETTINGS_SET); |
403 initialSettingsSetEvent.initialSettings = nativeInitialSettings; | 410 initialSettingsSetEvent.initialSettings = nativeInitialSettings; |
404 this.dispatchEvent(initialSettingsSetEvent); | 411 this.dispatchEvent(initialSettingsSetEvent); |
405 }, | 412 }, |
406 | 413 |
407 /** | 414 /** |
| 415 * @param {!Object} capabilities Object containing some of the PDF printer |
| 416 * capabilities, such as media size. |
| 417 */ |
| 418 onSetPdfCapabilities_: function(capabilities) { |
| 419 var event = new Event(NativeLayer.EventType.PDF_CAPABILITIES_READY); |
| 420 event.capabilities = capabilities; |
| 421 this.dispatchEvent(event); |
| 422 }, |
| 423 |
| 424 /** |
408 * Turn on the integration of Cloud Print. | 425 * Turn on the integration of Cloud Print. |
409 * @param {string} cloudPrintURL The URL to use for cloud print servers. | 426 * @param {string} cloudPrintURL The URL to use for cloud print servers. |
410 * @private | 427 * @private |
411 */ | 428 */ |
412 onSetUseCloudPrint_: function(cloudPrintURL) { | 429 onSetUseCloudPrint_: function(cloudPrintURL) { |
413 var cloudPrintEnableEvent = new Event( | 430 var cloudPrintEnableEvent = new Event( |
414 NativeLayer.EventType.CLOUD_PRINT_ENABLE); | 431 NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
415 cloudPrintEnableEvent.baseCloudPrintUrl = cloudPrintURL; | 432 cloudPrintEnableEvent.baseCloudPrintUrl = cloudPrintURL; |
416 this.dispatchEvent(cloudPrintEnableEvent); | 433 this.dispatchEvent(cloudPrintEnableEvent); |
417 }, | 434 }, |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 return this.serializedAppStateStr_; | 867 return this.serializedAppStateStr_; |
851 } | 868 } |
852 }; | 869 }; |
853 | 870 |
854 // Export | 871 // Export |
855 return { | 872 return { |
856 NativeInitialSettings: NativeInitialSettings, | 873 NativeInitialSettings: NativeInitialSettings, |
857 NativeLayer: NativeLayer | 874 NativeLayer: NativeLayer |
858 }; | 875 }; |
859 }); | 876 }); |
OLD | NEW |