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 // TODO(rltoscano): Move data/* into print_preview.data namespace | 5 // TODO(rltoscano): Move data/* into print_preview.data namespace |
6 | 6 |
7 // <include src="component.js"> | 7 // <include src="component.js"> |
8 // <include src="print_preview_focus_manager.js"> | 8 // <include src="print_preview_focus_manager.js"> |
9 // | 9 // |
10 | 10 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 /** @override */ | 345 /** @override */ |
346 enterDocument: function() { | 346 enterDocument: function() { |
347 // Native layer events. | 347 // Native layer events. |
348 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); | 348 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); |
349 this.tracker.add( | 349 this.tracker.add( |
350 nativeLayerEventTarget, | 350 nativeLayerEventTarget, |
351 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, | 351 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE, |
352 this.onCloudPrintEnable_.bind(this)); | 352 this.onCloudPrintEnable_.bind(this)); |
353 this.tracker.add( | 353 this.tracker.add( |
354 nativeLayerEventTarget, | 354 nativeLayerEventTarget, |
355 print_preview.NativeLayer.EventType.PRINT_TO_CLOUD, | |
356 this.onPrintToCloud_.bind(this)); | |
357 this.tracker.add( | |
358 nativeLayerEventTarget, | |
359 print_preview.NativeLayer.EventType.FILE_SELECTION_CANCEL, | |
360 this.onFileSelectionCancel_.bind(this)); | |
361 this.tracker.add( | |
362 nativeLayerEventTarget, | |
363 print_preview.NativeLayer.EventType.FILE_SELECTION_COMPLETE, | |
364 this.onFileSelectionComplete_.bind(this)); | |
365 this.tracker.add( | |
366 nativeLayerEventTarget, | |
367 print_preview.NativeLayer.EventType.SETTINGS_INVALID, | 355 print_preview.NativeLayer.EventType.SETTINGS_INVALID, |
368 this.onSettingsInvalid_.bind(this)); | 356 this.onSettingsInvalid_.bind(this)); |
369 this.tracker.add( | 357 this.tracker.add( |
370 nativeLayerEventTarget, | 358 nativeLayerEventTarget, |
371 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS, | 359 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS, |
372 this.onPrintPresetOptionsFromDocument_.bind(this)); | 360 this.onPrintPresetOptionsFromDocument_.bind(this)); |
373 this.tracker.add( | 361 this.tracker.add( |
374 nativeLayerEventTarget, | 362 nativeLayerEventTarget, |
375 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, | 363 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, |
376 this.onPageCountReady_.bind(this)); | 364 this.onPageCountReady_.bind(this)); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 } else if ( | 525 } else if ( |
538 this.destinationStore_.selectedDestination.id == | 526 this.destinationStore_.selectedDestination.id == |
539 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 527 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
540 this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; | 528 this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; |
541 } else { | 529 } else { |
542 this.uiState_ = PrintPreviewUiState_.PRINTING; | 530 this.uiState_ = PrintPreviewUiState_.PRINTING; |
543 } | 531 } |
544 this.setIsEnabled_(false); | 532 this.setIsEnabled_(false); |
545 this.printHeader_.isCancelButtonEnabled = true; | 533 this.printHeader_.isCancelButtonEnabled = true; |
546 var printAttemptResult = this.printIfReady_(); | 534 var printAttemptResult = this.printIfReady_(); |
547 if (printAttemptResult == print_preview.PrintAttemptResult_.PRINTED || | 535 if (printAttemptResult == |
548 printAttemptResult == | 536 print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { |
549 print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { | |
550 if ((this.destinationStore_.selectedDestination.isLocal && | 537 if ((this.destinationStore_.selectedDestination.isLocal && |
551 !this.destinationStore_.selectedDestination.isPrivet && | 538 !this.destinationStore_.selectedDestination.isPrivet && |
552 !this.destinationStore_.selectedDestination.isExtension && | 539 !this.destinationStore_.selectedDestination.isExtension && |
553 this.destinationStore_.selectedDestination.id != | 540 this.destinationStore_.selectedDestination.id != |
554 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || | 541 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || |
555 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { | 542 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { |
556 // Hide the dialog for now. The actual print command will be issued | 543 // Hide the dialog for now. The actual print command will be issued |
557 // when the preview generation is done. | 544 // when the preview generation is done. |
558 this.nativeLayer_.startHideDialog(); | 545 this.nativeLayer_.startHideDialog(); |
559 } | 546 } |
(...skipping 23 matching lines...) Expand all Loading... |
583 this.printTicketStore_.isTicketValid(), | 570 this.printTicketStore_.isTicketValid(), |
584 'Trying to print with invalid ticket'); | 571 'Trying to print with invalid ticket'); |
585 if (getIsVisible(this.moreSettings_.getElement())) { | 572 if (getIsVisible(this.moreSettings_.getElement())) { |
586 new print_preview.PrintSettingsUiMetricsContext().record( | 573 new print_preview.PrintSettingsUiMetricsContext().record( |
587 this.moreSettings_.isExpanded ? | 574 this.moreSettings_.isExpanded ? |
588 print_preview.Metrics.PrintSettingsUiBucket | 575 print_preview.Metrics.PrintSettingsUiBucket |
589 .PRINT_WITH_SETTINGS_EXPANDED : | 576 .PRINT_WITH_SETTINGS_EXPANDED : |
590 print_preview.Metrics.PrintSettingsUiBucket | 577 print_preview.Metrics.PrintSettingsUiBucket |
591 .PRINT_WITH_SETTINGS_COLLAPSED); | 578 .PRINT_WITH_SETTINGS_COLLAPSED); |
592 } | 579 } |
593 this.nativeLayer_.startPrint( | 580 var destination = assert(this.destinationStore_.selectedDestination); |
594 assert(this.destinationStore_.selectedDestination), | 581 var whenPrintDone = this.nativeLayer_.print( |
595 this.printTicketStore_, this.cloudPrintInterface_, this.documentInfo_, | 582 destination, this.printTicketStore_, this.cloudPrintInterface_, |
| 583 this.documentInfo_, |
596 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, | 584 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
597 this.showSystemDialogBeforeNextPrint_); | 585 this.showSystemDialogBeforeNextPrint_); |
| 586 |
| 587 if (!destination.isLocal) { |
| 588 // Cloud print resolves when print data is returned to submit to cloud |
| 589 // print, or if setings are invalid. |
| 590 whenPrintDone.then( |
| 591 this.onPrintToCloud_.bind(this), |
| 592 this.onSettingsInvalid_.bind(this)); |
| 593 } else if (destination.isPrivet || destination.isExtension) { |
| 594 // Privet and extension resolve when printing is complete or if there |
| 595 // is an error printing. |
| 596 whenPrintDone.then( |
| 597 this.close_.bind(this), |
| 598 this.onPrintFailed_.bind(this)); |
| 599 } else if ( |
| 600 destination.id == |
| 601 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 602 // Save as PDF resolves when file selection is completed or cancelled. |
| 603 whenPrintDone.then( |
| 604 this.onFileSelectionComplete_.bind(this), |
| 605 this.onFileSelectionCancel_.bind(this)); |
| 606 } else { // standard local printer |
| 607 var boundHideDialog = function () { |
| 608 this.nativeLayer_.startHideDialog(); |
| 609 }.bind(this); |
| 610 // Local printers resolve when print is started. Hide the dialog. |
| 611 whenPrintDone.then(boundHideDialog, boundHideDialog); |
| 612 } |
| 613 |
598 this.showSystemDialogBeforeNextPrint_ = false; | 614 this.showSystemDialogBeforeNextPrint_ = false; |
599 return print_preview.PrintAttemptResult_.PRINTED; | 615 return print_preview.PrintAttemptResult_.PRINTED; |
600 }, | 616 }, |
601 | 617 |
602 /** | 618 /** |
603 * Closes the print preview. | 619 * Closes the print preview. |
604 * @private | 620 * @private |
605 */ | 621 */ |
606 close_: function() { | 622 close_: function() { |
607 this.exitDocument(); | 623 this.exitDocument(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_); | 716 this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_); |
701 this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_); | 717 this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_); |
702 if (this.destinationSearch_.getIsVisible()) { | 718 if (this.destinationSearch_.getIsVisible()) { |
703 this.destinationStore_.startLoadCloudDestinations(); | 719 this.destinationStore_.startLoadCloudDestinations(); |
704 this.invitationStore_.startLoadingInvitations(); | 720 this.invitationStore_.startLoadingInvitations(); |
705 } | 721 } |
706 }, | 722 }, |
707 | 723 |
708 /** | 724 /** |
709 * Called from the native layer when ready to print to Google Cloud Print. | 725 * Called from the native layer when ready to print to Google Cloud Print. |
710 * @param {Event} event Contains the body to send in the HTTP request. | 726 * @param {string} data The body to send in the HTTP request. |
711 * @private | 727 * @private |
712 */ | 728 */ |
713 onPrintToCloud_: function(event) { | 729 onPrintToCloud_: function(data) { |
714 assert( | 730 assert( |
715 this.uiState_ == PrintPreviewUiState_.PRINTING, | 731 this.uiState_ == PrintPreviewUiState_.PRINTING, |
716 'Document ready to be sent to the cloud when not in printing ' + | 732 'Document ready to be sent to the cloud when not in printing ' + |
717 'state: ' + this.uiState_); | 733 'state: ' + this.uiState_); |
718 assert( | 734 assert( |
719 this.cloudPrintInterface_ != null, | 735 this.cloudPrintInterface_ != null, |
720 'Google Cloud Print is not enabled'); | 736 'Google Cloud Print is not enabled'); |
721 assert(this.destinationStore_.selectedDestination != null); | 737 assert(this.destinationStore_.selectedDestination != null); |
722 this.cloudPrintInterface_.submit( | 738 this.cloudPrintInterface_.submit( |
723 this.destinationStore_.selectedDestination, this.printTicketStore_, | 739 this.destinationStore_.selectedDestination, this.printTicketStore_, |
724 this.documentInfo_, event.data); | 740 this.documentInfo_, data); |
725 }, | 741 }, |
726 | 742 |
727 /** | 743 /** |
728 * Called from the native layer when the user cancels the save-to-pdf file | 744 * Called from the native layer when the user cancels the save-to-pdf file |
729 * selection dialog. | 745 * selection dialog. |
730 * @private | 746 * @private |
731 */ | 747 */ |
732 onFileSelectionCancel_: function() { | 748 onFileSelectionCancel_: function() { |
733 assert( | 749 assert( |
734 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, | 750 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 * @private | 1036 * @private |
1021 */ | 1037 */ |
1022 onPageCountReady_: function(event) { | 1038 onPageCountReady_: function(event) { |
1023 if (event.fitToPageScaling >= 0) { | 1039 if (event.fitToPageScaling >= 0) { |
1024 this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); | 1040 this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); |
1025 } | 1041 } |
1026 }, | 1042 }, |
1027 | 1043 |
1028 /** | 1044 /** |
1029 * Called when printing to a privet or extension printer fails. | 1045 * Called when printing to a privet or extension printer fails. |
1030 * @param {number | string} httpError The HTTP error code, or -1 if not an | 1046 * @param {*} httpError The HTTP error code, or -1 or a string describing |
1031 * HTTP error. | 1047 * the error, if not an HTTP error. |
1032 * @private | 1048 * @private |
1033 */ | 1049 */ |
1034 onPrintFailed_: function(httpError) { | 1050 onPrintFailed_: function(httpError) { |
1035 console.error('Privet printing failed with error code ' + httpError); | 1051 console.error('Privet printing failed with error code ' + httpError); |
1036 this.printHeader_.setErrorMessage( | 1052 this.printHeader_.setErrorMessage( |
1037 loadTimeData.getString('couldNotPrint')); | 1053 loadTimeData.getString('couldNotPrint')); |
1038 }, | 1054 }, |
1039 | 1055 |
1040 /** | 1056 /** |
1041 * Called when the print preview settings need to be changed for testing. | 1057 * Called when the print preview settings need to be changed for testing. |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 // <include src="search/destination_search.js"> | 1361 // <include src="search/destination_search.js"> |
1346 // <include src="search/provisional_destination_resolver.js"> | 1362 // <include src="search/provisional_destination_resolver.js"> |
1347 | 1363 |
1348 window.addEventListener('DOMContentLoaded', function() { | 1364 window.addEventListener('DOMContentLoaded', function() { |
1349 var previewWindow = /** @type {{isTest: boolean}} */ (window); | 1365 var previewWindow = /** @type {{isTest: boolean}} */ (window); |
1350 if (!previewWindow.isTest) { | 1366 if (!previewWindow.isTest) { |
1351 var printPreview = new print_preview.PrintPreview(); | 1367 var printPreview = new print_preview.PrintPreview(); |
1352 printPreview.initialize(); | 1368 printPreview.initialize(); |
1353 } | 1369 } |
1354 }); | 1370 }); |
OLD | NEW |