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 21 matching lines...) Expand all Loading... |
32 this.onInvalidPrinterSettings_.bind(this); | 32 this.onInvalidPrinterSettings_.bind(this); |
33 global['onDidGetDefaultPageLayout'] = | 33 global['onDidGetDefaultPageLayout'] = |
34 this.onDidGetDefaultPageLayout_.bind(this); | 34 this.onDidGetDefaultPageLayout_.bind(this); |
35 global['onDidGetPreviewPageCount'] = | 35 global['onDidGetPreviewPageCount'] = |
36 this.onDidGetPreviewPageCount_.bind(this); | 36 this.onDidGetPreviewPageCount_.bind(this); |
37 global['reloadPreviewPages'] = this.onReloadPreviewPages_.bind(this); | 37 global['reloadPreviewPages'] = this.onReloadPreviewPages_.bind(this); |
38 global['onDidPreviewPage'] = this.onDidPreviewPage_.bind(this); | 38 global['onDidPreviewPage'] = this.onDidPreviewPage_.bind(this); |
39 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); | 39 global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this); |
40 global['printScalingDisabledForSourcePDF'] = | 40 global['printScalingDisabledForSourcePDF'] = |
41 this.onPrintScalingDisabledForSourcePDF_.bind(this); | 41 this.onPrintScalingDisabledForSourcePDF_.bind(this); |
42 global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this); | |
43 }; | 42 }; |
44 | 43 |
45 /** | 44 /** |
46 * Event types dispatched from the Chromium native layer. | 45 * Event types dispatched from the Chromium native layer. |
47 * @enum {string} | 46 * @enum {string} |
48 * @const | 47 * @const |
49 */ | 48 */ |
50 NativeLayer.EventType = { | 49 NativeLayer.EventType = { |
51 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | |
52 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', | 50 CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET', |
53 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', | 51 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', |
54 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', | 52 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', |
55 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', | 53 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', |
56 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', | 54 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', |
57 FILE_SELECTION_COMPLETE: | 55 FILE_SELECTION_COMPLETE: |
58 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', | 56 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', |
59 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL', | 57 GET_CAPABILITIES_FAIL: 'print_preview.NativeLayer.GET_CAPABILITIES_FAIL', |
60 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', | 58 INITIAL_SETTINGS_SET: 'print_preview.NativeLayer.INITIAL_SETTINGS_SET', |
61 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', | 59 LOCAL_DESTINATIONS_SET: 'print_preview.NativeLayer.LOCAL_DESTINATIONS_SET', |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 * Version of the serialized state of the print preview. | 93 * Version of the serialized state of the print preview. |
96 * @type {number} | 94 * @type {number} |
97 * @const | 95 * @const |
98 * @private | 96 * @private |
99 */ | 97 */ |
100 NativeLayer.SERIALIZED_STATE_VERSION_ = 1; | 98 NativeLayer.SERIALIZED_STATE_VERSION_ = 1; |
101 | 99 |
102 NativeLayer.prototype = { | 100 NativeLayer.prototype = { |
103 __proto__: cr.EventTarget.prototype, | 101 __proto__: cr.EventTarget.prototype, |
104 | 102 |
105 /** | |
106 * Requests access token for cloud print requests. | |
107 * @param {string} authType type of access token. | |
108 */ | |
109 startGetAccessToken: function(authType) { | |
110 chrome.send('getAccessToken', [authType]); | |
111 }, | |
112 | |
113 /** Gets the initial settings to initialize the print preview with. */ | 103 /** Gets the initial settings to initialize the print preview with. */ |
114 startGetInitialSettings: function() { | 104 startGetInitialSettings: function() { |
115 chrome.send('getInitialSettings'); | 105 chrome.send('getInitialSettings'); |
116 }, | 106 }, |
117 | 107 |
118 /** | 108 /** |
119 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET | 109 * Requests the system's local print destinations. A LOCAL_DESTINATIONS_SET |
120 * event will be dispatched in response. | 110 * event will be dispatched in response. |
121 */ | 111 */ |
122 startGetLocalDestinations: function() { | 112 startGetLocalDestinations: function() { |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { | 513 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { |
524 var pagePreviewGenEvent = new cr.Event( | 514 var pagePreviewGenEvent = new cr.Event( |
525 NativeLayer.EventType.PAGE_PREVIEW_READY); | 515 NativeLayer.EventType.PAGE_PREVIEW_READY); |
526 pagePreviewGenEvent.pageIndex = pageNumber; | 516 pagePreviewGenEvent.pageIndex = pageNumber; |
527 pagePreviewGenEvent.previewUid = previewUid; | 517 pagePreviewGenEvent.previewUid = previewUid; |
528 pagePreviewGenEvent.previewResponseId = previewResponseId; | 518 pagePreviewGenEvent.previewResponseId = previewResponseId; |
529 this.dispatchEvent(pagePreviewGenEvent); | 519 this.dispatchEvent(pagePreviewGenEvent); |
530 }, | 520 }, |
531 | 521 |
532 /** | 522 /** |
533 * Notification that access token is ready. | |
534 * @param {string} authType Type of access token. | |
535 * @param {string} accessToken Access token. | |
536 * @private | |
537 */ | |
538 onDidGetAccessToken_: function(authType, accessToken) { | |
539 var getAccessTokenEvent = new cr.Event( | |
540 NativeLayer.EventType.ACCESS_TOKEN_READY); | |
541 getAccessTokenEvent.authType = authType; | |
542 getAccessTokenEvent.accessToken = accessToken; | |
543 this.dispatchEvent(getAccessTokenEvent); | |
544 }, | |
545 | |
546 /** | |
547 * Update the print preview when new preview data is available. | 523 * Update the print preview when new preview data is available. |
548 * Create the PDF plugin as needed. | 524 * Create the PDF plugin as needed. |
549 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 525 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
550 * @param {number} previewUid Preview unique identifier. | 526 * @param {number} previewUid Preview unique identifier. |
551 * @param {number} previewResponseId The preview request id that resulted in | 527 * @param {number} previewResponseId The preview request id that resulted in |
552 * this response. | 528 * this response. |
553 * @private | 529 * @private |
554 */ | 530 */ |
555 onUpdatePrintPreview_: function(previewUid, previewResponseId) { | 531 onUpdatePrintPreview_: function(previewUid, previewResponseId) { |
556 var previewGenDoneEvent = new cr.Event( | 532 var previewGenDoneEvent = new cr.Event( |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 return this.serializedAppStateStr_; | 708 return this.serializedAppStateStr_; |
733 } | 709 } |
734 }; | 710 }; |
735 | 711 |
736 // Export | 712 // Export |
737 return { | 713 return { |
738 NativeInitialSettings: NativeInitialSettings, | 714 NativeInitialSettings: NativeInitialSettings, |
739 NativeLayer: NativeLayer | 715 NativeLayer: NativeLayer |
740 }; | 716 }; |
741 }); | 717 }); |
OLD | NEW |