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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 * destination. | 769 * destination. |
| 770 * @param {string} extensionName Extension name associated with this | 770 * @param {string} extensionName Extension name associated with this |
| 771 * destination. | 771 * destination. |
| 772 * @private | 772 * @private |
| 773 */ | 773 */ |
| 774 fetchPreselectedDestination_: function( | 774 fetchPreselectedDestination_: function( |
| 775 origin, id, account, name, capabilities, extensionId, extensionName) { | 775 origin, id, account, name, capabilities, extensionId, extensionName) { |
| 776 this.autoSelectMatchingDestination_ = | 776 this.autoSelectMatchingDestination_ = |
| 777 this.createExactDestinationMatch_(origin, id); | 777 this.createExactDestinationMatch_(origin, id); |
| 778 | 778 |
| 779 if (origin == print_preview.Destination.Origin.LOCAL) { | 779 if (origin == print_preview.Destination.Origin.LOCAL || |
| 780 origin == print_preview.Destination.Origin.CROS) { | |
| 780 this.nativeLayer_.startGetLocalDestinationCapabilities(id); | 781 this.nativeLayer_.startGetLocalDestinationCapabilities(id); |
| 781 return true; | 782 return true; |
| 782 } | 783 } |
| 783 | 784 |
| 784 if (this.cloudPrintInterface_ && | 785 if (this.cloudPrintInterface_ && |
| 785 (origin == print_preview.Destination.Origin.COOKIES || | 786 (origin == print_preview.Destination.Origin.COOKIES || |
| 786 origin == print_preview.Destination.Origin.DEVICE)) { | 787 origin == print_preview.Destination.Origin.DEVICE)) { |
| 787 this.cloudPrintInterface_.printer(id, origin, account); | 788 this.cloudPrintInterface_.printer(id, origin, account); |
| 788 return true; | 789 return true; |
| 789 } | 790 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 if (!isLocal && !isCloud) { | 896 if (!isLocal && !isCloud) { |
| 896 console.error('Unsupported type: "' + matchRules.kind + '"'); | 897 console.error('Unsupported type: "' + matchRules.kind + '"'); |
| 897 return null; | 898 return null; |
| 898 } | 899 } |
| 899 | 900 |
| 900 var origins = []; | 901 var origins = []; |
| 901 if (isLocal) { | 902 if (isLocal) { |
| 902 origins.push(print_preview.Destination.Origin.LOCAL); | 903 origins.push(print_preview.Destination.Origin.LOCAL); |
| 903 origins.push(print_preview.Destination.Origin.PRIVET); | 904 origins.push(print_preview.Destination.Origin.PRIVET); |
| 904 origins.push(print_preview.Destination.Origin.EXTENSION); | 905 origins.push(print_preview.Destination.Origin.EXTENSION); |
| 906 origins.push(print_preview.Destination.Origin.CROS); | |
| 905 } | 907 } |
| 906 if (isCloud) { | 908 if (isCloud) { |
| 907 origins.push(print_preview.Destination.Origin.COOKIES); | 909 origins.push(print_preview.Destination.Origin.COOKIES); |
| 908 origins.push(print_preview.Destination.Origin.DEVICE); | 910 origins.push(print_preview.Destination.Origin.DEVICE); |
| 909 origins.push(print_preview.Destination.Origin.PROFILE); | 911 origins.push(print_preview.Destination.Origin.PROFILE); |
| 910 } | 912 } |
| 911 | 913 |
| 912 var idRegExp = null; | 914 var idRegExp = null; |
| 913 try { | 915 try { |
| 914 if (matchRules.idPattern) { | 916 if (matchRules.idPattern) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 this.cloudPrintInterface_.printer( | 1078 this.cloudPrintInterface_.printer( |
| 1077 destination.id, destination.origin, destination.account); | 1079 destination.id, destination.origin, destination.account); |
| 1078 } | 1080 } |
| 1079 } else { | 1081 } else { |
| 1080 cr.dispatchSimpleEvent( | 1082 cr.dispatchSimpleEvent( |
| 1081 this, | 1083 this, |
| 1082 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); | 1084 DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY); |
| 1083 } | 1085 } |
| 1084 }, | 1086 }, |
| 1085 | 1087 |
| 1088 resolveCrosDestination: function(destination) { | |
| 1089 this.nativeLayer_.setupPrinter(destination.id); | |
| 1090 }, | |
| 1091 | |
| 1086 /** | 1092 /** |
| 1087 * Attempts to resolve a provisional destination. | 1093 * Attempts to resolve a provisional destination. |
| 1088 * @param {!print_preview.Destination} destinaion Provisional destination | 1094 * @param {!print_preview.Destination} destinaion Provisional destination |
| 1089 * that should be resolved. | 1095 * that should be resolved. |
| 1090 */ | 1096 */ |
| 1091 resolveProvisionalDestination: function(destination) { | 1097 resolveProvisionalDestination: function(destination) { |
| 1092 assert( | 1098 assert( |
| 1093 destination.provisionalType == | 1099 destination.provisionalType == |
| 1094 print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION, | 1100 print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION, |
| 1095 'Provisional type cannot be resolved.'); | 1101 'Provisional type cannot be resolved.'); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 this.insertIntoStore_(destination); | 1271 this.insertIntoStore_(destination); |
| 1266 | 1272 |
| 1267 var event = new Event( | 1273 var event = new Event( |
| 1268 DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED); | 1274 DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED); |
| 1269 event.provisionalId = evt.provisionalId; | 1275 event.provisionalId = evt.provisionalId; |
| 1270 event.destination = destination; | 1276 event.destination = destination; |
| 1271 this.dispatchEvent(event); | 1277 this.dispatchEvent(event); |
| 1272 }, | 1278 }, |
| 1273 | 1279 |
| 1274 /** | 1280 /** |
| 1281 * Handle the result of a PRINTER_SETUP request. | |
| 1282 * @param {!Event} evt event carrying the results. | |
| 1283 * @private | |
| 1284 */ | |
| 1285 handleCrosDestinationResolved_: function(evt) { | |
| 1286 var event = new Event( | |
| 1287 DestinationStore.EventType.PRINTER_CONFIGURED); | |
|
xdai1
2016/12/30 00:38:13
Seems there is no DestinationStore.EventType.PRINT
skau
2017/01/04 18:57:06
Looks like it was left out of the CL somehow. It'
| |
| 1288 event.printerId = evt.printerId; | |
| 1289 event.capabilities = evt.capabilities; | |
| 1290 event.success = evt.success; | |
| 1291 this.dispatchEvent(event); | |
| 1292 }, | |
| 1293 | |
| 1294 /** | |
| 1275 * Inserts {@code destination} to the data store and dispatches a | 1295 * Inserts {@code destination} to the data store and dispatches a |
| 1276 * DESTINATIONS_INSERTED event. | 1296 * DESTINATIONS_INSERTED event. |
| 1277 * @param {!print_preview.Destination} destination Print destination to | 1297 * @param {!print_preview.Destination} destination Print destination to |
| 1278 * insert. | 1298 * insert. |
| 1279 * @private | 1299 * @private |
| 1280 */ | 1300 */ |
| 1281 insertDestination_: function(destination) { | 1301 insertDestination_: function(destination) { |
| 1282 if (this.insertIntoStore_(destination)) { | 1302 if (this.insertIntoStore_(destination)) { |
| 1283 this.destinationsInserted_(destination); | 1303 this.destinationsInserted_(destination); |
| 1284 } | 1304 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1449 print_preview.NativeLayer.EventType.EXTENSION_PRINTERS_ADDED, | 1469 print_preview.NativeLayer.EventType.EXTENSION_PRINTERS_ADDED, |
| 1450 this.onExtensionPrintersAdded_.bind(this)); | 1470 this.onExtensionPrintersAdded_.bind(this)); |
| 1451 this.tracker_.add( | 1471 this.tracker_.add( |
| 1452 this.nativeLayer_, | 1472 this.nativeLayer_, |
| 1453 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, | 1473 print_preview.NativeLayer.EventType.EXTENSION_CAPABILITIES_SET, |
| 1454 this.onExtensionCapabilitiesSet_.bind(this)); | 1474 this.onExtensionCapabilitiesSet_.bind(this)); |
| 1455 this.tracker_.add( | 1475 this.tracker_.add( |
| 1456 this.nativeLayer_, | 1476 this.nativeLayer_, |
| 1457 print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED, | 1477 print_preview.NativeLayer.EventType.PROVISIONAL_DESTINATION_RESOLVED, |
| 1458 this.handleProvisionalDestinationResolved_.bind(this)); | 1478 this.handleProvisionalDestinationResolved_.bind(this)); |
| 1479 this.tracker_.add( | |
| 1480 this.nativeLayer_, | |
| 1481 print_preview.NativeLayer.EventType.PRINTER_SETUP, | |
| 1482 this.handleCrosDestinationResolved_.bind(this)); | |
| 1459 }, | 1483 }, |
| 1460 | 1484 |
| 1461 /** | 1485 /** |
| 1462 * Creates a local PDF print destination. | 1486 * Creates a local PDF print destination. |
| 1463 * @return {!print_preview.Destination} Created print destination. | 1487 * @return {!print_preview.Destination} Created print destination. |
| 1464 * @private | 1488 * @private |
| 1465 */ | 1489 */ |
| 1466 createLocalPdfPrintDestination_: function() { | 1490 createLocalPdfPrintDestination_: function() { |
| 1467 // TODO(alekseys): Create PDF printer in the native code and send its | 1491 // TODO(alekseys): Create PDF printer in the native code and send its |
| 1468 // capabilities back with other local printers. | 1492 // capabilities back with other local printers. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1745 return this.getDestinationKey_( | 1769 return this.getDestinationKey_( |
| 1746 destination.origin, destination.id, destination.account); | 1770 destination.origin, destination.id, destination.account); |
| 1747 } | 1771 } |
| 1748 }; | 1772 }; |
| 1749 | 1773 |
| 1750 // Export | 1774 // Export |
| 1751 return { | 1775 return { |
| 1752 DestinationStore: DestinationStore | 1776 DestinationStore: DestinationStore |
| 1753 }; | 1777 }; |
| 1754 }); | 1778 }); |
| OLD | NEW |