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

Side by Side Diff: chrome/browser/resources/print_preview/cloud_print_interface.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 /** 8 /**
9 * API to the Google Cloud Print service. 9 * API to the Google Cloud Print service.
10 * @param {string} baseUrl Base part of the Google Cloud Print service URL 10 * @param {string} baseUrl Base part of the Google Cloud Print service URL
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 * @const 144 * @const
145 * @private 145 * @private
146 */ 146 */
147 CloudPrintInterface.VERSION_REGEXP_ = /.*Chrome\/([\d\.]+)/i; 147 CloudPrintInterface.VERSION_REGEXP_ = /.*Chrome\/([\d\.]+)/i;
148 148
149 /** 149 /**
150 * Enumeration of JSON response fields from Google Cloud Print API. 150 * Enumeration of JSON response fields from Google Cloud Print API.
151 * @enum {string} 151 * @enum {string}
152 * @private 152 * @private
153 */ 153 */
154 CloudPrintInterface.JsonFields_ = { 154 CloudPrintInterface.JsonFields_ = {PRINTER: 'printer'};
155 PRINTER: 'printer'
156 };
157 155
158 /** 156 /**
159 * Could Print origins used to search printers. 157 * Could Print origins used to search printers.
160 * @type {!Array<!print_preview.Destination.Origin>} 158 * @type {!Array<!print_preview.Destination.Origin>}
161 * @const 159 * @const
162 * @private 160 * @private
163 */ 161 */
164 CloudPrintInterface.CLOUD_ORIGINS_ = [ 162 CloudPrintInterface.CLOUD_ORIGINS_ = [
165 print_preview.Destination.Origin.COOKIES, 163 print_preview.Destination.Origin.COOKIES,
166 print_preview.Destination.Origin.DEVICE 164 print_preview.Destination.Origin.DEVICE
167 // TODO(vitalybuka): Enable when implemented. 165 // TODO(vitalybuka): Enable when implemented.
168 // ready print_preview.Destination.Origin.PROFILE 166 // ready print_preview.Destination.Origin.PROFILE
169 ]; 167 ];
170 168
171 CloudPrintInterface.prototype = { 169 CloudPrintInterface.prototype = {
172 __proto__: cr.EventTarget.prototype, 170 __proto__: cr.EventTarget.prototype,
173 171
174 /** @return {string} Base URL of the Google Cloud Print service. */ 172 /** @return {string} Base URL of the Google Cloud Print service. */
175 get baseUrl() { 173 get baseUrl() {
176 return this.baseUrl_; 174 return this.baseUrl_;
177 }, 175 },
178 176
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 * @param {string} account Account the search is sent for. It matters for 210 * @param {string} account Account the search is sent for. It matters for
213 * COOKIES origin only, and can be empty (sent on behalf of the primary 211 * COOKIES origin only, and can be empty (sent on behalf of the primary
214 * user in this case). 212 * user in this case).
215 * @param {!Array<!print_preview.Destination.Origin>} origins Origins to 213 * @param {!Array<!print_preview.Destination.Origin>} origins Origins to
216 * search printers for. 214 * search printers for.
217 * @private 215 * @private
218 */ 216 */
219 search_: function(isRecent, account, origins) { 217 search_: function(isRecent, account, origins) {
220 var params = [ 218 var params = [
221 new HttpParam('connection_status', 'ALL'), 219 new HttpParam('connection_status', 'ALL'),
222 new HttpParam('client', 'chrome'), 220 new HttpParam('client', 'chrome'), new HttpParam('use_cdd', 'true')
223 new HttpParam('use_cdd', 'true')
224 ]; 221 ];
225 if (isRecent) { 222 if (isRecent) {
226 params.push(new HttpParam('q', '^recent')); 223 params.push(new HttpParam('q', '^recent'));
227 } 224 }
228 origins.forEach(function(origin) { 225 origins.forEach(function(origin) {
229 var cpRequest = this.buildRequest_( 226 var cpRequest = this.buildRequest_(
230 'GET', 227 'GET', 'search', params, origin, account,
231 'search',
232 params,
233 origin,
234 account,
235 this.onSearchDone_.bind(this, isRecent)); 228 this.onSearchDone_.bind(this, isRecent));
236 this.outstandingCloudSearchRequests_.push(cpRequest); 229 this.outstandingCloudSearchRequests_.push(cpRequest);
237 this.sendOrQueueRequest_(cpRequest); 230 this.sendOrQueueRequest_(cpRequest);
238 }, this); 231 }, this);
239 }, 232 },
240 233
241 /** 234 /**
242 * Sends Google Cloud Print printer sharing invitations API requests. 235 * Sends Google Cloud Print printer sharing invitations API requests.
243 * @param {string} account Account the request is sent for. 236 * @param {string} account Account the request is sent for.
244 */ 237 */
245 invites: function(account) { 238 invites: function(account) {
246 var params = [ 239 var params = [
247 new HttpParam('client', 'chrome'), 240 new HttpParam('client', 'chrome'),
248 ]; 241 ];
249 this.sendOrQueueRequest_(this.buildRequest_( 242 this.sendOrQueueRequest_(this.buildRequest_(
250 'GET', 243 'GET', 'invites', params, print_preview.Destination.Origin.COOKIES,
251 'invites', 244 account, this.onInvitesDone_.bind(this)));
252 params,
253 print_preview.Destination.Origin.COOKIES,
254 account,
255 this.onInvitesDone_.bind(this)));
256 }, 245 },
257 246
258 /** 247 /**
259 * Accepts or rejects printer sharing invitation. 248 * Accepts or rejects printer sharing invitation.
260 * @param {!print_preview.Invitation} invitation Invitation to process. 249 * @param {!print_preview.Invitation} invitation Invitation to process.
261 * @param {boolean} accept Whether to accept this invitation. 250 * @param {boolean} accept Whether to accept this invitation.
262 */ 251 */
263 processInvite: function(invitation, accept) { 252 processInvite: function(invitation, accept) {
264 var params = [ 253 var params = [
265 new HttpParam('printerid', invitation.destination.id), 254 new HttpParam('printerid', invitation.destination.id),
266 new HttpParam('email', invitation.scopeId), 255 new HttpParam('email', invitation.scopeId),
267 new HttpParam('accept', accept), 256 new HttpParam('accept', accept),
268 new HttpParam('use_cdd', true), 257 new HttpParam('use_cdd', true),
269 ]; 258 ];
270 this.sendOrQueueRequest_(this.buildRequest_( 259 this.sendOrQueueRequest_(this.buildRequest_(
271 'POST', 260 'POST', 'processinvite', params, invitation.destination.origin,
272 'processinvite',
273 params,
274 invitation.destination.origin,
275 invitation.destination.account, 261 invitation.destination.account,
276 this.onProcessInviteDone_.bind(this, invitation, accept))); 262 this.onProcessInviteDone_.bind(this, invitation, accept)));
277 }, 263 },
278 264
279 /** 265 /**
280 * Sends a Google Cloud Print submit API request. 266 * Sends a Google Cloud Print submit API request.
281 * @param {!print_preview.Destination} destination Cloud destination to 267 * @param {!print_preview.Destination} destination Cloud destination to
282 * print to. 268 * print to.
283 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the 269 * @param {!print_preview.PrintTicketStore} printTicketStore Contains the
284 * print ticket to print. 270 * print ticket to print.
285 * @param {!print_preview.DocumentInfo} documentInfo Document data model. 271 * @param {!print_preview.DocumentInfo} documentInfo Document data model.
286 * @param {string} data Base64 encoded data of the document. 272 * @param {string} data Base64 encoded data of the document.
287 */ 273 */
288 submit: function(destination, printTicketStore, documentInfo, data) { 274 submit: function(destination, printTicketStore, documentInfo, data) {
289 var result = 275 var result =
290 CloudPrintInterface.VERSION_REGEXP_.exec(navigator.userAgent); 276 CloudPrintInterface.VERSION_REGEXP_.exec(navigator.userAgent);
291 var chromeVersion = 'unknown'; 277 var chromeVersion = 'unknown';
292 if (result && result.length == 2) { 278 if (result && result.length == 2) {
293 chromeVersion = result[1]; 279 chromeVersion = result[1];
294 } 280 }
295 var params = [ 281 var params = [
296 new HttpParam('printerid', destination.id), 282 new HttpParam('printerid', destination.id),
297 new HttpParam('contentType', 'dataUrl'), 283 new HttpParam('contentType', 'dataUrl'),
298 new HttpParam('title', documentInfo.title), 284 new HttpParam('title', documentInfo.title),
299 new HttpParam('ticket', 285 new HttpParam(
300 printTicketStore.createPrintTicket(destination)), 286 'ticket', printTicketStore.createPrintTicket(destination)),
301 new HttpParam('content', 'data:application/pdf;base64,' + data), 287 new HttpParam('content', 'data:application/pdf;base64,' + data),
302 new HttpParam('tag', 288 new HttpParam('tag', '__google__chrome_version=' + chromeVersion),
303 '__google__chrome_version=' + chromeVersion),
304 new HttpParam('tag', '__google__os=' + navigator.platform) 289 new HttpParam('tag', '__google__os=' + navigator.platform)
305 ]; 290 ];
306 var cpRequest = this.buildRequest_( 291 var cpRequest = this.buildRequest_(
307 'POST', 292 'POST', 'submit', params, destination.origin, destination.account,
308 'submit',
309 params,
310 destination.origin,
311 destination.account,
312 this.onSubmitDone_.bind(this)); 293 this.onSubmitDone_.bind(this));
313 this.sendOrQueueRequest_(cpRequest); 294 this.sendOrQueueRequest_(cpRequest);
314 }, 295 },
315 296
316 /** 297 /**
317 * Sends a Google Cloud Print printer API request. 298 * Sends a Google Cloud Print printer API request.
318 * @param {string} printerId ID of the printer to lookup. 299 * @param {string} printerId ID of the printer to lookup.
319 * @param {!print_preview.Destination.Origin} origin Origin of the printer. 300 * @param {!print_preview.Destination.Origin} origin Origin of the printer.
320 * @param {string=} account Account this printer is registered for. When 301 * @param {string=} account Account this printer is registered for. When
321 * provided for COOKIES {@code origin}, and users sessions are still not 302 * provided for COOKIES {@code origin}, and users sessions are still not
322 * known, will be checked against the response (both success and failure 303 * known, will be checked against the response (both success and failure
323 * to get printer) and, if the active user account is not the one 304 * to get printer) and, if the active user account is not the one
324 * requested, {@code account} is activated and printer request reissued. 305 * requested, {@code account} is activated and printer request reissued.
325 */ 306 */
326 printer: function(printerId, origin, account) { 307 printer: function(printerId, origin, account) {
327 var params = [ 308 var params = [
328 new HttpParam('printerid', printerId), 309 new HttpParam('printerid', printerId), new HttpParam('use_cdd', 'true'),
329 new HttpParam('use_cdd', 'true'),
330 new HttpParam('printer_connection_status', 'true') 310 new HttpParam('printer_connection_status', 'true')
331 ]; 311 ];
332 this.sendOrQueueRequest_(this.buildRequest_( 312 this.sendOrQueueRequest_(this.buildRequest_(
333 'GET', 313 'GET', 'printer', params, origin, account,
334 'printer',
335 params,
336 origin,
337 account,
338 this.onPrinterDone_.bind(this, printerId))); 314 this.onPrinterDone_.bind(this, printerId)));
339 }, 315 },
340 316
341 /** 317 /**
342 * Sends a Google Cloud Print update API request to accept (or reject) the 318 * Sends a Google Cloud Print update API request to accept (or reject) the
343 * terms-of-service of the given printer. 319 * terms-of-service of the given printer.
344 * @param {!print_preview.Destination} destination Destination to accept ToS 320 * @param {!print_preview.Destination} destination Destination to accept ToS
345 * for. 321 * for.
346 * @param {boolean} isAccepted Whether the user accepted ToS or not. 322 * @param {boolean} isAccepted Whether the user accepted ToS or not.
347 */ 323 */
348 updatePrinterTosAcceptance: function(destination, isAccepted) { 324 updatePrinterTosAcceptance: function(destination, isAccepted) {
349 var params = [ 325 var params = [
350 new HttpParam('printerid', destination.id), 326 new HttpParam('printerid', destination.id),
351 new HttpParam('is_tos_accepted', isAccepted) 327 new HttpParam('is_tos_accepted', isAccepted)
352 ]; 328 ];
353 this.sendOrQueueRequest_(this.buildRequest_( 329 this.sendOrQueueRequest_(this.buildRequest_(
354 'POST', 330 'POST', 'update', params, destination.origin, destination.account,
355 'update',
356 params,
357 destination.origin,
358 destination.account,
359 this.onUpdatePrinterTosAcceptanceDone_.bind(this))); 331 this.onUpdatePrinterTosAcceptanceDone_.bind(this)));
360 }, 332 },
361 333
362 /** 334 /**
363 * Adds event listeners to relevant events. 335 * Adds event listeners to relevant events.
364 * @private 336 * @private
365 */ 337 */
366 addEventListeners_: function() { 338 addEventListeners_: function() {
367 this.tracker_.add( 339 this.tracker_.add(
368 this.nativeLayer_, 340 this.nativeLayer_,
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 */ 496 */
525 onAccessTokenReady_: function(event) { 497 onAccessTokenReady_: function(event) {
526 // TODO(vitalybuka): remove when other Origins implemented. 498 // TODO(vitalybuka): remove when other Origins implemented.
527 assert(event.authType == print_preview.Destination.Origin.DEVICE); 499 assert(event.authType == print_preview.Destination.Origin.DEVICE);
528 this.requestQueue_ = this.requestQueue_.filter(function(request) { 500 this.requestQueue_ = this.requestQueue_.filter(function(request) {
529 assert(request.origin == print_preview.Destination.Origin.DEVICE); 501 assert(request.origin == print_preview.Destination.Origin.DEVICE);
530 if (request.origin != event.authType) { 502 if (request.origin != event.authType) {
531 return true; 503 return true;
532 } 504 }
533 if (event.accessToken) { 505 if (event.accessToken) {
534 request.xhr.setRequestHeader('Authorization', 506 request.xhr.setRequestHeader(
535 'Bearer ' + event.accessToken); 507 'Authorization', 'Bearer ' + event.accessToken);
536 this.sendRequest_(request); 508 this.sendRequest_(request);
537 } else { // No valid token. 509 } else { // No valid token.
538 // Without abort status does not exist. 510 // Without abort status does not exist.
539 request.xhr.abort(); 511 request.xhr.abort();
540 request.callback(request); 512 request.callback(request);
541 } 513 }
542 return false; 514 return false;
543 }, this); 515 }, this);
544 }, 516 },
545 517
(...skipping 29 matching lines...) Expand all
575 var lastRequestForThisOrigin = true; 547 var lastRequestForThisOrigin = true;
576 this.outstandingCloudSearchRequests_ = 548 this.outstandingCloudSearchRequests_ =
577 this.outstandingCloudSearchRequests_.filter(function(item) { 549 this.outstandingCloudSearchRequests_.filter(function(item) {
578 if (item != request && item.origin == request.origin) { 550 if (item != request && item.origin == request.origin) {
579 lastRequestForThisOrigin = false; 551 lastRequestForThisOrigin = false;
580 } 552 }
581 return item != request; 553 return item != request;
582 }); 554 });
583 var activeUser = ''; 555 var activeUser = '';
584 if (request.origin == print_preview.Destination.Origin.COOKIES) { 556 if (request.origin == print_preview.Destination.Origin.COOKIES) {
585 activeUser = 557 activeUser = request.result && request.result['request'] &&
586 request.result &&
587 request.result['request'] &&
588 request.result['request']['user']; 558 request.result['request']['user'];
589 } 559 }
590 var event = null; 560 var event = null;
591 if (request.xhr.status == 200 && request.result['success']) { 561 if (request.xhr.status == 200 && request.result['success']) {
592 // Extract printers. 562 // Extract printers.
593 var printerListJson = request.result['printers'] || []; 563 var printerListJson = request.result['printers'] || [];
594 var printerList = []; 564 var printerList = [];
595 printerListJson.forEach(function(printerJson) { 565 printerListJson.forEach(function(printerJson) {
596 try { 566 try {
597 printerList.push(cloudprint.CloudDestinationParser.parse( 567 printerList.push(cloudprint.CloudDestinationParser.parse(
598 printerJson, request.origin, activeUser)); 568 printerJson, request.origin, activeUser));
599 } catch (err) { 569 } catch (err) {
600 console.error('Unable to parse cloud print destination: ' + err); 570 console.error('Unable to parse cloud print destination: ' + err);
601 } 571 }
602 }); 572 });
603 // Extract and store users. 573 // Extract and store users.
604 this.setUsers_(request); 574 this.setUsers_(request);
605 // Dispatch SEARCH_DONE event. 575 // Dispatch SEARCH_DONE event.
606 event = new Event(CloudPrintInterface.EventType.SEARCH_DONE); 576 event = new Event(CloudPrintInterface.EventType.SEARCH_DONE);
607 event.origin = request.origin; 577 event.origin = request.origin;
608 event.printers = printerList; 578 event.printers = printerList;
609 event.isRecent = isRecent; 579 event.isRecent = isRecent;
610 } else { 580 } else {
611 event = this.createErrorEvent_( 581 event = this.createErrorEvent_(
612 CloudPrintInterface.EventType.SEARCH_FAILED, 582 CloudPrintInterface.EventType.SEARCH_FAILED, request);
613 request);
614 } 583 }
615 event.user = activeUser; 584 event.user = activeUser;
616 event.searchDone = lastRequestForThisOrigin; 585 event.searchDone = lastRequestForThisOrigin;
617 this.dispatchEvent(event); 586 this.dispatchEvent(event);
618 }, 587 },
619 588
620 /** 589 /**
621 * Called when invitations search request completes. 590 * Called when invitations search request completes.
622 * @param {!CloudPrintRequest} request Request that has been completed. 591 * @param {!CloudPrintRequest} request Request that has been completed.
623 * @private 592 * @private
624 */ 593 */
625 onInvitesDone_: function(request) { 594 onInvitesDone_: function(request) {
626 var event = null; 595 var event = null;
627 var activeUser = 596 var activeUser = (request.result && request.result['request'] &&
628 (request.result && 597 request.result['request']['user']) ||
629 request.result['request'] && 598 '';
630 request.result['request']['user']) || '';
631 if (request.xhr.status == 200 && request.result['success']) { 599 if (request.xhr.status == 200 && request.result['success']) {
632 // Extract invitations. 600 // Extract invitations.
633 var invitationListJson = request.result['invites'] || []; 601 var invitationListJson = request.result['invites'] || [];
634 var invitationList = []; 602 var invitationList = [];
635 invitationListJson.forEach(function(invitationJson) { 603 invitationListJson.forEach(function(invitationJson) {
636 try { 604 try {
637 invitationList.push(cloudprint.InvitationParser.parse( 605 invitationList.push(
638 invitationJson, activeUser)); 606 cloudprint.InvitationParser.parse(invitationJson, activeUser));
639 } catch (e) { 607 } catch (e) {
640 console.error('Unable to parse invitation: ' + e); 608 console.error('Unable to parse invitation: ' + e);
641 } 609 }
642 }); 610 });
643 // Dispatch INVITES_DONE event. 611 // Dispatch INVITES_DONE event.
644 event = new Event(CloudPrintInterface.EventType.INVITES_DONE); 612 event = new Event(CloudPrintInterface.EventType.INVITES_DONE);
645 event.invitations = invitationList; 613 event.invitations = invitationList;
646 } else { 614 } else {
647 event = this.createErrorEvent_( 615 event = this.createErrorEvent_(
648 CloudPrintInterface.EventType.INVITES_FAILED, request); 616 CloudPrintInterface.EventType.INVITES_FAILED, request);
649 } 617 }
650 event.user = activeUser; 618 event.user = activeUser;
651 this.dispatchEvent(event); 619 this.dispatchEvent(event);
652 }, 620 },
653 621
654 /** 622 /**
655 * Called when invitation processing request completes. 623 * Called when invitation processing request completes.
656 * @param {!print_preview.Invitation} invitation Processed invitation. 624 * @param {!print_preview.Invitation} invitation Processed invitation.
657 * @param {boolean} accept Whether this invitation was accepted or rejected. 625 * @param {boolean} accept Whether this invitation was accepted or rejected.
658 * @param {!CloudPrintRequest} request Request that has been completed. 626 * @param {!CloudPrintRequest} request Request that has been completed.
659 * @private 627 * @private
660 */ 628 */
661 onProcessInviteDone_: function(invitation, accept, request) { 629 onProcessInviteDone_: function(invitation, accept, request) {
662 var event = null; 630 var event = null;
663 var activeUser = 631 var activeUser = (request.result && request.result['request'] &&
664 (request.result && 632 request.result['request']['user']) ||
665 request.result['request'] && 633 '';
666 request.result['request']['user']) || '';
667 if (request.xhr.status == 200 && request.result['success']) { 634 if (request.xhr.status == 200 && request.result['success']) {
668 event = new Event(CloudPrintInterface.EventType.PROCESS_INVITE_DONE); 635 event = new Event(CloudPrintInterface.EventType.PROCESS_INVITE_DONE);
669 if (accept) { 636 if (accept) {
670 try { 637 try {
671 event.printer = cloudprint.CloudDestinationParser.parse( 638 event.printer = cloudprint.CloudDestinationParser.parse(
672 request.result['printer'], request.origin, activeUser); 639 request.result['printer'], request.origin, activeUser);
673 } catch (e) { 640 } catch (e) {
674 console.error('Failed to parse cloud print destination: ' + e); 641 console.error('Failed to parse cloud print destination: ' + e);
675 } 642 }
676 } 643 }
677 } else { 644 } else {
678 event = this.createErrorEvent_( 645 event = this.createErrorEvent_(
679 CloudPrintInterface.EventType.PROCESS_INVITE_FAILED, request); 646 CloudPrintInterface.EventType.PROCESS_INVITE_FAILED, request);
680 } 647 }
681 event.invitation = invitation; 648 event.invitation = invitation;
682 event.accept = accept; 649 event.accept = accept;
683 event.user = activeUser; 650 event.user = activeUser;
684 this.dispatchEvent(event); 651 this.dispatchEvent(event);
685 }, 652 },
686 653
687 /** 654 /**
688 * Called when the submit request completes. 655 * Called when the submit request completes.
689 * @param {!CloudPrintRequest} request Request that has been completed. 656 * @param {!CloudPrintRequest} request Request that has been completed.
690 * @private 657 * @private
691 */ 658 */
692 onSubmitDone_: function(request) { 659 onSubmitDone_: function(request) {
693 if (request.xhr.status == 200 && request.result['success']) { 660 if (request.xhr.status == 200 && request.result['success']) {
694 var submitDoneEvent = new Event( 661 var submitDoneEvent =
695 CloudPrintInterface.EventType.SUBMIT_DONE); 662 new Event(CloudPrintInterface.EventType.SUBMIT_DONE);
696 submitDoneEvent.jobId = request.result['job']['id']; 663 submitDoneEvent.jobId = request.result['job']['id'];
697 this.dispatchEvent(submitDoneEvent); 664 this.dispatchEvent(submitDoneEvent);
698 } else { 665 } else {
699 var errorEvent = this.createErrorEvent_( 666 var errorEvent = this.createErrorEvent_(
700 CloudPrintInterface.EventType.SUBMIT_FAILED, request); 667 CloudPrintInterface.EventType.SUBMIT_FAILED, request);
701 this.dispatchEvent(errorEvent); 668 this.dispatchEvent(errorEvent);
702 } 669 }
703 }, 670 },
704 671
705 /** 672 /**
706 * Called when the printer request completes. 673 * Called when the printer request completes.
707 * @param {string} destinationId ID of the destination that was looked up. 674 * @param {string} destinationId ID of the destination that was looked up.
708 * @param {!CloudPrintRequest} request Request that has been completed. 675 * @param {!CloudPrintRequest} request Request that has been completed.
709 * @private 676 * @private
710 */ 677 */
711 onPrinterDone_: function(destinationId, request) { 678 onPrinterDone_: function(destinationId, request) {
712 // Special handling of the first printer request. It does not matter at 679 // Special handling of the first printer request. It does not matter at
713 // this point, whether printer was found or not. 680 // this point, whether printer was found or not.
714 if (request.origin == print_preview.Destination.Origin.COOKIES && 681 if (request.origin == print_preview.Destination.Origin.COOKIES &&
715 request.result && 682 request.result && request.account &&
716 request.account &&
717 request.result['request']['user'] && 683 request.result['request']['user'] &&
718 request.result['request']['users'] && 684 request.result['request']['users'] &&
719 request.account != request.result['request']['user']) { 685 request.account != request.result['request']['user']) {
720 this.setUsers_(request); 686 this.setUsers_(request);
721 // In case the user account is known, but not the primary one, 687 // In case the user account is known, but not the primary one,
722 // activate it. 688 // activate it.
723 if (this.userSessionIndex_[request.account] > 0) { 689 if (this.userSessionIndex_[request.account] > 0) {
724 this.userInfo_.activeUser = request.account; 690 this.userInfo_.activeUser = request.account;
725 // Repeat the request for the newly activated account. 691 // Repeat the request for the newly activated account.
726 this.printer( 692 this.printer(
727 request.result['request']['params']['printerid'], 693 request.result['request']['params']['printerid'], request.origin,
728 request.origin,
729 request.account); 694 request.account);
730 // Stop processing this request, wait for the new response. 695 // Stop processing this request, wait for the new response.
731 return; 696 return;
732 } 697 }
733 } 698 }
734 // Process response. 699 // Process response.
735 if (request.xhr.status == 200 && request.result['success']) { 700 if (request.xhr.status == 200 && request.result['success']) {
736 var activeUser = ''; 701 var activeUser = '';
737 if (request.origin == print_preview.Destination.Origin.COOKIES) { 702 if (request.origin == print_preview.Destination.Origin.COOKIES) {
738 activeUser = request.result['request']['user']; 703 activeUser = request.result['request']['user'];
739 } 704 }
740 var printerJson = request.result['printers'][0]; 705 var printerJson = request.result['printers'][0];
741 var printer; 706 var printer;
742 try { 707 try {
743 printer = cloudprint.CloudDestinationParser.parse( 708 printer = cloudprint.CloudDestinationParser.parse(
744 printerJson, request.origin, activeUser); 709 printerJson, request.origin, activeUser);
745 } catch (err) { 710 } catch (err) {
746 console.error('Failed to parse cloud print destination: ' + 711 console.error(
712 'Failed to parse cloud print destination: ' +
747 JSON.stringify(printerJson)); 713 JSON.stringify(printerJson));
748 return; 714 return;
749 } 715 }
750 var printerDoneEvent = 716 var printerDoneEvent =
751 new Event(CloudPrintInterface.EventType.PRINTER_DONE); 717 new Event(CloudPrintInterface.EventType.PRINTER_DONE);
752 printerDoneEvent.printer = printer; 718 printerDoneEvent.printer = printer;
753 this.dispatchEvent(printerDoneEvent); 719 this.dispatchEvent(printerDoneEvent);
754 } else { 720 } else {
755 var errorEvent = this.createErrorEvent_( 721 var errorEvent = this.createErrorEvent_(
756 CloudPrintInterface.EventType.PRINTER_FAILED, request); 722 CloudPrintInterface.EventType.PRINTER_FAILED, request);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 this.name = name; 806 this.name = name;
841 807
842 /** 808 /**
843 * Name of the value. 809 * Name of the value.
844 * @type {string} 810 * @type {string}
845 */ 811 */
846 this.value = value; 812 this.value = value;
847 }; 813 };
848 814
849 // Export 815 // Export
850 return { 816 return {CloudPrintInterface: CloudPrintInterface};
851 CloudPrintInterface: CloudPrintInterface
852 };
853 }); 817 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698