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