| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 /** | 148 /** |
| 149 * ID of a timeout after the start of a privet search to end that privet | 149 * ID of a timeout after the start of a privet search to end that privet |
| 150 * search. | 150 * search. |
| 151 * @type {?number} | 151 * @type {?number} |
| 152 * @private | 152 * @private |
| 153 */ | 153 */ |
| 154 this.privetSearchTimeout_ = null; | 154 this.privetSearchTimeout_ = null; |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * Whether a search for extension destinations is in progress. |
| 158 * @type {boolean} |
| 159 * @private |
| 160 */ |
| 161 this.isExtensionDestinationSearchInProgress_ = false; |
| 162 |
| 163 /** |
| 164 * Whether the destination store has already loaded all extension |
| 165 * destinations. |
| 166 * @type {boolean} |
| 167 * @private |
| 168 */ |
| 169 this.hasLoadedAllExtensionDestinations_ = false; |
| 170 |
| 171 /** |
| 172 * ID of a timeout set at the start of an extension destination search. The |
| 173 * timeout ends the search. |
| 174 * @type {?number} |
| 175 * @private |
| 176 */ |
| 177 this.extensionSearchTimeout_ = null; |
| 178 |
| 179 /** |
| 157 * MDNS service name of destination that we are waiting to register. | 180 * MDNS service name of destination that we are waiting to register. |
| 158 * @type {?string} | 181 * @type {?string} |
| 159 * @private | 182 * @private |
| 160 */ | 183 */ |
| 161 this.waitForRegisterDestination_ = null; | 184 this.waitForRegisterDestination_ = null; |
| 162 | 185 |
| 163 this.addEventListeners_(); | 186 this.addEventListeners_(); |
| 164 this.reset_(); | 187 this.reset_(); |
| 165 }; | 188 }; |
| 166 | 189 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 194 | 217 |
| 195 /** | 218 /** |
| 196 * Amount of time spent searching for privet destination, in milliseconds. | 219 * Amount of time spent searching for privet destination, in milliseconds. |
| 197 * @type {number} | 220 * @type {number} |
| 198 * @const | 221 * @const |
| 199 * @private | 222 * @private |
| 200 */ | 223 */ |
| 201 DestinationStore.PRIVET_SEARCH_DURATION_ = 2000; | 224 DestinationStore.PRIVET_SEARCH_DURATION_ = 2000; |
| 202 | 225 |
| 203 /** | 226 /** |
| 227 * Maximum amount of time spent searching for extension destinations, in |
| 228 * milliseconds. |
| 229 * @type {number} |
| 230 * @const |
| 231 * @private |
| 232 */ |
| 233 DestinationStore.EXTENSION_SEARCH_DURATION_ = 2000; |
| 234 |
| 235 /** |
| 204 * Localizes printer capabilities. | 236 * Localizes printer capabilities. |
| 205 * @param {!Object} capabilities Printer capabilities to localize. | 237 * @param {!Object} capabilities Printer capabilities to localize. |
| 206 * @return {!Object} Localized capabilities. | 238 * @return {!Object} Localized capabilities. |
| 207 * @private | 239 * @private |
| 208 */ | 240 */ |
| 209 DestinationStore.localizeCapabilities_ = function(capabilities) { | 241 DestinationStore.localizeCapabilities_ = function(capabilities) { |
| 210 var mediaSize = capabilities.printer.media_size; | 242 var mediaSize = capabilities.printer.media_size; |
| 211 if (mediaSize) { | 243 if (mediaSize) { |
| 212 var mediaDisplayNames = { | 244 var mediaDisplayNames = { |
| 213 'ISO_A4': 'A4', | 245 'ISO_A4': 'A4', |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 get isAutoSelectDestinationInProgress() { | 292 get isAutoSelectDestinationInProgress() { |
| 261 return this.selectedDestination_ == null && | 293 return this.selectedDestination_ == null && |
| 262 this.autoSelectTimeout_ != null; | 294 this.autoSelectTimeout_ != null; |
| 263 }, | 295 }, |
| 264 | 296 |
| 265 /** | 297 /** |
| 266 * @return {boolean} Whether a search for local destinations is in progress. | 298 * @return {boolean} Whether a search for local destinations is in progress. |
| 267 */ | 299 */ |
| 268 get isLocalDestinationSearchInProgress() { | 300 get isLocalDestinationSearchInProgress() { |
| 269 return this.isLocalDestinationSearchInProgress_ || | 301 return this.isLocalDestinationSearchInProgress_ || |
| 270 this.isPrivetDestinationSearchInProgress_; | 302 this.isPrivetDestinationSearchInProgress_ || |
| 303 this.isExtensionDestinationSearchInProgress_; |
| 271 }, | 304 }, |
| 272 | 305 |
| 273 /** | 306 /** |
| 274 * @return {boolean} Whether a search for cloud destinations is in progress. | 307 * @return {boolean} Whether a search for cloud destinations is in progress. |
| 275 */ | 308 */ |
| 276 get isCloudDestinationSearchInProgress() { | 309 get isCloudDestinationSearchInProgress() { |
| 277 return !!this.cloudPrintInterface_ && | 310 return !!this.cloudPrintInterface_ && |
| 278 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; | 311 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; |
| 279 }, | 312 }, |
| 280 | 313 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 print_preview.Destination.Origin.PRIVET, | 365 print_preview.Destination.Origin.PRIVET, |
| 333 destinationName, | 366 destinationName, |
| 334 false /*isRecent*/, | 367 false /*isRecent*/, |
| 335 print_preview.Destination.ConnectionStatus.ONLINE); | 368 print_preview.Destination.ConnectionStatus.ONLINE); |
| 336 this.selectedDestination_.capabilities = | 369 this.selectedDestination_.capabilities = |
| 337 this.appState_.selectedDestinationCapabilities; | 370 this.appState_.selectedDestinationCapabilities; |
| 338 | 371 |
| 339 cr.dispatchSimpleEvent( | 372 cr.dispatchSimpleEvent( |
| 340 this, | 373 this, |
| 341 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY); | 374 DestinationStore.EventType.CACHED_SELECTED_DESTINATION_INFO_READY); |
| 375 } else if (this.appState_.selectedDestinationOrigin == |
| 376 print_preview.Destination.Origin.EXTENSION) { |
| 377 // TODO(tbarzic): Add support for requesting a single extension's |
| 378 // printer list. |
| 379 this.startLoadExtensionDestinations(); |
| 380 |
| 381 var parsedDestinationID = |
| 382 print_preview.ExtensionDestinationParser.parseDestinationID( |
| 383 this.appState_.selectedDestinationId); |
| 384 this.selectedDestination_ = |
| 385 print_preview.ExtensionDestinationParser.parse({ |
| 386 extensionId: parsedDestinationID.extensionID, |
| 387 id: parsedDestinationID.printerID, |
| 388 name: this.appState_.selectedDestinationName_ || '' |
| 389 }); |
| 390 |
| 391 if (this.appState_.selectedDestinationCapabilities) { |
| 392 this.selectedDestination_.capabilities = |
| 393 this.appState_.selectedDestinationCapabilities; |
| 394 |
| 395 cr.dispatchSimpleEvent( |
| 396 this, |
| 397 DestinationStore.EventType |
| 398 .CACHED_SELECTED_DESTINATION_INFO_READY); |
| 399 } |
| 342 } else { | 400 } else { |
| 343 this.selectDefaultDestination_(); | 401 this.selectDefaultDestination_(); |
| 344 } | 402 } |
| 345 } | 403 } |
| 346 }, | 404 }, |
| 347 | 405 |
| 348 /** | 406 /** |
| 349 * Sets the destination store's Google Cloud Print interface. | 407 * Sets the destination store's Google Cloud Print interface. |
| 350 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface | 408 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface |
| 351 * to set. | 409 * to set. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 CLOUD_DUPLICATE_SELECTED); | 488 CLOUD_DUPLICATE_SELECTED); |
| 431 } | 489 } |
| 432 // Notify about selected destination change. | 490 // Notify about selected destination change. |
| 433 cr.dispatchSimpleEvent( | 491 cr.dispatchSimpleEvent( |
| 434 this, DestinationStore.EventType.DESTINATION_SELECT); | 492 this, DestinationStore.EventType.DESTINATION_SELECT); |
| 435 // Request destination capabilities, of not known yet. | 493 // Request destination capabilities, of not known yet. |
| 436 if (destination.capabilities == null) { | 494 if (destination.capabilities == null) { |
| 437 if (destination.isPrivet) { | 495 if (destination.isPrivet) { |
| 438 this.nativeLayer_.startGetPrivetDestinationCapabilities( | 496 this.nativeLayer_.startGetPrivetDestinationCapabilities( |
| 439 destination.id); | 497 destination.id); |
| 440 } | 498 } else if (destination.isExtension) { |
| 441 else if (destination.isLocal) { | 499 var parsedDestinationID = |
| 500 print_preview.ExtensionDestinationParser.parseDestinationID( |
| 501 destination.id); |
| 502 this.nativeLayer_.startGetExtensionDestinationCapabilities( |
| 503 parsedDestinationID.extensionID, |
| 504 parsedDestinationID.printerID); |
| 505 } else if (destination.isLocal) { |
| 442 this.nativeLayer_.startGetLocalDestinationCapabilities( | 506 this.nativeLayer_.startGetLocalDestinationCapabilities( |
| 443 destination.id); | 507 destination.id); |
| 444 } else { | 508 } else { |
| 445 assert(this.cloudPrintInterface_ != null, | 509 assert(this.cloudPrintInterface_ != null, |
| 446 'Cloud destination selected, but GCP is not enabled'); | 510 'Cloud destination selected, but GCP is not enabled'); |
| 447 this.cloudPrintInterface_.printer( | 511 this.cloudPrintInterface_.printer( |
| 448 destination.id, destination.origin, destination.account); | 512 destination.id, destination.origin, destination.account); |
| 449 } | 513 } |
| 450 } else { | 514 } else { |
| 451 cr.dispatchSimpleEvent( | 515 cr.dispatchSimpleEvent( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 474 this.nativeLayer_.startGetLocalDestinations(); | 538 this.nativeLayer_.startGetLocalDestinations(); |
| 475 this.isLocalDestinationSearchInProgress_ = true; | 539 this.isLocalDestinationSearchInProgress_ = true; |
| 476 cr.dispatchSimpleEvent( | 540 cr.dispatchSimpleEvent( |
| 477 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); | 541 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
| 478 } | 542 } |
| 479 }, | 543 }, |
| 480 | 544 |
| 481 /** Initiates loading of privet print destinations. */ | 545 /** Initiates loading of privet print destinations. */ |
| 482 startLoadPrivetDestinations: function() { | 546 startLoadPrivetDestinations: function() { |
| 483 if (!this.hasLoadedAllPrivetDestinations_) { | 547 if (!this.hasLoadedAllPrivetDestinations_) { |
| 548 if (this.privetDestinationSearchInProgress_) |
| 549 clearTimeout(this.privetSearchTimeout_); |
| 484 this.isPrivetDestinationSearchInProgress_ = true; | 550 this.isPrivetDestinationSearchInProgress_ = true; |
| 485 this.nativeLayer_.startGetPrivetDestinations(); | 551 this.nativeLayer_.startGetPrivetDestinations(); |
| 486 cr.dispatchSimpleEvent( | 552 cr.dispatchSimpleEvent( |
| 487 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); | 553 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
| 488 if (this.privetDestinationSearchInProgress_) | |
| 489 clearTimeout(this.privetSearchTimeout_); | |
| 490 this.privetSearchTimeout_ = setTimeout( | 554 this.privetSearchTimeout_ = setTimeout( |
| 491 this.endPrivetPrinterSearch_.bind(this), | 555 this.endPrivetPrinterSearch_.bind(this), |
| 492 DestinationStore.PRIVET_SEARCH_DURATION_); | 556 DestinationStore.PRIVET_SEARCH_DURATION_); |
| 493 } | 557 } |
| 494 }, | 558 }, |
| 495 | 559 |
| 560 /** Initializes loading of extension managed print destinations. */ |
| 561 startLoadExtensionDestinations: function() { |
| 562 if (this.hasLoadedAllExtensionDestinations_) |
| 563 return; |
| 564 |
| 565 if (this.isExtensionDestinationSearchInProgress_) |
| 566 clearTimeout(this.extensionSearchTimeout_); |
| 567 |
| 568 this.isExtensionDestinationSearchInProgress_ = true; |
| 569 this.nativeLayer_.startGetExtensionDestinations(); |
| 570 cr.dispatchSimpleEvent( |
| 571 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
| 572 this.extensionSearchTimeout_ = setTimeout( |
| 573 this.endExtensionPrinterSearch_.bind(this), |
| 574 DestinationStore.EXTENSION_SEARCH_DURATION_); |
| 575 }, |
| 576 |
| 496 /** | 577 /** |
| 497 * Initiates loading of cloud destinations. | 578 * Initiates loading of cloud destinations. |
| 498 * @param {print_preview.Destination.Origin=} opt_origin Search destinations | 579 * @param {print_preview.Destination.Origin=} opt_origin Search destinations |
| 499 * for the specified origin only. | 580 * for the specified origin only. |
| 500 */ | 581 */ |
| 501 startLoadCloudDestinations: function(opt_origin) { | 582 startLoadCloudDestinations: function(opt_origin) { |
| 502 if (this.cloudPrintInterface_ != null) { | 583 if (this.cloudPrintInterface_ != null) { |
| 503 var origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || []; | 584 var origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || []; |
| 504 if (origins.length == 0 || | 585 if (origins.length == 0 || |
| 505 (opt_origin && origins.indexOf(opt_origin) < 0)) { | 586 (opt_origin && origins.indexOf(opt_origin) < 0)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 521 this.startLoadCloudDestinations( | 602 this.startLoadCloudDestinations( |
| 522 print_preview.Destination.Origin.COOKIES); | 603 print_preview.Destination.Origin.COOKIES); |
| 523 } | 604 } |
| 524 }, | 605 }, |
| 525 | 606 |
| 526 /** Initiates loading of all known destination types. */ | 607 /** Initiates loading of all known destination types. */ |
| 527 startLoadAllDestinations: function() { | 608 startLoadAllDestinations: function() { |
| 528 this.startLoadCloudDestinations(); | 609 this.startLoadCloudDestinations(); |
| 529 this.startLoadLocalDestinations(); | 610 this.startLoadLocalDestinations(); |
| 530 this.startLoadPrivetDestinations(); | 611 this.startLoadPrivetDestinations(); |
| 612 this.startLoadExtensionDestinations(); |
| 531 }, | 613 }, |
| 532 | 614 |
| 533 /** | 615 /** |
| 534 * Wait for a privet device to be registered. | 616 * Wait for a privet device to be registered. |
| 535 */ | 617 */ |
| 536 waitForRegister: function(id) { | 618 waitForRegister: function(id) { |
| 537 this.nativeLayer_.startGetPrivetDestinations(); | 619 this.nativeLayer_.startGetPrivetDestinations(); |
| 538 this.waitForRegisterDestination_ = id; | 620 this.waitForRegisterDestination_ = id; |
| 539 }, | 621 }, |
| 540 | 622 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 */ | 707 */ |
| 626 endPrivetPrinterSearch_: function() { | 708 endPrivetPrinterSearch_: function() { |
| 627 this.nativeLayer_.stopGetPrivetDestinations(); | 709 this.nativeLayer_.stopGetPrivetDestinations(); |
| 628 this.isPrivetDestinationSearchInProgress_ = false; | 710 this.isPrivetDestinationSearchInProgress_ = false; |
| 629 this.hasLoadedAllPrivetDestinations_ = true; | 711 this.hasLoadedAllPrivetDestinations_ = true; |
| 630 cr.dispatchSimpleEvent( | 712 cr.dispatchSimpleEvent( |
| 631 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); | 713 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); |
| 632 }, | 714 }, |
| 633 | 715 |
| 634 /** | 716 /** |
| 717 * Called when loading of extension managed printers is done. |
| 718 * @private |
| 719 */ |
| 720 endExtensionPrinterSearch_: function() { |
| 721 this.isExtensionDestinationSearchInProgress_ = false; |
| 722 this.hasLoadedAllExtensionDestinations_ = true; |
| 723 cr.dispatchSimpleEvent( |
| 724 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); |
| 725 // Clear initially selected (cached) extension destination if it hasn't |
| 726 // been found among reported extension destinations. |
| 727 if (this.isInAutoSelectMode_ && this.selectedDestination_.isExtension) |
| 728 this.selectDefaultDestination_(); |
| 729 }, |
| 730 |
| 731 /** |
| 635 * Inserts a destination into the store without dispatching any events. | 732 * Inserts a destination into the store without dispatching any events. |
| 636 * @return {boolean} Whether the inserted destination was not already in the | 733 * @return {boolean} Whether the inserted destination was not already in the |
| 637 * store. | 734 * store. |
| 638 * @private | 735 * @private |
| 639 */ | 736 */ |
| 640 insertIntoStore_: function(destination) { | 737 insertIntoStore_: function(destination) { |
| 641 var key = this.getKey_(destination); | 738 var key = this.getKey_(destination); |
| 642 var existingDestination = this.destinationMap_[key]; | 739 var existingDestination = this.destinationMap_[key]; |
| 643 if (existingDestination == null) { | 740 if (existingDestination == null) { |
| 644 this.destinations_.push(destination); | 741 this.destinations_.push(destination); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD, | 774 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD, |
| 678 this.onDestinationsReload_.bind(this)); | 775 this.onDestinationsReload_.bind(this)); |
| 679 this.tracker_.add( | 776 this.tracker_.add( |
| 680 this.nativeLayer_, | 777 this.nativeLayer_, |
| 681 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, | 778 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, |
| 682 this.onPrivetPrinterAdded_.bind(this)); | 779 this.onPrivetPrinterAdded_.bind(this)); |
| 683 this.tracker_.add( | 780 this.tracker_.add( |
| 684 this.nativeLayer_, | 781 this.nativeLayer_, |
| 685 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, | 782 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, |
| 686 this.onPrivetCapabilitiesSet_.bind(this)); | 783 this.onPrivetCapabilitiesSet_.bind(this)); |
| 784 this.tracker_.add( |
| 785 this.nativeLayer_, |
| 786 print_preview.NativeLayer.EventType.EXTENSION_PRINTERS_ADDED, |
| 787 this.onExtensionPrintersAdded_.bind(this)); |
| 788 this.tracker_.add( |
| 789 this.nativeLayer_, |
| 790 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, |
| 791 this.onExtensionCapabilitiesSet_.bind(this)); |
| 687 }, | 792 }, |
| 688 | 793 |
| 689 /** | 794 /** |
| 690 * Creates a local PDF print destination. | 795 * Creates a local PDF print destination. |
| 691 * @return {!print_preview.Destination} Created print destination. | 796 * @return {!print_preview.Destination} Created print destination. |
| 692 * @private | 797 * @private |
| 693 */ | 798 */ |
| 694 createLocalPdfPrintDestination_: function() { | 799 createLocalPdfPrintDestination_: function() { |
| 695 // TODO(alekseys): Create PDF printer in the native code and send its | 800 // TODO(alekseys): Create PDF printer in the native code and send its |
| 696 // capabilities back with other local printers. | 801 // capabilities back with other local printers. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 709 * Resets the state of the destination store to its initial state. | 814 * Resets the state of the destination store to its initial state. |
| 710 * @private | 815 * @private |
| 711 */ | 816 */ |
| 712 reset_: function() { | 817 reset_: function() { |
| 713 this.destinations_ = []; | 818 this.destinations_ = []; |
| 714 this.destinationMap_ = {}; | 819 this.destinationMap_ = {}; |
| 715 this.selectDestination(null); | 820 this.selectDestination(null); |
| 716 this.loadedCloudOrigins_ = {}; | 821 this.loadedCloudOrigins_ = {}; |
| 717 this.hasLoadedAllLocalDestinations_ = false; | 822 this.hasLoadedAllLocalDestinations_ = false; |
| 718 this.hasLoadedAllPrivetDestinations_ = false; | 823 this.hasLoadedAllPrivetDestinations_ = false; |
| 824 this.hasLoadedAllExtensionDestinations_ = false; |
| 719 | 825 |
| 720 clearTimeout(this.autoSelectTimeout_); | 826 clearTimeout(this.autoSelectTimeout_); |
| 721 this.autoSelectTimeout_ = setTimeout( | 827 this.autoSelectTimeout_ = setTimeout( |
| 722 this.selectDefaultDestination_.bind(this), | 828 this.selectDefaultDestination_.bind(this), |
| 723 DestinationStore.AUTO_SELECT_TIMEOUT_); | 829 DestinationStore.AUTO_SELECT_TIMEOUT_); |
| 724 }, | 830 }, |
| 725 | 831 |
| 726 /** | 832 /** |
| 727 * Called when the local destinations have been got from the native layer. | 833 * Called when the local destinations have been got from the native layer. |
| 728 * @param {Event} event Contains the local destinations. | 834 * @param {Event} event Contains the local destinations. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 print_preview.PrivetDestinationParser.parse(event.printer)); | 990 print_preview.PrivetDestinationParser.parse(event.printer)); |
| 885 } | 991 } |
| 886 }, | 992 }, |
| 887 | 993 |
| 888 /** | 994 /** |
| 889 * Called when capabilities for a privet printer are set. | 995 * Called when capabilities for a privet printer are set. |
| 890 * @param {Object} event Contains the capabilities and printer ID. | 996 * @param {Object} event Contains the capabilities and printer ID. |
| 891 * @private | 997 * @private |
| 892 */ | 998 */ |
| 893 onPrivetCapabilitiesSet_: function(event) { | 999 onPrivetCapabilitiesSet_: function(event) { |
| 894 var destinationId = event.printerId; | |
| 895 var destinations = | 1000 var destinations = |
| 896 print_preview.PrivetDestinationParser.parse(event.printer); | 1001 print_preview.PrivetDestinationParser.parse(event.printer); |
| 897 destinations.forEach(function(dest) { | 1002 destinations.forEach(function(dest) { |
| 898 dest.capabilities = event.capabilities; | 1003 dest.capabilities = event.capabilities; |
| 899 this.updateDestination_(dest); | 1004 this.updateDestination_(dest); |
| 900 }, this); | 1005 }, this); |
| 901 }, | 1006 }, |
| 902 | 1007 |
| 903 /** | 1008 /** |
| 1009 * Called when an extension responds to a getExtensionDestinations |
| 1010 * request. |
| 1011 * @param {Object} event Contains information about list of printers |
| 1012 * reported by the extension. |
| 1013 * {@code done} parameter is set iff this is the final list of printers |
| 1014 * returned as part of getExtensionDestinations request. |
| 1015 * @private |
| 1016 */ |
| 1017 onExtensionPrintersAdded_: function(event) { |
| 1018 this.insertDestinations_(event.printers.map(function(printer) { |
| 1019 return print_preview.ExtensionDestinationParser.parse(printer); |
| 1020 })); |
| 1021 |
| 1022 if (event.done && this.isExtensionDestinationSearchInProgress_) { |
| 1023 clearTimeout(this.extensionSearchTimeout_); |
| 1024 this.endExtensionPrinterSearch_(); |
| 1025 } |
| 1026 }, |
| 1027 |
| 1028 /** |
| 1029 * Called when capabilities for an extension managed printer are set. |
| 1030 * @param {Object} event Contains the printer capabilities and ID, and the |
| 1031 * ID of extension that manages the printer. |
| 1032 * @private |
| 1033 */ |
| 1034 onExtensionCapabilitiesSet_: function(event) { |
| 1035 var destinationID = |
| 1036 print_preview.ExtensionDestinationParser.generateDestinationID( |
| 1037 event.extensionID, event.printerID); |
| 1038 var destinationKey = this.getDestinationKey_( |
| 1039 print_preview.Destination.Origin.EXTENSION, |
| 1040 destinationID, |
| 1041 '' /* account */); |
| 1042 var destination = this.destinationMap_[destinationKey]; |
| 1043 if (!destination) |
| 1044 return; |
| 1045 destination.capabilities = event.capabilities; |
| 1046 this.updateDestination_(destination); |
| 1047 }, |
| 1048 |
| 1049 /** |
| 904 * Called from native layer after the user was requested to sign in, and did | 1050 * Called from native layer after the user was requested to sign in, and did |
| 905 * so successfully. | 1051 * so successfully. |
| 906 * @private | 1052 * @private |
| 907 */ | 1053 */ |
| 908 onDestinationsReload_: function() { | 1054 onDestinationsReload_: function() { |
| 909 this.reset_(); | 1055 this.reset_(); |
| 910 this.isInAutoSelectMode_ = true; | 1056 this.isInAutoSelectMode_ = true; |
| 911 this.createLocalPdfPrintDestination_(); | 1057 this.createLocalPdfPrintDestination_(); |
| 912 this.startLoadAllDestinations(); | 1058 this.startLoadAllDestinations(); |
| 913 }, | 1059 }, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 return id == this.appState_.selectedDestinationId && | 1104 return id == this.appState_.selectedDestinationId && |
| 959 origin == this.appState_.selectedDestinationOrigin; | 1105 origin == this.appState_.selectedDestinationOrigin; |
| 960 } | 1106 } |
| 961 }; | 1107 }; |
| 962 | 1108 |
| 963 // Export | 1109 // Export |
| 964 return { | 1110 return { |
| 965 DestinationStore: DestinationStore | 1111 DestinationStore: DestinationStore |
| 966 }; | 1112 }; |
| 967 }); | 1113 }); |
| OLD | NEW |