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

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

Issue 10450022: Print Preview Print Destination Search Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reduces size of search image. Created 8 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('cloudprint', function() { 5 cr.define('cloudprint', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** Namespace which contains a method to parse cloud destinations directly. */ 8 /** Namespace which contains a method to parse cloud destinations directly. */
9 function CloudDestinationParser() {}; 9 function CloudDestinationParser() {};
10 10
11 /** 11 /**
12 * Enumeration of cloud destination field names. 12 * Enumeration of cloud destination field names.
13 * @enum {string} 13 * @enum {string}
14 * @private 14 * @private
15 */ 15 */
16 CloudDestinationParser.Field_ = { 16 CloudDestinationParser.Field_ = {
17 CAPABILITIES: 'capabilities', 17 CAPABILITIES: 'capabilities',
18 DISPLAY_NAME: 'displayName', 18 DISPLAY_NAME: 'displayName',
19 FORMAT: 'capsFormat', 19 FORMAT: 'capsFormat',
20 ID: 'id', 20 ID: 'id',
21 TAGS: 'tags' 21 TAGS: 'tags',
22 TYPE: 'type'
22 }; 23 };
23 24
24 /** 25 /**
25 * Special tag that denotes whether the destination has been recently used. 26 * Special tag that denotes whether the destination has been recently used.
26 * @type {string} 27 * @type {string}
28 * @const
27 * @private 29 * @private
28 */ 30 */
29 CloudDestinationParser.RECENT_TAG_ = '^recent'; 31 CloudDestinationParser.RECENT_TAG_ = '^recent';
30 32
31 /** 33 /**
34 * Special tag that denotes whether the destination is owned by the user.
35 * @type {string}
36 * @const
37 * @private
38 */
39 CloudDestinationParser.OWNED_TAG_ = '^own';
40
41 /**
32 * Parses a destination from JSON from a Google Cloud Print search or printer 42 * Parses a destination from JSON from a Google Cloud Print search or printer
33 * response. 43 * response.
34 * @param {object} json Object that represents a Google Cloud Print search or 44 * @param {object} json Object that represents a Google Cloud Print search or
dpapad 2012/05/25 16:18:03 Nit: Should this be !Object?
Robert Toscano 2012/05/25 19:47:01 Done.
35 * printer response. 45 * printer response.
36 * @return {!print_preview.Destination} Parsed destination. 46 * @return {!print_preview.Destination} Parsed destination.
37 */ 47 */
38 CloudDestinationParser.parse = function(json) { 48 CloudDestinationParser.parse = function(json) {
39 if (!json.hasOwnProperty(CloudDestinationParser.Field_.ID) || 49 if (!json.hasOwnProperty(CloudDestinationParser.Field_.ID) ||
50 !json.hasOwnProperty(CloudDestinationParser.Field_.TYPE) ||
40 !json.hasOwnProperty(CloudDestinationParser.Field_.DISPLAY_NAME)) { 51 !json.hasOwnProperty(CloudDestinationParser.Field_.DISPLAY_NAME)) {
41 throw Error('Cloud destination does not have an ID or a display name'); 52 throw Error('Cloud destination does not have an ID or a display name');
42 } 53 }
43 var isRecent = arrayContains( 54 var tags = json[CloudDestinationParser.Field_.TAGS] || [];
44 json[CloudDestinationParser.Field_.TAGS] || [], 55 var isRecent = arrayContains(tags, CloudDestinationParser.RECENT_TAG_);
45 CloudDestinationParser.RECENT_TAG_); 56 var isOwned = arrayContains(tags, CloudDestinationParser.OWNED_TAG_);
46 var cloudDest = new print_preview.Destination( 57 var cloudDest = new print_preview.Destination(
47 json[CloudDestinationParser.Field_.ID], 58 json[CloudDestinationParser.Field_.ID],
59 CloudDestinationParser.parseType_(
60 json[CloudDestinationParser.Field_.TYPE]),
48 json[CloudDestinationParser.Field_.DISPLAY_NAME], 61 json[CloudDestinationParser.Field_.DISPLAY_NAME],
49 isRecent, 62 isRecent,
50 false /*isLocal*/, 63 tags,
51 json[CloudDestinationParser.Field_.TAGS] || []); 64 isOwned);
52 if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES) && 65 if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES) &&
53 json.hasOwnProperty(CloudDestinationParser.Field_.FORMAT)) { 66 json.hasOwnProperty(CloudDestinationParser.Field_.FORMAT)) {
54 cloudDest.capabilities = CloudCapabilitiesParser.parse( 67 cloudDest.capabilities = CloudCapabilitiesParser.parse(
55 json[CloudDestinationParser.Field_.FORMAT], 68 json[CloudDestinationParser.Field_.FORMAT],
56 json[CloudDestinationParser.Field_.CAPABILITIES]); 69 json[CloudDestinationParser.Field_.CAPABILITIES]);
57 } 70 }
58 return cloudDest; 71 return cloudDest;
59 }; 72 };
60 73
61 /** 74 /**
75 * Parses the destination type.
76 * @param {string} typeStr Destination type given by the Google Cloud Print
77 * server.
78 * @return {print_preview.Destination.Type} Destination type.
79 * @private
80 */
81 CloudDestinationParser.parseType_ = function(typeStr) {
82 if (typeStr == 'ANDROID_CHROME_SNAPSHOT' ||
dpapad 2012/05/25 16:18:03 Nit: Maybe define an enum somewhere instead of usi
Robert Toscano 2012/05/25 19:47:01 Done.
83 typeStr == 'IOS_CHROME_SNAPSHOT') {
84 return print_preview.Destination.Type.MOBILE;
85 } else if (typeStr == 'DOCS') {
86 return print_preview.Destination.Type.GOOGLE_PROMOTED;
87 } else {
88 return print_preview.Destination.Type.GOOGLE;
89 }
90 };
91
92 /**
62 * Namespace which contains a method to parse a cloud destination's print 93 * Namespace which contains a method to parse a cloud destination's print
63 * capabilities. 94 * capabilities.
64 */ 95 */
65 function CloudCapabilitiesParser() {}; 96 function CloudCapabilitiesParser() {};
66 97
67 /** 98 /**
68 * Enumeration of cloud destination print capabilities field names. 99 * Enumeration of cloud destination print capabilities field names.
69 * @enum {string} 100 * @enum {string}
70 * @private 101 * @private
71 */ 102 */
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 capId, simplexOption, longEdgeOption, isDuplexDefault); 229 capId, simplexOption, longEdgeOption, isDuplexDefault);
199 }; 230 };
200 231
201 // Export 232 // Export
202 return { 233 return {
203 CloudCapabilitiesParser: CloudCapabilitiesParser, 234 CloudCapabilitiesParser: CloudCapabilitiesParser,
204 CloudDestinationParser: CloudDestinationParser 235 CloudDestinationParser: CloudDestinationParser
205 }; 236 };
206 }); 237 });
207 238
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698