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

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

Issue 587013003: Add Print Preview UI to accept and reject printer sharing invitations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if (typeStr == CloudDestinationParser.CloudType_.ANDROID || 112 if (typeStr == CloudDestinationParser.CloudType_.ANDROID ||
113 typeStr == CloudDestinationParser.CloudType_.IOS) { 113 typeStr == CloudDestinationParser.CloudType_.IOS) {
114 return print_preview.Destination.Type.MOBILE; 114 return print_preview.Destination.Type.MOBILE;
115 } else if (typeStr == CloudDestinationParser.CloudType_.DOCS) { 115 } else if (typeStr == CloudDestinationParser.CloudType_.DOCS) {
116 return print_preview.Destination.Type.GOOGLE_PROMOTED; 116 return print_preview.Destination.Type.GOOGLE_PROMOTED;
117 } else { 117 } else {
118 return print_preview.Destination.Type.GOOGLE; 118 return print_preview.Destination.Type.GOOGLE;
119 } 119 }
120 }; 120 };
121 121
122 /** Namespace which contains a method to parse printer sharing invitation. */
123 function InvitationParser() {};
124
125 /**
126 * Enumeration of invitation field names.
127 * @enum {string}
128 * @private
129 */
130 InvitationParser.Field_ = {
131 PRINTER: 'printer',
132 RECEIVER: 'receiver',
133 SENDER: 'sender'
134 };
135
136 /**
137 * Enumeration of cloud destination types that are supported by print preview.
138 * @enum {string}
139 * @private
140 */
141 InvitationParser.AclType_ = {
142 DOMAIN: 'DOMAIN',
143 GROUP: 'GROUP',
144 PUBLIC: 'PUBLIC',
145 USER: 'USER'
146 };
147
148 /**
149 * Parses printer sharing invitation from JSON from GCP invite API response.
150 * @param {!Object} json Object that represents a invitation search response.
151 * @param {string} account The account this invitation is sent for.
152 * @return {!print_preview.Invitation} Parsed invitation.
153 */
154 InvitationParser.parse = function(json, account) {
155 if (!json.hasOwnProperty(InvitationParser.Field_.SENDER) ||
156 !json.hasOwnProperty(InvitationParser.Field_.RECEIVER) ||
157 !json.hasOwnProperty(InvitationParser.Field_.PRINTER)) {
158 throw Error('Invitation does not have necessary info.');
159 }
160
161 var nameFormatter = function(name, scope) {
162 return name && scope ? (name + ' (' + scope + ')') : (name || scope);
163 };
164
165 var sender = json[InvitationParser.Field_.SENDER];
166 var senderName = nameFormatter(sender['name'], sender['email']);
167
168 var receiver = json[InvitationParser.Field_.RECEIVER];
169 var receiverName = '';
170 var receiverType = receiver['type'];
171 if (receiverType == InvitationParser.AclType_.USER) {
172 // It's a personal invitation, empty name indicates just that.
173 } else if (receiverType == InvitationParser.AclType_.GROUP ||
174 receiverType == InvitationParser.AclType_.DOMAIN) {
175 receiverName = nameFormatter(receiver['name'], receiver['scope']);
176 } else {
177 throw Error('Invitation of unsupported receiver type');
178 }
179
180 var destination = cloudprint.CloudDestinationParser.parse(
181 json[InvitationParser.Field_.PRINTER],
182 print_preview.Destination.Origin.COOKIES,
183 account);
184
185 return new print_preview.Invitation(
186 senderName, receiverName, destination, receiver, account);
187 };
188
122 // Export 189 // Export
123 return { 190 return {
124 CloudDestinationParser: CloudDestinationParser 191 CloudDestinationParser: CloudDestinationParser,
192 InvitationParser: InvitationParser
125 }; 193 };
126 }); 194 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698