| 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 this.nativeLayer_ |
| 595 this.printTicketStore_, this.cloudPrintInterface_, this.documentInfo_, | 582 .print( |
| 596 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, | 583 destination, this.printTicketStore_, this.cloudPrintInterface_, |
| 597 this.showSystemDialogBeforeNextPrint_); | 584 this.documentInfo_, |
| 585 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
| 586 this.showSystemDialogBeforeNextPrint_) |
| 587 /** |
| 588 * @param {?string=} data Data for cloud print if this is a cloud |
| 589 * printer, otherwise undefined. |
| 590 */ |
| 591 .then( |
| 592 function(data) { |
| 593 if (!destination.isLocal) { |
| 594 assert(data); |
| 595 this.onPrintToCloud_(data); |
| 596 } else if (destination.isPrivet || destination.isExtension) { |
| 597 this.close_(); |
| 598 } else if ( |
| 599 destination.id == |
| 600 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 601 this.onFileSelectionComplete_(); |
| 602 } else { // local |
| 603 this.nativeLayer_.startHideDialog(); |
| 604 } |
| 605 }.bind(this), |
| 606 /** |
| 607 * @param {*} response The response indicating the type of error |
| 608 * for extension and privet printers, or undefined for PDF, |
| 609 * local, and cloud printers. |
| 610 */ |
| 611 function(response) { |
| 612 if (!destination.isLocal) { |
| 613 // Happens only if the ticket wasn't parsed. |
| 614 this.onSettingsInvalid_(); |
| 615 } else if (destination.isPrivet || destination.isExtension) { |
| 616 this.onPrintFailed_(response); |
| 617 } else if ( |
| 618 destination.id == |
| 619 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 620 this.onFileSelectionCancel_(); |
| 621 } else { // local |
| 622 this.nativeLayer_.startHideDialog(); |
| 623 } |
| 624 }.bind(this)); |
| 625 |
| 598 this.showSystemDialogBeforeNextPrint_ = false; | 626 this.showSystemDialogBeforeNextPrint_ = false; |
| 599 return print_preview.PrintAttemptResult_.PRINTED; | 627 return print_preview.PrintAttemptResult_.PRINTED; |
| 600 }, | 628 }, |
| 601 | 629 |
| 602 /** | 630 /** |
| 603 * Closes the print preview. | 631 * Closes the print preview. |
| 604 * @private | 632 * @private |
| 605 */ | 633 */ |
| 606 close_: function() { | 634 close_: function() { |
| 607 this.exitDocument(); | 635 this.exitDocument(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_); | 728 this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_); |
| 701 this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_); | 729 this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_); |
| 702 if (this.destinationSearch_.getIsVisible()) { | 730 if (this.destinationSearch_.getIsVisible()) { |
| 703 this.destinationStore_.startLoadCloudDestinations(); | 731 this.destinationStore_.startLoadCloudDestinations(); |
| 704 this.invitationStore_.startLoadingInvitations(); | 732 this.invitationStore_.startLoadingInvitations(); |
| 705 } | 733 } |
| 706 }, | 734 }, |
| 707 | 735 |
| 708 /** | 736 /** |
| 709 * Called from the native layer when ready to print to Google Cloud Print. | 737 * 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. | 738 * @param {string} data Contains the body to send in the HTTP request. |
| 711 * @private | 739 * @private |
| 712 */ | 740 */ |
| 713 onPrintToCloud_: function(event) { | 741 onPrintToCloud_: function(data) { |
| 714 assert( | 742 assert( |
| 715 this.uiState_ == PrintPreviewUiState_.PRINTING, | 743 this.uiState_ == PrintPreviewUiState_.PRINTING, |
| 716 'Document ready to be sent to the cloud when not in printing ' + | 744 'Document ready to be sent to the cloud when not in printing ' + |
| 717 'state: ' + this.uiState_); | 745 'state: ' + this.uiState_); |
| 718 assert( | 746 assert( |
| 719 this.cloudPrintInterface_ != null, | 747 this.cloudPrintInterface_ != null, |
| 720 'Google Cloud Print is not enabled'); | 748 'Google Cloud Print is not enabled'); |
| 721 assert(this.destinationStore_.selectedDestination != null); | 749 assert(this.destinationStore_.selectedDestination != null); |
| 722 this.cloudPrintInterface_.submit( | 750 this.cloudPrintInterface_.submit( |
| 723 this.destinationStore_.selectedDestination, this.printTicketStore_, | 751 this.destinationStore_.selectedDestination, this.printTicketStore_, |
| 724 this.documentInfo_, event.data); | 752 this.documentInfo_, data); |
| 725 }, | 753 }, |
| 726 | 754 |
| 727 /** | 755 /** |
| 728 * Called from the native layer when the user cancels the save-to-pdf file | 756 * Called from the native layer when the user cancels the save-to-pdf file |
| 729 * selection dialog. | 757 * selection dialog. |
| 730 * @private | 758 * @private |
| 731 */ | 759 */ |
| 732 onFileSelectionCancel_: function() { | 760 onFileSelectionCancel_: function() { |
| 733 assert( | 761 assert( |
| 734 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, | 762 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 * @private | 1048 * @private |
| 1021 */ | 1049 */ |
| 1022 onPageCountReady_: function(event) { | 1050 onPageCountReady_: function(event) { |
| 1023 if (event.fitToPageScaling >= 0) { | 1051 if (event.fitToPageScaling >= 0) { |
| 1024 this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); | 1052 this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); |
| 1025 } | 1053 } |
| 1026 }, | 1054 }, |
| 1027 | 1055 |
| 1028 /** | 1056 /** |
| 1029 * Called when printing to a privet or extension printer fails. | 1057 * Called when printing to a privet or extension printer fails. |
| 1030 * @param {number | string} httpError The HTTP error code, or -1 if not an | 1058 * @param {*} httpError The HTTP error code, or -1 or a string describing |
| 1031 * HTTP error. | 1059 * the error, if not an HTTP error. |
| 1032 * @private | 1060 * @private |
| 1033 */ | 1061 */ |
| 1034 onPrintFailed_: function(httpError) { | 1062 onPrintFailed_: function(httpError) { |
| 1035 console.error('Privet printing failed with error code ' + httpError); | 1063 console.error('Privet printing failed with error code ' + httpError); |
| 1036 this.printHeader_.setErrorMessage( | 1064 this.printHeader_.setErrorMessage( |
| 1037 loadTimeData.getString('couldNotPrint')); | 1065 loadTimeData.getString('couldNotPrint')); |
| 1038 }, | 1066 }, |
| 1039 | 1067 |
| 1040 /** | 1068 /** |
| 1041 * Called when the print preview settings need to be changed for testing. | 1069 * 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"> | 1373 // <include src="search/destination_search.js"> |
| 1346 // <include src="search/provisional_destination_resolver.js"> | 1374 // <include src="search/provisional_destination_resolver.js"> |
| 1347 | 1375 |
| 1348 window.addEventListener('DOMContentLoaded', function() { | 1376 window.addEventListener('DOMContentLoaded', function() { |
| 1349 var previewWindow = /** @type {{isTest: boolean}} */ (window); | 1377 var previewWindow = /** @type {{isTest: boolean}} */ (window); |
| 1350 if (!previewWindow.isTest) { | 1378 if (!previewWindow.isTest) { |
| 1351 var printPreview = new print_preview.PrintPreview(); | 1379 var printPreview = new print_preview.PrintPreview(); |
| 1352 printPreview.initialize(); | 1380 printPreview.initialize(); |
| 1353 } | 1381 } |
| 1354 }); | 1382 }); |
| OLD | NEW |