| 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 /** Namespace that contains a method to parse local print destinations. */ | 8 /** Namespace that contains a method to parse local print destinations. */ |
| 9 function LocalDestinationParser() {} | 9 function LocalDestinationParser() {} |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Parses a local print destination. | 12 * Parses a local print destination. |
| 13 * @param {!print_preview.LocalDestinationInfo} destinationInfo Information | 13 * @param {!print_preview.LocalDestinationInfo} destinationInfo Information |
| 14 * describing a local print destination. | 14 * describing a local print destination. |
| 15 * @return {!print_preview.Destination} Parsed local print destination. | 15 * @return {!print_preview.Destination} Parsed local print destination. |
| 16 */ | 16 */ |
| 17 LocalDestinationParser.parse = function(destinationInfo) { | 17 LocalDestinationParser.parse = function(destinationInfo) { |
| 18 var options = {description: destinationInfo.printerDescription, | 18 var options = { |
| 19 isEnterprisePrinter: destinationInfo.cupsEnterprisePrinter}; | 19 description: destinationInfo.printerDescription, |
| 20 isEnterprisePrinter: destinationInfo.cupsEnterprisePrinter |
| 21 }; |
| 20 if (destinationInfo.printerOptions) { | 22 if (destinationInfo.printerOptions) { |
| 21 // Convert options into cloud print tags format. | 23 // Convert options into cloud print tags format. |
| 22 options.tags = Object.keys(destinationInfo.printerOptions).map( | 24 options.tags = |
| 23 function(key) {return '__cp__' + key + '=' + this[key];}, | 25 Object.keys(destinationInfo.printerOptions).map(function(key) { |
| 24 destinationInfo.printerOptions); | 26 return '__cp__' + key + '=' + this[key]; |
| 27 }, destinationInfo.printerOptions); |
| 25 } | 28 } |
| 26 return new print_preview.Destination( | 29 return new print_preview.Destination( |
| 27 destinationInfo.deviceName, | 30 destinationInfo.deviceName, print_preview.DestinationType.LOCAL, |
| 28 print_preview.DestinationType.LOCAL, | |
| 29 cr.isChromeOS ? print_preview.DestinationOrigin.CROS : | 31 cr.isChromeOS ? print_preview.DestinationOrigin.CROS : |
| 30 print_preview.DestinationOrigin.LOCAL, | 32 print_preview.DestinationOrigin.LOCAL, |
| 31 destinationInfo.printerName, | 33 destinationInfo.printerName, false /*isRecent*/, |
| 32 false /*isRecent*/, | 34 print_preview.DestinationConnectionStatus.ONLINE, options); |
| 33 print_preview.DestinationConnectionStatus.ONLINE, | |
| 34 options); | |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 function PrivetDestinationParser() {} | 37 function PrivetDestinationParser() {} |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Parses a privet destination as one or more local printers. | 40 * Parses a privet destination as one or more local printers. |
| 41 * @param {!print_preview.PrivetPrinterDescription} destinationInfo Object | 41 * @param {!print_preview.PrivetPrinterDescription} destinationInfo Object |
| 42 * that describes a privet printer. | 42 * that describes a privet printer. |
| 43 * @return {!Array<!print_preview.Destination>} Parsed destination info. | 43 * @return {!Array<!print_preview.Destination>} Parsed destination info. |
| 44 */ | 44 */ |
| 45 PrivetDestinationParser.parse = function(destinationInfo) { | 45 PrivetDestinationParser.parse = function(destinationInfo) { |
| 46 var returnedPrinters = []; | 46 var returnedPrinters = []; |
| 47 | 47 |
| 48 if (destinationInfo.hasLocalPrinting) { | 48 if (destinationInfo.hasLocalPrinting) { |
| 49 returnedPrinters.push(new print_preview.Destination( | 49 returnedPrinters.push(new print_preview.Destination( |
| 50 destinationInfo.serviceName, | 50 destinationInfo.serviceName, print_preview.DestinationType.LOCAL, |
| 51 print_preview.DestinationType.LOCAL, | 51 print_preview.DestinationOrigin.PRIVET, destinationInfo.name, |
| 52 print_preview.DestinationOrigin.PRIVET, | 52 false /*isRecent*/, print_preview.DestinationConnectionStatus.ONLINE, |
| 53 destinationInfo.name, | |
| 54 false /*isRecent*/, | |
| 55 print_preview.DestinationConnectionStatus.ONLINE, | |
| 56 {cloudID: destinationInfo.cloudID})); | 53 {cloudID: destinationInfo.cloudID})); |
| 57 } | 54 } |
| 58 | 55 |
| 59 if (destinationInfo.isUnregistered) { | 56 if (destinationInfo.isUnregistered) { |
| 60 returnedPrinters.push(new print_preview.Destination( | 57 returnedPrinters.push(new print_preview.Destination( |
| 61 destinationInfo.serviceName, | 58 destinationInfo.serviceName, print_preview.DestinationType.GOOGLE, |
| 62 print_preview.DestinationType.GOOGLE, | 59 print_preview.DestinationOrigin.PRIVET, destinationInfo.name, |
| 63 print_preview.DestinationOrigin.PRIVET, | |
| 64 destinationInfo.name, | |
| 65 false /*isRecent*/, | 60 false /*isRecent*/, |
| 66 print_preview.DestinationConnectionStatus.UNREGISTERED)); | 61 print_preview.DestinationConnectionStatus.UNREGISTERED)); |
| 67 } | 62 } |
| 68 | 63 |
| 69 return returnedPrinters; | 64 return returnedPrinters; |
| 70 }; | 65 }; |
| 71 | 66 |
| 72 function ExtensionDestinationParser() {} | 67 function ExtensionDestinationParser() {} |
| 73 | 68 |
| 74 /** | 69 /** |
| 75 * Parses an extension destination from an extension supplied printer | 70 * Parses an extension destination from an extension supplied printer |
| 76 * description. | 71 * description. |
| 77 * @param {!Object} destinationInfo Object describing an extension printer. | 72 * @param {!Object} destinationInfo Object describing an extension printer. |
| 78 * @return {!print_preview.Destination} Parsed destination. | 73 * @return {!print_preview.Destination} Parsed destination. |
| 79 */ | 74 */ |
| 80 ExtensionDestinationParser.parse = function(destinationInfo) { | 75 ExtensionDestinationParser.parse = function(destinationInfo) { |
| 81 var provisionalType = | 76 var provisionalType = destinationInfo.provisional ? |
| 82 destinationInfo.provisional ? | 77 print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION : |
| 83 print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION : | 78 print_preview.DestinationProvisionalType.NONE; |
| 84 print_preview.DestinationProvisionalType.NONE; | |
| 85 | 79 |
| 86 return new print_preview.Destination( | 80 return new print_preview.Destination( |
| 87 destinationInfo.id, | 81 destinationInfo.id, print_preview.DestinationType.LOCAL, |
| 88 print_preview.DestinationType.LOCAL, | 82 print_preview.DestinationOrigin.EXTENSION, destinationInfo.name, |
| 89 print_preview.DestinationOrigin.EXTENSION, | 83 false /* isRecent */, print_preview.DestinationConnectionStatus.ONLINE, |
| 90 destinationInfo.name, | 84 { |
| 91 false /* isRecent */, | 85 description: destinationInfo.description || '', |
| 92 print_preview.DestinationConnectionStatus.ONLINE, | 86 extensionId: destinationInfo.extensionId, |
| 93 {description: destinationInfo.description || '', | 87 extensionName: destinationInfo.extensionName || '', |
| 94 extensionId: destinationInfo.extensionId, | 88 provisionalType: provisionalType |
| 95 extensionName: destinationInfo.extensionName || '', | 89 }); |
| 96 provisionalType: provisionalType}); | |
| 97 }; | 90 }; |
| 98 | 91 |
| 99 // Export | 92 // Export |
| 100 return { | 93 return { |
| 101 LocalDestinationParser: LocalDestinationParser, | 94 LocalDestinationParser: LocalDestinationParser, |
| 102 PrivetDestinationParser: PrivetDestinationParser, | 95 PrivetDestinationParser: PrivetDestinationParser, |
| 103 ExtensionDestinationParser: ExtensionDestinationParser | 96 ExtensionDestinationParser: ExtensionDestinationParser |
| 104 }; | 97 }; |
| 105 }); | 98 }); |
| OLD | NEW |