Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: chrome/browser/resources/print_preview/data/local_parsers.js

Issue 2862203002: Print Preview: Fix data/ errors (Closed)
Patch Set: Fix destination resolver Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 isEnterprisePrinter: destinationInfo.cupsEnterprisePrinter}; 19 isEnterprisePrinter: destinationInfo.cupsEnterprisePrinter};
20 if (destinationInfo.printerOptions) { 20 if (destinationInfo.printerOptions) {
21 // Convert options into cloud print tags format. 21 // Convert options into cloud print tags format.
22 options.tags = Object.keys(destinationInfo.printerOptions).map( 22 options.tags = Object.keys(destinationInfo.printerOptions).map(
23 function(key) {return '__cp__' + key + '=' + this[key];}, 23 function(key) {return '__cp__' + key + '=' + this[key];},
24 destinationInfo.printerOptions); 24 destinationInfo.printerOptions);
25 } 25 }
26 return new print_preview.Destination( 26 return new print_preview.Destination(
27 destinationInfo.deviceName, 27 destinationInfo.deviceName,
28 print_preview.Destination.Type.LOCAL, 28 print_preview.DestinationType.LOCAL,
29 cr.isChromeOS ? print_preview.Destination.Origin.CROS : 29 cr.isChromeOS ? print_preview.DestinationOrigin.CROS :
30 print_preview.Destination.Origin.LOCAL, 30 print_preview.DestinationOrigin.LOCAL,
31 destinationInfo.printerName, 31 destinationInfo.printerName,
32 false /*isRecent*/, 32 false /*isRecent*/,
33 print_preview.Destination.ConnectionStatus.ONLINE, 33 print_preview.DestinationConnectionStatus.ONLINE,
34 options); 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 {!Object} destinationInfo Object that describes a privet printer. 41 * @param {!Object} destinationInfo Object that describes a privet printer.
42 * @return {!Array<!print_preview.Destination>} Parsed destination info. 42 * @return {!Array<!print_preview.Destination>} Parsed destination info.
43 */ 43 */
44 PrivetDestinationParser.parse = function(destinationInfo) { 44 PrivetDestinationParser.parse = function(destinationInfo) {
45 var returnedPrinters = []; 45 var returnedPrinters = [];
46 46
47 if (destinationInfo.hasLocalPrinting) { 47 if (destinationInfo.hasLocalPrinting) {
48 returnedPrinters.push(new print_preview.Destination( 48 returnedPrinters.push(new print_preview.Destination(
49 destinationInfo.serviceName, 49 destinationInfo.serviceName,
50 print_preview.Destination.Type.LOCAL, 50 print_preview.DestinationType.LOCAL,
51 print_preview.Destination.Origin.PRIVET, 51 print_preview.DestinationOrigin.PRIVET,
52 destinationInfo.name, 52 destinationInfo.name,
53 false /*isRecent*/, 53 false /*isRecent*/,
54 print_preview.Destination.ConnectionStatus.ONLINE, 54 print_preview.DestinationConnectionStatus.ONLINE,
55 { cloudID: destinationInfo.cloudID })); 55 {cloudID: destinationInfo.cloudID}));
56 } 56 }
57 57
58 if (destinationInfo.isUnregistered) { 58 if (destinationInfo.isUnregistered) {
59 returnedPrinters.push(new print_preview.Destination( 59 returnedPrinters.push(new print_preview.Destination(
60 destinationInfo.serviceName, 60 destinationInfo.serviceName,
61 print_preview.Destination.Type.GOOGLE, 61 print_preview.DestinationType.GOOGLE,
62 print_preview.Destination.Origin.PRIVET, 62 print_preview.DestinationOrigin.PRIVET,
63 destinationInfo.name, 63 destinationInfo.name,
64 false /*isRecent*/, 64 false /*isRecent*/,
65 print_preview.Destination.ConnectionStatus.UNREGISTERED)); 65 print_preview.DestinationConnectionStatus.UNREGISTERED));
66 } 66 }
67 67
68 return returnedPrinters; 68 return returnedPrinters;
69 }; 69 };
70 70
71 function ExtensionDestinationParser() {} 71 function ExtensionDestinationParser() {}
72 72
73 /** 73 /**
74 * Parses an extension destination from an extension supplied printer 74 * Parses an extension destination from an extension supplied printer
75 * description. 75 * description.
76 * @param {!Object} destinationInfo Object describing an extension printer. 76 * @param {!Object} destinationInfo Object describing an extension printer.
77 * @return {!print_preview.Destination} Parsed destination. 77 * @return {!print_preview.Destination} Parsed destination.
78 */ 78 */
79 ExtensionDestinationParser.parse = function(destinationInfo) { 79 ExtensionDestinationParser.parse = function(destinationInfo) {
80 var provisionalType = 80 var provisionalType =
81 destinationInfo.provisional ? 81 destinationInfo.provisional ?
82 print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION : 82 print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION :
83 print_preview.Destination.ProvisionalType.NONE; 83 print_preview.DestinationProvisionalType.NONE;
84 84
85 return new print_preview.Destination( 85 return new print_preview.Destination(
86 destinationInfo.id, 86 destinationInfo.id,
87 print_preview.Destination.Type.LOCAL, 87 print_preview.DestinationType.LOCAL,
88 print_preview.Destination.Origin.EXTENSION, 88 print_preview.DestinationOrigin.EXTENSION,
89 destinationInfo.name, 89 destinationInfo.name,
90 false /* isRecent */, 90 false /* isRecent */,
91 print_preview.Destination.ConnectionStatus.ONLINE, 91 print_preview.DestinationConnectionStatus.ONLINE,
92 {description: destinationInfo.description || '', 92 {description: destinationInfo.description || '',
93 extensionId: destinationInfo.extensionId, 93 extensionId: destinationInfo.extensionId,
94 extensionName: destinationInfo.extensionName || '', 94 extensionName: destinationInfo.extensionName || '',
95 provisionalType: provisionalType}); 95 provisionalType: provisionalType});
96 }; 96 };
97 97
98 // Export 98 // Export
99 return { 99 return {
100 LocalDestinationParser: LocalDestinationParser, 100 LocalDestinationParser: LocalDestinationParser,
101 PrivetDestinationParser: PrivetDestinationParser, 101 PrivetDestinationParser: PrivetDestinationParser,
102 ExtensionDestinationParser: ExtensionDestinationParser 102 ExtensionDestinationParser: ExtensionDestinationParser
103 }; 103 };
104 }); 104 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698