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
3 // found in the LICENSE file.
5 cr.define('print_preview', function() {
8 /** Namespace that contains a method to parse local print destinations. */
9 function LocalDestinationParser() {};
12 * Parses a local print destination.
13 * @param {!Object} destinationInfo Information describing a local print
15 * @return {!print_preview.Destination} Parsed local print destination.
17 LocalDestinationParser.parse = function(destinationInfo) {
18 var options = {'description': destinationInfo.printerDescription};
19 if (destinationInfo.printerOptions) {
20 // Convert options into cloud print tags format.
21 options.tags = Object.keys(destinationInfo.printerOptions).map(
22 function(key) {return '__cp__' + key + '=' + this[key];},
23 destinationInfo.printerOptions);
25 return new print_preview.Destination(
26 destinationInfo.deviceName,
27 print_preview.Destination.Type.LOCAL,
28 print_preview.Destination.Origin.LOCAL,
29 destinationInfo.printerName,
31 print_preview.Destination.ConnectionStatus.ONLINE,
35 function PrivetDestinationParser() {}
38 * Parses a privet destination as one or more local printers.
39 * @param {!Object} destinationInfo Object that describes a privet printer.
40 * @return {!Array<!print_preview.Destination>} Parsed destination info.
42 PrivetDestinationParser.parse = function(destinationInfo) {
43 var returnedPrinters = [];
45 if (destinationInfo.hasLocalPrinting) {
46 returnedPrinters.push(new print_preview.Destination(
47 destinationInfo.serviceName,
48 print_preview.Destination.Type.LOCAL,
49 print_preview.Destination.Origin.PRIVET,
52 print_preview.Destination.ConnectionStatus.ONLINE,
53 { cloudID: destinationInfo.cloudID }));
56 if (destinationInfo.isUnregistered) {
57 returnedPrinters.push(new print_preview.Destination(
58 destinationInfo.serviceName,
59 print_preview.Destination.Type.GOOGLE,
60 print_preview.Destination.Origin.PRIVET,
63 print_preview.Destination.ConnectionStatus.UNREGISTERED));
66 return returnedPrinters;
69 function ExtensionDestinationParser() {}
72 * Parses an extension destination from an extension supplied printer
74 * @param {!Object} destinationInfo Object describing an extension printer.
75 * @return {!print_preview.Destination} Parsed destination.
77 ExtensionDestinationParser.parse = function(destinationInfo) {
79 destinationInfo.provisional ?
80 print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION :
81 print_preview.Destination.ProvisionalType.NONE;
83 return new print_preview.Destination(
85 print_preview.Destination.Type.LOCAL,
86 print_preview.Destination.Origin.EXTENSION,
89 print_preview.Destination.ConnectionStatus.ONLINE,
90 {description: destinationInfo.description || '',
91 extensionId: destinationInfo.extensionId,
92 extensionName: destinationInfo.extensionName || '',
93 provisionalType: provisionalType});
98 LocalDestinationParser: LocalDestinationParser,
99 PrivetDestinationParser: PrivetDestinationParser,
100 ExtensionDestinationParser: ExtensionDestinationParser