| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 print_preview.DestinationOrigin.LOCAL; | 170 print_preview.DestinationOrigin.LOCAL; |
| 171 | 171 |
| 172 /** | 172 /** |
| 173 * Whether to default to the system default printer instead of the most | 173 * Whether to default to the system default printer instead of the most |
| 174 * recent destination. | 174 * recent destination. |
| 175 * @private {boolean} | 175 * @private {boolean} |
| 176 */ | 176 */ |
| 177 this.useSystemDefaultAsDefault_ = | 177 this.useSystemDefaultAsDefault_ = |
| 178 loadTimeData.getBoolean('useSystemDefaultPrinter'); | 178 loadTimeData.getBoolean('useSystemDefaultPrinter'); |
| 179 | 179 |
| 180 this.addEventListeners_(); | |
| 181 this.reset_(); | 180 this.reset_(); |
| 182 } | 181 } |
| 183 | 182 |
| 184 /** | 183 /** |
| 185 * Event types dispatched by the data store. | 184 * Event types dispatched by the data store. |
| 186 * @enum {string} | 185 * @enum {string} |
| 187 */ | 186 */ |
| 188 DestinationStore.EventType = { | 187 DestinationStore.EventType = { |
| 189 DESTINATION_SEARCH_DONE: | 188 DESTINATION_SEARCH_DONE: |
| 190 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', | 189 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE', |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 538 |
| 540 /** | 539 /** |
| 541 * @return {boolean} Whether a search for cloud destinations is in progress. | 540 * @return {boolean} Whether a search for cloud destinations is in progress. |
| 542 */ | 541 */ |
| 543 get isCloudDestinationSearchInProgress() { | 542 get isCloudDestinationSearchInProgress() { |
| 544 return !!this.cloudPrintInterface_ && | 543 return !!this.cloudPrintInterface_ && |
| 545 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; | 544 this.cloudPrintInterface_.isCloudDestinationSearchInProgress; |
| 546 }, | 545 }, |
| 547 | 546 |
| 548 /** | 547 /** |
| 548 * Starts listening for relevant WebUI events and adds the listeners to |
| 549 * |listenerTracker|. |listenerTracker| is responsible for removing the |
| 550 * listeners when necessary. |
| 551 * @param {!WebUIListenerTracker} listenerTracker |
| 552 */ |
| 553 addWebUIEventListeners: function(listenerTracker) { |
| 554 listenerTracker.add( |
| 555 'privet-printer-added', this.onPrivetPrinterAdded_.bind(this)); |
| 556 listenerTracker.add( |
| 557 'extension-printers-added', |
| 558 this.onExtensionPrintersAdded_.bind(this)); |
| 559 listenerTracker.add( |
| 560 'reload-printer-list', this.onDestinationsReload.bind(this)); |
| 561 }, |
| 562 |
| 563 /** |
| 549 * Initializes the destination store. Sets the initially selected | 564 * Initializes the destination store. Sets the initially selected |
| 550 * destination. If any inserted destinations match this ID, that destination | 565 * destination. If any inserted destinations match this ID, that destination |
| 551 * will be automatically selected. This method must be called after the | 566 * will be automatically selected. This method must be called after the |
| 552 * print_preview.AppState has been initialized. | 567 * print_preview.AppState has been initialized. |
| 553 * @param {boolean} isInAppKioskMode Whether the print preview is in App | 568 * @param {boolean} isInAppKioskMode Whether the print preview is in App |
| 554 * Kiosk mode. | 569 * Kiosk mode. |
| 555 * @param {?string} systemDefaultDestinationId ID of the system default | 570 * @param {?string} systemDefaultDestinationId ID of the system default |
| 556 * destination. | 571 * destination. |
| 557 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized | 572 * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized |
| 558 * default destination selection rules. | 573 * default destination selection rules. |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 }, | 1187 }, |
| 1173 | 1188 |
| 1174 /** | 1189 /** |
| 1175 * Dispatches the PROVISIONAL_DESTINATION_RESOLVED event for id | 1190 * Dispatches the PROVISIONAL_DESTINATION_RESOLVED event for id |
| 1176 * |provisionalId| and destination |destination|. | 1191 * |provisionalId| and destination |destination|. |
| 1177 * @param {string} provisionalId The ID of the destination that was | 1192 * @param {string} provisionalId The ID of the destination that was |
| 1178 * resolved. | 1193 * resolved. |
| 1179 * @param {?print_preview.Destination} destination Information about the | 1194 * @param {?print_preview.Destination} destination Information about the |
| 1180 * destination if it was resolved successfully. | 1195 * destination if it was resolved successfully. |
| 1181 */ | 1196 */ |
| 1182 dispatchProvisionalDestinationResolvedEvent_: function(provisionalId, | 1197 dispatchProvisionalDestinationResolvedEvent_: function( |
| 1183 destination) { | 1198 provisionalId, destination) { |
| 1184 var event = new Event( | 1199 var event = new Event( |
| 1185 DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED); | 1200 DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED); |
| 1186 event.provisionalId = provisionalId; | 1201 event.provisionalId = provisionalId; |
| 1187 event.destination = destination; | 1202 event.destination = destination; |
| 1188 this.dispatchEvent(event); | 1203 this.dispatchEvent(event); |
| 1189 }, | 1204 }, |
| 1190 | 1205 |
| 1191 /** | 1206 /** |
| 1192 * Inserts {@code destination} to the data store and dispatches a | 1207 * Inserts {@code destination} to the data store and dispatches a |
| 1193 * DESTINATIONS_INSERTED event. | 1208 * DESTINATIONS_INSERTED event. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 destination.connectionStatus != | 1341 destination.connectionStatus != |
| 1327 print_preview.DestinationConnectionStatus.UNKNOWN) { | 1342 print_preview.DestinationConnectionStatus.UNKNOWN) { |
| 1328 existingDestination.connectionStatus = destination.connectionStatus; | 1343 existingDestination.connectionStatus = destination.connectionStatus; |
| 1329 return true; | 1344 return true; |
| 1330 } else { | 1345 } else { |
| 1331 return false; | 1346 return false; |
| 1332 } | 1347 } |
| 1333 }, | 1348 }, |
| 1334 | 1349 |
| 1335 /** | 1350 /** |
| 1336 * Binds handlers to events. | |
| 1337 * @private | |
| 1338 */ | |
| 1339 addEventListeners_: function() { | |
| 1340 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); | |
| 1341 this.tracker_.add( | |
| 1342 nativeLayerEventTarget, | |
| 1343 print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD, | |
| 1344 this.onDestinationsReload_.bind(this)); | |
| 1345 }, | |
| 1346 | |
| 1347 /** | |
| 1348 * Creates a local PDF print destination. | 1351 * Creates a local PDF print destination. |
| 1349 * @private | 1352 * @private |
| 1350 */ | 1353 */ |
| 1351 createLocalPdfPrintDestination_: function() { | 1354 createLocalPdfPrintDestination_: function() { |
| 1352 // TODO(alekseys): Create PDF printer in the native code and send its | 1355 // TODO(alekseys): Create PDF printer in the native code and send its |
| 1353 // capabilities back with other local printers. | 1356 // capabilities back with other local printers. |
| 1354 if (this.pdfPrinterEnabled_) { | 1357 if (this.pdfPrinterEnabled_) { |
| 1355 this.insertDestination_(new print_preview.Destination( | 1358 this.insertDestination_(new print_preview.Destination( |
| 1356 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, | 1359 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, |
| 1357 print_preview.DestinationType.LOCAL, | 1360 print_preview.DestinationType.LOCAL, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 * name: string, | 1545 * name: string, |
| 1543 * hasLocalPrinting: boolean, | 1546 * hasLocalPrinting: boolean, |
| 1544 * isUnregistered: boolean, | 1547 * isUnregistered: boolean, |
| 1545 * cloudID: string}} printer Information about the added printer. | 1548 * cloudID: string}} printer Information about the added printer. |
| 1546 * @private | 1549 * @private |
| 1547 */ | 1550 */ |
| 1548 onPrivetPrinterAdded_: function(printer) { | 1551 onPrivetPrinterAdded_: function(printer) { |
| 1549 if (printer.serviceName == this.waitForRegisterDestination_ && | 1552 if (printer.serviceName == this.waitForRegisterDestination_ && |
| 1550 !printer.isUnregistered) { | 1553 !printer.isUnregistered) { |
| 1551 this.waitForRegisterDestination_ = null; | 1554 this.waitForRegisterDestination_ = null; |
| 1552 this.onDestinationsReload_(); | 1555 this.onDestinationsReload(); |
| 1553 } else { | 1556 } else { |
| 1554 this.insertDestinations_( | 1557 this.insertDestinations_( |
| 1555 print_preview.PrivetDestinationParser.parse(printer)); | 1558 print_preview.PrivetDestinationParser.parse(printer)); |
| 1556 } | 1559 } |
| 1557 }, | 1560 }, |
| 1558 | 1561 |
| 1559 /** | 1562 /** |
| 1560 * Called when capabilities for a privet printer are set. | 1563 * Called when capabilities for a privet printer are set. |
| 1561 * @param {!print_preview.PrivetPrinterCapabilitiesResponse} printerInfo | 1564 * @param {!print_preview.PrivetPrinterCapabilitiesResponse} printerInfo |
| 1562 * Contains the privet printer's description and capabilities. | 1565 * Contains the privet printer's description and capabilities. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 print_preview.DestinationOrigin.EXTENSION, printerId, | 1613 print_preview.DestinationOrigin.EXTENSION, printerId, |
| 1611 '' /* account */); | 1614 '' /* account */); |
| 1612 var destination = this.destinationMap_[destinationKey]; | 1615 var destination = this.destinationMap_[destinationKey]; |
| 1613 if (!destination) | 1616 if (!destination) |
| 1614 return; | 1617 return; |
| 1615 destination.capabilities = capabilities; | 1618 destination.capabilities = capabilities; |
| 1616 this.updateDestination_(destination); | 1619 this.updateDestination_(destination); |
| 1617 }, | 1620 }, |
| 1618 | 1621 |
| 1619 /** | 1622 /** |
| 1620 * Called from native layer after the user was requested to sign in, and did | 1623 * Called from print preview after the user was requested to sign in, and |
| 1621 * so successfully. | 1624 * did so successfully. |
| 1622 * @private | |
| 1623 */ | 1625 */ |
| 1624 onDestinationsReload_: function() { | 1626 onDestinationsReload: function() { |
| 1625 this.reset_(); | 1627 this.reset_(); |
| 1626 this.autoSelectMatchingDestination_ = | 1628 this.autoSelectMatchingDestination_ = |
| 1627 this.convertPreselectedToDestinationMatch_(); | 1629 this.convertPreselectedToDestinationMatch_(); |
| 1628 this.createLocalPdfPrintDestination_(); | 1630 this.createLocalPdfPrintDestination_(); |
| 1629 this.startLoadAllDestinations(); | 1631 this.startLoadAllDestinations(); |
| 1630 }, | 1632 }, |
| 1631 | 1633 |
| 1632 // TODO(vitalybuka): Remove three next functions replacing Destination.id | 1634 // TODO(vitalybuka): Remove three next functions replacing Destination.id |
| 1633 // and Destination.origin by complex ID. | 1635 // and Destination.origin by complex ID. |
| 1634 /** | 1636 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1650 */ | 1652 */ |
| 1651 getKey_: function(destination) { | 1653 getKey_: function(destination) { |
| 1652 return this.getDestinationKey_( | 1654 return this.getDestinationKey_( |
| 1653 destination.origin, destination.id, destination.account); | 1655 destination.origin, destination.id, destination.account); |
| 1654 } | 1656 } |
| 1655 }; | 1657 }; |
| 1656 | 1658 |
| 1657 // Export | 1659 // Export |
| 1658 return {DestinationStore: DestinationStore}; | 1660 return {DestinationStore: DestinationStore}; |
| 1659 }); | 1661 }); |
| OLD | NEW |