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