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

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

Issue 2617663002: WIP: run clang-format-js on lots of things (Closed)
Patch Set: merge Created 3 years, 11 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 var id = json[CloudDestinationParser.Field_.ID]; 72 var id = json[CloudDestinationParser.Field_.ID];
73 var tags = json[CloudDestinationParser.Field_.TAGS] || []; 73 var tags = json[CloudDestinationParser.Field_.TAGS] || [];
74 var connectionStatus = 74 var connectionStatus =
75 json[CloudDestinationParser.Field_.CONNECTION_STATUS] || 75 json[CloudDestinationParser.Field_.CONNECTION_STATUS] ||
76 print_preview.Destination.ConnectionStatus.UNKNOWN; 76 print_preview.Destination.ConnectionStatus.UNKNOWN;
77 var optionalParams = { 77 var optionalParams = {
78 account: account, 78 account: account,
79 tags: tags, 79 tags: tags,
80 isOwned: arrayContains(tags, CloudDestinationParser.OWNED_TAG_), 80 isOwned: arrayContains(tags, CloudDestinationParser.OWNED_TAG_),
81 lastAccessTime: parseInt( 81 lastAccessTime:
82 json[CloudDestinationParser.Field_.LAST_ACCESS], 10) || Date.now(), 82 parseInt(json[CloudDestinationParser.Field_.LAST_ACCESS], 10) ||
83 Date.now(),
83 isTosAccepted: (id == print_preview.Destination.GooglePromotedId.FEDEX) ? 84 isTosAccepted: (id == print_preview.Destination.GooglePromotedId.FEDEX) ?
84 json[CloudDestinationParser.Field_.IS_TOS_ACCEPTED] : null, 85 json[CloudDestinationParser.Field_.IS_TOS_ACCEPTED] :
86 null,
85 cloudID: id, 87 cloudID: id,
86 description: json[CloudDestinationParser.Field_.DESCRIPTION] 88 description: json[CloudDestinationParser.Field_.DESCRIPTION]
87 }; 89 };
88 var cloudDest = new print_preview.Destination( 90 var cloudDest = new print_preview.Destination(
89 id, 91 id, CloudDestinationParser.parseType_(
90 CloudDestinationParser.parseType_( 92 json[CloudDestinationParser.Field_.TYPE]),
91 json[CloudDestinationParser.Field_.TYPE]), 93 origin, json[CloudDestinationParser.Field_.DISPLAY_NAME],
92 origin,
93 json[CloudDestinationParser.Field_.DISPLAY_NAME],
94 arrayContains(tags, CloudDestinationParser.RECENT_TAG_) /*isRecent*/, 94 arrayContains(tags, CloudDestinationParser.RECENT_TAG_) /*isRecent*/,
95 connectionStatus, 95 connectionStatus, optionalParams);
96 optionalParams);
97 if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES)) { 96 if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES)) {
98 cloudDest.capabilities = /** @type {!print_preview.Cdd} */( 97 cloudDest.capabilities = /** @type {!print_preview.Cdd} */ (
99 json[CloudDestinationParser.Field_.CAPABILITIES]); 98 json[CloudDestinationParser.Field_.CAPABILITIES]);
100 } 99 }
101 return cloudDest; 100 return cloudDest;
102 }; 101 };
103 102
104 /** 103 /**
105 * Parses the destination type. 104 * Parses the destination type.
106 * @param {string} typeStr Destination type given by the Google Cloud Print 105 * @param {string} typeStr Destination type given by the Google Cloud Print
107 * server. 106 * server.
108 * @return {!print_preview.Destination.Type} Destination type. 107 * @return {!print_preview.Destination.Type} Destination type.
109 * @private 108 * @private
110 */ 109 */
111 CloudDestinationParser.parseType_ = function(typeStr) { 110 CloudDestinationParser.parseType_ = function(typeStr) {
112 if (typeStr == CloudDestinationParser.CloudType_.ANDROID || 111 if (typeStr == CloudDestinationParser.CloudType_.ANDROID ||
113 typeStr == CloudDestinationParser.CloudType_.IOS) { 112 typeStr == CloudDestinationParser.CloudType_.IOS) {
114 return print_preview.Destination.Type.MOBILE; 113 return print_preview.Destination.Type.MOBILE;
115 } else if (typeStr == CloudDestinationParser.CloudType_.DOCS) { 114 } else if (typeStr == CloudDestinationParser.CloudType_.DOCS) {
116 return print_preview.Destination.Type.GOOGLE_PROMOTED; 115 return print_preview.Destination.Type.GOOGLE_PROMOTED;
117 } else { 116 } else {
118 return print_preview.Destination.Type.GOOGLE; 117 return print_preview.Destination.Type.GOOGLE;
119 } 118 }
120 }; 119 };
121 120
122 /** Namespace which contains a method to parse printer sharing invitation. */ 121 /** Namespace which contains a method to parse printer sharing invitation. */
123 function InvitationParser() {}; 122 function InvitationParser(){};
124 123
125 /** 124 /**
126 * Enumeration of invitation field names. 125 * Enumeration of invitation field names.
127 * @enum {string} 126 * @enum {string}
128 * @private 127 * @private
129 */ 128 */
130 InvitationParser.Field_ = { 129 InvitationParser.Field_ = {
131 PRINTER: 'printer', 130 PRINTER: 'printer',
132 RECEIVER: 'receiver', 131 RECEIVER: 'receiver',
133 SENDER: 'sender' 132 SENDER: 'sender'
134 }; 133 };
135 134
136 /** 135 /**
137 * Enumeration of cloud destination types that are supported by print preview. 136 * Enumeration of cloud destination types that are supported by print preview.
138 * @enum {string} 137 * @enum {string}
139 * @private 138 * @private
140 */ 139 */
141 InvitationParser.AclType_ = { 140 InvitationParser.AclType_ =
142 DOMAIN: 'DOMAIN', 141 {DOMAIN: 'DOMAIN', GROUP: 'GROUP', PUBLIC: 'PUBLIC', USER: 'USER'};
143 GROUP: 'GROUP',
144 PUBLIC: 'PUBLIC',
145 USER: 'USER'
146 };
147 142
148 /** 143 /**
149 * Parses printer sharing invitation from JSON from GCP invite API response. 144 * Parses printer sharing invitation from JSON from GCP invite API response.
150 * @param {!Object} json Object that represents a invitation search response. 145 * @param {!Object} json Object that represents a invitation search response.
151 * @param {string} account The account this invitation is sent for. 146 * @param {string} account The account this invitation is sent for.
152 * @return {!print_preview.Invitation} Parsed invitation. 147 * @return {!print_preview.Invitation} Parsed invitation.
153 */ 148 */
154 InvitationParser.parse = function(json, account) { 149 InvitationParser.parse = function(json, account) {
155 if (!json.hasOwnProperty(InvitationParser.Field_.SENDER) || 150 if (!json.hasOwnProperty(InvitationParser.Field_.SENDER) ||
156 !json.hasOwnProperty(InvitationParser.Field_.RECEIVER) || 151 !json.hasOwnProperty(InvitationParser.Field_.RECEIVER) ||
157 !json.hasOwnProperty(InvitationParser.Field_.PRINTER)) { 152 !json.hasOwnProperty(InvitationParser.Field_.PRINTER)) {
158 throw Error('Invitation does not have necessary info.'); 153 throw Error('Invitation does not have necessary info.');
159 } 154 }
160 155
161 var nameFormatter = function(name, scope) { 156 var nameFormatter = function(name, scope) {
162 return name && scope ? (name + ' (' + scope + ')') : (name || scope); 157 return name && scope ? (name + ' (' + scope + ')') : (name || scope);
163 }; 158 };
164 159
165 var sender = json[InvitationParser.Field_.SENDER]; 160 var sender = json[InvitationParser.Field_.SENDER];
166 var senderName = nameFormatter(sender['name'], sender['email']); 161 var senderName = nameFormatter(sender['name'], sender['email']);
167 162
168 var receiver = json[InvitationParser.Field_.RECEIVER]; 163 var receiver = json[InvitationParser.Field_.RECEIVER];
169 var receiverName = ''; 164 var receiverName = '';
170 var receiverType = receiver['type']; 165 var receiverType = receiver['type'];
171 if (receiverType == InvitationParser.AclType_.USER) { 166 if (receiverType == InvitationParser.AclType_.USER) {
172 // It's a personal invitation, empty name indicates just that. 167 // It's a personal invitation, empty name indicates just that.
173 } else if (receiverType == InvitationParser.AclType_.GROUP || 168 } else if (
174 receiverType == InvitationParser.AclType_.DOMAIN) { 169 receiverType == InvitationParser.AclType_.GROUP ||
170 receiverType == InvitationParser.AclType_.DOMAIN) {
175 receiverName = nameFormatter(receiver['name'], receiver['scope']); 171 receiverName = nameFormatter(receiver['name'], receiver['scope']);
176 } else { 172 } else {
177 throw Error('Invitation of unsupported receiver type'); 173 throw Error('Invitation of unsupported receiver type');
178 } 174 }
179 175
180 var destination = cloudprint.CloudDestinationParser.parse( 176 var destination = cloudprint.CloudDestinationParser.parse(
181 json[InvitationParser.Field_.PRINTER], 177 json[InvitationParser.Field_.PRINTER],
182 print_preview.Destination.Origin.COOKIES, 178 print_preview.Destination.Origin.COOKIES, account);
183 account);
184 179
185 return new print_preview.Invitation( 180 return new print_preview.Invitation(
186 senderName, receiverName, destination, receiver, account); 181 senderName, receiverName, destination, receiver, account);
187 }; 182 };
188 183
189 // Export 184 // Export
190 return { 185 return {
191 CloudDestinationParser: CloudDestinationParser, 186 CloudDestinationParser: CloudDestinationParser,
192 InvitationParser: InvitationParser 187 InvitationParser: InvitationParser
193 }; 188 };
194 }); 189 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698