OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 /** | 6 /** |
7 * Test version of the print preview PDF plugin | 7 * Test version of the print preview PDF plugin |
8 */ | 8 */ |
9 class PDFPluginStub { | 9 class PDFPluginStub { |
10 /** | 10 /** |
11 * @param {!print_preview.PreviewArea} The PreviewArea that owns this | 11 * @param {!print_preview.PreviewArea} The PreviewArea that owns this |
12 * plugin. | 12 * plugin. |
13 */ | 13 */ |
14 constructor(area) { | 14 constructor(area) { |
15 /** | 15 /** |
16 * @private {?Function} The callback to run when the plugin has loaded. | 16 * @private {?Function} The callback to run when the plugin has loaded. |
17 */ | 17 */ |
18 this.loadCallback_ = null; | 18 this.loadCallback_ = null; |
19 | 19 |
20 /** @private {!EventTracker} The plugin stub's event tracker. */ | |
21 this.tracker_ = new EventTracker(); | |
22 | |
23 // Call documentLoadComplete as soon as the preview area starts the | |
24 // preview. | |
25 this.tracker_.add( | |
26 area, | |
27 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS, | |
28 this.documentLoadComplete.bind(this)); | |
29 } | 20 } |
30 | 21 |
31 /** | 22 /** |
32 * @param {!Function} callback The callback to run when the plugin has | 23 * @param {!Function} callback The callback to run when the plugin has |
33 * loaded. | 24 * loaded. |
34 */ | 25 */ |
35 setLoadCallback(callback) { | 26 setLoadCallback(callback) { |
36 this.loadCallback_ = callback; | 27 this.loadCallback_ = callback; |
37 } | 28 } |
38 | 29 |
39 documentLoadComplete() { | |
40 if (this.loadCallback_) | |
41 this.loadCallback_(); | |
42 } | |
43 | |
44 /** | 30 /** |
45 * Stubbed out since some tests result in a call. | 31 * Stubbed out since some tests result in a call. |
46 * @param {string} url The url to initialize the plugin to. | 32 * @param {string} url The url to initialize the plugin to. |
47 * @param {boolean} color Whether the preview should be in color. | 33 * @param {boolean} color Whether the preview should be in color. |
48 * @param {!Array<number>} pages The pages to preview. | 34 * @param {!Array<number>} pages The pages to preview. |
49 * @param {boolean} modifiable Whether the source document is modifiable. | 35 * @param {boolean} modifiable Whether the source document is modifiable. |
50 */ | 36 */ |
51 resetPrintPreviewMode(url, color, pages, modifiable) {} | 37 resetPrintPreviewMode(url, color, pages, modifiable) {} |
| 38 |
| 39 /** |
| 40 * Called when the preview area wants the plugin to load a preview page. |
| 41 * Immediately calls loadCallback_(). |
| 42 * @param {string} url The preview URL |
| 43 * @param {number} index The index of the page number to load. |
| 44 */ |
| 45 loadPreviewPage(url, index) { |
| 46 if (this.loadCallback_) |
| 47 this.loadCallback_(); |
| 48 } |
52 } | 49 } |
53 | 50 |
54 return {PDFPluginStub: PDFPluginStub}; | 51 return {PDFPluginStub: PDFPluginStub}; |
55 }); | 52 }); |
OLD | NEW |