| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', | 182 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', |
| 183 DESTINATION_SEARCH_STARTED: | 183 DESTINATION_SEARCH_STARTED: |
| 184 'print_preview.DestinationStore.DESTINATION_SEARCH_STARTED', | 184 'print_preview.DestinationStore.DESTINATION_SEARCH_STARTED', |
| 185 DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT', | 185 DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT', |
| 186 DESTINATIONS_INSERTED: | 186 DESTINATIONS_INSERTED: |
| 187 'print_preview.DestinationStore.DESTINATIONS_INSERTED', | 187 'print_preview.DestinationStore.DESTINATIONS_INSERTED', |
| 188 PROVISIONAL_DESTINATION_RESOLVED: | 188 PROVISIONAL_DESTINATION_RESOLVED: |
| 189 'print_preview.DestinationStore.PROVISIONAL_DESTINATION_RESOLVED', | 189 'print_preview.DestinationStore.PROVISIONAL_DESTINATION_RESOLVED', |
| 190 CACHED_SELECTED_DESTINATION_INFO_READY: | 190 CACHED_SELECTED_DESTINATION_INFO_READY: |
| 191 'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY', | 191 'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY', |
| 192 SELECTED_DESTINATION_CAPABILITIES_READY: | 192 SELECTED_DESTINATION_CAPABILITIES_READY: 'print_preview.DestinationStore' + |
| 193 'print_preview.DestinationStore' + | |
| 194 '.SELECTED_DESTINATION_CAPABILITIES_READY', | 193 '.SELECTED_DESTINATION_CAPABILITIES_READY', |
| 195 }; | 194 }; |
| 196 | 195 |
| 197 /** | 196 /** |
| 198 * Delay in milliseconds before the destination store ignores the initial | 197 * Delay in milliseconds before the destination store ignores the initial |
| 199 * destination ID and just selects any printer (since the initial destination | 198 * destination ID and just selects any printer (since the initial destination |
| 200 * was not found). | 199 * was not found). |
| 201 * @private {number} | 200 * @private {number} |
| 202 * @const | 201 * @const |
| 203 */ | 202 */ |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (!capabilities.printer) | 394 if (!capabilities.printer) |
| 396 return capabilities; | 395 return capabilities; |
| 397 | 396 |
| 398 var mediaSize = capabilities.printer.media_size; | 397 var mediaSize = capabilities.printer.media_size; |
| 399 if (!mediaSize) | 398 if (!mediaSize) |
| 400 return capabilities; | 399 return capabilities; |
| 401 | 400 |
| 402 for (var i = 0, media; (media = mediaSize.option[i]); i++) { | 401 for (var i = 0, media; (media = mediaSize.option[i]); i++) { |
| 403 // No need to patch capabilities with localized names provided. | 402 // No need to patch capabilities with localized names provided. |
| 404 if (!media.custom_display_name_localized) { | 403 if (!media.custom_display_name_localized) { |
| 405 media.custom_display_name = | 404 media.custom_display_name = media.custom_display_name || |
| 406 media.custom_display_name || | 405 DestinationStore.MEDIA_DISPLAY_NAMES_[media.name] || media.name; |
| 407 DestinationStore.MEDIA_DISPLAY_NAMES_[media.name] || | |
| 408 media.name; | |
| 409 } | 406 } |
| 410 } | 407 } |
| 411 return capabilities; | 408 return capabilities; |
| 412 }; | 409 }; |
| 413 | 410 |
| 414 /** | 411 /** |
| 415 * Compare two media sizes by their names. | 412 * Compare two media sizes by their names. |
| 416 * @param {!Object} a Media to compare. | 413 * @param {!Object} a Media to compare. |
| 417 * @param {!Object} b Media to compare. | 414 * @param {!Object} b Media to compare. |
| 418 * @return {number} 1 if a > b, -1 if a < b, or 0 if a == b. | 415 * @return {number} 1 if a > b, -1 if a < b, or 0 if a == b. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 var categoryStandardCN = []; | 447 var categoryStandardCN = []; |
| 451 var categoryStandardISO = []; | 448 var categoryStandardISO = []; |
| 452 var categoryStandardJP = []; | 449 var categoryStandardJP = []; |
| 453 var categoryStandardMisc = []; | 450 var categoryStandardMisc = []; |
| 454 var categoryCustom = []; | 451 var categoryCustom = []; |
| 455 for (var i = 0, media; (media = mediaSize.option[i]); i++) { | 452 for (var i = 0, media; (media = mediaSize.option[i]); i++) { |
| 456 var name = media.name || 'CUSTOM'; | 453 var name = media.name || 'CUSTOM'; |
| 457 var category; | 454 var category; |
| 458 if (name.startsWith('NA_')) { | 455 if (name.startsWith('NA_')) { |
| 459 category = categoryStandardNA; | 456 category = categoryStandardNA; |
| 460 } else if (name.startsWith('PRC_') || name.startsWith('ROC_') || | 457 } else if ( |
| 461 name == 'OM_DAI_PA_KAI' || name == 'OM_JUURO_KU_KAI' || | 458 name.startsWith('PRC_') || name.startsWith('ROC_') || |
| 462 name == 'OM_PA_KAI') { | 459 name == 'OM_DAI_PA_KAI' || name == 'OM_JUURO_KU_KAI' || |
| 460 name == 'OM_PA_KAI') { |
| 463 category = categoryStandardCN; | 461 category = categoryStandardCN; |
| 464 } else if (name.startsWith('ISO_')) { | 462 } else if (name.startsWith('ISO_')) { |
| 465 category = categoryStandardISO; | 463 category = categoryStandardISO; |
| 466 } else if (name.startsWith('JIS_') || name.startsWith('JPN_')) { | 464 } else if (name.startsWith('JIS_') || name.startsWith('JPN_')) { |
| 467 category = categoryStandardJP; | 465 category = categoryStandardJP; |
| 468 } else if (name.startsWith('OM_')) { | 466 } else if (name.startsWith('OM_')) { |
| 469 category = categoryStandardMisc; | 467 category = categoryStandardMisc; |
| 470 } else { | 468 } else { |
| 471 assert(name == 'CUSTOM', 'Unknown media size. Assuming custom'); | 469 assert(name == 'CUSTOM', 'Unknown media size. Assuming custom'); |
| 472 category = categoryCustom; | 470 category = categoryCustom; |
| 473 } | 471 } |
| 474 category.push(media); | 472 category.push(media); |
| 475 } | 473 } |
| 476 | 474 |
| 477 // For each category, sort by name. | 475 // For each category, sort by name. |
| 478 categoryStandardNA.sort(DestinationStore.compareMediaNames_); | 476 categoryStandardNA.sort(DestinationStore.compareMediaNames_); |
| 479 categoryStandardCN.sort(DestinationStore.compareMediaNames_); | 477 categoryStandardCN.sort(DestinationStore.compareMediaNames_); |
| 480 categoryStandardISO.sort(DestinationStore.compareMediaNames_); | 478 categoryStandardISO.sort(DestinationStore.compareMediaNames_); |
| 481 categoryStandardJP.sort(DestinationStore.compareMediaNames_); | 479 categoryStandardJP.sort(DestinationStore.compareMediaNames_); |
| 482 categoryStandardMisc.sort(DestinationStore.compareMediaNames_); | 480 categoryStandardMisc.sort(DestinationStore.compareMediaNames_); |
| 483 categoryCustom.sort(DestinationStore.compareMediaNames_); | 481 categoryCustom.sort(DestinationStore.compareMediaNames_); |
| 484 | 482 |
| 485 // Then put it all back together. | 483 // Then put it all back together. |
| 486 mediaSize.option = categoryStandardNA; | 484 mediaSize.option = categoryStandardNA; |
| 487 mediaSize.option.push(...categoryStandardCN, ...categoryStandardISO, | 485 mediaSize.option.push( |
| 488 ...categoryStandardJP, ...categoryStandardMisc, ...categoryCustom); | 486 ...categoryStandardCN, ...categoryStandardISO, ...categoryStandardJP, |
| 487 ...categoryStandardMisc, ...categoryCustom); |
| 489 return capabilities; | 488 return capabilities; |
| 490 }; | 489 }; |
| 491 | 490 |
| 492 DestinationStore.prototype = { | 491 DestinationStore.prototype = { |
| 493 __proto__: cr.EventTarget.prototype, | 492 __proto__: cr.EventTarget.prototype, |
| 494 | 493 |
| 495 /** | 494 /** |
| 496 * @param {?string=} opt_account Account to filter destinations by. When | 495 * @param {?string=} opt_account Account to filter destinations by. When |
| 497 * null or omitted, all destinations are returned. | 496 * null or omitted, all destinations are returned. |
| 498 * @return {!Array<!print_preview.Destination>} List of destinations | 497 * @return {!Array<!print_preview.Destination>} List of destinations |
| (...skipping 20 matching lines...) Expand all Loading... |
| 519 get isAutoSelectDestinationInProgress() { | 518 get isAutoSelectDestinationInProgress() { |
| 520 return this.selectedDestination_ == null && | 519 return this.selectedDestination_ == null && |
| 521 this.autoSelectTimeout_ != null; | 520 this.autoSelectTimeout_ != null; |
| 522 }, | 521 }, |
| 523 | 522 |
| 524 /** | 523 /** |
| 525 * @return {boolean} Whether a search for local destinations is in progress. | 524 * @return {boolean} Whether a search for local destinations is in progress. |
| 526 */ | 525 */ |
| 527 get isLocalDestinationSearchInProgress() { | 526 get isLocalDestinationSearchInProgress() { |
| 528 return this.isLocalDestinationSearchInProgress_ || | 527 return this.isLocalDestinationSearchInProgress_ || |
| 529 this.isPrivetDestinationSearchInProgress_ || | 528 this.isPrivetDestinationSearchInProgress_ || |
| 530 this.isExtensionDestinationSearchInProgress_; | 529 this.isExtensionDestinationSearchInProgress_; |
| 531 }, | 530 }, |
| 532 | 531 |
| 533 /** | 532 /** |
| 534 * @return {boolean} Whether a search for cloud destinations is in progress. | 533 * @return {boolean} Whether a search for cloud destinations is in progress. |
| 535 */ | 534 */ |
| 536 get isCloudDestinationSearchInProgress() { | 535 get isCloudDestinationSearchInProgress() { |
| 537 return !!this.cloudPrintInterface_ && | 536 return !!this.cloudPrintInterface_ && |
| 538 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; | 537 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; |
| 539 }, | 538 }, |
| 540 | 539 |
| 541 /** | 540 /** |
| 542 * Initializes the destination store. Sets the initially selected | 541 * Initializes the destination store. Sets the initially selected |
| 543 * destination. If any inserted destinations match this ID, that destination | 542 * destination. If any inserted destinations match this ID, that destination |
| 544 * will be automatically selected. This method must be called after the | 543 * will be automatically selected. This method must be called after the |
| 545 * print_preview.AppState has been initialized. | 544 * print_preview.AppState has been initialized. |
| 546 * @param {boolean} isInAppKioskMode Whether the print preview is in App | 545 * @param {boolean} isInAppKioskMode Whether the print preview is in App |
| 547 * Kiosk mode. | 546 * Kiosk mode. |
| 548 * @param {?string} systemDefaultDestinationId ID of the system default | 547 * @param {?string} systemDefaultDestinationId ID of the system default |
| 549 * destination. | 548 * destination. |
| 550 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized | 549 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized |
| 551 * default destination selection rules. | 550 * default destination selection rules. |
| 552 */ | 551 */ |
| 553 init: function( | 552 init: function( |
| 554 isInAppKioskMode, | 553 isInAppKioskMode, systemDefaultDestinationId, |
| 555 systemDefaultDestinationId, | |
| 556 serializedDefaultDestinationSelectionRulesStr) { | 554 serializedDefaultDestinationSelectionRulesStr) { |
| 557 this.pdfPrinterEnabled_ = !isInAppKioskMode; | 555 this.pdfPrinterEnabled_ = !isInAppKioskMode; |
| 558 this.systemDefaultDestinationId_ = systemDefaultDestinationId; | 556 this.systemDefaultDestinationId_ = systemDefaultDestinationId; |
| 559 this.createLocalPdfPrintDestination_(); | 557 this.createLocalPdfPrintDestination_(); |
| 560 | 558 |
| 561 if (!this.appState_.isSelectedDestinationValid()) { | 559 if (!this.appState_.isSelectedDestinationValid()) { |
| 562 var destinationMatch = this.convertToDestinationMatch_( | 560 var destinationMatch = this.convertToDestinationMatch_( |
| 563 serializedDefaultDestinationSelectionRulesStr); | 561 serializedDefaultDestinationSelectionRulesStr); |
| 564 if (destinationMatch) { | 562 if (destinationMatch) { |
| 565 this.fetchMatchingDestination_(destinationMatch); | 563 this.fetchMatchingDestination_(destinationMatch); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 586 // destination, don't select any future destinations, just mark | 584 // destination, don't select any future destinations, just mark |
| 587 // them recent. Otherwise, there is a race condition between selecting | 585 // them recent. Otherwise, there is a race condition between selecting |
| 588 // destinations/updating the print ticket and this selecting a new | 586 // destinations/updating the print ticket and this selecting a new |
| 589 // destination that causes random print preview errors. | 587 // destination that causes random print preview errors. |
| 590 for (var i = 0; i < this.appState_.recentDestinations.length; i++) { | 588 for (var i = 0; i < this.appState_.recentDestinations.length; i++) { |
| 591 origin = this.appState_.recentDestinations[i].origin; | 589 origin = this.appState_.recentDestinations[i].origin; |
| 592 id = this.appState_.recentDestinations[i].id; | 590 id = this.appState_.recentDestinations[i].id; |
| 593 account = this.appState_.recentDestinations[i].account || ''; | 591 account = this.appState_.recentDestinations[i].account || ''; |
| 594 name = this.appState_.recentDestinations[i].name || ''; | 592 name = this.appState_.recentDestinations[i].name || ''; |
| 595 capabilities = this.appState_.recentDestinations[i].capabilities; | 593 capabilities = this.appState_.recentDestinations[i].capabilities; |
| 596 extensionId = this.appState_.recentDestinations[i].extensionId || | 594 extensionId = this.appState_.recentDestinations[i].extensionId || ''; |
| 597 ''; | |
| 598 extensionName = | 595 extensionName = |
| 599 this.appState_.recentDestinations[i].extensionName || ''; | 596 this.appState_.recentDestinations[i].extensionName || ''; |
| 600 var candidate = | 597 var candidate = this.destinationMap_[this.getDestinationKey_( |
| 601 this.destinationMap_[this.getDestinationKey_(origin, | 598 origin, id, account)]; |
| 602 id, account)]; | |
| 603 if (candidate != null) { | 599 if (candidate != null) { |
| 604 if (!foundDestination) | 600 if (!foundDestination) |
| 605 this.selectDestination(candidate); | 601 this.selectDestination(candidate); |
| 606 candidate.isRecent = true; | 602 candidate.isRecent = true; |
| 607 foundDestination = true; | 603 foundDestination = true; |
| 608 } else if (!foundDestination) { | 604 } else if (!foundDestination) { |
| 609 foundDestination = this.fetchPreselectedDestination_( | 605 foundDestination = this.fetchPreselectedDestination_( |
| 610 origin, | 606 origin, id, account, name, capabilities, extensionId, |
| 611 id, | 607 extensionName); |
| 612 account, | |
| 613 name, | |
| 614 capabilities, | |
| 615 extensionId, | |
| 616 extensionName); | |
| 617 } | 608 } |
| 618 } | 609 } |
| 619 } | 610 } |
| 620 if (foundDestination) return; | 611 if (foundDestination) |
| 612 return; |
| 621 | 613 |
| 622 // Try the system default | 614 // Try the system default |
| 623 id = this.systemDefaultDestinationId_ || ''; | 615 id = this.systemDefaultDestinationId_ || ''; |
| 624 origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ? | 616 origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ? |
| 625 print_preview.DestinationOrigin.LOCAL : | 617 print_preview.DestinationOrigin.LOCAL : |
| 626 this.platformOrigin_; | 618 this.platformOrigin_; |
| 627 account = ''; | 619 account = ''; |
| 628 var candidate = | 620 var candidate = |
| 629 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; | 621 this.destinationMap_[this.getDestinationKey_(origin, id, account)]; |
| 630 if (candidate != null) { | 622 if (candidate != null) { |
| 631 this.selectDestination(candidate); | 623 this.selectDestination(candidate); |
| 632 return; | 624 return; |
| 633 } | 625 } |
| 634 | 626 |
| 635 if (this.fetchPreselectedDestination_( | 627 if (this.fetchPreselectedDestination_( |
| 636 origin, | 628 origin, id, account, name, capabilities, extensionId, |
| 637 id, | |
| 638 account, | |
| 639 name, | |
| 640 capabilities, | |
| 641 extensionId, | |
| 642 extensionName)) { | 629 extensionName)) { |
| 643 return; | 630 return; |
| 644 } | 631 } |
| 645 | 632 |
| 646 this.selectPdfDestination_(); | 633 this.selectPdfDestination_(); |
| 647 }, | 634 }, |
| 648 | 635 |
| 649 /** | 636 /** |
| 650 * Attempts to fetch capabilities of the destination identified by the | 637 * Attempts to fetch capabilities of the destination identified by the |
| 651 * provided origin, id and account. | 638 * provided origin, id and account. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 664 */ | 651 */ |
| 665 fetchPreselectedDestination_: function( | 652 fetchPreselectedDestination_: function( |
| 666 origin, id, account, name, capabilities, extensionId, extensionName) { | 653 origin, id, account, name, capabilities, extensionId, extensionName) { |
| 667 this.autoSelectMatchingDestination_ = | 654 this.autoSelectMatchingDestination_ = |
| 668 this.createExactDestinationMatch_(origin, id); | 655 this.createExactDestinationMatch_(origin, id); |
| 669 | 656 |
| 670 if (origin == print_preview.DestinationOrigin.LOCAL || | 657 if (origin == print_preview.DestinationOrigin.LOCAL || |
| 671 origin == print_preview.DestinationOrigin.CROS) { | 658 origin == print_preview.DestinationOrigin.CROS) { |
| 672 this.nativeLayer_.getPrinterCapabilities(id).then( | 659 this.nativeLayer_.getPrinterCapabilities(id).then( |
| 673 this.onLocalDestinationCapabilitiesSet_.bind(this), | 660 this.onLocalDestinationCapabilitiesSet_.bind(this), |
| 674 this.onGetCapabilitiesFail_.bind(this, | 661 this.onGetCapabilitiesFail_.bind( |
| 675 /** @type {print_preview.DestinationOrigin} */ (origin), | 662 this, |
| 676 id)); | 663 /** @type {print_preview.DestinationOrigin} */ (origin), id)); |
| 677 return true; | 664 return true; |
| 678 } | 665 } |
| 679 | 666 |
| 680 if (this.cloudPrintInterface_ && | 667 if (this.cloudPrintInterface_ && |
| 681 (origin == print_preview.DestinationOrigin.COOKIES || | 668 (origin == print_preview.DestinationOrigin.COOKIES || |
| 682 origin == print_preview.DestinationOrigin.DEVICE)) { | 669 origin == print_preview.DestinationOrigin.DEVICE)) { |
| 683 this.cloudPrintInterface_.printer( | 670 this.cloudPrintInterface_.printer( |
| 684 id, | 671 id, |
| 685 /** @type {print_preview.DestinationOrigin} */(origin), | 672 /** @type {print_preview.DestinationOrigin} */ (origin), account); |
| 686 account); | |
| 687 return true; | 673 return true; |
| 688 } | 674 } |
| 689 | 675 |
| 690 if (origin == print_preview.DestinationOrigin.PRIVET) { | 676 if (origin == print_preview.DestinationOrigin.PRIVET) { |
| 691 // TODO(noamsml): Resolve a specific printer instead of listing all | 677 // TODO(noamsml): Resolve a specific printer instead of listing all |
| 692 // privet printers in this case. | 678 // privet printers in this case. |
| 693 this.nativeLayer_.getPrivetPrinters().then( | 679 this.nativeLayer_.getPrivetPrinters().then( |
| 694 this.endPrivetPrinterSearch_.bind(this)); | 680 this.endPrivetPrinterSearch_.bind(this)); |
| 695 | 681 |
| 696 // Create a fake selectedDestination_ that is not actually in the | 682 // Create a fake selectedDestination_ that is not actually in the |
| 697 // destination store. When the real destination is created, this | 683 // destination store. When the real destination is created, this |
| 698 // destination will be overwritten. | 684 // destination will be overwritten. |
| 699 this.selectedDestination_ = new print_preview.Destination( | 685 this.selectedDestination_ = new print_preview.Destination( |
| 700 id, | 686 id, print_preview.DestinationType.LOCAL, |
| 701 print_preview.DestinationType.LOCAL, | 687 print_preview.DestinationOrigin.PRIVET, name, false /*isRecent*/, |
| 702 print_preview.DestinationOrigin.PRIVET, | |
| 703 name, | |
| 704 false /*isRecent*/, | |
| 705 print_preview.DestinationConnectionStatus.ONLINE); | 688 print_preview.DestinationConnectionStatus.ONLINE); |
| 706 | 689 |
| 707 if (capabilities) { | 690 if (capabilities) { |
| 708 this.selectedDestination_.capabilities = capabilities; | 691 this.selectedDestination_.capabilities = capabilities; |
| 709 | 692 |
| 710 cr.dispatchSimpleEvent( | 693 cr.dispatchSimpleEvent( |
| 711 this, | 694 this, |
| 712 DestinationStore.EventType | 695 DestinationStore.EventType |
| 713 .CACHED_SELECTED_DESTINATION_INFO_READY); | 696 .CACHED_SELECTED_DESTINATION_INFO_READY); |
| 714 } | 697 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 743 }, | 726 }, |
| 744 | 727 |
| 745 /** | 728 /** |
| 746 * Attempts to find a destination matching the provided rules. | 729 * Attempts to find a destination matching the provided rules. |
| 747 * @param {!print_preview.DestinationMatch} destinationMatch Rules to match. | 730 * @param {!print_preview.DestinationMatch} destinationMatch Rules to match. |
| 748 * @private | 731 * @private |
| 749 */ | 732 */ |
| 750 fetchMatchingDestination_: function(destinationMatch) { | 733 fetchMatchingDestination_: function(destinationMatch) { |
| 751 this.autoSelectMatchingDestination_ = destinationMatch; | 734 this.autoSelectMatchingDestination_ = destinationMatch; |
| 752 | 735 |
| 753 if (destinationMatch.matchOrigin( | 736 if (destinationMatch.matchOrigin(print_preview.DestinationOrigin.LOCAL) || |
| 754 print_preview.DestinationOrigin.LOCAL) || | 737 destinationMatch.matchOrigin(print_preview.DestinationOrigin.CROS)) { |
| 755 destinationMatch.matchOrigin( | |
| 756 print_preview.DestinationOrigin.CROS)) { | |
| 757 this.startLoadLocalDestinations(); | 738 this.startLoadLocalDestinations(); |
| 758 } | 739 } |
| 759 if (destinationMatch.matchOrigin( | 740 if (destinationMatch.matchOrigin( |
| 760 print_preview.DestinationOrigin.PRIVET)) { | 741 print_preview.DestinationOrigin.PRIVET)) { |
| 761 this.startLoadPrivetDestinations(); | 742 this.startLoadPrivetDestinations(); |
| 762 } | 743 } |
| 763 if (destinationMatch.matchOrigin( | 744 if (destinationMatch.matchOrigin( |
| 764 print_preview.DestinationOrigin.EXTENSION)) { | 745 print_preview.DestinationOrigin.EXTENSION)) { |
| 765 this.startLoadExtensionDestinations(); | 746 this.startLoadExtensionDestinations(); |
| 766 } | 747 } |
| 767 if (destinationMatch.matchOrigin( | 748 if (destinationMatch.matchOrigin( |
| 768 print_preview.DestinationOrigin.COOKIES) || | 749 print_preview.DestinationOrigin.COOKIES) || |
| 769 destinationMatch.matchOrigin( | 750 destinationMatch.matchOrigin( |
| 770 print_preview.DestinationOrigin.DEVICE) || | 751 print_preview.DestinationOrigin.DEVICE) || |
| 771 destinationMatch.matchOrigin( | 752 destinationMatch.matchOrigin( |
| 772 print_preview.DestinationOrigin.PROFILE)) { | 753 print_preview.DestinationOrigin.PROFILE)) { |
| 773 this.startLoadCloudDestinations(); | 754 this.startLoadCloudDestinations(); |
| 774 } | 755 } |
| 775 }, | 756 }, |
| 776 | 757 |
| 777 /** | 758 /** |
| 778 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized | 759 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized |
| 779 * default destination selection rules. | 760 * default destination selection rules. |
| 780 * @return {?print_preview.DestinationMatch} Creates rules matching | 761 * @return {?print_preview.DestinationMatch} Creates rules matching |
| 781 * previously selected destination. | 762 * previously selected destination. |
| 782 * @private | 763 * @private |
| 783 */ | 764 */ |
| 784 convertToDestinationMatch_: function( | 765 convertToDestinationMatch_: function( |
| 785 serializedDefaultDestinationSelectionRulesStr) { | 766 serializedDefaultDestinationSelectionRulesStr) { |
| 786 var matchRules = null; | 767 var matchRules = null; |
| 787 try { | 768 try { |
| 788 if (serializedDefaultDestinationSelectionRulesStr) { | 769 if (serializedDefaultDestinationSelectionRulesStr) { |
| 789 matchRules = | 770 matchRules = |
| 790 JSON.parse(serializedDefaultDestinationSelectionRulesStr); | 771 JSON.parse(serializedDefaultDestinationSelectionRulesStr); |
| 791 } | 772 } |
| 792 } catch(e) { | 773 } catch (e) { |
| 793 console.error( | 774 console.error('Failed to parse defaultDestinationSelectionRules: ' + e); |
| 794 'Failed to parse defaultDestinationSelectionRules: ' + e); | |
| 795 } | 775 } |
| 796 if (!matchRules) | 776 if (!matchRules) |
| 797 return null; | 777 return null; |
| 798 | 778 |
| 799 var isLocal = !matchRules.kind || matchRules.kind == 'local'; | 779 var isLocal = !matchRules.kind || matchRules.kind == 'local'; |
| 800 var isCloud = !matchRules.kind || matchRules.kind == 'cloud'; | 780 var isCloud = !matchRules.kind || matchRules.kind == 'cloud'; |
| 801 if (!isLocal && !isCloud) { | 781 if (!isLocal && !isCloud) { |
| 802 console.error('Unsupported type: "' + matchRules.kind + '"'); | 782 console.error('Unsupported type: "' + matchRules.kind + '"'); |
| 803 return null; | 783 return null; |
| 804 } | 784 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 828 var displayNameRegExp = null; | 808 var displayNameRegExp = null; |
| 829 try { | 809 try { |
| 830 if (matchRules.namePattern) { | 810 if (matchRules.namePattern) { |
| 831 displayNameRegExp = new RegExp(matchRules.namePattern || '.*'); | 811 displayNameRegExp = new RegExp(matchRules.namePattern || '.*'); |
| 832 } | 812 } |
| 833 } catch (e) { | 813 } catch (e) { |
| 834 console.error('Failed to parse regexp for "name": ' + e); | 814 console.error('Failed to parse regexp for "name": ' + e); |
| 835 } | 815 } |
| 836 | 816 |
| 837 return new print_preview.DestinationMatch( | 817 return new print_preview.DestinationMatch( |
| 838 origins, | 818 origins, idRegExp, displayNameRegExp, |
| 839 idRegExp, | |
| 840 displayNameRegExp, | |
| 841 true /*skipVirtualDestinations*/); | 819 true /*skipVirtualDestinations*/); |
| 842 }, | 820 }, |
| 843 | 821 |
| 844 /** | 822 /** |
| 845 * @return {print_preview.DestinationMatch} Creates rules matching | 823 * @return {print_preview.DestinationMatch} Creates rules matching |
| 846 * previously selected destination. | 824 * previously selected destination. |
| 847 * @private | 825 * @private |
| 848 */ | 826 */ |
| 849 convertPreselectedToDestinationMatch_: function() { | 827 convertPreselectedToDestinationMatch_: function() { |
| 850 if (this.appState_.isSelectedDestinationValid()) { | 828 if (this.appState_.isSelectedDestinationValid()) { |
| 851 return this.createExactDestinationMatch_( | 829 return this.createExactDestinationMatch_( |
| 852 this.appState_.selectedDestination.origin, | 830 this.appState_.selectedDestination.origin, |
| 853 this.appState_.selectedDestination.id); | 831 this.appState_.selectedDestination.id); |
| 854 } | 832 } |
| 855 if (this.systemDefaultDestinationId_) { | 833 if (this.systemDefaultDestinationId_) { |
| 856 return this.createExactDestinationMatch_( | 834 return this.createExactDestinationMatch_( |
| 857 this.platformOrigin_, | 835 this.platformOrigin_, this.systemDefaultDestinationId_); |
| 858 this.systemDefaultDestinationId_); | |
| 859 } | 836 } |
| 860 return null; | 837 return null; |
| 861 }, | 838 }, |
| 862 | 839 |
| 863 /** | 840 /** |
| 864 * @param {string | print_preview.DestinationOrigin} origin Destination | 841 * @param {string | print_preview.DestinationOrigin} origin Destination |
| 865 * origin. | 842 * origin. |
| 866 * @param {string} id Destination id. | 843 * @param {string} id Destination id. |
| 867 * @return {!print_preview.DestinationMatch} Creates rules matching | 844 * @return {!print_preview.DestinationMatch} Creates rules matching |
| 868 * provided destination. | 845 * provided destination. |
| 869 * @private | 846 * @private |
| 870 */ | 847 */ |
| 871 createExactDestinationMatch_: function(origin, id) { | 848 createExactDestinationMatch_: function(origin, id) { |
| 872 return new print_preview.DestinationMatch( | 849 return new print_preview.DestinationMatch( |
| 873 [origin], | 850 [origin], |
| 874 new RegExp('^' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$'), | 851 new RegExp('^' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$'), |
| 875 null /*displayNameRegExp*/, | 852 null /*displayNameRegExp*/, false /*skipVirtualDestinations*/); |
| 876 false /*skipVirtualDestinations*/); | |
| 877 }, | 853 }, |
| 878 | 854 |
| 879 /** | 855 /** |
| 880 * Sets the destination store's Google Cloud Print interface. | 856 * Sets the destination store's Google Cloud Print interface. |
| 881 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface | 857 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface |
| 882 * to set. | 858 * to set. |
| 883 */ | 859 */ |
| 884 setCloudPrintInterface: function(cloudPrintInterface) { | 860 setCloudPrintInterface: function(cloudPrintInterface) { |
| 885 this.cloudPrintInterface_ = cloudPrintInterface; | 861 this.cloudPrintInterface_ = cloudPrintInterface; |
| 886 this.tracker_.add( | 862 this.tracker_.add( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 } else if (destination == this.selectedDestination_) { | 906 } else if (destination == this.selectedDestination_) { |
| 931 return; | 907 return; |
| 932 } | 908 } |
| 933 if (destination == null) { | 909 if (destination == null) { |
| 934 this.selectedDestination_ = null; | 910 this.selectedDestination_ = null; |
| 935 cr.dispatchSimpleEvent( | 911 cr.dispatchSimpleEvent( |
| 936 this, DestinationStore.EventType.DESTINATION_SELECT); | 912 this, DestinationStore.EventType.DESTINATION_SELECT); |
| 937 return; | 913 return; |
| 938 } | 914 } |
| 939 | 915 |
| 940 assert(!destination.isProvisional, | 916 assert( |
| 941 'Unable to select provisonal destinations'); | 917 !destination.isProvisional, |
| 918 'Unable to select provisonal destinations'); |
| 942 | 919 |
| 943 // Update and persist selected destination. | 920 // Update and persist selected destination. |
| 944 this.selectedDestination_ = destination; | 921 this.selectedDestination_ = destination; |
| 945 this.selectedDestination_.isRecent = true; | 922 this.selectedDestination_.isRecent = true; |
| 946 this.appState_.persistSelectedDestination(this.selectedDestination_); | 923 this.appState_.persistSelectedDestination(this.selectedDestination_); |
| 947 // Adjust metrics. | 924 // Adjust metrics. |
| 948 if (destination.cloudID && | 925 if (destination.cloudID && |
| 949 this.destinations_.some(function(otherDestination) { | 926 this.destinations_.some(function(otherDestination) { |
| 950 return otherDestination.cloudID == destination.cloudID && | 927 return otherDestination.cloudID == destination.cloudID && |
| 951 otherDestination != destination; | 928 otherDestination != destination; |
| 952 })) { | 929 })) { |
| 953 this.metrics_.record(destination.isPrivet ? | 930 this.metrics_.record( |
| 954 print_preview.Metrics.DestinationSearchBucket. | 931 destination.isPrivet ? print_preview.Metrics.DestinationSearchBucket |
| 955 PRIVET_DUPLICATE_SELECTED : | 932 .PRIVET_DUPLICATE_SELECTED : |
| 956 print_preview.Metrics.DestinationSearchBucket. | 933 print_preview.Metrics.DestinationSearchBucket |
| 957 CLOUD_DUPLICATE_SELECTED); | 934 .CLOUD_DUPLICATE_SELECTED); |
| 958 } | 935 } |
| 959 // Notify about selected destination change. | 936 // Notify about selected destination change. |
| 960 cr.dispatchSimpleEvent( | 937 cr.dispatchSimpleEvent( |
| 961 this, DestinationStore.EventType.DESTINATION_SELECT); | 938 this, DestinationStore.EventType.DESTINATION_SELECT); |
| 962 // Request destination capabilities from backend, since they are not | 939 // Request destination capabilities from backend, since they are not |
| 963 // known yet. | 940 // known yet. |
| 964 if (destination.capabilities == null) { | 941 if (destination.capabilities == null) { |
| 965 if (destination.isPrivet) { | 942 if (destination.isPrivet) { |
| 966 this.nativeLayer_.getPrivetPrinterCapabilities(destination.id).then( | 943 this.nativeLayer_.getPrivetPrinterCapabilities(destination.id) |
| 967 this.onPrivetCapabilitiesSet_.bind(this), | 944 .then( |
| 968 this.onGetCapabilitiesFail_.bind(this, destination.origin, | 945 this.onPrivetCapabilitiesSet_.bind(this), |
| 969 destination.id)); | 946 this.onGetCapabilitiesFail_.bind( |
| 947 this, destination.origin, destination.id)); |
| 970 } else if (destination.isExtension) { | 948 } else if (destination.isExtension) { |
| 971 this.nativeLayer_.getExtensionPrinterCapabilities(destination.id) | 949 this.nativeLayer_.getExtensionPrinterCapabilities(destination.id) |
| 972 .then( | 950 .then( |
| 973 this.onExtensionCapabilitiesSet_.bind(this, destination.id), | 951 this.onExtensionCapabilitiesSet_.bind(this, destination.id), |
| 974 this.onGetCapabilitiesFail_.bind(this, destination.origin, | 952 this.onGetCapabilitiesFail_.bind( |
| 975 destination.id) | 953 this, destination.origin, destination.id)); |
| 976 ); | |
| 977 } else if (destination.isLocal) { | 954 } else if (destination.isLocal) { |
| 978 this.nativeLayer_.getPrinterCapabilities(destination.id).then( | 955 this.nativeLayer_.getPrinterCapabilities(destination.id) |
| 979 this.onLocalDestinationCapabilitiesSet_.bind(this), | 956 .then( |
| 980 this.onGetCapabilitiesFail_.bind(this, destination.origin, | 957 this.onLocalDestinationCapabilitiesSet_.bind(this), |
| 981 destination.id)); | 958 this.onGetCapabilitiesFail_.bind( |
| 959 this, destination.origin, destination.id)); |
| 982 } else { | 960 } else { |
| 983 assert(this.cloudPrintInterface_ != null, | 961 assert( |
| 984 'Cloud destination selected, but GCP is not enabled'); | 962 this.cloudPrintInterface_ != null, |
| 963 'Cloud destination selected, but GCP is not enabled'); |
| 985 this.cloudPrintInterface_.printer( | 964 this.cloudPrintInterface_.printer( |
| 986 destination.id, destination.origin, destination.account); | 965 destination.id, destination.origin, destination.account); |
| 987 } | 966 } |
| 988 } else { | 967 } else { |
| 989 cr.dispatchSimpleEvent( | 968 cr.dispatchSimpleEvent( |
| 990 this, | 969 this, |
| 991 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); | 970 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); |
| 992 } | 971 } |
| 993 }, | 972 }, |
| 994 | 973 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1016 this.nativeLayer_.grantExtensionPrinterAccess(destination.id); | 995 this.nativeLayer_.grantExtensionPrinterAccess(destination.id); |
| 1017 }, | 996 }, |
| 1018 | 997 |
| 1019 /** | 998 /** |
| 1020 * Selects 'Save to PDF' destination (since it always exists). | 999 * Selects 'Save to PDF' destination (since it always exists). |
| 1021 * @private | 1000 * @private |
| 1022 */ | 1001 */ |
| 1023 selectPdfDestination_: function() { | 1002 selectPdfDestination_: function() { |
| 1024 var saveToPdfKey = this.getDestinationKey_( | 1003 var saveToPdfKey = this.getDestinationKey_( |
| 1025 print_preview.DestinationOrigin.LOCAL, | 1004 print_preview.DestinationOrigin.LOCAL, |
| 1026 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 1005 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, ''); |
| 1027 ''); | |
| 1028 this.selectDestination( | 1006 this.selectDestination( |
| 1029 this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null); | 1007 this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null); |
| 1030 }, | 1008 }, |
| 1031 | 1009 |
| 1032 /** | 1010 /** |
| 1033 * Attempts to select system default destination with a fallback to | 1011 * Attempts to select system default destination with a fallback to |
| 1034 * 'Save to PDF' destination. | 1012 * 'Save to PDF' destination. |
| 1035 * @private | 1013 * @private |
| 1036 */ | 1014 */ |
| 1037 selectDefaultDestination_: function() { | 1015 selectDefaultDestination_: function() { |
| 1038 if (this.systemDefaultDestinationId_) { | 1016 if (this.systemDefaultDestinationId_) { |
| 1039 if (this.autoSelectMatchingDestination_ && | 1017 if (this.autoSelectMatchingDestination_ && |
| 1040 !this.autoSelectMatchingDestination_.matchIdAndOrigin( | 1018 !this.autoSelectMatchingDestination_.matchIdAndOrigin( |
| 1041 this.systemDefaultDestinationId_, | 1019 this.systemDefaultDestinationId_, this.platformOrigin_)) { |
| 1042 this.platformOrigin_)) { | |
| 1043 if (this.fetchPreselectedDestination_( | 1020 if (this.fetchPreselectedDestination_( |
| 1044 this.platformOrigin_, | 1021 this.platformOrigin_, this.systemDefaultDestinationId_, |
| 1045 this.systemDefaultDestinationId_, | 1022 '' /*account*/, '' /*name*/, null /*capabilities*/, |
| 1046 '' /*account*/, | 1023 '' /*extensionId*/, '' /*extensionName*/)) { |
| 1047 '' /*name*/, | |
| 1048 null /*capabilities*/, | |
| 1049 '' /*extensionId*/, | |
| 1050 '' /*extensionName*/)) { | |
| 1051 return; | 1024 return; |
| 1052 } | 1025 } |
| 1053 } | 1026 } |
| 1054 } | 1027 } |
| 1055 this.selectPdfDestination_(); | 1028 this.selectPdfDestination_(); |
| 1056 }, | 1029 }, |
| 1057 | 1030 |
| 1058 /** Initiates loading of local print destinations. */ | 1031 /** Initiates loading of local print destinations. */ |
| 1059 startLoadLocalDestinations: function() { | 1032 startLoadLocalDestinations: function() { |
| 1060 if (!this.hasLoadedAllLocalDestinations_) { | 1033 if (!this.hasLoadedAllLocalDestinations_) { |
| 1061 this.hasLoadedAllLocalDestinations_ = true; | 1034 this.hasLoadedAllLocalDestinations_ = true; |
| 1062 this.nativeLayer_.getPrinters().then( | 1035 this.nativeLayer_.getPrinters().then( |
| 1063 this.onLocalDestinationsSet_.bind(this)); | 1036 this.onLocalDestinationsSet_.bind(this)); |
| 1064 this.isLocalDestinationSearchInProgress_ = true; | 1037 this.isLocalDestinationSearchInProgress_ = true; |
| 1065 cr.dispatchSimpleEvent( | 1038 cr.dispatchSimpleEvent( |
| 1066 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); | 1039 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
| 1067 } | 1040 } |
| 1068 }, | 1041 }, |
| 1069 | 1042 |
| 1070 /** Initiates loading of privet print destinations. */ | 1043 /** Initiates loading of privet print destinations. */ |
| 1071 startLoadPrivetDestinations: function() { | 1044 startLoadPrivetDestinations: function() { |
| 1072 if (this.hasLoadedAllPrivetDestinations_) | 1045 if (this.hasLoadedAllPrivetDestinations_) |
| 1073 return; | 1046 return; |
| 1074 this.isPrivetDestinationSearchInProgress_ = true; | 1047 this.isPrivetDestinationSearchInProgress_ = true; |
| 1075 this.nativeLayer_.getPrivetPrinters().then( | 1048 this.nativeLayer_.getPrivetPrinters().then( |
| 1076 this.endPrivetPrinterSearch_.bind(this), | 1049 this.endPrivetPrinterSearch_.bind(this), function() { |
| 1077 function() { | |
| 1078 // Rejected by C++, indicating privet printing is disabled. | 1050 // Rejected by C++, indicating privet printing is disabled. |
| 1079 this.hasLoadedAllPrivetDestinations_ = true; | 1051 this.hasLoadedAllPrivetDestinations_ = true; |
| 1080 this.isPrivetDestinationSearchInProgress_ = false; | 1052 this.isPrivetDestinationSearchInProgress_ = false; |
| 1081 }.bind(this)); | 1053 }.bind(this)); |
| 1082 cr.dispatchSimpleEvent( | 1054 cr.dispatchSimpleEvent( |
| 1083 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); | 1055 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
| 1084 }, | 1056 }, |
| 1085 | 1057 |
| 1086 /** Initializes loading of extension managed print destinations. */ | 1058 /** Initializes loading of extension managed print destinations. */ |
| 1087 startLoadExtensionDestinations: function() { | 1059 startLoadExtensionDestinations: function() { |
| 1088 if (this.hasLoadedAllExtensionDestinations_) | 1060 if (this.hasLoadedAllExtensionDestinations_) |
| 1089 return; | 1061 return; |
| 1090 | 1062 |
| 1091 if (this.isExtensionDestinationSearchInProgress_) | 1063 if (this.isExtensionDestinationSearchInProgress_) |
| 1092 clearTimeout(this.extensionSearchTimeout_); | 1064 clearTimeout(this.extensionSearchTimeout_); |
| 1093 | 1065 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 /** | 1224 /** |
| 1253 * Updates an existing print destination with capabilities and display name | 1225 * Updates an existing print destination with capabilities and display name |
| 1254 * information. If the destination doesn't already exist, it will be added. | 1226 * information. If the destination doesn't already exist, it will be added. |
| 1255 * @param {!print_preview.Destination} destination Destination to update. | 1227 * @param {!print_preview.Destination} destination Destination to update. |
| 1256 * @private | 1228 * @private |
| 1257 */ | 1229 */ |
| 1258 updateDestination_: function(destination) { | 1230 updateDestination_: function(destination) { |
| 1259 assert(destination.constructor !== Array, 'Single printer expected'); | 1231 assert(destination.constructor !== Array, 'Single printer expected'); |
| 1260 destination.capabilities_ = DestinationStore.localizeCapabilities_( | 1232 destination.capabilities_ = DestinationStore.localizeCapabilities_( |
| 1261 assert(destination.capabilities_)); | 1233 assert(destination.capabilities_)); |
| 1262 destination.capabilities_ = DestinationStore.sortMediaSizes_( | 1234 destination.capabilities_ = |
| 1263 destination.capabilities_); | 1235 DestinationStore.sortMediaSizes_(destination.capabilities_); |
| 1264 var existingDestination = this.destinationMap_[this.getKey_(destination)]; | 1236 var existingDestination = this.destinationMap_[this.getKey_(destination)]; |
| 1265 if (existingDestination != null) { | 1237 if (existingDestination != null) { |
| 1266 existingDestination.capabilities = destination.capabilities; | 1238 existingDestination.capabilities = destination.capabilities; |
| 1267 } else { | 1239 } else { |
| 1268 this.insertDestination_(destination); | 1240 this.insertDestination_(destination); |
| 1269 } | 1241 } |
| 1270 | 1242 |
| 1271 if (this.selectedDestination_ && | 1243 if (this.selectedDestination_ && |
| 1272 (existingDestination == this.selectedDestination_ || | 1244 (existingDestination == this.selectedDestination_ || |
| 1273 destination == this.selectedDestination_)) { | 1245 destination == this.selectedDestination_)) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1296 endExtensionPrinterSearch_: function() { | 1268 endExtensionPrinterSearch_: function() { |
| 1297 this.isExtensionDestinationSearchInProgress_ = false; | 1269 this.isExtensionDestinationSearchInProgress_ = false; |
| 1298 this.hasLoadedAllExtensionDestinations_ = true; | 1270 this.hasLoadedAllExtensionDestinations_ = true; |
| 1299 cr.dispatchSimpleEvent( | 1271 cr.dispatchSimpleEvent( |
| 1300 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); | 1272 this, DestinationStore.EventType.DESTINATION_SEARCH_DONE); |
| 1301 // Clear initially selected (cached) extension destination if it hasn't | 1273 // Clear initially selected (cached) extension destination if it hasn't |
| 1302 // been found among reported extension destinations. | 1274 // been found among reported extension destinations. |
| 1303 if (this.autoSelectMatchingDestination_ && | 1275 if (this.autoSelectMatchingDestination_ && |
| 1304 this.autoSelectMatchingDestination_.matchOrigin( | 1276 this.autoSelectMatchingDestination_.matchOrigin( |
| 1305 print_preview.DestinationOrigin.EXTENSION) && | 1277 print_preview.DestinationOrigin.EXTENSION) && |
| 1306 this.selectedDestination_ && | 1278 this.selectedDestination_ && this.selectedDestination_.isExtension) { |
| 1307 this.selectedDestination_.isExtension) { | |
| 1308 this.selectDefaultDestination_(); | 1279 this.selectDefaultDestination_(); |
| 1309 } | 1280 } |
| 1310 }, | 1281 }, |
| 1311 | 1282 |
| 1312 /** | 1283 /** |
| 1313 * Inserts a destination into the store without dispatching any events. | 1284 * Inserts a destination into the store without dispatching any events. |
| 1314 * @return {boolean} Whether the inserted destination was not already in the | 1285 * @return {boolean} Whether the inserted destination was not already in the |
| 1315 * store. | 1286 * store. |
| 1316 * @private | 1287 * @private |
| 1317 */ | 1288 */ |
| 1318 insertIntoStore_: function(destination) { | 1289 insertIntoStore_: function(destination) { |
| 1319 var key = this.getKey_(destination); | 1290 var key = this.getKey_(destination); |
| 1320 var existingDestination = this.destinationMap_[key]; | 1291 var existingDestination = this.destinationMap_[key]; |
| 1321 if (existingDestination == null) { | 1292 if (existingDestination == null) { |
| 1322 destination.isRecent |= this.appState_.recentDestinations.some( | 1293 destination.isRecent |= |
| 1323 function(recent) { | 1294 this.appState_.recentDestinations.some(function(recent) { |
| 1324 return (destination.id == recent.id && | 1295 return ( |
| 1325 destination.origin == recent.origin); | 1296 destination.id == recent.id && |
| 1297 destination.origin == recent.origin); |
| 1326 }, this); | 1298 }, this); |
| 1327 this.destinations_.push(destination); | 1299 this.destinations_.push(destination); |
| 1328 this.destinationMap_[key] = destination; | 1300 this.destinationMap_[key] = destination; |
| 1329 return true; | 1301 return true; |
| 1330 } else if (existingDestination.connectionStatus == | 1302 } else if ( |
| 1331 print_preview.DestinationConnectionStatus.UNKNOWN && | 1303 existingDestination.connectionStatus == |
| 1332 destination.connectionStatus != | 1304 print_preview.DestinationConnectionStatus.UNKNOWN && |
| 1333 print_preview.DestinationConnectionStatus.UNKNOWN) { | 1305 destination.connectionStatus != |
| 1306 print_preview.DestinationConnectionStatus.UNKNOWN) { |
| 1334 existingDestination.connectionStatus = destination.connectionStatus; | 1307 existingDestination.connectionStatus = destination.connectionStatus; |
| 1335 return true; | 1308 return true; |
| 1336 } else { | 1309 } else { |
| 1337 return false; | 1310 return false; |
| 1338 } | 1311 } |
| 1339 }, | 1312 }, |
| 1340 | 1313 |
| 1341 /** | 1314 /** |
| 1342 * Binds handlers to events. | 1315 * Binds handlers to events. |
| 1343 * @private | 1316 * @private |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1359 * @private | 1332 * @private |
| 1360 */ | 1333 */ |
| 1361 createLocalPdfPrintDestination_: function() { | 1334 createLocalPdfPrintDestination_: function() { |
| 1362 // TODO(alekseys): Create PDF printer in the native code and send its | 1335 // TODO(alekseys): Create PDF printer in the native code and send its |
| 1363 // capabilities back with other local printers. | 1336 // capabilities back with other local printers. |
| 1364 if (this.pdfPrinterEnabled_) { | 1337 if (this.pdfPrinterEnabled_) { |
| 1365 this.insertDestination_(new print_preview.Destination( | 1338 this.insertDestination_(new print_preview.Destination( |
| 1366 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 1339 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
| 1367 print_preview.DestinationType.LOCAL, | 1340 print_preview.DestinationType.LOCAL, |
| 1368 print_preview.DestinationOrigin.LOCAL, | 1341 print_preview.DestinationOrigin.LOCAL, |
| 1369 loadTimeData.getString('printToPDF'), | 1342 loadTimeData.getString('printToPDF'), false /*isRecent*/, |
| 1370 false /*isRecent*/, | |
| 1371 print_preview.DestinationConnectionStatus.ONLINE)); | 1343 print_preview.DestinationConnectionStatus.ONLINE)); |
| 1372 } | 1344 } |
| 1373 }, | 1345 }, |
| 1374 | 1346 |
| 1375 /** | 1347 /** |
| 1376 * Resets the state of the destination store to its initial state. | 1348 * Resets the state of the destination store to its initial state. |
| 1377 * @private | 1349 * @private |
| 1378 */ | 1350 */ |
| 1379 reset_: function() { | 1351 reset_: function() { |
| 1380 this.destinations_ = []; | 1352 this.destinations_ = []; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 * information about and capabilities of the local print destination. | 1388 * information about and capabilities of the local print destination. |
| 1417 * @private | 1389 * @private |
| 1418 */ | 1390 */ |
| 1419 onLocalDestinationCapabilitiesSet_: function(settingsInfo) { | 1391 onLocalDestinationCapabilitiesSet_: function(settingsInfo) { |
| 1420 var destinationId = settingsInfo['printerId']; | 1392 var destinationId = settingsInfo['printerId']; |
| 1421 var printerName = settingsInfo['printerName']; | 1393 var printerName = settingsInfo['printerName']; |
| 1422 var printerDescription = settingsInfo['printerDescription']; | 1394 var printerDescription = settingsInfo['printerDescription']; |
| 1423 // PDF is special since we don't need to query the device for | 1395 // PDF is special since we don't need to query the device for |
| 1424 // capabilities. | 1396 // capabilities. |
| 1425 var origin = destinationId == | 1397 var origin = destinationId == |
| 1426 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ? | 1398 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ? |
| 1427 print_preview.DestinationOrigin.LOCAL : this.platformOrigin_; | 1399 print_preview.DestinationOrigin.LOCAL : |
| 1428 var key = this.getDestinationKey_( | 1400 this.platformOrigin_; |
| 1429 origin, | 1401 var key = this.getDestinationKey_(origin, destinationId, ''); |
| 1430 destinationId, | |
| 1431 ''); | |
| 1432 var destination = this.destinationMap_[key]; | 1402 var destination = this.destinationMap_[key]; |
| 1433 var capabilities = DestinationStore.localizeCapabilities_( | 1403 var capabilities = |
| 1434 settingsInfo.capabilities); | 1404 DestinationStore.localizeCapabilities_(settingsInfo.capabilities); |
| 1435 // Special case for PDF printer (until local printers capabilities are | 1405 // Special case for PDF printer (until local printers capabilities are |
| 1436 // reported in CDD format too). | 1406 // reported in CDD format too). |
| 1437 if (destinationId == | 1407 if (destinationId == |
| 1438 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 1408 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 1439 if (destination) { | 1409 if (destination) { |
| 1440 destination.capabilities = capabilities; | 1410 destination.capabilities = capabilities; |
| 1441 } | 1411 } |
| 1442 } else { | 1412 } else { |
| 1443 if (destination) { | 1413 if (destination) { |
| 1444 // In case there were multiple capabilities request for this local | 1414 // In case there were multiple capabilities request for this local |
| 1445 // destination, just ignore the later ones. | 1415 // destination, just ignore the later ones. |
| 1446 if (destination.capabilities != null) { | 1416 if (destination.capabilities != null) { |
| 1447 return; | 1417 return; |
| 1448 } | 1418 } |
| 1449 destination.capabilities = capabilities; | 1419 destination.capabilities = capabilities; |
| 1450 } else { | 1420 } else { |
| 1451 var isEnterprisePrinter = settingsInfo['cupsEnterprisePrinter']; | 1421 var isEnterprisePrinter = settingsInfo['cupsEnterprisePrinter']; |
| 1452 destination = print_preview.LocalDestinationParser.parse( | 1422 destination = print_preview.LocalDestinationParser.parse({ |
| 1453 {deviceName: destinationId, | 1423 deviceName: destinationId, |
| 1454 printerName: printerName, | 1424 printerName: printerName, |
| 1455 cupsEnterprisePrinter: isEnterprisePrinter, | 1425 cupsEnterprisePrinter: isEnterprisePrinter, |
| 1456 printerDescription: printerDescription}); | 1426 printerDescription: printerDescription |
| 1427 }); |
| 1457 destination.capabilities = capabilities; | 1428 destination.capabilities = capabilities; |
| 1458 this.insertDestination_(destination); | 1429 this.insertDestination_(destination); |
| 1459 } | 1430 } |
| 1460 } | 1431 } |
| 1461 if (this.selectedDestination_ && | 1432 if (this.selectedDestination_ && |
| 1462 this.selectedDestination_.id == destinationId) { | 1433 this.selectedDestination_.id == destinationId) { |
| 1463 cr.dispatchSimpleEvent( | 1434 cr.dispatchSimpleEvent( |
| 1464 this, | 1435 this, |
| 1465 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); | 1436 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); |
| 1466 } | 1437 } |
| 1467 }, | 1438 }, |
| 1468 | 1439 |
| 1469 /** | 1440 /** |
| 1470 * Called when a request to get a local destination's print capabilities | 1441 * Called when a request to get a local destination's print capabilities |
| 1471 * fails. If the destination is the initial destination, auto-select another | 1442 * fails. If the destination is the initial destination, auto-select another |
| 1472 * destination instead. | 1443 * destination instead. |
| 1473 * @param {print_preview.DestinationOrigin} origin The origin type of the | 1444 * @param {print_preview.DestinationOrigin} origin The origin type of the |
| 1474 * failed destination. | 1445 * failed destination. |
| 1475 * @param {string} destinationId The destination ID that failed. | 1446 * @param {string} destinationId The destination ID that failed. |
| 1476 * @private | 1447 * @private |
| 1477 */ | 1448 */ |
| 1478 onGetCapabilitiesFail_: function(origin, destinationId) { | 1449 onGetCapabilitiesFail_: function(origin, destinationId) { |
| 1479 console.warn('Failed to get print capabilities for printer ' + | 1450 console.warn( |
| 1480 destinationId); | 1451 'Failed to get print capabilities for printer ' + destinationId); |
| 1481 if (this.autoSelectMatchingDestination_ && | 1452 if (this.autoSelectMatchingDestination_ && |
| 1482 this.autoSelectMatchingDestination_.matchIdAndOrigin( | 1453 this.autoSelectMatchingDestination_.matchIdAndOrigin( |
| 1483 destinationId, origin)) { | 1454 destinationId, origin)) { |
| 1484 this.selectDefaultDestination_(); | 1455 this.selectDefaultDestination_(); |
| 1485 } | 1456 } |
| 1486 }, | 1457 }, |
| 1487 | 1458 |
| 1488 /** | 1459 /** |
| 1489 * Called when the /search call completes, either successfully or not. | 1460 * Called when the /search call completes, either successfully or not. |
| 1490 * In case of success, stores fetched destinations. | 1461 * In case of success, stores fetched destinations. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 }, | 1583 }, |
| 1613 | 1584 |
| 1614 /** | 1585 /** |
| 1615 * Called when capabilities for an extension managed printer are set. | 1586 * Called when capabilities for an extension managed printer are set. |
| 1616 * @param {string} printerId The printer Id. | 1587 * @param {string} printerId The printer Id. |
| 1617 * @param {!print_preview.Cdd} capabilities The printer's capabilities. | 1588 * @param {!print_preview.Cdd} capabilities The printer's capabilities. |
| 1618 * @private | 1589 * @private |
| 1619 */ | 1590 */ |
| 1620 onExtensionCapabilitiesSet_: function(printerId, capabilities) { | 1591 onExtensionCapabilitiesSet_: function(printerId, capabilities) { |
| 1621 var destinationKey = this.getDestinationKey_( | 1592 var destinationKey = this.getDestinationKey_( |
| 1622 print_preview.DestinationOrigin.EXTENSION, | 1593 print_preview.DestinationOrigin.EXTENSION, printerId, |
| 1623 printerId, | |
| 1624 '' /* account */); | 1594 '' /* account */); |
| 1625 var destination = this.destinationMap_[destinationKey]; | 1595 var destination = this.destinationMap_[destinationKey]; |
| 1626 if (!destination) | 1596 if (!destination) |
| 1627 return; | 1597 return; |
| 1628 destination.capabilities = capabilities; | 1598 destination.capabilities = capabilities; |
| 1629 this.updateDestination_(destination); | 1599 this.updateDestination_(destination); |
| 1630 }, | 1600 }, |
| 1631 | 1601 |
| 1632 /** | 1602 /** |
| 1633 * Called from native layer after the user was requested to sign in, and did | 1603 * Called from native layer after the user was requested to sign in, and did |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1661 * @param {!print_preview.Destination} destination Destination. | 1631 * @param {!print_preview.Destination} destination Destination. |
| 1662 * @private | 1632 * @private |
| 1663 */ | 1633 */ |
| 1664 getKey_: function(destination) { | 1634 getKey_: function(destination) { |
| 1665 return this.getDestinationKey_( | 1635 return this.getDestinationKey_( |
| 1666 destination.origin, destination.id, destination.account); | 1636 destination.origin, destination.id, destination.account); |
| 1667 } | 1637 } |
| 1668 }; | 1638 }; |
| 1669 | 1639 |
| 1670 // Export | 1640 // Export |
| 1671 return { | 1641 return {DestinationStore: DestinationStore}; |
| 1672 DestinationStore: DestinationStore | |
| 1673 }; | |
| 1674 }); | 1642 }); |
| OLD | NEW |