Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / data / local_parsers.js
blobf6b4c734958bcf4dc26f824270ccf1bbd039cb46
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() {
6   'use strict';
8   /** Namespace that contains a method to parse local print destinations. */
9   function LocalDestinationParser() {};
11   /**
12    * Parses a local print destination.
13    * @param {!Object} destinationInfo Information describing a local print
14    *     destination.
15    * @return {!print_preview.Destination} Parsed local print destination.
16    */
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);
24     }
25     return new print_preview.Destination(
26         destinationInfo.deviceName,
27         print_preview.Destination.Type.LOCAL,
28         print_preview.Destination.Origin.LOCAL,
29         destinationInfo.printerName,
30         false /*isRecent*/,
31         print_preview.Destination.ConnectionStatus.ONLINE,
32         options);
33   };
35   function PrivetDestinationParser() {}
37   /**
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.
41    */
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,
50            destinationInfo.name,
51            false /*isRecent*/,
52            print_preview.Destination.ConnectionStatus.ONLINE,
53            { cloudID: destinationInfo.cloudID }));
54     }
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,
61           destinationInfo.name,
62           false /*isRecent*/,
63           print_preview.Destination.ConnectionStatus.UNREGISTERED));
64     }
66     return returnedPrinters;
67   };
69   function ExtensionDestinationParser() {}
71   /**
72    * Parses an extension destination from an extension supplied printer
73    * description.
74    * @param {!Object} destinationInfo Object describing an extension printer.
75    * @return {!print_preview.Destination} Parsed destination.
76    */
77   ExtensionDestinationParser.parse = function(destinationInfo) {
78     var provisionalType =
79         destinationInfo.provisional ?
80             print_preview.Destination.ProvisionalType.NEEDS_USB_PERMISSION :
81             print_preview.Destination.ProvisionalType.NONE;
83     return new print_preview.Destination(
84         destinationInfo.id,
85         print_preview.Destination.Type.LOCAL,
86         print_preview.Destination.Origin.EXTENSION,
87         destinationInfo.name,
88         false /* isRecent */,
89         print_preview.Destination.ConnectionStatus.ONLINE,
90         {description: destinationInfo.description || '',
91          extensionId: destinationInfo.extensionId,
92          extensionName: destinationInfo.extensionName || '',
93          provisionalType: provisionalType});
94   };
96   // Export
97   return {
98     LocalDestinationParser: LocalDestinationParser,
99     PrivetDestinationParser: PrivetDestinationParser,
100     ExtensionDestinationParser: ExtensionDestinationParser
101   };