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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized | 588 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized |
| 589 * default destination selection rules. | 589 * default destination selection rules. |
| 590 */ | 590 */ |
| 591 init: function( | 591 init: function( |
| 592 isInAppKioskMode, | 592 isInAppKioskMode, |
| 593 systemDefaultDestinationId, | 593 systemDefaultDestinationId, |
| 594 serializedDefaultDestinationSelectionRulesStr) { | 594 serializedDefaultDestinationSelectionRulesStr) { |
| 595 this.pdfPrinterEnabled_ = !isInAppKioskMode; | 595 this.pdfPrinterEnabled_ = !isInAppKioskMode; |
| 596 this.systemDefaultDestinationId_ = systemDefaultDestinationId; | 596 this.systemDefaultDestinationId_ = systemDefaultDestinationId; |
| 597 this.createLocalPdfPrintDestination_(); | 597 this.createLocalPdfPrintDestination_(); |
| 598 cr.addWebUIListener('extension-printers-added', | |
| 599 this.onExtensionPrintersAdded_.bind(this)); | |
| 598 | 600 |
| 599 if (!this.appState_.isSelectedDestinationValid()) { | 601 if (!this.appState_.isSelectedDestinationValid()) { |
| 600 var destinationMatch = this.convertToDestinationMatch_( | 602 var destinationMatch = this.convertToDestinationMatch_( |
| 601 serializedDefaultDestinationSelectionRulesStr); | 603 serializedDefaultDestinationSelectionRulesStr); |
| 602 if (destinationMatch) { | 604 if (destinationMatch) { |
| 603 this.fetchMatchingDestination_(destinationMatch); | 605 this.fetchMatchingDestination_(destinationMatch); |
| 604 return; | 606 return; |
| 605 } | 607 } |
| 606 } | 608 } |
| 607 | 609 |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 | 1105 |
| 1104 /** Initializes loading of extension managed print destinations. */ | 1106 /** Initializes loading of extension managed print destinations. */ |
| 1105 startLoadExtensionDestinations: function() { | 1107 startLoadExtensionDestinations: function() { |
| 1106 if (this.hasLoadedAllExtensionDestinations_) | 1108 if (this.hasLoadedAllExtensionDestinations_) |
| 1107 return; | 1109 return; |
| 1108 | 1110 |
| 1109 if (this.isExtensionDestinationSearchInProgress_) | 1111 if (this.isExtensionDestinationSearchInProgress_) |
| 1110 clearTimeout(this.extensionSearchTimeout_); | 1112 clearTimeout(this.extensionSearchTimeout_); |
| 1111 | 1113 |
| 1112 this.isExtensionDestinationSearchInProgress_ = true; | 1114 this.isExtensionDestinationSearchInProgress_ = true; |
| 1113 this.nativeLayer_.startGetExtensionDestinations(); | 1115 this.nativeLayer_.getExtensionPrinters().then( |
| 1116 this.onExtensionPrintersDone_.bind(this)); | |
| 1114 cr.dispatchSimpleEvent( | 1117 cr.dispatchSimpleEvent( |
| 1115 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); | 1118 this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED); |
| 1116 this.extensionSearchTimeout_ = setTimeout( | 1119 this.extensionSearchTimeout_ = setTimeout( |
| 1117 this.endExtensionPrinterSearch_.bind(this), | 1120 this.endExtensionPrinterSearch_.bind(this), |
| 1118 DestinationStore.EXTENSION_SEARCH_DURATION_); | 1121 DestinationStore.EXTENSION_SEARCH_DURATION_); |
| 1119 }, | 1122 }, |
| 1120 | 1123 |
| 1121 /** | 1124 /** |
| 1122 * Initiates loading of cloud destinations. | 1125 * Initiates loading of cloud destinations. |
| 1123 * @param {print_preview.DestinationOrigin=} opt_origin Search destinations | 1126 * @param {print_preview.DestinationOrigin=} opt_origin Search destinations |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1376 this.tracker_.add( | 1379 this.tracker_.add( |
| 1377 nativeLayerEventTarget, | 1380 nativeLayerEventTarget, |
| 1378 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, | 1381 print_preview.NativeLayer.EventType.PRIVET_PRINTER_CHANGED, |
| 1379 this.onPrivetPrinterAdded_.bind(this)); | 1382 this.onPrivetPrinterAdded_.bind(this)); |
| 1380 this.tracker_.add( | 1383 this.tracker_.add( |
| 1381 nativeLayerEventTarget, | 1384 nativeLayerEventTarget, |
| 1382 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, | 1385 print_preview.NativeLayer.EventType.PRIVET_CAPABILITIES_SET, |
| 1383 this.onPrivetCapabilitiesSet_.bind(this)); | 1386 this.onPrivetCapabilitiesSet_.bind(this)); |
| 1384 this.tracker_.add( | 1387 this.tracker_.add( |
| 1385 nativeLayerEventTarget, | 1388 nativeLayerEventTarget, |
| 1386 print_preview.NativeLayer.EventType.EXTENSION_PRINTERS_ADDED, | |
| 1387 this.onExtensionPrintersAdded_.bind(this)); | |
| 1388 this.tracker_.add( | |
| 1389 nativeLayerEventTarget, | |
| 1390 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, | 1389 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, |
| 1391 this.onExtensionCapabilitiesSet_.bind(this)); | 1390 this.onExtensionCapabilitiesSet_.bind(this)); |
| 1392 this.tracker_.add( | 1391 this.tracker_.add( |
| 1393 nativeLayerEventTarget, | 1392 nativeLayerEventTarget, |
| 1394 print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED, | 1393 print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED, |
| 1395 this.handleProvisionalDestinationResolved_.bind(this)); | 1394 this.handleProvisionalDestinationResolved_.bind(this)); |
| 1396 }, | 1395 }, |
| 1397 | 1396 |
| 1398 /** | 1397 /** |
| 1399 * Creates a local PDF print destination. | 1398 * Creates a local PDF print destination. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1618 print_preview.PrivetDestinationParser.parse(event.printer); | 1617 print_preview.PrivetDestinationParser.parse(event.printer); |
| 1619 destinations.forEach(function(dest) { | 1618 destinations.forEach(function(dest) { |
| 1620 dest.capabilities = event.capabilities; | 1619 dest.capabilities = event.capabilities; |
| 1621 this.updateDestination_(dest); | 1620 this.updateDestination_(dest); |
| 1622 }, this); | 1621 }, this); |
| 1623 }, | 1622 }, |
| 1624 | 1623 |
| 1625 /** | 1624 /** |
| 1626 * Called when an extension responds to a getExtensionDestinations | 1625 * Called when an extension responds to a getExtensionDestinations |
| 1627 * request. | 1626 * request. |
| 1628 * @param {Object} event Contains information about list of printers | 1627 * @param {!Array<!{extensionId: string, |
| 1629 * reported by the extension. | 1628 * extensionName: string, |
| 1630 * {@code done} parameter is set iff this is the final list of printers | 1629 * id: string, |
| 1631 * returned as part of getExtensionDestinations request. | 1630 * name: string, |
| 1631 * description: (string|undefined), | |
| 1632 * provisional: (boolean|undefined)}>} printers The list | |
| 1633 * containing information about printers added by an extension. | |
| 1632 * @private | 1634 * @private |
| 1633 */ | 1635 */ |
| 1634 onExtensionPrintersAdded_: function(event) { | 1636 onExtensionPrintersAdded_: function(printers) { |
| 1635 this.insertDestinations_(event.printers.map(function(printer) { | 1637 this.insertDestinations_( |
| 1636 return print_preview.ExtensionDestinationParser.parse(printer); | 1638 printers.map(print_preview.ExtensionDestinationParser.parse)); |
| 1637 })); | 1639 }, |
| 1638 | 1640 |
| 1639 if (event.done && this.isExtensionDestinationSearchInProgress_) { | 1641 /** |
| 1642 * Called when all extensions are done adding printers. | |
| 1643 * @param {boolean} done Whether printers are done | |
|
dpapad
2017/06/07 03:20:11
Nit: Maybe update this comment to
Whether searchin
rbpotter
2017/06/07 03:46:41
Removed this comment since parameter was removed p
| |
| 1644 * @private | |
| 1645 */ | |
| 1646 onExtensionPrintersDone_: function(done) { | |
| 1647 if (done && this.isExtensionDestinationSearchInProgress_) { | |
|
dpapad
2017/06/07 03:20:11
This is basically same question as in the C++ hand
rbpotter
2017/06/07 03:46:41
Done.
| |
| 1640 clearTimeout(this.extensionSearchTimeout_); | 1648 clearTimeout(this.extensionSearchTimeout_); |
| 1641 this.endExtensionPrinterSearch_(); | 1649 this.endExtensionPrinterSearch_(); |
| 1642 } | 1650 } |
| 1643 }, | 1651 }, |
| 1644 | 1652 |
| 1645 /** | 1653 /** |
| 1646 * Called when capabilities for an extension managed printer are set. | 1654 * Called when capabilities for an extension managed printer are set. |
| 1647 * @param {Object} event Contains the printer's capabilities and ID. | 1655 * @param {Object} event Contains the printer's capabilities and ID. |
| 1648 * @private | 1656 * @private |
| 1649 */ | 1657 */ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1695 return this.getDestinationKey_( | 1703 return this.getDestinationKey_( |
| 1696 destination.origin, destination.id, destination.account); | 1704 destination.origin, destination.id, destination.account); |
| 1697 } | 1705 } |
| 1698 }; | 1706 }; |
| 1699 | 1707 |
| 1700 // Export | 1708 // Export |
| 1701 return { | 1709 return { |
| 1702 DestinationStore: DestinationStore | 1710 DestinationStore: DestinationStore |
| 1703 }; | 1711 }; |
| 1704 }); | 1712 }); |
| OLD | NEW |