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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 'use strict'; | 70 'use strict'; |
71 | 71 |
72 /** | 72 /** |
73 * An interface to the native Chromium printing system layer. | 73 * An interface to the native Chromium printing system layer. |
74 * @constructor | 74 * @constructor |
75 */ | 75 */ |
76 function NativeLayer() { | 76 function NativeLayer() { |
77 // Bind global handlers | 77 // Bind global handlers |
78 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); | 78 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); |
79 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); | 79 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
80 global.printToCloud = this.onPrintToCloud_.bind(this); | |
81 global.fileSelectionCancelled = this.onFileSelectionCancelled_.bind(this); | |
82 global.fileSelectionCompleted = this.onFileSelectionCompleted_.bind(this); | |
83 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); | 80 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); |
84 global.invalidPrinterSettings = this.onInvalidPrinterSettings_.bind(this); | 81 global.invalidPrinterSettings = this.onInvalidPrinterSettings_.bind(this); |
85 global.onDidGetDefaultPageLayout = | 82 global.onDidGetDefaultPageLayout = |
86 this.onDidGetDefaultPageLayout_.bind(this); | 83 this.onDidGetDefaultPageLayout_.bind(this); |
87 global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this); | 84 global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this); |
88 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); | 85 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
89 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); | 86 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); |
90 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); | 87 global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this); |
91 global.onEnableManipulateSettingsForTest = | 88 global.onEnableManipulateSettingsForTest = |
92 this.onEnableManipulateSettingsForTest_.bind(this); | 89 this.onEnableManipulateSettingsForTest_.bind(this); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 /** | 122 /** |
126 * Event types dispatched from the Chromium native layer. | 123 * Event types dispatched from the Chromium native layer. |
127 * @enum {string} | 124 * @enum {string} |
128 * @const | 125 * @const |
129 */ | 126 */ |
130 NativeLayer.EventType = { | 127 NativeLayer.EventType = { |
131 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', | 128 ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY', |
132 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', | 129 CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE', |
133 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', | 130 DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD', |
134 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', | 131 DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING', |
135 FILE_SELECTION_CANCEL: 'print_preview.NativeLayer.FILE_SELECTION_CANCEL', | |
136 FILE_SELECTION_COMPLETE: | |
137 'print_preview.NativeLayer.FILE_SELECTION_COMPLETE', | |
138 MANIPULATE_SETTINGS_FOR_TEST: | 132 MANIPULATE_SETTINGS_FOR_TEST: |
139 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', | 133 'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST', |
140 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', | 134 PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY', |
141 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', | 135 PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY', |
142 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', | 136 PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY', |
143 PREVIEW_GENERATION_DONE: | 137 PREVIEW_GENERATION_DONE: |
144 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', | 138 'print_preview.NativeLayer.PREVIEW_GENERATION_DONE', |
145 PREVIEW_GENERATION_FAIL: | 139 PREVIEW_GENERATION_FAIL: |
146 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', | 140 'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL', |
147 PRINT_TO_CLOUD: 'print_preview.NativeLayer.PRINT_TO_CLOUD', | |
148 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', | 141 SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID', |
149 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', | 142 PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS', |
150 PROVISIONAL_DESTINATION_RESOLVED: | 143 PROVISIONAL_DESTINATION_RESOLVED: |
151 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED' | 144 'print_preview.NativeLayer.PROVISIONAL_DESTINATION_RESOLVED' |
152 }; | 145 }; |
153 | 146 |
154 /** | 147 /** |
155 * Constant values matching printing::DuplexMode enum. | 148 * Constant values matching printing::DuplexMode enum. |
156 * @enum {number} | 149 * @enum {number} |
157 */ | 150 */ |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 * @param {!print_preview.Destination} destination Destination to print to. | 403 * @param {!print_preview.Destination} destination Destination to print to. |
411 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 404 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
412 * state of the print ticket. | 405 * state of the print ticket. |
413 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface | 406 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface |
414 * to Google Cloud Print. | 407 * to Google Cloud Print. |
415 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 408 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
416 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the | 409 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the |
417 * system's preview application. | 410 * system's preview application. |
418 * @param {boolean=} opt_showSystemDialog Whether to open system dialog for | 411 * @param {boolean=} opt_showSystemDialog Whether to open system dialog for |
419 * advanced settings. | 412 * advanced settings. |
| 413 * @return {!Promise} Promise that will resolve when the print request is |
| 414 * finished or rejected. |
420 */ | 415 */ |
421 startPrint: function( | 416 print: function( |
422 destination, printTicketStore, cloudPrintInterface, documentInfo, | 417 destination, printTicketStore, cloudPrintInterface, documentInfo, |
423 opt_isOpenPdfInPreview, opt_showSystemDialog) { | 418 opt_isOpenPdfInPreview, opt_showSystemDialog) { |
424 assert( | 419 assert( |
425 printTicketStore.isTicketValid(), | 420 printTicketStore.isTicketValid(), |
426 'Trying to print when ticket is not valid'); | 421 'Trying to print when ticket is not valid'); |
427 | 422 |
428 assert( | 423 assert( |
429 !opt_showSystemDialog || (cr.isWindows && destination.isLocal), | 424 !opt_showSystemDialog || (cr.isWindows && destination.isLocal), |
430 'Implemented for Windows only'); | 425 'Implemented for Windows only'); |
431 | 426 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 482 |
488 if (destination.isPrivet || destination.isExtension) { | 483 if (destination.isPrivet || destination.isExtension) { |
489 ticket['ticket'] = printTicketStore.createPrintTicket(destination); | 484 ticket['ticket'] = printTicketStore.createPrintTicket(destination); |
490 ticket['capabilities'] = JSON.stringify(destination.capabilities); | 485 ticket['capabilities'] = JSON.stringify(destination.capabilities); |
491 } | 486 } |
492 | 487 |
493 if (opt_isOpenPdfInPreview) { | 488 if (opt_isOpenPdfInPreview) { |
494 ticket['OpenPDFInPreview'] = true; | 489 ticket['OpenPDFInPreview'] = true; |
495 } | 490 } |
496 | 491 |
497 chrome.send('print', [JSON.stringify(ticket)]); | 492 return cr.sendWithPromise('print', JSON.stringify(ticket)); |
498 }, | 493 }, |
499 | 494 |
500 /** Requests that the current pending print request be cancelled. */ | 495 /** Requests that the current pending print request be cancelled. */ |
501 startCancelPendingPrint: function() { | 496 startCancelPendingPrint: function() { |
502 chrome.send('cancelPendingPrintRequest'); | 497 chrome.send('cancelPendingPrintRequest'); |
503 }, | 498 }, |
504 | 499 |
505 /** Shows the system's native printing dialog. */ | 500 /** Shows the system's native printing dialog. */ |
506 startShowSystemDialog: function() { | 501 startShowSystemDialog: function() { |
507 assert(!cr.isWindows); | 502 assert(!cr.isWindows); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent); | 558 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent); |
564 }, | 559 }, |
565 | 560 |
566 /** Reloads the printer list. */ | 561 /** Reloads the printer list. */ |
567 onReloadPrintersList_: function() { | 562 onReloadPrintersList_: function() { |
568 cr.dispatchSimpleEvent( | 563 cr.dispatchSimpleEvent( |
569 this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD); | 564 this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD); |
570 }, | 565 }, |
571 | 566 |
572 /** | 567 /** |
573 * Called from the C++ layer. | |
574 * Take the PDF data handed to us and submit it to the cloud, closing the | |
575 * print preview dialog once the upload is successful. | |
576 * @param {string} data Data to send as the print job. | |
577 * @private | |
578 */ | |
579 onPrintToCloud_: function(data) { | |
580 var printToCloudEvent = new Event(NativeLayer.EventType.PRINT_TO_CLOUD); | |
581 printToCloudEvent.data = data; | |
582 this.eventTarget_.dispatchEvent(printToCloudEvent); | |
583 }, | |
584 | |
585 /** | |
586 * Called from PrintPreviewUI::OnFileSelectionCancelled to notify the print | |
587 * preview dialog regarding the file selection cancel event. | |
588 * @private | |
589 */ | |
590 onFileSelectionCancelled_: function() { | |
591 cr.dispatchSimpleEvent( | |
592 this.eventTarget_, NativeLayer.EventType.FILE_SELECTION_CANCEL); | |
593 }, | |
594 | |
595 /** | |
596 * Called from PrintPreviewUI::OnFileSelectionCompleted to notify the print | |
597 * preview dialog regarding the file selection completed event. | |
598 * @private | |
599 */ | |
600 onFileSelectionCompleted_: function() { | |
601 // If the file selection is completed and the dialog is not already closed | |
602 // it means that a pending print to pdf request exists. | |
603 cr.dispatchSimpleEvent( | |
604 this.eventTarget_, NativeLayer.EventType.FILE_SELECTION_COMPLETE); | |
605 }, | |
606 | |
607 /** | |
608 * Display an error message when print preview fails. | 568 * Display an error message when print preview fails. |
609 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). | 569 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). |
610 * @private | 570 * @private |
611 */ | 571 */ |
612 onPrintPreviewFailed_: function() { | 572 onPrintPreviewFailed_: function() { |
613 cr.dispatchSimpleEvent( | 573 cr.dispatchSimpleEvent( |
614 this.eventTarget_, NativeLayer.EventType.PREVIEW_GENERATION_FAIL); | 574 this.eventTarget_, NativeLayer.EventType.PREVIEW_GENERATION_FAIL); |
615 }, | 575 }, |
616 | 576 |
617 /** | 577 /** |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 return this.serializedDefaultDestinationSelectionRulesStr_; | 939 return this.serializedDefaultDestinationSelectionRulesStr_; |
980 } | 940 } |
981 }; | 941 }; |
982 | 942 |
983 // Export | 943 // Export |
984 return { | 944 return { |
985 NativeInitialSettings: NativeInitialSettings, | 945 NativeInitialSettings: NativeInitialSettings, |
986 NativeLayer: NativeLayer | 946 NativeLayer: NativeLayer |
987 }; | 947 }; |
988 }); | 948 }); |
OLD | NEW |