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

Side by Side Diff: chrome/browser/resources/print_preview/data/cloud_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('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 CONNECTION_STATUS: 'connectionStatus', 18 CONNECTION_STATUS: 'connectionStatus',
19 DESCRIPTION: 'description', 19 DESCRIPTION: 'description',
(...skipping 29 matching lines...) Expand all
49 ANDROID: 'ANDROID_CHROME_SNAPSHOT', 49 ANDROID: 'ANDROID_CHROME_SNAPSHOT',
50 DOCS: 'DOCS', 50 DOCS: 'DOCS',
51 IOS: 'IOS_CHROME_SNAPSHOT' 51 IOS: 'IOS_CHROME_SNAPSHOT'
52 }; 52 };
53 53
54 /** 54 /**
55 * Parses a destination from JSON from a Google Cloud Print search or printer 55 * Parses a destination from JSON from a Google Cloud Print search or printer
56 * response. 56 * response.
57 * @param {!Object} json Object that represents a Google Cloud Print search or 57 * @param {!Object} json Object that represents a Google Cloud Print search or
58 * printer response. 58 * printer response.
59 * @param {!print_preview.Destination.Origin} origin The origin of the 59 * @param {!print_preview.DestinationOrigin} origin The origin of the
60 * response. 60 * response.
61 * @param {string} account The account this destination is registered for or 61 * @param {string} account The account this destination is registered for or
62 * empty string, if origin != COOKIES. 62 * empty string, if origin != COOKIES.
63 * @return {!print_preview.Destination} Parsed destination. 63 * @return {!print_preview.Destination} Parsed destination.
64 */ 64 */
65 CloudDestinationParser.parse = function(json, origin, account) { 65 CloudDestinationParser.parse = function(json, origin, account) {
66 if (!json.hasOwnProperty(CloudDestinationParser.Field_.ID) || 66 if (!json.hasOwnProperty(CloudDestinationParser.Field_.ID) ||
67 !json.hasOwnProperty(CloudDestinationParser.Field_.TYPE) || 67 !json.hasOwnProperty(CloudDestinationParser.Field_.TYPE) ||
68 !json.hasOwnProperty(CloudDestinationParser.Field_.DISPLAY_NAME)) { 68 !json.hasOwnProperty(CloudDestinationParser.Field_.DISPLAY_NAME)) {
69 throw Error('Cloud destination does not have an ID or a display name'); 69 throw Error('Cloud destination does not have an ID or a display name');
70 } 70 }
71 var id = json[CloudDestinationParser.Field_.ID]; 71 var id = json[CloudDestinationParser.Field_.ID];
72 var tags = json[CloudDestinationParser.Field_.TAGS] || []; 72 var tags = json[CloudDestinationParser.Field_.TAGS] || [];
73 var connectionStatus = 73 var connectionStatus =
74 json[CloudDestinationParser.Field_.CONNECTION_STATUS] || 74 json[CloudDestinationParser.Field_.CONNECTION_STATUS] ||
75 print_preview.Destination.ConnectionStatus.UNKNOWN; 75 print_preview.DestinationConnectionStatus.UNKNOWN;
76 var optionalParams = { 76 var optionalParams = {
77 account: account, 77 account: account,
78 tags: tags, 78 tags: tags,
79 isOwned: arrayContains(tags, CloudDestinationParser.OWNED_TAG_), 79 isOwned: arrayContains(tags, CloudDestinationParser.OWNED_TAG_),
80 lastAccessTime: parseInt( 80 lastAccessTime: parseInt(
81 json[CloudDestinationParser.Field_.LAST_ACCESS], 10) || Date.now(), 81 json[CloudDestinationParser.Field_.LAST_ACCESS], 10) || Date.now(),
82 cloudID: id, 82 cloudID: id,
83 description: json[CloudDestinationParser.Field_.DESCRIPTION] 83 description: json[CloudDestinationParser.Field_.DESCRIPTION]
84 }; 84 };
85 var cloudDest = new print_preview.Destination( 85 var cloudDest = new print_preview.Destination(
86 id, 86 id,
87 CloudDestinationParser.parseType_( 87 CloudDestinationParser.parseType_(
88 json[CloudDestinationParser.Field_.TYPE]), 88 json[CloudDestinationParser.Field_.TYPE]),
89 origin, 89 origin,
90 json[CloudDestinationParser.Field_.DISPLAY_NAME], 90 json[CloudDestinationParser.Field_.DISPLAY_NAME],
91 arrayContains(tags, CloudDestinationParser.RECENT_TAG_) /*isRecent*/, 91 arrayContains(tags, CloudDestinationParser.RECENT_TAG_) /*isRecent*/,
92 connectionStatus, 92 connectionStatus,
93 optionalParams); 93 optionalParams);
94 if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES)) { 94 if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES)) {
95 cloudDest.capabilities = /** @type {!print_preview.Cdd} */( 95 cloudDest.capabilities = /** @type {!print_preview.Cdd} */(
96 json[CloudDestinationParser.Field_.CAPABILITIES]); 96 json[CloudDestinationParser.Field_.CAPABILITIES]);
97 } 97 }
98 return cloudDest; 98 return cloudDest;
99 }; 99 };
100 100
101 /** 101 /**
102 * Parses the destination type. 102 * Parses the destination type.
103 * @param {string} typeStr Destination type given by the Google Cloud Print 103 * @param {string} typeStr Destination type given by the Google Cloud Print
104 * server. 104 * server.
105 * @return {!print_preview.Destination.Type} Destination type. 105 * @return {!print_preview.DestinationType} Destination type.
106 * @private 106 * @private
107 */ 107 */
108 CloudDestinationParser.parseType_ = function(typeStr) { 108 CloudDestinationParser.parseType_ = function(typeStr) {
109 if (typeStr == CloudDestinationParser.CloudType_.ANDROID || 109 if (typeStr == CloudDestinationParser.CloudType_.ANDROID ||
110 typeStr == CloudDestinationParser.CloudType_.IOS) { 110 typeStr == CloudDestinationParser.CloudType_.IOS) {
111 return print_preview.Destination.Type.MOBILE; 111 return print_preview.DestinationType.MOBILE;
112 } else if (typeStr == CloudDestinationParser.CloudType_.DOCS) { 112 } else if (typeStr == CloudDestinationParser.CloudType_.DOCS) {
113 return print_preview.Destination.Type.GOOGLE_PROMOTED; 113 return print_preview.DestinationType.GOOGLE_PROMOTED;
114 } else { 114 } else {
115 return print_preview.Destination.Type.GOOGLE; 115 return print_preview.DestinationType.GOOGLE;
116 } 116 }
117 }; 117 };
118 118
119 /** Namespace which contains a method to parse printer sharing invitation. */ 119 /** Namespace which contains a method to parse printer sharing invitation. */
120 function InvitationParser() {}; 120 function InvitationParser() {}
121 121
122 /** 122 /**
123 * Enumeration of invitation field names. 123 * Enumeration of invitation field names.
124 * @enum {string} 124 * @enum {string}
125 * @private 125 * @private
126 */ 126 */
127 InvitationParser.Field_ = { 127 InvitationParser.Field_ = {
128 PRINTER: 'printer', 128 PRINTER: 'printer',
129 RECEIVER: 'receiver', 129 RECEIVER: 'receiver',
130 SENDER: 'sender' 130 SENDER: 'sender'
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // It's a personal invitation, empty name indicates just that. 169 // It's a personal invitation, empty name indicates just that.
170 } else if (receiverType == InvitationParser.AclType_.GROUP || 170 } else if (receiverType == InvitationParser.AclType_.GROUP ||
171 receiverType == InvitationParser.AclType_.DOMAIN) { 171 receiverType == InvitationParser.AclType_.DOMAIN) {
172 receiverName = nameFormatter(receiver['name'], receiver['scope']); 172 receiverName = nameFormatter(receiver['name'], receiver['scope']);
173 } else { 173 } else {
174 throw Error('Invitation of unsupported receiver type'); 174 throw Error('Invitation of unsupported receiver type');
175 } 175 }
176 176
177 var destination = cloudprint.CloudDestinationParser.parse( 177 var destination = cloudprint.CloudDestinationParser.parse(
178 json[InvitationParser.Field_.PRINTER], 178 json[InvitationParser.Field_.PRINTER],
179 print_preview.Destination.Origin.COOKIES, 179 print_preview.DestinationOrigin.COOKIES,
180 account); 180 account);
181 181
182 return new print_preview.Invitation( 182 return new print_preview.Invitation(
183 senderName, receiverName, destination, receiver, account); 183 senderName, receiverName, destination, receiver, account);
184 }; 184 };
185 185
186 // Export 186 // Export
187 return { 187 return {
188 CloudDestinationParser: CloudDestinationParser, 188 CloudDestinationParser: CloudDestinationParser,
189 InvitationParser: InvitationParser 189 InvitationParser: InvitationParser
190 }; 190 };
191 }); 191 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698