Chromium Code Reviews| 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 * A data store that stores destinations and dispatches events when the data | 9 * A data store that stores destinations and dispatches events when the data |
| 10 * store changes. | 10 * store changes. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 * @enum {string} | 192 * @enum {string} |
| 193 */ | 193 */ |
| 194 DestinationStore.EventType = { | 194 DestinationStore.EventType = { |
| 195 DESTINATION_SEARCH_DONE: | 195 DESTINATION_SEARCH_DONE: |
| 196 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', | 196 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', |
| 197 DESTINATION_SEARCH_STARTED: | 197 DESTINATION_SEARCH_STARTED: |
| 198 'print_preview.DestinationStore.DESTINATION_SEARCH_STARTED', | 198 'print_preview.DestinationStore.DESTINATION_SEARCH_STARTED', |
| 199 DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT', | 199 DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT', |
| 200 DESTINATIONS_INSERTED: | 200 DESTINATIONS_INSERTED: |
| 201 'print_preview.DestinationStore.DESTINATIONS_INSERTED', | 201 'print_preview.DestinationStore.DESTINATIONS_INSERTED', |
| 202 PROVISIONAL_DESTINATION_RESOLVED: | |
| 203 'print_preview.DestinationStore.PROVISIONAL_DESTINATION_RESOLVED', | |
| 202 CACHED_SELECTED_DESTINATION_INFO_READY: | 204 CACHED_SELECTED_DESTINATION_INFO_READY: |
| 203 'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY', | 205 'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY', |
| 204 SELECTED_DESTINATION_CAPABILITIES_READY: | 206 SELECTED_DESTINATION_CAPABILITIES_READY: |
| 205 'print_preview.DestinationStore.SELECTED_DESTINATION_CAPABILITIES_READY' | 207 'print_preview.DestinationStore.SELECTED_DESTINATION_CAPABILITIES_READY' |
| 206 }; | 208 }; |
| 207 | 209 |
| 208 /** | 210 /** |
| 209 * Delay in milliseconds before the destination store ignores the initial | 211 * Delay in milliseconds before the destination store ignores the initial |
| 210 * destination ID and just selects any printer (since the initial destination | 212 * destination ID and just selects any printer (since the initial destination |
| 211 * was not found). | 213 * was not found). |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 this.autoSelectTimeout_ = null; | 456 this.autoSelectTimeout_ = null; |
| 455 } else if (destination == this.selectedDestination_) { | 457 } else if (destination == this.selectedDestination_) { |
| 456 return; | 458 return; |
| 457 } | 459 } |
| 458 if (destination == null) { | 460 if (destination == null) { |
| 459 this.selectedDestination_ = null; | 461 this.selectedDestination_ = null; |
| 460 cr.dispatchSimpleEvent( | 462 cr.dispatchSimpleEvent( |
| 461 this, DestinationStore.EventType.DESTINATION_SELECT); | 463 this, DestinationStore.EventType.DESTINATION_SELECT); |
| 462 return; | 464 return; |
| 463 } | 465 } |
| 466 | |
| 467 assert(!destination.isProvisional, | |
| 468 'Unable to select provisonal destinations'); | |
| 469 | |
| 464 // Update and persist selected destination. | 470 // Update and persist selected destination. |
| 465 this.selectedDestination_ = destination; | 471 this.selectedDestination_ = destination; |
| 466 this.selectedDestination_.isRecent = true; | 472 this.selectedDestination_.isRecent = true; |
| 467 if (destination.id == print_preview.Destination.GooglePromotedId.FEDEX && | 473 if (destination.id == print_preview.Destination.GooglePromotedId.FEDEX && |
| 468 !destination.isTosAccepted) { | 474 !destination.isTosAccepted) { |
| 469 assert(this.cloudPrintInterface_ != null, | 475 assert(this.cloudPrintInterface_ != null, |
| 470 'Selected FedEx destination, but GCP API is not available'); | 476 'Selected FedEx destination, but GCP API is not available'); |
| 471 destination.isTosAccepted = true; | 477 destination.isTosAccepted = true; |
| 472 this.cloudPrintInterface_.updatePrinterTosAcceptance(destination, true); | 478 this.cloudPrintInterface_.updatePrinterTosAcceptance(destination, true); |
| 473 } | 479 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 destination.id, destination.origin, destination.account); | 511 destination.id, destination.origin, destination.account); |
| 506 } | 512 } |
| 507 } else { | 513 } else { |
| 508 cr.dispatchSimpleEvent( | 514 cr.dispatchSimpleEvent( |
| 509 this, | 515 this, |
| 510 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); | 516 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); |
| 511 } | 517 } |
| 512 }, | 518 }, |
| 513 | 519 |
| 514 /** | 520 /** |
| 521 * Attempts to resolve a provisional destination. | |
| 522 * @param {!print_preview.Destination} destinaion Provisional destination | |
| 523 * that should be resolved. | |
| 524 */ | |
| 525 resolveProvisionalDestination: function(destination) { | |
| 526 assert( | |
| 527 destination.provisionalType == | |
| 528 print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION, | |
| 529 'Provisional type cannot be resolved.'); | |
| 530 this.nativeLayer_.grantExtensionPrinterAccess(destination.id); | |
| 531 }, | |
| 532 | |
| 533 /** | |
| 515 * Selects 'Save to PDF' destination (since it always exists). | 534 * Selects 'Save to PDF' destination (since it always exists). |
| 516 * @private | 535 * @private |
| 517 */ | 536 */ |
| 518 selectDefaultDestination_: function() { | 537 selectDefaultDestination_: function() { |
| 519 var saveToPdfKey = this.getDestinationKey_( | 538 var saveToPdfKey = this.getDestinationKey_( |
| 520 print_preview.Destination.Origin.LOCAL, | 539 print_preview.Destination.Origin.LOCAL, |
| 521 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 540 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
| 522 ''); | 541 ''); |
| 523 this.selectDestination( | 542 this.selectDestination( |
| 524 this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null); | 543 this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 | 626 |
| 608 /** | 627 /** |
| 609 * Wait for a privet device to be registered. | 628 * Wait for a privet device to be registered. |
| 610 */ | 629 */ |
| 611 waitForRegister: function(id) { | 630 waitForRegister: function(id) { |
| 612 this.nativeLayer_.startGetPrivetDestinations(); | 631 this.nativeLayer_.startGetPrivetDestinations(); |
| 613 this.waitForRegisterDestination_ = id; | 632 this.waitForRegisterDestination_ = id; |
| 614 }, | 633 }, |
| 615 | 634 |
| 616 /** | 635 /** |
| 636 * Event handler for {@code | |
| 637 * print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED}. | |
| 638 * Currently assumes the provisional destination is an extension | |
| 639 * destination. | |
| 640 * Called when a provisional destination resolvement attempt finishes. | |
| 641 * The provisional destination is removed from the store and replaced with | |
| 642 * a destination created from the resolved destination properties, if any | |
| 643 * are reported. | |
| 644 * Emits {@code DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED} | |
| 645 * event. | |
| 646 * @param {!Event} The event containing the provisional destination ID and | |
| 647 * resolved destination description. If the destination was not | |
| 648 * successfully resolved, the description will not be set. | |
| 649 * @private | |
| 650 */ | |
| 651 handleProvisionalDestinationResolved_: function(evt) { | |
| 652 var provisionalDestinationIndex = -1; | |
| 653 var provisionalDestination = null; | |
| 654 for (var i = 0; i < this.destinations_.length; ++i) { | |
| 655 if (evt.provisionalId == this.destinations_[i].id) { | |
| 656 provisionalDestinationIndex = i; | |
| 657 provisionalDestination = this.destinations_[i]; | |
| 658 break; | |
| 659 } | |
| 660 } | |
| 661 | |
| 662 if (!provisionalDestination) | |
| 663 return; | |
| 664 | |
| 665 this.destinations_.splice(provisionalDestinationIndex, 1); | |
| 666 this.destinationMap_[this.getKey_(provisionalDestination)] = undefined; | |
|
Aleksey Shlyapnikov
2015/06/08 23:00:54
delete this.destinationMap_[this.getKey_(provision
tbarzic
2015/06/09 18:21:59
Done.
| |
| 667 | |
| 668 var destination = evt.destination ? | |
| 669 print_preview.ExtensionDestinationParser.parse(evt.destination) : | |
| 670 null; | |
| 671 | |
| 672 if (destination) | |
| 673 this.insertIntoStore_(destination); | |
| 674 | |
| 675 var event = new Event( | |
| 676 DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED); | |
| 677 event.provisionalId = evt.provisionalId; | |
| 678 event.destination = destination; | |
| 679 this.dispatchEvent(event); | |
| 680 }, | |
| 681 | |
| 682 /** | |
| 617 * Inserts {@code destination} to the data store and dispatches a | 683 * Inserts {@code destination} to the data store and dispatches a |
| 618 * DESTINATIONS_INSERTED event. | 684 * DESTINATIONS_INSERTED event. |
| 619 * @param {!print_preview.Destination} destination Print destination to | 685 * @param {!print_preview.Destination} destination Print destination to |
| 620 * insert. | 686 * insert. |
| 621 * @private | 687 * @private |
| 622 */ | 688 */ |
| 623 insertDestination_: function(destination) { | 689 insertDestination_: function(destination) { |
| 624 if (this.insertIntoStore_(destination)) { | 690 if (this.insertIntoStore_(destination)) { |
| 625 this.destinationsInserted_(destination); | 691 this.destinationsInserted_(destination); |
| 626 } | 692 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, | 841 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, |
| 776 this.onPrivetCapabilitiesSet_.bind(this)); | 842 this.onPrivetCapabilitiesSet_.bind(this)); |
| 777 this.tracker_.add( | 843 this.tracker_.add( |
| 778 this.nativeLayer_, | 844 this.nativeLayer_, |
| 779 print_preview.NativeLayer.EventType.EXTENSION_PRINTERS_ADDED, | 845 print_preview.NativeLayer.EventType.EXTENSION_PRINTERS_ADDED, |
| 780 this.onExtensionPrintersAdded_.bind(this)); | 846 this.onExtensionPrintersAdded_.bind(this)); |
| 781 this.tracker_.add( | 847 this.tracker_.add( |
| 782 this.nativeLayer_, | 848 this.nativeLayer_, |
| 783 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, | 849 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, |
| 784 this.onExtensionCapabilitiesSet_.bind(this)); | 850 this.onExtensionCapabilitiesSet_.bind(this)); |
| 851 this.tracker_.add( | |
| 852 this.nativeLayer_, | |
| 853 print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED, | |
| 854 this.handleProvisionalDestinationResolved_.bind(this)); | |
| 785 }, | 855 }, |
| 786 | 856 |
| 787 /** | 857 /** |
| 788 * Creates a local PDF print destination. | 858 * Creates a local PDF print destination. |
| 789 * @return {!print_preview.Destination} Created print destination. | 859 * @return {!print_preview.Destination} Created print destination. |
| 790 * @private | 860 * @private |
| 791 */ | 861 */ |
| 792 createLocalPdfPrintDestination_: function() { | 862 createLocalPdfPrintDestination_: function() { |
| 793 // TODO(alekseys): Create PDF printer in the native code and send its | 863 // TODO(alekseys): Create PDF printer in the native code and send its |
| 794 // capabilities back with other local printers. | 864 // capabilities back with other local printers. |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 return id == this.appState_.selectedDestinationId && | 1163 return id == this.appState_.selectedDestinationId && |
| 1094 origin == this.appState_.selectedDestinationOrigin; | 1164 origin == this.appState_.selectedDestinationOrigin; |
| 1095 } | 1165 } |
| 1096 }; | 1166 }; |
| 1097 | 1167 |
| 1098 // Export | 1168 // Export |
| 1099 return { | 1169 return { |
| 1100 DestinationStore: DestinationStore | 1170 DestinationStore: DestinationStore |
| 1101 }; | 1171 }; |
| 1102 }); | 1172 }); |
| OLD | NEW |